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: , Previous: , Up: Compiling to the Virtual Machine   [Contents][Index]

9.4.4 GLIL

Guile Lowlevel Intermediate Language (GLIL) is a structured intermediate language whose expressions more closely approximate Guile’s VM instruction set. Its expression types are defined in (language glil).

Scheme Variable: <glil-program> meta . body

A unit of code that at run-time will correspond to a compiled procedure. meta should be an alist of properties, as in Tree-IL’s <lambda>. body is an ordered list of GLIL expressions.

Scheme Variable: <glil-std-prelude> nreq nlocs else-label

A prologue for a function with no optional, keyword, or rest arguments. nreq is the number of required arguments. nlocs the total number of local variables, including the arguments. If the procedure was not given exactly nreq arguments, control will jump to else-label, if given, or otherwise signal an error.

Scheme Variable: <glil-opt-prelude> nreq nopt rest nlocs else-label

A prologue for a function with optional or rest arguments. Like <glil-std-prelude>, with the addition that nopt is the number of optional arguments (possibly zero) and rest is an index of a local variable at which to bind a rest argument, or #f if there is no rest argument.

Scheme Variable: <glil-kw-prelude> nreq nopt rest kw allow-other-keys? nlocs else-label

A prologue for a function with keyword arguments. Like <glil-opt-prelude>, with the addition that kw is a list of keyword arguments, and allow-other-keys? is a flag indicating whether to allow unknown keys. See bind-kwargs, for details on the format of kw.

Scheme Variable: <glil-bind> . vars

An advisory expression that notes a liveness extent for a set of variables. vars is a list of (name type index), where type should be either argument, local, or external.

<glil-bind> expressions end up being serialized as part of a program’s metadata and do not form part of a program’s code path.

Scheme Variable: <glil-mv-bind> vars rest

A multiple-value binding of the values on the stack to vars. If rest is true, the last element of vars will be treated as a rest argument.

In addition to pushing a binding annotation on the stack, like <glil-bind>, an expression is emitted at compilation time to make sure that there are enough values available to bind. See the notes on truncate-values in Procedure Call and Return Instructions, for more information.

Scheme Variable: <glil-unbind>

Closes the liveness extent of the most recently encountered <glil-bind> or <glil-mv-bind> expression. As GLIL expressions are compiled, a parallel stack of live bindings is maintained; this expression pops off the top element from that stack.

Bindings are written into the program’s metadata so that debuggers and other tools can determine the set of live local variables at a given offset within a VM program.

Scheme Variable: <glil-source> loc

Records source information for the preceding expression. loc should be an association list of containing line column, and filename keys, e.g. as returned by source-properties.

Scheme Variable: <glil-void>

Pushes “the unspecified value” on the stack.

Scheme Variable: <glil-const> obj

Pushes a constant value onto the stack. obj must be a number, string, symbol, keyword, boolean, character, uniform array, the empty list, or a pair or vector of constants.

Scheme Variable: <glil-lexical> local? boxed? op index

Accesses a lexically bound variable. If the variable is not local? it is free. All variables may have ref, set, and bound? as their op. Boxed variables may also have the ops box, empty-box, and fix, which correspond in semantics to the VM instructions box, empty-box, and fix-closure. See Stack Layout, for more information.

Scheme Variable: <glil-toplevel> op name

Accesses a toplevel variable. op may be ref, set, or define.

Scheme Variable: <glil-module> op mod name public?

Accesses a variable within a specific module. See Tree-IL’s <module-ref>, for more information.

Scheme Variable: <glil-label> label

Creates a new label. label can be any Scheme value, and should be unique.

Scheme Variable: <glil-branch> inst label

Branch to a label. label should be a <ghil-label>. inst is a branching instruction: br-if, br, etc.

Scheme Variable: <glil-call> inst nargs

This expression is probably misnamed, as it does not correspond to function calls. <glil-call> invokes the VM instruction named inst, noting that it is called with nargs stack arguments. The arguments should be pushed on the stack already. What happens to the stack afterwards depends on the instruction.

Scheme Variable: <glil-mv-call> nargs ra

Performs a multiple-value call. ra is a <glil-label> corresponding to the multiple-value return address for the call. See the notes on mv-call in Procedure Call and Return Instructions, for more information.

Scheme Variable: <glil-prompt> label escape-only?

Push a dynamic prompt into the stack, with a handler at label. escape-only? is a flag that is propagated to the prompt, allowing an abort to avoid capturing a continuation in some cases. See Prompts, for more information.

Users may enter in GLIL at the REPL as well, though there is a bit more bookkeeping to do:

scheme@(guile-user)> ,language glil
Happy hacking with Guile Lowlevel Intermediate Language (GLIL)!
To switch back, type `,L scheme'.
glil@(guile-user)> (program () (std-prelude 0 0 #f)
                       (const 3) (call return 1))
⇒ 3

Just as in all of Guile’s compilers, an environment is passed to the GLIL-to-object code compiler, and one is returned as well, along with the object code.

Next: , Previous: , Up: Compiling to the Virtual Machine   [Contents][Index]