commit 20ab077b0d8e5f9fcbacbcb1b910280e21abbce2
parent 851e14e221f26bfe3d4b2f3ffc4d2f412b7fc534
Author: Pavel Renev <an2qzavok@gmail.com>
Date: Mon, 4 Oct 2021 13:55:10 +0300
start debugging
Diffstat:
M | fortum.go | | | 2 | ++ |
M | third.go | | | 89 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- |
2 files changed, 89 insertions(+), 2 deletions(-)
diff --git a/fortum.go b/fortum.go
@@ -149,6 +149,7 @@ func (F *First) define() error {
if err != nil {
return err
}
+ fmt.Printf("[%s]", s)
F.strings = append(F.strings, s)
id := len(F.strings) - 1
F.Compile(F.lwp, id, -2)
@@ -162,6 +163,7 @@ func (F *First) _read() error {
if err != nil {
return err
}
+ fmt.Printf("(%s)", s)
wp := F.findWord(s)
if wp != 0 {
err = F.rpush(F.pc)
diff --git a/third.go b/third.go
@@ -1,6 +1,6 @@
package main
-const third string = `
+var third string = `
: r 1 exit
: ]
@@ -69,6 +69,91 @@ main
: dec dup @ 1 - swap ! ;
+: tor
+ r @ @
+ swap
+ r @ !
+ r @ 1 + r !
+ r @ !
+;
-`
+: fromr
+ r @ @
+ r @ 1 - r !
+ r @ @
+ swap
+ r @ !
+;
+
+: tail fromr fromr drop tor ;
+
+: minus 0 swap 0 ;
+
+: bnot 1 swap - ;
+
+: < - <0 ;
+
+: logical
+ dup
+ 0 <
+ swap minus
+ 0 <
+ +
+;
+: not logical bnot ;
+
+: = - not ;
+
+: branch
+ r @
+ @
+ @
+ r @ @
+ +
+ r + !
+;
+
+: computebranch 1 - * 1 + ;
+
+: notbranch
+ not
+ r @ @ @
+ computebranch
+ r @ @ +
+ r @ !
+;
+
+: here h @ ;
+
+: if immediate
+ ' notbranch ,
+ here
+ 0 ,
+;
+
+: then immediate
+ dup
+ here
+ swap -
+ swap !
+;
+
+: find-)
+ key
+ ')' =
+ not if
+ tail find -)
+ then
+;
+
+: ( immediate
+ find-)
+;
+
+(we should be able to do FORTH-style comments now )
+
+( now that we've got comments, we can comment the rest of the code
+ in a legitimate [self parsing] fashion. Note that you can't
+ nest parentheses... )
+`