X-Git-Url: https://git.rrq.au/?a=blobdiff_plain;f=reference.html;h=41b019023b1af32bf74615ca410080ca0b93aa9c;hb=39427aee877cab09feea798b146e06dc7bfc25cc;hp=0fc06e19112a3d6eea43df52850d7670d96558cd;hpb=8a2d8dc0e8ff7f3e6b402d2d496169d19d032db5;p=rrq%2Frrqforth.git diff --git a/reference.html b/reference.html index 0fc06e1..41b0190 100644 --- a/reference.html +++ b/reference.html @@ -770,17 +770,24 @@ asciidoc.install(); !   C@   C!   +W@   +W!   +D@   +D!   2@   2!   !+   @n++   @n--   C,   -S"   +W,   +D,   +S"   >R   R@   R>   -R[n]  

+R[n]   +D[n]  

DATA-STACK   RETURN-STACK     @@ -793,6 +800,7 @@ asciidoc.install(); 2OVER   2SWAP  

ABS   +AGAIN   ALLOT   AND   [ASM]  

@@ -800,10 +808,12 @@ asciidoc.install(); BEGIN   BREAK  

CFA>FLAGS@   +CFA>TFA   CLEAR-STREAM   CREATE   CURRENT-WORDLIST  

DECIMAL   +DEFINITIONS   DEPTH   DIGITS   /MOD   @@ -825,6 +835,8 @@ asciidoc.install(); EXECUTE   EXIT  

FALSE   +FDEMIT   +FDTELL   FIND   FORTH  

HERE   @@ -835,7 +847,9 @@ asciidoc.install(); IMMEDIATE   INPUT  

LIT   -LOAD-FILE"  

+LIT-STRING   +LOAD-BUFFER-SIZE   +LOAD-FILE  

MAIN-ARGS   MALLOC  

NEGATE   @@ -843,7 +857,7 @@ asciidoc.install(); NL   NOT   NUMBER  

-

OPEN-FILE"   +

OPEN-FILE   OR   OVER  

PAD   @@ -851,21 +865,29 @@ asciidoc.install(); PROGRAM_VERSION  

QUIT  

READ-STREAM-CHAR   +READ-STREAM-LINE   READ-WORD   REALLOC   +RETURN   ROLL   -ROT  

+ROT   +RSP  

SP   STATE   STDIN   STREAM   STREAM-NCHARS   +STR>TEMP   STRLEN   STRNCMP   STRNCPY   SWAP   SYSTEM  

TELL   +.TEMP   +TEMP   +TEMPHELD   +TEMPSPACE   TERMINATE0   TFA>CFA   TFA>DFA   @@ -875,6 +897,8 @@ asciidoc.install(); THIS-WORD   TRUE   TUCK  

+

UNSTREAM   +USE  

VERBOSE?  

WITHIN   WORDS  

@@ -1127,6 +1151,85 @@ at the current free head address, which also is incremented.

_______________________________________________________
+

+ +
+

Word: W,

+
+
+
Data stack: ( v -- )
+
+

"W," (W-comma) is a function word that puts a "word" (double-byte) on +the HERE heap. The two least significant bytes of the value +are put at the current free head address, which also is incremented +accordingly.

+
+
+
+
+
Definition concept for W,
+

: W, HERE @ 2 ALLOT W! ;

+
+
+
+_______________________________________________________ +
+

+
+
+

Word: D,

+
+
+
Data stack: ( v -- )
+
+

"D," (D-comma) is a function word that puts a "double word" +(double-byte) on the HERE heap. The four least significant +bytes of the value are put at the current free head address, which +also is incremented accordingly.

+
+
+
+
+
Definition concept for D,
+

: D, HERE @ 4 ALLOT D! ;

+
+
+
+_______________________________________________________ +
+

+
+
+

Word: D[n]

+
+
+
Data stack: ( n -- a )
+
+

"D[n]" is a function word that pushes the address for the n:th cell of +the data stack onto the data stack.

+
+_______________________________________________________ +
+

+
+
+

Word: CFA>TFA

+
+
+
Data stack: ( cfa -- tfa )
+
+

"CFA>TFA" is a function word that pushes word tfa of the given cfa.

+
+
+
+
+
Definition concept for CFA>TFA
+

: CFA>TFA 14 - @ ;

+
+
+
+_______________________________________________________ +

@@ -1139,6 +1242,32 @@ _______________________________________________________
_______________________________________________________
+

+
+
+

Word: W@

+
+
+
Data stack: ( a -- v )
+
+

"W@" is a function word that pushes the "word" (double-byte) value v +from the address a.

+
+_______________________________________________________ +
+

+
+
+

Word: R@

+
+
+
Data stack: ( -- v )   Return stack: ( v -- v )
+
+

"R@" is a function word that "copies" the top return stack value onto +the data stack.

+
+_______________________________________________________ +

@@ -1152,10 +1281,36 @@ significant byte of the cell) at the address a.

_______________________________________________________
+

+ +
+

Word: W!

+
+
+
Data stack: ( v a -- )
+
+

"W!" is a function word that stores the "word" (2-byte) value v (the +two least significant bytes of the cell) at the address a.

+
+_______________________________________________________ +
+

+
+
+

Word: D!

+
+
+
Data stack: ( v a -- )
+
+

"D!" is a function word that stores the "doublw word" (4-byte) value v +(the four least significant bytes of the cell) at the address a.

+
+_______________________________________________________ +

-

Word: R@

+

Word: R@

Data stack: ( -- v )   Return stack: ( v -- v )
@@ -1191,6 +1346,23 @@ value. To that end, the values are 64-bit signed integers.

_______________________________________________________
+

+
+
+

Word: AGAIN

+
+
+
Data stack: Compiling: ( -- a )
+
+

"AGAIN" is an immediate function word that is used together with +BEGIN and instead of END to implement structured +execution control. AGAIN scans the datastack for the nearest preceding +BEGIN marker and lays out an unconditional branch from this point the +beginning of the block during execution. It thereafter performs the +END compile action to end the block.

+
+_______________________________________________________ +

@@ -1240,7 +1412,8 @@ _______________________________________________________

"ARGS" is a value word that holds a pointer to the command line data block which consists of a count cell followed by that many asciiz -pointers and then a 0 cell.

+pointers and then a 0 cell. That is next followed by the environment +as a number of asciiz pointers and a 0 cell.

@@ -1248,9 +1421,10 @@ pointers and then a 0 cell.

ARGS -> 8 bytes: count of non-zero asciiz pointers following
         8 bytes: command name string
-        8 bytes: first argument string
-        8* ...
-        8 zero
+ 8* bytes: argument strings + 8 bytes: zero cell + 8* bytes: envirnment strings + 8 bytes: zero cell
@@ -1610,6 +1784,27 @@ _______________________________________________________
_______________________________________________________
+

+
+
+

Word: DEFINITIONS

+
+
+
Data stack: ( wordlist -- )
+
+

"DEFINITIONS" is a function word that installs the given wordlist as +the CURRENT-WORDLIST one.

+
+
+
+
+
Definition concept for DEFINITIONS
+

: DEFINITIONS CURRENT-WORDLIST ! ;

+
+
+
+_______________________________________________________ +

@@ -1825,6 +2020,23 @@ the current BASE (either DECIMAL
_______________________________________________________
+

+
+
+

Word: .TEMP

+
+
+
Data stack: ( v -- char* n )
+
+

".TEMP" is a function word that renders a cell value as an integer +using the current BASE, which is either +DECIMAL or HEX. In DECIMAL +BASE, a negative value is rendered as such with a leading +minus sign, whereas HEX BASE rendering is +unsigned.

+
+_______________________________________________________ +

@@ -2071,11 +2283,10 @@ _______________________________________________________

Word: EXIT

-
Data stack: ( -- )
+
Data stack: ( v -- )
-

"EXIT" is a function word that implements the ending of a FORTH -definition and its threading to the subsequent step of the calling -definition.

+

"EXIT" is a function word that terminates the rrqforth process +immediately with the given exit code.

_______________________________________________________
@@ -2091,6 +2302,33 @@ _______________________________________________________
_______________________________________________________
+

+
+
+

Word: FDEMIT

+
+
+
Data stack: ( c fd -- )
+
+

"FDEMIT" is a function word that puts the given character code to the +given file descriptor. The character is the least significant byte of +the data stack cell.

+
+_______________________________________________________ +
+

+
+
+

Word: FDTELL

+
+
+
Data stack: ( char* n fd -- )
+
+

"FDTELL" is a function word that prints a string to the given file +descriptor.

+
+_______________________________________________________ +

@@ -2430,38 +2668,72 @@ _______________________________________________________

-

Word: S"

+

Word: LIT-STRING

Data stack: ( -- chars* n )
-

"S"" is a function word that pushes the [n:char] pointer for a string -inlined subsequently to it in the containing definition. This is -similar to LIT but for a string literal.

+

"LIT-STRING" is a function word that pushes the char* and length n of +a subsequent inline string, then advances execution to continue after +the string. This is similar to LIT but for a block literal.

+

Note that the inlined byte count includes the terminating NUL byte.

-
Definition concept for LIT
-

: LIT R> DUP @ 2DUP + 8 + >R SWAP 8 + SWAP ;

+
Definition concept for LIT-STRING
+

: LIT-STRING R@ DUP @ 8 + R@ @ 2DUP + R> + >R 1 - ;

+
+
+
+_______________________________________________________ +
+

+
+
+

Word: S"

+
+
+
Data stack: ( -- )  Input stream: " chars"
+

"S"" is an immediate function word that compiles the subseqent +characters up to terminating double-quote into the current definition, +preceded by a LIT-STRING cell, and the count of +bytes scanned. The inline text includes a terminating NUL character +which also is included in the inlined count.

+

Note that "S"" uses " for reading the string.

+
+_______________________________________________________ +
+

+
+
+

Word: LOAD-BUFFER-SIZE

+
+
+
data stack: ( -- a )
+

"LOAD-BUFFER-SIZE" is a variable word telling the buffer size in bytes +that LOAD-FILE should use.

_______________________________________________________
-

+

-

Word: LOAD-FILE"

+

Word: LOAD-FILE

-
data stack: ( "name" -- )
+
data stack: ( chaz* -- * 0/1 )
-

"LOAD-FILE"" is a function word that opens a file via -OPEN-FILE", allocates a stream buffer of 15000 -bytes for reading it, saves the stream pointer as value for the newly -created filename variable, and then it invokes -EVALUATE-STREAM for processing the file.

+

"LOAD-FILE" is a function word that evaluates a text file. It opens a +file via OPEN-FILE and sets up a stream with a +buffer of LOAD-BUFFER-SIZE bytes for +reading it. The stream is passed to +EVALUATE-STREAM for processing its words. Upon +its return the file is closed and the stream memory is reclaimed, and +then the function returns whatever +EVALUATE-STREAM returns.

_______________________________________________________
@@ -2608,17 +2880,17 @@ integers.

_______________________________________________________
-

+

-

Word: OPEN-FILE"

+

Word: OPEN-FILE

-
Data stack: ( "name" -- fd )
+
Data stack: ( chaz* -- fd )
-

"OPEN-FILE"" is a function word that reads the intputstream for a -filename, adds that to the dictionary as a no-content variable, opens -that file and returns the input file descriptor.

+

"OPEN-FILE" is a function word that opens the file named by the zero +terminated character string and returns the file descriptor, or if +less than 0, the system call error code.

_______________________________________________________
@@ -2763,6 +3035,40 @@ word on the input stream and pushes its cfa.

_______________________________________________________
+

+ +
+

Word: RSP

+
+
+
Data stack: ( -- a )
+
+

"RSP" is a function word that pushes the return stack pointer value +onto the data stack.

+
+_______________________________________________________ +
+

+
+
+

Word: R[n]

+
+
+
Data stack: ( n -- a )
+
+

"R[n]" is a function word that pushes the address for the n:th cell of +the return stack onto the data stack.

+
+
+
+
+
Defintion concept for R[n]
+

( n — a ) : R[n] 8 * RSP + ;

+
+
+
+_______________________________________________________ +

@@ -2781,6 +3087,22 @@ instead.

_______________________________________________________
+

+ +
+

Word: READ-STREAM-LINE

+
+
+
Data stack: ( stream -- n )
+
+

"READ-STREAM-LINE" is a function word that gets the next line from the +given stream buffer into PAD and returns number of characters. If the +stream is backed by a file descriptor, the stream buffer is refilled +from there as needed, by a SYS_READ call when more characters are +needed.

+
+_______________________________________________________ +

@@ -2794,6 +3116,18 @@ separated word from the given stream and returns the [n:char*] duoble cell pointer for it. The characters of the word are copied to PAD, and there is a limit of 1024 characters.

At the end of the stream READ-WORD returns 0 length.

+
+
Special syntax 1: Whitespace
+
+

All character codes less or equal to 32 are regarded as "whitespace".

+
+
+
Special syntax 2: Rest-of-line comment
+
+

The "#" character following whitespace starts a line comment and the +rest of the line is ignored. Note that this is also recognised with +parethesis commenting.

+
_______________________________________________________
@@ -2815,6 +3149,20 @@ kernel, and the granularity is in pages, i.e. a multiple of 4 kb.

_______________________________________________________
+

+ +
+

Word: RETURN

+
+
+
Data stack: ( -- )
+
+

"RETURN" is a function word that implements the ending of a FORTH +definition and make execution return to the next step in the calling +definition.

+
+_______________________________________________________ +

compile.asm: WORD p_right_bracket,],fasm

@@ -2874,19 +3222,6 @@ and the first becomes the second.

_______________________________________________________
-

- -
-

Word: R[n]

-
-
-
Data stack: ( n -- a )
-
-

"R[n]" is a function word that pushes the address for the n:th cell on -the top return stack value onto the data stack.

-
-_______________________________________________________ -

@@ -2895,8 +3230,9 @@ _______________________________________________________
Data stack: ( -- )
-

";" (semi-colon) is a function word that ends a new forth definition -by means of adding an EXIT

+

";" (semi-colon) is an immediate function word that ends a new forth +definition by means of adding an EXIT cell, then changing +<<p_state,STATE> to interpreting.

@@ -3061,6 +3397,29 @@ stream (or filling it by reading the backing file).

_______________________________________________________
+

+
+
+

Word: STR>TEMP

+
+
+

Data stack: ( char* n — char* n )

+
+

"STR>TEMP" is a function word that copies a given string plus a +terminating NUL character into a TEMPSPACE snippet, +all preceded by a length cell. It returns a pointer for to the text in +the snippet and its length, excluding the NUL character at end and the +length cell before tie text.

+
+
Layout for copied string
+
+
        length: 8 bytes
+returned char*: n bytes
+           nul: 1 byte
+
+
+_______________________________________________________ +

@@ -3146,6 +3505,74 @@ descriptor 1).

_______________________________________________________
+

+
+
+

Word: TEMP

+
+
+

Data stack: ( size — addr )

+
+

"TEMP" is a function word that "allocates" a TEMPSPACE +area of given size and returns its base address. The allocation is +temporary and only valid until there is a later allocation that +overruns this area.

+

Allocations are done in succession until the requested size overruns +the TEMPSPACE. If so, the allocation pointer is reset +and the space is allocated from start again. This is all intended for +small and short-lived data areas.

+
+_______________________________________________________ +
+

+
+
+

Word: TEMPHELD

+
+
+
Data stack: ( -- a )
+
+

"TEMPHELD" is a variable word that keeps the lowest offset of the +TEMPSPACE space to reuse upon cycling. The space +below TEMPHELD is "held" in the sense of not being reused upon +cycling. An application may change the TEMPSPACE offset as needed to +dynamically preserve memory longer term.

+
+_______________________________________________________ +
+

+
+
+

Word: TEMPSPACE

+
+
+
Data stack: ( -- a )
+
+

"TEMPSPACE" is a variable word that holds three cells the for managing +"temporary memory":

+
+

This memory is intended to be used by requesting snippets of memory in +a cyclic fashion via TEMP without concern about it possibly +overlapping a prior request.

+
+_______________________________________________________ +

@@ -3320,6 +3747,48 @@ values are unequal, and 0 otherwise.

_______________________________________________________
+

+ +
+

Word: UNSTREAM

+
+
+
Data stack: ( stream* -- )
+
+

"UNSTREAM" is a function word that releases the memory allocated for a +stream, and closes the associated file if it’s a file stream.

+
+

File descriptor backed stream

+

This kind of stream has the stream header as a prefix within the +allocated memory. Thus, stream* is the base address for the memory to +reclaim, and the size of this is determined from the cell at (stream* ++ 16) plus the 32 bytes head itself.

+
+
+

Memory block backed STREAM

+

This kind of stream has a separate header which points at the memory +area to reclaim. The cell at stream* is the base address, and the cell +at (stream* + 16) is its size.

+
+_______________________________________________________ +
+

+
+
+
+

Word: USE

+
+
+
Data value: ( wordlist -- )  Input stream: word
+
+

"USE" is a function word that looks up next word given the wordlist. +It reads next word on INPUT via READ-WORD, +then temporarily changes CURRENT-WORDLIST to +FIND the word via the given wordlist, and returns the TFA +of that word, or just 0 if the word coudn’t be found.

+
+_______________________________________________________ +

@@ -3411,7 +3880,7 @@ is deepest.