The Stack Machine Language
Code for the stack machine is written in a specialized assembler. The
following description is written in the syntax appropriate for the
scheme side of the interface.
General notes
Arithmetic operations on 2D and 3D vectors are not included, because
they will be broken down into 1D operations by the compiler.
Except where indicated, operations do not need to check whether their
inputs are missing.
This list does not include operations required by the scheme-icp
interface but not in the code for user-defined functions. So, for
example, a function for pushing sheets onto the stack may be required
by the scheme-icp interface, but the compiler never needs to generate
a PUSH-SHEET instruction.
Types
The following types of objects can be pushed onto the stack:
- real points
- integer points
- booleans
- sheets
- samples
The stack can also contain missing real points and missing integer points.
Booleans, sheets, and samples cannot be missing.
Control structure
- CALL k
-
Calls the coprocessor function whose ID number is k (an integer).
The inputs to the function should lie at the top of the stack.
The function will replaces them with its outputs.
- RETURN
- Copy the return values from the top of the stack
to just above the frame pointer, then return from the function.
The call/return mechanism is supposed to know how many bytes to
move in this case.
- NOT
-
Expects a boolean to be at the top of the stack. Negates it, leaving the
result on the top of the stack.
- JUMP k
- Jump (unconditionally) to line number k
- JUMP-IF-FALSE k
- Expects a boolean to be at the top of the stack. Removes the boolean.
Jumps to line number k if the boolean is false.
- JUMP-IF-TRUE k
- Expects a boolean to be at the top of the stack. Removes the boolean.
Jumps to line number k if the boolean is false.
- GUARD-ONE-INTEGER k
- Expects an integer to be on the top of the stack. If the integer
is missing, jump to line number k. The integer is left on the stack.
This is used to "guard" an unary arithmetic operation which will be
carried out by the next instruction or the next few instructions.
- GUARD-ONE-REAL k
- Expects a real to be on the top of the stack. If the real
is missing, jump to line number k. The real is left on the stack.
- GUARD-TWO-INTEGERS k
- Expects two integers to be on the top of the stack. If either integer
is missing, replace them with one missing integer and
jump to line number k. Otherwise do nothing.
This is used to "guard" a binary arithmetic operation which will be
carried out by the next instruction or the next few instructions.
- GUARD-TWO-REALS k
- Similar, but for reals.
- GUARD-THREE-INTEGERS k, GUARD-THREE-REALS k
- Similar, but for 3 values on the stack
- ERROR k
- Unconditionally generates run-time error number k (an integer).
The error messages corresponding to different error arguments are as
follows:
- 0 = an expect form turned out to be false
- 1 = missing inputs passed to a form that can't handle them (e.g. <)
- 2 = attempt to access a non-grid location
- 3 = point-coordinate given a dimension out of range
- [any other number] = unspecified run-time error
Storage
- ADD-SPACE k
- Increments the stack pointer by k bytes (e.g. to reserve space for
local variables).
- PUSH-INTEGER k
- Pushes the 1D integer point k onto the stack
- PUSH-REAL x
- Pushes the 1D real point x onto the stack.
- PUSH-TRUE, PUSH-FALSE
- Push the appropriate binary constant onto the stack.
- POP-SHEET, POP-REAL, POP-INTEGER, POP-SAMPLE, POP-BOOLEAN
- Pops an object from the top of the stack and drops it on the floor.
- MAKE-MISSING-REAL, MAKE-MISSING-INTEGER
- Create a missing object of the appropriate type and push it onto the stack.
- SET-SHEET k
- Moves a sheet from the top of the stack to the location k bytes above the
frame pointer.
- SET-REAL, SET-INTEGER, SET-BOOLEAN, SET-SAMPLE,
- Similar
- GET-SHEET k
- Gets a sheet from the location k bytes above the
frame pointer and puts it on the top of the stack.
- GET-REAL, GET-INTEGER, GET-BOOLEAN, GET-SAMPLE
- Similar
Structure assembly and disassembly
- MAKE-REAL-POINT-2D
- Expects two 1D real points at the top of the stack. Replaces them with
one 2D real point.
- MAKE-REAL-POINT-3D, MAKE-INTEGER-POINT-2D, MAKE-INTEGER-POINT-3D
- Similar.
- INTEGER-POINT-COORDINATE
- Expects a 1D integer point (j) on the top of the stack and an integer
point (p) right below it.
Replaces them with a 1D integer point made from p's jth coordinate.
Can assume that j is known to be in the right range.
- REAL-POINT-COORDINATE
- Expects a 1D integer point (j) on the top of the stack and a real
point (p) right below it.
Replaces them with a 1D real point made from p's jth coordinate.
Can assume that j is known to be in the right range.
- INTEGER-SHEET-REF
- Expects an integer point at the top of the stack and a sheet right below it.
Replaces them with the result of the reference.
- REAL-SHEET-REF
- Expects a real point at the top of the stack and a sheet right below it.
Replaces them with the result of the reference.
- UNSCALED-SHEET-SET!
- Expects two integer points at the top of the stack, with a sheet right
below them. Does the sheet set and removes all three objects.
- SHEET-DOMAIN-SCALING-REAL, SHEET-DOMAIN-SCALING-INTEGER
- Expects a sheet at the top of the stack. Replaces it with the
corresponding scaling number.
- SHEET-CODOMAIN-SCALING-REAL, SHEET-CODOMAIN-SCALING-INTEGER
- Similar
- SHEET-DOMAIN-OFFSET-REAL, SHEET-DOMAIN-OFFSET-INTEGER
- Expects a sheet at the top of the stack. Replaces it with the
corresponding offset number.
- SHEET-CODOMAIN-OFFSET-REAL, SHEET-CODOMAIN-OFFSET-INTEGER
- Similar
- SHEET-MIN-SAMPLE, SHEET-MAX-SAMPLE
- Expects a sheet at the top of the stack. Replaces it with the
appropriate sample.
- FOCUS-MIN-SAMPLE, FOCUS-MAX-SAMPLE
- Expects a sheet at the top of the stack. Replaces it with the
appropriate sample.
- SAMPLE->SHEET, SAMPLE-UNSCALED-POINT
- Expects a sample at the top of the stack. Replaces it with the
appropriate one of its components.
- MAKE-SAMPLE
- Expects a point at the top of the stack and a sheet right below it.
Replaces them with a newly created sample.
Type Coercion
- INEXACT-TO-EXACT
- Expects a 1D real point at the top of the stack. Replaces it with the
nearest 1D integer point.
- EXACT-TO-INEXACT
- Expects a 1D integer point at the top of the stack. Replaces it with the
corresponding 1D real point.
Missing objects
- MISSING-INTEGER
- Expects an integer to be on the top of the stack. If the integer
is missing, replace it with TRUE. Otherwise, replace it with FALSE.
- MISSING-REAL
- Similar, but for reals.
Numerical tests
- INTEGER-=
- Expects two integers on the top of the stack. Replaces them with
the appropriate boolean.
- INTEGER-<, INTEGER-<=, INTEGER->, INTEGER->=
- Similar.
- REAL-<
- Expects two reals on the top of the stack. Replaces them with
the appropriate boolean.
- REAL-<=, REAL->, REAL->=
- Similar.
REAL ARITHMETIC OPERATIONS
The following operations expect one real on the top of the stack. They
replace it with one real.
- LOG, EXP, SQRT
- SIN, COS, TAN, ASIN, ACOS, UNARY-ATAN
- FLOOR, CEILING, ROUND, TRUNCATE
- REAL-UNARY-MINUS
- REAL-ABS
The following expect two reals on the top of the stack. They replace them
with one real.
- RANDOM-REAL, BINARY-ATAN, EXPT, DIVIDE
- REAL-MIN, REAL-MAX
- REAL-+, REAL-MINUS, REAL-*
These operations must check the following conditions and return a
missing value in these cases:
- both of binary-atan's inputs are zero
- the input to log is zero or negative
- the input to sqrt is negative
- the input to asin or acos is outside the range [-1,1]
- the first input to random-real is greater than the second
- expt: either the first input is zero and the second is negative,
or the first input is negative and the second input is not an integer
- the second input to divide is zero
Integer arithmetic operations
The following function expects an integer at the top of the stack and
replace it with another integer.
- INTEGER-UNARY-MINUS
- INTEGER-ABS
- BITWISE-NOT
The following functions expect two integers at the top of the stack and
replace them with a single integer.
- BITWISE-AND, BITWISE-IOR, BITWISE-XOR, ARITHMETIC-SHIFT
- REMAINDER, QUOTIENT, MODULO
- INTEGER-MIN, INTEGER-MAX
- INTEGER-+, INTEGER-MINUS, INTEGER-*
These operations must check the following conditions and return a
missing value in these cases:
- the second input to remainder, quotient or modulo is zero
Ownership, Maintenance and Disclaimers
Manual Top Page
Last modified