We can now separately process a prelude Cooma definition and read its information in to the execution of a different Cooma program (or REPL). This mechanism constitutes a simple form of separate compilation.
It all works via the new -P option which processes a prelude and generates:
A static file that contains names and types of prelude-defined entities. In the case of prelude types it also contains their definition.
A dynamic file that contains IR for the prelude.
The new -p option specifies the prelude to use in a run. The corresponding static and dynamic files will be loaded into the compiler and runtime before analysing and executing the user's code. The static file provides an initial environment for semantic analysis. The IR code in the dynamic file is executed to produce an initial environment for execution. Thus, all of the entities defined in the prelude are available automatically in user code.
The default prelude is prelude/prelude.cooma. After any changes, we need to reprocess it with -P to get the default static and dynamic files.
The new -Q option can be used to run without using a prelude.
Details of main changes:
Config
add prelude-related options (-p, -P and -Q)
Main
add invocation of prelude driver if -P specified
cooma.syntax
Cooma: remove constructs that are defined in prelude (Boolean-related things, Ints, Strings, Vectors, equal)
Cooma: remove syntactic capability types in favour of identifiers from prelude (e.g., Reader)
IR: add syntax definition to get parser for prelude processing and replace old hand-written pretty-printer
IR: alter syntax to make it easier to parse, e.g., more keywords
IR: prefix keywords with % so they can't clash with identifiers
IR: prefix generated identifiers with $ so they can't clash with user names
IR: encode continuation syntax properly rather than just using identifiers (new Cont syntax category)
prelude: add syntax of static and dynamic prelude files
fix some small pretty-printing bugs
SemanticAnalysis
some reorganisation to tidy-up checking code
remove hard-coded typing of constructs that are now in the prelude
add support for pre-defined entities. These come from the compilation of the prelude and are loaded from the static file.
Compiler
add positions parameter to main compilation methods for use in setting positions of target constructs; this replaces the use of source parameters in backend IR creation API
put most of compiler in CompilerCore class to make it easy to access the positions from anywhere
remove hard-coded types and compilation of values that now come from prelude
Server
hover support for primitive types and operations plus pre-defined entities from prelude
SymbolTable
add entity kinds for pre-defined functions and let-defined values
fix bug in isPrimitiveTypeName where bitwise or was used instead of logical or
remove hard-coded types for things now defined in prelude (e.g., readerT)
add support for building initial environment from prelude static file
Util
add $ prefix to fresh variable names to distinguish from user identifiers
Primitives
replace object-oriented style with functional one since the abstract syntax of primitives is now generated from grammar
make Primitives into a trait so it can be mixed-in with backends instead of requiring backend parameters
Interpreter
some rearrangement to make parameter orders more logical and consistent (e.g., ClsC, ConsCE etc)
remove source node propagation since it's handled in compiler now
add support for reading dynamic prelude file to initialise runtime environment
remove linking in runtime value pretty-printing
Backend
remove source parameters from Term and ValueR constructor methods
rename FieldValue to FldV to better match other types and operations
use FldV in variant values (varV) as in record values (recV)
remove primitive methods (now in syntax)
unitR is now uniR to better match other constructs
add showTerm for backend-specific way to print Term
add stdout writer for use by primitives
maintain string values in escaped form to correct output issues
ReferenceBackend
conform to new smaller Backend API
remove classes for IR definition, since they are generated from syntax spec now
remove hand-coded IR pretty-printer since we use a generated one now
CoomaLanguage
add support for reading dynamic prelude
other Truffle-side changes
add Rats!-defined parser that builds Truffle CoomaTerm nodes
adapt to adjusted Term syntax and simplified Backend API
use new syntax-defined Primitive constructs
remove some unneeded code for processing halt continuations
remove an unused connection to the pretty-printer from the Java side
tests
adjust IR and IRAST test output for new IR syntax
standardise on default lowercase starting letter for test titles
semantic tests:
adapt primitive tests for new functional-style
add some missing vector tests
execution tests:
add a test of environment capture
add a test of unit equality
adjust types for new prelude processing
adapt primitive tests for new functional-style
allow for "no type" in REPL tests, since we have some programs that don't type at the moment
We can now separately process a prelude Cooma definition and read its information in to the execution of a different Cooma program (or REPL). This mechanism constitutes a simple form of separate compilation.
It all works via the new
-P
option which processes a prelude and generates:A
static
file that contains names and types of prelude-defined entities. In the case of prelude types it also contains their definition.A
dynamic
file that contains IR for the prelude.The new
-p
option specifies the prelude to use in a run. The correspondingstatic
anddynamic
files will be loaded into the compiler and runtime before analysing and executing the user's code. Thestatic
file provides an initial environment for semantic analysis. The IR code in thedynamic
file is executed to produce an initial environment for execution. Thus, all of the entities defined in the prelude are available automatically in user code.The default prelude is
prelude/prelude.cooma
. After any changes, we need to reprocess it with-P
to get the defaultstatic
anddynamic
files.The new
-Q
option can be used to run without using a prelude.Details of main changes:
Config
-p
,-P
and-Q
)Main
-P
specifiedcooma.syntax
Ints
,Strings
,Vectors
,equal
)Reader
)Cont
syntax category)SemanticAnalysis
static
file.Compiler
positions
parameter to main compilation methods for use in setting positions of target constructs; this replaces the use ofsource
parameters in backend IR creation APICompilerCore
class to make it easy to access the positions from anywhereServer
SymbolTable
isPrimitiveTypeName
where bitwise or was used instead of logical orreaderT
)static
fileUtil
Primitives
Primitives
into a trait so it can be mixed-in with backends instead of requiring backend parametersInterpreter
ClsC
,ConsCE
etc)source
node propagation since it's handled in compiler nowdynamic
prelude file to initialise runtime environmentBackend
Term
andValueR
constructor methodsFieldValue
toFldV
to better match other types and operationsFldV
in variant values (varV
) as in record values (recV
)unitR
is nowuniR
to better match other constructsshowTerm
for backend-specific way to printTerm
stdout
writer for use by primitivesReferenceBackend
Backend
APICoomaLanguage
dynamic
preludeother
Truffle
-side changesCoomaTerm
nodesTerm
syntax and simplifiedBackend
APIPrimitive
constructstests
README