diff options
| author | Mel <einebeere@gmail.com> | 2022-08-17 00:07:35 +0000 |
|---|---|---|
| committer | Mel <einebeere@gmail.com> | 2022-08-17 00:07:35 +0000 |
| commit | be6cd2217b6bb1bb411d46ebd9d003dfd928af96 (patch) | |
| tree | 94e5807aae0fb65d2768adce594e245052ecf578 /cmd | |
| parent | d84c0f36afcde4e5af2907d70931de75957d5277 (diff) | |
| download | jinx-be6cd2217b6bb1bb411d46ebd9d003dfd928af96.tar.zst jinx-be6cd2217b6bb1bb411d46ebd9d003dfd928af96.zip | |
Add different "say" outputs to VM
Diffstat (limited to 'cmd')
| -rw-r--r-- | cmd/lang/main.go | 26 | ||||
| -rw-r--r-- | cmd/vm/main.go | 9 |
2 files changed, 16 insertions, 19 deletions
diff --git a/cmd/lang/main.go b/cmd/lang/main.go index f5046a7..c5c0fe6 100644 --- a/cmd/lang/main.go +++ b/cmd/lang/main.go @@ -8,6 +8,8 @@ import ( "jinx/pkg/lang/scanner" "jinx/pkg/lang/vm" "os" + "os/user" + "path" ) func main() { @@ -20,12 +22,12 @@ func main() { exit("nothing to do, either -c or -r is required") } - path := flag.Arg(0) - if path == "" { + filePath := flag.Arg(0) + if filePath == "" { exit("no file specified") } - file, err := os.Open(path) + file, err := os.Open(filePath) if err != nil { exit("could not open file: %v", err) } @@ -43,7 +45,7 @@ func main() { exit("error during parsing: %v", err) } - comp := compiler.New("program", "noone", program) + comp := compiler.New(path.Base(filePath), getUsername(), program) module, err := comp.Compile() if err != nil { exit("compilation failed: %v", err) @@ -62,18 +64,20 @@ func main() { } if *run { - vm := vm.New(module) + vm := vm.New(module, vm.NewConsoleOutput()) if err := vm.Run(); err != nil { exit("execution failed: %v", err) } + } +} - res, err := vm.GetResult() - if err != nil { - exit("could not get result: %v", err) - } - - fmt.Println(res) +func getUsername() string { + me, err := user.Current() + if err != nil { + return "unknown" } + + return me.Username } func exit(format string, args ...any) { diff --git a/cmd/vm/main.go b/cmd/vm/main.go index ecebcbf..bb8f142 100644 --- a/cmd/vm/main.go +++ b/cmd/vm/main.go @@ -91,17 +91,10 @@ func main() { } if *run { - vm := vm.New(modules.NewUnknownModule(&bc)) + vm := vm.New(modules.NewUnknownModule(&bc), vm.NewConsoleOutput()) if err := vm.Run(); err != nil { exit("execution failed: %v", err) } - - res, err := vm.GetResult() - if err != nil { - exit("could not get result: %v", err) - } - - fmt.Println(res) } } |
