From: Ralph Ronnquist Date: Sun, 6 Jun 2021 13:22:09 +0000 (+1000) Subject: some new words X-Git-Url: https://git.rrq.au/?a=commitdiff_plain;h=d7958ae7b474ef357864237fc40412139e43b117;p=rrq%2Frrqforth.git some new words --- diff --git a/adoc/p_definitions.adoc b/adoc/p_definitions.adoc new file mode 100644 index 0000000..37f2180 --- /dev/null +++ b/adoc/p_definitions.adoc @@ -0,0 +1,19 @@ +// stack.asm: WORD p_definitions, 'DEFINITIONS',fasm + +anchor:p_definitions[] + +=== Word: DEFINITIONS + +.... +Data stack: ( wordlist -- ) +.... + +"DEFINITIONS" is a function word that installs the given wordlist as +the <> one. + +==== +.Definition concept for DEFINITIONS +**** +: DEFINITIONS CURRENT-WORDLIST ! ; +**** +==== diff --git a/adoc/p_exit.adoc b/adoc/p_exit.adoc index 1d9d78a..f0db678 100644 --- a/adoc/p_exit.adoc +++ b/adoc/p_exit.adoc @@ -5,10 +5,8 @@ anchor:p_exit[] === 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. diff --git a/adoc/p_return.adoc b/adoc/p_return.adoc new file mode 100644 index 0000000..9fb33a2 --- /dev/null +++ b/adoc/p_return.adoc @@ -0,0 +1,13 @@ +// rrqforth.asm: WORD p_return, 'RETURN',fasm + +anchor:p_return[] + +=== 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. diff --git a/adoc/p_use.adoc b/adoc/p_use.adoc new file mode 100644 index 0000000..4dc5168 --- /dev/null +++ b/adoc/p_use.adoc @@ -0,0 +1,15 @@ +// rrqforth.asm: WORD p_use,'USE',dovariable + +anchor:p_use[] + +=== 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 <> via <>, +then temporarily changes <> to +<> the word via the given wordlist, and returns the TFA +of that word, or just 0 if the word coudn't be found. diff --git a/compile.asm b/compile.asm index defb1ac..fc9d3f5 100644 --- a/compile.asm +++ b/compile.asm @@ -41,7 +41,7 @@ p_create_COPY: WORD p_allot,'ALLOT' ;; ( n -- ) ;; Allocate n bytes on the heap - dq p_here, p_put_plus, p_exit + dq p_here, p_put_plus, p_return WORD p_quote,"'" ;; ( "word" -- cfa ) @@ -50,22 +50,22 @@ p_create_COPY: BRANCH 0,p_quote_end dq p_tfa2cfa p_quote_end: - dq p_exit + dq p_return WORD p_bracketed_quote,"[']",doforth,IMMEDIATE ;; Compilation ( "word" -- cfa ) ;; Compile down " LIT value " - dq p_literal, p_literal, p_comma,p_quote, p_comma, p_exit + dq p_literal, p_literal, p_comma,p_quote, p_comma, p_return WORD p_comma,',' ;; ( v -- ) ;; Put cell value onto the heap and advance "HERE" - dq p_here, p_literal, 8, p_get_n_increment, p_put, p_exit + dq p_here, p_literal, 8, p_get_n_increment, p_put, p_return WORD p_Ccomma,'C,' ;; ( c -- ) ;; Put byte value onto the heap and advance "HERE" - dq p_here, p_Cput, p_literal, 1, p_here, p_put_plus, p_exit + dq p_here, p_Cput, p_literal, 1, p_here, p_put_plus, p_return WORD p_does,"DOES>",fasm,IMMEDIATE ;; ( -- ) @@ -286,7 +286,7 @@ p_evaluate_stream_END: dq p_literal, 1 p_evaluate_stream_BAD: dq p_Rgt, p_input, p_put ; restore previous stream - dq p_exit + dq p_return WORD p_colon,':' ;; ( -- ) @@ -299,12 +299,12 @@ p_evaluate_stream_BAD: dq p_tfa2cfa dq p_put dq p_right_bracket - dq p_exit + dq p_return WORD p_semicolon,';',,IMMEDIATE ;; ( -- ) - ;; Lay out p_exit, and set interpreting mode - dq p_literal, p_exit, p_comma, p_left_bracket, p_exit + ;; Lay out p_return, and set interpreting mode + dq p_literal, p_return, p_comma, p_left_bracket, p_return WORD p_immediate,'IMMEDIATE',fasm,IMMEDIATE ;; ( -- ) @@ -346,4 +346,4 @@ p_load_file_badfile: dq p_tell, p_dot, p_nl, p_emit dq p_literal,1 p_load_file_exit: - dq p_exit + dq p_return diff --git a/reference.adoc b/reference.adoc index 7720490..e9e369f 100644 --- a/reference.adoc +++ b/reference.adoc @@ -79,6 +79,8 @@ include::adoc/data_stack.adoc[] include::separator.adoc[] include::adoc/p_decimal.adoc[] include::separator.adoc[] +include::adoc/p_definitions.adoc[] +include::separator.adoc[] include::adoc/p_depth.adoc[] include::separator.adoc[] include::adoc/p_dfa2tfa.adoc[] @@ -229,6 +231,8 @@ include::adoc/p_read_word.adoc[] include::separator.adoc[] include::adoc/p_realloc.adoc[] include::separator.adoc[] +include::adoc/p_return.adoc[] +include::separator.adoc[] include::adoc/p_right_bracket.adoc[] include::separator.adoc[] include::adoc/p_roll.adoc[] @@ -289,6 +293,8 @@ include::adoc/p_unequal.adoc[] include::separator.adoc[] include::adoc/p_unstream.adoc[] include::separator.adoc[] +include::adoc/p_use.adoc[] +include::separator.adoc[] include::adoc/p_verboseQ.adoc[] include::separator.adoc[] include::adoc/p_within.adoc[] diff --git a/reference.html b/reference.html index a1de89c..988e551 100644 --- a/reference.html +++ b/reference.html @@ -806,6 +806,7 @@ asciidoc.install(); CREATE   CURRENT-WORDLIST  

DECIMAL   +DEFINITIONS   DEPTH   DIGITS   /MOD   @@ -858,6 +859,7 @@ asciidoc.install();

@@ -882,7 +884,8 @@ asciidoc.install(); THIS-WORD   TRUE   TUCK  

- +

UNSTREAM   +USE  

@@ -1655,6 +1658,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 ! ;

+
+
+
+_______________________________________________________ +

@@ -2133,11 +2157,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.

_______________________________________________________
@@ -2966,6 +2989,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

@@ -3483,10 +3520,26 @@ 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.

+
+_______________________________________________________ +
+

+
+

Word: VERBOSE?

@@ -3575,7 +3628,7 @@ is deepest.

diff --git a/rrqforth b/rrqforth index 81b5b6c..6634bcb 100755 Binary files a/rrqforth and b/rrqforth differ diff --git a/rrqforth.asm b/rrqforth.asm index 894e4b4..5187c90 100644 --- a/rrqforth.asm +++ b/rrqforth.asm @@ -133,7 +133,12 @@ previous_word = 0 pop rax jmp qword [rax] ; goto code of that FORTH word (64 bit jump) - WORD p_exit, 'EXIT',fasm + WORD p_sysexit, 'EXIT', + ;; ( v -- ) + ;; Terminate RRQFORTH with error code + dq sys_exit + + WORD p_return, 'RETURN',fasm ;; ( -- ) ( R: addr -- ) ;; Returns execution to the calling definition as per the ;; return stack. diff --git a/stdio.asm b/stdio.asm index 467952b..e07e809 100644 --- a/stdio.asm +++ b/stdio.asm @@ -288,22 +288,22 @@ p_double_quote_endstream: WORD p_fdtell,'FDTELL', ;; ( chars* n fd -- ) ;; Write n bytes from chars* to fd - dq p_rot, p_rot, sys_write, p_drop, p_exit + dq p_rot, p_rot, sys_write, p_drop, p_return WORD p_tell,'TELL' ;; ( chars* n -- ) ;; Write n bytes from chars* to stdout - dq p_literal,1,p_fdtell, p_exit + dq p_literal,1,p_fdtell, p_return WORD p_fdemit,'FDEMIT' ;; ( c fd -- ) ;; Write byte to fd - dq p_literal,1, p_dsp, p_literal,1, sys_write, p_2drop, p_exit + dq p_literal,1, p_dsp, p_literal,1, sys_write, p_2drop, p_return WORD p_emit,'EMIT' ;; ( c -- ) ;; Write byte to stdout - dq p_literal,1, p_fdemit, p_exit + dq p_literal,1, p_fdemit, p_return WORD p_nl,'NL',dovalue ;; ( -- c ) @@ -360,4 +360,4 @@ p_dot_remainder: WORD p_dot,'.' ;; ( v -- ) ;; Print value to stdout - dq p_dot_temp, p_literal,1, p_fdtell, p_exit + dq p_dot_temp, p_literal,1, p_fdtell, p_return diff --git a/temp.asm b/temp.asm index f85cb33..46a1358 100644 --- a/temp.asm +++ b/temp.asm @@ -48,4 +48,4 @@ p_objecthole_from_tail: dq p_dup, p_gtR ; ( -- char* n addr+8 ) [ n addr+8 ] dq p_swap, p_strncpy ; ( -- ) [ n addr+8 ] dq p_Rgt, p_Rgt ; ( -- addr+8 n ) [ ] - dq p_exit + dq p_return diff --git a/wordindex.adoc b/wordindex.adoc index a64f84b..66d0ae8 100644 --- a/wordindex.adoc +++ b/wordindex.adoc @@ -74,6 +74,7 @@ xref:p_create[CREATE] {nbsp} xref:p_current_wordlist[CURRENT-WORDLIST] {nbsp} xref:p_decimal[DECIMAL] {nbsp} +xref:p_definitions[DEFINITIONS] {nbsp} xref:p_depth[DEPTH] {nbsp} xref:p_digits[DIGITS] {nbsp} xref:p_divmod[/MOD] {nbsp} @@ -137,6 +138,7 @@ xref:p_quit[QUIT] {nbsp} xref:p_read_stream_char[READ-STREAM-CHAR] {nbsp} xref:p_read_word[READ-WORD] {nbsp} xref:p_realloc[REALLOC] {nbsp} +xref:p_return[RETURN] {nbsp} xref:p_roll[ROLL] {nbsp} xref:p_rot[ROT] {nbsp} xref:p_rbp[RSP] {nbsp} @@ -165,6 +167,7 @@ xref:p_true[TRUE] {nbsp} xref:p_tuck[TUCK] {nbsp} xref:p_unstream[UNSTREAM] {nbsp} +xref:p_use[USE] {nbsp} xref:p_verboseQ[VERBOSE?] {nbsp} diff --git a/wordlists.asm b/wordlists.asm index 7daa428..0ee7aec 100644 --- a/wordlists.asm +++ b/wordlists.asm @@ -14,6 +14,30 @@ ;; CURRENT-WORDLIST points to dfa of the currently active wordlist. dq p_forth_DFA ; compilation word list + WORD p_definitions,'DEFINITIONS',fasm + ;; ( wordlist -- ) + ;; Change CURRENT-WORDLIST to use the given word list + pop qword [p_wordlist_DFA] + next + + WORD p_use,'USE',fasm + ;; ( wordlist "name" -- cfa ) + ;; Read next word using the given wordlist + pushr rsi + mov rax,qword [p_wordlist_DFA] + pushr rax + pop qword [p_wordlist_DFA] + DOFORTH p_input, p_get, p_read_word, p_find + popr rax + mov qword [p_wordlist_DFA],rax + cmp qword [rsp],0 + jne p_use_done + add rsp,16 + mov qword [rsp],0 +p_use_done: + popr rsi + next + WORD p_words,'WORDS',fasm ;; ( w -- ) ;; Dump all words of the word list w (the dfa of a word list)