Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; Generic Foo definition
- i1 ; actual type. There can be only two types (Int32 or Float32), ~>, it's i1
- }
- ; Specialized Foo(Int32) definition
- i32 ; @bar : Int32
- i64 ; @common : Int64
- }
- ; Foo(Int32).initialize(@bar: Int32, @common : Int64)
- ; Store @bar
- ; Store @common
- ret void
- }
- ; Specialized Foo(Float32) definition
- float ; @bar : Float32
- i64 ; @common : Int64
- }
- ; Foo(Float32).initialize(@bar: Float32, @common : Int64)
- ; ditto
- }
- }
- ; Bar.new(@foo : Foo(?))
- ; Store @foo : Foo(?)
- ret void
- }
- ; Return Foo(Int32)@bar : Int32 value
- %entry:
- ; Get pointer to the type value
- ; Proceed if it's Foo(Int32), unreacheable otherwise
- %proceed:
- ret %bar
- %unreacheable
- unreacheable
- }
- ; Return Foo(?)@common : Int64 value, which offset depends on its actual type
- %entry:
- ; Get pointer to the type value
- %Foo(Int32):
- ret %common
- %Foo(Float32):
- ret %common
- %unreacheable
- unreacheable
- }
- ; Main (entry) function
- ; Skip a & b example
- ; Put the actual Foo type (which is 1st = 0) into the union
- ; Put the actual Foo(Int32) instance into the union
- ; Initialize @foo : Foo(Int32)
- ; Initialize baz : Baz
- ; Get the baz.foo pointer of type Foo(?)
- ; Load baz.foo.bar
- ; Load baz.foo.common
- ; Sum
- ; Puts
- ; Return
- ret 0
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement