Artifact ID: | e9fac2e80c410d5a1500d68653a52c9f2da63ea0 |
---|---|
Page Name: | Program instructions |
Date: | 2018-04-07 20:46:58 |
Original User: | zzo38 |
Parent: | 518554159fe770dca69116a0ddbdfae73c6f86dd (diff) |
(Note: This may change as the program is being written and it is currently a draft.)
In some places in a .class file, program instructions can be used. This includes in any global message block, class message block, SUBS block, Goal block, or global function definition.
The heading includes the instruction name (if in parentheses, it takes other stuff inside of the same block with parentheses; there may be brackets afterward if some other name or number is a part of it), followed by the stack effect (given in a notation like Forth).
Some headings include , and/or = after the stack diagram if it supports those prefixes optionally. In this case, , means a variable of another object (taken on the stack below the value, if writing), while = means to write instead of read (the value to write is taken below another argument if any, but above the object if any). If the heading says ,c then you can also read the value from a class (it is read-only in this case; the syntax does not change).
You can also use numbers as instructions (that push their value to the stack), either in decimal or in hexadecimal (with 0x at first), and an optional minus sign is allowed at first for negative decimal numbers. Built-in message names can also be used as instructions, pushing it to the stack..
. ( x -- )
Simply discards one value from data stack.$[] ( -- class )
Push a class name to the stack. The class must be defined, although it does not necessarily have to be defined above where it is mentioned.#[] ( -- message )
Push a message name to the stack. The message does not have to be declared anywhere. If there are no message handlers, sending this message to any object will just result in zero.%[] ( -- value ) =
Read a user variable of this object. All user variables are initialized to zero and can store any value. You do not need to declare them first."[]" ( -- string )
Push a string to the stack. The string can include escape codes:- \\ - Represents a literal backslash.
- \" - Represents a literal quotation mark.
- \0 - Set text colour to black.
- \1 - Set text colour to blue.
- \2 - Set text colour to green.
- \3 - Set text colour to cyan.
- \4 - Set text colour to red.
- \5 - Set text colour to purple.
- \6 - Set text colour to yellow.
- \7 - Set text colour to white.
- \b - Draw a horizontal line.
- \c - Centre alignment.
- \i - Follow by a class name (without $ at front), a colon, a image number, and then another backslash. Draws that picture.
- \l - Left alignment.
- \n - Line break.
- \q - Quiz button; follow by a single character specifying what key code is emitted when it is clicked (you can also push the keys directly, even if there is no corresponding quiz button). If this escape code is present, then a KEY message is sent to the object that displayed this string.
- \x - Follow by two hex digits to represent that character code.
The string can also include directives:
- %% - Represents a literal percentage sign.
- %c - A single character (by 8-bit character code)
- %d - Signed decimal number
- %i - A picture (given a class and image number)
- %n - A representation of the value (a class, message, or object)
- %u - Unsigned decimal number
- %x - Hexadecimal number
The directives can optionally have a minimum field width and/or a "0" flag.