Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Isaiah Becker-Mayer authored and Isaiah Becker-Mayer committed Jan 22, 2024
1 parent d823f1c commit ada1356
Show file tree
Hide file tree
Showing 4 changed files with 377 additions and 368 deletions.
13 changes: 9 additions & 4 deletions Compiler/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"fmt"
"log"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -29,7 +30,8 @@ func main() {
// First argument should be .jack file or directory of .jack files. Currently
// do not support multiple directory builds.
if len(os.Args) < 2 {
panic("program requires the first argument be a path to .jack file or directory that contains at least one .jack file")
fmt.Printf("program requires the first argument be a path to .jack file or directory that contains at least one .jack file")
os.Exit(1)
}
toCompile := os.Args[1]
var files []string
Expand All @@ -46,18 +48,21 @@ func main() {
}
return nil
}); err != nil {
panic(err.Error())
log.Printf("%v", err)
os.Exit(1)
}
if len(files) == 0 {
panic(fmt.Sprintf("invalid compilation input: \"%v\"; first argument must be either a .jack file or a directory with at least one .jack file in it", toCompile))
log.Printf("invalid compilation input: \"%v\"; first argument must be either a .jack file or a directory with at least one .jack file in it", toCompile)
os.Exit(1)
}

// for each jack file
for _, filePath := range files {
ce, err := compiler.NewCompilationEngine(filePath)
err = ce.Run()
if err != nil {
panic(err)
log.Printf("Error running the compilation engine: %v", err)
os.Exit(1)
}
}
}
Loading

0 comments on commit ada1356

Please sign in to comment.