commit db3662f7b9ef73095cef59148851832b56e3e881
parent 9fe75ac071f656cef8dd0135d5edca314f8a9bc1
Author: Henry Wilson <m3henry@googlemail.com>
Date: Mon, 19 Jun 2017 19:52:16 +0100
first interpreter running
Diffstat:
M | main.s | | | 63 | +++++++++++++++++++++++++++++++++++++++++++++++++-------------- |
M | makefile | | | 2 | +- |
2 files changed, 50 insertions(+), 15 deletions(-)
diff --git a/main.s b/main.s
@@ -2,7 +2,7 @@
.quad \label
.endm
-.macro forthword
+.macro forthword name
do enter
.endm
@@ -31,13 +31,17 @@
do store
.endm
-.macro string msg
- do dostr
+.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
@@ -88,6 +92,20 @@
do plus
.endm
+.macro verb name:req altname end
+.ifnb \end
+ .quad 0
+.else
+ .quad 7b - 8
+.endif
+.ifnb \altname
+7: strlit "\altname\()"
+.else
+7: strlit "\name\()"
+.endif
+\name\():
+.endm
+
.data
cold: forthword
@@ -108,13 +126,7 @@ quit: forthword
do inputtest
set numin 0
1: do getword
- do dup
- do print
- string "VERYLONGWORDIE"
- do strcmp
- unless 2f
- say " *"
- 2: do cr
+ do find
get numin
get numtib
do less
@@ -178,7 +190,28 @@ getword: forthword
do pad
endword
-greet: forthword
+find: forthword
+ const dictionaryhead
+2: do dup2
+ const 8
+ do plus
+ do strcmp
+ unless 1f
+ const 16
+ do plus
+ do swap
+ do fetch
+ do plus
+ do execute
+ endword
+1: do fetch
+ do dup
+ if 2b
+ do drop2
+ endword
+
+verb greet "GREET" end
+ forthword
say "Hello, World!"
do cr
endword
@@ -202,7 +235,8 @@ line: forthword
do cr
endword
-star: forthword
+verb star "STAR"
+ forthword
const '*'
do emit
endword
@@ -222,8 +256,9 @@ numtib: forthword
numin: forthword
variable
endword
-
-cr: forthword
+dictionaryhead:
+verb cr "CR"
+ forthword
const '\n'
do emit
endword
diff --git a/makefile b/makefile
@@ -1,6 +1,6 @@
all: bin/aFORTH
@echo Testing...
- @/bin/echo -ne "TEST VERYLONGWORDIE DIFFERENTWORDY DUP" | bin/aFORTH
+ @/bin/echo -ne "STAR CR WORDY GREET" | bin/aFORTH
bin/aFORTH: obj/main.o
@echo Linking...