HolonJ Forth
Using HolonJ
Clock
Tic Tac Toe

Classes
Methods
Parameter
Variables
Forth
Flow Control
Compiler
Libraries
Constructors
Exception

Forth

The Forth words are defined in the toolbox as a preamble to the target program. 

Standard Forth words

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 )

 

Operators

This preliminary set can be expanded as needed. The operators are defined in the toolbox in the target.

Arithmetic 

Integer: +   -   *   /   mod  
Double: d+   d-

Logic and binary 

Integer:  and  or  xor  not   <<   >>    >>>
Long:  andl  orl

Comparison

Integer:    =  <>  !=   <   <=  >=  >      
Object:    a=  a<>    

Assignment

All types:    =:   +=

Examples    33 =: xx     10 += yy     aaa 44 / =: bbb

 

Flow control structures

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  ;

Literals

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.

Return stack

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.

next