"flatten" now inlines functions

This commit is contained in:
Tom Robinson
2010-02-25 00:57:21 -08:00
parent ff43be6d7b
commit 555b83a359
2 changed files with 32 additions and 8 deletions
+5 -2
View File
@@ -22,7 +22,7 @@
var FileExecutablesForPaths = { };
function FileExecutable(/*String*/ aPath)
function FileExecutable(/*String*/ aPath, /*Executable*/ anExecutable)
{
var existingFileExecutable = FileExecutablesForPaths[aPath];
@@ -35,7 +35,10 @@ function FileExecutable(/*String*/ aPath)
executable = NULL,
extension = FILE.extension(aPath);
if (fileContents.match(/^@STATIC;/))
if (anExecutable)
executable = anExecutable;
else if (fileContents.match(/^@STATIC;/))
executable = decompile(fileContents, aPath);
else if (extension === ".j" || extension === "")
+27 -6
View File
@@ -31,7 +31,7 @@ function main(args)
var flattener = new ObjectiveJFlattener(rootPath);
flattener.setIncludePaths([rootPath.join("Frameworks/Debug")]);
flattener.setIncludePaths([rootPath.join("Frameworks")]);
flattener.setEnvironments(["Browser", "ObjJ"]);
flattener.load(rootPath.join("main.j"));
@@ -65,6 +65,7 @@ function ObjectiveJFlattener(rootPath) {
this.resourceBuffer = [];
this.bundleBuffer = [];
this.functionsBuffer = [];
this._outputBundles = {};
}
@@ -75,6 +76,7 @@ ObjectiveJFlattener.prototype.buildApplicationJS = function(applicationRoot) {
print(applicationRoot);
this.serializeStaticResources(applicationRoot);
this.serializeStaticFileExecutables();
var buffer = []
@@ -89,14 +91,31 @@ ObjectiveJFlattener.prototype.buildApplicationJS = function(applicationRoot) {
buffer.push(this.resourceBuffer.join("\n"));
buffer.push("console.log(ObjectiveJ.StaticResource.root);");
buffer.push("console.log(applicationRoot);");
buffer.push("ObjectiveJ.bootstrap();");
buffer.push("})();");
buffer.push(this.functionsBuffer.join("\n"));
buffer.push("ObjectiveJ.bootstrap();");
return buffer.join("\n");
}
ObjectiveJFlattener.prototype.serializeStaticFileExecutables = function() {
this.require("objective-j").FileExecutable.allFileExecutables().forEach(function(aFileExecutable) {
var deps = aFileExecutable.fileDependencies().map(function(dependency) {
return "new ObjectiveJ.FileDependency("+JSON.stringify(dependency.path())+","+JSON.stringify(dependency.isLocal())+")"
}).join(",");
var func = aFileExecutable._function.toString();
// HACK
func = func.replace(", require, exports, module, system, print, window", "");
this.functionsBuffer.push("var path = ObjectiveJ.StaticResource.cwd + "+JSON.stringify("/"+this.rootPath.relative(aFileExecutable.path()))+";");
this.functionsBuffer.push("new ObjectiveJ.FileExecutable(path,"+
"new ObjectiveJ.Executable(null, ["+deps+"], path, "+func+"));");
}, this);
}
ObjectiveJFlattener.prototype.serializeStaticResources = function(node, depth) {
depth = depth || 0;
@@ -130,8 +149,10 @@ ObjectiveJFlattener.prototype.serializeStaticResources = function(node, depth) {
this.resourceBuffer.push("newNode = applicationRoot;");
}
if (node.contents())
this.resourceBuffer.push("newNode._contents = " + JSON.stringify(node.contents()) + ";");
// var contents = node.contents();
// if (contents) {
// this.resourceBuffer.push("newNode._contents = " + JSON.stringify(contents) + ";");
// }
if (!node.children())
return;