Skip to content

Instantly share code, notes, and snippets.

View harlanhaskins's full-sized avatar
🦅
Swifting

Harlan Haskins harlanhaskins

🦅
Swifting
View GitHub Profile
@harlanhaskins
harlanhaskins / test.ll
Created October 21, 2016 18:26
Swift static dispatch
; ModuleID = '-'
source_filename = "-"
target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-apple-macosx10.9"
define hidden void @_TFV4test3Foo8printBarfT_T_(i64) #0 {
entry:
%1 = call %swift.type* @_TMaP_() #6
%2 = call { %swift.bridge*, i8* } @_TFs27_allocateUninitializedArrayurFBwTGSax_Bp_(i64 1, %swift.type* %1)
%3 = extractvalue { %swift.bridge*, i8* } %2, 0
(source_file
(import_decl 'Foundation')
(top_level_code_decl
(brace_stmt
(pattern_binding_decl
(pattern_named type='CGPoint' 'a')
(call_expr type='CGPoint' location=point.swift:2:9 range=[point.swift:2:9 - line:2:38] nothrow arg_labels=x:y:
(constructor_ref_call_expr type='(Int, Int) -> CGPoint' location=point.swift:2:9 range=[point.swift:2:9 - line:2:9] nothrow
(declref_expr implicit type='(CGPoint.Type) -> (Int, Int) -> CGPoint' location=point.swift:2:9 range=[point.swift:2:9 - line:2:9] decl=CoreGraphics.(file).CGPoint.init(x:y:) function_ref=single specialized=no)
(type_expr type='CGPoint.Type' location=point.swift:2:9 range=[point.swift:2:9 - line:2:9] typerepr='CGPoint'))
@harlanhaskins
harlanhaskins / shuffle.tr
Created January 3, 2017 19:50
Shuffle program for Trill in the iOS app
foreign type Array {
foreign init() -> Array
foreign func push(_: Any)
foreign subscript(_: Int) -> Any
foreign var length: Int
}
foreign type Math {
foreign static func random() -> Double
foreign static func floor(_: Double) -> Int
@harlanhaskins
harlanhaskins / bf.tr
Last active January 3, 2017 21:52
BF interpreter for the Trill iOS App
foreign type String {
foreign init(_: *Int8) -> String
foreign var length: Int
foreign func charCodeAt(_: Int) -> Int8
foreign static func fromCharCode(_: Int8) -> String
}
type Op {
let opcode: Int8
var operand: Int
@harlanhaskins
harlanhaskins / Lexer.swift
Last active March 4, 2023 20:10
Building a Compiler in Swift with LLVM, Part 1: Introduction and the Lexer
#if os(macOS)
import Darwin
#elseif os(Linux)
import Glibc
#endif
enum BinaryOperator: Character {
case plus = "+"
case minus = "-"
case times = "*"
@harlanhaskins
harlanhaskins / Parser.swift
Last active July 18, 2021 02:47
Building a Compiler in Swift with LLVM, Part 2: AST and the Parser
#if os(macOS)
import Darwin
#elseif os(Linux)
import Glibc
#endif
// MARK: Tokens
enum BinaryOperator: Character {
case plus = "+"
Name: cllvm
Description: The llvm library
Version: 3.9.1
Libs: -L/usr/local/Cellar/llvm/3.9.1/lib -lLLVMLTO -lLLVMObjCARCOpts -lLLVMSymbolize -lLLVMDebugInfoPDB -lLLVMDebugInfoDWARF -lLLVMGlobalISel -lLLVMCoverage -lLLVMTableGen -lLLVMOrcJIT -lLLVMMIRParser -lLLVMNVPTXCodeGen -lLLVMNVPTXDesc -lLLVMNVPTXInfo -lLLVMNVPTXAsmPrinter -lLLVMARMDisassembler -lLLVMARMCodeGen -lLLVMARMAsmParser -lLLVMARMDesc -lLLVMARMInfo -lLLVMARMAsmPrinter -lLLVMAMDGPUDisassembler -lLLVMAMDGPUCodeGen -lLLVMAMDGPUAsmParser -lLLVMAMDGPUDesc -lLLVMAMDGPUInfo -lLLVMAMDGPUAsmPrinter -lLLVMAMDGPUUtils -lLLVMObjectYAML -lLLVMX86Disassembler -lLLVMX86AsmParser -lLLVMX86CodeGen -lLLVMSelectionDAG -lLLVMAsmPrinter -lLLVMDebugInfoCodeView -lLLVMX86Desc -lLLVMMCDisassembler -lLLVMX86Info -lLLVMX86AsmPrinter -lLLVMX86Utils -lLLVMMCJIT -lLLVMLibDriver -lLLVMOption -lLLVMLineEditor -lLLVMPasses -lLLVMipo -lLLVMVectorize -lLLVMLinker -lLLVMIRReader -lLLVMAsmParser -lLLVMInterpreter -lLLVMExecutionEngine -lLLVMRuntimeDyld -lLLVMObject -lLLVMMCParser
(var_assign_decl <none>:2:18 kind="global" modifiers="implicit" mutable=false name="__llvm__" type="Int"
(num_expr <none>:2:18 raw="1" type="Int" value=1))
(var_assign_decl <none>:3:19 kind="global" modifiers="implicit" mutable=false name="__clang__" type="Int"
(num_expr <none>:3:19 raw="1" type="Int" value=1))
(var_assign_decl <none>:4:25 kind="global" modifiers="implicit" mutable=false name="__clang_major__" type="Int"
(num_expr <none>:4:25 raw="3" type="Int" value=3))
(var_assign_decl <none>:5:25 kind="global" modifiers="implicit" mutable=false name="__clang_minor__" type="Int"
(num_expr <none>:5:25 raw="9" type="Int" value=9))
(var_assign_decl <none>:6:30 kind="global" modifiers="implicit" mutable=false name="__clang_patchlevel__" type="Int"
(num_expr <none>:6:30 raw="1" type="Int" value=1))
@harlanhaskins
harlanhaskins / interface.swift
Last active March 2, 2017 20:33
A "Generated Interface" of everything Trill imports from C.
// <none>:2:18
let __llvm__: Int
// <none>:3:19
let __clang__: Int
// <none>:4:25
let __clang_major__: Int
// <none>:5:25