From: Ralph Ronnquist Date: Sun, 30 May 2021 03:15:34 +0000 (+1000) Subject: more and better documentation and some reorganisation X-Git-Url: https://git.rrq.au/?a=commitdiff_plain;h=bf67023324b2a0c5723dd3167ef757209ba62e01;p=rrq%2Frrqforth.git more and better documentation and some reorganisation --- diff --git a/adoc/p_2get.adoc b/adoc/p_2get.adoc new file mode 100644 index 0000000..2f02bc8 --- /dev/null +++ b/adoc/p_2get.adoc @@ -0,0 +1,14 @@ +// memory.asm: WORD p_2get, '2@',fasm + +anchor:p_2get[] + +=== Word: 2@ + +.... +Data stack: ( a -- v2 v1 ) +.... + +"2@" is a function word that pushes the two concecutive values v1 and +v2 from the address a onto the data stack. Value v1 is from address a +and value v2 is from address a + 8. + diff --git a/adoc/p_2put.adoc b/adoc/p_2put.adoc new file mode 100644 index 0000000..ce3b294 --- /dev/null +++ b/adoc/p_2put.adoc @@ -0,0 +1,13 @@ +// memory.asm: WORD p_2put, '2!',fasm + +anchor:p_2out[] + +=== Word: 2! + +.... +Data stack: ( v2 v1 a -- ) +.... + +"2!" is a function word that stors two concecutive values v1 and v2 to +the address a from the data stack. Value v1 is stored at address a and +value v2 is stored at address a + 8. diff --git a/adoc/p_Cget.adoc b/adoc/p_Cget.adoc new file mode 100644 index 0000000..cfc03e0 --- /dev/null +++ b/adoc/p_Cget.adoc @@ -0,0 +1,12 @@ +// memory.asm: WORD p_Cget, 'C@',fasm + +anchor:p_Cget[] + +=== Word: C@ + +.... +Data stack: ( a -- v ) +.... + +"C@" is a function word that pushes the byte value v from the address a. + diff --git a/adoc/p_Cput.adoc b/adoc/p_Cput.adoc new file mode 100644 index 0000000..f82682f --- /dev/null +++ b/adoc/p_Cput.adoc @@ -0,0 +1,13 @@ +// memory.asm: WORD p_Cput, 'C!',fasm + +anchor:p_Cput[] + +=== Word: C! + +.... +Data stack: ( v a -- ) +.... + +"C!" is a function word that stores the byte value v (the least +significant byte of the cell) at the address a. + diff --git a/adoc/p_allot.adoc b/adoc/p_allot.adoc index 7844010..304ce2a 100644 --- a/adoc/p_allot.adoc +++ b/adoc/p_allot.adoc @@ -12,20 +12,13 @@ Data stack: ( n -- ) variable with +n+ so as to claim that amount of the heap. ==== -.Word: ALLOT -[caption='Defintion concept {counter:exec}: '] ----- -: ALLOT HERE @ + HERE ! ; ----- -==== - -==== -.Usage example +.Defintion concept for ALLOT **** -HERE @ 16 ALLOT ( -- p ; Claiming 16 bytes ) +( n -- ) : ALLOT HERE @ + HERE ! ; **** ==== -See also <>, <>, <>, <>, -<> and <>. - +==== +.Usage example {counter:example}: claim 16 bytes for variable FOO +CREATE FOO DROP HERE @ 16 ALLOT +==== diff --git a/adoc/p_args.adoc b/adoc/p_args.adoc index a003e7a..825ca35 100644 --- a/adoc/p_args.adoc +++ b/adoc/p_args.adoc @@ -1,15 +1,25 @@ -//rrqforth.asm: WORD p_args,'ARGS',dostring +//rrqforth.asm: WORD p_args,'ARGS',dovalue -anchor:p_args[] +anchor:p_args[MAIN-ARGS] -=== Word: ARGS +=== Word: MAIN-ARGS .... -Data stack: ( -- argv** argc ) +Data stack: ( -- p[argv** argc] ) .... -"ARGS" is a value word that results in pusing the command line -argument block. Here argc is the length of the block, and argv** is a -pointer to a data block of that many asciiz pointers, which are the -command line arguments given to RRQFORTH at start. +"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. +==== +.the command line argument block +[caption='Usage example {counter:example}: '] +---- +ARGS -> 8 bytes: count of non-zero asciiz pointers following + 8 bytes: command name string + 8 bytes: first argument string + 8* ... + 8 zero +---- +==== diff --git a/adoc/p_base.adoc b/adoc/p_base.adoc index a8748b7..fe6d66f 100644 --- a/adoc/p_base.adoc +++ b/adoc/p_base.adoc @@ -17,3 +17,9 @@ supported. See also <>, which holds the mapping table from digits to text. + +==== +.Usage example {counter:example}: claim 16 bytes for variable FOO +[caption='Usage example {counter:example}: '] +CREATE FOO BASE +==== diff --git a/adoc/p_cfa2flags_get.adoc b/adoc/p_cfa2flags_get.adoc new file mode 100644 index 0000000..761ffd2 --- /dev/null +++ b/adoc/p_cfa2flags_get.adoc @@ -0,0 +1,18 @@ +// memory.asm: WORD p_cfa2flags_get, 'CFA>FLAGS@',fasm + +anchor:p_cfa2flags_get[] + +=== Word: CFA>FLAGS@ + +.... +Data stack: ( cfa -- flags ) +.... + +"CFA>FLAGS@" is a function word that pushes word flags of the given cfa. + +==== +.Defintion concept for CFA>FLAGS@ +**** +: CFA>FLAGS@ 16 - @ 16 + ; +**** +==== diff --git a/adoc/p_dfa2tfa.adoc b/adoc/p_dfa2tfa.adoc new file mode 100644 index 0000000..5d1fcda --- /dev/null +++ b/adoc/p_dfa2tfa.adoc @@ -0,0 +1,18 @@ +// memory.asm: WORD p_dfa2tfa, 'DFA>TFA',fasm + +anchor:p_dfa2tfa[] + +=== Word: TFA>DFA + +.... +Data stack: ( dfa -- tfa ) +.... + +"DFA>TFA" is a function word that pushes word tfa of the given dfa. + +==== +.Definition concept for DFA>TFA +**** +: DFA>TFA 24 - @ ; +**** +==== diff --git a/adoc/p_erase.adoc b/adoc/p_erase.adoc new file mode 100644 index 0000000..83b26fe --- /dev/null +++ b/adoc/p_erase.adoc @@ -0,0 +1,13 @@ +// memory.asm: WORD p_erase, 'ERASE',fasm + +anchor:p_erase[] + +=== Word: ERASE + +.... +Data stack: ( a n -- ) +.... + +"ERASE" is a function word that stores n NUL bytes at address a an up. + + diff --git a/adoc/p_get.adoc b/adoc/p_get.adoc new file mode 100644 index 0000000..0c861bc --- /dev/null +++ b/adoc/p_get.adoc @@ -0,0 +1,12 @@ +// memory.asm: WORD p_get, '@',fasm + +anchor:p_get[] + +=== Word: @ + +.... +Data stack: ( a -- v ) +.... + +"@" is a function word that pushes the value v from the address a. + diff --git a/adoc/p_get_n_decrement.adoc b/adoc/p_get_n_decrement.adoc new file mode 100644 index 0000000..b419099 --- /dev/null +++ b/adoc/p_get_n_decrement.adoc @@ -0,0 +1,20 @@ +// memory.asm: WORD p_get_n_decrement, '@n--',fasm + +anchor:p_get_n_decrement[] + +=== Word: @n-- + +.... +Data stack: ( a n -- v ) +.... + +"@n--" is a function word that pushes the value from the address, a, +then decrements the cell at that address by n. + +==== +.Word: @n++ +[caption='Defintion concept {counter:exec}'] +---- +: @n++ OVER @ DUP ROT - ROT ! ; +---- +==== diff --git a/adoc/p_get_n_increment.adoc b/adoc/p_get_n_increment.adoc new file mode 100644 index 0000000..412252b --- /dev/null +++ b/adoc/p_get_n_increment.adoc @@ -0,0 +1,19 @@ +// memory.asm: WORD p_get_n_increment, '@n++',fasm + +anchor:p_get_n_increment[] + +=== Word: @n++ + +.... +Data stack: ( a n -- v ) +.... + +"@n++" is a function word that pushes the value from the address, a, +then increments the cell at that address by n. + +==== +.Defintion concept for @n++ +**** +( a n -- v ) : @n++ OVER @ DUP ROT + ROT ! ; +**** +==== diff --git a/adoc/p_put.adoc b/adoc/p_put.adoc new file mode 100644 index 0000000..3cffc7a --- /dev/null +++ b/adoc/p_put.adoc @@ -0,0 +1,12 @@ +// memory.asm: WORD p_put, '!',fasm + +anchor:p_put[] + +=== Word: ! + +.... +Data stack: ( v a -- ) +.... + +"!" is a function word that stores the cell value v at the address a. + diff --git a/adoc/p_put_plus.adoc b/adoc/p_put_plus.adoc new file mode 100644 index 0000000..420cbe2 --- /dev/null +++ b/adoc/p_put_plus.adoc @@ -0,0 +1,18 @@ +// memory.asm: WORD p_put_plus, '!+',fasm + +anchor:p_put_plus[] + +=== Word: !+ + +.... +Data stack: ( a n -- ) +.... + +"!+" is a function word that adds n to the cell value at a. + +==== +.definition concept for !+ +**** +( a n -- ) : !+ OVER @ + SWAP ! ; +**** +==== diff --git a/adoc/p_rsp.adoc b/adoc/p_rsp.adoc new file mode 100644 index 0000000..9b757da --- /dev/null +++ b/adoc/p_rsp.adoc @@ -0,0 +1,12 @@ +// stack.asm: WORD p_rsp, 'R[n]',fasm + +anchor:p_rsp[] + +=== 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. diff --git a/adoc/p_shift_left.adoc b/adoc/p_shift_left.adoc new file mode 100644 index 0000000..7190b2e --- /dev/null +++ b/adoc/p_shift_left.adoc @@ -0,0 +1,12 @@ +// math.asm: WORD p_shift_left, '<<',fasm + +anchor:p_shift_left[] + +=== Word: << + +.... +Data stack: ( v1 n -- v2 ) +.... + +"<<" is a function word that shifts value v1 n steps left (i.e. +"moving" bits towards more significant bits) to form value v2. diff --git a/adoc/p_shift_right.adoc b/adoc/p_shift_right.adoc new file mode 100644 index 0000000..225e388 --- /dev/null +++ b/adoc/p_shift_right.adoc @@ -0,0 +1,12 @@ +// math.asm: WORD p_shift_right, '>>',fasm + +anchor:p_shift_right[] + +=== Word: >> + +.... +Data stack: ( v1 n -- v2 ) +.... + +">>" is a function word that shifts value v1 n steps right (i.e. +"moving" bits towards less significant bits) to form value v2. diff --git a/adoc/p_shift_signed_right.adoc b/adoc/p_shift_signed_right.adoc new file mode 100644 index 0000000..27a9b7e --- /dev/null +++ b/adoc/p_shift_signed_right.adoc @@ -0,0 +1,13 @@ +// math.asm: WORD p_shift_signed_right, 's>>',fasm + +anchor:p_shift_signed_right[] + +=== Word: s>> + +.... +Data stack: ( v1 n -- v2 ) +.... + +"s>>" is a function word that shifts value v1 n steps right (i.e. +"moving" bits towards less significant bits) to form value v2, but +preserving (and copying) the sign bit. diff --git a/adoc/p_tfa2cfa.adoc b/adoc/p_tfa2cfa.adoc new file mode 100644 index 0000000..22258b3 --- /dev/null +++ b/adoc/p_tfa2cfa.adoc @@ -0,0 +1,18 @@ +// memory.asm: WORD p_tfa2cfa, 'TFA>CFA',fasm + +anchor:p_tfa2cfa[] + +=== Word: TFA>CFA + +.... +Data stack: ( tfa -- cfa ) +.... + +"TFA>CFA" is a function word that pushes word cfa of the given tfa. + +==== +.Definition concept for TFA>CFA +**** +: TFA>CFA 8 + @ ; +**** +==== diff --git a/adoc/p_tfa2dfa.adoc b/adoc/p_tfa2dfa.adoc new file mode 100644 index 0000000..2547fd3 --- /dev/null +++ b/adoc/p_tfa2dfa.adoc @@ -0,0 +1,18 @@ +// memory.asm: WORD p_tfa2dfa, 'TFA>DFA',fasm + +anchor:p_tfa2dfa[] + +=== Word: TFA>DFA + +.... +Data stack: ( tfa -- dfa ) +.... + +"TFA>DFA" is a function word that pushes word dfa of the given tfa. + +==== +.Definition concept for TFA>DFA +**** +: TFA>DFA TFA>CFA 8 + ; +**** +==== diff --git a/adoc/p_tfa2flags_get.adoc b/adoc/p_tfa2flags_get.adoc new file mode 100644 index 0000000..5ded0d4 --- /dev/null +++ b/adoc/p_tfa2flags_get.adoc @@ -0,0 +1,19 @@ +// memory.asm: WORD p_tfa2flags_get, 'TFA>FLAGS@',fasm + +anchor:p_tfa2flags_get[] + +=== Word: TFA>FLAGS@ + +.... +Data stack: ( tfa -- flags ) +.... + +"TFA>FLAGS@" is a function word that pushes word flags of the given tfa. + +==== +.Word: TFA>FLAGS@ +[caption='Defintion concept {counter:exec}'] +---- +: TFA>FLAGS@ 16 + @ ; +---- +==== diff --git a/control.asm b/control.asm index e4051d7..f46d7d4 100644 --- a/control.asm +++ b/control.asm @@ -41,7 +41,7 @@ p_true_branch_SKIP: ;; This prepares for a subsequent THEN to resolve the ;; conditional branch length. mov rax,qword [p_here_DFA] - mov qword [rax],p_zero_branch_DFA + mov qword [rax],p_zero_branch_CFA mov qword [rax+8],0 add rax,16 mov qword [p_here_DFA],rax @@ -65,7 +65,7 @@ p_true_branch_SKIP: ;; the pending (0BRANCH 0) distance to egin the "else-part" of ;; the conditional. mov rax,qword [p_here_DFA] - mov qword [rax],p_branch_DFA + mov qword [rax],p_branch_CFA mov qword [rax+8],0 add rax,16 mov qword [p_here_DFA],rax @@ -84,16 +84,40 @@ p_true_branch_SKIP: push qword 0 next + WORD p_break,'BREAK',fasm,IMMEDIATE + ;; ( 0 * -- 0 a * ) + ;; Lays out a (BRANCH 0) cell pair and marks the current + ;; address for later resolution + mov rax,qword [p_here_DFA] + mov qword [rax],p_branch_CFA + mov qword [rax+8],0 + add rax,16 + mov qword [p_here_DFA],rax + jmp p_ifbreak_elevate + WORD p_ifbreak,'IFBREAK',fasm,IMMEDIATE - ;; ( -- a ) + ;; ( 0 * -- 0 a * ) ;; Lays out a (1BRANCH 0) cell pair and marks the current ;; address for later resolution mov rax,qword [p_here_DFA] - mov qword [rax],p_true_branch_DFA + mov qword [rax],p_true_branch_CFA mov qword [rax+8],0 add rax,16 mov qword [p_here_DFA],rax - push rax + ;; Elevate stack entries until a 0 is found. This places the + ;; IFBREAK pointer below any IF-THEN block pointers +p_ifbreak_elevate: + sub rsp,8 + mov rbx,rsp +p_ifbreak_loop: + add rbx,8 + cmp qword [rbx],0 + je p_ifbreak_end + mov rcx,qword [rbx] + mov qword [rbx-8],rcx + jmp p_ifbreak_loop +p_ifbreak_end: + mov qword [rbx-8],rax next WORD p_ifagain,'IFAGAIN',fasm,IMMEDIATE @@ -101,7 +125,7 @@ p_true_branch_SKIP: ;; Lays out a (1BRANCH ?) cell pair to conditionally repeat ;; from the prior BEGIN. mov rax,qword [p_here_DFA] - mov qword [rax],p_true_branch_DFA + mov qword [rax],p_true_branch_CFA mov qword [rax+8],0 add rax,16 mov qword [p_here_DFA],rax diff --git a/memory.asm b/memory.asm index 335a04d..7d5f144 100644 --- a/memory.asm +++ b/memory.asm @@ -1,12 +1,5 @@ ;;; This file defines "memory access words" - WORD p_cfa2flags_get,'CFA>FLAGS@',fasm - ;; ( cfa -- flags ) - pop rax - cfa2tfa rax - push qword[rax+16] - next - WORD p_tfa2cfa,'TFA>CFA',fasm ;; ( tfa -- cfa ) ;; Advance a word tfa pointer to the cfa field @@ -29,6 +22,13 @@ push qword[rax+16] next + WORD p_cfa2flags_get,'CFA>FLAGS@',fasm + ;; ( cfa -- flags ) + pop rax + cfa2tfa rax + push qword[rax+16] + next + WORD p_dfa2tfa,'DFA>TFA',fasm ;; ( dfa -- tfa ) ;; Advance a word tfa pointer to the dfa field @@ -108,39 +108,55 @@ p_erase_last: jg p_erase_more next - WORD p_1plus, '1+',fasm - ;; ( n1 -- n2 ) - ;; Add one (1) to n1 resulting in n2. - inc qword [rsp] - next - - WORD p_plus_put, '+!',fasm - ;; ( n addr -- ) + WORD p_put_plus, '!+',fasm + ;; ( addr n -- ) ;; Add n to the value at addr. - pop rax pop rbx + pop rax add [rax],rbx next - WORD p_1minus, '1-',fasm - ;; ( n1 -- n2 ) - ;; Subtract one (1) from n1 resulting in n2. - dec qword [rsp] - next - - WORD p_2mult, '2*',fasm - ;; ( x1 -- x2 ) + WORD p_shift_left, '<<',fasm + ;; ( x1 n -- x2 ) ;; x2 is the result of shifting x1 one bit toward the ;; most-significant bit, filling the vacated least-significant ;; bit with zero. - shl qword [rsp],1 + pop rcx + shl qword [rsp],cl next - WORD p_2div, '2/',fasm - ;; ( x1 -- x2 ) + WORD p_shift_right, '>>',fasm + ;; ( x1 n -- x2 ) ;; x2 is the result of shifting x1 one bit toward the ;; least-significant bit, leaving the most-significant bit ;; unchanged. (signed right shift) - sar qword [rsp],1 + pop rcx + shr qword [rsp],cl next + WORD p_shift_signed_right, 's>>',fasm + ;; ( x1 n -- x2 ) + ;; x2 is the result of shifting x1 one bit toward the + ;; least-significant bit, leaving the most-significant bit + ;; unchanged. (signed right shift) + pop rcx + sar qword [rsp],cl + next + + WORD p_get_n_increment,'@n++',fasm + ;; ( a n -- v ) + ;; Fetch value at address then increment that address by n + pop rbx + pop rax + push qword [rax] + add qword [rax],rbx + next + + WORD p_get_n_decrement,'@n--',fasm + ;; ( a n -- v ) + ;; Fetch value at address then decrement that address by n + pop rbx + pop rax + push qword [rax] + sub qword [rax],rbx + next diff --git a/reference.adoc b/reference.adoc index 6237f82..caeedbc 100644 --- a/reference.adoc +++ b/reference.adoc @@ -1,241 +1,241 @@ = RRQFORTH Reference Documentation :author: Ralph Ronnquist +:mult: * -== Compilation Words -// include::compile.adoc[] +== Words Descriptions + +include::adoc/inline_code.adoc[] +include::adoc/p_0branch.adoc[] +include::adoc/p_0equal.adoc[] +include::adoc/p_0less.adoc[] +include::adoc/p_1branch.adoc[] +include::adoc/p_2drop.adoc[] +include::adoc/p_2dup.adoc[] +include::adoc/p_2get.adoc[] +include::adoc/p_2over.adoc[] +include::adoc/p_2put.adoc[] +include::adoc/p_2swap.adoc[] +include::adoc/p_Ccomma.adoc[] +include::adoc/p_Cget.adoc[] +include::adoc/p_Cput.adoc[] +include::adoc/p_Rget.adoc[] +include::adoc/p_Rgt.adoc[] +include::adoc/p_abs.adoc[] include::adoc/p_allot.adoc[] -include::separator.adoc[] +include::adoc/p_and.adoc[] +include::adoc/p_args.adoc[] include::adoc/p_base.adoc[] +include::adoc/p_begin.adoc[] +include::adoc/p_branch.adoc[] +include::adoc/p_cfa2flags_get.adoc[] +include::adoc/p_clear_stream.adoc[] +include::adoc/p_colon.adoc[] +include::adoc/p_comma.adoc[] +include::adoc/p_create.adoc[] +include::adoc/p_current_wordlist.adoc[] +include::adoc/data_stack.adoc[] +include::adoc/p_decimal.adoc[] +include::adoc/p_depth.adoc[] +include::adoc/p_dfa2tfa.adoc[] +include::adoc/p_digits.adoc[] +include::adoc/p_div.adoc[] +include::adoc/p_divmod.adoc[] +include::adoc/p_dodoes.adoc[] +include::adoc/p_does.adoc[] +include::adoc/p_dofasm.adoc[] +include::adoc/p_doforth.adoc[] +include::adoc/p_dostring.adoc[] +include::adoc/p_dot.adoc[] +include::adoc/p_double_quote.adoc[] +include::adoc/p_dovalue.adoc[] +include::adoc/p_dovariable.adoc[] +include::adoc/p_drop.adoc[] +include::adoc/p_dup.adoc[] +include::adoc/p_else.adoc[] +include::adoc/p_emit.adoc[] +include::adoc/p_end.adoc[] +include::adoc/p_equal.adoc[] +include::adoc/p_erase.adoc[] +include::adoc/p_evaluate_stream.adoc[] +include::adoc/p_execute.adoc[] +include::adoc/p_exit.adoc[] +include::adoc/p_false.adoc[] +include::adoc/p_find.adoc[] +include::adoc/p_forth.adoc[] +include::adoc/p_get.adoc[] +include::adoc/p_get_n_decrement.adoc[] +include::adoc/p_get_n_increment.adoc[] +include::adoc/p_greaterequal.adoc[] +include::adoc/p_greaterthan.adoc[] +include::adoc/p_gtR.adoc[] +include::adoc/p_here.adoc[] +include::adoc/p_hex.adoc[] +include::adoc/p_if.adoc[] +include::adoc/p_ifagain.adoc[] +include::adoc/p_ifbreak.adoc[] +include::adoc/p_immediate.adoc[] +include::adoc/p_left_bracket.adoc[] +include::adoc/p_lessequal.adoc[] +include::adoc/p_lessthan.adoc[] +include::adoc/p_literal.adoc[] +include::adoc/p_literal_string.adoc[] +include::adoc/p_lparen.adoc[] +include::adoc/p_malloc.adoc[] +include::adoc/p_minus.adoc[] +include::adoc/p_mult.adoc[] +include::adoc/p_negate.adoc[] +include::adoc/p_nip.adoc[] +include::adoc/p_nl.adoc[] +include::adoc/p_not.adoc[] +include::adoc/p_number.adoc[] +include::adoc/p_or.adoc[] +include::adoc/p_over.adoc[] +include::adoc/p_pad.adoc[] +include::adoc/p_pick.adoc[] +include::adoc/p_plus.adoc[] +include::adoc/p_program_version.adoc[] +include::adoc/p_put.adoc[] +include::adoc/p_put_plus.adoc[] +include::adoc/p_quit.adoc[] +include::adoc/p_quote.adoc[] +include::adoc/p_read_stream_char.adoc[] +include::adoc/p_read_word.adoc[] +include::adoc/p_realloc.adoc[] +include::adoc/p_right_bracket.adoc[] +include::adoc/p_roll.adoc[] +include::adoc/p_rot.adoc[] +include::adoc/p_rsp.adoc[] +include::adoc/p_semicolon.adoc[] +include::adoc/p_shift_left.adoc[] +include::adoc/p_shift_right.adoc[] +include::adoc/p_shift_signed_right.adoc[] +include::adoc/p_sp.adoc[] +include::adoc/p_state.adoc[] +include::adoc/p_stdin.adoc[] +include::adoc/p_stream.adoc[] +include::adoc/p_stream_nchars.adoc[] +include::adoc/p_strlen.adoc[] +include::adoc/p_strncmp.adoc[] +include::adoc/p_strncpy.adoc[] +include::adoc/p_swap.adoc[] +include::adoc/p_system.adoc[] +include::adoc/p_tell.adoc[] +include::adoc/p_terminate0.adoc[] +include::adoc/p_tfa2cfa.adoc[] +include::adoc/p_tfa2dfa.adoc[] +include::adoc/p_tfa2flags_get.adoc[] +include::adoc/p_then.adoc[] +include::adoc/p_this_word.adoc[] +include::adoc/p_true.adoc[] +include::adoc/p_tuck.adoc[] +include::adoc/p_unequal.adoc[] +include::adoc/p_within.adoc[] +include::adoc/p_words.adoc[] +include::adoc/p_xor.adoc[] +include::adoc/return_stack.adoc[] +include::separator.adoc[] +include::separator.adoc[] include::separator.adoc[] -include::adoc/p_Ccomma.adoc[] include::separator.adoc[] -include::adoc/p_colon.adoc[] include::separator.adoc[] -include::adoc/p_comma.adoc[] include::separator.adoc[] -include::adoc/p_create.adoc[] include::separator.adoc[] -include::adoc/p_decimal.adoc[] include::separator.adoc[] -include::adoc/p_div.adoc[] include::separator.adoc[] -include::adoc/p_does.adoc[] include::separator.adoc[] -include::adoc/p_evaluate_stream.adoc[] include::separator.adoc[] -include::adoc/p_here.adoc[] include::separator.adoc[] -include::adoc/p_hex.adoc[] include::separator.adoc[] -include::adoc/p_immediate.adoc[] include::separator.adoc[] -include::adoc/p_left_bracket.adoc[] include::separator.adoc[] -include::adoc/p_literal.adoc[] include::separator.adoc[] -include::adoc/p_literal_string.adoc[] include::separator.adoc[] -include::adoc/p_number.adoc[] include::separator.adoc[] -include::adoc/p_quote.adoc[] include::separator.adoc[] -include::adoc/p_right_bracket.adoc[] include::separator.adoc[] -include::adoc/p_semicolon.adoc[] include::separator.adoc[] -include::adoc/p_state.adoc[] include::separator.adoc[] -include::adoc/p_this_word.adoc[] - -== Execution Control Words -//include::control.adoc[] -include::adoc/p_0branch.adoc[] include::separator.adoc[] -include::adoc/p_1branch.adoc[] include::separator.adoc[] -include::adoc/p_begin.adoc[] include::separator.adoc[] -include::adoc/p_branch.adoc[] include::separator.adoc[] -include::adoc/p_else.adoc[] include::separator.adoc[] -include::adoc/p_end.adoc[] include::separator.adoc[] -include::adoc/p_if.adoc[] include::separator.adoc[] -include::adoc/p_ifagain.adoc[] include::separator.adoc[] -include::adoc/p_ifbreak.adoc[] include::separator.adoc[] -include::adoc/p_then.adoc[] - -== Logic Operation Words -//include::logic.adoc[] -include::adoc/p_0equal.adoc[] include::separator.adoc[] -include::adoc/p_0less.adoc[] include::separator.adoc[] -include::adoc/p_and.adoc[] include::separator.adoc[] -include::adoc/p_equal.adoc[] include::separator.adoc[] -include::adoc/p_false.adoc[] include::separator.adoc[] -include::adoc/p_greaterequal.adoc[] include::separator.adoc[] -include::adoc/p_greaterthan.adoc[] include::separator.adoc[] -include::adoc/p_lessequal.adoc[] include::separator.adoc[] -include::adoc/p_lessthan.adoc[] include::separator.adoc[] -include::adoc/p_not.adoc[] include::separator.adoc[] -include::adoc/p_or.adoc[] include::separator.adoc[] -include::adoc/p_true.adoc[] include::separator.adoc[] -include::adoc/p_unequal.adoc[] include::separator.adoc[] -include::adoc/p_within.adoc[] include::separator.adoc[] -include::adoc/p_xor.adoc[] - -== Math Operation Words -// include::math.adoc[] -include::adoc/p_abs.adoc[] include::separator.adoc[] -include::adoc/p_divmod.adoc[] include::separator.adoc[] -include::adoc/p_minus.adoc[] include::separator.adoc[] -include::adoc/p_mult.adoc[] include::separator.adoc[] -include::adoc/p_negate.adoc[] include::separator.adoc[] -include::adoc/p_plus.adoc[] - -== RRQFORTH Main Words -//include::rrqforth.adoc[] -include::adoc/data_stack.adoc[] include::separator.adoc[] -include::adoc/inline_code.adoc[] include::separator.adoc[] -include::adoc/p_args.adoc[] include::separator.adoc[] -include::adoc/p_dodoes.adoc[] include::separator.adoc[] -include::adoc/p_dofasm.adoc[] include::separator.adoc[] -include::adoc/p_doforth.adoc[] include::separator.adoc[] -include::adoc/p_dostring.adoc[] include::separator.adoc[] -include::adoc/p_dovalue.adoc[] include::separator.adoc[] -include::adoc/p_dovariable.adoc[] include::separator.adoc[] -include::adoc/p_execute.adoc[] include::separator.adoc[] -include::adoc/p_exit.adoc[] include::separator.adoc[] -include::adoc/p_lparen.adoc[] include::separator.adoc[] -include::adoc/p_program_version.adoc[] include::separator.adoc[] -include::adoc/p_quit.adoc[] include::separator.adoc[] -include::adoc/p_stdin.adoc[] include::separator.adoc[] -include::adoc/p_system.adoc[] include::separator.adoc[] -include::adoc/p_terminate0.adoc[] include::separator.adoc[] -include::adoc/return_stack.adoc[] - -== Stack operation words -//include::stack.adoc[] -include::adoc/p_2drop.adoc[] include::separator.adoc[] -include::adoc/p_2dup.adoc[] include::separator.adoc[] -include::adoc/p_2over.adoc[] include::separator.adoc[] -include::adoc/p_2swap.adoc[] include::separator.adoc[] -include::adoc/p_depth.adoc[] include::separator.adoc[] -include::adoc/p_drop.adoc[] include::separator.adoc[] -include::adoc/p_dup.adoc[] include::separator.adoc[] -include::adoc/p_gtR.adoc[] include::separator.adoc[] -include::adoc/p_nip.adoc[] include::separator.adoc[] -include::adoc/p_over.adoc[] include::separator.adoc[] -include::adoc/p_pick.adoc[] include::separator.adoc[] -include::adoc/p_Rget.adoc[] include::separator.adoc[] -include::adoc/p_Rgt.adoc[] include::separator.adoc[] -include::adoc/p_roll.adoc[] include::separator.adoc[] -include::adoc/p_rot.adoc[] include::separator.adoc[] -include::adoc/p_swap.adoc[] include::separator.adoc[] -include::adoc/p_tuck.adoc[] - -== Input/output words -//include::stdio.adoc[] -include::adoc/p_clear_stream.adoc[] include::separator.adoc[] -include::adoc/p_digits.adoc[] include::separator.adoc[] -include::adoc/p_dot.adoc[] include::separator.adoc[] -include::adoc/p_double_quote.adoc[] include::separator.adoc[] -include::adoc/p_emit.adoc[] include::separator.adoc[] -include::adoc/p_malloc.adoc[] include::separator.adoc[] -include::adoc/p_nl.adoc[] include::separator.adoc[] -include::adoc/p_pad.adoc[] include::separator.adoc[] -include::adoc/p_read_stream_char.adoc[] include::separator.adoc[] -include::adoc/p_read_word.adoc[] include::separator.adoc[] -include::adoc/p_realloc.adoc[] include::separator.adoc[] -include::adoc/p_sp.adoc[] include::separator.adoc[] -include::adoc/p_stream.adoc[] include::separator.adoc[] -include::adoc/p_stream_nchars.adoc[] include::separator.adoc[] -include::adoc/p_tell.adoc[] - -== Wordlist words -//include::wordlists.adoc[] -include::adoc/p_current_wordlist.adoc[] include::separator.adoc[] -include::adoc/p_find.adoc[] include::separator.adoc[] -include::adoc/p_forth.adoc[] include::separator.adoc[] -include::adoc/p_strlen.adoc[] include::separator.adoc[] -include::adoc/p_strncmp.adoc[] include::separator.adoc[] -include::adoc/p_strncpy.adoc[] include::separator.adoc[] -include::adoc/p_words.adoc[] == System calls //include::syscalls.adoc[] diff --git a/rrqforth.asm b/rrqforth.asm index 5d36030..f7f310a 100644 --- a/rrqforth.asm +++ b/rrqforth.asm @@ -168,10 +168,14 @@ include 'compile.asm' ;; Initialised to hold a STREAM for fd 0 dq 0 - WORD p_args,'ARGS',dostring + WORD p_args,'MAIN-ARGS',dovalue ;; Pointer to initial argument block dq 0 ; *(int argc,(char*[argc]) argv) + WORD p_verboseQ,'VERBOSE?',dovariable + ;; Flags whether the running is in verbose mode ot not + dq 0 ; + WORD p_lparen,'(',fasm,IMMEDIATE pushr rsi p_lparen_loop: @@ -194,12 +198,46 @@ p_lparen_exit: next ;;; ******** The main entry point. ******** +;;; This could be set up as a WORD but it isn't + main: ;; Initial rsp points to the arguments block of size (64 bits) ;; followed by the argument pointers. mov qword [p_args_DFA],rsp + call main_is_verbose + mov qword [p_verboseQ_DFA],rdx jmp p_quit_DFA ; QUIT + ;; Subroutine to check the command line for a "-v" + ;; return boolean in rdx + ;; implementation for that 2 byte asciiz string +main_is_verbose_data: + dq main_is_verbose_data_end - $ ; length of data + db '-v',0 +main_is_verbose_data_end: + +main_is_verbose: + mov rbx,qword [p_args_DFA] ; Pointer to main arguments + mov r8,qword [rbx] + xor rdx,rdx + cld +main_is_verbose_next: + dec r8 + jl main_is_not_verbose + add rbx,8 + mov rsi,qword [rbx] + mov rdi,main_is_verbose_data + lodsq + mov rcx,rax +main_is_verbose_loop: + cmpsb + jne main_is_verbose_next + dec rcx + jg main_is_verbose_loop + not rdx +main_is_not_verbose: + ret + ;;; This word is also the last word before syscalls last_forth_word: WORD p_quit,'QUIT',fasm @@ -218,8 +256,12 @@ last_forth_word: p_quit_INITIALIZED: ;; Initial blurb FORTH + dq p_verboseQ + dq p_get + BRANCH 0,p_quit_EVAL dq p_program_version dq p_tell +p_quit_EVAL: dq p_stdin dq p_evaluate_stream BRANCH 0,p_quit_ERROR diff --git a/stack.asm b/stack.asm index d867276..5b6910b 100644 --- a/stack.asm +++ b/stack.asm @@ -151,3 +151,12 @@ p_roll_eq: ;; Copy x from the return stack to the data stack. push qword [rbp] next + + WORD p_rsp,'R[n]',fasm + ;; ( n -- a ) + ;; push the address of the n:th cell on the return stack + mov rax,qword [rsp] + shl rax,3 + add rax,rbp + mov qword [rsp],rax + next diff --git a/wordindex.adoc b/wordindex.adoc index 252fd2e..6ab01d4 100644 --- a/wordindex.adoc +++ b/wordindex.adoc @@ -1,6 +1,7 @@ == Index of word links +xref:p_lparen[(] {nbsp} xref:p_colon[: (colon)] {nbsp} xref:p_semicolon[: (semi-colon)] {nbsp} xref:p_comma[, (comma)] {nbsp} @@ -11,24 +12,37 @@ xref:p_left_bracket[[ (left bracket)] {nbsp} xref:p_right_bracket[\] (right bracket)] {nbsp} xref:p_lessthan[<] {nbsp} -xref:p_equal[= ] {nbsp} -xref:p_greaterthan[>] {nbsp} -xref:p_lparen[(] {nbsp} -xref:p_minus[ - ] {nbsp} -xref:p_mult[*] {nbsp} -xref:p_plus[+] {nbsp} -xref:p_div[/] {nbsp} -{nbsp} -xref:p_0equal[0=] {nbsp} -xref:p_0less[0<] {nbsp} xref:p_lessequal[\<=] {nbsp} +xref:p_equal[=] {nbsp} xref:p_unequal[!=] {nbsp} +xref:p_greaterthan[>] {nbsp} xref:p_greaterequal[>= ] {nbsp} +xref:p_0equal[0=] {nbsp} +xref:p_0less[0<] {nbsp} +xref:p_minus[-] {nbsp} +xref:p_mult[{mult}] {nbsp} +xref:p_plus[{plus}] {nbsp} +xref:p_div[/] {nbsp} +xref:p_shift_left[<<] {nbsp} +xref:p_shift_right[>>] {nbsp} +xref:p_shift_signed_right[s>>] {nbsp} + + +xref:p_get[@] {nbsp} +xref:p_put[!] {nbsp} +xref:p_Cget[C@] {nbsp} +xref:p_Cput[C!] {nbsp} +xref:p_2get[2@] {nbsp} +xref:p_2put[2!] {nbsp} +xref:p_put_plus[!{plus}] {nbsp} +xref:p_get_n_increment[@n{plus}{plus}] {nbsp} +xref:p_get_n_decrement[@n--] {nbsp} xref:p_Ccomma[C,] {nbsp} xref:p_literal_string[S"] {nbsp} xref:p_gtR[>R] {nbsp} xref:p_Rget[R@] {nbsp} -xref:ef:p_Rgt[R>] {nbsp} +xref:p_Rgt[R>] {nbsp} +<> {nbsp} xref:data_stack[DATA-STACK] {nbsp} xref:return_stack[RETURN-STACK] {nbsp} @@ -45,7 +59,6 @@ xref:p_2swap[2SWAP] {nbsp} xref:p_abs[ABS] {nbsp} xref:p_allot[ALLOT] {nbsp} xref:p_and[AND] {nbsp} -xref:p_args[ARGS] {nbsp} xref:inline_code[[ASM]] {nbsp} xref:p_base[BASE] {nbsp} @@ -90,6 +103,7 @@ xref:p_immediate[IMMEDIATE] {nbsp} xref:p_literal[LIT] {nbsp} +xref:p_args[MAIN-ARGS] {nbsp} xref:p_malloc[MALLOC] {nbsp} xref:p_negate[NEGATE] {nbsp} @@ -126,6 +140,7 @@ xref:p_system[SYSTEM] {nbsp} xref:p_tell[TELL] {nbsp} xref:p_terminate0[TERMINATE0] {nbsp} +xref:p_cfa2flags_get[TFA>FLAGS@] {nbsp} xref:p_then[THEN] {nbsp} xref:p_this_word[THIS-WORD] {nbsp} xref:p_true[TRUE] {nbsp}