Skip to content

Instantly share code, notes, and snippets.

View harlanhaskins's full-sized avatar
🦅
Swifting

Harlan Haskins harlanhaskins

🦅
Swifting
View GitHub Profile
fatal error: Test!: file fatalErrorTest/main.swift, line 3
Current stack trace:
0 libswiftCore.dylib 0x000000011af5910a reportBacktrace() + 42
1 libswiftCore.dylib 0x000000011af58d8d reportOnCrash(char const*) + 45
2 libswiftCore.dylib 0x000000011af58ece swift_reportFatalErrorInFile + 190
3 libswiftCore.dylib 0x000000011ab76cf0 Swift.(_assertionFailed (Swift.StaticString, Swift.String, Swift.StaticString, Swift.UInt) -> ()).(closure #1).(closure #1).(closure #1) + 336
4 libswiftCore.dylib 0x000000011af0fc17 partial apply forwarder for Swift.(_assertionFailed (Swift.StaticString, Swift.String, Swift.StaticString, Swift.UInt) -> ()).(closure #1).(closure #1).(closure #1) + 103
5 libswiftCore.dylib 0x000000011ab761b7 reabstraction thunk helper from @callee_owned (@unowned Swift.UnsafeBufferPointer<Swift.UInt8>) -> (@unowned ()) to @callee_owned (@unowned Swift.UnsafeBufferPointer<Swift.UInt8>) -> (@o
Current stack trace:
0 libswiftCore.dylib 0x000000011040010a reportBacktrace() + 42
1 libswiftCore.dylib 0x00000001103ffd8d reportOnCrash(char const*) + 45
2 libswiftCore.dylib 0x00000001103ffece swift_reportFatalErrorInFile + 190
3 libswiftCore.dylib 0x000000011001dcf0 Swift.(_assertionFailed (Swift.StaticString, Swift.String, Swift.StaticString, Swift.UInt) -> ()).(closure #1).(closure #1).(closure #1) + 336
4 libswiftCore.dylib 0x00000001103b6c17 partial apply forwarder for Swift.(_assertionFailed (Swift.StaticString, Swift.String, Swift.StaticString, Swift.UInt) -> ()).(closure #1).(closure #1).(closure #1) + 103
5 libswiftCore.dylib 0x000000011001d1b7 reabstraction thunk helper from @callee_owned (@unowned Swift.UnsafeBufferPointer<Swift.UInt8>) -> (@unowned ()) to @callee_owned (@unowned Swift.UnsafeBufferPointer<Swift.UInt8>) -> (@out ()) + 23
6 libswiftCore.dylib 0x00000
import CCairo
class Surface {
private let surface: COpaquePointer
private let cr: COpaquePointer
init(format: cairo_format_t, width: Int, height: Int) {
self.surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 240, 80)
self.cr = cairo_create(surface)
}
func writeToPNG(filename: String) {
import qualified Data.ByteString.Lazy.Char8 as L8
import Data.Digest.Pure.MD5 (md5)
md5List l = zip (map (md5 . L8.pack . ("yzbqklnj" ++) . show) l) l
main = print $ filter (\(x,_) -> "00000" == take 5 (show x)) (md5List [0..])
(def fact (n)
(if (= n 0)
1
(* n (fact (- n 1)))))
define private i64 @fact(i64 %n) {
entry:
%n1 = alloca i64
store i64 %n, i64* %n1
%n2 = load i64, i64* %n1
%eqtmp = icmp eq i64 %n2, 0
%0 = sext i1 %eqtmp to i64
%ifcond = icmp ne i64 %0, 0
br i1 %ifcond, label %then, label %else
func main() {
var z = 0
func goto(label: String) {
switch label {
case "start":
goto("cond")
case "cond":
if z == 5 {
goto("end")
} else {
import Darwin
func printFile(fileName: String) {
var line: UnsafeMutablePointer<Int8> = nil
var len = 0
var read = 0
let file = fopen(fileName, "r")
guard file != nil else { return }
func goto(label: String) {
switch label {
@harlanhaskins
harlanhaskins / loops.swift
Created January 8, 2016 07:11
Loops implemented terribly, in Swift
func while_(@autoclosure(escaping) cond: () -> Bool, body: () -> ()) {
func goto(label: String) {
switch label {
case "cond": goto(cond() ? "body" : "end")
case "body":
body()
goto("cond")
case "end":
fallthrough
default: break
@harlanhaskins
harlanhaskins / Goto.swift
Created January 8, 2016 07:35
An Extensible Goto framework for Swift
struct Goto {
typealias Closure = () -> ()
var closures = [String: Closure]()
func to(label: String) {
guard let closure = closures[label] else {
fatalError("Unknown label: \(label)")
}
closure()
}
mutating func set(label: String, closure: () -> ()) {