about summary refs log tree commit diff
path: root/cmd/lang/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/lang/main.go')
-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) {