Exceptions

Disassembly


Disasm(code);


This disassembles code, showing its bytecodes. Note that this function only works if code has been compiled for debugging. For a brief description of the bytecodes, see TABLE 8.3. Some of the operations of NewtonScript are not bytecodes, but are primitive functions, which the interpreter calls when it finds them. These primitive functions appear in a disassembly as shown in TABLE 8.4.

Here is a NewtonScript function and its disassembly:

func()
begin
   local localInD := ["one", 6, 52];
   Print(localInD[3]);
end
Disasm(GetCurrentFunction(0))
    0: Push                 "one"
    1: PushConstant         6
    4: PushConstant         52
    7: Push                 'Array
    8: MakeArray            3
    9: SetVar               localInD
   10: GetVar               localInD
   11: PushConstant         3
   14: ARef                 2
   15: Push                 'Print
   16: Call                 1
   17: Return
Bytecodes in NewtonScript virtual machine.
Bytecodes
PopPop the top element from the stack (discard the value).
PushSelfPush the current message context on the interpreter stack.
Push <X>Push the nonimmediate value <X> on the top of the stack.
PushConstant <X>Push the immediate value described by <X> on the stack.
FindVar <X>Look for the variable <X> using both the inherited lexical context and the current message context (self), including _proto and _parent inheritance, and push it on the stack.
GetVar <X>Get the parameter or local <X> (which is located at a particular offset in the current lexical scope) and push it on the stack.
MakeFrame <N>Frame constructor. Using the frame map (an array of symbols) found on the top of the stack, make a frame using the next <N> elements of the stack (in bottom-up order) to fill the frame slots. That frame is pushed on the stack.
MakeArray <N>Array constructor. Make an array of the class of the top element of the stack, using the next <N> elements of the stack (in bottom-up order) to populate the array. The resulting array is pushed on the stack.
GetPath <N>Look for the slot on the top of the stack in the frame that's second on the stack, using _proto inheritance only.
SetPath <N>Take the value on the top of the stack; assign it to the slot that's second on the stack in the frame that's third on the stack.
SetVar <N> [<X>]Assign the value on the top of the stack to the local or parameter that's at offset <N> in the current lexical scope. <X> is the name of this variable or parameter.
SetFindVar <X>Inherited variable assignment. Assign the value on the top of the stack to the variable that's second on the stack, using FindVar (see above) to locate that variable.
SetLexScopeSet the lexical scope (inherited locals and params) of the thing on the top of the stack to the currently executing function.
ReturnReturn from the function. Top of stack contains result of function.
Branch <I>Goto the instruction at <I>.
BranchT <I>If the top of the stack is non-nil, jump to instruction <I>.
BranchF<I>If the top of the stack is nil, jump to instruction <I>.
IncrVar <N>Increment the loop variable found at offset <N> into the current lexical scope by the amount at the top of the stack, pushing the result. This one's weird in that it doesn't pop the top of the stack (the increment) when using it.
BranchIfLoopNotDone <I>Using the top three elements of the stack as the current loop variable, the loop limit, and the loop increment, determine if the loop is complete. If not, branch to <I>.
NewHandlers <N>Register the top <N> pairs of elements on the stack as exception handlers for the currently executing function. Within each pair of items, the second (lower) is the exception symbol, and the first (higher) is the instruction number to jump to in order to process that exception.
PopHandlersPop one set of exception handlers (see NewHandlers <N>).
IterNextIncrement array/frame iterator.
IterDoneTest to see if an array/frame iterator is complete; push result of test on the stack.
Call <N>Execute global function (symbol for which is on top of stack), passing <N> elements below that on the stack as arguments.
Invoke <N>Execute a function on the top of the stack using its message context, passing the next <N> stack elements as arguments.
Send <N>Send the message on the top of the stack to the receiver that's second on the stack, passing the next <N> elements of the stack as arguments.
SendIfDefined <N>Like Send <N>, but it is not an error if the function can't be found.
Resend <N>inherited: Send the message on the top of the stack to the current message context, but start looking for the actual function to invoke after the implementor of the function currently executing. Pass the next <N> things on the stack as arguments.
ResendIfDefined <N>inherited:? Works like Resend<N>, but it is not an error if the function can't be found.
Primitive functions.
NameEffect
+
-
*
/
Div
=
<>
<
>
<=
>=
Evaluates firstOnStack operator secondOnStack.
notEvaluates not firstOnStack.
ARefDereference array or string on top of the stack using the second element on the stack as an index.
NewIteratorCreates an iterator object as used in foreach loops.
AddArraySlot
BAnd
BOr
HasPath
SetClass
Evaluates Function(secondOnStack, firstOnStack).
BNot
ClassOf
Clone
Length
Stringer
Evaluates Function(firstOnStack).


An online version of Programming for the Newton using Macintosh, 2nd ed. ©1996, 1994, Julie McKeehan and Neil Rhodes.

Last modified: 1 DEC 1996