comparison tpc.js @ 128:5e34563f90ae

Get javascript backend working from the command line compiler again
author Mike Pavone <pavone@retrodev.com>
date Tue, 06 Aug 2013 00:17:22 -0700
parents 926b65fe92b4
children 6fe9343b1400
comparison
equal deleted inserted replaced
127:2b25d0ce2946 128:5e34563f90ae
1 var module = {exports: {}}; 1 var module = {exports: {}};
2 var console = {log: function(text){}};
2 var PEG; 3 var PEG;
3 4
4 var file = null; 5 var file = null;
5 var argtype = 'normal'; 6 var argtype = 'normal';
6 var includes = ['.']; 7 var includes = ['.'];
62 function parseFile(filename) 63 function parseFile(filename)
63 { 64 {
64 debugprint('//parsing', filename); 65 debugprint('//parsing', filename);
65 var text = read(filename); 66 var text = read(filename);
66 try { 67 try {
67 var parsed = parser.parse(text); 68 var parsed = parser.parse(text);
68 } catch (error) { 69 } catch (error) {
69 print('SyntaxError on at', error.line, ',', error.column, ':', error.message); 70 print('SyntaxError on at', error.line, ',', error.column, ':', error.message);
70 var lines = text.split('\n'); 71 var lines = text.split('\n');
71 print(lines[error.line-1]); 72 print(lines[error.line-1]);
72 var spacer = ''; 73 var spacer = '';
84 } 85 }
85 86
86 87
87 function compileFile(filename, basedir, includes, debugmode, backend) 88 function compileFile(filename, basedir, includes, debugmode, backend)
88 { 89 {
89 90 load(basedir + 'mquery.js');
90 load(basedir + 'peg.js'); 91 load(basedir + 'peg.js');
91 PEG = module.exports; 92 PEG = module.exports;
92 load(basedir + 'parser.js'); 93 load(basedir + 'parser.js');
93 load(basedir + 'compiler.js'); 94 load(basedir + 'compiler.js');
94 if (backend == 'C') { 95 if (backend == 'C') {
95 load(basedir + 'cbackend.js'); 96 load(basedir + 'cbackend.js');
96 } else { 97 } else {
97 load(basedir + 'jsbackend.js'); 98 load(basedir + 'jsbackend.js');
98 } 99 }
99 100
100 var parsed = parseFile(filename); 101 var parsed = parseFile(filename);
101 if (debugmode) { 102 if (debugmode) {
102 debugprint = print; 103 debugprint = print;
103 } 104 }
104 toplevel = new topsymbols(includes); 105 toplevel = new topsymbols(includes);