From: Ralph Ronnquist Date: Fri, 4 Jun 2021 08:27:33 +0000 (+1000) Subject: adding the AGAIN control word X-Git-Url: https://git.rrq.au/?a=commitdiff_plain;ds=sidebyside;h=421b56b401697dda99a7cfe402f16943ea094cd6;hp=92ed95a59cba9c0685150503196877c3d81fedbc;p=rrq%2Frrqforth.git adding the AGAIN control word --- diff --git a/adoc/p_again.adoc b/adoc/p_again.adoc new file mode 100644 index 0000000..62e72f1 --- /dev/null +++ b/adoc/p_again.adoc @@ -0,0 +1,16 @@ +// control.asm: WORD p_again,'AGAIN',fasm + +anchor:p_again[] + +=== Word: AGAIN + +.... +Data stack: Compiling: ( -- a ) +.... + +"AGAIN" is an immediate function word that is used together with +<> and instead of <> 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 +<> compile action to end the block. diff --git a/control.asm b/control.asm index b6bfe0f..949f48c 100644 --- a/control.asm +++ b/control.asm @@ -165,4 +165,23 @@ p_end_ending: pop rbx next - + WORD p_again,'AGAIN',fasm,IMMEDIATE + ;; Compiling: ( a 0 * -- ) + ;; Lay out unconditional loop-back, then perform END action + 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 + mov rbx,rsp +p_again_loop: + cmp qword [rbx],0 + je p_ifagain_resolve + add rbx,8 + jmp p_ifagain_loop +p_again_resolve: + mov rbx,qword [rbx+8] + sub rbx,rax + mov qword [rax-8],rbx + mov rax,rsp + jmp p_end_scan diff --git a/reference.adoc b/reference.adoc index 1700ddf..7bf6815 100644 --- a/reference.adoc +++ b/reference.adoc @@ -41,6 +41,8 @@ include::adoc/p_Rgt.adoc[] include::separator.adoc[] include::adoc/p_abs.adoc[] include::separator.adoc[] +include::adoc/p_again.adoc[] +include::separator.adoc[] include::adoc/p_allot.adoc[] include::separator.adoc[] include::adoc/p_and.adoc[] diff --git a/wordindex.adoc b/wordindex.adoc index ebac853..2ffe08e 100644 --- a/wordindex.adoc +++ b/wordindex.adoc @@ -58,6 +58,7 @@ xref:p_2over[2OVER] {nbsp} xref:p_2swap[2SWAP] {nbsp} xref:p_abs[ABS] {nbsp} +xref:p_again[AGAIN] {nbsp} xref:p_allot[ALLOT] {nbsp} xref:p_and[AND] {nbsp} <> {nbsp}