--- /dev/null
+// 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 ! ;
+****
+====
=== 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.
--- /dev/null
+// 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.
--- /dev/null
+// 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.
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 )
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
;; ( -- )
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,':'
;; ( -- )
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
;; ( -- )
dq p_tell, p_dot, p_nl, p_emit
dq p_literal,1
p_load_file_exit:
- dq p_exit
+ dq p_return
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[]
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[]
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[]
<a href="#p_create">CREATE</a>  \r
<a href="#p_current_wordlist">CURRENT-WORDLIST</a>  </p></div>\r
<div class="paragraph"><p><a href="#p_decimal">DECIMAL</a>  \r
+<a href="#p_definitions">DEFINITIONS</a>  \r
<a href="#p_depth">DEPTH</a>  \r
<a href="#p_digits">DIGITS</a>  \r
<a href="#p_divmod">/MOD</a>  \r
<div class="paragraph"><p><a href="#p_read_stream_char">READ-STREAM-CHAR</a>  \r
<a href="#p_read_word">READ-WORD</a>  \r
<a href="#p_realloc">REALLOC</a>  \r
+<a href="#p_return">RETURN</a>  \r
<a href="#p_roll">ROLL</a>  \r
<a href="#p_rot">ROT</a>  \r
<a href="#p_rbp">RSP</a>  </p></div>\r
<a href="#p_this_word">THIS-WORD</a>  \r
<a href="#p_true">TRUE</a>  \r
<a href="#p_tuck">TUCK</a>  </p></div>\r
-<div class="paragraph"><p><a href="#p_unstream">UNSTREAM</a>  </p></div>\r
+<div class="paragraph"><p><a href="#p_unstream">UNSTREAM</a>  \r
+<a href="#p_use">USE</a>  </p></div>\r
<div class="paragraph"><p><a href="#p_verboseQ">VERBOSE?</a>  </p></div>\r
<div class="paragraph"><p><a href="#p_within">WITHIN</a>  \r
<a href="#p_words">WORDS</a>  </p></div>\r
<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
<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: ( v -- )</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
<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
<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’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
<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
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.
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 )
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
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
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}
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}
xref:p_tuck[TUCK] {nbsp}
xref:p_unstream[UNSTREAM] {nbsp}
+xref:p_use[USE] {nbsp}
xref:p_verboseQ[VERBOSE?] {nbsp}
;; 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)