Skip to content

Instantly share code, notes, and snippets.

View jspahrsummers's full-sized avatar

Justin Spahr-Summers jspahrsummers

View GitHub Profile
data Tuple a b c d =
OneTuple a |
TwoTuple a b |
ThreeTuple a b c |
FourTuple a b c d
tuple1 :: Tuple a b c d -> Maybe a
tuple1 (OneTuple a) = Just a
tuple1 (TwoTuple a b) = Just a
tuple1 (ThreeTuple a b c) = Just a
data List a =
Nil |
Cons a (List a)
listLength :: Num b => List a -> b
listLength Nil = 0
listLength (Cons x xs) = 1 + listLength xs
listHead :: List a -> a
listHead (Cons x xs) = x
@jspahrsummers
jspahrsummers / gist:947835
Created April 29, 2011 04:27
Clang ivar write -O0
.section __TEXT,__text,regular,pure_instructions
.section __TEXT,__textcoal_nt,coalesced,pure_instructions
.section __TEXT,__const_coal,coalesced
.section __TEXT,__picsymbolstub4,symbol_stubs,none,16
.section __TEXT,__StaticInit,regular,pure_instructions
.syntax unified
.section __TEXT,__text,regular,pure_instructions
.align 2
.code 16
@jspahrsummers
jspahrsummers / gist:947836
Created April 29, 2011 04:28
Clang ivar write -Os
.section __TEXT,__text,regular,pure_instructions
.section __TEXT,__textcoal_nt,coalesced,pure_instructions
.section __TEXT,__const_coal,coalesced
.section __TEXT,__picsymbolstub4,symbol_stubs,none,16
.section __TEXT,__StaticInit,regular,pure_instructions
.syntax unified
.section __TEXT,__text,regular,pure_instructions
.align 2
.code 16
.thumb_func "-[IvarWriteAppDelegate application:didFinishLaunchingWithOptions:]"
@jspahrsummers
jspahrsummers / gist:947838
Created April 29, 2011 04:29
Clang ivar write source code
@synthesize window=_window;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
asm("#before");
_window = nil;
asm("#after");
// Override point for customization after application launch.
[self.window makeKeyAndVisible];
@jspahrsummers
jspahrsummers / scope.m
Created May 5, 2011 05:07
Following this behavior, how would you want to write it naturally?
- (NSString *)myMethod {
NSString *str = nil;
scope {
NSAutoreleasePool *pool = [NSAutoreleasePool new];
scope(exit)
[pool drain];
str = [[NSMutableString alloc] initWithFormat:@"%i", 42];
@jspahrsummers
jspahrsummers / releaseOnExit.m
Created May 9, 2011 01:59
I don't think I'll actually do this, but it was fun to come up with.
// syntactic sugar for @onExit
#define releaseOnExit \
ext_saveSelf]; @onExit { [ext_releaseObj release]; }; [(id)nil self
NSMutableString *str = [[@"foo" mutableCopy] releaseOnExit];
@jspahrsummers
jspahrsummers / gist:986175
Created May 23, 2011 03:27
Tentative coroutine syntax
#define coroutine(ARGS) \
__block unsigned long ext_coroutine_line_ = 0; \
\
return ^(ARGS){ \
for (;; ext_coroutine_line_ = 0) \
switch (ext_coroutine_line_) \
default:
#define return_coroutine \
}
@jspahrsummers
jspahrsummers / gist:1005645
Created June 3, 2011 00:44
Concurrent map for NSArray
- (NSArray *)mapWithOptions:(NSEnumerationOptions)options usingBlock:(id (^)(id obj))block {
NSUInteger count = [self count];
NSArray *result = nil;
if (options & NSEnumerationConcurrent) {
volatile id * restrict objects = malloc(sizeof(id) * count);
if (!objects) {
return nil;
}
typedef id (^Tuple)(size_t);
#define tuple(...) \
tupleMake(__VA_ARGS__, nil)
#define emptyTuple \
tupleMake(nil)
Tuple tupleMake (id firstObject, ...) NS_REQUIRES_NIL_TERMINATION
{