WFROTH glossary

This chapter groups the wfroth definitions according to their purpose. You can use this chapter to determine which definitions you may need to perform a task.
 

Last update:

07-February-1999

State (estimation)

50%


This chapter includes the following sections:


Categories

The following categories have been used to group the definitions:

 

Definitions arranged by category

Parameters Stack

Definition 

Stack 

Description 

sp!

( ... --- )

Reset the parameters stack, i.e. discard all values from the stack.

depth

( --- n )

Return the number of parameters on the stack (prior to call depth).

drop 

( n --- )

Discard the value from the top of the stack. 

dup 

( n --- n n )

Duplicate the value on the top of the stack.

over

( n1 n2 --- n1 n2 n1 )

Duplicate the value under the top of the stack.

above

pluck

( n1 n2 n3 --- n1 n2 n3 n1 )

Duplicate the value under-under the top of the stack.

pick

( n1 --- n2 )

Duplicate the n-th value under the top of the stack.

swap

( n1 n2 --- n2 n1 )

Swap (permute) the two values on top of the stack.

under

nip

( n1 n2 --- n2 )

Discard the value under the top of the stack.

below

( n1 n2 n3 --- n2 n3 )

Discard the value under-under the top of the stack.

rot

( n1 n2 n3 --- n2 n3 n1 )

Rotate the 3 values on top of the stack.

-rot

( n1 n2 n3 --- n3 n1 n2 )

Rotate the 3 values on top of the stack.

tuck

( n1 n2 --- n2 n1 n2 )

Make a swap then over

ddrop 

2drop

( n1 n2 --- )

Discard the 2 values from the top of the stack. 

ddup 

2dup

( n1 n2 --- n1 n2 n1 n2 )

Duplicate the 2 values on the top of the stack.

 

Return Stack

 

Definition

Parameters Stack 

Return Stack

Description 

rp!

( --- )

( ... --- )

Reset the return stack, i.e. discard all values on the return stack.

>r

( n --- )

( --- n )

Push a value to the return stack.

r> 

( --- n )

( n --- )

Pop a value from the return stack. 

I

( --- n )

( n --- n )

Copy the value from the top of the return stack.

 

Integer Arithmetic

Definition 

Stack 

Operation 

Description 

negate 

( n1 --- n2 )

n2 = -n1

Negate the top stack value.

( n1 n2 --- n3 )

n3 = n1+n2

Add the values on top of stack.

1+ 

( n1 --- n2 )

n2 = n1+1

Add 1 to the value on top of stack.

2+ 

( n1 --- n2 )

n2 = n1+2

Add 2 to the value on top of stack.

( n1 n2 --- n3 )

n3 = n1-n2

Sub the values on top of stack.

1-

( n1 --- n2 )

n2 = n1-1

Sub 1 to the value on top of stack.

2-

( n1 --- n2 )

n2 = n1-2

Sub 2 to the value on top of stack.

*

( n1 n2 --- n3 )

n3 = n1*n2

Multiply the values on top of stack.

/

( n1 n2 --- n3 )

n3 = n1/n2

Integer division of the values on top of stack.

/mod

( n1 n2 --- n3 n4 )

n3 = n1%n2
n4 = n1/n2

Discard the value under the top of the stack.

mod

( n1 n2 --- n3 )

n3 = n1%n2

Modulo operation.

rnd

( n1 n2 --- n3 )

n3 = [n1..n2]

Return a random number between n1 and n2.

 

Logical

Definition 

Stack 

Operation 

Description 

true 

( --- tf )

 

Push logical true value on stack.

false

( --- ff )

 

Push logical false value on stack.

== 

=

( n1 n2 --- f )

f = (n1==n2) ? TRUE : FALSE

Return a logical value which is true if the given condition 
for the two top stack values are true.

!= 

<>

( n1 n2 --- f )

f = (n1!=n2) ? TRUE : FALSE

Return a logical value which is true if the given condition 
for the two top stack values are true.

not 

0==

0=

( f1 --- f2 )

f2 = (f1) ? FALSE : TRUE

Return a boolean flag which is the 'reverse' value.

<

( n1 n2 --- f )

f = (n1<n2) ? TRUE : FALSE

Return a logical value which is true if the given condition 
for the two top stack values are true.

<=

( n1 n2 --- f )

f = (n1<=n2) ? TRUE : FALSE

Return a logical value which is true if the given condition 
for the two top stack values are true.

>

( n1 n2 --- f )

f = (n1>n2) ? TRUE : FALSE

Return a logical value which is true if the given condition 
for the two top stack values are true.

>=

( n1 n2 --- f )

f = (n1>=n2) ? TRUE : FALSE

Return a logical value which is true if the given condition 
for the two top stack values are true.

U<

( u1 u2 --- f )

f = (u1<u2) ? TRUE : FALSE

Return a logical value which is true if the given condition 
for the two top stack values are true.

U<=

( n1 n2 --- f )

f = (u1<=u2) ? TRUE : FALSE

Return a logical value which is true if the given condition 
for the two top stack values are true.

U>

( u1 u2 --- f )

f = (u1>u2) ? TRUE : FALSE

Return a logical value which is true if the given condition 
for the two top stack values are true.

U>=

( u1 u2 --- f )

f = (u1>=u2) ? TRUE : FALSE

Return a logical value which is true if the given condition 
for the two top stack values are true.

and

( n1 n2 --- n3 )

n3 = n1 & n2

Perform a AND logical (bit) operation between the 2 top stack values.

or

( n1 n2 --- n3 )

n3 = n1 | n2

Perform a OR logical (bit) operation between the 2 top stack values.

xor

( n1 n2 --- n3 )

n3 = n1 ^ n2

Perform a XOR logical (bit) operation between the 2 top stack values.

shl

( n1 n2 --- n3 )

n3 = n1 << n2

Perform a left shift logical (bit) operation.

shr

( n1 n2 --- n3 )

n3 = n1 >> n2

Perform a right shift logical (bit) operation.

 

Control Structures

Definition 

Model 

Description 

Example 

begin

again

until

while

repeat

?break

?continue

BEGIN 

...
[?BREAK][?CONTINUE]
...

AGAIN

 

BEGIN 

...
[?BREAK][?CONTINUE]
...

<f> UNTIL

 

BEGIN 

...
[?BREAK][?CONTINUE]
...

<f> WHILE

...

REPEAT

This is the forever loop. ?BREAK can be used to exit from the loop.
?CONTINUE restart at the beginning of the loop.

This is a conditionnal loop. The runtime part of UNTIL pop the value <f> from stack,
and restart at the beginningof the loop if zero (means not true).
?BREAK can be used to exit from the loop.
?CONTINUE restart at the beginningof the loop.

This is a conditionnal loop. The runtime part of WHILE pop the value <f> from stack,
and jump to the end of the the loop if zero (means not true). The runtime part of
REPEAT jump to the beginning of the loop.
?BREAK can be used to exit from the loop.
?CONTINUE restart at the beginning of the loop.

: test

BEGIN

key dup 'X' ==

?BREAK

emit

AGAIN drop ;

 

: test

BEGIN

key dup emit 'X' ==

UNTIL ;

 

: test

BEGIN

key dup 'X' != WHILE emit REPEAT drop ;

if

else

endif

IF ... ENDIF

IF ... ELSE ... ENDIF

This is the IF structure.

: test
key 65 90 [within]
IF 
" is a letter" type 
ENDIF ;

case

of

endof

endcase

CASE

value1 OF ... ENDOF

value2 OF ... ENDOF

[...]

ENDCASE

This is the CASE structure.

: test
cr key CASE
49 OF ." one" ENDOF
50 OF ." two" ENDOF
." neither 1 or 2"
ENDCASE drop ;

do

I J K

loop (enddo)

+loop (+endo)

DO ... I ... LOOP

DO ... I ... +LOOP

This the LOOP structure.

: test1
10 1 DO 
I . space
LOOP ;

: test2
-20 0 DO 
I . space
-4 +LOOP ;

 

Control Structures (Runtime)

Definition 

Stack 

Operation 

Description 

(branch) 

( --- )

Inconditionnel jump

Inconditionnal jump to the given cell.

(0branch)

( f --- )

Conditionnel jump

Conditionnal jump to the given cell: jump if value popped from stack is false.

(1branch)

( f --- )

Conditionnel jump

Conditionnal jump to the given cell: jump if value popped from stack is true.

(of)

( n1 n2 --- n1 )

Conditionnel jump

Conditionnal jump to the given cell: compare popped value from stack with top
stack, and jump if different.

 

Memory

Definition 

Stack 

Operation 

Description 

>a 

(a --- )

areg = a

Set the address register to a given value.

a>

( --- a )

a = areg

Push the current value of the address register on the stack.

!

( n --- )

*(int*)areg = n

Write the given value to the address pointed by the address register.

0!

( --- )

*(int*)areg = 0

Write the value 0 to the address pointed by the address register.

!+

( n --- )

*(int*)areg++ = n

Write the given value to the address pointed by the address register, then increment the address register.

!-

( n --- )

*(int*)areg-- = n

Write the given value to the address pointed by the address register, then decrement the address register.

C!

( b --- )

*(unsigned char*)areg = n

Write the given 8-bits value to the address pointed by the address register.

C!+

( b --- )

*(unsigned char*)areg++ = n

Write the given 8-bits value to the address pointed by the address register, , then increment the address register.

@

( --- n )

n = *(int*)areg

Read the given value from the address pointed by the address register.

@+

( --- n )

n = *(int*)areg++

Read the given value from the address pointed by the address register, then increment the address register.

C@

( --- b )

b = *(unsigned char*)areg

Read the given 8-bits value from the address pointed by the address register.

C@+

( --- b )

b = *(unsigned char*)areg++

Read the given 8-bits value from the address pointed by the address register, then increment the address register.

1+!

( --- )

(*(int*)areg)++

Increment cell pointed by address register.

1-!

( --- )

(*(int*)areg)--

Decrement cell pointed by address register.

+!

( n --- )

(*(int*)areg) += n

Increment cell pointed by address register with a given value.

-!

( n --- )

(*(int*)areg) -= n

Decrement cell pointed by address register with a given value.

peek

( addr --- n )

n = *(int*)addr

Read the given value from the address given as stack parameter.

poke

( n addr --- )

*(int*)addr = n

Write the given value to the address given as stack parameter.

 

Text terminal

Definition 

Stack 

Description 

cls

( --- )

Clear screen and put cursor in (0, 0)

clreol

( --- )

Clear from current position to the end of line.

#lines

( --- n )

Push number of lines available on the current terminal.

#cols

( --- n )

Push number of columns available on the current terminal.

gotoxy

( x y --- )

Move text cursor to column x, row y.

gotox

( x --- )

Move text cursor to column x

gotoy

( y --- )

Move text cursor to row y.

wherexy

( --- x y )

Push position of the cursor.

wherex

( --- x )

Push position (column) of the cursor.

wherey

( --- y )

Push position (row) of the cursor.

key

( --- n )

Wait for a character from the keyboard.

?key

( --- f )

Return a true flag if a character is available from the keyboard.

emit

( c --- )

Emit a character to the console.

space

( --- )

Emit a space character to the console.

cr

( --- )

Emit a carriage-return character to the console.

type

( str --- )

Print a string to the console.

 

Compiler

Definition 

Stack 

Form 

Description 

"error

( --- )

" msg" "error

Inconditionnal given error message. Return to external interpret..

?"error

( f --- )

" msg" <flag> "error

Conditionnal given error message (if flag is true). Return to external interpret..

?chat

( --- )

variable

If true, the compiler prints out some informations while compiling
(mainly each newly created definition).

?redefinitions

( --- )

variable

If false, redefinitions of definitions are not allowed.

(lit)

( --- f )

 

Run-time part of LITERAL (mainly compiled by the external interpret for numbers).

(")

( --- str )

 

Run-time part of " (compiled by the external interpret for strings).

'

( --- cfa )

' word

Return the CFA (code address) of the next parsed definition.

execute

( cfa --- )

 

Execute the definition whose CFA is given.

:

 

: word

Creation of a new colon definition.

;

 

 

End of either a colon definition or an anonymous definition
(in this case, the anonymous definition is then executed).

(;)

 

 

Run-time part of ; (return of the colon-definition)

immediate

 

: word ; immediate

Mark the last created colon-definition as immediate
(ie executed at the compilation stage).

alias

( cfa --- )

' word1 alias word2

Creation of an alias.

myself

 

 

Jump to the beginning of the named-definition
(can't be used inside an anomyous definition)

recurse

 

 

Call the named-definition (the one being defined)
(can't be used inside an anomyous definition)

forget

 

forget word

Remove the given definition and all defined after
(nothing is done is given definition is not found)

( )

 

( comment )

All words between ( and ) are considered as comment.

//

 

// comment

All rest of the line after // is considered as comment.

\

 

\ comment

All rest of the line after \ is considered as comment.

/* */

 

/* comment */

All words between /* and */ are considered as comment.

here

( --- n )

 

Return current code pointer (code dictionnary).

cellsize

( --- n )

 

Return the size of a word (4 in a 32-bits implementation).

compile

( --- n )

 

Return the size of a word (4 in a 32-bits implementation).

(compile)

( --- n )

 

Return the size of a word (4 in a 32-bits implementation).

!code

( --- n )

 

Return the size of a word (4 in a 32-bits implementation).

 

Defining Words

Definition 

Stack 

Operation 

Description 

build>

 

What to do at compile time

The words given after build> are executed when the word is created by the defining word.

does>

 

What to do at run-time

The words given after does> are executed when the word created by the defining word is executed.

allot

( n --- )

Data memory allocation

Allocation of data memory (cells)
(can only be specified with build> ... does>)

callot

( n --- )

Data memory allocation

Allocation of data memory (bytes)
(can only be specified with build> ... does>)

,

( n --- )

Data memory allocation

Allocation of data memory (cell) and store constant
(can only be specified with build> ... does>)

c,

( b --- )

Data memory allocation

Allocation of data memory (byte) and store constant
(can only be specified with build> ... does>)

 

Variables

Definition 

Stack 
(compile-time)

Stack 
(run-time)

Example 

Description 

const

constant

( --- )

( --- n )

10 constant ten

Create integer-constant.
Running the constant push its value on stack.

int

integer

variable

( --- )

( --- )

int myVar
123 myVar !
myVar @

Create integer-variable.
Running the variable sets the address register.

iint

( n --- )

( --- )

123 iint myVar
234 myVar !
myVar @

Create integer-variable with an initial value.
Running the variable sets the address register.

 

Port I/O

Definition

Parameters Stack 

Description 

p@

( p --- n )

Read the 16-bits data from the I/O port.

pc@

( p --- b )

Read the 8-bits data from the I/O port.

p!

( p n --- )

Write the 16-bits data at the I/O port.

pc!

( p b --- )

Write the 8-bits data at the I/O port.

 

Miscelaneaous

Definition

Parameters Stack 

Description 

bye

 

Return the host OS (either QNX or Windows/NT)

windows?

( --- f )

Return true if host OS is Windows/NT, else false.

photon?

( --- f )

Return true if host OS is QNX/Photon, else false.

delay

( n --- )

Wait n milli-sec

noop

( --- )

Empty definition (No Operation).

 

Development environment (tools)

Definition

Parameters Stack 

Form 

Description 

help

( --- )

 

Print some help.

infos

( --- )

 

Print informations about the memoy used, the number of defined words, etc..

what

( --- )

what word

Print informations about a given definition.

see

( --- )

see word

Decompile a given definition.

!editor

( sz --- )

 

This string variable contains the executable which is run as the external editor.

!curr_file

( sz --- )

 

This string variable contains the filename of the text file which is opened by the external editor.

ed

 

 

 

#ed

 

 

 

"load

( sz --- )

 

Compile (interpret) the given text file.

load

( --- )

 

Compile (interpret) the current text file (see !curr_file)

.s

 

 

 

 

Numeric IO

Definition

Parameters Stack 

Description 

base

( --- )

System variable: value used as the base used in numeric I/O.

decimal

( --- )

Fix the base for numeric I/O to 10.

hex

( --- )

Fix the base for numeric I/O to 16.

octal

( --- )

Fix the base for numeric I/O to 8.

binary

( --- )

Fix the base for numeric I/O to 2.

( n --- )

Display the popped value to the terminal (use the current value of base).

h. 

( n --- )

Display the popped value to the terminal (in hexadecimal).