login  home  contents  what's new  discussion  bug reports     help  links  subscribe  changes  refresh  edit

Edit detail for SandBox Domains and Types revision 1 of 1

1
Editor:
Time: 2007/11/18 17:59:00 GMT-8
Note:

changed:
-
In searching for use and meaning of the domain 'Domain', in all
the Axiom library I can find only one place that uses this domain::

  algebra/forttyp.spad.pamphlet

So apparently at least in 1992, such a domain did exist in Axiom.

Oddly (or perhaps as we might expect :) compiling this code in
the current version of Axiom produces some error messages::

   Semantic Errors: 
      [1]  Domain is not a known type
      [2]  void is not a known type

yet the compiler does apparently successfully complete. But
does it work?

\begin{spad}
)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() : Exports == Implementation where

  S    ==> Symbol
  FST  ==> FortranScalarType
  FSTU ==> Union(fst:FST,void:"void")

  Exports == 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

  Implementation == 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

    endSubProgram():Symbol ==
    -- 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.
      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
\end{spad}

In searching for use and meaning of the domain Domain, in all the Axiom library I can find only one place that uses this domain:

  algebra/forttyp.spad.pamphlet

So apparently at least in 1992, such a domain did exist in Axiom.

Oddly (or perhaps as we might expect :) compiling this code in the current version of Axiom produces some error messages:

   Semantic Errors: 
      [1]  Domain is not a known type
      [2]  void is not a known type

yet the compiler does apparently successfully complete. But does it work?

spad
)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() : Exports == Implementation where
S ==> Symbol FST ==> FortranScalarType FSTU ==> Union(fst:FST,void:"void")
Exports == 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
Implementation == 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
endSubProgram():Symbol == -- 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. 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
spad
   Compiling FriCAS source code from file 
      /var/zope2/var/LatexWiki/5955188495929791613-25px001.spad using 
      old system compiler.
   SYMS abbreviates domain TheSymbolTable 
   processing macro definition S ==> Symbol 
   processing macro definition FST ==> FortranScalarType 
   processing macro definition FSTU ==> Union(fst: FortranScalarType,void: void) 
------------------------------------------------------------------------
   initializing NRLIB SYMS for TheSymbolTable 
   compiling into NRLIB SYMS 
   compiling local newEntry : () -> Entry
Time: 0.01 SEC.
compiling local checkIfEntryExists : (Symbol,$) -> Void Time: 0.01 SEC.
compiling exported returnTypeOf : (Symbol,$) -> Union(fst: FortranScalarType,void: void) Time: 0 SEC.
compiling exported argumentListOf : (Symbol,$) -> List Symbol Time: 0 SEC.
compiling exported symbolTableOf : (Symbol,$) -> SymbolTable Time: 0 SEC.
compiling exported coerce : $ -> OutputForm Time: 0.01 SEC.
compiling exported showTheSymbolTable : () -> $ Time: 0 SEC.
compiling exported clearTheSymbolTable : () -> Void Time: 0 SEC.
compiling exported clearTheSymbolTable : Symbol -> Void Time: 0 SEC.
compiling exported empty : () -> $ Time: 0 SEC.
compiling exported currentSubProgram : () -> Symbol Time: 0 SEC.
compiling exported endSubProgram : () -> Symbol Time: 0 SEC.
compiling exported newSubProgram : Symbol -> Void Time: 0 SEC.
compiling exported argumentList! : (Symbol,List Symbol,$) -> Void Time: 0 SEC.
compiling exported argumentList! : (Symbol,List Symbol) -> Void Time: 0.06 SEC.
compiling exported argumentList! : List Symbol -> Void Time: 0 SEC.
compiling exported returnType! : (Symbol,Union(fst: FortranScalarType,void: void),$) -> Void Time: 0 SEC.
compiling exported returnType! : (Symbol,Union(fst: FortranScalarType,void: void)) -> Void Time: 0 SEC.
compiling exported returnType! : Union(fst: FortranScalarType,void: void) -> Void Time: 0.01 SEC.
compiling exported declare! : (Symbol,FortranType) -> FortranType Time: 0 SEC.
compiling exported declare! : (Symbol,FortranType,Symbol,$) -> FortranType Time: 0 SEC.
compiling exported declare! : (List Symbol,FortranType,Symbol,$) -> FortranType Time: 0 SEC.
compiling exported declare! : (Symbol,FortranType,Symbol) -> FortranType Time: 0.01 SEC.
compiling exported printHeader : (Symbol,$) -> Void Time: 0.02 SEC.
compiling exported printHeader : Symbol -> Void Time: 0 SEC.
compiling exported printHeader : () -> Void Time: 0 SEC.
compiling exported printTypes : Symbol -> Void Time: 0.05 SEC.
(time taken in buildFunctor: 1)
;;; *** |TheSymbolTable| REDEFINED
;;; *** |TheSymbolTable| REDEFINED Time: 0.01 SEC.
Semantic Errors: [1] Domain is not a known type [2] void is not a known type
Cumulative Statistics for Constructor TheSymbolTable Time: 0.19 seconds
finalizing NRLIB SYMS Processing TheSymbolTable for Browser database: --------(showTheSymbolTable ($))--------- --------(clearTheSymbolTable ((Void)))--------- --------(clearTheSymbolTable ((Void) (Symbol)))--------- --------(declare! ((FortranType) (Symbol) (FortranType) (Symbol) $))--------- --------(declare! ((FortranType) (List (Symbol)) (FortranType) (Symbol) $))--------- --------(declare! ((FortranType) (Symbol) (FortranType)))--------- --------(declare! ((FortranType) (Symbol) (FortranType) (Symbol)))--------- --------(newSubProgram ((Void) (Symbol)))--------- --------(currentSubProgram ((Symbol)))--------- --------(endSubProgram ((Symbol)))--------- --------(argumentList! ((Void) (Symbol) (List (Symbol)) $))--------- --------(argumentList! ((Void) (Symbol) (List (Symbol))))--------- --------(argumentList! ((Void) (List (Symbol))))--------- --------(returnType! ((Void) (Symbol) FSTU $))--------- --------(returnType! ((Void) (Symbol) FSTU))--------- --------(returnType! ((Void) FSTU))--------- --------(printHeader ((Void) (Symbol) $))--------- --------(printHeader ((Void) (Symbol)))--------- --------(printHeader ((Void)))--------- --------(printTypes ((Void) (Symbol)))--------- --------(empty ($))--------- --------(returnTypeOf (FSTU (Symbol) $))--------- --------(argumentListOf ((List (Symbol)) (Symbol) $))--------- --------(symbolTableOf ((SymbolTable) (Symbol) $))--------- --------constructor--------- ------------------------------------------------------------------------ TheSymbolTable is now explicitly exposed in frame initial TheSymbolTable will be automatically loaded when needed from /var/zope2/var/LatexWiki/SYMS.NRLIB/code