aboutsummaryrefslogtreecommitdiff
path: root/cmd/headless_interpreter/main.go
diff options
context:
space:
mode:
authorJulien Dessaux2021-09-23 00:24:53 +0200
committerJulien Dessaux2021-09-23 00:24:53 +0200
commite3bc1251e8cb20b30d0c5a27cd1da8f147a82de7 (patch)
treeffaaee42eedb2a380d45b6710f43a6c1350a080d /cmd/headless_interpreter/main.go
parentFixed test order mistake between expected value and got value (diff)
downloadgofunge98-e3bc1251e8cb20b30d0c5a27cd1da8f147a82de7.tar.gz
gofunge98-e3bc1251e8cb20b30d0c5a27cd1da8f147a82de7.tar.bz2
gofunge98-e3bc1251e8cb20b30d0c5a27cd1da8f147a82de7.zip
Began coding the interpreter (only manages the minimal example for now!)
Diffstat (limited to '')
-rw-r--r--cmd/headless_interpreter/main.go42
1 files changed, 42 insertions, 0 deletions
diff --git a/cmd/headless_interpreter/main.go b/cmd/headless_interpreter/main.go
new file mode 100644
index 0000000..73b71dc
--- /dev/null
+++ b/cmd/headless_interpreter/main.go
@@ -0,0 +1,42 @@
+package main
+
+import (
+ "flag"
+ "fmt"
+ "os"
+
+ "git.adyxax.org/adyxax/gofunge/pkg/field"
+ "git.adyxax.org/adyxax/gofunge/pkg/interpreter"
+ "git.adyxax.org/adyxax/gofunge/pkg/pointer"
+)
+
+func main() {
+ filename := flag.String("f", "", "b98 file to interpret")
+ help := flag.Bool("h", false, "display this help message")
+ flag.Parse()
+
+ if *help {
+ flag.Usage()
+ os.Exit(0)
+ }
+
+ if *filename == "" {
+ fmt.Println("Error : no b98 file to interpret")
+ flag.Usage()
+ os.Exit(1)
+ }
+ file, err := os.Open(*filename)
+ if err != nil {
+ fmt.Printf("Failed to open file %s : %+v", *filename, err)
+ os.Exit(2)
+ }
+ defer file.Close()
+
+ f, err := field.Load(file)
+ if err != nil {
+ fmt.Printf("Failed to load file %s : %+v", *filename, err)
+ os.Exit(3)
+ }
+
+ interpreter.NewInterpreter(f, pointer.NewPointer()).Run()
+}