view scripttags.js @ 251:2557ce4e671f

Fix a couple of compiler bugs. topenv was getting initialized in multiple places. This resulted in multiple copies of modules getting created which caused problems for macro expansion. Additionally, arguments were not being marked as declared during code generation so assigning to an argument that was not closed over generated invalid C code.
author Michael Pavone <pavone@retrodev.com>
date Fri, 11 Apr 2014 22:29:32 -0700
parents da7f585bf626
children
line wrap: on
line source


function compileAndRun(src)
{
	var ast = parser.parse(src);
	asyncProcessTopLevelJS(toplevel, function() {
		var js = makeJSProg(ast);
		eval(js);
	});
	/*.toJSModule();
	mainModule = eval(js);
	if (mainModule.strue) {
		each(mainModule.strue, function(key, val) {
			if(val instanceof Function) {
				Boolean.prototype[key] = function() {
					return this.valueOf() ? mainModule.strue[key].apply(mainModule.strue, arguments) : mainModule.sfalse[key].apply(mainModule.sfalse, arguments);
				};
			}
		});
	}
	mainModule.main();*/
}

onReady(function() {
	toplevel.onReady( function() {
		var tags = qall('script[type="text/tabletprog"]');

		for (var i = 0; i < tags.length; ++i) {
			if (tags[i].src) {
				(function() {
					var src = tags[i].src;
					get(src, function(req) {
						console.log('Compiling ' + src);
						compileAndRun(req.responseText);
					});
				})();
			} else {
				compileAndRun(tags[i].innerHTML);
			}
		}
	});
});