/usr/share/axiom-20170501/src/algebra/SYMS.spad is in axiom-source 20170501-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 | )abbrev domain SYMS TheSymbolTable
++ Author: Mike Dewar
++ Date Created: October 1992
++ Description:
++ Creates and manipulates one global symbol table for FORTRAN
++ code generation, containing details of types, dimensions, and argument
++ lists.
TheSymbolTable() : SIG == CODE where
S ==> Symbol
FST ==> FortranScalarType
FSTU ==> Union(fst:FST,void:"void")
SIG ==> CoercibleTo OutputForm with
showTheSymbolTable : () -> $
++ showTheSymbolTable() returns the current symbol table.
clearTheSymbolTable : () -> Void
++ clearTheSymbolTable() clears the current symbol table.
clearTheSymbolTable : Symbol -> Void
++ clearTheSymbolTable(x) removes the symbol x from the table
declare! : (Symbol,FortranType,Symbol,$) -> FortranType
++ declare!(u,t,asp,tab) declares the parameter u of subprogram asp
++ to have type t in symbol table tab.
declare! : (List Symbol,FortranType,Symbol,$) -> FortranType
++ declare!(u,t,asp,tab) declares the parameters u of subprogram asp
++ to have type t in symbol table tab.
declare! : (Symbol,FortranType) -> FortranType
++ declare!(u,t) declares the parameter u to have type t in the
++ current level of the symbol table.
declare! : (Symbol,FortranType,Symbol) -> FortranType
++ declare!(u,t,asp) declares the parameter u to have type t in asp.
newSubProgram : Symbol -> Void
++ newSubProgram(f) asserts that from now on type declarations are part
++ of subprogram f.
currentSubProgram : () -> Symbol
++ currentSubProgram() returns the name of the current subprogram being
++ processed
endSubProgram : () -> Symbol
++ endSubProgram() asserts that we are no longer processing the current
++ subprogram.
argumentList! : (Symbol,List Symbol,$) -> Void
++ argumentList!(f,l,tab) declares that the argument list for
++ subprogram f in symbol table tab is l.
argumentList! : (Symbol,List Symbol) -> Void
++ argumentList!(f,l) declares that the argument list for subprogram f in
++ the global symbol table is l.
argumentList! : List Symbol -> Void
++ argumentList!(l) declares that the argument list for the current
++ subprogram in the global symbol table is l.
returnType! : (Symbol,FSTU,$) -> Void
++ returnType!(f,t,tab) declares that the return type of subprogram f in
++ symbol table tab is t.
returnType! : (Symbol,FSTU) -> Void
++ returnType!(f,t) declares that the return type of subprogram f in
++ the global symbol table is t.
returnType! : FSTU -> Void
++ returnType!(t) declares that the return type of he current subprogram
++ in the global symbol table is t.
printHeader : (Symbol,$) -> Void
++ printHeader(f,tab) produces the FORTRAN header for subprogram f in
++ symbol table tab on the current FORTRAN output stream.
printHeader : Symbol -> Void
++ printHeader(f) produces the FORTRAN header for subprogram f in
++ the global symbol table on the current FORTRAN output stream.
printHeader : () -> Void
++ printHeader() produces the FORTRAN header for the current subprogram
++ in the global symbol table on the current FORTRAN output stream.
printTypes : Symbol -> Void
++ printTypes(tab) produces FORTRAN type declarations from tab, on the
++ current FORTRAN output stream
empty : () -> $
++ empty() creates a new, empty symbol table.
returnTypeOf : (Symbol,$) -> FSTU
++ returnTypeOf(f,tab) returns the type of the object returned by f
argumentListOf : (Symbol,$) -> List(Symbol)
++ argumentListOf(f,tab) returns the argument list of f
symbolTableOf : (Symbol,$) -> SymbolTable
++ symbolTableOf(f,tab) returns the symbol table of f
CODE ==> add
Entry : Domain := Record(symtab:SymbolTable, _
returnType:FSTU, _
argList:List Symbol)
Rep := Table(Symbol,Entry)
-- These are the global variables we want to update:
theSymbolTable : $ := empty()$Rep
currentSubProgramName : Symbol := MAIN
newEntry():Entry ==
construct(empty()$SymbolTable,["void"]$FSTU,[]::List(Symbol))$Entry
checkIfEntryExists(name:Symbol,tab:$) : Void ==
key?(name,tab) => void()$Void
setelt(tab,name,newEntry())$Rep
void()$Void
returnTypeOf(name:Symbol,tab:$):FSTU ==
elt(elt(tab,name)$Rep,returnType)$Entry
argumentListOf(name:Symbol,tab:$):List(Symbol) ==
elt(elt(tab,name)$Rep,argList)$Entry
symbolTableOf(name:Symbol,tab:$):SymbolTable ==
elt(elt(tab,name)$Rep,symtab)$Entry
coerce(u:$):OutputForm ==
coerce(u)$Rep
showTheSymbolTable():$ ==
theSymbolTable
clearTheSymbolTable():Void ==
theSymbolTable := empty()$Rep
void()$Void
clearTheSymbolTable(u:Symbol):Void ==
remove!(u,theSymbolTable)$Rep
void()$Void
empty():$ ==
empty()$Rep
currentSubProgram():Symbol ==
currentSubProgramName
-- If we want to support more complex languages then we should keep
-- a list of subprograms / blocks - but for the moment lets stick with
-- Fortran.
endSubProgram():Symbol ==
currentSubProgramName := MAIN
newSubProgram(u:Symbol):Void ==
setelt(theSymbolTable,u,newEntry())$Rep
currentSubProgramName := u
void()$Void
argumentList!(u:Symbol,args:List Symbol,symbols:$):Void ==
checkIfEntryExists(u,symbols)
setelt(elt(symbols,u)$Rep,argList,args)$Entry
argumentList!(u:Symbol,args:List Symbol):Void ==
argumentList!(u,args,theSymbolTable)
argumentList!(args:List Symbol):Void ==
checkIfEntryExists(currentSubProgramName,theSymbolTable)
setelt(elt(theSymbolTable,currentSubProgramName)$Rep, _
argList,args)$Entry
returnType!(u:Symbol,type:FSTU,symbols:$):Void ==
checkIfEntryExists(u,symbols)
setelt(elt(symbols,u)$Rep,returnType,type)$Entry
returnType!(u:Symbol,type:FSTU):Void ==
returnType!(u,type,theSymbolTable)
returnType!(type:FSTU ):Void ==
checkIfEntryExists(currentSubProgramName,theSymbolTable)
setelt(elt(theSymbolTable,currentSubProgramName)$Rep, _
returnType,type)$Entry
declare!(u:Symbol,type:FortranType):FortranType ==
declare!(u,type,currentSubProgramName,theSymbolTable)
declare!(u:Symbol,type:FortranType,asp:Symbol,symbols:$):FortranType ==
checkIfEntryExists(asp,symbols)
declare!(u,type, elt(elt(symbols,asp)$Rep,symtab)$Entry)$SymbolTable
declare!(u:List Symbol,type:FortranType,asp:Symbol,syms:$):FortranType ==
checkIfEntryExists(asp,syms)
declare!(u,type, elt(elt(syms,asp)$Rep,symtab)$Entry)$SymbolTable
declare!(u:Symbol,type:FortranType,asp:Symbol):FortranType ==
checkIfEntryExists(asp,theSymbolTable)
declare!(u,type,elt(elt(theSymbolTable,asp)$Rep,symtab)$Entry)$SymbolTable
printHeader(u:Symbol,symbols:$):Void ==
entry := elt(symbols,u)$Rep
fortFormatHead(elt(entry,returnType)$Entry::OutputForm,u::OutputForm, _
elt(entry,argList)$Entry::OutputForm)$Lisp
printTypes(elt(entry,symtab)$Entry)$SymbolTable
printHeader(u:Symbol):Void ==
printHeader(u,theSymbolTable)
printHeader():Void ==
printHeader(currentSubProgramName,theSymbolTable)
printTypes(u:Symbol):Void ==
printTypes(elt(elt(theSymbolTable,u)$Rep,symtab)$Entry)$SymbolTable
|