From 379eb051440384ec1ba8a105402078733f6d9794 Mon Sep 17 00:00:00 2001 From: Tom Robinson Date: Thu, 3 Sep 2009 01:07:50 -0700 Subject: [PATCH 1/3] Various improvements to objj and objjc modules, added plist module. --- External/Rakefile | 34 ++- Objective-J/Tools/objj/bin/objjc | 222 +------------------ Objective-J/Tools/objj/lib-js/objj/loader.js | 2 +- Objective-J/Tools/objj/lib-js/objj/objj.js | 67 ++++-- Objective-J/Tools/objj/lib-js/objj/objjc.js | 163 ++++++++++++++ Objective-J/Tools/objj/lib-js/objj/plist.js | 15 ++ 6 files changed, 249 insertions(+), 254 deletions(-) create mode 100644 Objective-J/Tools/objj/lib-js/objj/objjc.js create mode 100644 Objective-J/Tools/objj/lib-js/objj/plist.js diff --git a/External/Rakefile b/External/Rakefile index b51625b9f..91dc7ba4d 100644 --- a/External/Rakefile +++ b/External/Rakefile @@ -8,28 +8,42 @@ require 'rake/clean' require 'fileutils' $ENVIRONMENT_NARWHAL_PRODUCT = $ENVIRONMENT_DIR -$ENVIRONMENT_BROWSERJS_PRODUCT = File.join($ENVIRONMENT_NARWHAL_PRODUCT, 'packages', 'browserjs') -$ENVIRONMENT_JACK_PRODUCT = File.join($ENVIRONMENT_NARWHAL_PRODUCT, 'packages', 'jack') +$ENVIRONMENT_PACKAGES_PRODUCT = File.join($ENVIRONMENT_NARWHAL_PRODUCT, 'packages') + +$EXTERNALS = ['browserjs', 'jack', 'narwhal', 'ojunit'] +$PACKAGES = ['browserjs', 'jack'] file_d $ENVIRONMENT_DIR do mkdir_p $ENVIRONMENT_DIR end task :update_submodules do - if executable_exists? "git" - system %{cd .. && git submodule init && git submodule update} - else - puts "Git not installed" - rake abort + if !ENV['NOSUBUP'] then + if executable_exists? "git" + system %{cd .. && git submodule init && git submodule update} + else + puts "Git not installed" + rake abort + end end end task :build => [:update_submodules, $ENVIRONMENT_DIR] do rm_rf($ENVIRONMENT_NARWHAL_PRODUCT) + cp_r('narwhal', $ENVIRONMENT_NARWHAL_PRODUCT) - cp_r('browserjs', $ENVIRONMENT_BROWSERJS_PRODUCT) - cp_r('jack', $ENVIRONMENT_JACK_PRODUCT) - symlink_executable(File.join($ENVIRONMENT_JACK_PRODUCT, "bin", "jackup")) + + $PACKAGES.each do |package| + cp_r(package, File.join($ENVIRONMENT_PACKAGES_PRODUCT, package)) + end + + symlink_executable(File.join($ENVIRONMENT_PACKAGES_PRODUCT, 'jack', 'bin', 'jackup')) end CLOBBER.include($ENVIRONMENT_NARWHAL_PRODUCT) + +task :pull do + $EXTERNALS.each do |external| + system "cd #{external} && git pull origin master" + end +end \ No newline at end of file diff --git a/Objective-J/Tools/objj/bin/objjc b/Objective-J/Tools/objj/bin/objjc index a710cc94a..595203812 100755 --- a/Objective-J/Tools/objj/bin/objjc +++ b/Objective-J/Tools/objj/bin/objjc @@ -1,223 +1,3 @@ #!/usr/bin/env narwhal -var objj = require("objj/objj"), - File = require("file"), - os = require("os"); - -require("objj/regexp-rhino-patch"); - -with (objj) -{ - -importPackage(java.lang); - -importClass(java.io.BufferedReader); - -var SHRINKSAFE_PATH = File.join(OBJJ_HOME, "shrinksafe", "shrinksafe.jar"), - RHINO_PATH = File.join(OBJJ_HOME, "shrinksafe", "js.jar") - -OBJJ_PREPROCESSOR_PREPROCESS = 1 << 10; -OBJJ_PREPROCESSOR_COMPRESS = 1 << 11; -OBJJ_PREPROCESSOR_SYNTAX = 1 << 12; - -function exec(/*Array*/ command, /*Boolean*/ showOutput) -{ - var line = "", - output = "", - - process = Packages.java.lang.Runtime.getRuntime().exec(command),//jsArrayToJavaArray(command)); - reader = new Packages.java.io.BufferedReader(new Packages.java.io.InputStreamReader(process.getInputStream(), "UTF-8")); - - while (line = reader.readLine()) - { - if (showOutput) - System.out.println(line); - - output += line + '\n'; - } - - reader = new Packages.java.io.BufferedReader(new Packages.java.io.InputStreamReader(process.getErrorStream(), "UTF-8")); - - while (line = reader.readLine()) - System.out.println(line); - - try - { - if (process.waitFor() != 0) - System.err.println("exit value = " + process.exitValue()); - } - catch (anException) - { - System.err.println(anException); - } - - return output; -} - -function compress(/*String*/ aCode, /*Object*/ flags, /*File*/ tmpFile) -{ - File.write(tmpFile, aCode, { charset:"UTF-8" }); - - return exec(["java", "-Dfile.encoding=UTF-8", "-classpath", [RHINO_PATH, SHRINKSAFE_PATH].join(":"), "org.dojotoolkit.shrinksafe.Main", tmpFile.getCanonicalPath()]); -} - -//#define SET_CONTEXT(aFragment, aContext) aFragment.context = aContext -//#define GET_CONTEXT(aFragment) aFragment.context - -//#define SET_TYPE(aFragment, aType) aFragment.type = (aType) -//#define GET_TYPE(aFragment) aFragment.type - -function GET_CODE(aFragment) { return aFragment.info; } -//#define SET_CODE(aFragment, aCode) aFragment.info = (aCode) - -function GET_PATH(aFragment) { return aFragment.info; } -//#define SET_PATH(aFragment, aPath) aFragment.info = aPath - -//#define GET_BUNDLE(aFragment) aFragment.bundle -//#define SET_BUNDLE(aFragment, aBundle) aFragment.bundle = aBundle - -function GET_FILE(aFragment) { return aFragment.file; } -//#define SET_FILE(aFragment, aFile) aFragment.file = aFile - -function IS_FILE(aFragment) { return (aFragment.type & FRAGMENT_FILE); } -function IS_LOCAL(aFragment) { return (aFragment.type & FRAGMENT_LOCAL); } -//#define IS_IMPORT(aFragment) (aFragment.type & FRAGMENT_IMPORT) - -function preprocess(aFilePath, outFilePath, gccArgs, flags) -{ - print("Statically Preprocessing " + aFilePath); - - var shouldObjjPreprocess = flags & OBJJ_PREPROCESSOR_PREPROCESS, - shouldCheckSyntax = flags & OBJJ_PREPROCESSOR_SYNTAX, - shouldCompress = flags & OBJJ_PREPROCESSOR_COMPRESS; - - // FIXME: figure out why this doesn't work on Windows/Cygwin - //var tmpFile = java.io.File.createTempFile("OBJJC", ""); - var tmpFile = new java.io.File(outFilePath + ".tmp"); - tmpFile.deleteOnExit(); - - // -E JUST preprocess. - // -x c Interpret language as C -- closest thing to JavaScript. - // -P Don't generate #line directives - var gccComponents = ["gcc", "-E", "-x", "c", "-P", aFilePath, "-o", shouldObjjPreprocess ? tmpFile.getAbsolutePath() : outFilePath], - index = gccArgs.length; - - // Add custom gcc arguments. - while (index--) - gccComponents.splice(5, 0, gccArgs[index]); - - exec(gccComponents); - - if (!shouldObjjPreprocess) - return; - - // Read file and preprocess it. - var fileContents = File.read(tmpFile, { charset: "UTF-8" }); - - // Preprocess contents into fragments. - var filePath = new String(new java.io.File(aFilePath).getName()), - fragments = objj_preprocess(fileContents, { path:"/x" }, {path:filePath}, flags), - index = 0, - count = fragments.length, - preprocessed = ""; - - // Writer preprocessed fragments out. - for (; index < count; ++index) - { - var fragment = fragments[index]; - - if (IS_FILE(fragment)) - preprocessed += (IS_LOCAL(fragment) ? MARKER_IMPORT_LOCAL : MARKER_IMPORT_STD) + ';' + GET_PATH(fragment).length + ';' + GET_PATH(fragment); - else - { - var code = GET_CODE(fragment); - - if (shouldCheckSyntax) - { - try - { - new Function(GET_CODE(fragment)); - } - catch (e) - { - var lines = code.split("\n"), - PAD = 3; - - print("Syntax error in "+GET_FILE(fragment).path+ - " on preprocessed line number "+e.lineNumber+"\n"+ - "\t"+lines.slice(Math.max(0, e.lineNumber - 1 - PAD), e.lineNumber+PAD).join("\n\t")); - - os.exit(1); - } - } - - if (shouldCompress) - { - code = compress("function(){" + code + '}', 0, tmpFile); - - code = code.substr("function(){".length, code.length - "function(){};\n\n".length); - } - - preprocessed += MARKER_CODE + ';' + code.length + ';' + code; - } - } - - // Write file. - File.write(outFilePath, preprocessed, { charset: "UTF-8" }); -} - -function main() -{ - // FIXME: ARGS - system.args.shift(); - - var filePaths = [], - outFilePaths = [], - - index = 0, - count = system.args.length, - - gccArgs = [], - - flags = OBJJ_PREPROCESSOR_PREPROCESS | OBJJ_PREPROCESSOR_SYNTAX; - - - for (; index < count; ++index) - { - var argument = system.args[index]; - - if (argument === "-o") - { - if (++index < count) - outFilePaths.push(system.args[index]); - } - - else if (argument.indexOf("-D") === 0) - gccArgs.push(argument) - - else if (argument.indexOf("-U") === 0) - gccArgs.push(argument); - - else if (argument.indexOf("-E") === 0) - flags &= ~OBJJ_PREPROCESSOR_PREPROCESS; - - else if (argument.indexOf("-S") === 0) - flags &= ~OBJJ_PREPROCESSOR_SYNTAX; - - else if (argument.indexOf("-g") === 0) - flags |= OBJJ_PREPROCESSOR_DEBUG_SYMBOLS; - - else if (argument.indexOf("-O") === 0) - flags |= OBJJ_PREPROCESSOR_COMPRESS; - - else - filePaths.push(argument); - } - - for (index = 0, count = filePaths.length; index < count; ++index) - preprocess(filePaths[index], outFilePaths[index], gccArgs, flags); -} - -main(); - -} \ No newline at end of file +require("objj/objjc").main(system.args); diff --git a/Objective-J/Tools/objj/lib-js/objj/loader.js b/Objective-J/Tools/objj/lib-js/objj/loader.js index 2077a23fb..47265122e 100644 --- a/Objective-J/Tools/objj/lib-js/objj/loader.js +++ b/Objective-J/Tools/objj/lib-js/objj/loader.js @@ -8,7 +8,7 @@ function ObjectiveJLoader() { if (!objj) objj = require("objj/objj"); //print("loading objective-j: " + topId + " (" + path + ")"); - factories[topId] = objj.make_narwhal_factory(system.fs.read(path)/*, topId, path*/); + factories[topId] = objj.make_narwhal_factory(system.fs.read(path), path); } loader.load = function(topId, path) { diff --git a/Objective-J/Tools/objj/lib-js/objj/objj.js b/Objective-J/Tools/objj/lib-js/objj/objj.js index f4ef4d678..89fe1f244 100644 --- a/Objective-J/Tools/objj/lib-js/objj/objj.js +++ b/Objective-J/Tools/objj/lib-js/objj/objj.js @@ -1,20 +1,12 @@ -var File = require("file"), +var file = require("file"), readline = require("readline").readline; var window = require("browser/window"); -// variables to be exported from the module, for use in objjc, etc -var exported = [ - "objj_preprocess", - "FRAGMENT_FILE", "FRAGMENT_LOCAL", - "MARKER_CODE", "MARKER_IMPORT_STD", "MARKER_IMPORT_LOCAL", - "OBJJ_PREPROCESSOR_DEBUG_SYMBOLS" -]; - // setup OBJJ_HOME, OBJJ_INCLUDE_PATHS, etc -var OBJJ_HOME = exports.OBJJ_HOME = File.resolve(module.path, "..", ".."), - frameworksPath = File.resolve(OBJJ_HOME, "lib/", "Frameworks/"), - objectivejPath = File.resolve(frameworksPath, "Objective-J/", "rhino.platform/", "Objective-J.js"); +var OBJJ_HOME = exports.OBJJ_HOME = file.resolve(module.path, "..", ".."), + frameworksPath = file.resolve(OBJJ_HOME, "lib/", "Frameworks/"), + objectivejPath = file.resolve(frameworksPath, "Objective-J/", "rhino.platform/", "Objective-J.js"); window.OBJJ_INCLUDE_PATHS = [frameworksPath]; if (system.env["OBJJ_INCLUDE_PATHS"]) @@ -25,12 +17,44 @@ if (system.env["OBJJ_INCLUDE_PATHS"]) with (window) { // read and eval Objective-J.js with the module's scope - eval(File.read(objectivejPath, { charset:"UTF-8" })); + eval(file.read(objectivejPath, { charset:"UTF-8" })); - // export desired variables. must eval variable name to obtain a reference - for (var i = 0; i < exported.length; i++) - exports[exported[i]] = eval(exported[i]); + // export desired variables. must eval variable name to obtain a reference. + [ + "objj_preprocess", + "FRAGMENT_FILE", "FRAGMENT_LOCAL", + "MARKER_CODE", "MARKER_IMPORT_STD", "MARKER_IMPORT_LOCAL", + "OBJJ_PREPROCESSOR_DEBUG_SYMBOLS", + "objj_data", + "CPPropertyListCreateData", "CPPropertyListCreateFromData", + "kCFPropertyListXMLFormat_v1_0", "kCFPropertyList280NorthFormat_v1_0" + ].forEach(function(v) { + exports[v] = eval(v); + }); + + // extra macros + exports.SET_CONTEXT = function(aFragment, aContext) { aFragment.context = aContext; } + exports.GET_CONTEXT = function(aFragment) { return aFragment.context; } + exports.SET_TYPE = function(aFragment, aType) { aFragment.type = aType; } + exports.GET_TYPE = function(aFragment) { return aFragment.type; } + + exports.GET_CODE = function(aFragment) { return aFragment.info; } + exports.SET_CODE = function(aFragment, aCode) { aFragment.info = aCode; } + + exports.GET_PATH = function(aFragment) { return aFragment.info; } + exports.SET_PATH = function(aFragment, aPath) { aFragment.info = aPath; } + + exports.GET_BUNDLE = function(aFragment) { return aFragment.bundle; } + exports.SET_BUNDLE = function(aFragment, aBundle) { aFragment.bundle = aBundle; } + + exports.GET_FILE = function(aFragment) { return aFragment.file; } + exports.SET_FILE = function(aFragment, aFile) { aFragment.file = aFile; } + + exports.IS_FILE = function(aFragment) { return (aFragment.type & FRAGMENT_FILE); } + exports.IS_LOCAL = function(aFragment) { return (aFragment.type & FRAGMENT_LOCAL); } + exports.IS_IMPORT = function(aFragment) { return (aFragment.type & FRAGMENT_IMPORT); } + /* objj_set_evaluator(function(code) { return function(OBJJ_CURRENT_BUNDLE) { @@ -55,7 +79,7 @@ exports.run = function(args) while (args.length && args[0].indexOf('-I') === 0) OBJJ_INCLUDE_PATHS = args.shift().substr(2).split(':').concat(OBJJ_INCLUDE_PATHS); - var mainFilePath = File.canonical(args.shift()); + var mainFilePath = file.canonical(args.shift()); objj_import(mainFilePath, YES, function() { if (typeof main === "function") @@ -97,7 +121,7 @@ var objj_eval = exports.objj_eval = function(code) } // prepocesses Objective-J code into JavaScript, which will perform imports synchronously when eval'd -var objj_preprocess_sync = function(code) +var objj_preprocess_sync = function(code, path) { var fragments = objj_preprocess(code, new objj_bundle(), new objj_file(), OBJJ_PREPROCESSOR_DEBUG_SYMBOLS) @@ -107,7 +131,7 @@ var objj_preprocess_sync = function(code) if (fragment.type & FRAGMENT_CODE) preprocessed.push(fragment.info); else if (fragment.type & FRAGMENT_LOCAL) - preprocessed.push("objj_import_sync('"+fragment.info+"',YES);"); + preprocessed.push("objj_import_sync('"+(path ? file.join(file.dirname(path), fragment.info) : fragment.info)+"',YES);"); else preprocessed.push("objj_import_sync('"+fragment.info+"',NO);"); }); @@ -128,13 +152,12 @@ var objj_import_sync = function(pathOrPaths, isLocal) } // creates a narwhal factory function in the objj module scope -exports.make_narwhal_factory = function(code) { - // TODO: integrate better with objj load system so relative paths work +exports.make_narwhal_factory = function(code, path) { var OBJJ_CURRENT_BUNDLE = new objj_bundle(); return eval( "(function(require,exports,module,system,print){" + - objj_preprocess_sync(code) + + objj_preprocess_sync(code, path) + "/**/\n})" ); } diff --git a/Objective-J/Tools/objj/lib-js/objj/objjc.js b/Objective-J/Tools/objj/lib-js/objj/objjc.js new file mode 100644 index 000000000..6e532d89e --- /dev/null +++ b/Objective-J/Tools/objj/lib-js/objj/objjc.js @@ -0,0 +1,163 @@ +var file = require("file"), + os = require("os") + objj = require("./objj"); + +require("objj/regexp-rhino-patch"); + +var OBJJ_PREPROCESSOR_DEBUG_SYMBOLS = exports.OBJJ_PREPROCESSOR_DEBUG_SYMBOLS = objj.OBJJ_PREPROCESSOR_DEBUG_SYMBOLS; +var OBJJ_PREPROCESSOR_TYPE_SIGNATURES = exports.OBJJ_PREPROCESSOR_TYPE_SIGNATURES = objj.OBJJ_PREPROCESSOR_TYPE_SIGNATURES; +var OBJJ_PREPROCESSOR_PREPROCESS = exports.OBJJ_PREPROCESSOR_PREPROCESS = 1 << 10; +var OBJJ_PREPROCESSOR_COMPRESS = exports.OBJJ_PREPROCESSOR_COMPRESS = 1 << 11; +var OBJJ_PREPROCESSOR_SYNTAX = exports.OBJJ_PREPROCESSOR_SYNTAX = 1 << 12; + +var SHRINKSAFE_PATH = file.join(objj.OBJJ_HOME, "shrinksafe", "shrinksafe.jar"), + RHINO_PATH = file.join(objj.OBJJ_HOME, "shrinksafe", "js.jar") + +function compress(/*String*/ aCode, /*Object*/ flags, /*String*/ tmpFile) +{ + file.write(tmpFile, aCode, { charset:"UTF-8" }); + + return os.command(["java", "-Dfile.encoding=UTF-8", "-classpath", [RHINO_PATH, SHRINKSAFE_PATH].join(":"), "org.dojotoolkit.shrinksafe.Main", tmpFile]); +} + +exports.preprocess = function(inFile, outFile, flags, gccArgs) +{ + with(objj) + { + + print("Statically Preprocessing " + inFile); + + if (flags === undefined) + flags = OBJJ_PREPROCESSOR_PREPROCESS | OBJJ_PREPROCESSOR_SYNTAX; + + var shouldObjjPreprocess = flags & OBJJ_PREPROCESSOR_PREPROCESS, + shouldCheckSyntax = flags & OBJJ_PREPROCESSOR_SYNTAX, + shouldCompress = flags & OBJJ_PREPROCESSOR_COMPRESS; + + // FIXME: figure out why this doesn't work on Windows/Cygwin + //var tmpFile = java.io.File.createTempFile("OBJJC", ""); + var tmpFile = new java.io.File(outFile + ".tmp"); + tmpFile.deleteOnExit(); + tmpFile = tmpFile.getAbsolutePath(); + + // -E JUST preprocess. + // -x c Interpret language as C -- closest thing to JavaScript. + // -P Don't generate #line directives + var gccComponents = ["gcc"] + .concat("-E", "-x", "c", "-P", inFile) + .concat(gccArgs || []) + .concat("-o", shouldObjjPreprocess ? tmpFile : outFile); + + os.system(gccComponents); + + if (!shouldObjjPreprocess) + return; + + // Read file and preprocess it. + var fileContents = file.read(tmpFile, { charset: "UTF-8" }); + + // Preprocess contents into fragments. + var fragments = objj_preprocess(fileContents, { path : "/x" }, { path: file.basename(inFile) }, flags), + preprocessed = ""; + + // Writer preprocessed fragments out. + for (var index = 0; index < fragments.length; index++) + { + var fragment = fragments[index]; + + if (IS_FILE(fragment)) + preprocessed += (IS_LOCAL(fragment) ? MARKER_IMPORT_LOCAL : MARKER_IMPORT_STD) + ';' + GET_PATH(fragment).length + ';' + GET_PATH(fragment); + else + { + var code = GET_CODE(fragment); + + if (shouldCheckSyntax) + { + try + { + new Function(GET_CODE(fragment)); + } + catch (e) + { + var lines = code.split("\n"), + PAD = 3; + + print("Syntax error in "+GET_FILE(fragment).path+ + " on preprocessed line number "+e.lineNumber+"\n"+ + "\t"+lines.slice(Math.max(0, e.lineNumber - 1 - PAD), e.lineNumber+PAD).join("\n\t")); + + os.exit(1); + } + } + + if (shouldCompress) + { + code = compress("function(){" + code + '}', 0, tmpFile); + + code = code.substr("function(){".length, code.length - "function(){};\n\n".length); + } + + preprocessed += MARKER_CODE + ';' + code.length + ';' + code; + } + } + + // Write file. + file.write(outFile, preprocessed, { charset: "UTF-8" }); + + } +} + +exports.main = function(args) +{ + // FIXME: ARGS + args.shift(); + + var filePaths = [], + outFilePaths = [], + + index = 0, + count = args.length, + + gccArgs = [], + + flags = OBJJ_PREPROCESSOR_PREPROCESS | OBJJ_PREPROCESSOR_SYNTAX; + + + for (; index < count; ++index) + { + var argument = args[index]; + + if (argument === "-o") + { + if (++index < count) + outFilePaths.push(args[index]); + } + + else if (argument.indexOf("-D") === 0) + gccArgs.push(argument) + + else if (argument.indexOf("-U") === 0) + gccArgs.push(argument); + + else if (argument.indexOf("-E") === 0) + flags &= ~OBJJ_PREPROCESSOR_PREPROCESS; + + else if (argument.indexOf("-S") === 0) + flags &= ~OBJJ_PREPROCESSOR_SYNTAX; + + else if (argument.indexOf("-g") === 0) + flags |= OBJJ_PREPROCESSOR_DEBUG_SYMBOLS; + + else if (argument.indexOf("-O") === 0) + flags |= OBJJ_PREPROCESSOR_COMPRESS; + + else + filePaths.push(argument); + } + + for (index = 0, count = filePaths.length; index < count; ++index) + exports.preprocess(filePaths[index], outFilePaths[index], flags, gccArgs); +} + +if (require.main == module.id) + exports.main(system.args); \ No newline at end of file diff --git a/Objective-J/Tools/objj/lib-js/objj/plist.js b/Objective-J/Tools/objj/lib-js/objj/plist.js new file mode 100644 index 000000000..fd6e88e3e --- /dev/null +++ b/Objective-J/Tools/objj/lib-js/objj/plist.js @@ -0,0 +1,15 @@ +var file = require("file"), + objj = require("./objj"), + CPPropertyListCreateData = objj.CPPropertyListCreateData, + kCFPropertyListXMLFormat_v1_0 = objj.kCFPropertyListXMLFormat_v1_0; + +exports.readPlist = function(path) { + var plistData = new objj.objj_data(); + plistData.string = file.read(path); + return objj.CPPropertyListCreateFromData(plistData); +} + +exports.writePlist = function(path, plist, format) { + format = format || objj.kCFPropertyListXMLFormat_v1_0; + file.write(path, objj.CPPropertyListCreateData(plist, format).string); +} From 7017000c81dc03e15644378377479bd50053a6e7 Mon Sep 17 00:00:00 2001 From: Tom Robinson Date: Thu, 3 Sep 2009 01:08:35 -0700 Subject: [PATCH 2/3] Added dictionary methods to objj_dictionary.prototype --- Objective-J/dictionary.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Objective-J/dictionary.js b/Objective-J/dictionary.js index 488994e1d..43bc30b03 100644 --- a/Objective-J/dictionary.js +++ b/Objective-J/dictionary.js @@ -28,6 +28,13 @@ function objj_dictionary() this.__address = _objj_generateObjectHash(); } + +objj_dictionary.prototype.containsKey = function(aKey) { return dictionary_containsKey(this, aKey); } +objj_dictionary.prototype.getCount = function() { return dictionary_getCount(this); } +objj_dictionary.prototype.getValue = function(aKey) { return dictionary_getValue(this, aKey); } +objj_dictionary.prototype.setValue = function(aKey, aValue) { return dictionary_setValue(this, aKey, aValue); } +objj_dictionary.prototype.removeValue = function(aKey) { return dictionary_removeValue(this, aKey); } + function dictionary_containsKey(aDictionary, aKey) { return aDictionary._buckets[aKey] != NULL; @@ -116,4 +123,4 @@ function dictionary_description(aDictionary) str += " }"; return str; -} +} \ No newline at end of file From 3a7dee6cc2a0e0c9c7aaed723fa47cb2cf987e88 Mon Sep 17 00:00:00 2001 From: Tom Robinson Date: Thu, 3 Sep 2009 01:09:20 -0700 Subject: [PATCH 3/3] Added template config file to "capp", and ability to specify an absolute path for a template. --- Tools/capp/Generate.j | 47 +++++++++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 15 deletions(-) diff --git a/Tools/capp/Generate.j b/Tools/capp/Generate.j index 276ed6161..26576f98b 100644 --- a/Tools/capp/Generate.j +++ b/Tools/capp/Generate.j @@ -48,8 +48,18 @@ function gen(/*va_args*/) if (!justFrameworks && destination.length === 0) destination = "Untitled"; - var sourceTemplate = new java.io.File(OBJJ_HOME + "/lib/capp/Resources/Templates/" + template), - destinationProject = new java.io.File(destination), + var sourceTemplate = null; + if (File.isAbsolute(template)) + sourceTemplate = new java.io.File(template); + else + sourceTemplate = new java.io.File(OBJJ_HOME + "/lib/capp/Resources/Templates/" + template); + + var configFile = File.join(sourceTemplate, "template.config"), + config = {}; + if (File.isFile(configFile)) + config = JSON.parse(File.read(configFile)); + print(config.FrameworksPath) + var destinationProject = new java.io.File(destination), configuration = noConfig ? [Configuration defaultConfiguration] : [Configuration userConfiguration]; if (justFrameworks) @@ -86,36 +96,43 @@ function gen(/*va_args*/) File.write(path, contents, { charset: "UTF-8"}); } - createFrameworksInFile(destinationProject, shouldSymbolicallyLink); + var frameworkDestination = destinationProject.getCanonicalPath(); + if (config.FrameworksPath) + frameworkDestination = File.join(frameworkDestination, config.FrameworksPath); + + createFrameworksInFile(frameworkDestination, shouldSymbolicallyLink); } else print("Directory already exists"); } -function createFrameworksInFile(/*File*/ aFile, /*Boolean*/ shouldSymbolicallyLink, /*Boolean*/ force) +function createFrameworksInFile(/*String*/ aFile, /*Boolean*/ shouldSymbolicallyLink, /*Boolean*/ force) { - var destinationFrameworks = new java.io.File(aFile.getCanonicalPath()+ "/Frameworks"), - destinationDebugFrameworks = new java.io.File(aFile.getCanonicalPath() + "/Frameworks/Debug"); + if (!File.isDirectory(aFile)) + throw new Error("Can't create Frameworks. Directory does not exist: " + aFile); + + var destinationFrameworks = new java.io.File(aFile+ "/Frameworks"), + destinationDebugFrameworks = new java.io.File(aFile + "/Frameworks/Debug"); if (destinationFrameworks.exists()) { if (force) { print("Updating existing Frameworks directory."); - exec(["rm", "-rf", destinationFrameworks.getCanonicalPath()], true); + exec(["rm", "-rf", destinationFrameworks], true); } else { print("Frameworks directory already exists. Use --force to overwrite."); return; } } else { - print("Creating Frameworks directory."); + print("Creating Frameworks directory in "+destinationFrameworks+"."); } if (!shouldSymbolicallyLink) { var sourceFrameworks = new java.io.File(OBJJ_HOME + "/lib/Frameworks"); - exec(["cp", "-R", sourceFrameworks.getCanonicalPath(), destinationFrameworks.getCanonicalPath()], true); + exec(["cp", "-R", sourceFrameworks.getCanonicalPath(), destinationFrameworks], true); return; } @@ -129,25 +146,25 @@ function createFrameworksInFile(/*File*/ aFile, /*Boolean*/ shouldSymbolicallyLi new java.io.File(destinationFrameworks).mkdir(); exec(["ln", "-s", new java.io.File(BUILD + "/Release/Objective-J").getCanonicalPath(), - new java.io.File(aFile.getCanonicalPath() + "/Frameworks/Objective-J").getCanonicalPath()], true); + new java.io.File(aFile + "/Frameworks/Objective-J").getCanonicalPath()], true); exec(["ln", "-s", new java.io.File(BUILD + "/Release/Foundation").getCanonicalPath(), - new java.io.File(aFile.getCanonicalPath() + "/Frameworks/Foundation").getCanonicalPath()], true); + new java.io.File(aFile + "/Frameworks/Foundation").getCanonicalPath()], true); exec(["ln", "-s", new java.io.File(BUILD + "/Release/AppKit").getCanonicalPath(), - new java.io.File(aFile.getCanonicalPath() + "/Frameworks/AppKit").getCanonicalPath()], true); + new java.io.File(aFile + "/Frameworks/AppKit").getCanonicalPath()], true); // Debug Frameworks new java.io.File(destinationDebugFrameworks).mkdir(); exec(["ln", "-s", new java.io.File(BUILD + "/Debug/Objective-J").getCanonicalPath(), - new java.io.File(aFile.getCanonicalPath() + "/Frameworks/Debug/Objective-J").getCanonicalPath()], true); + new java.io.File(aFile + "/Frameworks/Debug/Objective-J").getCanonicalPath()], true); exec(["ln", "-s", new java.io.File(BUILD + "/Debug/Foundation").getCanonicalPath(), - new java.io.File(aFile.getCanonicalPath() + "/Frameworks/Debug/Foundation").getCanonicalPath()], true); + new java.io.File(aFile + "/Frameworks/Debug/Foundation").getCanonicalPath()], true); exec(["ln", "-s", new java.io.File(BUILD + "/Debug/AppKit").getCanonicalPath(), - new java.io.File(aFile.getCanonicalPath() + "/Frameworks/Debug/AppKit").getCanonicalPath()], true); + new java.io.File(aFile + "/Frameworks/Debug/AppKit").getCanonicalPath()], true); } function toIdentifier(/*String*/ aString)