Next: , Previous: , Up: Instruction Set   [Contents][Index] Procedure Call and Return Instructions

As described earlier (see Stack Layout), Guile’s calling convention is that arguments are passed and values returned on the stack.

For calls, both in tail position and in non-tail position, we require that the procedure and the arguments already be shuffled into place befor the call instruction. “Into place” for a tail call means that the procedure should be in slot 0, relative to the fp, and the arguments should follow. For a non-tail call, if the procedure is in fp-relative slot n, the arguments should follow from slot n+1, and there should be two free slots at n-1 and n-2 in which to save the ip and fp.

Returning values is similar. Multiple-value returns should have values already shuffled down to start from fp-relative slot 1 before emitting return-values. There is a short-cut in the single-value case, in that return handles the trivial shuffling itself. We start from slot 1 instead of slot 0 to make tail calls to values trivial.

In both calls and returns, the sp is used to indicate to the callee or caller the number of arguments or return values, respectively. After receiving return values, it is the caller’s responsibility to restore the frame by resetting the sp to its former value.

Instruction: call f24:proc x8:_ c24:nlocals

Call a procedure. proc is the local corresponding to a procedure. The two values below proc will be overwritten by the saved call frame data. The new frame will have space for nlocals locals: one for the procedure, and the rest for the arguments which should already have been pushed on.

When the call returns, execution proceeds with the next instruction. There may be any number of values on the return stack; the precise number can be had by subtracting the address of proc from the post-call sp.

Instruction: call-label f24:proc x8:_ c24:nlocals l32:label

Call a procedure in the same compilation unit.

This instruction is just like call, except that instead of dereferencing proc to find the call target, the call target is known to be at label, a signed 32-bit offset in 32-bit units from the current ip. Since proc is not dereferenced, it may be some other representation of the closure.

Instruction: tail-call c24:nlocals

Tail-call a procedure. Requires that the procedure and all of the arguments have already been shuffled into position. Will reset the frame to nlocals.

Instruction: tail-call-label c24:nlocals l32:label

Tail-call a known procedure. As call is to call-label, tail-call is to tail-call-label.

Instruction: tail-call/shuffle f24:from

Tail-call a procedure. The procedure should already be set to slot 0. The rest of the args are taken from the frame, starting at from, shuffled down to start at slot 0. This is part of the implementation of the call-with-values builtin.

Instruction: receive f12:dst f12:proc x8:_ c24:nlocals

Receive a single return value from a call whose procedure was in proc, asserting that the call actually returned at least one value. Afterwards, resets the frame to nlocals locals.

Instruction: receive-values f24:proc b1:allow-extra? x7:_ c24:nvalues

Receive a return of multiple values from a call whose procedure was in proc. If fewer than nvalues values were returned, signal an error. Unless allow-extra? is true, require that the number of return values equals nvalues exactly. After receive-values has run, the values can be copied down via mov, or used in place.

Instruction: return s24:src

Return a value.

Instruction: return-values c24:nlocals

Return a number of values from a call frame. This opcode corresponds to an application of values in tail position. As with tail calls, we expect that the values have already been shuffled down to a contiguous array starting at slot 1. If nlocals is nonzero, reset the frame to hold that number of locals. Note that a frame reset to 1 local returns 0 values.

Instruction: call/cc x24:_

Capture the current continuation, and tail-apply the procedure in local slot 1 to it. This instruction is part of the implementation of call/cc, and is not generated by the compiler.

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