Skip to content

Instantly share code, notes, and snippets.

@fjolnir
fjolnir / client.m
Created June 19, 2012 07:14
A remote debugging/inspection tool for Objective-C
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <dispatch/dispatch.h>
#include <readline/readline.h>
% build/tranquil < calltest.tq
Starting parse
Entering state 0
Reducing stack by rule 69 (line 300):
-> $$ = nterm empty (-1950691328.32767--1950691328.32767: )
Stack now 0
Entering state 2
Reading a token: Next token is token tIDENTIFIER (1.1-1.1: )
Reducing stack by rule 70 (line 303):
$1 = nterm empty (-1950691328.32767--1950691328.32767: )
captureMePlease = "hey I was defined in the root! "
a = { :arg |
block = { :arg |
arg = arg stringByAppendingString:captureMePlease.
return arg.
}
return (block:arg.).
}
myBlock = a
numAsStr = a:(321 stringValue.).
state 50
62 message_unterminated: message_receiver identifier . ':' opt_nl message_args
63 | message_receiver identifier .
':' shift, and go to state 72
':' [reduce using rule 63 (message_unterminated)]
$default reduce using rule 63 (message_unterminated)
captureMePlease = "hey I was defined in the root! "
a = { :arg |
block = {:arg |
arg = arg stringByAppendingString:captureMePlease
return arg
}
return block(arg).
}
myBlock = a
#Foo < NSObject {
+ classMethod {
print("I'm a class method %@", captureMePlease)
}
- instanceMethod: iMethArg {
print("From: %@ To: %@", iMethArg, self)
}
}
#import "TQRuntime.h"
#import <Foundation/Foundation.h>
#import <objc/runtime.h>
#import <objc/message.h>
static const NSString *_TQDynamicIvarTableKey = @"TQDynamicIvarTableKey";
#pragma mark - Utilities
\ A backslash outside a string is a comment
¥ The Yen sign can also be used (See Japanese keyboard layouts to understand why)
\ Keywords
yes
no
nil
self
super
BOOL TQAugmentClassWithOperators(Class klass)
{
// Check if it already has operators
if(class_getInstanceMethod(Klass, sel_registerName("==:"))
return NO;
// ==
IMP imp = imp_implementationWithBlock(^(id a, id b) { return [a isEqual:b] ? @YES : @NO; });
SEL sel = sel_registerName("==:");
class_addMethod(klass, sel, imp, "@@:@");
- map: lambda {
^self reduce: { obj accum=#[] | accum push lambda(obj) }
}
- _reduce: lambda result: result {
^self empty? unless: {
result push lambda(self next)
^self _map:lambda result: result
} else: {
^result
}