Mercurial > repos > tabletprog
changeset 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 | c58e17f5c0f6 |
children | 004946743678 |
files | cbackend.js compiler.js tpc.js |
diffstat | 3 files changed, 12 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- 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 = []
--- 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;
--- 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':