some new words
authorRalph Ronnquist <ralph.ronnquist@gmail.com>
Sun, 6 Jun 2021 13:22:09 +0000 (23:22 +1000)
committerRalph Ronnquist <ralph.ronnquist@gmail.com>
Sun, 6 Jun 2021 13:22:09 +0000 (23:22 +1000)
13 files changed:
adoc/p_definitions.adoc [new file with mode: 0644]
adoc/p_exit.adoc
adoc/p_return.adoc [new file with mode: 0644]
adoc/p_use.adoc [new file with mode: 0644]
compile.asm
reference.adoc
reference.html
rrqforth
rrqforth.asm
stdio.asm
temp.asm
wordindex.adoc
wordlists.asm

diff --git a/adoc/p_definitions.adoc b/adoc/p_definitions.adoc
new file mode 100644 (file)
index 0000000..37f2180
--- /dev/null
@@ -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 <<p_current_wordlist,CURRENT-WORDLIST>> one.
+
+====
+.Definition concept for DEFINITIONS
+****
+: DEFINITIONS CURRENT-WORDLIST ! ;
+****
+====
index 1d9d78ad8a77156fc73012dc3ea92f7c7f192c16..f0db678babe5f06e03efbdc876c553c2a6cdcd6e 100644 (file)
@@ -5,10 +5,8 @@ anchor:p_exit[]
 === Word: EXIT
 
 ....
-Data stack: ( -- )
+Data stack: ( -- )
 ....
 
-"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 (file)
index 0000000..9fb33a2
--- /dev/null
@@ -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 (file)
index 0000000..4dc5168
--- /dev/null
@@ -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 <<p_input,INPUT>> via <<p_read_word,READ-WORD>>,
+then temporarily changes <<p_current_wordlist,CURRENT-WORDLIST>> to
+<<p_find,FIND>> the word via the given wordlist, and returns the TFA
+of that word, or just 0 if the word coudn't be found.
index defb1acaa5dcfc25e59eac9acbe315c216b5c450..fc9d3f5416207f48d6f27ec4568ff44c8aa80a81 100644 (file)
@@ -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
index 7720490e575869c23ef6cbb815368d86e09f4af7..e9e369f6ed7fe1a8207f94904b9efa9c1b72e165 100644 (file)
@@ -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[]
index a1de89cbf7de1fde99526c0439f3bba94bdd8a81..988e55177cc3476fd286dc94d7b0324a2893bef9 100644 (file)
@@ -806,6 +806,7 @@ asciidoc.install();
 <a href="#p_create">CREATE</a> &#160;\r
 <a href="#p_current_wordlist">CURRENT-WORDLIST</a> &#160;</p></div>\r
 <div class="paragraph"><p><a href="#p_decimal">DECIMAL</a> &#160;\r
+<a href="#p_definitions">DEFINITIONS</a> &#160;\r
 <a href="#p_depth">DEPTH</a> &#160;\r
 <a href="#p_digits">DIGITS</a> &#160;\r
 <a href="#p_divmod">/MOD</a> &#160;\r
@@ -858,6 +859,7 @@ asciidoc.install();
 <div class="paragraph"><p><a href="#p_read_stream_char">READ-STREAM-CHAR</a> &#160;\r
 <a href="#p_read_word">READ-WORD</a> &#160;\r
 <a href="#p_realloc">REALLOC</a> &#160;\r
+<a href="#p_return">RETURN</a> &#160;\r
 <a href="#p_roll">ROLL</a> &#160;\r
 <a href="#p_rot">ROT</a> &#160;\r
 <a href="#p_rbp">RSP</a> &#160;</p></div>\r
@@ -882,7 +884,8 @@ asciidoc.install();
 <a href="#p_this_word">THIS-WORD</a> &#160;\r
 <a href="#p_true">TRUE</a> &#160;\r
 <a href="#p_tuck">TUCK</a> &#160;</p></div>\r
-<div class="paragraph"><p><a href="#p_unstream">UNSTREAM</a> &#160;</p></div>\r
+<div class="paragraph"><p><a href="#p_unstream">UNSTREAM</a> &#160;\r
+<a href="#p_use">USE</a> &#160;</p></div>\r
 <div class="paragraph"><p><a href="#p_verboseQ">VERBOSE?</a> &#160;</p></div>\r
 <div class="paragraph"><p><a href="#p_within">WITHIN</a> &#160;\r
 <a href="#p_words">WORDS</a> &#160;</p></div>\r
@@ -1655,6 +1658,27 @@ _______________________________________________________
 <div style="text-align:center">\r
 _______________________________________________________\r
 </div>\r
+<div class="paragraph"><p><a id="p_definitions"></a></p></div>\r
+</div>\r
+<div class="sect2">\r
+<h3 id="_word_definitions">Word: DEFINITIONS</h3>\r
+<div class="literalblock">\r
+<div class="content">\r
+<pre><code>Data stack: ( wordlist -- )</code></pre>\r
+</div></div>\r
+<div class="paragraph"><p>"DEFINITIONS" is a function word that installs the given wordlist as\r
+the <a href="#p_current_wordlist">CURRENT-WORDLIST</a> one.</p></div>\r
+<div class="exampleblock">\r
+<div class="content">\r
+<div class="sidebarblock">\r
+<div class="content">\r
+<div class="title">Definition concept for DEFINITIONS</div>\r
+<div class="paragraph"><p>: DEFINITIONS CURRENT-WORDLIST ! ;</p></div>\r
+</div></div>\r
+</div></div>\r
+<div style="text-align:center">\r
+_______________________________________________________\r
+</div>\r
 <div class="paragraph"><p><a id="p_depth"></a></p></div>\r
 </div>\r
 <div class="sect2">\r
@@ -2133,11 +2157,10 @@ _______________________________________________________
 <h3 id="_word_exit">Word: EXIT</h3>\r
 <div class="literalblock">\r
 <div class="content">\r
-<pre><code>Data stack: ( -- )</code></pre>\r
+<pre><code>Data stack: ( -- )</code></pre>\r
 </div></div>\r
-<div class="paragraph"><p>"EXIT" is a function word that implements the ending of a FORTH\r
-definition and its threading to the subsequent step of the calling\r
-definition.</p></div>\r
+<div class="paragraph"><p>"EXIT" is a function word that terminates the <code>rrqforth</code> process\r
+immediately with the given exit code.</p></div>\r
 <div style="text-align:center">\r
 _______________________________________________________\r
 </div>\r
@@ -2966,6 +2989,20 @@ kernel, and the granularity is in pages, i.e. a multiple of 4 kb.</p></div>
 <div style="text-align:center">\r
 _______________________________________________________\r
 </div>\r
+<div class="paragraph"><p><a id="p_return"></a></p></div>\r
+</div>\r
+<div class="sect2">\r
+<h3 id="_word_return">Word: RETURN</h3>\r
+<div class="literalblock">\r
+<div class="content">\r
+<pre><code>Data stack: ( -- )</code></pre>\r
+</div></div>\r
+<div class="paragraph"><p>"RETURN" is a function word that implements the ending of a FORTH\r
+definition and make execution return to the next step in the calling\r
+definition.</p></div>\r
+<div style="text-align:center">\r
+_______________________________________________________\r
+</div>\r
 <div class="paragraph"><p>compile.asm:    WORD p_right_bracket,<em>]</em>,fasm</p></div>\r
 <div class="paragraph"><p><a id="p_right_bracket"></a></p></div>\r
 </div>\r
@@ -3483,10 +3520,26 @@ at (stream* + 16) is its size.</p></div>
 <div style="text-align:center">\r
 _______________________________________________________\r
 </div>\r
-<div class="paragraph"><p><a id="p_verboseQ"></a></p></div>\r
+<div class="paragraph"><p><a id="p_use"></a></p></div>\r
 </div>\r
 </div>\r
 <div class="sect2">\r
+<h3 id="_word_use">Word: USE</h3>\r
+<div class="literalblock">\r
+<div class="content">\r
+<pre><code>Data value: ( wordlist -- )  Input stream: word</code></pre>\r
+</div></div>\r
+<div class="paragraph"><p>"USE" is a function word that looks up next word given the wordlist.\r
+It reads next word on <a href="#p_input">INPUT</a> via <a href="#p_read_word">READ-WORD</a>,\r
+then temporarily changes <a href="#p_current_wordlist">CURRENT-WORDLIST</a> to\r
+<a href="#p_find">FIND</a> the word via the given wordlist, and returns the TFA\r
+of that word, or just 0 if the word coudn&#8217;t be found.</p></div>\r
+<div style="text-align:center">\r
+_______________________________________________________\r
+</div>\r
+<div class="paragraph"><p><a id="p_verboseQ"></a></p></div>\r
+</div>\r
+<div class="sect2">\r
 <h3 id="_word_verbose">Word: VERBOSE?</h3>\r
 <div class="literalblock">\r
 <div class="content">\r
@@ -3575,7 +3628,7 @@ is deepest.</p></div>
 <div id="footer">\r
 <div id="footer-text">\r
 Last updated\r
- 2021-06-06 09:36:53 AEST\r
+ 2021-06-06 23:19:36 AEST\r
 </div>\r
 </div>\r
 </body>\r
index 81b5b6ce79bada6af919d3e84198aa42d8d1e884..6634bcbd47cdaff0d58c3409f43008f338536276 100755 (executable)
Binary files a/rrqforth and b/rrqforth differ
index 894e4b440bcb5e2d890020dd87a2577e7890aa9d..5187c902a06c7a202b08a4292bb98482d2a897e6 100644 (file)
@@ -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.
index 467952ba2f8a4b7f9716a3a2b3f22b69372ea7e4..e07e809d8bba5deda2d599f73c9660a1cfd04f2d 100644 (file)
--- 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
index f85cb3375faff34eaea45ea027fde734c36fa31e..46a1358e85632fd4c6c41a4de1f5f8a9f443b9c2 100644 (file)
--- 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
index a64f84be51f9d6ace63ed6b8ee65a72d93f6fe39..66d0ae8ab58ef8ee0c4bb65b3a93fc3e0dc7f68f 100644 (file)
@@ -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}
 
index 7daa4289c964b501314d40dbb21f4609d92fc480..0ee7aecedb83c134e75a86d0f82f30661015a27b 100644 (file)
        ;; 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)