-
Notifications
You must be signed in to change notification settings - Fork 32
FastLoadFile
Twobit compiles Scheme source code (.sch
) to MacScheme Assembly Language (.lap
files), which are assembled into .lop
files which are then something'd into fast load (.fasl
) files.
A fasl file is a sequence of expressions. Really, that's it. It's just that Larceny has an external representation for compiled procedures, global variable cells, etc. So when the reader reads in a fasl file, it produces a bunch of s-expressions. It just happens that the car of each s-expression is a procedure literal, so the whole thing is a procedure application, and that's how the interpreter runs your compiled code when you load a fasl file. That also means that you can concatenate fasl files, interleave compiled expressions with normal Scheme code, etc.
That isn't 100% true, for several reasons:
- Fasl files now begin with
#!fasl
so they will be read in case-sensitive mode with the reader extensions needed by procedure literals, global value cells, and so forth. - Petit Larceny's fasl files contain references to
.petit-shared-object
and.petit-patch-procedure
. In ERR5RS mode, Petit Larceny uses afasl-evaluator
that treats#!fasl
as animport
form that declares those procedures. - Starting with v0.96, the ERR5RS/R6RS
load
procedure opens the file in raw Latin-1 mode and looks at the first line of the file. If the first line consists of the#!fasl
flag, then it loads the rest of the file from the raw Latin-1 port. Otherwise it closes the file, reopens it as an ordinary textual port, and loads from that port. - The
load
procedure attempts to detect whether an expression matches what we'd see in a Fasl file, and if so, it sends the procedure toapply
rather thaneval
.- see source:trunk/larceny_src/src/Lib/Common/load.sch for the code.
- This way, on CompileOnLoad or CompileOnEval systems, the compiler won't have to try to figure out how to emit code for a procedure literal constant.
- But the way it attempts to detect such procedure literals is a bit fragile; arbitrary reordering of the expressions in the fasl file, which would be legal if it were scheme source, will cause the compiler to die (because it won't know how to handle procedure literals). We could attempt to make the detection process more robust, perhaps by having the compiler throw an exception which is caught and handled by the load procedure...
The main thing to know, though, is that a fasl file is a fully-compiled Scheme source file.
See also CompilerInterface.