-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtaal.js
45 lines (38 loc) · 1014 Bytes
/
taal.js
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
const Tokenizer = require('./compiler/tokenizer');
const StringStream = require('./compiler/stringstream');
const Parser = require('./compiler/parser');
const Compiler = require('./compiler/assembly/compiler');
const Runner = require('./compiler/processes/runner');
const chalk = require('chalk');
const fs = require('fs');
const path = require('path');
class Taal {
static compileFile(p, outputname) {
let f = fs.readFileSync(
p
).toString('utf8');
return new Promise((resolve, reject) => {
try {
let script = new Parser(
new Tokenizer(
new StringStream(f),
p
).parse(),
p
).parse();
if (global.TAAL_CONFIG.debug) console.log(JSON.stringify(script, null, 4));
let c = new Compiler(script, p);
let binary = c.compile();
let runner = new Runner(outputname, binary);
runner.run().then((obj) => {
resolve(obj);
}).catch((ex) => {
reject(ex);
});
} catch (ex) {
reject(ex);
}
});
}
}
module.exports = Taal;