This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Copyright (c) 2011 Jens Ayton | |
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | |
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@implementation Foo | |
- (id) foo | |
{ | |
return [self bar]; | |
} | |
- (id) bar | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#undef MIN | |
#define MIN__(A,B,C) ({ __typeof__(A) __a##C = (A); __typeof__(B) __b##C = (B); __a##C < __b##C ? __a##C : __b##C; }) | |
#define MIN_(A,B,C) MIN__(A,B,C) | |
#define MIN(A,B) MIN_(A,B,__COUNTER__) | |
#undef MAX | |
#define MAX__(A,B,C) ({ __typeof__(A) __a##C = (A); __typeof__(B) __b##C = (B); __a##C < __b##C ? __b##C : __a##C; }) | |
#define MAX_(A,B,C) MAX__(A,B,C) | |
#define MAX(A,B) MAX_(A,B,__COUNTER__) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef format_h | |
#define format_h | |
#define reset "0" | |
#define bold "1" | |
#define red "31" | |
#define format(first, ...) \ | |
"\e[" first join_format_codes(__VA_ARGS__) "m" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Expansion of JATExpandLiteral(@"foo: {foo}; bar: {bar}; baz: {baz}", foo, bar, baz) | |
JAT_DoExpandTemplateUsingMacroKeysAndValues(@"foo: {foo}; bar: {bar}; baz: {baz}", (JATNameArray){ @"foo", @"bar", @"baz", ((void*)0) }, (JATParameterArray){ JATCastParameter(foo), JATCastParameter(bar), JATCastParameter(baz), ((void*)0) }, 3) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct ifparams { | |
#if __has_feature(objc_arc) | |
__unsafe_unretained | |
#endif | |
dispatch_block_t then, otherwise; | |
}; | |
static inline void iff(bool condition, struct ifparams params) { | |
((condition?params.then:params.otherwise)?:^{})(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern "C" { | |
// This is global, but you can call it what you like | |
inline void MyPrefixedCFShow(const void *object) { | |
// Redeclared system function is local scope and counts as extern "C" | |
extern void CFShow(const void * object); | |
CFShow(object); | |
} | |
} | |
class DumbThing { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Sketch for multiple return values in Objective-C | |
// Method declaration: | |
- (id, NSError *) someMethod:param; | |
// Desugars to: | |
typedef struct { id a, NSError *b } __someMethodResult; // Obviously gensym/anonymous in real implementation | |
- (__someMethodResult) someMethod:param; | |
// Return type encoding would be "{?=@@}", anonymous struct of two objects. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let opIncr: UInt8 = 43 // + | |
let opDecr: UInt8 = 45 // - | |
let opPrev: UInt8 = 60 // < | |
let opNext: UInt8 = 62 // > | |
let opFwd: UInt8 = 91 // [ | |
let opBck: UInt8 = 93 // ] | |
let opOutput: UInt8 = 46 // . | |
let opInput: UInt8 = 44 // , | |
let opStop: UInt8 = 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Test {} | |
extension Test: LosslessStringConvertible { | |
init?(_ description: String) { | |
print("unlabelled init") | |
} | |
var description: String { "Test" } | |
} |