adding the AGAIN control word
authorRalph Ronnquist <ralph.ronnquist@gmail.com>
Fri, 4 Jun 2021 08:27:33 +0000 (18:27 +1000)
committerRalph Ronnquist <ralph.ronnquist@gmail.com>
Fri, 4 Jun 2021 08:27:33 +0000 (18:27 +1000)
adoc/p_again.adoc [new file with mode: 0644]
control.asm
reference.adoc
wordindex.adoc

diff --git a/adoc/p_again.adoc b/adoc/p_again.adoc
new file mode 100644 (file)
index 0000000..62e72f1
--- /dev/null
@@ -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
+<<p_begin,BEGIN>> and instead of <<p_end,END>> 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
+<<p_end,END>> compile action to end the block.
index b6bfe0f005e964ce1773fa025d7d618e01ea95e4..949f48c7110c262c6683bbfafaf44d8c1cbcf0b9 100644 (file)
@@ -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
index 1700ddf714b8720640baf6479c47ebe9558dc211..7bf6815b1682f9c91bd5ef0f19c1965fa2662e62 100644 (file)
@@ -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[]
index ebac8532ee0c4ce0606f8637eaa7281edfbf004f..2ffe08ea99ad9cb86fef027652047fc1266e01b1 100644 (file)
@@ -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}
 <<inline_code,[ASM]>> {nbsp}