Next: , Previous: , Up: Instruction Set   [Contents][Index] Function Prologue Instructions

A function call in Guile is very cheap: the VM simply hands control to the procedure. The procedure itself is responsible for asserting that it has been passed an appropriate number of arguments. This strategy allows arbitrarily complex argument parsing idioms to be developed, without harming the common case.

For example, only calls to keyword-argument procedures “pay” for the cost of parsing keyword arguments. (At the time of this writing, calling procedures with keyword arguments is typically two to four times as costly as calling procedures with a fixed set of arguments.)

Instruction: assert-nargs-ee c24:expected
Instruction: assert-nargs-ge c24:expected
Instruction: assert-nargs-le c24:expected

If the number of actual arguments is not ==, >=, or <= expected, respectively, signal an error.

The number of arguments is determined by subtracting the stack pointer from the frame pointer (fp - sp). See Stack Layout, for more details on stack frames. Note that expected includes the procedure itself.

Instruction: br-if-nargs-ne c24:expected x8:_ l24:offset
Instruction: br-if-nargs-lt c24:expected x8:_ l24:offset
Instruction: br-if-nargs-gt c24:expected x8:_ l24:offset

If the number of actual arguments is not equal, less than, or greater than expected, respectively, add offset, a signed 24-bit number, to the current instruction pointer. Note that expected includes the procedure itself.

These instructions are used to implement multiple arities, as in case-lambda. See Case-lambda, for more information.

Instruction: alloc-frame c24:nlocals

Ensure that there is space on the stack for nlocals local variables, setting them all to SCM_UNDEFINED, except those values that are already on the stack.

Instruction: reset-frame c24:nlocals

Like alloc-frame, but doesn’t check that the stack is big enough, and doesn’t initialize values to SCM_UNDEFINED. Used to reset the frame size to something less than the size that was previously set via alloc-frame.

Instruction: assert-nargs-ee/locals c12:expected c12:nlocals

Equivalent to a sequence of assert-nargs-ee and reserve-locals. The number of locals reserved is expected + nlocals.

Instruction: br-if-npos-gt c24:nreq x8:_ c24:npos x8:_ l24:offset

Find the first positional argument after nreq. If it is greater than npos, jump to offset.

This instruction is only emitted for functions with multiple clauses, and an earlier clause has keywords and no rest arguments. See Case-lambda, for more on how case-lambda chooses the clause to apply.

Instruction: bind-kwargs c24:nreq c8:flags c24:nreq-and-opt x8:_ c24:ntotal n32:kw-offset

flags is a bitfield, whose lowest bit is allow-other-keys, second bit is has-rest, and whose following six bits are unused.

Find the last positional argument, and shuffle all the rest above ntotal. Initialize the intervening locals to SCM_UNDEFINED. Then load the constant at kw-offset words from the current ip, and use it and the allow-other-keys flag to bind keyword arguments. If has-rest, collect all shuffled arguments into a list, and store it in nreq-and-opt. Finally, clear the arguments that we shuffled up.

The parsing is driven by a keyword arguments association list, looked up using kw-offset. The alist is a list of pairs of the form (kw . index), mapping keyword arguments to their local slot indices. Unless allow-other-keys is set, the parser will signal an error if an unknown key is found.

A macro-mega-instruction.

Instruction: bind-rest f24:dst

Collect any arguments at or above dst into a list, and store that list at dst.

Next: , Previous: , Up: Instruction Set   [Contents][Index]