-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.v
46 lines (41 loc) · 935 Bytes
/
main.v
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
45
46
module main
import vm
import ir
import os
import flag
struct VVMOptions {
file string
help bool
debug bool
dumpir bool
args []string
}
fn main() {
mut fp := flag.new_flag_parser(os.args)
fp.application('vvm')
fp.version('0.0.1a')
fp.description('This tool converts the V AST to an IR and executes on its own virtual machine')
fp.skip_executable()
mut opts := &VVMOptions{
debug: fp.bool('debug', `d`, false, 'show debug information')
dumpir: fp.bool('dumpir', `D`, false, 'dump IR')
file: fp.string('file', `f`, '', 'Input file')
help: fp.bool('help', `h`, false, 'show this help message')
}
if opts.help {
eprintln(fp.usage())
} else if opts.file != '' {
mut vvm_ir := ir.VVMIR{}
vvm_ir.parse_file(opts.file)
mut vvm_vm := vm.VVM{
vir: &vvm_ir
debug: opts.debug
}
if opts.dumpir || opts.debug {
eprintln(vvm_ir)
}
vvm_vm.run(mut vvm_ir)
} else {
eprintln(fp.usage())
}
}