Hi. This is my implementation of the libraries feature. Suggestions are welcome.
Here is brief summary of changes:
added a new structure Lib that contains a list of symbols and a list of Defns to represent a library.
added a new instruction for global and the matching code in printer.rkt to print its assembly.
read in compile-file.rkt was replaced by read-sequence to read a list of forms
check-label-targets-declared was removed because now we can have labels declared outside of current file. handle-undeclared-labels was added to list these undeclared labels using extern
asm-string was modified so that it does not try to find the first label and prepend a global in the case of a library, determined by if the list of instructions already begins with a Global (added by compiling the provide clause)
Two files, length.rkt and use-le.rkt were included to demo the feature.
make length.o
make use-len.o
ld -r main.o char.o io.o length.o -o runtime.o
gcc runtime.o use-len.o -o use-len
./use-len
Some drawbacks of this implementation:
Two tests were broken because of the changes made to parse to accommodate read-sequence and need to be fixed
globals are not at the top of the assembly file
the way to distinguish between a program and library (by the first instruction in the sequence) is hacky
Hi. This is my implementation of the libraries feature. Suggestions are welcome.
Here is brief summary of changes:
Lib
that contains a list of symbols and a list ofDefn
s to represent a library.global
and the matching code inprinter.rkt
to print its assembly.read
incompile-file.rkt
was replaced byread-sequence
to read a list of formscheck-label-targets-declared
was removed because now we can have labels declared outside of current file.handle-undeclared-labels
was added to list these undeclared labels usingextern
asm-string
was modified so that it does not try to find the first label and prepend aglobal
in the case of a library, determined by if the list of instructions already begins with aGlobal
(added by compiling theprovide
clause)Two files,
length.rkt
anduse-le.rkt
were included to demo the feature.Some drawbacks of this implementation:
parse
to accommodateread-sequence
and need to be fixedglobal
s are not at the top of the assembly file