diff tpc.js @ 126:a2d2d8e09291

Merge
author Mike Pavone <pavone@retrodev.com>
date Mon, 05 Aug 2013 23:37:17 -0700
parents 926b65fe92b4
children 5e34563f90ae
line wrap: on
line diff
--- a/tpc.js	Mon Aug 05 23:36:18 2013 -0700
+++ b/tpc.js	Mon Aug 05 23:37:17 2013 -0700
@@ -6,12 +6,14 @@
 var includes = ['.'];
 var basedir = '';
 var debugmode = false;
+var backend = 'C';
 for (var i = 0; i < arguments.length; i++) {
 	switch (argtype) {
 	case 'normal':
 		switch (arguments[i]) {
 		case '-basedir':
 		case '-i':
+		case '-backend':
 			argtype = arguments[i];
 			break;
 		case '-compilerdebug':
@@ -38,6 +40,10 @@
 		includes.push(arguments[i]);
 		argtype = 'normal';
 		break;
+	case '-backend':
+		backend = arguments[i];
+		argtype = 'normal';
+		break;
 	}
 }
 if (argtype != 'normal') {
@@ -50,7 +56,7 @@
 	quit(1);
 }
 includes.push(basedir + 'modules');
-compileFile(file, basedir, includes, debugmode);
+compileFile(file, basedir, includes, debugmode, backend);
 
 
 function parseFile(filename)
@@ -78,19 +84,35 @@
 }
 
 
-function compileFile(filename, basedir, includes, debugmode)
+function compileFile(filename, basedir, includes, debugmode, backend)
 {
 	
 	load(basedir + 'peg.js');
 	PEG = module.exports;
 	load(basedir + 'parser.js');
 	load(basedir + 'compiler.js');
-	load(basedir + 'cbackend.js');
+	if (backend == 'C') {
+		load(basedir + 'cbackend.js');
+	} else {
+		load(basedir + 'jsbackend.js');
+	}
+	
 	var parsed = parseFile(filename);
 	if (debugmode) {
 		debugprint = print;
 	}
 	toplevel = new topsymbols(includes);
-	var c = parsed.toCModule();
+	switch(backend)
+	{
+	case 'C':
+		var c = parsed.toCModule();
+		break;
+	case 'JS':
+		var c = makeJSProg(parsed);
+		break;
+	default:
+		print('Backend', backend, ' not recognized');
+		quit(1);
+	}
 	print(c);
 }