Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'amalgamated' of https://github.com/philipwhite/nu into …

…amalgamated
  • Loading branch information...
commit 30e5c093c7d4d6678524731902582492cfa6c68a 2 parents 41865a8 + 217c2ea
@timburks authored
Showing with 31 additions and 33 deletions.
  1. +2 −5 nu/cblocks.nu
  2. +18 −27 objc/Nu.m
  3. +11 −1 test/test_bridge.nu
View
7 nu/cblocks.nu
@@ -28,10 +28,7 @@
(try ((NuBridgedBlock class))
(catch (execption) (throw* "NuException" "This build of Nu does not support C blocks.")))
- (function __get_type_signature (identifier)
- (((NuBridgedFunction functionWithName:"signature_for_identifier" signature:"@@@") identifier
- (NuSymbolTable sharedSymbolTable))))
- (set __sig (__get_type_signature (list ret)))
+ (set __sig (signature (list ret)))
(set __blockparams ())
(set __paramlist params)
(until (eq __paramlist nil)
@@ -42,7 +39,7 @@
(set __param (car (cdr __paramlist)))
(set __paramlist (cdr (cdr __paramlist)))
(set __sig (__sig stringByAppendingString:
- (__get_type_signature __type)))
+ (signature __type)))
(set __blockparams (append __blockparams (list __param))))
;(puts "Signature: #{__sig}")
;(puts "Block params: #{__blockparams}")
View
45 objc/Nu.m
@@ -1730,26 +1730,9 @@ static id nu_calling_objc_method_handler(id target, Method m, NSMutableArray *ar
// dynamically construct the method call
- //the method_***** functions seems to count c blocks twice, i.e. they separate
- //the @ and ?. Using an NSMethodSignature seems to be an easy way around it.
- //However, it appears to have some flaws as it causes 'nuke test' to fail
-#define USE_SIG 1
-
-#if USE_SIG
- NSMethodSignature *sig = [target methodSignatureForSelector:s];
- NSUInteger argument_count = [sig numberOfArguments];
- BOOL zeroArguments = NO;
- if (argument_count == 0)
- {
- // - [NSMethodSignature numberOfArguments] returns 0 if there are no arguments, but we expect 2 (cmd and self).
- // If we get zero, we use method_getNumberOfArguments() here, and method_getArgumentType() below.
- // This works around Apple's bug in the method_*** functions, but allows 'nuke test' to pass
- argument_count = method_getNumberOfArguments(m);
- zeroArguments = YES;
- }
-#else
+
int argument_count = method_getNumberOfArguments(m);
-#endif
+
if ( [args count] != argument_count-2) {
raise_argc_exception(s, argument_count-2, [args count]);
@@ -1764,15 +1747,8 @@ static id nu_calling_objc_method_handler(id target, Method m, NSMutableArray *ar
int *argument_needs_retained = (int *) malloc (argument_count * sizeof(int));
int i;
for (i = 0; i < argument_count; i++) {
-#if USE_SIG
- if (zeroArguments) {
- method_getArgumentType(m, i, &arg_type_buffer[0], BUFSIZE);
- } else {
- strncpy(&arg_type_buffer[0], [sig getArgumentTypeAtIndex:i], BUFSIZE);
- }
-#else
+
method_getArgumentType(m, i, &arg_type_buffer[0], BUFSIZE);
-#endif
argument_types[i] = ffi_type_for_objc_type(&arg_type_buffer[0]);
argument_values[i] = value_buffer_for_objc_type(&arg_type_buffer[0]);
@@ -8966,6 +8942,19 @@ - (id) callWithArguments:(id)cdr context:(NSMutableDictionary *)context
@end
+@interface Nu_signature_operator : NuOperator {}
+@end
+
+@implementation Nu_signature_operator
+
+// signature operator; basically gives access to the static signature_for_identifier function from within Nu code
+- (id) callWithArguments:(id)cdr context:(NSMutableDictionary *)context
+{
+ return signature_for_identifier( [[cdr car] evalWithContext:context],[NuSymbolTable sharedSymbolTable]);
+}
+
+@end
+
#define install(name, class) [(NuSymbol *) [symbolTable symbolWithString:name] setValue:[[[class alloc] init] autorelease]]
void load_builtins(NuSymbolTable *symbolTable);
@@ -9098,6 +9087,8 @@ void load_builtins(NuSymbolTable *symbolTable)
install(@"?", Nu_help_operator);
install(@"version", Nu_version_operator);
+ install(@"signature", Nu_signature_operator);
+
// set some commonly-used globals
[(NuSymbol *) [symbolTable symbolWithString:@"NSUTF8StringEncoding"]
setValue:[NSNumber numberWithInt:NSUTF8StringEncoding]];
View
12 test/test_bridge.nu
@@ -32,5 +32,15 @@
(assert_equal (list 1 2 3 4) (NuTestHelper getCGRectFromProxy:structHelper))
(assert_equal (list 1 2) (NuTestHelper getCGPointFromProxy:structHelper))
(assert_equal (list 3 4) (NuTestHelper getCGSizeFromProxy:structHelper))
- (assert_equal (list 5 6) (NuTestHelper getNSRangeFromProxy:structHelper))))
+ (assert_equal (list 5 6) (NuTestHelper getNSRangeFromProxy:structHelper)))
+ (- (id) testBlocks is
+ (load "cblocks")
+ (let ((num nil)
+ (num-array (array 1 2)))
+ (set equals-num? (cblock BOOL ((id) obj (unsigned long) idx (void*) stop)
+ (if (== obj num) YES (else NO))))
+ (set num 1)
+ (assert_equal 0 (num-array indexOfObjectPassingTest:equals-num?))
+ (set num 2)
+ (assert_equal 1 (num-array indexOfObjectPassingTest:equals-num?)))))
Please sign in to comment.
Something went wrong with that request. Please try again.