aboutsummaryrefslogtreecommitdiff
path: root/src/nimfunge98.nim
blob: f80006293af7d0b510c56baa53ba8c28f81ae1a4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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