aboutsummaryrefslogtreecommitdiff
path: root/cmd/lang
diff options
context:
space:
mode:
authorMel <einebeere@gmail.com>2022-08-17 00:07:35 +0000
committerMel <einebeere@gmail.com>2022-08-17 00:07:35 +0000
commitbe6cd2217b6bb1bb411d46ebd9d003dfd928af96 (patch)
tree94e5807aae0fb65d2768adce594e245052ecf578 /cmd/lang
parentd84c0f36afcde4e5af2907d70931de75957d5277 (diff)
downloadjinx-be6cd2217b6bb1bb411d46ebd9d003dfd928af96.tar.zst
jinx-be6cd2217b6bb1bb411d46ebd9d003dfd928af96.zip
Add different "say" outputs to VM
Diffstat (limited to 'cmd/lang')
-rw-r--r--cmd/lang/main.go26
1 files changed, 15 insertions, 11 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) {