-- usually implemented words.
Copyright (C) Tektronix, Inc. 1998 - 2001. All rights reserved.
description: There are lots of useful words that do not appear in any standard. This wordset defines some of them.
FORTH
#BACKSPACE-CHAR
( .. )( | ) ; |
; |
( '\b' ) constant #BACKSPACE-CHAR
an ordinary constant (no special usage info)
FORTH
C+!
( n addr -- )(
)
;
p4:"c-plus-store";
Add the low-order byte of _n_ to the byte at _addr_, removing both from the stack.
FORTH
VOCABULARY
( 'name' -- )(
)
;
p4:"vocabulary";
create a vocabulary of that name. If the named vocabulary is called later, it will run ((VOCABULARY)) , thereby putting it into the current search order. Special pfe-extensions are accessible via CASE-SENSITIVE-VOC and SEARCH-ALSO-VOC
simulate: : VOCABULARY CREATE ALLOT-WORDLIST DOES> ( the ((VOCABULARY)) runtime ) CONTEXT ! ; IMMEDIATE
FORTH
BOUNDS
( str len -- str+len str )( | ) ; |
; |
Convert _str len_ to range for DO-loop.
: BOUNDS ( str len -- str+len str ) OVER + SWAP ;
FORTH
OFF!
( .. )(
)
;
as:"off-store";
ordinary primitive OFF!
an executable word (no special usage info)
or wrapper call around p4_off_store
FORTH
ON!
( addr -- )(
)
;
p4:"on-store";
Store -1 at _addr_. Defined in f83 as ON. See antonym OFF!.
: ON! ( addr -- ) -1 SWAP ! ;
FORTH
OFF
( addr -- )(
)
;
p4:"off-store";
Store 0 at _addr_. Defined in f84 as OFF. See antonym ON!.
: OFF ( addr -- ) 0 SWAP ! ;
FORTH
ON
( .. )(
)
;
as:"on";
forthword synonym ON
is doing the same as ON!
this word is provided only for compatibility with common forth usage in programs. Thegiven synonym should be preferred however.
FORTH
PLACE
( str len addr -- )(
)
;
p4:"place";
Place the string _str len_ at _addr_, formatting it as a counted string.
: PLACE 2DUP 2>R 1+ SWAP MOVE 2R> C! ; : PLACE 2DUP C! 1+ SWAP CMOVE ;
FORTH
+PLACE
( .. )(
)
;
as:"plus-place";
ordinary primitive +PLACE
an executable word (no special usage info)
or wrapper call around p4_append
FORTH
C+PLACE
( .. )(
)
;
as:"c-plus-place";
ordinary primitive C+PLACE
an executable word (no special usage info)
or wrapper call around p4_append_char
FORTH
APPEND
( str len add2 -- )(
)
;
p4:"append";
Append string _str len_ to the counted string at _addr_. a.k.a. +PLACE of the PLACE family
: APPEND 2DUP 2>R COUNT + SWAP MOVE ( ) 2R> C+! ;
Append string _str len_ to the counted string at _addr_. a.k.a. APPEND (being a SYNONYM now)
: +PLACE 2DUP 2>R COUNT + SWAP MOVE ( ) 2R> C+! ;
FORTH
APPEND-CHAR
( char addr -- )( | ) ; |
; |
Append _char_ to the counted string at _addr_. a.k.a. C+PLACE of the PLACE family
: APPEND-CHAR DUP >R COUNT DUP 1+ R> C! + C! ;
Append _char_ to the counted string at _addr_. a.k.a. APPEND-CHAR (being a SYNONYM now)
: C+PLACE DUP >R COUNT DUP 1+ R> C! + C! ;
FORTH
@EXECUTE
( xt -- ? )(
)
;
p4:"fetch-execute";
same as @ EXECUTE , but checks for null as xt and silently ignores it. Same as in most forths where defined.
simulate: : @EXECUTE @ ?DUP IF EXECUTE THEN ;
FORTH
?LEAVE
( cond -- )(
)
;
p4:"question-leave";
leave a (innermost) loop if condition is true
FORTH
NOOP
( .. )(
)
;
as:"noop";
ordinary primitive NOOP
an executable word (no special usage info)
or wrapper call around p4_noop
FORTH
RP@
( -- addr )(
)
;
p4:"r-p-fetch";
returns the return stack pointer
example: : R@ RP@ @ ;
FORTH
RP!
( addr -- )(
)
;
p4:"r-p-store";
sets the return stack pointer, reverse of RP@
FORTH
SP!
( ... addr -- )(
)
;
p4:"s-p-store";
sets the stack pointer, reverse of SP@
FORTH
-ROT
( a b c -- c a b )(
)
;
p4:"dash-rot";
inverse of ROT
FORTH
CSET
( n addr -- )(
)
;
p4:"c-set";
set bits in byte at given address
simulate: : CSET TUCK @ SWAP OR SWAP ! ;
FORTH
CRESET
( n addr -- )(
)
;
p4:"c-reset";
reset bits in byte at given address
simulate: : CRESET TUCK @ SWAP NOT AND SWAP ! ;
FORTH
CTOGGLE
( n addr -- )(
)
;
p4:"c-toggle";
toggle bits in byte at given address
simulate: : CTOGGLE TUCK @ SWAP XOR SWAP ! ;
FORTH
TOGGLE
( c-addr charmask -- )( | ) ; |
; |
toggle the bits given in charmask, see also SMUDGE and = UNSMUDGE
example: the fig-style SMUDGE had been defined such : FIG-SMUDGE LATEST >FFA (SMUDGE#) TOGGLE ;
FORTH
3DUP
( x y z -- x y z x y z )( | ) ; |
; |
Copy top three elements on the stack onto top of stack.
: 3DUP THIRD THIRD THIRD ;
or
: 3DUP 3 PICK 3 PICK 3 PICK ;
FORTH
3DROP
( x y z -- )(
)
;
p4:"three-drop";
Drop the top three elements from the stack.
: 3DROP DROP 2DROP ;
FORTH
4DUP
( a b c d -- a b c d a b c d )( | ) ; |
; |
simulate: : 4DUP 4 PICK 4 PICK 4 PICK 4 PICK ;
FORTH
4DROP
( x y z -- )(
)
;
p4:"four-drop";
Drop the top three elements from the stack.
: 4DROP 2DROP 2DROP ;
FORTH
TOUPPER
( c1 -- c2 )(
)
;
p4:"toupper";
convert a single character to upper case
: TOUPPER >R _toupper ;
FORTH
UPPER
( addr cnt -- )(
)
;
p4:"upper";
convert string to upper case
simulate: : UPPER 0 DO DUP I + DUP C@ UPC SWAP C! LOOP DROP ;
FORTH
LOWER
( addr cnt -- )(
)
;
p4:"lower";
convert string to lower case This is not in L&P's F83 but provided for symmetry
simulate: : LOWER 0 DO DUP I + DUP C@ >R _tolower SWAP C! LOOP DROP ;
FORTH
ASCII
( [word] -- val )(
)
;
p4:"ascii";
state smart version of CHAR or [CHAR] resp.
simulate: : ASCII [COMPILE] [CHAR] STATE @ IF [COMPILE] LITERAL THEN ;
FORTH
CONTROL
( [word] -- val )(
)
;
p4:"control";
see ASCII, but returns char - '@'
simulate: : CONTROL [COMPILE] [CHAR] [CHAR] @ - STATE @ IF [COMPILE] LITERAL THEN ;
FORTH
NUMBER?
( addr -- d flag )( | ) ; |
; |
convert counted string to number - used in inner interpreter ( INTERPRET ), flags if conversion was successful
example: BL WORD HERE NUMBER? 0= IF ." not a number " THEN .
FORTH
VOCS
( -- )(
)
;
p4:"vocs";
list all vocabularies in the system
simulate: : VOCS VOC-LINK @ BEGIN DUP WHILE DUP ->WORDLIST.NAME @ ID. ->WORDLIST.LINK @ REPEAT DROP ;
FORTH
EMITS
( n char -- )(
)
;
p4:"emits";
Emit _char_ _n_ times.
: EMITS ( n char -- ) SWAP 0 ?DO DUP EMIT LOOP DROP ;
also compare
: SPACES BL EMITS ; : SPACE BL EMIT ;
FORTH
FILE-CHECK
( n -- )(
)
;
p4:"file-check";
Check for file access error.
\ : FILE-CHECK ( n -- ) THROW ; : FILE-CHECK ( n -- ) ABORT" File Access Error " ;
FORTH
MEMORY-CHECK
( n -- )(
)
;
p4:"memory-check";
Check for memory allocation error.
\ : MEMORY-CHECK ( n -- ) THROW ; : MEMORY-CHECK ( n -- ) ABORT" Memory Allocation Error " ;
FORTH
++
( addr -- )(
)
;
p4:"plus-plus";
Increment the value at _addr_.
: ++ ( addr -- ) 1 SWAP +! ;
FORTH
@++
( addr -- addr' x )( | ) ; |
; |
Fetch the value _x_ from _addr_, and increment the address by one cell.
: @++ ( addr -- addr' x ) DUP CELL+ SWAP @ ;
FORTH
!++
( addr x -- addr' )( | ) ; |
; |
Store the value _x_ into _addr_, and increment the address by one cell.
: !++ ( addr x -- addr' ) OVER ! CELL+ ;
FORTH
@+
( .. )(
)
;
as:"fetch-plus";
forthword synonym @+
is doing the same as @++
this word is provided only for compatibility with common forth usage in programs. Thegiven synonym should be preferred however.
FORTH
!+
( .. )(
)
;
as:"store-plus";
forthword synonym !+
is doing the same as !++
this word is provided only for compatibility with common forth usage in programs. Thegiven synonym should be preferred however.
FORTH
ENDIF
( .. )(
)
;
as:"endif";
immediate synonym ENDIF
is doing the same as THEN
this word is provided only for compatibility with common forth usage in programs. Thegiven synonym should be preferred however.
EXTENSIONS
>WORDLIST
( xt -- wordl* )( | ) ; |
; |
convert a VOCABULARY-xt into its wordlist reference (as in win32forth)
EXTENSIONS
PERFORM
( .. )(
)
;
as:"perform";
obsolete forthword PERFORM
is doing the same as @EXECUTE
This word should be replaced. It will be deleted in the near future. Instead use the (newer) synonym word given above.
EXTENSIONS
UPC
( .. )(
)
;
as:"upc";
obsolete forthword UPC
is doing the same as TOUPPER
This word should be replaced. It will be deleted in the near future. Instead use the (newer) synonym word given above.