comparison compiler.js @ 329:eef8a5cea812

Use a smarter algorithm for calculating module init order and break some circular module dependencies in the standard library
author Michael Pavone <pavone@retrodev.com>
date Sat, 28 Mar 2015 13:26:03 -0700
parents d4df33596e7d
children
comparison
equal deleted inserted replaced
328:c1fad3d93861 329:eef8a5cea812
3 function indent(str) 3 function indent(str)
4 { 4 {
5 return str.split('\n').join('\n\t'); 5 return str.split('\n').join('\n\t');
6 } 6 }
7 7
8 var currentModule = null;
8 function modulefile(path, file) 9 function modulefile(path, file)
9 { 10 {
10 this.path = path; 11 this.path = path;
11 this.file = file; 12 this.file = file;
13 this.dependencies = {};
12 } 14 }
13 15
14 modulefile.prototype.populateSymbols = function (toplevel) { 16 modulefile.prototype.populateSymbols = function (toplevel) {
15 if (!this.ast) { 17 if (!this.ast) {
18 currentModule = this;
16 this.ast = parseFile(this.path + '/' + this.file).macroexpand(toplevel.topenv); 19 this.ast = parseFile(this.path + '/' + this.file).macroexpand(toplevel.topenv);
17 this.ast.populateSymbols(toplevel); 20 this.ast.populateSymbols(toplevel);
21 currentModule = null;
18 } 22 }
19 }; 23 };
20 24
21 modulefile.prototype.popuplateSymbolsAsync = function(toplevel, whenDone) { 25 modulefile.prototype.popuplateSymbolsAsync = function(toplevel, whenDone) {
22 if (!this.ast) { 26 if (!this.ast) {
23 var self = this; 27 var self = this;
24 get(this.path + '/' + this.file, function(data) { 28 get(this.path + '/' + this.file, function(data) {
25 //TODO: macro expand in the async case 29 //TODO: macro expand in the async case
30 currentModule = this;
26 self.ast = parser.parse(data.responseText); 31 self.ast = parser.parse(data.responseText);
27 self.ast.populateSymbols(toplevel); 32 self.ast.populateSymbols(toplevel);
33 currentModule = null;
28 whenDone(); 34 whenDone();
29 }); 35 });
30 } else { 36 } else {
31 whenDone(); 37 whenDone();
32 } 38 }
91 debugprint('//topsymbols.find', name, name in this.names); 97 debugprint('//topsymbols.find', name, name in this.names);
92 if (!this.names) { 98 if (!this.names) {
93 throw new Error('data not ready'); 99 throw new Error('data not ready');
94 } 100 }
95 if (name in this.names) { 101 if (name in this.names) {
102 if (currentModule) {
103 currentModule.dependencies[name] = true;
104 }
96 this.used[name] = true; 105 this.used[name] = true;
97 return { 106 return {
98 type: 'toplevel', 107 type: 'toplevel',
99 def: this.names[name] 108 def: this.names[name]
100 }; 109 };