-
Notifications
You must be signed in to change notification settings - Fork 32
CompilerInterface
= Compiler Interface =
Twobit is defined in src/Compiler
.
Twobit was designed as a portable cross-compiler
with a fairly simple interface, but that interface
has become more complex through ad hoc extensions for:
- different host systems
- different front ends (macro expanders)
- different back ends
The accomodation for different host systems shows up in
the src/Compat
directory and in Twobit's own
implementations of hashtables, sets, sorting procedure,
and error system.
It also shows up in the lexical syntax of Twobit's code,
and more generally in the lexical syntax of Larceny's code.
The accomodation for different front ends shows up mainly
in pass0.sch
, which will become more complex as the
ERR5RS/R6RS front end (or something similar) becomes more
integrated into Larceny.
The accomodation for different back ends shows up in the
compiler tables, the driver procedures, and in various
definitions of various procedures such as load
and
compile-file
, which are scattered throughout
Larceny's current code base.
At this time, the only host systems that still work are Larceny and PLT Scheme v37x. Note that PLT Scheme v4 does not work.
In the past, Larceny could use MacScheme, Gambit, Gambit-C,
MIT Scheme, Chez Scheme, and Petite Chez at various times.
For more on this, see src/Compat/README
.
The load-compiler
procedure, which is defined in
Build/petit-unix-defns.sch
and Build/dotnet.sch
,
takes an optional argument that, among sundry other things,
determines which files are considered to be part of Twobit.
If the symbol development
is passed to load-compiler
,
then Twobit's usual files are loaded, including
hash.sch
hashtable.sch
driver-twobit.sch
but not driver-larceny.sch
.
If the symbol release
is passed to load-compiler
,
then Twobit's own hash.sch
and hashtable.sch
are
not loaded, and driver-larceny.sch
is loaded
instead of driver-twobit.sch
.
When Twobit is loaded, its macro expander must not overwrite the existing macro expander until the new macro expander has been completely loaded. That involves some magic that Will still doesn't understand.
For each back end, there are two compiler tables that must match the assembler provided for the back end.
Each back end may also define its own linker, heap dumper,
and fasl dumper, and may provide its own weird version of
Twobit's driver and/or the load
and compile-file
procedures.
What's more, the ERR5RS/R6RS runtime system also redefines
load
and compile-file
.
All back ends must implement the MacSchemeInstructionSet
along with the basic primops listed in
src/Compiler/common.imp.sch
.
The full sets of primops that are implemented by each back end are listed in
src/Compiler/sparc.imp.sch
src/Compiler/iasn.imp.sch
src/Compiler/standard-C.imp.sch
src/Asm/IL/il.imp.sch
Those files must be consistent with both common.imp.sch
and with the various assemblers.
Each back end must also provide tables that are used by Twobit's representation inference:
src/Compiler/sparc.imp2.sch
src/Compiler/iasn.imp2.sch
src/Compiler/standard-C.imp2.sch
src/Asm/IL/il.imp2.sch
Those tables must be consistent with each other and with the invariants documented in those files, which is not as easy as it should be. If you make any changes to the tables used by representation inference, then you should test thoroughly.
Some back ends override the usual heap-dumping routines,
which are defined in src/Asm/Shared/dumpheap.sch
:
CSharp/dumpheap-extra.sch
IL/dumpheap-extra.sch
IL/dumpheap-il.sch
Nasm/dumpheap-overrides.sch
Nasm/dumpheap-unix.sch
Nasm/dumpheap-win32.sch
Standard-C/dumpheap-overrides.sch
Standard-C/dumpheap-unix.sch
Standard-C/dumpheap-win32.sch
The compile-file
, compile313
, assemble313
,
and make-fasl
procedures are defined in
src/Compiler/driver-*.sch
.
The assemble-file
procedure is defined in
src/Compiler/driver-common.sch
, along with
process-file
and several other auxiliary
procedures. Some of those procedure are duplicated
or redefined in lib/R6RS/r6rsmode.sch
.
The compile
procedure is defined in
src/Compiler/pass4.aux.sch
.
Some back ends also define or redefine procedures such as
c-compile-file
c-compiler:gcc-win32
c-compiler:msvc-win32
c-compiler:msvc-win32:6.0
c-compiler:mwcc-win32
compile-application
compile-file
compile-file/clr
In particular, see:
lib/Base/dotnet-compile-file.sch
lib/Base/petit-compile-file.sch
The load
procedure is defined or redefined in several
different places:
lib/Base/load.sch
lib/R6RS/r6rs-expander.sch (ex:load)
lib/R6RS/r6rsmode.sch
(r5rs:load, larceny:autoload-r6rs-library, load-r6rs-program
lib/SRFI/srfi-96.sch
(macro:load, slib:load-source, slib:load-compiled, slib:eval-load, slib:load)