# HG changeset patch # User Michael Pavone # Date 1397280572 25200 # Node ID 2557ce4e671f244b69932942116a3af785d6c014 # Parent c58e17f5c0f66e222f3b27fa24d614c3ea5605c3 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. diff -r c58e17f5c0f6 -r 2557ce4e671f cbackend.js --- a/cbackend.js Wed Apr 09 22:55:10 2014 -0700 +++ b/cbackend.js Fri Apr 11 22:29:32 2014 -0700 @@ -1061,7 +1061,7 @@ } for (var i = 0; i < args.length; ++i) { var argname = args[i].toC(); - + this.symbols.declareVar(args[i].cleanName()); args[i] = (argname.indexOf('->') < 0 ? '\tobject * ' : '\t') + argname + ' = va_arg(args, object *);\n'; } var compiled = [] diff -r c58e17f5c0f6 -r 2557ce4e671f compiler.js --- a/compiler.js Wed Apr 09 22:55:10 2014 -0700 +++ b/compiler.js Fri Apr 11 22:29:32 2014 -0700 @@ -13,7 +13,7 @@ modulefile.prototype.populateSymbols = function (toplevel) { if (!this.ast) { - this.ast = parseFile(this.path + '/' + this.file).macroexpand(new topenv(toplevel.moduledirs)); + this.ast = parseFile(this.path + '/' + this.file).macroexpand(toplevel.topenv); this.ast.populateSymbols(toplevel); } }; @@ -46,10 +46,14 @@ }); } -var toplevel = new topsymbols([]); -function topsymbols(moduledirs) +var toplevel = null;//new topsymbols([]); +function topsymbols(moduledirs, top) { - this.moduledirs = moduledirs; + if (!top) { + top = new topenv(moduledirs); + } + this.topenv = top; + this.moduledirs = moduledirs; this.names = null; this.used = {}; this.nextmodulenum = 0; diff -r c58e17f5c0f6 -r 2557ce4e671f tpc.js --- a/tpc.js Wed Apr 09 22:55:10 2014 -0700 +++ b/tpc.js Fri Apr 11 22:29:32 2014 -0700 @@ -109,11 +109,12 @@ if (debugmode) { debugprint = print; } - parsed = parsed.macroexpand(new topenv(includes)); + var top = new topenv(includes); + parsed = parsed.macroexpand(top); if (macroonly) { print(''+parsed); } else { - toplevel = new topsymbols(includes); + toplevel = new topsymbols(includes, top); switch(backend) { case 'C':