From b5dd57dc1e068c730142fb1007ce6c43a6ef7090 Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Sat, 31 Oct 2009 03:39:23 +0000 Subject: [PATCH] Finished porting to GNUstep, although it doesn't actually work (but it /did/ find a bug in NeXT support...). --- Cycript.y.in | 75 ++++++++++++++++++++++++++++--------- Library.cpp | 8 +--- Linux.mk | 1 - ObjectiveC/Library.mm | 87 ++++++++++++++++++++++++++++++------------- control => control.in | 0 cycript.hpp | 1 + makefile | 15 ++++++-- 7 files changed, 133 insertions(+), 54 deletions(-) rename control => control.in (100%) diff --git a/Cycript.y.in b/Cycript.y.in index 9055cb5..dde7908 100644 --- a/Cycript.y.in +++ b/Cycript.y.in @@ -307,6 +307,27 @@ int cylex(YYSTYPE *lvalp, cy::location *llocp, void *scanner); %token XML "xml" @end +@begin ObjectiveC +%type AdditiveExpressionNoWC +%type AssigneeExpressionNoWC +%type AssignmentExpressionNoWC +%type BitwiseANDExpressionNoWC +%type BitwiseXORExpressionNoWC +%type BitwiseORExpressionNoWC +%type ConditionalExpressionNoWC +%type EqualityExpressionNoWC +%type LeftHandSideExpressionNoWC +%type LogicalANDExpressionNoWC +%type LogicalORExpressionNoWC +%type MemberExpressionNoWC +%type MultiplicativeExpressionNoWC +%type NewExpressionNoWC +%type PostfixExpressionNoWC +%type RelationalExpressionNoWC +%type ShiftExpressionNoWC +%type UnaryExpressionNoWC +@end + %token Identifier_ %token NumericLiteral %token StringLiteral @@ -314,7 +335,6 @@ int cylex(YYSTYPE *lvalp, cy::location *llocp, void *scanner); %type AdditiveExpression %type AdditiveExpressionNoBF -%type AdditiveExpressionNoWC %type ArgumentList %type ArgumentList_ %type ArgumentListOpt @@ -323,27 +343,22 @@ int cylex(YYSTYPE *lvalp, cy::location *llocp, void *scanner); %type AssigneeExpression %type AssigneeExpressionNoBF %type AssigneeExpressionNoRE -%type AssigneeExpressionNoWC %type AssignmentExpression %type AssignmentExpression_ %type AssignmentExpressionNoBF %type AssignmentExpressionNoIn -%type AssignmentExpressionNoWC %type BitwiseANDExpression %type BitwiseANDExpressionNoBF %type BitwiseANDExpressionNoIn -%type BitwiseANDExpressionNoWC %type Block %type Block_ %type BooleanLiteral %type BitwiseORExpression %type BitwiseORExpressionNoBF %type BitwiseORExpressionNoIn -%type BitwiseORExpressionNoWC %type BitwiseXORExpression %type BitwiseXORExpressionNoBF %type BitwiseXORExpressionNoIn -%type BitwiseXORExpressionNoWC %type BreakStatement %type CallExpression %type CallExpressionNoBF @@ -357,7 +372,6 @@ int cylex(YYSTYPE *lvalp, cy::location *llocp, void *scanner); %type ConditionalExpression %type ConditionalExpressionNoBF %type ConditionalExpressionNoIn -%type ConditionalExpressionNoWC %type ContinueStatement %type DefaultClause %type DoWhileStatement @@ -370,7 +384,6 @@ int cylex(YYSTYPE *lvalp, cy::location *llocp, void *scanner); %type EqualityExpression %type EqualityExpressionNoBF %type EqualityExpressionNoIn -%type EqualityExpressionNoWC %type Expression %type ExpressionOpt %type Expression_ @@ -403,7 +416,6 @@ int cylex(YYSTYPE *lvalp, cy::location *llocp, void *scanner); %type LeftHandSideExpression %type LeftHandSideExpressionNoBF %type LeftHandSideExpressionNoRE -%type LeftHandSideExpressionNoWC //%type LetStatement %type Literal %type LiteralNoRE @@ -411,31 +423,25 @@ int cylex(YYSTYPE *lvalp, cy::location *llocp, void *scanner); %type LogicalANDExpression %type LogicalANDExpressionNoBF %type LogicalANDExpressionNoIn -%type LogicalANDExpressionNoWC %type LogicalORExpression %type LogicalORExpressionNoBF %type LogicalORExpressionNoIn -%type LogicalORExpressionNoWC %type MemberAccess %type MemberExpression %type MemberExpression_ %type MemberExpressionNoBF %type MemberExpressionNoRE -%type MemberExpressionNoWC %type MultiplicativeExpression %type MultiplicativeExpressionNoBF -%type MultiplicativeExpressionNoWC %type NewExpression %type NewExpression_ %type NewExpressionNoBF %type NewExpressionNoRE -%type NewExpressionNoWC %type NullLiteral %type ObjectLiteral %type PostfixExpression %type PostfixExpressionNoBF %type PostfixExpressionNoRE -%type PostfixExpressionNoWC %type PrimaryExpression %type PrimaryExpressionNo %type PrimaryExpressionNoBF @@ -456,12 +462,10 @@ int cylex(YYSTYPE *lvalp, cy::location *llocp, void *scanner); %type RelationalExpression_ %type RelationalExpressionNoBF %type RelationalExpressionNoIn -%type RelationalExpressionNoWC %type RelationalExpressionNoIn_ %type ReturnStatement %type ShiftExpression %type ShiftExpressionNoBF -%type ShiftExpressionNoWC %type SourceElement %type SourceElement_ %type SourceElements @@ -477,7 +481,6 @@ int cylex(YYSTYPE *lvalp, cy::location *llocp, void *scanner); %type UnaryExpression_ %type UnaryExpressionNoBF %type UnaryExpressionNoRE -%type UnaryExpressionNoWC %type VariableDeclaration %type VariableDeclarationNoIn %type VariableDeclarationList @@ -838,12 +841,14 @@ MemberExpressionNoRE | 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); } @@ -864,10 +869,12 @@ NewExpressionNoRE | NewExpression_ { $$ = $1; } ; +@begin ObjectiveC NewExpressionNoWC : MemberExpressionNoWC { $$ = $1; } | LexSetRegExp NewExpression_ { $$ = $2; } ; +@end CallExpression : PrimaryExpressionNoWC Arguments { $$ = new(driver.pool_) CYCall($1, $2); } @@ -920,10 +927,12 @@ LeftHandSideExpressionNoRE | CallExpressionNoRE { $$ = $1; } ; +@begin ObjectiveC LeftHandSideExpressionNoWC : NewExpressionNoWC { $$ = $1; } | CallExpression { $$ = $1; } ; +@end /* }}} */ /* 11.3 Postfix Expressions {{{ */ PostfixExpression @@ -944,11 +953,13 @@ PostfixExpressionNoRE | 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_ @@ -980,10 +991,12 @@ UnaryExpressionNoRE | UnaryExpression_ { $$ = $1; } ; +@begin ObjectiveC UnaryExpressionNoWC : PostfixExpressionNoWC { $$ = $1; } | LexSetRegExp UnaryExpression_ { $$ = $2; } ; +@end /* }}} */ /* 11.5 Multiplicative Operators {{{ */ MultiplicativeExpression @@ -1000,12 +1013,14 @@ MultiplicativeExpressionNoBF | 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 @@ -1020,11 +1035,13 @@ AdditiveExpressionNoBF | 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 @@ -1041,12 +1058,14 @@ ShiftExpressionNoBF | 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_ @@ -1077,10 +1096,12 @@ RelationalExpressionNoBF | RelationalExpressionNoBF RelationalExpression_ { $2->SetLeft($1); $$ = $2; } ; +@begin ObjectiveC RelationalExpressionNoWC : ShiftExpressionNoWC { $$ = $1; } | RelationalExpression RelationalExpression_ { $2->SetLeft($1); $$ = $2; } ; +@end /* }}} */ /* 11.9 Equality Operators {{{ */ EqualityExpression @@ -1107,6 +1128,7 @@ EqualityExpressionNoBF | EqualityExpressionNoBF "!==" RelationalExpression { $$ = new(driver.pool_) CYNotIdentical($1, $3); } ; +@begin ObjectiveC EqualityExpressionNoWC : RelationalExpressionNoWC { $$ = $1; } | EqualityExpression "==" RelationalExpression { $$ = new(driver.pool_) CYEqual($1, $3); } @@ -1114,6 +1136,7 @@ EqualityExpressionNoWC | EqualityExpression "===" RelationalExpression { $$ = new(driver.pool_) CYIdentical($1, $3); } | EqualityExpression "!==" RelationalExpression { $$ = new(driver.pool_) CYNotIdentical($1, $3); } ; +@end /* }}} */ /* 11.10 Binary Bitwise Operators {{{ */ BitwiseANDExpression @@ -1131,10 +1154,12 @@ BitwiseANDExpressionNoBF | 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; } @@ -1151,10 +1176,12 @@ BitwiseXORExpressionNoBF | 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; } @@ -1171,10 +1198,12 @@ BitwiseORExpressionNoBF | 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 @@ -1192,10 +1221,12 @@ LogicalANDExpressionNoBF | 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; } @@ -1212,10 +1243,12 @@ LogicalORExpressionNoBF | 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 @@ -1233,10 +1266,12 @@ ConditionalExpressionNoBF | 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_ @@ -1269,10 +1304,12 @@ AssigneeExpressionNoRE | UnaryAssigneeExpression { $$ = $1; } ; +@begin ObjectiveC AssigneeExpressionNoWC : LeftHandSideExpressionNoWC { $$ = $1; } | LexSetRegExp UnaryAssigneeExpression { $$ = $2; } ; +@end AssignmentExpression : ConditionalExpression { $$ = $1; } @@ -1300,10 +1337,12 @@ AssignmentExpressionNoBF | AssigneeExpressionNoBF AssignmentExpression_ { $2->SetLeft($1); $$ = $2; } ; +@begin ObjectiveC AssignmentExpressionNoWC : ConditionalExpressionNoWC { $$ = $1; } | AssigneeExpression AssignmentExpression_ { $2->SetLeft($1); $$ = $2; } ; +@end /* }}} */ /* 11.14 Comma Operator {{{ */ Expression_ diff --git a/Library.cpp b/Library.cpp index dbb86f2..cccd69b 100644 --- a/Library.cpp +++ b/Library.cpp @@ -1449,8 +1449,6 @@ CYJSError::CYJSError(JSContextRef context, const char *format, ...) { CYThrow(context, exception); } -void CYObjectiveC(JSContextRef context, JSObjectRef global); - JSGlobalContextRef CYGetJSContext() { CYInitialize(); @@ -1569,10 +1567,8 @@ JSGlobalContextRef CYGetJSContext() { Result_ = JSStringCreateWithUTF8CString("_"); -// XXX: this is very wrong and sad -#ifdef __APPLE__ - CYObjectiveC(context, global); -#endif + if (hooks_ != NULL && hooks_->SetupContext != NULL) + (*hooks_->SetupContext)(context); } return Context_; diff --git a/Linux.mk b/Linux.mk index 93e2e94..8d23656 100644 --- a/Linux.mk +++ b/Linux.mk @@ -1,5 +1,4 @@ export PATH := /usr/local/bin:$(PATH) flags += -I/usr/include/webkit-1.0 flags += -DCY_EXECUTE -depends += libffi4 libreadline5 library += -lwebkit-1.0 diff --git a/ObjectiveC/Library.mm b/ObjectiveC/Library.mm index 787a81f..1e6f9b4 100644 --- a/ObjectiveC/Library.mm +++ b/ObjectiveC/Library.mm @@ -1,4 +1,6 @@ +#ifdef __APPLE__ #include +#endif #include "ObjectiveC/Internal.hpp" @@ -220,12 +222,12 @@ static JSObjectRef Instance_prototype_; #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; @@ -370,13 +372,16 @@ NSString *CYCastNSCYON(id value) { 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]; } @@ -1291,21 +1296,16 @@ static JSValueRef CYObjectiveC_FromFFI(JSContextRef context, sig::Type *type, ff } } 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; } @@ -1433,8 +1433,16 @@ static bool Messages_setProperty(JSContextRef context, JSObjectRef object, JSStr 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; } @@ -1711,11 +1719,17 @@ static void Internal_getPropertyNames_(Class _class, JSPropertyNameAccumulatorRe 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) { @@ -1946,6 +1960,7 @@ static JSValueRef $objc_msgSend(JSContextRef context, JSObjectRef object, JSObje } CYCatch } /* Hook: objc_registerClassPair {{{ */ +#ifdef __OBJC2__ // XXX: replace this with associated objects MSHook(void, CYDealloc, id self, SEL sel) { @@ -1977,6 +1992,7 @@ static JSValueRef objc_registerClassPair_(JSContextRef context, JSObjectRef obje $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) { @@ -2064,9 +2080,9 @@ static JSValueRef Instance_getProperty_protocol(JSContextRef context, JSObjectRe static JSValueRef Instance_getProperty_messages(JSContextRef context, JSObjectRef object, JSStringRef property, JSValueRef *exception) { Instance *internal(reinterpret_cast(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 { @@ -2084,7 +2100,11 @@ static JSValueRef Instance_callAsFunction_toJSON(JSContextRef context, JSObjectR Instance *internal(reinterpret_cast(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) @@ -2174,23 +2194,22 @@ static JSStaticFunction Selector_staticFunctions[5] = { {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; @@ -2298,15 +2317,33 @@ void CYObjectiveC(JSContextRef context, JSObjectRef global) { 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(&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; diff --git a/control b/control.in similarity index 100% rename from control rename to control.in diff --git a/cycript.hpp b/cycript.hpp index 20c6b8e..3e38a0f 100644 --- a/cycript.hpp +++ b/cycript.hpp @@ -126,6 +126,7 @@ struct CYHooks { JSValueRef (*RuntimeProperty)(JSContextRef, CYUTF8String); void (*CallFunction)(JSContextRef, ffi_cif *, void (*)(), uint8_t *, void **); + void (*SetupContext)(JSContextRef); bool (*PoolFFI)(apr_pool_t *, JSContextRef, sig::Type *, ffi_type *, void *, JSValueRef); JSValueRef (*FromFFI)(JSContextRef, sig::Type *, ffi_type *, void *, bool, JSObjectRef); diff --git a/makefile b/makefile index b789532..3fe6d9e 100644 --- a/makefile +++ b/makefile @@ -57,16 +57,23 @@ flags += -I. -I$(shell apr-1-config --includedir) all += libcycript.$(dll) ifdef arch -deb := $(shell grep ^Package: control | cut -d ' ' -f 2-)_$(shell grep ^Version: control | cut -d ' ' -f 2 | sed -e 's/\#/$(svn)/')_$(arch).deb +deb := $(shell grep ^Package: control.in | cut -d ' ' -f 2-)_$(shell grep ^Version: control.in | cut -d ' ' -f 2 | sed -e 's/\#/$(svn)/')_$(arch).deb all: $(deb) extra: -$(deb): $(all) +control: control.in cycript libcycript.so +ifeq ($(depends),) + sed -e 's/&/'"$$(dpkg-query -S $$(ldd cycript libcycript.so | sed -e '/:$$/ d; s/^[ \t]*\([^ ]* => \)\?\([^ ]*\) .*/\2/' | sort -u) 2>/dev/null | sed -e 's/:.*//; /^cycript$$/ d; s/$$/,/' | sort -u | tr '\n' ' ')"'/;s/, $$//;s/#/$(svn)/;s/%/$(arch)/' $< >$@ +else + sed -e 's/&/$(foreach depend,$(depends),$(depend),)/;s/,$$//;s/#/$(svn)/;s/%/$(arch)/' $< >$@ +endif + +$(deb): $(all) control rm -rf package mkdir -p package/DEBIAN - sed -e 's/&/$(foreach depend,$(depends),$(depend),)/;s/,$$//;s/#/$(svn)/;s/%/$(arch)/' control >package/DEBIAN/control + cp -a control package/DEBIAN $(restart) extra mkdir -p package/usr/{bin,lib,sbin} cp -a libcycript.$(dll) package/usr/lib @@ -79,7 +86,7 @@ endif all: $(all) clean: - rm -f *.o libcycript.$(dll) cycript libcycript.db Struct.hpp lex.cy.c Cycript.tab.cc Cycript.tab.hh location.hh position.hh stack.hh cyrver Cycript.y Cycript.l + rm -f *.o libcycript.$(dll) cycript libcycript.db Struct.hpp lex.cy.c Cycript.tab.cc Cycript.tab.hh location.hh position.hh stack.hh cyrver Cycript.y Cycript.l control libcycript.db: Bridge.def rm -f libcycript.db -- 2.45.2