aboutsummaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
Diffstat (limited to 'cmd')
-rw-r--r--cmd/lang/main.go26
-rw-r--r--cmd/vm/main.go9
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)
}
}