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:
The following categories have been used to group the definitions:
|
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. |
|
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. |
|
|
r |
I |
( --- n ) |
( n --- n ) |
Copy the value from the top of the return stack. |
|
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 |
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. |
|
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 |
|
|
!= |
<> |
( n1 n2 --- f ) |
f = (n1!=n2) ? TRUE : FALSE |
Return a logical value
which is true if the given condition |
|
|
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 |
||
|
<= |
( n1 n2 --- f ) |
f = (n1<=n2) ? TRUE : FALSE |
Return a logical value
which is true if the given condition |
||
|
> |
( n1 n2 --- f ) |
f = (n1>n2) ? TRUE : FALSE |
Return a logical value
which is true if the given condition |
||
|
>= |
( n1 n2 --- f ) |
f = (n1>=n2) ? TRUE : FALSE |
Return a logical value
which is true if the given condition |
||
|
U< |
( u1 u2 --- f ) |
f = (u1<u2) ? TRUE : FALSE |
Return a logical value
which is true if the given condition |
||
|
U<= |
( n1 n2 --- f ) |
f = (u1<=u2) ? TRUE : FALSE |
Return a logical value
which is true if the given condition |
||
|
U> |
( u1 u2 --- f ) |
f = (u1>u2) ? TRUE : FALSE |
Return a logical value
which is true if the given condition |
||
|
U>= |
( u1 u2 --- f ) |
f = (u1>=u2) ? TRUE : FALSE |
Return a logical value
which is true if the given condition |
||
|
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. |
||
|
Definition |
Model |
Description |
Example |
|
begin again until while repeat ?break ?continue |
BEGIN ... AGAIN
BEGIN ... <f> UNTIL
BEGIN ... <f> WHILE ... REPEAT |
This is the forever loop.
?BREAK can be used to exit from the loop. This is a conditionnal loop. The runtime
part of UNTIL pop the value <f> from stack, This is a conditionnal loop. The runtime
part of WHILE pop the value <f> from stack, |
: 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
|
|
case of endof endcase |
CASE value1 OF ... ENDOF value2 OF ... ENDOF [...] ENDCASE |
This is the CASE structure. |
: test
|
|
do I J K loop (enddo) +loop (+endo) |
DO ... I ... LOOP DO ... I ... +LOOP |
This the LOOP structure. |
: test1
: test2 |
|
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 |
|
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. |
|
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. |
|
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 |
|
?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 |
|
(;) |
|
|
Run-time part of ; (return of the colon-definition) |
|
immediate |
|
: word ; immediate |
Mark the last created
colon-definition as immediate |
|
alias |
( cfa --- ) |
' word1 alias word2 |
Creation of an alias. |
|
myself |
|
|
Jump to the beginning of
the named-definition |
|
recurse |
|
|
Call the named-definition
(the one being defined) |
|
forget |
|
forget word |
Remove the given definition
and all defined after |
|
( ) |
|
( 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). |
|
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) |
|
callot |
( n --- ) |
Data memory allocation |
Allocation of data memory
(bytes) |
|
, |
( n --- ) |
Data memory allocation |
Allocation of data memory
(cell) and store constant |
|
c, |
( b --- ) |
Data memory allocation |
Allocation of data memory
(byte) and store constant |
|
Definition |
Stack |
Stack |
Example |
Description |
||
|
const |
constant |
( --- ) |
( --- n ) |
10 constant ten |
Create integer-constant. |
|
|
int |
integer |
variable |
( --- ) |
( --- ) |
int
myVar |
Create integer-variable. |
|
iint |
( n --- ) |
( --- ) |
123
iint myVar |
Create integer-variable
with an initial value. |
||
|
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. |
|
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). |
|
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 |
|
|
|
|
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). |