Mercurial > repos > tabletprog
comparison tpc.js @ 66:25b697c91629
Finish implementation of external module access
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Sat, 14 Jul 2012 12:30:25 -0700 |
parents | 976a0924e1d4 |
children | 3a169ebb3224 |
comparison
equal
deleted
inserted
replaced
65:b4190db72288 | 66:25b697c91629 |
---|---|
1 var module = {exports: {}}; | 1 var module = {exports: {}}; |
2 var PEG; | 2 var PEG; |
3 | 3 |
4 var file = null; | 4 var file = null; |
5 var argtype = 'normal'; | 5 var argtype = 'normal'; |
6 var includes = []; | 6 var includes = ['.']; |
7 var basedir = ''; | 7 var basedir = ''; |
8 var debugmode = false; | 8 var debugmode = false; |
9 for (var i = 0; i < arguments.length; i++) { | 9 for (var i = 0; i < arguments.length; i++) { |
10 switch (argtype) { | 10 switch (argtype) { |
11 case 'normal': | 11 case 'normal': |
51 } | 51 } |
52 | 52 |
53 compileFile(file, basedir, includes, debugmode); | 53 compileFile(file, basedir, includes, debugmode); |
54 | 54 |
55 | 55 |
56 function compileFile(filename, basedir, includes, debugmode) | 56 function parseFile(filename) |
57 { | 57 { |
58 var text = read(filename); | 58 var text = read(filename); |
59 load(basedir + 'peg.js'); | |
60 PEG = module.exports; | |
61 load(basedir + 'parser.js'); | |
62 load(basedir + 'compiler.js'); | |
63 load(basedir + 'cbackend.js'); | |
64 try { | 59 try { |
65 var parsed = parser.parse(text); | 60 var parsed = parser.parse(text); |
66 } catch (error) { | 61 } catch (error) { |
67 print('SyntaxError on at', error.line, ',', error.column, ':', error.message); | 62 print('SyntaxError on at', error.line, ',', error.column, ':', error.message); |
68 var lines = text.split('\n'); | 63 var lines = text.split('\n'); |
76 } | 71 } |
77 } | 72 } |
78 print(spacer + '^'); | 73 print(spacer + '^'); |
79 quit(1); | 74 quit(1); |
80 } | 75 } |
76 return parsed; | |
77 } | |
78 | |
79 | |
80 function compileFile(filename, basedir, includes, debugmode) | |
81 { | |
82 | |
83 load(basedir + 'peg.js'); | |
84 PEG = module.exports; | |
85 load(basedir + 'parser.js'); | |
86 load(basedir + 'compiler.js'); | |
87 load(basedir + 'cbackend.js'); | |
88 var parsed = parseFile(filename); | |
81 if (debugmode) { | 89 if (debugmode) { |
82 debugprint = print; | 90 debugprint = print; |
83 } | 91 } |
92 toplevel = new topsymbols(includes); | |
84 var c = parsed.toCModule(); | 93 var c = parsed.toCModule(); |
85 print(c); | 94 print(c); |
86 } | 95 } |