diff --git a/Objective-J/Bootstrap.js b/Objective-J/Bootstrap.js index bfbc8ce4e..53d476812 100644 --- a/Objective-J/Bootstrap.js +++ b/Objective-J/Bootstrap.js @@ -1,3 +1,6 @@ + +makeExportsGlobal(); + var rootNode = new StaticResourceNode("", null, StaticResourceNode.DirectoryType, YES), cwd = FILE.cwd(); diff --git a/Objective-J/DebugOptions.js b/Objective-J/DebugOptions.js new file mode 100644 index 000000000..affc401b4 --- /dev/null +++ b/Objective-J/DebugOptions.js @@ -0,0 +1,4 @@ + +#define DEPENDENCY_LOGGING 1 +#define STATIC_RESOURCE_LOGGING 1 +#define EXECUTION_LOGGING 1 diff --git a/Objective-J/Executable.js b/Objective-J/Executable.js index 39eda3fd9..21b9ceeeb 100644 --- a/Objective-J/Executable.js +++ b/Objective-J/Executable.js @@ -71,7 +71,7 @@ if (code.indexOf("/Users/tolmasky/Desktop/LoadTest/main.j/**/") !== -1) Executable.prototype.path = function() { - return FILE.cwd(); + return FILE.join(FILE.cwd(), "(Anonymous)"); } Executable.prototype.functionParameters = function() @@ -88,6 +88,9 @@ Executable.prototype.functionArguments = function() Executable.prototype.execute = function() { +#if EXECUTION_LOGGING + console.log("EXECUTION: " + this.path()); +#endif var oldContextBundle = CONTEXT_BUNDLE; CONTEXT_BUNDLE = Bundle.bundleContainingPath(this.path()); @@ -102,9 +105,8 @@ Executable.prototype.code = function() return this._code; } -Executable.prototype.fileDependencies = function() +Executable.prototype.filePathDependencies = function() { - return this._fileDependencies; } Executable.prototype.scope = function() @@ -117,14 +119,18 @@ Executable.prototype.hasLoadedFileDependencies = function() return this._fileDependencyLoadStatus === ExecutableLoadedFileDependencies; } var globalIteration = 0; + Executable.prototype.loadFileDependencies = function() -{console.log("load deps for " + this.scope()); +{ +#if DEPENDENCY_LOGGING + console.log("DEPENDENCY: initiated by " + this.scope()); +#endif if (this._fileDependencyLoadStatus !== ExecutableUnloadedFileDependencies) return; this._fileDependencyLoadStatus = ExecutableLoadingFileDependencies; - var searchedPaths = { }, + var searchedPaths = [{ }, { }], foundExecutablePaths = { }, fileExecutableSearches = new MutableDictionary(), incompleteFileExecutableSearches = new MutableDictionary(); @@ -136,79 +142,90 @@ Executable.prototype.loadFileDependencies = function() if (anExecutable.hasLoadedFileDependencies()) return; - var fileDependencies = anExecutable.fileDependencies(), - index = 0, - count = fileDependencies.length; + var executables = [anExecutable], + executableIndex = 0, + executableCount = executables.length; - for (; index < count; ++index) + for (; executableIndex < executableCount; ++executableIndex) { - var fileDependency = fileDependencies[index], - path = fileDependency.path(), - isLocal = fileDependency.isLocal(); - - if (isLocal) - path = FILE.join(anExecutable.path ? FILE.dirname(anExecutable.path()) : FILE.cwd(), path); + var executable = executables[executableIndex], + cwd = FILE.dirname(executable.path()), + fileDependencies = executable.fileDependencies(), + fileDependencyIndex = 0, + fileDependencyCount = fileDependencies.length; - if (searchedPaths[path]) - continue; - - searchedPaths[path] = YES; - - var fileExecutableSearch = new FileExecutableSearch(path, isLocal), - fileExecutableSearchUID = fileExecutableSearch.UID(); - - if (fileExecutableSearches.containsKey(fileExecutableSearchUID)) - continue; - - fileExecutableSearches.setValueForKey(fileExecutableSearchUID, fileExecutableSearch); - - if (fileExecutableSearch.isComplete()) - searchForFileDependencies(fileExecutableSearch.result()); - - else + for (; fileDependencyIndex < fileDependencyCount; ++fileDependencyIndex) { - incompleteFileExecutableSearches.setValueForKey(fileExecutableSearchUID, fileExecutableSearch); - - fileExecutableSearch.addEventListener("complete", function(/*Event*/ anEvent) + var fileDependency = fileDependencies[fileDependencyIndex], + isLocal = fileDependency.isLocal(), + path = importablePath(fileDependency.path(), isLocal, cwd); + + if (searchedPaths[isLocal ? 1 : 0][path]) + continue; + + searchedPaths[isLocal ? 1 : 0][path] = YES; + + var fileExecutableSearch = new FileExecutableSearch(path, isLocal), + fileExecutableSearchUID = fileExecutableSearch.UID(); + + if (fileExecutableSearches.containsKey(fileExecutableSearchUID)) + continue; + + fileExecutableSearches.setValueForKey(fileExecutableSearchUID, fileExecutableSearch); + + if (fileExecutableSearch.isComplete()) { - var fileExecutableSearch = anEvent.fileExecutableSearch, - fileExecutable = fileExecutableSearch.result(); - //console.log("DONE FOR: " + search.UID() + " " + search.resultantFilePath()); - foundExecutablePaths[fileExecutable.path()] = fileExecutable; - incompleteFileExecutableSearches.removeValueForKey(fileExecutableSearch.UID()); - - searchForFileDependencies(fileExecutableSearch.result()); - }); + var newFileExecutable = fileExecutableSearch.result(); + + foundExecutablePaths[newFileExecutable.path()] = executable; + executables.push(newFileExecutable); + ++executableCount; + } + + else + { + incompleteFileExecutableSearches.setValueForKey(fileExecutableSearchUID, fileExecutableSearch); + + fileExecutableSearch.addEventListener("complete", function( anEvent) + { + var fileExecutableSearch = anEvent.fileExecutableSearch, + fileExecutable = fileExecutableSearch.result(); + + foundExecutablePaths[fileExecutable.path()] = fileExecutable; + incompleteFileExecutableSearches.removeValueForKey(fileExecutableSearch.UID()); + + searchForFileDependencies(fileExecutable); + }); + } } } if (incompleteFileExecutableSearches.count() > 0) - { - if (globalIteration++ > 200) - throw "too many."; - console.log("keep going"); - var keys = incompleteFileExecutableSearches.keys(), - index = 0, - count = keys.length; - for(; index < count; ++index) - console.log(":::"+keys[index] + " " + incompleteFileExecutableSearches.valueForKey(keys[index])._path); +#if !DEPENDENCY_LOGGING return; -} -console.log("what?"); +#else + { + console.log("DEPENDENCY: more dependencies: "); + console.log(incompleteFileExecutableSearches.toString()); + return; + } + + console.log("DEPENDENCY: Ended"); +#end var fileExecutablesNeedingEventDispatch = []; for (var executablePath in foundExecutablePaths) if (hasOwnProperty.apply(foundExecutablePaths, [executablePath])) { var fileExecutable = new FileExecutable(executablePath); - console.log("no go for... " + fileExecutable.path()); + //console.log("no go for... " + fileExecutable.path()); if (fileExecutable.hasLoadedFileDependencies()) continue; fileExecutablesNeedingEventDispatch.push(fileExecutable); fileExecutable._fileDependencyLoadStatus = FileExecutableLoadedDependencies; } - + var index = 0, count = fileExecutablesNeedingEventDispatch.length; diff --git a/Objective-J/FileExecutable.js b/Objective-J/FileExecutable.js index 6b09da94f..e888af293 100644 --- a/Objective-J/FileExecutable.js +++ b/Objective-J/FileExecutable.js @@ -71,42 +71,6 @@ FileExecutable.prototype.hasExecuted = function() return this._hasExecuted; } -function importFile(/*String*/ aPath, /*BOOL*/ isLocal, /*Function*/ aCallback) -{ - aPath = FILE.normal(aPath); - - if (isLocal) - aPath = FILE.absolute(aPath); - - var search = new FileExecutableSearch(aPath, isLocal); - - function searchComplete(/*FileExecutableSearch*/ aFileExecutableSearch) - {console.log("search complete: " + aFileExecutableSearch); - var fileExecutable = aFileExecutableSearch.result(); - - if (!fileExecutable.hasLoadedFileDependencies()) - { - fileExecutable.loadFileDependencies(); - - fileExecutable.addEventListener("dependenciesload", function() - { - executeFile(aPath, isLocal); - }); - } - else - executeFile(aPath, isLocal); - } - - if (search.isComplete()) - searchComplete(search); - else - search.addEventListener("complete", function(/*Event*/ anEvent) - { - console.log("completed..."); - searchComplete(anEvent.fileExecutableSearch); - }); -} - function decompile(/*String*/ aString, /*String*/ aPath) { var stream = new MarkedStream(aString); diff --git a/Objective-J/FileExecutableSearch.js b/Objective-J/FileExecutableSearch.js index 491e4398e..1699bc5e9 100644 --- a/Objective-J/FileExecutableSearch.js +++ b/Objective-J/FileExecutableSearch.js @@ -98,3 +98,10 @@ FileExecutableSearch.prototype.removeEventListener = function(/*String*/ anEvent { this._eventDispatcher.removeEventListener(anEventName, aListener); } + +#if DEPENDENCY_LOGGING +FileExecutableSearch.prototype.toString = function() +{ + return ""; +} +#endif diff --git a/Objective-J/Includes.js b/Objective-J/Includes.js index ac236a68c..569bfe5e0 100644 --- a/Objective-J/Includes.js +++ b/Objective-J/Includes.js @@ -1,4 +1,5 @@ +#include "DebugOptions.js" #include "Constants.js" #include "EventDispatcher.js" #include "HTTPRequest.js" diff --git a/Objective-J/Runtime.js b/Objective-J/Runtime.js index c01de60dc..51af4d3d8 100644 --- a/Objective-J/Runtime.js +++ b/Objective-J/Runtime.js @@ -285,8 +285,6 @@ function class_getMethodImplementation(/*Class*/ aClass, /*SEL*/ aSelector) var GLOBAL_NAMESPACE = global, REGISTERED_CLASSES = { }; -var CONTEXT_BUNDLE = nil; - function objj_allocateClassPair(/*Class*/ superclass, /*String*/ aName) { var classObject = new objj_class(), @@ -331,12 +329,14 @@ function objj_allocateClassPair(/*Class*/ superclass, /*String*/ aName) return classObject; } +var CONTEXT_BUNDLE = nil; + function objj_registerClassPair(/*Class*/ aClass) { GLOBAL_NAMESPACE[aClass.name] = aClass; REGISTERED_CLASSES[aClass.name] = aClass; - addClassToBundle(CONTEXT_BUNDLE, aClass); + addClassToBundle(aClass, CONTEXT_BUNDLE); } // Instantiating Classes diff --git a/Objective-J/Scope.js b/Objective-J/Scope.js index fa54c5efb..52aaf1f0d 100644 --- a/Objective-J/Scope.js +++ b/Objective-J/Scope.js @@ -1,4 +1,11 @@ +function makeExportsGlobal() +{ + for (var exportName in exports) + if (hasOwnProperty.apply(exports, [exportName])) + global[exportName] = exports[exportName]; +} + var cachedExportedNames = [], cachedExportedValues = []; @@ -66,7 +73,7 @@ function fileExecuterForPath(/*String*/ referencePath) if (0 && !fileExecutable.hasLoadedFileDependencies()) throw "No executable loaded for file at path " + aPath; - console.log("executing " + aPath); + //console.log("executing " + aPath); //console.log(aPath + " " + (isLocal ? 1 : 0) + " " + executable.isLoaded() + " " + executable.hasLoadedDependencies());