mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-11-24 23:45:52 +00:00
Fixed: Faster objj_msgSend
Conflicts: Objective-J/Runtime.js
This commit is contained in:
1 parent
1557c567d4
commit
2411edd461
2 files changed
+211
-2
No files matched your search
@@ -829,7 +829,12 @@ Program: function(node, st, c) {
|
||||
BlockStatement: function(node, st, c) {
|
||||
var compiler = st.compiler,
|
||||
generate = compiler.generate,
|
||||
endOfScopeBody = st.endOfScopeBody,
|
||||
buffer;
|
||||
|
||||
if (endOfScopeBody)
|
||||
delete st.endOfScopeBody;
|
||||
|
||||
if (generate) {
|
||||
st.indentBlockLevel = typeof st.indentBlockLevel === "undefined" ? 0 : st.indentBlockLevel + 1;
|
||||
buffer = compiler.jsBuffer;
|
||||
@@ -840,6 +845,18 @@ BlockStatement: function(node, st, c) {
|
||||
c(node.body[i], st, "Statement");
|
||||
}
|
||||
if (generate) {
|
||||
var maxReceiverLevel = st.maxReceiverLevel;
|
||||
if (endOfScopeBody && maxReceiverLevel) {
|
||||
buffer.concat(indentation);
|
||||
buffer.concat("var ");
|
||||
for (var i = 0; i < maxReceiverLevel; i++) {
|
||||
if (i) buffer.concat(", ");
|
||||
buffer.concat("___r");
|
||||
buffer.concat((i + 1) + "");
|
||||
}
|
||||
buffer.concat(";\n");
|
||||
}
|
||||
|
||||
buffer.concat(indentation.substring(indentationSpaces));
|
||||
buffer.concat("}");
|
||||
if (st.isDecl || st.indentBlockLevel > 0)
|
||||
@@ -1023,6 +1040,7 @@ TryStatement: function(node, st, c) {
|
||||
buffer.concat(") ");
|
||||
}
|
||||
indentation += indentStep;
|
||||
inner.endOfScopeBody = true;
|
||||
c(handler.body, inner, "ScopeBody");
|
||||
indentation = indentation.substring(indentationSpaces);
|
||||
inner.copyAddedSelfToIvarsToParent();
|
||||
@@ -1161,6 +1179,7 @@ Function: function(node, st, c) {
|
||||
buffer.concat(")\n");
|
||||
}
|
||||
indentation += indentStep;
|
||||
inner.endOfScopeBody = true;
|
||||
c(node.body, inner, "ScopeBody");
|
||||
indentation = indentation.substring(indentationSpaces);
|
||||
inner.copyAddedSelfToIvarsToParent();
|
||||
@@ -2022,6 +2041,7 @@ MethodDeclarationStatement: function(node, st, c) {
|
||||
if (!generate)
|
||||
compiler.lastPos = node.startOfBody;
|
||||
indentation += indentStep;
|
||||
methodScope.endOfScopeBody = true;
|
||||
c(node.body, methodScope, "Statement");
|
||||
indentation = indentation.substring(indentationSpaces);
|
||||
if (!generate)
|
||||
@@ -2118,19 +2138,43 @@ MessageSendExpression: function(node, st, c) {
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!st.receiverLevel) st.receiverLevel = 0;
|
||||
if (!generate) buffer.concat(" "); // Add an extra space if it looks something like this: "return(<expression>)". No space between return and expression.
|
||||
buffer.concat("objj_msgSend(");
|
||||
buffer.concat("((___r");
|
||||
buffer.concat(++st.receiverLevel + "");
|
||||
buffer.concat(" = ");
|
||||
c(node.object, st, "Expression");
|
||||
buffer.concat("), ___r");
|
||||
buffer.concat(st.receiverLevel + "");
|
||||
buffer.concat(" == null ? null : ___r");
|
||||
buffer.concat(st.receiverLevel + "");
|
||||
buffer.concat(".isa.objj_msgSend");
|
||||
if (!generate) buffer.concat(compiler.source.substring(compiler.lastPos, node.object.end));
|
||||
if (!(st.maxReceiverLevel >= st.receiverLevel))
|
||||
st.maxReceiverLevel = st.receiverLevel;
|
||||
}
|
||||
|
||||
var selectors = node.selectors,
|
||||
arguments = node.arguments,
|
||||
argumentsLength = arguments.length,
|
||||
firstSelector = selectors[0],
|
||||
selector = firstSelector ? firstSelector.name : ""; // There is always at least one selector
|
||||
|
||||
if (!node.superObject) {
|
||||
var totalNoOfParameters = argumentsLength;
|
||||
|
||||
if (node.parameters)
|
||||
totalNoOfParameters += node.parameters.length;
|
||||
if (totalNoOfParameters < 4) {
|
||||
buffer.concat("" + totalNoOfParameters);
|
||||
}
|
||||
|
||||
buffer.concat("(___r");
|
||||
buffer.concat(st.receiverLevel + "");
|
||||
}
|
||||
|
||||
// Put together the selector. Maybe this should be done in the parser...
|
||||
for (var i = 0; i < arguments.length; i++)
|
||||
for (var i = 0; i < argumentsLength; i++)
|
||||
if (i === 0)
|
||||
selector += ":";
|
||||
else
|
||||
@@ -2169,6 +2213,11 @@ MessageSendExpression: function(node, st, c) {
|
||||
}
|
||||
}
|
||||
|
||||
if (!node.superObject) {
|
||||
buffer.concat(")");
|
||||
st.receiverLevel--;
|
||||
}
|
||||
|
||||
buffer.concat(")");
|
||||
if (!generate) compiler.lastPos = node.end;
|
||||
},
|
||||
|
||||
@@ -454,6 +454,17 @@ var _class_initialize = function(/*Class*/ aClass)
|
||||
{
|
||||
SETINFO(meta, CLS_INITIALIZING);
|
||||
|
||||
aClass.objj_msgSend = objj_msgSendMany;
|
||||
aClass.objj_msgSend0 = objj_msgSend0;
|
||||
aClass.objj_msgSend1 = objj_msgSend1;
|
||||
aClass.objj_msgSend2 = objj_msgSend2;
|
||||
aClass.objj_msgSend3 = objj_msgSend3;
|
||||
meta.objj_msgSend = objj_msgSendMany;
|
||||
meta.objj_msgSend0 = objj_msgSend0;
|
||||
meta.objj_msgSend1 = objj_msgSend1;
|
||||
meta.objj_msgSend2 = objj_msgSend2;
|
||||
meta.objj_msgSend3 = objj_msgSend3;
|
||||
|
||||
objj_msgSend(aClass, "initialize");
|
||||
|
||||
CHANGEINFO(meta, CLS_INITIALIZED, CLS_INITIALIZING);
|
||||
@@ -570,11 +581,25 @@ GLOBAL(objj_allocateClassPair) = function(/*Class*/ superclass, /*String*/ aName
|
||||
classObject.info = CLS_CLASS;
|
||||
classObject._UID = objj_generateObjectUID();
|
||||
|
||||
// It needs initialize
|
||||
classObject.objj_msgSend = objj_msgSendManyInitialize;
|
||||
classObject.objj_msgSend0 = objj_msgSend0Initialize;
|
||||
classObject.objj_msgSend1 = objj_msgSend1Initialize;
|
||||
classObject.objj_msgSend2 = objj_msgSend2Initialize;
|
||||
classObject.objj_msgSend3 = objj_msgSend3Initialize;
|
||||
|
||||
metaClassObject.isa = rootClassObject.isa;
|
||||
metaClassObject.name = aName;
|
||||
metaClassObject.info = CLS_META;
|
||||
metaClassObject._UID = objj_generateObjectUID();
|
||||
|
||||
// It needs initialize
|
||||
metaClassObject.objj_msgSend = objj_msgSendManyInitialize;
|
||||
metaClassObject.objj_msgSend0 = objj_msgSend0Initialize;
|
||||
metaClassObject.objj_msgSend1 = objj_msgSend1Initialize;
|
||||
metaClassObject.objj_msgSend2 = objj_msgSend2Initialize;
|
||||
metaClassObject.objj_msgSend3 = objj_msgSend3Initialize;
|
||||
|
||||
return classObject;
|
||||
}
|
||||
|
||||
@@ -788,6 +813,141 @@ GLOBAL(objj_msgSendSuper) = function(/*id*/ aSuper, /*SEL*/ aSelector)
|
||||
return implementation.apply(aSuper.receiver, arguments);
|
||||
}
|
||||
|
||||
var objj_msgSendMany = function(/*id*/ aReceiver, /*SEL*/ aSelector)
|
||||
{
|
||||
var method = this.method_dtable[aSelector],
|
||||
implementation = method ? method.method_imp : _objj_forward;
|
||||
|
||||
#ifdef MAXIMUM_RECURSION_CHECKS
|
||||
if (__objj_msgSend__StackDepth++ > MAXIMUM_RECURSION_DEPTH)
|
||||
throw new Error("Maximum call stack depth exceeded.");
|
||||
|
||||
try {
|
||||
#endif
|
||||
|
||||
return implementation.apply(aReceiver, arguments);
|
||||
|
||||
#ifdef MAXIMUM_RECURSION_CHECKS
|
||||
} finally {
|
||||
__objj_msgSend__StackDepth--;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
var objj_msgSendManyInitialize = function(/*id*/ aReceiver, /*SEL*/ aSelector)
|
||||
{
|
||||
_class_initialize(this);
|
||||
return this.objj_msgSend.apply(this, arguments);
|
||||
}
|
||||
|
||||
var objj_msgSend0 = function(/*id*/ aReceiver, /*SEL*/ aSelector)
|
||||
{
|
||||
var method = this.method_dtable[aSelector],
|
||||
implementation = method ? method.method_imp : _objj_forward;
|
||||
|
||||
#ifdef MAXIMUM_RECURSION_CHECKS
|
||||
if (__objj_msgSend__StackDepth++ > MAXIMUM_RECURSION_DEPTH)
|
||||
throw new Error("Maximum call stack depth exceeded.");
|
||||
|
||||
try {
|
||||
#endif
|
||||
|
||||
return implementation(aReceiver, aSelector);
|
||||
|
||||
#ifdef MAXIMUM_RECURSION_CHECKS
|
||||
} finally {
|
||||
__objj_msgSend__StackDepth--;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
var objj_msgSend0Initialize = function(/*id*/ aReceiver, /*SEL*/ aSelector)
|
||||
{
|
||||
_class_initialize(this);
|
||||
return this.objj_msgSend0(aReceiver, aSelector);
|
||||
}
|
||||
|
||||
var objj_msgSend1 = function(/*id*/ aReceiver, /*SEL*/ aSelector, arg0)
|
||||
{
|
||||
var method = this.method_dtable[aSelector],
|
||||
implementation = method ? method.method_imp : _objj_forward;
|
||||
|
||||
#ifdef MAXIMUM_RECURSION_CHECKS
|
||||
if (__objj_msgSend__StackDepth++ > MAXIMUM_RECURSION_DEPTH)
|
||||
throw new Error("Maximum call stack depth exceeded.");
|
||||
|
||||
try {
|
||||
#endif
|
||||
|
||||
return implementation(aReceiver, aSelector, arg0);
|
||||
|
||||
#ifdef MAXIMUM_RECURSION_CHECKS
|
||||
} finally {
|
||||
__objj_msgSend__StackDepth--;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
var objj_msgSend1Initialize = function(/*id*/ aReceiver, /*SEL*/ aSelector, arg0)
|
||||
{
|
||||
_class_initialize(this);
|
||||
return this.objj_msgSend1(aReceiver, aSelector, arg0);
|
||||
}
|
||||
|
||||
var objj_msgSend2 = function(/*id*/ aReceiver, /*SEL*/ aSelector, arg0, arg1)
|
||||
{
|
||||
var method = this.method_dtable[aSelector],
|
||||
implementation = method ? method.method_imp : _objj_forward;
|
||||
|
||||
#ifdef MAXIMUM_RECURSION_CHECKS
|
||||
if (__objj_msgSend__StackDepth++ > MAXIMUM_RECURSION_DEPTH)
|
||||
throw new Error("Maximum call stack depth exceeded.");
|
||||
|
||||
try {
|
||||
#endif
|
||||
|
||||
return implementation(aReceiver, aSelector, arg0, arg1);
|
||||
|
||||
#ifdef MAXIMUM_RECURSION_CHECKS
|
||||
} finally {
|
||||
__objj_msgSend__StackDepth--;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
var objj_msgSend2Initialize = function(/*id*/ aReceiver, /*SEL*/ aSelector, arg0, arg1)
|
||||
{
|
||||
_class_initialize(this);
|
||||
return this.objj_msgSend2(aReceiver, aSelector, arg0, arg1);
|
||||
}
|
||||
|
||||
var objj_msgSend3 = function(/*id*/ aReceiver, /*SEL*/ aSelector, arg0, arg1, arg2)
|
||||
{
|
||||
var method = this.method_dtable[aSelector],
|
||||
implementation = method ? method.method_imp : _objj_forward;
|
||||
|
||||
#ifdef MAXIMUM_RECURSION_CHECKS
|
||||
if (__objj_msgSend__StackDepth++ > MAXIMUM_RECURSION_DEPTH)
|
||||
throw new Error("Maximum call stack depth exceeded.");
|
||||
|
||||
try {
|
||||
#endif
|
||||
|
||||
return implementation(aReceiver, aSelector, arg0, arg1, arg2);
|
||||
|
||||
#ifdef MAXIMUM_RECURSION_CHECKS
|
||||
} finally {
|
||||
__objj_msgSend__StackDepth--;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
var objj_msgSend3Initialize = function(/*id*/ aReceiver, /*SEL*/ aSelector, arg0, arg1, arg2)
|
||||
{
|
||||
_class_initialize(this);
|
||||
return this.objj_msgSend3(aReceiver, aSelector, arg0, arg1, arg2);
|
||||
}
|
||||
|
||||
// Working with Methods
|
||||
|
||||
GLOBAL(method_getName) = function(/*Method*/ aMethod)
|
||||
|
||||
Reference in new issue
Block a user