Internal - Internal implementation of the forth virtual machine
[Forth - Forth virtual machine]

Collaboration diagram for Internal - Internal implementation of the forth virtual machine:

Classes

class  WordHeader
 Representation of a forth word's header in the dictionary. More...
struct  Wordlist
 Representaion of a forth wordlist. More...
class  ForthVM
 Implementation of the forth virtual machine. More...

Defines

#define LITTLE_ENDIAN
#define CELLS(x)   ((CELL)(((CELL*)256)+(x))-(CELL)((CELL*)256))
#define CHARS(x)   ((CELL)(((CHAR*)256)+(x))-(CELL)((CHAR*)256))
#define SLASH_CELL(x)   ((CELL*)(256+(x))-((CELL*)256))
#define SLASH_CHAR(x)   ((CHAR*)(256+(x))-((CHAR*)256))
#define ALIGNED(x)   (((x)+CELLS(1)-1)&~(CELLS(1)-1))
#define XT_BRANCH(offset)   XT_PAREN_BRANCH,CELLS(offset)
#define XT_0BRANCH(offset)   XT_PAREN_0BRANCH,CELLS(offset)
#define LIT(x)   XT_PAREN_LITERAL,(CELL)x
#define XT_M_SLASH_MOD   (((-1)/2) ? (CELL)XT_FM_SLASH_MOD : (CELL)XT_SM_SLASH_REM)

Enumerations

enum  Exception
enum  ControlStackMarkers {
  ColonMagic = 12340,
  OrigMagic = 12341,
  DestMagic = 12342
}
enum  ForthXT {
  XT_STORE,
  XT_NUMBER_SIGN,
  XT_NUMBER_SIGN_GREATER,
  XT_STAR,
  XT_PLUS,
  XT_PLUS_STORE,
  XT_PAREN_PLUS_LOOP,
  XT_COMMA,
  XT_MINUS,
  XT_0_LESS,
  XT_0_EQUALS,
  XT_1_PLUS,
  XT_1_MINUS,
  XT_2_STORE,
  XT_2_STAR,
  XT_2_SLASH,
  XT_2_FETCH,
  XT_2DROP,
  XT_2DUP,
  XT_2OVER,
  XT_2SWAP,
  XT_LESS_THAN,
  XT_LESS_NUMBER_SIGN,
  XT_EQUALS,
  XT_GREATER_THAN,
  XT_TO_IN,
  XT_TO_NUMBER,
  XT_TO_R,
  XT_QUESTION_DUP,
  XT_FETCH,
  XT_ABS,
  XT_ACCEPT,
  XT_ALIGN,
  XT_ALIGNED,
  XT_ALLOT,
  XT_AND,
  XT_BASE,
  XT_C_STORE,
  XT_C_COMMA,
  XT_C_FETCH,
  XT_CELL_PLUS,
  XT_CELLS,
  XT_CHAR_PLUS,
  XT_CHARS,
  XT_PAREN_CONSTANT,
  XT_COUNT,
  XT_DEPTH,
  XT_PAREN_DO,
  XT_DROP,
  XT_DUP,
  XT_PAREN_BRANCH,
  XT_EMIT,
  XT_EXECUTE,
  XT_EXIT,
  XT_FILL,
  XT_HERE,
  XT_HOLD,
  XT_I,
  XT_PAREN_0BRANCH,
  XT_INVERT,
  XT_J,
  XT_KEY,
  XT_LEAVE,
  XT_PAREN_LITERAL,
  XT_PAREN_LOOP,
  XT_LSHIFT,
  XT_MAX,
  XT_MIN,
  XT_MOVE,
  XT_NEGATE,
  XT_OR,
  XT_OVER,
  XT_R_FROM,
  XT_R_FETCH,
  XT_ROT,
  XT_RSHIFT,
  XT_S_TO_D,
  XT_SIGN,
  XT_SPACE,
  XT_STATE,
  XT_SWAP,
  XT_TYPE,
  XT_U_LESS_THAN,
  XT_UM_STAR,
  XT_UNLOOP,
  XT_XOR,
  XT_LEFT_BRACKET,
  XT_RIGHT_BRACKET,
  XT_0_NOT_EQUALS,
  XT_0_GREATER,
  XT_2_TO_R,
  XT_2_R_FROM,
  XT_2_R_FETCH,
  XT_NOT_EQUALS,
  XT_PAREN_QUESTION_DO,
  XT_ERASE,
  XT_FALSE,
  XT_NIP,
  XT_PAD,
  XT_PARSE,
  XT_PICK,
  XT_ROLL,
  XT_TRUE,
  XT_TUCK,
  XT_U_GREATER_THAN,
  XT_UNUSED,
  XT_D_PLUS,
  XT_DABS,
  XT_DNEGATE,
  XT_M_PLUS,
  XT_CATCH,
  XT_THROW,
  XT_CMOVE,
  XT_CMOVE_UP
}

Functions

bool ForthVM::DoReset ()
CELL ForthVM::DoExecute (CELL xt)
CELL ForthVM::DoQuit ()
CELL ForthVM::DoEvaluate (const CHAR *text, unsigned textLength)
const CELLForthVM::DoPop (unsigned numCells)
void ForthVM::DoPush (const CELL *cells, unsigned numCells)
CELL ForthVM::Run (const CELL *ip)
CELL ForthVM::UncaughtException (CELL exceptionNumber)

Variables

static const CELL BitsPerCell = BITS_PER_CHAR*CHARS_PER_CELL
static const CELL CellLoMask = ((CELL)1<<(BitsPerCell/2))-1
static const CELL SlashCountedString = 255
static const CELL NameLengthMask = 31
static const CELL NumberTIB = 80
static const CELL SlashPad = 84
static const CELL DictionaryOverhead = CHARS(SlashCountedString+2+SlashPad)
static const CELL MaxWordlists = 16
static const CELL StackCells = 256
static const CELL ReturnStackCells = 256
static const CELL XT_NEST_CHECK []
static const CELL XT_FORWARD_BRANCH_COMMA []
static const CELL XT_BACKWARD_BRANCH_COMMA []
static const CELL XT_IF []
static const CELL XT_AHEAD []
static const CELL XT_THEN []
static const CELL XT_BEGIN []
static const CELL XT_AGAIN []
static const CELL XT_UM_SLASH_MOD []
static const CELL XT_CHECK_NEG []
static const CELL XT_CHECK_POS []
static const CELL XT_SM_SLASH_REM []
static const CELL XT_FM_SLASH_MOD []
static const CELL XT_SLASH_MOD []
static const CELL XT_M_STAR []
static const CELL XT_STAR_SLASH_MOD []
static const CELL XT_NUMBER_SIGN_S []
static const CELL XT_D_DOT []
static const CELL XT_DOT []
static const CELL XT_CR []
static const CELL XT_CREATE_WORD []
static const CELL XT_VALIDATE []
static const CELL XT_PAREN_CREATE []
static const CELL XT_CREATE []
static const CELL XT_PAREN_DOES []
static const CELL XT_LITERAL []
static const CELL XT_PAREN_S_QUOTE []
static const CELL XT_S_QUOTE []
static const CELL XT_CHAR []
static const CELL XT_PAREN_FIND []
static const CELL XT_THROW_QUOTE []
static const CELL XT_PAREN_TICK []
static const CELL XT_TICK []
static const CELL XT_TO_SIGN []
static const CELL XT_NUMBER_QUERY []
static const CELL XT_INTERPRET_WORD []
static const CELL XT_COMPILE_WORD []
static const CELL XT_INTERPRET []
static const CELL XT_EVALUATE []
static const CELL XT_REFILL_TIB []
static const CELL XT_REFILL []
static const CELL XT_DO_QUIT []
const CELL XT_EXCEPTION_DOT []
const CELL XT_QUIT []
static const CELL ForthDictionary []
static const CELL EnvironmentDictionary []

Detailed Description

Version:
2005-12-27
  • Fixed various bugs in Forth virtual machine which manifested when sizeof(CELL) was greater than sizeof(CELL*).
2007-01-13
  • Fixed GCC compilation warnings.
2007-05-28
2009-10-02
  • Fixed bug in the implemntation QUIT. The WHILE branch in XT_DO_QUIT was jumping one token to far, which would produce unpredicable results if REFILL returned false.
  • Updated the example class StdForthIo (mentioned in ForthIo), to use standard posix functions rather than Microsoft's conio.h.
  • Updated ForthVM::Accept to accept alternative keys for backspace (0x08 and 0x7F) and input end (0x0a and 0x0d).

Define Documentation

#define LITTLE_ENDIAN

Define this when compiling for a little endian target

Definition at line 59 of file forth.cpp.

#define CELLS (  )     ((CELL)(((CELL*)256)+(x))-(CELL)((CELL*)256))

Size of x cells in address untits.

Parameters:
x 

Definition at line 68 of file forth.cpp.

#define CHARS (  )     ((CELL)(((CHAR*)256)+(x))-(CELL)((CHAR*)256))

Size of x chars in address untits.

Parameters:
x 

Definition at line 74 of file forth.cpp.

#define SLASH_CELL (  )     ((CELL*)(256+(x))-((CELL*)256))

Number of cells in x address units.

Parameters:
x 

Definition at line 80 of file forth.cpp.

#define SLASH_CHAR (  )     ((CHAR*)(256+(x))-((CHAR*)256))

Number of chars in x address units.

Parameters:
x 

Definition at line 86 of file forth.cpp.

#define ALIGNED (  )     (((x)+CELLS(1)-1)&~(CELLS(1)-1))

Next aligned cell address equal or higher than address x.

Parameters:
x The address to align.

Definition at line 92 of file forth.cpp.

#define XT_BRANCH ( offset   )     XT_PAREN_BRANCH,CELLS(offset)

Macro for an unconditional branch. I.e. the execution sematics of AGAIN .

Parameters:
offset Offset, in cells, to the target of the branch. The xt following this branch has an offset of one.

Definition at line 402 of file forth.cpp.

#define XT_0BRANCH ( offset   )     XT_PAREN_0BRANCH,CELLS(offset)

Macro for an conditional branch. I.e. the execution sematics of IF .

Parameters:
offset Offset, in cells, to the target of the branch. The xt following this branch has an offset of one.

Definition at line 410 of file forth.cpp.

#define LIT (  )     XT_PAREN_LITERAL,(CELL)x

Macro for construction the execution semantics of LITERAL .

Parameters:
x The value which will be placed on the stack when these execution semantics are performed.

Definition at line 417 of file forth.cpp.

#define XT_M_SLASH_MOD   (((-1)/2) ? (CELL)XT_FM_SLASH_MOD : (CELL)XT_SM_SLASH_REM)

Definition of non standard forth word.

: M/MOD   ( d1 n1 -- n2 n3 )
    \ If the system uses floored division, execute FM/MOD
    \ otherwise execute SM/MOD
;

Definition at line 620 of file forth.cpp.


Enumeration Type Documentation

enum Exception

Exception values define by the ANS standard

Definition at line 204 of file forth.cpp.

Values placed on the control stack to indicate the type of control flow nesting value.

Enumerator:
ColonMagic 

colon-sys

OrigMagic 

orig

DestMagic 

dest

Definition at line 241 of file forth.cpp.

enum ForthXT

Enumeration of forth execution tokens.

Enumerator:
XT_STORE 

xt for ! ( x a-addr -- )

XT_NUMBER_SIGN 

xt for # ( ud1 -- ud2 )

XT_NUMBER_SIGN_GREATER 

xt for #> ( xd -- c-addr u )

XT_STAR 

xt for * ( n1|u1 n2|u2 -- n3|u3 )

XT_PLUS 

xt for + ( n1|u1 n2|u2 -- n3|u3 )

XT_PLUS_STORE 

xt for +! ( n|u a-addr -- )

XT_PAREN_PLUS_LOOP 

xt for runtime semantics of +LOOP ( n -- ) ( R: loop-sys1 -- | loop-sys2 )

XT_COMMA 

xt for , ( x -- )

XT_MINUS 

xt for - ( n1|u1 n2|u2 -- n3|u3 )

XT_0_LESS 

xt for 0< ( n -- flag )

XT_0_EQUALS 

xt for 0= ( x -- flag )

XT_1_PLUS 

xt for 1+ ( n1|u1 -- n2|u2 )

XT_1_MINUS 

xt for 1- ( n1|u1 -- n2|u2 )

XT_2_STORE 

xt for 2! ( x1 x2 a-addr -- )

XT_2_STAR 

xt for 2* ( x1 -- x2 )

XT_2_SLASH 

xt for 2/ ( x1 -- x2 )

XT_2_FETCH 

xt for 2@ ( a-addr -- x1 x2 )

XT_2DROP 

xt for 2DROP ( x1 x2 -- )

XT_2DUP 

xt for 2DUP ( x1 x2 -- x1 x2 x1 x2 )

XT_2OVER 

xt for 2OVER ( x1 x2 x3 x4 -- x1 x2 x3 x4 x1 x2 )

XT_2SWAP 

xt for 2SWAP ( x1 x2 x3 x4 -- x3 x4 x1 x2 )

XT_LESS_THAN 

xt for < ( n1 n2 -- flag )

XT_LESS_NUMBER_SIGN 

xt for <# ( -- )

XT_EQUALS 

xt for = ( x1 x2 -- flag )

XT_GREATER_THAN 

xt for > ( n1 n2 -- flag )

XT_TO_IN 

xt for >IN ( -- a-addr )

XT_TO_NUMBER 

xt for >NUMBER ( ud1 c-addr1 u1 -- ud2 c-addr2 u2 )

XT_TO_R 

xt for >R ( x -- ) ( R: -- x )

XT_QUESTION_DUP 

xt for ?DUP ( x -- 0 | x x )

XT_FETCH 

xt for @ ( a-addr -- x )

XT_ABS 

xt for ABS ( n -- u )

XT_ACCEPT 

xt for ACCEPT ( c-addr +n1 -- +n2 )

XT_ALIGN 

xt for ALIGN ( -- )

XT_ALIGNED 

xt for ALIGNED ( addr -- a-addr )

XT_ALLOT 

xt for ALLOT ( n -- )

XT_AND 

xt for AND ( x1 x2 -- x3 )

XT_BASE 

xt for BASE ( -- a-addr )

XT_C_STORE 

xt for C! ( char c-addr -- )

XT_C_COMMA 

xt for C, ( char -- )

XT_C_FETCH 

xt for C@ ( c-addr -- char )

XT_CELL_PLUS 

xt for CELL+ ( a-addr1 -- a-addr2 )

XT_CELLS 

xt for CELLS ( n1 -- n2 )

XT_CHAR_PLUS 

xt for CHAR+ ( c-addr1 -- c-addr2 )

XT_CHARS 

xt for CHARS ( n1 -- n2 )

XT_PAREN_CONSTANT 

xt for runtime semantics of words defined with CONSTANT ( -- x )

XT_COUNT 

xt for COUNT ( c-addr1 -- c-addr2 u )

XT_DEPTH 

xt for DEPTH ( -- +n )

XT_PAREN_DO 

xt for runtime semantics of DO ( n1|u1 n2|u2 -- ) ( R: -- loop-sys )

XT_DROP 

xt for DROP ( x -- )

XT_DUP 

xt for DUP ( x -- x x )

XT_PAREN_BRANCH 

xt for un-conditional branch as compiled by REPEAT ( -- )

XT_EMIT 

xt for EMIT ( x -- )

XT_EXECUTE 

xt for EXECUTE ( i*x xt -- j*x )

XT_EXIT 

xt for EXIT ( -- ) ( R: nest-sys -- )

XT_FILL 

xt for FILL ( c-addr u char -- )

XT_HERE 

xt for HERE ( -- addr )

XT_HOLD 

xt for HOLD ( char -- )

XT_I 

xt for I ( -- n|u ) ( R: loop-sys -- loop-sys )

XT_PAREN_0BRANCH 

xt for conditional branch as compiled by IF ( x -- )

XT_INVERT 

xt for INVERT ( x1 -- x2 )

XT_J 

xt for J ( -- n|u ) ( R: loop-sys1 loop-sys2 -- loop-sys1 loop-sys2 )

XT_KEY 

xt for KEY ( -- char )

XT_LEAVE 

xt for LEAVE ( -- ) ( R: loop-sys -- )

XT_PAREN_LITERAL 

xt for runtime semantics of LITERAL ( -- x )

XT_PAREN_LOOP 

xt for runtime semantics of LOOP ( -- ) ( R: loop-sys1 -- | loop-sys2 )

XT_LSHIFT 

xt for LSHIFT ( x1 u -- x2 )

XT_MAX 

xt for MAX ( n1 n2 -- n3 )

XT_MIN 

xt for MIN ( n1 n2 -- n3 )

XT_MOVE 

xt for MOVE ( addr1 addr2 u -- )

XT_NEGATE 

xt for NEGATE ( n1 -- n2 )

XT_OR 

xt for OR ( x1 x2 -- x3 )

XT_OVER 

xt for OVER ( x1 x2 -- x1 x2 x1 )

XT_R_FROM 

xt for R> ( -- x ) ( R: x -- )

XT_R_FETCH 

xt for R@ ( -- x ) ( R: x -- x )

XT_ROT 

xt for ROT ( x1 x2 x3 -- x2 x3 x1 )

XT_RSHIFT 

xt for RSHIFT ( x1 u -- x2 )

XT_S_TO_D 

xt for S>D ( n -- d )

XT_SIGN 

xt for SIGN ( n -- )

XT_SPACE 

xt for SPACE ( -- )

XT_STATE 

xt for STATE ( -- a-addr )

XT_SWAP 

xt for SWAP ( x1 x2 -- x2 x1 )

XT_TYPE 

xt for TYPE ( c-addr u -- )

XT_U_LESS_THAN 

xt for U< ( u1 u2 -- flag )

XT_UM_STAR 

xt for UM* ( u1 u2 -- ud )

XT_UNLOOP 

xt for UNLOOP ( -- ) ( R: loop-sys -- )

XT_XOR 

xt for XOR ( x1 x2 -- x3 )

XT_LEFT_BRACKET 

xt for [ ( -- )

XT_RIGHT_BRACKET 

xt for ] ( -- )

XT_0_NOT_EQUALS 

xt for 0<> ( x -- flag )

XT_0_GREATER 

xt for 0> ( x -- flag )

XT_2_TO_R 

xt for 2>R ( x1 x2 -- ) ( R: -- x1 x2 )

XT_2_R_FROM 

xt for 2R> ( -- x1 x2 ) ( R: x1 x2 -- )

XT_2_R_FETCH 

xt for 2R@ ( -- x1 x2 ) ( R: x1 x2 -- x1 x2 )

XT_NOT_EQUALS 

xt for <> ( x1 x2 -- flag )

XT_PAREN_QUESTION_DO 

xt for runtime semantics of ?DO ( n1|u1 n2|u2 -- ) ( R: -- | loop-sys )

XT_ERASE 

xt for ERASE ( addr u -- )

XT_FALSE 

xt for FALSE ( -- false )

XT_NIP 

xt for NIP ( x1 x2 -- x2 )

XT_PAD 

xt for PAD ( -- a-addr )

XT_PARSE 

xt for PARSE ( char "ccc<char>" -- c-addr u )

XT_PICK 

xt for PICK ( xu ... x1 x0 u -- xu ... x1 x0 xu )

XT_ROLL 

xt for ROLL ( xu xu-1 ... x0 u -- xu-1 ... x0 xu )

XT_TRUE 

xt for TRUE ( -- true )

XT_TUCK 

xt for TUCK ( x1 x2 -- x2 x1 x2 )

XT_U_GREATER_THAN 

xt for U> ( u1 u2 -- flag )

XT_UNUSED 

xt for UNUSED ( -- u )

XT_D_PLUS 

xt for D+ ( d1|ud1 d2|ud2 -- d3|ud3 )

XT_DABS 

xt for DABS ( d -- ud )

XT_DNEGATE 

xt for DNEGATE ( d1 -- d2 )

XT_M_PLUS 

xt for M+ ( d1|ud1 n -- d2|ud2 )

XT_CATCH 

xt for CATCH ( i*x xt -- j*x 0 | i*x n )

XT_THROW 

xt for THROW ( k*x n -- k*x | i*x n )

XT_CMOVE 

xt for CMOVE ( c-addr1 c-addr2 u -- )

XT_CMOVE_UP 

xt for CMOVE> ( c-addr1 c-addr2 u -- )

Definition at line 252 of file forth.cpp.


Function Documentation

bool ForthVM::DoReset (  )  [private, inherited]

Implementation of Forth::Reset

Definition at line 1764 of file forth.cpp.

CELL ForthVM::DoExecute ( CELL  xt  )  [private, inherited]

Implementation of Forth::Execute

Definition at line 1804 of file forth.cpp.

CELL ForthVM::DoQuit (  )  [private, inherited]

Implementation of Forth::Quit

Definition at line 1813 of file forth.cpp.

CELL ForthVM::DoEvaluate ( const CHAR text,
unsigned  textLength 
) [private, inherited]

Implementation of Forth::Evaluate

Definition at line 1819 of file forth.cpp.

const CELL * ForthVM::DoPop ( unsigned  numCells  )  [private, inherited]

Implementation of Forth::Pop

Definition at line 1829 of file forth.cpp.

void ForthVM::DoPush ( const CELL cells,
unsigned  numCells 
) [private, inherited]

Implementation of Forth::Push

Definition at line 1837 of file forth.cpp.

CELL ForthVM::Run ( const CELL ip  )  [private, inherited]

Execute forth code.

Parameters:
ip Pointer to the forth execution tokens to execute.
Returns:
Forth exception number or zero if code executed OK.

Definition at line 1856 of file forth.cpp.

CELL ForthVM::UncaughtException ( CELL  exceptionNumber  )  [private, inherited]

Called if there is not a CATCH for a THROW.

Parameters:
exceptionNumber Forth exception number
Returns:
exceptionNumber

Definition at line 2073 of file forth.cpp.


Variable Documentation

const CELL BitsPerCell = BITS_PER_CHAR*CHARS_PER_CELL [static]

Number of bits in a cell.

Definition at line 97 of file forth.cpp.

const CELL CellLoMask = ((CELL)1<<(BitsPerCell/2))-1 [static]

The mask value for the bits in the least significant half of a cell. I.e. x&CellLoMask will clear the bits on the most significant half of a cell.

Definition at line 103 of file forth.cpp.

const CELL SlashCountedString = 255 [static]

Maximum length of a counted string.

Definition at line 108 of file forth.cpp.

const CELL NameLengthMask = 31 [static]

Value to AND with the length of a words name length in order to remove any flag bits. This also represents the maximum length a word's name may have.

See also:
ForthVM::WordFlags

Definition at line 115 of file forth.cpp.

const CELL NumberTIB = 80 [static]

Size of the Terminal Input Buffer.

Definition at line 120 of file forth.cpp.

const CELL SlashPad = 84 [static]

Size of the PAD area.

Definition at line 125 of file forth.cpp.

The size of memory after HERE which is used for the transiant buffers used by pictured numeric output, PAD, and WORD.

Definition at line 131 of file forth.cpp.

const CELL MaxWordlists = 16 [static]

Maximum number of wordlists in the search order.

Definition at line 136 of file forth.cpp.

const CELL StackCells = 256 [static]

Size of parameter stack in cells.

Definition at line 141 of file forth.cpp.

const CELL ReturnStackCells = 256 [static]

Size of return stack in cells.

Definition at line 146 of file forth.cpp.

const CELL XT_NEST_CHECK[] [static]

Definition of non standard forth word.

: NEST-CHECK   ( C: x1 -- ) ( x2 -- )   \ Check control structure nesting value x1 equals x2.
   = IF EXIT THEN -22 THROW
;

Definition at line 425 of file forth.cpp.

const CELL XT_FORWARD_BRANCH_COMMA[] [static]

Definition of non standard forth word.

: >BRANCH,   ( C: -- orig ) ( xt -- )   \ Compile a forwards branch of type specified by xt.
    , HERE 0 , OrigMagic
;

Definition at line 437 of file forth.cpp.

const CELL XT_BACKWARD_BRANCH_COMMA[] [static]

Definition of non standard forth word.

: <BRANCH,   ( C: dest -- ) ( xt -- )   \ Compile a backwards branch of type specified by xt.
    , DestMagic NEST-CHECK HERE - ,
;

Definition at line 449 of file forth.cpp.

const CELL XT_IF[] [static]

Definition of ANS forth word.

: IF   ( C: -- orig )
    ['] (0branch) >BRANCH,
; IMMEDIATE

Definition at line 461 of file forth.cpp.

const CELL XT_AHEAD[] [static]

Definition of ANS forth word.

: AHEAD   ( C: -- orig )
    ['] (branch) >BRANCH,
; IMMEDIATE

Definition at line 473 of file forth.cpp.

const CELL XT_THEN[] [static]

Definition of ANS forth word.

: THEN   ( C: orig -- )
    OrigMagic NEST-CHECK
    HERE OVER - SWAP !
; IMMEDIATE

Definition at line 486 of file forth.cpp.

const CELL XT_BEGIN[] [static]

Definition of ANS forth word.

: BEGIN   ( C: -- dest )
    HERE DestMagic
; IMMEDIATE

Definition at line 498 of file forth.cpp.

const CELL XT_AGAIN[] [static]

Definition of ANS forth word.

: AGAIN   ( C: dest -- )
    ['] (branch) <BRANCH,
; IMMEDIATE

Definition at line 509 of file forth.cpp.

const CELL XT_UM_SLASH_MOD[] [static]

Definition of ANS forth word.

: UM/MOD   ( ud u1 -- u2 u3 )
    DUP 0= IF -10 THROW THEN
    UDM/MOD
    IF -11 THROW THEN
;

Definition at line 523 of file forth.cpp.

const CELL XT_CHECK_NEG[] [static]

Definition of non standard forth word.

: CHECK-NEG   ( n -- n )
    \ If n is greater than zero, throw -11 (result out of range)
    DUP 0> IF -11 THROW THEN
;

Definition at line 539 of file forth.cpp.

const CELL XT_CHECK_POS[] [static]

Definition of non standard forth word.

: CHECK-POS   ( n -- n )
    \ If n is less than zero, throw -11 (result out of range)
    DUP 0< IF -11 THROW THEN
;

Definition at line 552 of file forth.cpp.

const CELL XT_SM_SLASH_REM[] [static]

Definition of ANS forth word.

: SM/REM   ( d1 n1 -- n2 n3 )
    OVER >R 2DUP XOR >R
    ABS >R DABS R>
    UM/MOD
    R> 0<
    IF NEGATE CHECK-NEG
    ELSE CHECK-POS
    THEN
    SWAP R> 0< IF NEGATE THEN
    SWAP
;

Definition at line 572 of file forth.cpp.

const CELL XT_FM_SLASH_MOD[] [static]

Definition of ANS forth word.

: FM/MOD   ( d1 n1 -- n2 n3 )
    DUP >R 2DUP XOR >R
    ABS >R DABS R>
    UM/MOD
    R> 0<
    IF NEGATE CHECK-NEG OVER
        IF 1- CHECK-NEG R@ ABS ROT - SWAP
        THEN
    ELSE CHECK-POS
    THEN
    SWAP R> 0< IF NEGATE THEN SWAP
;

Definition at line 599 of file forth.cpp.

const CELL XT_SLASH_MOD[] [static]

Definition of ANS forth word.

: /MOD   ( n1 n2 -- n3 n4 )
    >R S>D R> M/MOD
;

Definition at line 628 of file forth.cpp.

const CELL XT_M_STAR[] [static]

Definition of ANS forth word.

: M*   ( n1 n2 -- d )
    2DUP XOR >R ABS SWAP ABS
    UM* R> 0< IF DNEGATE THEN
;

Definition at line 640 of file forth.cpp.

const CELL XT_STAR_SLASH_MOD[] [static]

Definition of ANS forth word.

: * /MOD   ( n1 n2 n3 -- n4 n5 )
    >R M* R> M/MOD
;

Definition at line 653 of file forth.cpp.

const CELL XT_NUMBER_SIGN_S[] [static]

Definition of ANS forth word.

: #S   ( ud1 -- ud2 )
    BEGIN # 2DUP OR 0= UNTIL
;

Definition at line 665 of file forth.cpp.

const CELL XT_D_DOT[] [static]

Definition of ANS forth word.

: D.   ( d -- )
    <# BL HOLD
    DUP >R DABS #S R> SIGN
    #> TYPE
;

Definition at line 679 of file forth.cpp.

const CELL XT_DOT[] [static]

Definition of ANS forth word.

: .   ( n -- )
    S>D D.
;

Definition at line 693 of file forth.cpp.

const CELL XT_CR[] [static]

Definition of ANS forth word.

: CR   ( -- )
    (cr) TYPE
;

Definition at line 704 of file forth.cpp.

const CELL XT_CREATE_WORD[] [static]

Definition of non standard forth word.

: CREATE-WORD   ( c-addr u -- )
    \ Create a dictionary entry for a word named by the string c-addr u.
    \ This entry cannot be found until VALIDATE is called.
    OVER 0<> OVER 0> INVERT AND IF -16 THROW THEN   \ check address and length are valid
    NameLengthMask MIN                              \ truncate name to maximum
    ALIGN HERE >R                                   \ get location to store word's header
    CURRENT @                                       \ get current wordlist
    DUP @ R@ - ,                                    \ write link field
    R@ SWAP !                                       \ update current wordlist
    DUP C,                                          \ write name length
    BEGIN DUP                                       \ write each character in name...
    WHILE OVER C@ C, SWAP CHAR+ SWAP 1-
    REPEAT
    2DROP ALIGN                                     \ tidy up
    R> LATEST !                                     \ update LATEST to point to new word
;

Definition at line 730 of file forth.cpp.

const CELL XT_VALIDATE[] [static]

Definition of non standard forth word.

: VALIDATE   ( -- )   \ Mark latest word as valid (findable).
    WordValid
    LATEST @ >FLAGS
    TUCK C@ OR SWAP C!
;

Definition at line 757 of file forth.cpp.

const CELL XT_PAREN_CREATE[] [static]

Definition of runtime semantics for words defined with ANS forth word CREATE

: (create)   ( -- a-addr )
    R>
;

Definition at line 773 of file forth.cpp.

const CELL XT_CREATE[] [static]

Definition of ANS forth word.

: CREATE   ( "<spaces>name" -- )
    PARSE-WORD CREATE-WORD POSTPONE (create) VALIDATE
;

Definition at line 784 of file forth.cpp.

const CELL XT_PAREN_DOES[] [static]

Definition of runtime semantics for ANS forth word DOES>

: (does>)   ( -- ) ( R: nest-sys1 -- )
    R> LATEST @ >CFA !
;

Definition at line 798 of file forth.cpp.

const CELL XT_LITERAL[] [static]

Definition of ANS forth word.

: LITERAL   ( x -- )
    ['] (literal) , ,
;

Definition at line 810 of file forth.cpp.

const CELL XT_PAREN_S_QUOTE[] [static]

Definition of runtime semantics for ANS forth word S

: (s)   ( -- c-addr u )
    R@ CELL+ R> @
    2DUP CHARS + ALIGNED >R
;

Definition at line 824 of file forth.cpp.

const CELL XT_S_QUOTE[] [static]

Definition of ANS forth word.

: S"   ( "ccc<quote>" -- )
    [CHAR] " PARSE
    POSTPONE (s)
    DUP ,
    HERE SWAP DUP CHARS ALLOT ALIGN CMOVE
;

Definition at line 840 of file forth.cpp.

const CELL XT_CHAR[] [static]

Definition of ANS forth word.

: CHAR   ( "<spaces>name" -- char )
    PARSE-WORD IF C@ EXIT THEN DROP FALSE
;

Definition at line 854 of file forth.cpp.

const CELL XT_PAREN_FIND[] [static]

Definition of non standard forth word.

: (find)   ( c-addr u -- xt flag header | c-addr u 0 )
    \ Find the defination named by the string c-addr u.
    \ If the definition is not found return c-addr u and zero.
    \ If the definition is found, return its execution token xt,
    \ a flag which is true if the word is immediate, and it's header address.
    CONTEXT @ 0                         \ loop through number of wordlists in CONTEXT
    DO
        CONTEXT I 1+ CELLS +            \ get pointer to next wordlist
        @ (search-wordlist)             \ search this wordlist
        ?DUP IF UNLOOP EXIT THEN        \ exit if found
    LOOP
    FALSE                               \ return FALSE for words not found
;

Definition at line 878 of file forth.cpp.

const CELL XT_THROW_QUOTE[] [static]

Definition of non standard forth word.

: THROW   ( c-addr u x -- )   \ Throw execption x with message string c-addr u
    >R EXCEPTION-MESSAGE 2! R> THROW
;

Definition at line 894 of file forth.cpp.

const CELL XT_PAREN_TICK[] [static]

Definition of non standard forth word.

: (')   ( "<spaces>name" -- xt immediate-flag )   \ Implementation factor for ' (tick).
    PARSE-WORD (find) IF EXIT THEN -13 THROW
;

Definition at line 906 of file forth.cpp.

const CELL XT_TICK[] [static]

Definition of ANS forth word.

: '   ( "<spaces>name" -- xt )
    (') DROP
;

Definition at line 919 of file forth.cpp.

const CELL XT_TO_SIGN[] [static]

Definition of non standard forth word.

: >SIGN   ( c-addr1 u1 -- c-addr2 u2 true | c-addr1 u1 false )
   \ If the string specified by c-addr1 u1 begings with a minus sign
   \ then adjust string to remove it and return true,
   \ else return then original string and false.
   DUP 0= IF FALSE EXIT THEN
   OVER C@ [CHAR] - =
   IF SWAP CHAR+ SWAP 1- TRUE EXIT THEN FALSE
;

Definition at line 937 of file forth.cpp.

const CELL XT_NUMBER_QUERY[] [static]

Definition of non standard forth word.

: NUMBER?   ( c-addr1 u1 -- d 2 | n 1 | 0 )
    \ Convert the string specified by c-addr1 u1 into a number.
    \ Return d and 2 if the number is a double number,
    \ return n and 1 if the number is a single number;
    \ otherwise return zero.
    >SIGN >R                                \ check for leading minus sign
    0 0 2SWAP >NUMBER 2SWAP                 \ convert string to a number
    R> IF DNEGATE THEN                      \ apply sign to number
    2SWAP DUP 0=                            \ all of string converted?
    IF 2DROP DROP 1 EXIT THEN               \ return a single cell number
    1 = SWAP C@ [CHAR] . = AND              \ remainder of string is a single decimal point?
    IF 2 EXIT THEN                          \ return a double cell number
    2DROP 0                                 \ not a number, so return 0
;

Definition at line 964 of file forth.cpp.

const CELL XT_INTERPRET_WORD[] [static]

Definition of non standard forth word.

: INTERPRET-WORD   ( c-addr u -- i*x | d | n )
    \ Find the defination named by the string c-addr u.
    \ If the definition is found, perform it's execution semantics,
    \ i*x represents the results of this.
    \ If the definition is not found, convert c-addr u into a number.
    \ If the number is valid double number, leave its value d on the stack.
    \ If the number is valid single number, leave its value n on the stack.
    \ If the number isn't valid, throw exception -13.
    (find)                          \ search dictionary for the word
    IF DROP EXECUTE EXIT THEN       \ if found, execute it and end
    2DUP 2>R                        \ save string
    NUMBER?                         \ convert string into a number
    IF                              \ if it is a valid number
        R> DROP R> DROP             \   discard saved string
        EXIT                        \   leave number's value on stack and end
    THEN
    2R> -13 THROW                   \ throw -13 (with string on top of stack)
;

Definition at line 1000 of file forth.cpp.

const CELL XT_COMPILE_WORD[] [static]

Definition of non standard forth word.

: COMPILE-WORD   ( c-addr u -- i*x | )
    \ Find the defination named by the string c-addr u.
    \ If the definition is found, then if the word is immediate perform it's
    \ execution semantics, i*x represents the results of this. If the word
    \ isn't immediate, append it's execution semantics to the current definition.
    \ If the definition is not found, convert c-addr u into a number.
    \ If the number is valid single or double number, append code to the current
    \ definition which when executed will leave the number's value on the stack.
    \ If the number isn't valid, throw exception -13.
    (find)                                  \ search dictionary for the word
    IF                                      \ if found
        IF                                  \   and it's immediate,
            EXECUTE EXIT                    \     then execute it and end
        THEN                                \   else
        , EXIT                              \     compile it and end
    THEN
    2DUP 2>R                                \ save string
    NUMBER? DUP                             \ convert string into a number
    IF                                      \ if it is a valid number
        R> DROP R> DROP                     \   discard saved string
        1- IF SWAP POSTPONE LITERAL THEN    \   compile number as a literal...
        POSTPONE LITERAL EXIT
    THEN
    2R> -13 THROW                           \ throw -13 (with string on top of stack)
;

Definition at line 1040 of file forth.cpp.

const CELL XT_INTERPRET[] [static]

Definition of non standard forth word.

: INTERPRET   ( -- i*x)   \ Interpret the current input, i*x is the result of this
    BEGIN
        PARSE-WORD DUP                  \ get a word from the input
    WHILE                               \ while there is a word
        STATE @                         \   if in compile state
        IF COMPILE-WORD                 \   compile the word
        ELSE INTERPRET-WORD             \   else interpret the word
        THEN
    REPEAT                              \ get next word
    2DROP                               \ discard empty word and end
;

Definition at line 1067 of file forth.cpp.

const CELL XT_EVALUATE[] [static]

Definition of ANS forth word.

: EVALUATE   ( i*x c-addr u -- j*x )
    (source) 2@ 2>R >IN 2@ 2>R
    (source) 2! -1 0 >IN 2!
	' INTERPRET CATCH
    2R> >IN 2! 2R> (source) 2!
	THROW
;

Definition at line 1086 of file forth.cpp.

const CELL XT_REFILL_TIB[] [static]

Definition of non standard forth word.

: REFILL-TIB   ( -- true )
    \ Refill the terminal input buffer (TIB)
    \ and make it the current input source.
    TIB DUP /TIB ACCEPT SPACE   \ get input from terminal
    (source) 2!                 \ make SOURCE point to TIB
    0 >IN ! TRUE                \ set >IN to zero
;

Definition at line 1110 of file forth.cpp.

const CELL XT_REFILL[] [static]

Definition of ANS forth word.

: REFILL   ( -- flag )
    \ Attempt to fill the input buffer from the input source,
    \ returning a true flag if successful.
    >IN CELL+ @ 0=              \ if input source is 0
    IF REFILL-TIB EXIT THEN     \ get input from terminal and return true
    FALSE                       \ otherwise, return false
;

Definition at line 1129 of file forth.cpp.

const CELL XT_DO_QUIT[] [static]

Definition of non standard forth word.

: DO-QUIT   ( -- )  ( R:  i*x -- )
    EMPTYR
    0 >IN CELL+ !   \ set SOURCE-ID to 0
    POSTPONE [
    BEGIN
        REFILL
    WHILE
        INTERPRET
        STATE @ 0= IF ."  OK" THEN
        CR
    REPEAT
;

Definition at line 1151 of file forth.cpp.

Definition of ANS forth word.

: EXCEPTION.   ( n -- n )
    DUP -1 =
    IF ." ABORT" EXIT THEN         // Print 'ABORT', and end
    DUP -2 =
    IF EXCEPTION-STRING 2@ TYPE EXIT THEN  // Print exception message, and end
    DUP -13 =
    IF
        EXCEPTION-STRING 2@ TYPE   // Print word name
        SPACE [CHAR] ? EMIT EXIT   // followed by " ?", then end
    THEN
    ." Exception" DUP .            // Print "Exception n", then end
;

Definition at line 1180 of file forth.cpp.

const CELL XT_QUIT[]

Definition of ANS forth word.

: QUIT   ( i*x n -- )
	BEGIN
		EMPTYR  ['] DO-QUIT CATCH
		EXCEPTION. CR
	AGAIN
;

Definition at line 1205 of file forth.cpp.

const CELL ForthDictionary[] [static]

Initial contents for FORTH dictionary

Definition at line 1280 of file forth.cpp.

const CELL EnvironmentDictionary[] [static]

Initial contents for ENVIRONMENT dictionary

Definition at line 1576 of file forth.cpp.


Generated by  doxygen 1.6.1