%token <identifier_> XML "xml"
@end
+@begin ObjectiveC
+%type <expression_> AdditiveExpressionNoWC
+%type <expression_> AssigneeExpressionNoWC
+%type <expression_> AssignmentExpressionNoWC
+%type <expression_> BitwiseANDExpressionNoWC
+%type <expression_> BitwiseXORExpressionNoWC
+%type <expression_> BitwiseORExpressionNoWC
+%type <expression_> ConditionalExpressionNoWC
+%type <expression_> EqualityExpressionNoWC
+%type <expression_> LeftHandSideExpressionNoWC
+%type <expression_> LogicalANDExpressionNoWC
+%type <expression_> LogicalORExpressionNoWC
+%type <expression_> MemberExpressionNoWC
+%type <expression_> MultiplicativeExpressionNoWC
+%type <expression_> NewExpressionNoWC
+%type <expression_> PostfixExpressionNoWC
+%type <expression_> RelationalExpressionNoWC
+%type <expression_> ShiftExpressionNoWC
+%type <expression_> UnaryExpressionNoWC
+@end
+
%token <identifier_> Identifier_
%token <number_> NumericLiteral
%token <string_> StringLiteral
%type <expression_> AdditiveExpression
%type <expression_> AdditiveExpressionNoBF
-%type <expression_> AdditiveExpressionNoWC
%type <argument_> ArgumentList
%type <argument_> ArgumentList_
%type <argument_> ArgumentListOpt
%type <expression_> AssigneeExpression
%type <expression_> AssigneeExpressionNoBF
%type <expression_> AssigneeExpressionNoRE
-%type <expression_> AssigneeExpressionNoWC
%type <expression_> AssignmentExpression
%type <assignment_> AssignmentExpression_
%type <expression_> AssignmentExpressionNoBF
%type <expression_> AssignmentExpressionNoIn
-%type <expression_> AssignmentExpressionNoWC
%type <expression_> BitwiseANDExpression
%type <expression_> BitwiseANDExpressionNoBF
%type <expression_> BitwiseANDExpressionNoIn
-%type <expression_> BitwiseANDExpressionNoWC
%type <statement_> Block
%type <statement_> Block_
%type <boolean_> BooleanLiteral
%type <expression_> BitwiseORExpression
%type <expression_> BitwiseORExpressionNoBF
%type <expression_> BitwiseORExpressionNoIn
-%type <expression_> BitwiseORExpressionNoWC
%type <expression_> BitwiseXORExpression
%type <expression_> BitwiseXORExpressionNoBF
%type <expression_> BitwiseXORExpressionNoIn
-%type <expression_> BitwiseXORExpressionNoWC
%type <statement_> BreakStatement
%type <expression_> CallExpression
%type <expression_> CallExpressionNoBF
%type <expression_> ConditionalExpression
%type <expression_> ConditionalExpressionNoBF
%type <expression_> ConditionalExpressionNoIn
-%type <expression_> ConditionalExpressionNoWC
%type <statement_> ContinueStatement
%type <clause_> DefaultClause
%type <statement_> DoWhileStatement
%type <expression_> EqualityExpression
%type <expression_> EqualityExpressionNoBF
%type <expression_> EqualityExpressionNoIn
-%type <expression_> EqualityExpressionNoWC
%type <expression_> Expression
%type <expression_> ExpressionOpt
%type <compound_> Expression_
%type <expression_> LeftHandSideExpression
%type <expression_> LeftHandSideExpressionNoBF
%type <expression_> LeftHandSideExpressionNoRE
-%type <expression_> LeftHandSideExpressionNoWC
//%type <statement_> LetStatement
%type <literal_> Literal
%type <literal_> LiteralNoRE
%type <expression_> LogicalANDExpression
%type <expression_> LogicalANDExpressionNoBF
%type <expression_> LogicalANDExpressionNoIn
-%type <expression_> LogicalANDExpressionNoWC
%type <expression_> LogicalORExpression
%type <expression_> LogicalORExpressionNoBF
%type <expression_> LogicalORExpressionNoIn
-%type <expression_> LogicalORExpressionNoWC
%type <member_> MemberAccess
%type <expression_> MemberExpression
%type <expression_> MemberExpression_
%type <expression_> MemberExpressionNoBF
%type <expression_> MemberExpressionNoRE
-%type <expression_> MemberExpressionNoWC
%type <expression_> MultiplicativeExpression
%type <expression_> MultiplicativeExpressionNoBF
-%type <expression_> MultiplicativeExpressionNoWC
%type <expression_> NewExpression
%type <expression_> NewExpression_
%type <expression_> NewExpressionNoBF
%type <expression_> NewExpressionNoRE
-%type <expression_> NewExpressionNoWC
%type <null_> NullLiteral
%type <literal_> ObjectLiteral
%type <expression_> PostfixExpression
%type <expression_> PostfixExpressionNoBF
%type <expression_> PostfixExpressionNoRE
-%type <expression_> PostfixExpressionNoWC
%type <expression_> PrimaryExpression
%type <expression_> PrimaryExpressionNo
%type <expression_> PrimaryExpressionNoBF
%type <infix_> RelationalExpression_
%type <expression_> RelationalExpressionNoBF
%type <expression_> RelationalExpressionNoIn
-%type <expression_> RelationalExpressionNoWC
%type <infix_> RelationalExpressionNoIn_
%type <statement_> ReturnStatement
%type <expression_> ShiftExpression
%type <expression_> ShiftExpressionNoBF
-%type <expression_> ShiftExpressionNoWC
%type <statement_> SourceElement
%type <statement_> SourceElement_
%type <statement_> SourceElements
%type <expression_> UnaryExpression_
%type <expression_> UnaryExpressionNoBF
%type <expression_> UnaryExpressionNoRE
-%type <expression_> UnaryExpressionNoWC
%type <declaration_> VariableDeclaration
%type <declaration_> VariableDeclarationNoIn
%type <declarations_> VariableDeclarationList
| MemberExpression_ { $$ = $1; }
;
+@begin ObjectiveC
MemberExpressionNoWC
: PrimaryExpression { $$ = $1; }
| LexSetRegExp FunctionExpression { $$ = $2; }
| MemberExpression MemberAccess { $2->SetLeft($1); $$ = $2; }
| LexSetRegExp MemberExpression_ { $$ = $2; }
;
+@end
NewExpression_
: "new" NewExpression { $$ = new(driver.pool_) CYNew($2, NULL); }
| NewExpression_ { $$ = $1; }
;
+@begin ObjectiveC
NewExpressionNoWC
: MemberExpressionNoWC { $$ = $1; }
| LexSetRegExp NewExpression_ { $$ = $2; }
;
+@end
CallExpression
: PrimaryExpressionNoWC Arguments { $$ = new(driver.pool_) CYCall($1, $2); }
| CallExpressionNoRE { $$ = $1; }
;
+@begin ObjectiveC
LeftHandSideExpressionNoWC
: NewExpressionNoWC { $$ = $1; }
| CallExpression { $$ = $1; }
;
+@end
/* }}} */
/* 11.3 Postfix Expressions {{{ */
PostfixExpression
| LeftHandSideExpressionNoRE "--" { $$ = new(driver.pool_) CYPostDecrement($1); }
;
+@begin ObjectiveC
PostfixExpressionNoWC
: AssigneeExpressionNoWC { $$ = $1; }
| LeftHandSideExpression "++" { $$ = new(driver.pool_) CYPostIncrement($1); }
| LeftHandSideExpression "--" { $$ = new(driver.pool_) CYPostDecrement($1); }
;
+@end
/* }}} */
/* 11.4 Unary Operators {{{ */
UnaryExpression_
| UnaryExpression_ { $$ = $1; }
;
+@begin ObjectiveC
UnaryExpressionNoWC
: PostfixExpressionNoWC { $$ = $1; }
| LexSetRegExp UnaryExpression_ { $$ = $2; }
;
+@end
/* }}} */
/* 11.5 Multiplicative Operators {{{ */
MultiplicativeExpression
| MultiplicativeExpressionNoBF "%" UnaryExpression { $$ = new(driver.pool_) CYModulus($1, $3); }
;
+@begin ObjectiveC
MultiplicativeExpressionNoWC
: UnaryExpressionNoWC { $$ = $1; }
| MultiplicativeExpression "*" UnaryExpression { $$ = new(driver.pool_) CYMultiply($1, $3); }
| MultiplicativeExpression "/" UnaryExpression { $$ = new(driver.pool_) CYDivide($1, $3); }
| MultiplicativeExpression "%" UnaryExpression { $$ = new(driver.pool_) CYModulus($1, $3); }
;
+@end
/* }}} */
/* 11.6 Additive Operators {{{ */
AdditiveExpression
| AdditiveExpressionNoBF "-" MultiplicativeExpression { $$ = new(driver.pool_) CYSubtract($1, $3); }
;
+@begin ObjectiveC
AdditiveExpressionNoWC
: MultiplicativeExpressionNoWC { $$ = $1; }
| AdditiveExpression "+" MultiplicativeExpression { $$ = new(driver.pool_) CYAdd($1, $3); }
| AdditiveExpression "-" MultiplicativeExpression { $$ = new(driver.pool_) CYSubtract($1, $3); }
;
+@end
/* }}} */
/* 11.7 Bitwise Shift Operators {{{ */
ShiftExpression
| ShiftExpressionNoBF ">>>" AdditiveExpression { $$ = new(driver.pool_) CYShiftRightUnsigned($1, $3); }
;
+@begin ObjectiveC
ShiftExpressionNoWC
: AdditiveExpressionNoWC { $$ = $1; }
| ShiftExpression "<<" AdditiveExpression { $$ = new(driver.pool_) CYShiftLeft($1, $3); }
| ShiftExpression ">>" AdditiveExpression { $$ = new(driver.pool_) CYShiftRightSigned($1, $3); }
| ShiftExpression ">>>" AdditiveExpression { $$ = new(driver.pool_) CYShiftRightUnsigned($1, $3); }
;
+@end
/* }}} */
/* 11.8 Relational Operators {{{ */
RelationalExpressionNoIn_
| RelationalExpressionNoBF RelationalExpression_ { $2->SetLeft($1); $$ = $2; }
;
+@begin ObjectiveC
RelationalExpressionNoWC
: ShiftExpressionNoWC { $$ = $1; }
| RelationalExpression RelationalExpression_ { $2->SetLeft($1); $$ = $2; }
;
+@end
/* }}} */
/* 11.9 Equality Operators {{{ */
EqualityExpression
| EqualityExpressionNoBF "!==" RelationalExpression { $$ = new(driver.pool_) CYNotIdentical($1, $3); }
;
+@begin ObjectiveC
EqualityExpressionNoWC
: RelationalExpressionNoWC { $$ = $1; }
| EqualityExpression "==" RelationalExpression { $$ = new(driver.pool_) CYEqual($1, $3); }
| EqualityExpression "===" RelationalExpression { $$ = new(driver.pool_) CYIdentical($1, $3); }
| EqualityExpression "!==" RelationalExpression { $$ = new(driver.pool_) CYNotIdentical($1, $3); }
;
+@end
/* }}} */
/* 11.10 Binary Bitwise Operators {{{ */
BitwiseANDExpression
| BitwiseANDExpressionNoBF "&" EqualityExpression { $$ = new(driver.pool_) CYBitwiseAnd($1, $3); }
;
+@begin ObjectiveC
BitwiseANDExpressionNoWC
: EqualityExpressionNoWC { $$ = $1; }
| BitwiseANDExpression "&" EqualityExpression { $$ = new(driver.pool_) CYBitwiseAnd($1, $3); }
;
+@end
BitwiseXORExpression
: BitwiseANDExpression { $$ = $1; }
| BitwiseXORExpressionNoBF "^" BitwiseANDExpression { $$ = new(driver.pool_) CYBitwiseXOr($1, $3); }
;
+@begin ObjectiveC
BitwiseXORExpressionNoWC
: BitwiseANDExpressionNoWC { $$ = $1; }
| BitwiseXORExpression "^" BitwiseANDExpression { $$ = new(driver.pool_) CYBitwiseXOr($1, $3); }
;
+@end
BitwiseORExpression
: BitwiseXORExpression { $$ = $1; }
| BitwiseORExpressionNoBF "|" BitwiseXORExpression { $$ = new(driver.pool_) CYBitwiseOr($1, $3); }
;
+@begin ObjectiveC
BitwiseORExpressionNoWC
: BitwiseXORExpressionNoWC { $$ = $1; }
| BitwiseORExpression "|" BitwiseXORExpression { $$ = new(driver.pool_) CYBitwiseOr($1, $3); }
;
+@end
/* }}} */
/* 11.11 Binary Logical Operators {{{ */
LogicalANDExpression
| LogicalANDExpressionNoBF "&&" BitwiseORExpression { $$ = new(driver.pool_) CYLogicalAnd($1, $3); }
;
+@begin ObjectiveC
LogicalANDExpressionNoWC
: BitwiseORExpressionNoWC { $$ = $1; }
| LogicalANDExpression "&&" BitwiseORExpression { $$ = new(driver.pool_) CYLogicalAnd($1, $3); }
;
+@end
LogicalORExpression
: LogicalANDExpression { $$ = $1; }
| LogicalORExpressionNoBF "||" LogicalANDExpression { $$ = new(driver.pool_) CYLogicalOr($1, $3); }
;
+@begin ObjectiveC
LogicalORExpressionNoWC
: LogicalANDExpressionNoWC { $$ = $1; }
| LogicalORExpression "||" LogicalANDExpression { $$ = new(driver.pool_) CYLogicalOr($1, $3); }
;
+@end
/* }}} */
/* 11.12 Conditional Operator ( ? : ) {{{ */
ConditionalExpression
| LogicalORExpressionNoBF "?" AssignmentExpression ":" AssignmentExpression { $$ = new(driver.pool_) CYCondition($1, $3, $5); }
;
+@begin ObjectiveC
ConditionalExpressionNoWC
: LogicalORExpressionNoWC { $$ = $1; }
| LogicalORExpression "?" AssignmentExpression ":" AssignmentExpression { $$ = new(driver.pool_) CYCondition($1, $3, $5); }
;
+@end
/* }}} */
/* 11.13 Assignment Operators {{{ */
AssignmentExpression_
| UnaryAssigneeExpression { $$ = $1; }
;
+@begin ObjectiveC
AssigneeExpressionNoWC
: LeftHandSideExpressionNoWC { $$ = $1; }
| LexSetRegExp UnaryAssigneeExpression { $$ = $2; }
;
+@end
AssignmentExpression
: ConditionalExpression { $$ = $1; }
| AssigneeExpressionNoBF AssignmentExpression_ { $2->SetLeft($1); $$ = $2; }
;
+@begin ObjectiveC
AssignmentExpressionNoWC
: ConditionalExpressionNoWC { $$ = $1; }
| AssigneeExpression AssignmentExpression_ { $2->SetLeft($1); $$ = $2; }
;
+@end
/* }}} */
/* 11.14 Comma Operator {{{ */
Expression_
+#ifdef __APPLE__
#include <substrate.h>
+#endif
#include "ObjectiveC/Internal.hpp"
#ifdef __APPLE__
static Class NSCFBoolean_;
static Class NSCFType_;
+static Class NSMessageBuilder_;
+static Class NSZombie_;
#endif
static Class NSArray_;
static Class NSDictionary_;
-static Class NSMessageBuilder_;
-static Class NSZombie_;
static Class Object_;
static Type_privateData *Object_type;
string = [value cy$toCYON];
else goto fail;
} else fail: {
- if (value == NSZombie_)
+ if (false);
+#ifdef __APPLE__
+ else if (value == NSZombie_)
string = @"_NSZombie_";
else if (_class == NSZombie_)
string = [NSString stringWithFormat:@"<_NSZombie_: %p>", value];
// XXX: frowny /in/ the pants
else if (value == NSMessageBuilder_ || value == Object_)
string = nil;
+#endif
else
string = [NSString stringWithFormat:@"%@", value];
}
}
} CYObjectiveCatch }
-static CYHooks CYObjectiveCHooks = {
- &CYObjectiveC_ExecuteStart,
- &CYObjectiveC_ExecuteEnd,
- &CYObjectiveC_RuntimeProperty,
- &CYObjectiveC_CallFunction,
- &CYObjectiveC_PoolFFI,
- &CYObjectiveC_FromFFI,
-};
-
static bool CYImplements(id object, Class _class, SEL selector, bool devoid) {
if (objc_method *method = class_getInstanceMethod(_class, selector)) {
if (!devoid)
return true;
+#ifdef __OBJC2__
char type[16];
method_getReturnType(method, type, sizeof(type));
+#else
+ const char *type(method_getTypeEncoding(method));
+#endif
if (type[0] != 'v')
return true;
}
if (method != NULL)
method_setImplementation(method, imp);
- else
- class_replaceMethod(_class, sel, imp, type);
+ else {
+#ifdef GNU_RUNTIME
+ GSMethodList list(GSAllocMethodList(1));
+ GSAppendMethodToList(list, sel, type, imp, YES);
+ GSAddMethodList(_class, list, YES);
+ GSFlushMethodCacheForClass(_class);
+#else
+ class_addMethod(_class, sel, imp, type);
+#endif
+ }
return true;
}
if (Class super = class_getSuperclass(_class))
Internal_getPropertyNames_(super, names);
+#ifdef __OBJC2__
unsigned int size;
objc_ivar **data(class_copyIvarList(_class, &size));
for (size_t i(0); i != size; ++i)
JSPropertyNameAccumulatorAddName(names, CYJSString(ivar_getName(data[i])));
free(data);
+#else
+ if (objc_ivar_list *ivars = _class->ivars)
+ for (int i(0); i != ivars->ivar_count; ++i)
+ JSPropertyNameAccumulatorAddName(names, CYJSString(ivar_getName(&ivars->ivar_list[i])));
+#endif
}
static void Internal_getPropertyNames(JSContextRef context, JSObjectRef object, JSPropertyNameAccumulatorRef names) {
} CYCatch }
/* Hook: objc_registerClassPair {{{ */
+#ifdef __OBJC2__
// XXX: replace this with associated objects
MSHook(void, CYDealloc, id self, SEL sel) {
$objc_registerClassPair(_class);
return CYJSUndefined(context);
} CYCatch }
+#endif
/* }}} */
static JSValueRef Selector_callAsFunction(JSContextRef context, JSObjectRef object, JSObjectRef _this, size_t count, const JSValueRef arguments[], JSValueRef *exception) {
static JSValueRef Instance_getProperty_messages(JSContextRef context, JSObjectRef object, JSStringRef property, JSValueRef *exception) {
Instance *internal(reinterpret_cast<Instance *>(JSObjectGetPrivate(object)));
id self(internal->GetValue());
- if (class_getInstanceMethod(object_getClass(self), @selector(alloc)) == NULL)
+ if (!CYIsClass(self))
return CYJSUndefined(context);
- return Messages::Make(context, self);
+ return Messages::Make(context, (Class) self);
}
static JSValueRef Instance_callAsFunction_toCYON(JSContextRef context, JSObjectRef object, JSObjectRef _this, size_t count, const JSValueRef arguments[], JSValueRef *exception) { CYTry {
Instance *internal(reinterpret_cast<Instance *>(JSObjectGetPrivate(_this)));
CYPoolTry {
- NSString *key(count == 0 ? nil : CYCastNSString(NULL, context, CYJSString(context, arguments[0])));
+ NSString *key;
+ if (count == 0)
+ key = nil;
+ else
+ key = CYCastNSString(NULL, context, CYJSString(context, arguments[0]));
// XXX: check for support of cy$toJSON?
return CYCastJSValue(context, CYJSString([internal->GetValue() cy$toJSON:key]));
} CYPoolCatch(NULL)
{NULL, NULL, 0}
};
-void CYObjectiveC(JSContextRef context, JSObjectRef global) {
+void CYObjectiveC_SetupContext(JSContextRef context) {
+ JSObjectRef global(CYGetGlobalObject(context));
apr_pool_t *pool(CYGetGlobalPool());
- hooks_ = &CYObjectiveCHooks;
-
Object_type = new(pool) Type_privateData(pool, "@");
Selector_type = new(pool) Type_privateData(pool, ":");
#ifdef __APPLE__
NSCFBoolean_ = objc_getClass("NSCFBoolean");
NSCFType_ = objc_getClass("NSCFType");
+ NSMessageBuilder_ = objc_getClass("NSMessageBuilder");
+ NSZombie_ = objc_getClass("_NSZombie_");
#endif
NSArray_ = objc_getClass("NSArray");
- NSDictionary_ = objc_getClass("NSDictonary");
- NSMessageBuilder_ = objc_getClass("NSMessageBuilder");
- NSZombie_ = objc_getClass("_NSZombie_");
+ NSDictionary_ = objc_getClass("NSDictionary");
Object_ = objc_getClass("Object");
JSClassDefinition definition;
CYSetProperty(context, global, CYJSString("Selector"), Selector);
CYSetProperty(context, global, CYJSString("Super"), Super);
+#ifdef __OBJC2__
CYSetProperty(context, global, CYJSString("objc_registerClassPair"), JSObjectMakeFunctionWithCallback(context, CYJSString("objc_registerClassPair"), &objc_registerClassPair_));
+ MSHookFunction(&objc_registerClassPair, MSHake(objc_registerClassPair));
+#endif
+
CYSetProperty(context, global, CYJSString("objc_msgSend"), JSObjectMakeFunctionWithCallback(context, CYJSString("objc_msgSend"), &$objc_msgSend));
JSObjectSetPrototype(context, (JSObjectRef) CYGetProperty(context, Message, prototype_), Function_prototype_);
JSObjectSetPrototype(context, (JSObjectRef) CYGetProperty(context, Selector, prototype_), Function_prototype_);
- MSHookFunction(&objc_registerClassPair, MSHake(objc_registerClassPair));
-
#ifdef __APPLE__
class_addMethod(NSCFType_, @selector(cy$toJSON:), reinterpret_cast<IMP>(&NSCFType$cy$toJSON), "@12@0:4@8");
#endif
}
+
+static CYHooks CYObjectiveCHooks = {
+ &CYObjectiveC_ExecuteStart,
+ &CYObjectiveC_ExecuteEnd,
+ &CYObjectiveC_RuntimeProperty,
+ &CYObjectiveC_CallFunction,
+ &CYObjectiveC_SetupContext,
+ &CYObjectiveC_PoolFFI,
+ &CYObjectiveC_FromFFI,
+};
+
+struct CYObjectiveC {
+ CYObjectiveC() {
+ hooks_ = &CYObjectiveCHooks;
+ }
+} CYObjectiveC;