From 9b5527f0b979deba030328eb11c355b5785aceb5 Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Fri, 16 Oct 2009 15:48:31 +0000 Subject: [PATCH] Implemented ->, &, and fleshed out *. --- Cycript.y | 75 ++++++++++++-------- Library.mm | 200 +++++++++++++++++++++++++++++++++++++++++++---------- Output.cpp | 40 +++++++---- Parser.hpp | 26 +++++++ makefile | 10 +-- 5 files changed, 268 insertions(+), 83 deletions(-) diff --git a/Cycript.y b/Cycript.y index d39bbeb..7b1399d 100644 --- a/Cycript.y +++ b/Cycript.y @@ -71,6 +71,7 @@ typedef struct { CYIdentifier *identifier_; CYInfix *infix_; CYLiteral *literal_; + CYMember *member_; CYMessage *message_; CYMessageParameter *messageParameter_; CYNull *null_; @@ -243,6 +244,9 @@ int cylex(YYSTYPE *lvalp, cy::location *llocp, void *scanner); %type ArgumentListOpt %type Arguments %type ArrayLiteral +%type AssigneeExpression +%type AssigneeExpression_ +%type AssigneeExpressionNoBF %type AssignmentExpression %type AssignmentExpression_ %type AssignmentExpressionNoBF @@ -313,7 +317,6 @@ int cylex(YYSTYPE *lvalp, cy::location *llocp, void *scanner); %type IterationStatement %type LabelledStatement %type LeftHandSideExpression -%type LeftHandSideExpression_ %type LeftHandSideExpressionNoBF %type Literal %type LogicalANDExpression @@ -322,6 +325,7 @@ int cylex(YYSTYPE *lvalp, cy::location *llocp, void *scanner); %type LogicalORExpression %type LogicalORExpressionNoBF %type LogicalORExpressionNoIn +%type MemberAccess %type MemberExpression %type MemberExpression_ %type MemberExpressionNoBF @@ -591,18 +595,21 @@ MemberExpression_ : "new" MemberExpression Arguments { $$ = new(driver.pool_) CYNew($2, $3); } ; +MemberAccess + : "[" Expression "]" { $$ = new(driver.pool_) CYDirectMember(NULL, $2); } + | "." Identifier { $$ = new(driver.pool_) CYDirectMember(NULL, new(driver.pool_) CYString($2)); } + ; + MemberExpression : PrimaryExpression { $$ = $1; } | FunctionExpression { $$ = $1; } - | MemberExpression "[" Expression "]" { $$ = new(driver.pool_) CYMember($1, $3); } - | MemberExpression "." Identifier { $$ = new(driver.pool_) CYMember($1, new(driver.pool_) CYString($3)); } + | MemberExpression MemberAccess { $2->SetLeft($1); $$ = $2; } | MemberExpression_ { $$ = $1; } ; MemberExpressionNoBF : PrimaryExpressionNoBF { $$ = $1; } - | MemberExpressionNoBF "[" Expression "]" { $$ = new(driver.pool_) CYMember($1, $3); } - | MemberExpressionNoBF "." Identifier { $$ = new(driver.pool_) CYMember($1, new(driver.pool_) CYString($3)); } + | MemberExpressionNoBF MemberAccess { $2->SetLeft($1); $$ = $2; } | MemberExpression_ { $$ = $1; } ; @@ -623,15 +630,13 @@ NewExpressionNoBF CallExpression : MemberExpression Arguments { $$ = new(driver.pool_) CYCall($1, $2); } | CallExpression Arguments { $$ = new(driver.pool_) CYCall($1, $2); } - | CallExpression "[" Expression "]" { $$ = new(driver.pool_) CYMember($1, $3); } - | CallExpression "." Identifier { $$ = new(driver.pool_) CYMember($1, new(driver.pool_) CYString($3)); } + | CallExpression MemberAccess { $2->SetLeft($1); $$ = $2; } ; CallExpressionNoBF : MemberExpressionNoBF Arguments { $$ = new(driver.pool_) CYCall($1, $2); } | CallExpressionNoBF Arguments { $$ = new(driver.pool_) CYCall($1, $2); } - | CallExpressionNoBF "[" Expression "]" { $$ = new(driver.pool_) CYMember($1, $3); } - | CallExpressionNoBF "." Identifier { $$ = new(driver.pool_) CYMember($1, new(driver.pool_) CYString($3)); } + | CallExpressionNoBF MemberAccess { $2->SetLeft($1); $$ = $2; } ; ArgumentList_ @@ -655,23 +660,21 @@ Arguments LeftHandSideExpression : NewExpression { $$ = $1; } | CallExpression { $$ = $1; } - | LeftHandSideExpression_ { $$ = $1; } ; LeftHandSideExpressionNoBF : NewExpressionNoBF { $$ = $1; } | CallExpressionNoBF { $$ = $1; } - | LeftHandSideExpression_ { $$ = $1; } ; PostfixExpression - : LeftHandSideExpression { $$ = $1; } + : AssigneeExpression { $$ = $1; } | LeftHandSideExpression "++" { $$ = new(driver.pool_) CYPostIncrement($1); } | LeftHandSideExpression "--" { $$ = new(driver.pool_) CYPostDecrement($1); } ; PostfixExpressionNoBF - : LeftHandSideExpressionNoBF { $$ = $1; } + : AssigneeExpressionNoBF { $$ = $1; } | LeftHandSideExpressionNoBF "++" { $$ = new(driver.pool_) CYPostIncrement($1); } | LeftHandSideExpressionNoBF "--" { $$ = new(driver.pool_) CYPostDecrement($1); } ; @@ -897,30 +900,40 @@ AssignmentExpression_ | "|=" AssignmentExpression { $$ = new(driver.pool_) CYBitwiseOrAssign(NULL, $2); } ; +AssigneeExpression + : LeftHandSideExpression { $$ = $1; } + | AssigneeExpression_ { $$ = $1; } + ; + +AssigneeExpressionNoBF + : LeftHandSideExpressionNoBF { $$ = $1; } + | AssigneeExpression_ { $$ = $1; } + ; + AssignmentExpression : ConditionalExpression { $$ = $1; } - | LeftHandSideExpression AssignmentExpression_ { $2->SetLeft($1); $$ = $2; } + | AssigneeExpression AssignmentExpression_ { $2->SetLeft($1); $$ = $2; } ; AssignmentExpressionNoIn : ConditionalExpressionNoIn { $$ = $1; } - | LeftHandSideExpression "=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYAssign($1, $3); } - | LeftHandSideExpression "*=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYMultiplyAssign($1, $3); } - | LeftHandSideExpression "/=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYDivideAssign($1, $3); } - | LeftHandSideExpression "%=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYModulusAssign($1, $3); } - | LeftHandSideExpression "+=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYAddAssign($1, $3); } - | LeftHandSideExpression "-=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYSubtractAssign($1, $3); } - | LeftHandSideExpression "<<=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYShiftLeftAssign($1, $3); } - | LeftHandSideExpression ">>=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYShiftRightSignedAssign($1, $3); } - | LeftHandSideExpression ">>>=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYShiftRightUnsignedAssign($1, $3); } - | LeftHandSideExpression "&=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYBitwiseAndAssign($1, $3); } - | LeftHandSideExpression "^=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYBitwiseXOrAssign($1, $3); } - | LeftHandSideExpression "|=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYBitwiseOrAssign($1, $3); } + | AssigneeExpression "=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYAssign($1, $3); } + | AssigneeExpression "*=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYMultiplyAssign($1, $3); } + | AssigneeExpression "/=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYDivideAssign($1, $3); } + | AssigneeExpression "%=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYModulusAssign($1, $3); } + | AssigneeExpression "+=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYAddAssign($1, $3); } + | AssigneeExpression "-=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYSubtractAssign($1, $3); } + | AssigneeExpression "<<=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYShiftLeftAssign($1, $3); } + | AssigneeExpression ">>=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYShiftRightSignedAssign($1, $3); } + | AssigneeExpression ">>>=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYShiftRightUnsignedAssign($1, $3); } + | AssigneeExpression "&=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYBitwiseAndAssign($1, $3); } + | AssigneeExpression "^=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYBitwiseXOrAssign($1, $3); } + | AssigneeExpression "|=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYBitwiseOrAssign($1, $3); } ; AssignmentExpressionNoBF : ConditionalExpressionNoBF { $$ = $1; } - | LeftHandSideExpressionNoBF AssignmentExpression_ { $2->SetLeft($1); $$ = $2; } + | AssigneeExpressionNoBF AssignmentExpression_ { $2->SetLeft($1); $$ = $2; } ; Expression_ @@ -1283,12 +1296,16 @@ PrimaryExpression_ ; /* }}} */ -LeftHandSideExpression_ - : "*" LeftHandSideExpression { $$ = new(driver.pool_) CYIndirect($2); } +AssigneeExpression_ + : "*" UnaryExpression { $$ = new(driver.pool_) CYIndirect($2); } ; UnaryExpression_ : "&" UnaryExpression { $$ = new(driver.pool_) CYAddressOf($2); } ; +MemberAccess + : "->" Identifier { $$ = new(driver.pool_) CYIndirectMember(NULL, new(driver.pool_) CYString($2)); } + ; + %% diff --git a/Library.mm b/Library.mm index a2f5891..350c659 100644 --- a/Library.mm +++ b/Library.mm @@ -111,6 +111,7 @@ static JSObjectRef ObjectiveC_; static JSClassRef Functor_; static JSClassRef Instance_; +static JSClassRef Internal_; static JSClassRef Pointer_; static JSClassRef Runtime_; static JSClassRef Selector_; @@ -180,6 +181,11 @@ struct CYValue : value_(value) { } + + CYValue(const CYValue &rhs) : + value_(rhs.value_) + { + } }; struct Selector_privateData : @@ -231,6 +237,26 @@ struct Instance : } }; +struct Internal : + CYValue +{ + JSObjectRef owner_; + + Internal(id value, JSObjectRef owner) : + CYValue(value), + owner_(owner) + { + } + + static JSObjectRef Make(JSContextRef context, id object, JSObjectRef owner) { + return JSObjectMake(context, Internal_, new Internal(object, owner)); + } + + id GetValue() const { + return reinterpret_cast(value_); + } +}; + namespace sig { void Copy(apr_pool_t *pool, Type &lhs, Type &rhs); @@ -1440,7 +1466,7 @@ JSObjectRef CYMakeSelector(JSContextRef context, SEL sel) { return JSObjectMake(context, Selector_, data); } -JSObjectRef CYMakePointer(JSContextRef context, void *pointer, sig::Type *type, JSObjectRef owner) { +JSObjectRef CYMakePointer(JSContextRef context, void *pointer, sig::Type *type, ffi_type *ffi, JSObjectRef owner) { Pointer *data(new Pointer(pointer, type, owner)); return JSObjectMake(context, Pointer_, data); } @@ -1641,7 +1667,7 @@ JSValueRef CYFromFFI(JSContextRef context, sig::Type *type, ffi_type *ffi, void case sig::pointer_P: if (void *pointer = *reinterpret_cast(data)) - value = CYMakePointer(context, pointer, type->data.data.type, owner); + value = CYMakePointer(context, pointer, type->data.data.type, ffi, owner); else goto null; break; @@ -1675,7 +1701,7 @@ static JSValueRef Instance_getProperty(JSContextRef context, JSObjectRef object, CYPool pool; CYTry { - NSString *self(CYCastNSObject(pool, context, object)); + id self(CYCastNSObject(pool, context, object)); NSString *name(CYCastNSString(pool, property)); if (CYInternal *internal = CYInternal::Get(self)) @@ -1695,20 +1721,20 @@ static JSValueRef Instance_getProperty(JSContextRef context, JSObjectRef object, return CYSendMessage(pool, context, self, sel, 0, NULL, false, exception); } - if (Ivar ivar = object_getInstanceVariable(self, string, NULL)) { - Type_privateData type(pool, ivar_getTypeEncoding(ivar)); - return CYFromFFI(context, type.type_, type.GetFFI(), reinterpret_cast(self) + ivar_getOffset(ivar)); - } - return NULL; } CYCatch } +static JSValueRef Instance_getProperty_$cyi(JSContextRef context, JSObjectRef object, JSStringRef property, JSValueRef *exception) { + Instance *internal(reinterpret_cast(JSObjectGetPrivate(object))); + return Internal::Make(context, internal->GetValue(), object); +} + static bool Instance_setProperty(JSContextRef context, JSObjectRef object, JSStringRef property, JSValueRef value, JSValueRef *exception) { CYPool pool; CYTry { - NSString *self(CYCastNSObject(pool, context, object)); + id self(CYCastNSObject(pool, context, object)); NSString *name(CYCastNSString(pool, property)); NSString *data(CYCastNSObject(pool, context, value)); @@ -1729,12 +1755,6 @@ static bool Instance_setProperty(JSContextRef context, JSObjectRef object, JSStr } } - if (Ivar ivar = object_getInstanceVariable(self, string, NULL)) { - Type_privateData type(pool, ivar_getTypeEncoding(ivar)); - CYPoolFFI(pool, context, type.type_, type.GetFFI(), reinterpret_cast(self) + ivar_getOffset(ivar), value); - return true; - } - if (CYInternal *internal = CYInternal::Set(self)) { internal->SetProperty(context, property, value); return true; @@ -1747,7 +1767,7 @@ static bool Instance_setProperty(JSContextRef context, JSObjectRef object, JSStr static bool Instance_deleteProperty(JSContextRef context, JSObjectRef object, JSStringRef property, JSValueRef *exception) { CYTry { CYPoolTry { - NSString *self(CYCastNSObject(NULL, context, object)); + id self(CYCastNSObject(NULL, context, object)); NSString *name(CYCastNSString(NULL, property)); return [self cy$deleteProperty:name]; } CYPoolCatch(NULL) @@ -1766,6 +1786,57 @@ static void Instance_getPropertyNames(JSContextRef context, JSObjectRef object, JSPropertyNameAccumulatorAddName(names, CYJSString(property_getName(data[i]))); free(data); } +} + +static JSObjectRef Instance_callAsConstructor(JSContextRef context, JSObjectRef object, size_t count, const JSValueRef arguments[], JSValueRef *exception) { + CYTry { + Instance *data(reinterpret_cast(JSObjectGetPrivate(object))); + JSObjectRef value(Instance::Make(context, [data->GetValue() alloc], Instance::Uninitialized)); + return value; + } CYCatch +} + +static JSValueRef Internal_getProperty(JSContextRef context, JSObjectRef object, JSStringRef property, JSValueRef *exception) { + Internal *internal(reinterpret_cast(JSObjectGetPrivate(object))); + CYPool pool; + + CYTry { + id self(internal->GetValue()); + const char *name(CYPoolCString(pool, property)); + + if (Ivar ivar = object_getInstanceVariable(self, name, NULL)) { + Type_privateData type(pool, ivar_getTypeEncoding(ivar)); + return CYFromFFI(context, type.type_, type.GetFFI(), reinterpret_cast(self) + ivar_getOffset(ivar)); + } + + return NULL; + } CYCatch +} + +static bool Internal_setProperty(JSContextRef context, JSObjectRef object, JSStringRef property, JSValueRef value, JSValueRef *exception) { + Internal *internal(reinterpret_cast(JSObjectGetPrivate(object))); + CYPool pool; + + CYTry { + id self(internal->GetValue()); + const char *name(CYPoolCString(pool, property)); + + if (Ivar ivar = object_getInstanceVariable(self, name, NULL)) { + Type_privateData type(pool, ivar_getTypeEncoding(ivar)); + CYPoolFFI(pool, context, type.type_, type.GetFFI(), reinterpret_cast(self) + ivar_getOffset(ivar), value); + return true; + } + + return false; + } CYCatch +} + +static void Internal_getPropertyNames(JSContextRef context, JSObjectRef object, JSPropertyNameAccumulatorRef names) { + Internal *internal(reinterpret_cast(JSObjectGetPrivate(object))); + CYPool pool; + + id self(internal->GetValue()); + Class _class(object_getClass(self)); for (Class super(_class); super != NULL; super = class_getSuperclass(super)) { unsigned int size; @@ -1776,12 +1847,9 @@ static void Instance_getPropertyNames(JSContextRef context, JSObjectRef object, } } -static JSObjectRef Instance_callAsConstructor(JSContextRef context, JSObjectRef object, size_t count, const JSValueRef arguments[], JSValueRef *exception) { - CYTry { - Instance *data(reinterpret_cast(JSObjectGetPrivate(object))); - JSObjectRef value(Instance::Make(context, [data->GetValue() alloc], Instance::Uninitialized)); - return value; - } CYCatch +static JSValueRef Internal_callAsFunction_$cya(JSContextRef context, JSObjectRef object, JSObjectRef _this, size_t count, const JSValueRef arguments[], JSValueRef *exception) { + Internal *internal(reinterpret_cast(JSObjectGetPrivate(object))); + return internal->owner_; } bool Index_(apr_pool_t *pool, Struct_privateData *internal, JSStringRef property, ssize_t &index, uint8_t *&base) { @@ -1827,18 +1895,10 @@ bool Index_(apr_pool_t *pool, Struct_privateData *internal, JSStringRef property return true; } -static JSValueRef Pointer_getProperty(JSContextRef context, JSObjectRef object, JSStringRef property, JSValueRef *exception) { - CYPool pool; +static JSValueRef Pointer_getIndex(JSContextRef context, JSObjectRef object, size_t index, JSValueRef *exception) { Pointer *internal(reinterpret_cast(JSObjectGetPrivate(object))); Type_privateData *typical(internal->type_); - if (typical->type_ == NULL) - return NULL; - - ssize_t index; - if (!CYGetIndex(pool, property, index)) - return NULL; - ffi_type *ffi(typical->GetFFI()); uint8_t *base(reinterpret_cast(internal->value_)); @@ -1851,7 +1911,7 @@ static JSValueRef Pointer_getProperty(JSContextRef context, JSObjectRef object, } CYCatch } -static bool Pointer_setProperty(JSContextRef context, JSObjectRef object, JSStringRef property, JSValueRef value, JSValueRef *exception) { +static JSValueRef Pointer_getProperty(JSContextRef context, JSObjectRef object, JSStringRef property, JSValueRef *exception) { CYPool pool; Pointer *internal(reinterpret_cast(JSObjectGetPrivate(object))); Type_privateData *typical(internal->type_); @@ -1863,6 +1923,17 @@ static bool Pointer_setProperty(JSContextRef context, JSObjectRef object, JSStri if (!CYGetIndex(pool, property, index)) return NULL; + return Pointer_getIndex(context, object, index, exception); +} + +static JSValueRef Pointer_getProperty_$cyi(JSContextRef context, JSObjectRef object, JSStringRef property, JSValueRef *exception) { + return Pointer_getIndex(context, object, 0, exception); +} + +static bool Pointer_setIndex(JSContextRef context, JSObjectRef object, size_t index, JSValueRef value, JSValueRef *exception) { + Pointer *internal(reinterpret_cast(JSObjectGetPrivate(object))); + Type_privateData *typical(internal->type_); + ffi_type *ffi(typical->GetFFI()); uint8_t *base(reinterpret_cast(internal->value_)); @@ -1874,6 +1945,31 @@ static bool Pointer_setProperty(JSContextRef context, JSObjectRef object, JSStri } CYCatch } +static bool Pointer_setProperty(JSContextRef context, JSObjectRef object, JSStringRef property, JSValueRef value, JSValueRef *exception) { + CYPool pool; + Pointer *internal(reinterpret_cast(JSObjectGetPrivate(object))); + Type_privateData *typical(internal->type_); + + if (typical->type_ == NULL) + return NULL; + + ssize_t index; + if (!CYGetIndex(pool, property, index)) + return NULL; + + return Pointer_setIndex(context, object, 0, value, exception); +} + +static bool Pointer_setProperty_$cyi(JSContextRef context, JSObjectRef object, JSStringRef property, JSValueRef value, JSValueRef *exception) { + return Pointer_setIndex(context, object, 0, value, exception); +} + +static JSValueRef Struct_callAsFunction_$cya(JSContextRef context, JSObjectRef object, JSObjectRef _this, size_t count, const JSValueRef arguments[], JSValueRef *exception) { + Struct_privateData *internal(reinterpret_cast(JSObjectGetPrivate(_this))); + Type_privateData *typical(internal->type_); + return CYMakePointer(context, internal->value_, typical->type_, typical->ffi_, _this); +} + static JSValueRef Struct_getProperty(JSContextRef context, JSObjectRef object, JSStringRef property, JSValueRef *exception) { CYPool pool; Struct_privateData *internal(reinterpret_cast(JSObjectGetPrivate(object))); @@ -2281,7 +2377,7 @@ JSObjectRef Pointer_new(JSContextRef context, JSObjectRef object, size_t count, sig::Signature signature; sig::Parse(pool, &signature, type, &Structor_); - return CYMakePointer(context, value, signature.elements[0].type, NULL); + return CYMakePointer(context, value, signature.elements[0].type, NULL, NULL); } CYCatch } @@ -2322,7 +2418,7 @@ static JSObjectRef Type_callAsConstructor(JSContextRef context, JSObjectRef obje size_t size(count == 0 ? 0 : CYCastDouble(context, arguments[0])); // XXX: alignment? void *value(malloc(internal->GetFFI()->size * size)); - return CYMakePointer(context, value, internal->type_, NULL); + return CYMakePointer(context, value, internal->type_, internal->ffi_, NULL); } CYCatch } @@ -2470,6 +2566,11 @@ static JSStaticValue CYValue_staticValues[2] = { {NULL, NULL, NULL, 0} }; +static JSStaticValue Pointer_staticValues[2] = { + {"$cyi", &Pointer_getProperty_$cyi, &Pointer_setProperty_$cyi, kJSPropertyAttributeDontDelete}, + {NULL, NULL, NULL, 0} +}; + static JSStaticFunction Pointer_staticFunctions[4] = { {"toCYON", &CYValue_callAsFunction_toCYON, kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete}, {"toJSON", &CYValue_callAsFunction_toJSON, kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete}, @@ -2477,6 +2578,11 @@ static JSStaticFunction Pointer_staticFunctions[4] = { {NULL, NULL, 0} }; +static JSStaticFunction Struct_staticFunctions[2] = { + {"$cya", &Struct_callAsFunction_$cya, kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete}, + {NULL, NULL, 0} +}; + static JSStaticFunction Functor_staticFunctions[4] = { {"toCYON", &CYValue_callAsFunction_toCYON, kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete}, {"toJSON", &CYValue_callAsFunction_toJSON, kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete}, @@ -2489,6 +2595,12 @@ static JSStaticFunction Functor_staticFunctions[4] = { {NULL, NULL, NULL, 0} };*/ +static JSStaticValue Instance_staticValues[3] = { + {"value", &CYValue_getProperty_value, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete}, + {"$cyi", &Instance_getProperty_$cyi, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete}, + {NULL, NULL, NULL, 0} +}; + static JSStaticFunction Instance_staticFunctions[4] = { {"toCYON", &Instance_callAsFunction_toCYON, kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete}, {"toJSON", &Instance_callAsFunction_toJSON, kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete}, @@ -2496,6 +2608,11 @@ static JSStaticFunction Instance_staticFunctions[4] = { {NULL, NULL, 0} }; +static JSStaticFunction Internal_staticFunctions[2] = { + {"$cya", &Internal_callAsFunction_$cya, kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete}, + {NULL, NULL, 0} +}; + static JSStaticFunction Selector_staticFunctions[5] = { {"toCYON", &Selector_callAsFunction_toCYON, kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete}, {"toJSON", &Selector_callAsFunction_toJSON, kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete}, @@ -2504,7 +2621,7 @@ static JSStaticFunction Selector_staticFunctions[5] = { {NULL, NULL, 0} }; -static JSStaticFunction Type_staticFunctions[5] = { +static JSStaticFunction Type_staticFunctions[4] = { {"toCYON", &Type_callAsFunction_toCYON, kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete}, {"toJSON", &Type_callAsFunction_toJSON, kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete}, {"toString", &Type_callAsFunction_toString, kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete}, @@ -2751,7 +2868,7 @@ JSGlobalContextRef CYGetJSContext() { definition = kJSClassDefinitionEmpty; definition.className = "Instance"; - definition.staticValues = CYValue_staticValues; + definition.staticValues = Instance_staticValues; definition.staticFunctions = Instance_staticFunctions; definition.getProperty = &Instance_getProperty; definition.setProperty = &Instance_setProperty; @@ -2761,8 +2878,18 @@ JSGlobalContextRef CYGetJSContext() { definition.finalize = &CYData::Finalize; Instance_ = JSClassCreate(&definition); + definition = kJSClassDefinitionEmpty; + definition.className = "Internal"; + definition.staticFunctions = Internal_staticFunctions; + definition.getProperty = &Internal_getProperty; + definition.setProperty = &Internal_setProperty; + definition.getPropertyNames = &Internal_getPropertyNames; + definition.finalize = &CYData::Finalize; + Internal_ = JSClassCreate(&definition); + definition = kJSClassDefinitionEmpty; definition.className = "Pointer"; + definition.staticValues = Pointer_staticValues; definition.staticFunctions = Pointer_staticFunctions; definition.getProperty = &Pointer_getProperty; definition.setProperty = &Pointer_setProperty; @@ -2780,6 +2907,7 @@ JSGlobalContextRef CYGetJSContext() { definition = kJSClassDefinitionEmpty; definition.className = "Struct"; + definition.staticFunctions = Struct_staticFunctions; definition.getProperty = &Struct_getProperty; definition.setProperty = &Struct_setProperty; definition.getPropertyNames = &Struct_getPropertyNames; diff --git a/Output.cpp b/Output.cpp index 3d11cc1..a10705a 100644 --- a/Output.cpp +++ b/Output.cpp @@ -46,7 +46,7 @@ bool CYTrue::Value() const { void CYAddressOf::Output(std::ostream &out, CYFlags flags) const { rhs_->Output(out, 1, CYLeft(flags)); - out << ".addressOf()"; + out << ".$cya()"; } void CYArgument::Output(std::ostream &out) const { @@ -214,6 +214,17 @@ void CYDeclarations::Output(std::ostream &out) const { out << ';'; } +void CYDirectMember::Output(std::ostream &out, CYFlags flags) const { + object_->Output(out, Precedence(), CYLeft(flags)); + if (const char *word = property_->Word()) + out << '.' << word; + else { + out << '['; + property_->Output(out, CYNoFlags); + out << ']'; + } +} + void CYDoWhile::Output(std::ostream &out) const { // XXX: extra space character! out << "do "; @@ -320,7 +331,19 @@ void CYIf::Output(std::ostream &out) const { void CYIndirect::Output(std::ostream &out, CYFlags flags) const { rhs_->Output(out, 1, CYLeft(flags)); - out << "[0]"; + out << ".$cyi"; +} + +void CYIndirectMember::Output(std::ostream &out, CYFlags flags) const { + object_->Output(out, Precedence(), CYLeft(flags)); + out << ".$cyi"; + if (const char *word = property_->Word()) + out << '.' << word; + else { + out << '['; + property_->Output(out, CYNoFlags); + out << ']'; + } } void CYInfix::Output(std::ostream &out, CYFlags flags) const { @@ -360,17 +383,6 @@ void CYLambda::Output(std::ostream &out, CYFlags flags) const { out << ')'; } -void CYMember::Output(std::ostream &out, CYFlags flags) const { - object_->Output(out, Precedence(), CYLeft(flags)); - if (const char *word = property_->Word()) - out << '.' << word; - else { - out << '['; - property_->Output(out, CYNoFlags); - out << ']'; - } -} - void CYMessage::Output(std::ostream &out, bool replace) const { if (next_ != NULL) next_->Output(out, replace); @@ -601,7 +613,7 @@ void CYTry::Output(std::ostream &out) const { out << "try"; try_->Output(out, true); if (catch_ != NULL) - out << catch_; + catch_->Output(out); if (finally_ != NULL) { out << "finally"; finally_->Output(out, true); diff --git a/Parser.hpp b/Parser.hpp index d7cc5fd..71bdee4 100644 --- a/Parser.hpp +++ b/Parser.hpp @@ -829,6 +829,32 @@ struct CYMember : { } + void SetLeft(CYExpression *object) { + object_ = object; + } +}; + +struct CYDirectMember : + CYMember +{ + CYDirectMember(CYExpression *object, CYExpression *property) : + CYMember(object, property) + { + } + + CYPrecedence(1) + + virtual void Output(std::ostream &out, CYFlags flags) const; +}; + +struct CYIndirectMember : + CYMember +{ + CYIndirectMember(CYExpression *object, CYExpression *property) : + CYMember(object, property) + { + } + CYPrecedence(1) virtual void Output(std::ostream &out, CYFlags flags) const; diff --git a/makefile b/makefile index f75fd3a..4fbd67d 100644 --- a/makefile +++ b/makefile @@ -4,8 +4,6 @@ else target := $(PKG_TARG)- endif -package: - flags := -mthumb -g3 -O0 -Wall -Werror -I. -fno-common flags += -F${PKG_ROOT}/System/Library/PrivateFrameworks @@ -14,6 +12,8 @@ deb := $(shell grep ^Package: control | cut -d ' ' -f 2-)_$(shell grep ^Version: header := Cycript.tab.hh Parser.hpp Pooling.hpp Struct.hpp cycript.hpp +$(deb): + all: cycript libcycript.dylib libcycript.plist clean: @@ -74,7 +74,7 @@ cycript: Application.o libcycript.dylib -framework JavaScriptCore -framework UIKit ldid -S cycript -package: all +$(deb): all rm -rf package mkdir -p package/DEBIAN sed -e 's/#/$(svn)/' control >package/DEBIAN/control @@ -93,7 +93,9 @@ package: all cp -a libcycript.plist package/usr/lib dpkg-deb -b package $(deb) -test: package +package: $(deb) + +test: $(deb) dpkg -i $(deb) cycript test.cy -- 2.45.2