Added support for new compiler when loading objj files in the browsers

This commit is contained in:
Martin Carlberg committed 2012-12-15 23:35:36 +01:00
1 parent a202cfbbe9
commit 59fa5c27b6
5 files changed
+4597 -7

No files matched your search

+27 -3
View File
@@ -26,15 +26,17 @@ var ExecutableUnloadedFileDependencies = 0,
ExecutableLoadedFileDependencies = 2,
AnonymousExecutableCount = 0;
function Executable(/*String*/ aCode, /*Array*/ fileDependencies, /*CFURL|String*/ aURL, /*Function*/ aFunction)
function Executable(/*String*/ aCode, /*Array*/ fileDependencies, /*CFURL|String*/ aURL, /*Function*/ aFunction, /*ObjJCompiler*/aCompiler)
{
if (arguments.length === 0)
return this;
this._code = aCode;
this._function = aFunction || NULL;
this._function = aFunction || null;
this._URL = makeAbsoluteURL(aURL || new CFURL("(Anonymous" + (AnonymousExecutableCount++) + ")"));
this._compiler = aCompiler || null;
this._fileDependencies = fileDependencies;
if (fileDependencies.length)
@@ -48,7 +50,8 @@ function Executable(/*String*/ aCode, /*Array*/ fileDependencies, /*CFURL|String
if (this._function)
return;
this.setCode(aCode);
if (!aCompiler)
this.setCode(aCode);
}
exports.Executable = Executable;
@@ -135,6 +138,27 @@ Executable.prototype.execute = function()
#if EXECUTION_LOGGING
CPLog("EXECUTION: " + this.URL());
#endif
if (this._compiler)
{
var fileDependencies = this.fileDependencies(),
index = 0,
count = fileDependencies.length;
for (; index < count; ++index)
{
var fileDependency = fileDependencies[index],
isQuoted = fileDependency.isLocal(),
URL = fileDependency.URL();
CPLog("Execute FileDependant: " + URL);
objj_executeFile(URL, isQuoted);
}
CPLog("Compile Pass 2: " + this.URL());
this.setCode(this._compiler.compilePass2());
}
var oldContextBundle = CONTEXT_BUNDLE;
// FIXME: Should we have stored this?
+8 -4
View File
@@ -41,13 +41,17 @@ function FileExecutable(/*CFURL|String*/ aURL)
if (fileContents.match(/^@STATIC;/))
executable = decompile(fileContents, aURL);
else if (extension === "j" || !extension)
executable = exports.preprocess(fileContents, aURL, Preprocessor.Flags.IncludeDebugSymbols);
else if (extension === "j" || !extension) {
// console.log("Compile: " + aURL);
// if (!aURL || aURL.toString().indexOf("Boplats/Office/Applications") === -1)
// executable = exports.preprocess(fileContents, aURL, Preprocessor.Flags.IncludeDebugSymbols);
// else
executable = exports.compileFileDependencies(fileContents, aURL, ObjJCompiler.Flags.IncludeDebugSymbols);
}
else
executable = new Executable(fileContents, [], aURL);
Executable.apply(this, [executable.code(), executable.fileDependencies(), aURL, executable._function]);
Executable.apply(this, [executable.code(), executable.fileDependencies(), aURL, executable._function, executable._compiler]);
this._hasExecuted = NO;
}
+2
View File
@@ -43,6 +43,8 @@
#include "CFBundle.js"
#include "StaticResource.js"
#include "Preprocessor.js"
#include "Parser.js"
#include "ObjJCompiler.js"
#include "FileDependency.js"
#include "Executable.js"
#include "FileExecutable.js"
File diff suppressed because it is too large. Load diff
+382
View File
@@ -0,0 +1,382 @@
var Parser = { };
var compiledGrammar = {"table":[[0,"source",1],[0,"start",2],[4,3,4,3],[0,"_",5],[8,6],[6,7],[0,"SourceElements",8],[3,9,10,11],[4,12,13],[0,"WhiteSpace",14],[0,"LineTerminator",15],[0,"Comment",16],[0,"SourceElement",17],[6,18],[2,"[\\u0009\\u000B\\u000C\\u0020\\u00A0\\uFEFF\\u1680\\u180E\\u2000-\\u200A\\u202F\\u205F\\u3000]"],[2,"[\\u000A\\u000D\\u2028\\u2029]"],[3,19,20],[3,21,22],[4,3,12],[0,"MultiLineComment",23],[0,"SingleLineComment",24],[0,"Statement",25],[0,"FunctionDeclaration",26],[4,27,28,29],[4,30,31],[3,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,22,47,48,49],[4,50,3,51,3,52,3,53,3,54,3,55,3,56,3,57],[5,"/*"],[6,58],[5,"*/"],[5,"//"],[6,59],[0,"Block",60],[0,"VariableStatement",61],[0,"EmptyStatement",62],[0,"ExpressionStatement",63],[0,"IfStatement",64],[0,"IterationStatement",65],[0,"ContinueStatement",66],[0,"BreakStatement",67],[0,"ReturnStatement",68],[0,"WithStatement",69],[0,"LabelledStatement",70],[0,"SwitchStatement",71],[0,"ThrowStatement",72],[0,"TryStatement",73],[0,"DebuggerStatement",74],[0,"FunctionExpression",75],[0,"ImportStatement",76],[0,"ClassDeclarationStatement",77],[0,"FUNCTION",78],[0,"Identifier",79],[5,"("],[8,80],[5,")"],[5,"{"],[0,"FunctionBody",2],[5,"}"],[4,81,82],[0,"SingleLineCommentChar",83],[4,55,3,84,3,57],[4,85,3,86,87,88],[5,";"],[4,89,90,88],[4,91,3,52,3,90,3,54,3,21,92],[3,93,94,95,96,97],[4,98,99,100],[4,101,99,100],[4,102,99,103],[4,104,3,52,3,90,3,54,3,21],[4,51,3,105,3,21],[4,106,3,52,3,90,3,54,3,107],[4,108,99,103],[4,109,3,32,3,110],[4,111,88],[4,50,3,112,3,52,3,53,3,54,3,55,3,56,3,57],[4,113,3,114,88],[4,115,3,51,3,116,3,117,3,118,3,119,88],[4,120,121],[4,122,123],[0,"FormalParameterList",124],[9,29],[1],[4,125,82],[8,126],[0,"VAR",127],[0,"VariableDeclaration",128],[6,129],[0,"EOS",130],[9,131],[0,"Expression",132],[0,"IF",133],[8,134],[0,"DoWhileStatement",135],[0,"WhileStatement",136],[0,"ForStatement",137],[0,"ForInStatement",138],[0,"EachStatement",139],[0,"CONTINUE",140],[0,"__",141],[3,142,143],[0,"BREAK",144],[0,"RETURN",145],[3,143,146],[0,"WITH",147],[5,":"],[0,"SWITCH",148],[0,"CaseBlock",149],[0,"THROW",150],[0,"TRY",151],[3,152,153],[0,"DEBUGGER",154],[8,51],[5,"@import"],[3,155,156],[5,"@implementation"],[8,157],[8,158],[0,"ClassBody",159],[5,"@end"],[5,"function"],[9,160],[9,161],[0,"IdentifierName",162],[4,51,163],[9,10],[0,"StatementList",164],[4,165,121],[4,51,166],[4,3,167,3,86],[3,168,169,170,171],[3,55,50],[4,172,173],[4,174,121],[4,3,175,3,21],[4,176,3,21,3,177,3,52,3,90,3,54,88],[4,177,3,52,3,90,3,54,3,21],[4,178,3,52,3,179,3,62,3,180,3,62,3,180,3,54,3,21],[4,178,3,52,3,181,3,182,3,90,3,54,3,21],[4,183,3,52,3,181,3,182,3,90,3,54,3,21],[4,184,121],[6,185],[4,51,88],[0,"SemicolonInsertionEOS",186],[4,187,121],[4,188,121],[4,90,88],[4,189,121],[4,190,121],[4,55,3,191,3,192,3,191,3,57],[4,193,121],[4,194,121],[4,195,196],[0,"Finally",197],[4,198,121],[0,"LocalFilePath",199],[0,"StandardFilePath",200],[3,201,202],[4,55,203,3,57],[8,204],[0,"IdentifierPart",205],[4,206,121],[4,207,208],[6,209],[4,21,210],[5,"var"],[8,211],[5,","],[4,3,62],[4,99,212],[4,99,213],[4,99,214],[0,"AssignmentExpression",215],[6,216],[5,"if"],[0,"ELSE",217],[0,"DO",218],[0,"WHILE",219],[0,"FOR",220],[8,221],[8,90],[0,"ForInFirstExpression",222],[0,"IN",223],[5,"@each"],[5,"continue"],[3,9,224,20],[3,225,169,170,171],[5,"break"],[5,"return"],[5,"with"],[5,"switch"],[8,226],[8,227],[5,"throw"],[5,"try"],[0,"Catch",228],[8,229],[4,230,3,32],[5,"debugger"],[0,"StringLiteral",231],[4,232,3,233,3,234],[0,"SuperclassDeclaration",235],[0,"CategoryDeclaration",236],[6,237],[0,"ClassElements",238],[3,207,239,240,241,242,243],[0,"ReservedWord",244],[0,"IdentifierStart",245],[6,160],[4,3,167,3,51],[6,246],[4,3,247,248,3,172],[0,"LineTerminatorSequence",249],[10,57],[0,"EOF",250],[3,251,252],[4,3,167,3,172],[4,253,121],[4,254,121],[4,255,121],[4,256,121],[0,"ForFirstExpression",257],[3,258,259],[4,260,121],[0,"SingleLineMultiLineComment",261],[4,99,62],[0,"CaseClauses",262],[0,"DefaultClause",263],[4,264,3,52,3,51,3,54,3,32],[4,3,153],[0,"FINALLY",265],[3,266,267],[5,"<"],[6,268],[5,">"],[4,105,3,51],[4,52,3,51,3,54],[4,3,269],[4,270,271],[0,"UnicodeCombiningMark",272],[0,"UnicodeDigit",273],[0,"UnicodeConnectorPunctuation",274],[0,"ZWNJ",275],[0,"ZWJ",276],[3,277,278,279,280],[3,281,282,283],[4,3,21],[5,"="],[9,247],[3,284,285,286,287,288],[9,82],[4,258,3,289,3,172],[0,"ConditionalExpression",290],[5,"else"],[5,"do"],[5,"while"],[5,"for"],[3,291,292],[0,"LeftHandSideExpression",293],[4,85,3,294],[5,"in"],[4,27,295,29],[4,296,297],[4,298,3,105,299],[0,"CATCH",300],[4,301,121],[4,302,303,304,303],[4,305,306,305],[3,307,308],[0,"CompoundIvarDeclaration",309],[0,"ClassElement",310],[6,311],[3,312,313,314,315,316,317],[3,318,319,320,321],[2,"[\\u005F\\u203F\\u2040\\u2054\\uFE33\\uFE34\\uFE4D-\\uFE4F\\uFF3F]"],[5,"\u200C"],[5,"\u200D"],[0,"Keyword",322],[0,"FutureReservedWord",323],[0,"NullLiteral",324],[0,"BooleanLiteral",325],[0,"UnicodeLetter",326],[2,"[$_]"],[4,327,32Line truncated
//function Parser(/*String | CompiledGrammar*/ aGrammar)
/*{
if (typeof aGrammar.valueOf() === "string")
this.compiledGrammar = new (require("./compiledgrammar"))(aGrammar);
else
this.compiledGrammar = aGrammar;
return this;
}*/
//exports.Parser = Parser;
var Parser = function(/*CompiledGrammar*/ aGrammar)
{
this.compiledGrammar = aGrammar;
}
//Parser.compiledGrammar = compiledGrammar;
Parser.prototype.parse = function(input)
{
return parse(this.compiledGrammar, input);
}
var NAME = 0,
DOT = 1,
CHARACTER_CLASS = 2,
ORDERED_CHOICE = 3,
SEQUENCE = 4,
STRING_LITERAL = 5,
ZERO_OR_MORE = 6,
ONE_OR_MORE = 7,
OPTIONAL = 8,
NEGATIVE_LOOK_AHEAD = 9,
POSITIVE_LOOK_AHEAD = 10,
ERROR_NAME = 11,
ERROR_CHOICE = 12;
function parse(aCompiledGrammar, input, name)
{
var node = new SyntaxNode("#document", input, 0, 0),
table = aCompiledGrammar.table,
nameToUID = aCompiledGrammar.nameToUID;
name = name || "start";
// This is a stupid check.
if (aCompiledGrammar.nameToUID["EOF"] !== undefined)
table[0] = [SEQUENCE, nameToUID[name], nameToUID["EOF"]];
if (!evaluate(new context(input, table), node, table, 0))
{
// This is a stupid check.
if (aCompiledGrammar.nameToUID["EOF"] !== undefined)
table[0] = [SEQUENCE, nameToUID["%" + name], nameToUID["EOF"]];
node.children.length = 0;
evaluate(new context(input, table), node, table, 0);
node.traverse(
{
traverseTextNodes:false,
enteredNode:function(node)
{
if (node.error)
console.log(node.message() + "\n");
}
});
}
return node;
}
exports.parse = parse;
function context(input, table)
{
this.position = 0;
this.input = input;
this.memos = [];
for (var i=0;i<table.length;++i)
this.memos[i] = [];
}
function evaluate(context, parent, rules, rule_id)
{
var rule = rules[rule_id],
type = rule[0],
input_length = context.input.length,
memos = context.memos[rule_id];
var uid = context.position,
entry = memos[uid];
if (entry === false)
return false;
else if (entry === true)
return true;
else if (entry)
{
if (parent)
parent.children.push(entry.node);
context.position = entry.position;
return true;
}
switch (type)
{
case NAME:
case ERROR_NAME:
var node = new SyntaxNode(rule[1], context.input, context.position, 0, rule[3]);
if (!evaluate(context, node, rules, rule[2]))
{
memos[uid] = false;
return false;
}
node.range.length = context.position - node.range.location;
memos[uid] = { node:node, position:context.position };
if (parent)
parent.children.push(node);
return true;
case CHARACTER_CLASS:
var character = context.input.charAt(context.position);
if (typeof rule[1].valueOf() === "string")
rule[1] = new RegExp(rule[1], "g");
if (character.match(rule[1]))
{
if (parent)
parent.children.push(character);
++context.position;
return true;
}
memos[uid] = false;
return false;
case SEQUENCE:
var index = 1,
count = rule.length;
for (; index < count; ++index)
if (!evaluate(context, parent, rules, rule[index]))
{
memos[uid] = false;
return false;
}
return true;
case ORDERED_CHOICE:
case ERROR_CHOICE:
var index = 1,
count = rule.length,
position = context.position;
for (; index < count; ++index)
{
// cache opportunity here.
var child_count = parent && parent.children.length;
if (evaluate(context, parent, rules, rule[index]))
return true;
if (parent)
parent.children.length = child_count;
context.position = position;
}
memos[uid] = false;
return false;
case STRING_LITERAL:
var string = rule[1],
string_length = string.length;
if (string_length + context.position > input_length)
{
memos[uid] = false;
return false;
}
var index = 0;
for (; index < string_length; ++context.position, ++index)
if (context.input.charCodeAt(context.position) !== string.charCodeAt(index))
{
context.position -= index;
memos[uid] = false;
return false;
}
// memos[uid] = string;
if (parent)
parent.children.push(string);
return true;
case DOT:
if (context.position < input_length)
{
if (parent)
parent.children.push(context.input.charAt(context.position));
++context.position;
return true;
}
memos[uid] = false;
return false;
case POSITIVE_LOOK_AHEAD:
case NEGATIVE_LOOK_AHEAD:
var position = context.position,
result = evaluate(context, null, rules, rule[1]) === (type === POSITIVE_LOOK_AHEAD);
context.position = position;
memos[uid] = result;
return result;
case ZERO_OR_MORE:
var child,
position = context.position,
childCount = parent && parent.children.length;
while (evaluate(context, parent, rules, rule[1]))
{
position = context.position,
childCount = parent && parent.children.length;
}
context.position = position;
if (parent)
parent.children.length = childCount;
return true;
case ONE_OR_MORE:
var position = context.position,
childCount = parent && parent.children.length;
if (!evaluate(context, parent, rules, rule[1]))
{
memos[uid] = false;
context.position = position;
if (parent)
parent.children.length = childCount;
return false;
}
position = context.position,
childCount = parent && parent.children.length;
while (evaluate(context, parent, rules, rule[1]))
{
position = context.position;
childCount = parent && parent.children.length;
}
context.position = position;
if (parent)
parent.children.length = childCount;
return true;
case OPTIONAL:
var position = context.position,
childCount = parent && parent.children.length;
if (!evaluate(context, parent, rules, rule[1]))
{
context.position = position;
if (parent)
parent.children.length = childCount;
}
return true;
}
}
function SyntaxNode(/*String*/ aName, /*String*/ aSource, /*Number*/ aLocation, /*Number*/ aLength, /*String*/anErrorMessage)
{
this.name = aName;
this.source = aSource;
this.range = { location:aLocation, length:aLength };
this.children = [];
if (anErrorMessage)
this.error = anErrorMessage;
}
SyntaxNode.prototype.message = function()
{
var source = this.source,
lineNumber = 1,
index = 0,
start = 0,
length = source.length,
range = this.range;
for (; index < range.location; ++index)
if (source.charAt(index) === '\n')
{
++lineNumber;
start = index + 1;
}
for (; index < length; ++index)
if (source.charAt(index) === '\n')
break;
var line = source.substring(start, index);
message = line + "\n";
message += (new Array(this.range.location - start + 1)).join(" ");
message += (new Array(Math.min(range.length, line.length) + 1)).join("^") + "\n";
message += "ERROR line " + lineNumber + ": " + this.error;
return message;
}
SyntaxNode.prototype.toString = function(/*String*/ spaces)
{
if (!spaces)
spaces = "";
var string = spaces + this.name + " <" + this.innerText() + "> ",
children = this.children,
index = 0,
count = children.length;
for (; index < count; ++index)
{
var child = children[index];
if (typeof child === "string")
string += "\n" + spaces + "\t" + child;
else
string += "\n" + children[index].toString(spaces + '\t');
}
return string;
}
SyntaxNode.prototype.innerText = function()
{
var range = this.range;
return this.source.substr(range.location, range.length);
}
SyntaxNode.prototype.traverse = function(walker)
{
if (!walker.enteredNode || walker.enteredNode(this) !== false)
{
var children = this.children,
index = 0,
count = children && children.length;
for (; index < count; ++index)
{
var child = children[index];
if (typeof child !== "string")
child.traverse(walker);
else if (walker.traversesTextNodes)
{
walker.enteredNode(child);
walker.exitedNode(child);
}
}
}
if (walker.exitedNode)
walker.exitedNode(this);
}
exports.Parser = new Parser(compiledGrammar);