Began coding the interpreter (only manages the minimal example for now!)

This commit is contained in:
Julien Dessaux 2021-09-23 00:24:53 +02:00
parent 6f70a7237b
commit e3bc1251e8
4 changed files with 99 additions and 0 deletions

View file

@ -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()
}