diff options
author | Julien Dessaux | 2021-10-06 23:25:41 +0200 |
---|---|---|
committer | Julien Dessaux | 2021-10-06 23:25:41 +0200 |
commit | cca0eb2117a98695a0280adbc1693b3c92cfab7a (patch) | |
tree | a9167286c69938fb39cea9a45afded2990638621 /src/nimfunge98.nim | |
parent | Implemented missing functions for the interpreter (diff) | |
download | nimfunge98-cca0eb2117a98695a0280adbc1693b3c92cfab7a.tar.gz nimfunge98-cca0eb2117a98695a0280adbc1693b3c92cfab7a.tar.bz2 nimfunge98-cca0eb2117a98695a0280adbc1693b3c92cfab7a.zip |
Implemented the interpreter
Diffstat (limited to 'src/nimfunge98.nim')
-rw-r--r-- | src/nimfunge98.nim | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/nimfunge98.nim b/src/nimfunge98.nim new file mode 100644 index 0000000..6e6efb9 --- /dev/null +++ b/src/nimfunge98.nim @@ -0,0 +1,44 @@ +import field +import interpreter +import pointer + +import os +import parseopt +import strformat + +proc Usage(i: int = 0) = + let filename = getAppFilename().extractFilename() + echo fmt"""Usage of {filename}: + -f string b98 file to interpret + -h display this help message + """ + if i != 0: + quit i + +var filename: string + +for kind, key, value in getOpt(): + case kind + of cmdArgument: + if filename != "": + echo "Invalid argument: ", key + Usage(1) + filename = key + of cmdLongOption, cmdShortOption: + case key + of "h": + Usage() + else: + echo "Unknown option: ", key + Usage(1) + of cmdEnd: + discard + +var f = Load(filename) +if f == nil: + echo "Failed to load ", filename + quit 1 +let argv = @[filename] +var p = NewPointer(argv=argv) +let v = NewInterpreter(f, p)[].Run() +quit v |