Warning: This is the manual of the legacy Guile 2.0 series. You may want to read the manual of the current stable series instead.
Next: Writing New High-Level Languages, Previous: Assembly, Up: Compiling to the Virtual Machine [Contents][Index]
Finally, the raw bytes. There are actually two different “languages” here, corresponding to two different ways to represent the bytes.
“Bytecode” represents code as uniform byte vectors, useful for structuring and destructuring code on the Scheme level. Bytecode is the next step down from assembly:
scheme@(guile-user)> (compile '(+ 32 10) #:to 'bytecode) ⇒ #vu8(8 0 0 0 25 0 0 0 ; Header. 95 0 ; Prologue. 10 32 10 10 148 66 17 ; Actual code. 0 0 0 0 0 0 0 9 ; Metadata thunk. 9 10 2 10 8 11 18 0 3 18 0 1 18 0 3 66)
“Objcode” is bytecode, but mapped directly to a C structure,
struct scm_objcode
:
struct scm_objcode { scm_t_uint32 len; scm_t_uint32 metalen; scm_t_uint8 base[0]; };
As one might imagine, objcode imposes a minimum length on the
bytecode. Also, the len
and metalen
fields are in native
endianness, which makes objcode (and bytecode) system-dependent.
Objcode also has a couple of important efficiency hacks. First, objcode may be mapped directly from disk, allowing compiled code to be loaded quickly, often from the system’s disk cache, and shared among multiple processes. Secondly, objcode may be embedded in other objcode, allowing procedures to have the text of other procedures inlined into their bodies, without the need for separate allocation of the code. Of course, the objcode object itself does need to be allocated.
Procedures related to objcode are defined in the (system vm
objcode)
module.
Returns #f
if obj is object code, #f
otherwise.
Makes a bytecode object from bytecode, which should be a bytevector. See Bytevectors.
Load object code from a file named file. The file will be mapped
into memory via mmap
, so this is a very fast operation.
On disk, object code has an sixteen-byte cookie prepended to it, to prevent accidental loading of arbitrary garbage.
Write object code out to a file, prepending the sixteen-byte cookie.
Copy object code out to a bytevector for analysis by Scheme.
The following procedure is actually in (system vm program)
, but
we’ll mention it here:
Load up object code into a Scheme program. The resulting program will
have objtable as its object table, which should be a vector or
#f
, and will capture the free variables from free-vars.
Object code from a file may be disassembled at the REPL via the
meta-command ,disassemble-file
, abbreviated as ,xx
.
Programs may be disassembled via ,disassemble
, abbreviated as
,x
.
Compiling object code to the fake language, value
, is performed
via loading objcode into a program, then executing that thunk with
respect to the compilation environment. Normally the environment
propagates through the compiler transparently, but users may specify
the compilation environment manually as well, as a module.
Next: Writing New High-Level Languages, Previous: Assembly, Up: Compiling to the Virtual Machine [Contents][Index]