From ecf94af80a71bb579df516d76181f696b8c11867 Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Sat, 24 Apr 2010 23:11:51 +0000 Subject: [PATCH] Pretend to support Blocks. --- ObjectiveC/Library.mm | 4 ++++ sig/ffi_type.cpp | 2 ++ sig/parse.cpp | 25 +++++++++++++++++-------- sig/types.hpp | 3 ++- todo.txt | 1 + 5 files changed, 26 insertions(+), 9 deletions(-) diff --git a/ObjectiveC/Library.mm b/ObjectiveC/Library.mm index f40d74c..9d5289f 100644 --- a/ObjectiveC/Library.mm +++ b/ObjectiveC/Library.mm @@ -1343,6 +1343,8 @@ static void CYObjectiveC_CallFunction(JSContextRef context, ffi_cif *cif, void ( static bool CYObjectiveC_PoolFFI(apr_pool_t *pool, JSContextRef context, sig::Type *type, ffi_type *ffi, void *data, JSValueRef value) { CYSadTry { switch (type->primitive) { + // XXX: do something epic about blocks + case sig::block_P: case sig::object_P: case sig::typename_P: *reinterpret_cast(data) = CYCastNSObject(pool, context, value); @@ -1361,6 +1363,8 @@ static bool CYObjectiveC_PoolFFI(apr_pool_t *pool, JSContextRef context, sig::Ty static JSValueRef CYObjectiveC_FromFFI(JSContextRef context, sig::Type *type, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) { CYPoolTry { switch (type->primitive) { + // XXX: do something epic about blocks + case sig::block_P: case sig::object_P: if (NSObject *object = *reinterpret_cast(data)) { JSValueRef value(CYCastJSValue(context, object)); diff --git a/sig/ffi_type.cpp b/sig/ffi_type.cpp index 05dbb12..e542ba4 100644 --- a/sig/ffi_type.cpp +++ b/sig/ffi_type.cpp @@ -71,6 +71,7 @@ ffi_type *ObjectiveC(apr_pool_t *pool, struct Type *type) { case string_P: return &ffi_type_pointer; case selector_P: return &ffi_type_pointer; + case block_P: return &ffi_type_pointer; case object_P: return &ffi_type_pointer; case boolean_P: return &ffi_type_uchar; case uchar_P: return &ffi_type_uchar; @@ -139,6 +140,7 @@ ffi_type *Java(apr_pool_t *pool, struct Type *type) { case union_P: return &ffi_type_pointer; case string_P: return &ffi_type_pointer; case selector_P: return &ffi_type_pointer; + case block_P: return &ffi_type_pointer; case object_P: return &ffi_type_pointer; case boolean_P: return &ffi_type_uchar; case uchar_P: return &ffi_type_uchar; diff --git a/sig/parse.cpp b/sig/parse.cpp index 7fc663f..02e5429 100644 --- a/sig/parse.cpp +++ b/sig/parse.cpp @@ -124,17 +124,25 @@ struct Type *Parse_(apr_pool_t *pool, const char **name, char eos, bool named, C case '*': type->primitive = string_P; break; case ':': type->primitive = selector_P; break; - case '@': - if (**name == '"') { - const char *quote = strchr(*name + 1, '"'); - if (!named || quote[1] == eos || quote[1] == '"') { - type->name = apr_pstrmemdup(pool, *name + 1, quote - *name - 1); - *name = quote + 1; + case '@': { + char next(**name); + + if (next == '?') { + type->primitive = block_P; + ++*name; + } else { + type->primitive = object_P; + + if (next == '"') { + const char *quote = strchr(*name + 1, '"'); + if (!named || quote[1] == eos || quote[1] == '"') { + type->name = apr_pstrmemdup(pool, *name + 1, quote - *name - 1); + *name = quote + 1; + } } } - type->primitive = object_P; - break; + } break; case 'B': type->primitive = boolean_P; break; case 'C': type->primitive = uchar_P; break; @@ -255,6 +263,7 @@ const char *Unparse(apr_pool_t *pool, struct Type *type) { case union_P: return apr_psprintf(pool, "(%s)", Unparse(pool, &type->data.signature)); case string_P: return "*"; case selector_P: return ":"; + case block_P: return "@?"; case object_P: return type->name == NULL ? "@" : apr_psprintf(pool, "@\"%s\"", type->name); case boolean_P: return "B"; case uchar_P: return "C"; diff --git a/sig/types.hpp b/sig/types.hpp index 0d3cf20..580d999 100644 --- a/sig/types.hpp +++ b/sig/types.hpp @@ -49,7 +49,8 @@ enum Primitive { union_P = '(', string_P = '*', selector_P = ':', - object_P = '@', + block_P = '?', + object_P = 'W', boolean_P = 'B', uchar_P = 'C', uint_P = 'I', diff --git a/todo.txt b/todo.txt index b7480c1..bc4bea2 100644 --- a/todo.txt +++ b/todo.txt @@ -26,3 +26,4 @@ NSArray's .toString() and .toLocaleString() fail hard, as Array.prototype.to*Str applyOnMainThread, when done at console, loops the cyonifier special work needs to be done to correctly handle the "arguments" symbol: Declare("arguments", ...Special) at the Program level I seem to be eating away all of the var statements +function pointers are ?; note that blocks are currently block_P = '?' -- 2.45.2