-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
saving the xml test compiler in a separate dir
- Loading branch information
Isaiah Becker-Mayer
committed
Mar 28, 2021
1 parent
cb68ca2
commit c834139
Showing
31 changed files
with
8,141 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# TestCompiler | ||
|
||
A first draft for the compiler that spits out XML for testing purposes. The book suggests this be modified in order to create the final compiler that spits out actual VM code. In order to keep this xml test version, though, I decided to save a separate copy of this XML version. The final compiler is in the Compiler directory. | ||
|
||
#### Testing | ||
|
||
To run all the tests from the command line, run | ||
|
||
``` | ||
go test ./test/ | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module github.com/ibeckermayer/Nand2TetrisFPGA/Compiler | ||
|
||
go 1.15 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
github.com/ibeckermayer/Nand2TetrisFPGA v0.0.0-20210122031511-4a0dddc9b098 h1:j3186jVNdOZV30DubToqydS37xNZEmzKFHrtPbMpFnM= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
|
||
"github.com/ibeckermayer/Nand2TetrisFPGA/Compiler/pkg/compiler" | ||
) | ||
|
||
// isJack determines whether a string ends in ".jack" or not | ||
func isJack(in string) bool { | ||
split := strings.Split(in, ".") | ||
return split[len(split)-1] == "jack" | ||
} | ||
|
||
// jackFilter filters a list of strings down to only those which end in ".jack" | ||
func jackFilter(ss []string) (ret []string) { | ||
for _, s := range ss { | ||
if isJack(s) { | ||
ret = append(ret, s) | ||
} | ||
} | ||
return | ||
} | ||
|
||
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") | ||
} | ||
toCompile := os.Args[1] | ||
var files []string | ||
|
||
// try to list all the files in a directory by the name of the first command line argument, | ||
// or just list the single jack file argument | ||
if err := filepath.Walk(toCompile, func(path string, info os.FileInfo, err error) error { | ||
if path != toCompile && info.IsDir() { | ||
// only walk a single level of directories | ||
return filepath.SkipDir | ||
} | ||
if isJack(path) { | ||
files = append(files, path) | ||
} | ||
return nil | ||
}); err != nil { | ||
panic(err.Error()) | ||
} | ||
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)) | ||
} | ||
|
||
// for each jack file | ||
for _, filePath := range files { | ||
ce, err := compiler.New(filePath) | ||
err = ce.Run() | ||
if err != nil { | ||
panic(err) | ||
} | ||
} | ||
} |
Oops, something went wrong.