# HG changeset patch # User Mike Pavone # Date 1376171438 25200 # Node ID d6e79885bd3b94622249d1cbb7448e40ecbad617 # Parent 9de2572a34a7d682803738da68e0a40db8e1745d Fix compiler bug involving referencing a self method in a method defined before the referenced method diff -r 9de2572a34a7 -r d6e79885bd3b cbackend.js --- a/cbackend.js Sat Aug 10 14:19:38 2013 -0700 +++ b/cbackend.js Sat Aug 10 14:50:38 2013 -0700 @@ -982,7 +982,7 @@ for (var key in this.symbols.closedover) { print(key, ": ", this.symbols.closedover[key]); } - throw new Error('this.symbols.closedover is not empty, but it was when compilation of "' + assignPaths + '" started'); + throw new Error('this.symbols.closedover is not empty, but it was when compilation of ' + this.name + ' "' + assignPath + '" started'); } forwarddec += 'struct ' + this.name + '_env {\n'; if (this.symbols.needsParentEnv) { @@ -1093,11 +1093,13 @@ }; assignment.prototype.toCObject = function(cobj) { debugprint('//message definition', this.symbol.name); + assignNames.push('#' + this.symbol.name); if (this.expression.toCObject) { var val = this.expression.toCObject(cobj.name); } else { var val = this.expression.toC(); } + assignNames.pop(); if (val === null) { return; } diff -r 9de2572a34a7 -r d6e79885bd3b compiler.js --- a/compiler.js Sat Aug 10 14:19:38 2013 -0700 +++ b/compiler.js Sat Aug 10 14:50:38 2013 -0700 @@ -230,9 +230,12 @@ }; } else { if (nestedcall) { - this.closedover[name] = true; - this.passthruenv = false; - } + if (!(name in this.closedover)) { + debugprint('//' + name + ' is now closed over'); + this.closedover[name] = true; + this.passthruenv = false; + } + } if (name in this.closedover) { var ret = { type: 'closedover', @@ -414,13 +417,19 @@ } } +funcall.prototype.predefSymbolsObject = function(symbols) { +}; + funcall.prototype.populateSymbolsObject = function(symbols) { this.populateSymbols(symbols); -} +}; object.prototype.populateSymbols = function(symbols) { var symbols = new osymbols(symbols); for (var i in this.messages) { + this.messages[i].predefSymbolsObject(symbols); + } + for (var i in this.messages) { this.messages[i].populateSymbolsObject(symbols); } this.symbols = symbols; @@ -456,14 +465,17 @@ this.expression.populateSymbols(symbols); this.symbols = symbols; }; -assignment.prototype.populateSymbolsObject = function(symbols) { - debugprint('//messagedef', this.symbol.name, 'populateSymbols'); +assignment.prototype.predefSymbolsObject = function(symbols) { + debugprint('//messagedef', this.symbol.name, 'predefSymbolsObject'); if (this.expression instanceof lambda || (this.expression instanceof funcall & this.expression.name == 'foreign:')) { symbols.defineMsg(this.symbol.name, this.expression); } else { symbols.defineMsg(this.symbol.name, new getter(null)); symbols.defineMsg(this.symbol.name + '!', new setter(null)); } +}; +assignment.prototype.populateSymbolsObject = function(symbols) { + debugprint('//messagedef', this.symbol.name, 'populateSymbols'); this.symbol.populateSymbols(symbols); this.expression.populateSymbols(symbols, true); this.symbols = symbols;