-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwamp
executable file
·43 lines (34 loc) · 1022 Bytes
/
wamp
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
#!/usr/bin/env node
// Copyright Joel Martin <[email protected]>
// Licensed under MPL-2.0 (see ./LICENSE)
// https://github.com/kanaka/wam
const {readFileSync} = require('fs')
const {docopt} = require('docopt')
const {read_str, wam_eval, emit_module, empty_ctx} = require('./wamp.js')
// Parse arguments
doc = `
Usage:
wamp [--memorySize=<PAGES>] [--memoryBase=<BYTES>] FILES...
Options:
--memorySize=<PAGES> memory size in 64K pages [default: 256]
--memoryBase=<BYTES> static memory offset bytes [default: 4096]
`
let opts = docopt(doc)
for (let k in opts) {
if (k.startsWith('--')) {
opts[k.slice(2)] = opts[k]
delete opts[k]
}
}
// Load and parse the files
let asts = []
for (let f of opts.FILES) {
asts.push(read_str(readFileSync(f)))
}
//console.log("asts:", asts)
// Do macro evaluation/transformation
let ctx = empty_ctx()
asts = asts.map(a => wam_eval(a, ctx))
// Emit the resulting module
console.log(emit_module(asts, ctx, opts))
// vim:syntax=javascript