Forth
The Forth words are defined in the toolbox as a preamble to the target program.
Most words are implemented as code words (actually macros), which insert Java byte code in line. Examples:
code: rot dup2_x1 pop pop ;
code: dup jdup ;
code: d+ dadd ;Note: Contrary to normal Forth code words, a code:-word can not be executed on its own.The smallest executable unit is the Forth colon (":")-word, which is implemented as a Java method.
A couple of words are implemented as methods of external classes in the Java library. Example:
static importMethod: max Math max ( int int -- int )
This preliminary set can be expanded as needed. The operators are defined in the toolbox in the target.
Integer: + - * / mod
Double: d+ d-
Integer: and or xor not << >> >>>
Long: andl orl
Integer: = <> != < <= >= >
Object: a= a<>
All types: =: +=
Examples 33 =: xx 10 += yy aaa 44 / =: bbb
The flow control words are implemented with the compiling word constructor of Holon. Example:
compiler: if
intp: >assembler ifeq 2 >mark ;compiler: then
intp: 2 >resolve ;
Numbers are compiled according to their size as either 8 bit bytes, 16 or 32 bit integer values. Forth double numbers (numbers with a dot) are compiled as 64 bit long values.
The numbers -1, 0, 1, 2, 3, 4 and 5 are stored as the corresponding Java byte code constants.
HolonJ implements a return stack for local storage in a method. The return stack is not needed for the execution of Forth words (methods), because execution is taken care of by the JVM. We use the return stack to implement do..loops and for intermediate storage.
The push operator depends on the type of the data value. i>r pushes an int, a>r pushes an object reference. r@ and r> recall the top value on the return stack, taking care of the type as well.