commit 6f90630f1d0bbf48737a8556b0b2b0772f8d5fc8
parent 2bb5669ea3e5d66fab6c4c67b92d1dd9b2808add
Author: Henry Wilson <m3henry@googlemail.com>
Date: Tue, 20 Jun 2017 04:21:25 +0100
split macros in to own file
Diffstat:
A | macros.i | | | 150 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 file changed, 150 insertions(+), 0 deletions(-)
diff --git a/macros.i b/macros.i
@@ -0,0 +1,150 @@
+.macro do label
+ .quad \label
+.endm
+
+.macro forthword name
+ do enter
+.endm
+
+.macro endword
+ do EXIT
+.endm
+
+.macro const val
+ do docon
+ .quad \val
+.endm
+
+.macro variable
+ do dovar
+ .quad 0
+.endm
+
+.macro get var
+ do \var
+ do fetch
+.endm
+
+.macro set var:req value
+.ifnb \value
+ const \value
+.endif
+ do \var
+ do store
+.endm
+
+.macro strlit msg
+ .quad 9f - 8f
+8: .ascii "\msg\()"
+9:
+.endm
+
+.macro string msg
+ do dostr
+ strlit "\msg\()"
+.endm
+
+.macro say msg
+ string "\msg\()"
+ do PRINT
+.endm
+
+.macro saycr msg
+ say "\msg\()\n"
+.endm
+
+.macro scratch length
+ const 8f
+ goto 9f
+8: .skip \length
+9:
+.endm
+
+.macro goto label
+ do dogoto
+ .quad \label
+.endm
+
+.macro if label
+ do dobranch
+ .quad \label
+.endm
+
+.macro test compare:req value:req target:req
+ do DUP
+ const \value
+ do \compare
+ if \target
+.endm
+
+.macro unless label
+ do NOT
+ if \label
+.endm
+
+.macro debug
+ do DUP
+ do dot
+ do CR
+.endm
+
+.macro offset var distance
+ do \var
+ const \distance
+ do plus
+.endm
+
+.macro verb type:req name:req altname end
+.ifnb \end
+ .quad 0
+.else
+ .quad 7b - 8
+.endif
+.ifnb \altname
+7: strlit "\altname\()"
+.else
+7: strlit "\name\()"
+.endif
+\name\(): \type\()word
+.endm
+
+# Codeword macros
+
+.macro codeword
+ .quad . + 8
+.endm
+
+.macro advance register
+ add $8, \register
+.endm
+
+.macro retreat register
+ sub $8, \register
+.endm
+
+# Stack manipulation
+
+.macro _dup
+ advance SP
+ mov TOS, (SP)
+.endm
+
+# Comparison
+
+.macro compare op name altname
+verb code \name "\altname\()"
+ cmp TOS, (SP)
+ \op truecmp
+ movq $0, (SP)
+ jmp _drop
+.endm
+
+.macro cmpaddr op name altname
+verb code \name "\altname\()"
+ mov (SP), ACC
+ mov (ACC), ACC
+ cmp (TOS), ACC
+ \op truecmp
+ movq $0, (SP)
+ jmp _drop
+.endm