comparison compiler.js @ 68:3a169ebb3224

Change strategy for handling true and false to avoid some initialization order problems and improve performance. Add support for negative integer literals. Update samples to reflect true/false change.
author Mike Pavone <pavone@retrodev.com>
date Sat, 14 Jul 2012 16:14:01 -0700
parents 25b697c91629
children 8a9b96888b7d
comparison
equal deleted inserted replaced
67:42d5660b30b4 68:3a169ebb3224
14 var toplevel = new topsymbols([]); 14 var toplevel = new topsymbols([]);
15 function topsymbols(moduledirs) 15 function topsymbols(moduledirs)
16 { 16 {
17 this.names = null; 17 this.names = null;
18 this.used = {}; 18 this.used = {};
19 this.nextmodulenum = 0;
19 var self = this; 20 var self = this;
20 if (typeof window === "object") { 21 if (typeof window === "object") {
21 get('/src/', function(data) { 22 get('/src/', function(data) {
22 self.names = {}; 23 self.names = {};
23 var fakeEl = newEl("div", { 24 var fakeEl = newEl("div", {
34 this.names = {}; 35 this.names = {};
35 for (var dirnum in moduledirs) { 36 for (var dirnum in moduledirs) {
36 var results = os.system("ls", [moduledirs[dirnum]]).split('\n'); 37 var results = os.system("ls", [moduledirs[dirnum]]).split('\n');
37 for (var i in results) { 38 for (var i in results) {
38 var tpidx = results[i].indexOf('.tp') 39 var tpidx = results[i].indexOf('.tp')
39 if (tpidx > -1) { 40 if (tpidx > 0 && tpidx == results[i].length - 3) {
40 this.names[results[i].substr(0, tpidx)] = new modulefile(moduledirs[dirnum], results[i]); 41 this.names[results[i].substr(0, tpidx)] = new modulefile(moduledirs[dirnum], results[i]);
41 } 42 }
42 } 43 }
43 } 44 }
44 } 45 }
57 } 58 }
58 return null; 59 return null;
59 } 60 }
60 topsymbols.prototype.getEnvType = function() { 61 topsymbols.prototype.getEnvType = function() {
61 return 'void'; 62 return 'void';
63 }
64 topsymbols.prototype.moduleVar = function(name) {
65 if (!(name in this.names)) {
66 throw new Error('symbol ' + name + ' not found at toplevel');
67 }
68 if (name == 'true' || name == 'false') {
69 return 'module_' + name;
70 }
71 if (!this.names[name].modulevar) {
72 this.names[name].modulevar = 'module_' + this.nextmodulenum++
73 }
74 return this.names[name].modulevar;
62 } 75 }
63 76
64 function osymbols(parent) 77 function osymbols(parent)
65 { 78 {
66 this.parent = parent; 79 this.parent = parent;