]> git.saurik.com Git - cycript.git/commitdiff
Finished porting to GNUstep, although it doesn't actually work (but it /did/ find...
authorJay Freeman (saurik) <saurik@saurik.com>
Sat, 31 Oct 2009 03:39:23 +0000 (03:39 +0000)
committerJay Freeman (saurik) <saurik@saurik.com>
Sat, 31 Oct 2009 03:39:23 +0000 (03:39 +0000)
Cycript.y.in
Library.cpp
Linux.mk
ObjectiveC/Library.mm
control [deleted file]
control.in [new file with mode: 0644]
cycript.hpp
makefile

index 9055cb57bce93b38d239d6d7ba50fe6d3ed07d11..dde7908ede31790ad216c8a0e0816258bd62d289 100644 (file)
@@ -307,6 +307,27 @@ int cylex(YYSTYPE *lvalp, cy::location *llocp, void *scanner);
 %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
@@ -314,7 +335,6 @@ int cylex(YYSTYPE *lvalp, cy::location *llocp, void *scanner);
 
 %type <expression_> AdditiveExpression
 %type <expression_> AdditiveExpressionNoBF
-%type <expression_> AdditiveExpressionNoWC
 %type <argument_> ArgumentList
 %type <argument_> ArgumentList_
 %type <argument_> ArgumentListOpt
@@ -323,27 +343,22 @@ int cylex(YYSTYPE *lvalp, cy::location *llocp, void *scanner);
 %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
@@ -357,7 +372,6 @@ int cylex(YYSTYPE *lvalp, cy::location *llocp, void *scanner);
 %type <expression_> ConditionalExpression
 %type <expression_> ConditionalExpressionNoBF
 %type <expression_> ConditionalExpressionNoIn
-%type <expression_> ConditionalExpressionNoWC
 %type <statement_> ContinueStatement
 %type <clause_> DefaultClause
 %type <statement_> DoWhileStatement
@@ -370,7 +384,6 @@ int cylex(YYSTYPE *lvalp, cy::location *llocp, void *scanner);
 %type <expression_> EqualityExpression
 %type <expression_> EqualityExpressionNoBF
 %type <expression_> EqualityExpressionNoIn
-%type <expression_> EqualityExpressionNoWC
 %type <expression_> Expression
 %type <expression_> ExpressionOpt
 %type <compound_> Expression_
@@ -403,7 +416,6 @@ int cylex(YYSTYPE *lvalp, cy::location *llocp, void *scanner);
 %type <expression_> LeftHandSideExpression
 %type <expression_> LeftHandSideExpressionNoBF
 %type <expression_> LeftHandSideExpressionNoRE
-%type <expression_> LeftHandSideExpressionNoWC
 //%type <statement_> LetStatement
 %type <literal_> Literal
 %type <literal_> LiteralNoRE
@@ -411,31 +423,25 @@ int cylex(YYSTYPE *lvalp, cy::location *llocp, void *scanner);
 %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
@@ -456,12 +462,10 @@ int cylex(YYSTYPE *lvalp, cy::location *llocp, void *scanner);
 %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
@@ -477,7 +481,6 @@ int cylex(YYSTYPE *lvalp, cy::location *llocp, void *scanner);
 %type <expression_> UnaryExpression_
 %type <expression_> UnaryExpressionNoBF
 %type <expression_> UnaryExpressionNoRE
-%type <expression_> UnaryExpressionNoWC
 %type <declaration_> VariableDeclaration
 %type <declaration_> VariableDeclarationNoIn
 %type <declarations_> 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_
index dbb86f243b860b25882a8ed3cc81ff5f41f92129..cccd69bb6e7f6ded3b714aa8bccdb69f8cd09130 100644 (file)
@@ -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_;
index 93e2e94afe6025c380fabd485426e40038700f90..8d23656819128c9d510a14fb1466d2ecd64c1dc5 100644 (file)
--- 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
index 787a81fef1e844cb710f70c8b13bf707328bd6a7..1e6f9b4c8e4c0e15bc4fdbdfb61383bc31689e67 100644 (file)
@@ -1,4 +1,6 @@
+#ifdef __APPLE__
 #include <substrate.h>
+#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<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 {
@@ -2084,7 +2100,11 @@ static JSValueRef Instance_callAsFunction_toJSON(JSContextRef context, JSObjectR
     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)
@@ -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<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;
diff --git a/control b/control
deleted file mode 100644 (file)
index fbea69e..0000000
--- a/control
+++ /dev/null
@@ -1,12 +0,0 @@
-Package: cycript
-Priority: optional
-Section: Development
-Maintainer: Jay Freeman (saurik) <saurik@saurik.com>
-Architecture: %
-Version: 0.9.#-1
-Description: runtime execution server and disassembler
-Name: Cycript
-Depends: &
-Author: Jay Freeman (saurik) <saurik@saurik.com>
-Depiction: http://cydia.saurik.com/info/cycript/
-Tag: purpose::daemon, role::developer
diff --git a/control.in b/control.in
new file mode 100644 (file)
index 0000000..fbea69e
--- /dev/null
@@ -0,0 +1,12 @@
+Package: cycript
+Priority: optional
+Section: Development
+Maintainer: Jay Freeman (saurik) <saurik@saurik.com>
+Architecture: %
+Version: 0.9.#-1
+Description: runtime execution server and disassembler
+Name: Cycript
+Depends: &
+Author: Jay Freeman (saurik) <saurik@saurik.com>
+Depiction: http://cydia.saurik.com/info/cycript/
+Tag: purpose::daemon, role::developer
index 20c6b8e8baf5fc826455ce7409bc2d6d46784681..3e38a0f8f6ad8c6a90a5a09dbfdd63372ac6f90f 100644 (file)
@@ -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);
index b7895326d1978bd1f14907f94de46a3243ff7cf9..3fe6d9e89f24406bea8d84f916c3e8945554918b 100644 (file)
--- 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