doc: update docs and sample files
This commit is contained in:
530
doc/mie/sample/Person.2.mie
Normal file
530
doc/mie/sample/Person.2.mie
Normal file
@@ -0,0 +1,530 @@
|
||||
meta.source-filename "Person.im"
|
||||
|
||||
ivy.package-scope "net.doorstuck.test"
|
||||
|
||||
ivy.package-ref "std.io"
|
||||
|
||||
ivy.module {
|
||||
%cout = ivy.global-ref @cout -> ptr
|
||||
%StringBuilder = ivy.global-ref @StringBuilder : ptr
|
||||
|
||||
ivy.class @Person {
|
||||
%self.name = ivy.object-var @name : #ivy.id -> ptr
|
||||
%self.age = ivy.object-var @age : #ivy.id -> ptr
|
||||
%self.val = ivy.object-var @val : #ivy.id -> ptr
|
||||
%self.__example-property-4 = ivy.object-var @val : #ivy.id -> ptr
|
||||
%self.__example-property-5 = ivy.object-var @val : #ivy.id -> ptr
|
||||
|
||||
%lambda.0 = ivy.lambda.body <%env> (%i: #ivy.id) -> void {
|
||||
%StringBuilder = ivy.global-ref @StringBuilder -> ptr
|
||||
%0 = ivy.msg.send to %StringBuilder, new -> #ivy.id
|
||||
|
||||
%1 = ivy.str.constant "Count is "
|
||||
ivy.msg.send to %0, append:%1 -> void
|
||||
|
||||
ivy.msg.send to %0, append:%i -> void
|
||||
|
||||
%2 = ivy.msg.send to %0, to-string -> #ivy.id
|
||||
|
||||
%cout = ivy.global-ref @cout -> ptr
|
||||
%3 = ptr.load %cout : ptr -> #ivy.id
|
||||
ivy.msg.send to %3, put:%2 -> void
|
||||
|
||||
func.return : ()
|
||||
}
|
||||
|
||||
%lambda.1 = ivy.lambda.body <%env> () -> void {
|
||||
%env.q = ivy.pkg.get %env[@q] : #ivy.id -> #ivy.id
|
||||
|
||||
%StringBuilder = ivy.global-ref @StringBuilder -> ptr
|
||||
%0 = ivy.msg.send to %StringBuilder, new -> #ivy.id
|
||||
|
||||
%1 = ivy.str.constant "Value of q is "
|
||||
ivy.msg.send to %0, append:%1 -> void
|
||||
|
||||
ivy.msg.send to %0, append:%env.q -> void
|
||||
|
||||
%2 = ivy.msg.send to %0, to-string -> #ivy.id
|
||||
|
||||
%cout = ivy.global-ref @cout -> ptr
|
||||
%3 = ptr.load %cout : ptr -> #ivy.id
|
||||
ivy.msg.send to %3, put:%2 -> void
|
||||
}
|
||||
|
||||
ivy.method init(name:%name, age:%age) -> void {
|
||||
ptr.store %name, %self.name : #ivy.id, ptr
|
||||
ptr.store %age, %self.age : #ivy.id, ptr
|
||||
func.return : ()
|
||||
}
|
||||
|
||||
ivy.method test(param:%data, _:%extra) -> void {
|
||||
%0 = ptr.load %StringBuilder : ptr -> #ivy.id
|
||||
%1 = ivy.msg.send to %0, new -> #ivy.id
|
||||
|
||||
%2 = ivy.str.constant "Received "
|
||||
ivy.msg.send to %1, append:%2 -> void
|
||||
|
||||
ivy.msg.send to %1, append:%data -> void
|
||||
|
||||
%3 = ivy.str.constant ", "
|
||||
ivy.msg.send to %1, append:%3 -> void
|
||||
|
||||
ivy.msg.send to %1, append:%extra -> void
|
||||
|
||||
%4 = ivy.msg.send to %1, to-string -> #ivy.id
|
||||
|
||||
%5 = ptr.load %cout : ptr -> #ivy.id
|
||||
ivy.msg.send to %5, put:%4 -> void
|
||||
func.return : ()
|
||||
}
|
||||
|
||||
ivy.method name -> #ivy.id {
|
||||
%0 = ptr.load %self.name : ptr -> #ivy.id
|
||||
func.return %0 : #ivy.id
|
||||
}
|
||||
|
||||
ivy.method age -> #ivy.id {
|
||||
%0 = ptr.load %self.age : ptr -> #ivy.id
|
||||
func.return %0 : #ivy.id
|
||||
}
|
||||
|
||||
ivy.method age-in-months -> #ivy.id {
|
||||
%0 = ptr.load %self.age : ptr -> #ivy.id
|
||||
%1 = i32.constant 12
|
||||
%multmp = ivy.mul %0, %1 : (#ivy.id, i32) -> #ivy.id
|
||||
func.return %multmp : #ivy.id
|
||||
}
|
||||
|
||||
ivy.method set-name:%name -> void {
|
||||
ptr.store %name, %self.name : #ivy.id, ptr
|
||||
func.return : ()
|
||||
}
|
||||
|
||||
ivy.method set-age:%age -> void {
|
||||
ptr.store %age, %self.age : #ivy.id, ptr
|
||||
func.return : ()
|
||||
}
|
||||
|
||||
ivy.method set-age:%age in-units:%units -> void {
|
||||
^switch.cond.0:
|
||||
%0 = ivy.atom "years"
|
||||
%cmptmp.0 = ivy.cmp eq %age, %0 : (#ivy.id, #ivy.atom) -> i1
|
||||
cf.br-cond %cmptmp.0, ^switch.body.0, ^switch.cond.1
|
||||
|
||||
^switch.body.0:
|
||||
ptr.store %age, %self.age : #ivy.id, ptr
|
||||
cf.br ^switch.end.0
|
||||
|
||||
^switch.cond.1:
|
||||
%1 = ivy.atom "months"
|
||||
%cmptmp.1 = ivy.cmp eq %age, %1 : (#ivy.id, #ivy.atom) -> i1
|
||||
cf.br-cond %cmptmp.1, ^switch.body.1, ^switch.cond.2
|
||||
|
||||
^switch.body.1:
|
||||
%d0 = i32.constant 12
|
||||
%divtmp.0 = ivy.div %age, %d0 : (#ivy.id, i32) -> #ivy.id
|
||||
ptr.store %divtmp.0, %self.age : #ivy.id, ptr
|
||||
cf.br ^switch.end.0
|
||||
|
||||
^switch.cond.2:
|
||||
%2 = ivy.atom "days"
|
||||
%cmptmp.2 = ivy.cmp eq %age, %2 : (#ivy.id, #ivy.atom) -> i1
|
||||
cf.br-cond %cmptmp.2, ^switch.body.2, ^switch.default
|
||||
|
||||
^switch.body.2:
|
||||
%d1 = i32.constant 365
|
||||
%divtmp.1 = ivy.div %age, %d1 : (#ivy.id, i32) -> #ivy.id
|
||||
ptr.store %divtmp.1, %self.age : #ivy.id, ptr
|
||||
cf.br ^switch.end.0
|
||||
|
||||
^switch.default:
|
||||
%d2 = i32.constant 0
|
||||
cf.br ^switch.end.0
|
||||
|
||||
^switch.end:
|
||||
func.return : ()
|
||||
}
|
||||
|
||||
ivy.method get-age-in-units:%units -> #ivy.id {
|
||||
^switch.cond.0:
|
||||
%0 = ivy.atom "years"
|
||||
%cmptmp.0 = ivy.cmp eq %age, %0 : (#ivy.id, #ivy.atom) -> i1
|
||||
cf.br-cond %cmptmp.0, ^switch.body.0, ^switch.cond.1
|
||||
|
||||
^switch.body.0:
|
||||
%v0 = ptr.load %self.age : ptr -> #ivy.id
|
||||
cf.br ^switch.end(%v0: #ivy.id)
|
||||
|
||||
^switch.cond.0:
|
||||
%1 = ivy.atom "months"
|
||||
%cmptmp.1 = ivy.cmp eq %age, %1 : (#ivy.id, #ivy.atom) -> i1
|
||||
cf.br-cond %cmptmp.1, ^switch.body.1, ^switch.cond.2
|
||||
|
||||
^switch.body.0:
|
||||
%v0 = ptr.load %self.age : ptr -> #ivy.id
|
||||
%d0 = i32.constant 12
|
||||
%divtmp.0 = ivy.div %v0, %d0 : (#ivy.id, i32) -> #ivy.id
|
||||
cf.br ^switch.end(%divtmp.0: #ivy.id)
|
||||
|
||||
^switch.cond.0:
|
||||
%2 = ivy.atom "days"
|
||||
%cmptmp.2 = ivy.cmp eq %age, %2 : (#ivy.id, #ivy.atom) -> i1
|
||||
cf.br-cond %cmptmp.2, ^switch.body.2, ^switch.default
|
||||
|
||||
^switch.body.0:
|
||||
%v1 = ptr.load %self.age : ptr -> #ivy.id
|
||||
%d1 = i32.constant 365
|
||||
%divtmp.1 = ivy.div %v1, %d1 : (#ivy.id, i32) -> #ivy.id
|
||||
cf.br ^switch.end(%divtmp.1: #ivy.id)
|
||||
|
||||
^switch.default:
|
||||
%d2 = i32.constant 0
|
||||
cf.br ^switch.end(%d2.1: i32)
|
||||
|
||||
^switch.end(%result: #ivy.id):
|
||||
func.return %result : #ivy.id
|
||||
}
|
||||
|
||||
ivy.object-prop example-property
|
||||
get {
|
||||
%0 = ptr.load %self.val : ptr -> #ivy.id
|
||||
func.return %0 : #ivy.id
|
||||
}
|
||||
set (%value: #ivy.id) {
|
||||
ptr.store %value, %self.val : #ivy.id, ptr
|
||||
func.return : ()
|
||||
}
|
||||
|
||||
ivy.object-prop example-property-2 get {
|
||||
%0 = ptr.load %self.val : ptr -> #ivy.id
|
||||
func.return %0 : #ivy.id
|
||||
} set (%x: #ivy.id) {
|
||||
ptr.store %x, %self.val : #ivy.id, ptr
|
||||
func.return : ()
|
||||
}
|
||||
|
||||
ivy.object-prop example-property-3 get {
|
||||
%0 = i32.constant 42
|
||||
func.return %0 : i32
|
||||
}
|
||||
|
||||
ivy.object-prop example-property-4 get {
|
||||
%0 = ptr.load %self.p-example-property-4 : ptr -> #ivy.id
|
||||
func.return %0 : #ivy.id
|
||||
} set (%0: #ivy.id) {
|
||||
ptr.store %0, %self.p-example-property-4 : #ivy.id, ptr
|
||||
func.return : ()
|
||||
}
|
||||
|
||||
ivy.object-prop example-property-5 get {
|
||||
%0 = ptr.load %self.p-example-property-5 : ptr -> #ivy.id
|
||||
func.return %0 : #ivy.id
|
||||
}
|
||||
}
|
||||
|
||||
ivy.init-text {
|
||||
; p1 = Person new(name:'John Doe', age:34).
|
||||
%Person = ivy.global-ref @Person : ptr
|
||||
%0 = ivy.str.constant "John Doe"
|
||||
%1 = i32.constant 34
|
||||
|
||||
%2 = ivy.msg.send to %Person, new(name:%0, age:%1) -> #ivy.id
|
||||
|
||||
%p1 = ptr.alloca #ivy.id -> ptr
|
||||
ptr.store %2, %p1 : #ivy.id, ptr
|
||||
|
||||
; p1 set-age:100 in-unit:$months.
|
||||
%3 = ptr.load %p1 : ptr -> #ivy.id
|
||||
%4 = i32.constant 100
|
||||
%5 = ivy.atom "months"
|
||||
ivy.msg.send to %3, set-age:%4 in-units:%5 -> void
|
||||
|
||||
; p1 test(param:'Hello', 'World').
|
||||
%6 = ptr.load %p1 : ptr -> #ivy.id
|
||||
%7 = ivy.str.constant "Hello"
|
||||
%8 = ivy.str.constant "World"
|
||||
ivy.msg.send to %6, test(param:%7, _:%8) -> void
|
||||
|
||||
; i = 0.
|
||||
%i = ptr.alloca i32 -> ptr
|
||||
%9 = i32.constant 0
|
||||
ptr.store %9, %i : i32, ptr
|
||||
|
||||
; while i < 100 do
|
||||
^while.cond:
|
||||
; i < 100
|
||||
%10 = ptr.load %i : ptr -> i32
|
||||
%11 = i32.constant 100
|
||||
%cmptmp = ivy.cmp lt %10, %11 : (i32, i32) -> i1
|
||||
scf.condition(%cmptmp)
|
||||
cf.br-cond %cmptmp, ^while.body, ^while.end
|
||||
|
||||
^while.body:
|
||||
; cout put:'Count is {i}'.
|
||||
%12 = ivy.msg.send to %StringBuilder, new -> #ivy.id
|
||||
|
||||
%13 = ivy.str.constant "Count is "
|
||||
ivy.msg.send to %12, append:%13 -> void
|
||||
|
||||
%14 = ptr.load %i : ptr -> i32
|
||||
ivy.msg.send to %12, append:14 -> void
|
||||
|
||||
%15 = ivy.msg.send to %12, to-string -> #ivy.id
|
||||
|
||||
%16 = ptr.load %cout : ptr -> #ivy.id
|
||||
ivy.msg.send to %16, put:%15 -> void
|
||||
|
||||
; i += 2
|
||||
%17 = ptr.load %i : ptr -> i32
|
||||
%18 = i32.constant 2
|
||||
%addtmp = ivy.add %17, %18 : (i32, i32) -> i32
|
||||
ptr.store %addtmp, %i : i32, ptr
|
||||
cf.br ^while.cond
|
||||
|
||||
^while.end:
|
||||
; 0 to:100 step:2
|
||||
%19 = i32.constant 0
|
||||
%20 = i32.constant 100
|
||||
%21 = i32.constant 2
|
||||
%22 = ivy.msg.send to %19, to:%20 step:%21 -> #ivy.id
|
||||
|
||||
%for.iv.0 = ivy.msg.send to %22, value -> #ivy.id
|
||||
cf.br ^for.cond(%for.iv.0: #ivy.id)
|
||||
|
||||
^for.step:
|
||||
ivy.msg.send to %22, move-next -> void
|
||||
%for.iv.next = ivy.msg.send to %22, value -> #ivy.id
|
||||
cf.br ^for.cond(%for.iv.next: #ivy.id)
|
||||
|
||||
^for.cond(%iv: #ivy.id):
|
||||
%for.valid = ivy.is-null-ref %iv : #ivy.id -> i1
|
||||
cf.br-cond %for.valid, ^for.body(%iv: #ivy.id), ^for.end
|
||||
|
||||
^for.body(%x: #ivy.id):
|
||||
; for x in 0 to:100 step:2 do
|
||||
%23 = ivy.msg.send to %StringBuilder, new -> #ivy.id
|
||||
|
||||
; 'Count is {x}'
|
||||
%24 = ivy.str.constant "Count is "
|
||||
ivy.msg.send to %23, append:%24 -> void
|
||||
|
||||
ivy.msg.send to %23, append:%x -> void
|
||||
|
||||
%25 = ivy.msg.send to %23, to-string -> #ivy.id
|
||||
|
||||
; cout put:"Count is {x}"
|
||||
%26 = ptr.load %cout : ptr -> #ivy.id
|
||||
ivy.msg.send to %26, put:%25 -> void
|
||||
|
||||
cf.br ^for.step
|
||||
|
||||
^for.end:
|
||||
; 0 to:100 step:2 do:...
|
||||
%27 = i32.constant 0
|
||||
%28 = i32.constant 100
|
||||
%29 = i32.constant 2
|
||||
; [ :i | cout put:'Count: {i}' ]
|
||||
%30 = ivy.lambda.create %lambda.0 -> #ivy.id
|
||||
|
||||
; 0 to:100 step:2 do:[ :i | cout put:'Count: {i}' ].
|
||||
ivy.msg.send to %27, to:%28 step:%29 do:%30
|
||||
|
||||
; q = 32.
|
||||
%q = ptr.alloca i32 -> ptr
|
||||
%31 = i32.constant 32
|
||||
ptr.store %31, %q : i32, ptr
|
||||
|
||||
; l = [ cout put:'Value of q is {q}' ].
|
||||
%l = ptr.alloca #ivy.id
|
||||
%32 = ptr.load %q : ptr -> i32
|
||||
%lambda.env = ivy.pkg.create -> #ivy.id
|
||||
ivy.pkg.put %lambda.env[@q] = %32 : (#ivy.id, #ivy.id)
|
||||
|
||||
%33 = ivy.lambda.create <%lambda.env> %lambda.1 -> #ivy.id
|
||||
|
||||
ptr.store %33, %l : #ivy.id, ptr
|
||||
|
||||
; q = 64.
|
||||
%34 = i32.constant 64
|
||||
ptr.store %34, %q : i32, ptr
|
||||
|
||||
; l call.
|
||||
%35 = ptr.load %l : ptr -> #ivy.id
|
||||
ivy.msg.send to %35, call -> void
|
||||
|
||||
%j = ptr.alloca i32 -> ptr
|
||||
|
||||
%36 = i32.constant 32
|
||||
ptr.store %36, %j : i32, ptr
|
||||
|
||||
%37 = ptr.load %i : ptr -> i32
|
||||
%38 = ptr.load %j : ptr -> i32
|
||||
|
||||
%cmptmp = arith.cmp lt %37, %38 : (i32, i32) -> i1
|
||||
|
||||
%39 = ivy.lambda : () -> void {
|
||||
%cout = ivy.global-ref @cout -> ptr
|
||||
%0 = ivy.str.constant "True!"
|
||||
%1 = ptr.load %cout : ptr -> #ivy.id
|
||||
ivy.msg.send to %1, put:%0 -> void
|
||||
}
|
||||
|
||||
%40 = ivy.lambda : () -> void {
|
||||
%cout = ivy.global-ref @cout -> ptr
|
||||
%0 = ivy.str.constant "False!"
|
||||
%1 = ptr.load %cout : ptr -> #ivy.id
|
||||
ivy.msg.send to %1, put:%0 -> void
|
||||
}
|
||||
|
||||
ivy.msg.send to %cmptmp, if:%39 else:%40 -> void
|
||||
|
||||
%41 = ptr.load %i : ptr -> i32
|
||||
%42 = ptr.load %j : ptr -> i32
|
||||
|
||||
%cmptmp.0 = arith.cmp lt %41, %42 : (i32, i32) -> i1
|
||||
|
||||
scf.if %cmptmp.0 -> void {
|
||||
%43 = ivy.str.constant "True!"
|
||||
%44 = ptr.load %cout : ptr -> #ivy.id
|
||||
ivy.msg.send to %44, put:%43 -> void
|
||||
}
|
||||
|
||||
; pkg = {}.
|
||||
%pkg = ptr.alloca #ivy.id -> ptr
|
||||
|
||||
|
||||
%45 = ivy.pkg.create -> #ivy.id
|
||||
ptr.store %45, %pkg : #ivy.id, ptr
|
||||
|
||||
; pkg[0] = 16.
|
||||
%46 = ptr.load %pkg : ptr -> #ivy.id
|
||||
%47 = i32.constant 0
|
||||
%48 = i32.constant 16
|
||||
|
||||
ivy.msg.send to %46, at:%47 put:%48 -> void
|
||||
|
||||
; tuple = (32, 'a string')
|
||||
%tuple = ptr.alloca #ivy.id -> ptr
|
||||
|
||||
%49 = i32.constant 32
|
||||
%50 = ivy.str.constant "a string"
|
||||
|
||||
%51 = ivy.tuple.create %49, %50 : (i32, #ivy.id) -> #ivy.id
|
||||
|
||||
ptr.store %51, %tuple : #ivy.id, ptr
|
||||
|
||||
%52 = ptr.load %tuple : ptr -> #ivy.id
|
||||
%53 = ivy.msg.send to %52, get-iterator -> #ivy.id
|
||||
|
||||
ivy.for %54 in %53 -> void {
|
||||
%key = ivy.tuple.get-item %54[0] : #ivy.id -> #ivy.id
|
||||
%val = ivy.tuple.get-item %54[1] : #ivy.id -> #ivy.id
|
||||
|
||||
; '{key} -> {val}'
|
||||
%55 = ivy.msg.send to %StringBuilder, new -> #ivy.id
|
||||
|
||||
ivy.msg.send to %55, append:%key -> void
|
||||
|
||||
%56 = ivy.str.constant " -> "
|
||||
ivy.msg.send to %55, append:%56 -> void
|
||||
|
||||
ivy.msg.send to %55, append:%val -> void
|
||||
|
||||
%57 = ivy.msg.send to %23, to-string -> #ivy.id
|
||||
|
||||
; cout put:'{key} -> {val}'
|
||||
%58 = ptr.load %cout : ptr -> #ivy.id
|
||||
ivy.msg.send to %58, put:%57 -> void
|
||||
}
|
||||
|
||||
; _ = 3 * 2.
|
||||
%59 = i32.constant 3
|
||||
%60 = i32.constant 2
|
||||
%multmp = arith.mul %59, %60 : (i32, i32) -> i32
|
||||
|
||||
; a = (32, 64).
|
||||
%a = ptr.alloca #ivy.id -> ptr
|
||||
|
||||
%61 = i32.constant 32
|
||||
%62 = i32.constant 64
|
||||
%63 = ivy.tuple.create %61, %62 : (i32, i32) -> #ivy.id
|
||||
|
||||
ptr.store %63, %a : #ivy.id, ptr
|
||||
|
||||
%v = ptr.alloca #ivy.id -> ptr
|
||||
|
||||
%64 = ptr.load %a : ptr -> #ivy.id
|
||||
%65 = ivy.tuple.get-item %64[1] : #ivy.id -> #ivy.id
|
||||
|
||||
ptr.store %65, %v : #ivy.id, ptr
|
||||
|
||||
%66 = ivy.atom "err:number-format"
|
||||
|
||||
ivy.try -> void {
|
||||
|
||||
} catch (%ex = %66), %data {
|
||||
|
||||
} catch-all %ex, %data {
|
||||
|
||||
}
|
||||
|
||||
%67 = ivy.lambda : () -> void {
|
||||
%v = ptr.alloca #ivy.id -> ptr
|
||||
%Int = ivy.global-ref @Int -> ptr
|
||||
%0 = ivy.str.constant "342"
|
||||
|
||||
%1 = ivy.msg.send to %Int, parse:%0
|
||||
|
||||
ptr.store %1, %v : #ivy.id, ptr
|
||||
}
|
||||
|
||||
%68 = ivy.lambda %err, %data : (#ivy.id, #ivy.id) -> void {
|
||||
%0 = ivy.msg.send to %StringBuilder, new -> #ivy.id
|
||||
|
||||
ivy.msg.send to %0, append:%key -> void
|
||||
|
||||
%1 = ivy.str.constant "Cannot parse integer string ("
|
||||
ivy.msg.send to %0, append:%1 -> void
|
||||
|
||||
ivy.msg.send to %0, append:%err -> void
|
||||
|
||||
%2 = ivy.str.constant ")"
|
||||
ivy.msg.send to %0, append:%2 -> void
|
||||
|
||||
%3 = ivy.msg.send to %0, to-string -> #ivy.id
|
||||
|
||||
; cout put:'{key} -> {val}'
|
||||
%4 = ptr.load %cout : ptr -> #ivy.id
|
||||
ivy.msg.send to %4, put:%3 -> void
|
||||
}
|
||||
|
||||
%69 = ivy.lambda %err, %data : (#ivy.id, #ivy.id) -> void {
|
||||
%0 = ivy.msg.send to %StringBuilder, new -> #ivy.id
|
||||
|
||||
ivy.msg.send to %0, append:%key -> void
|
||||
|
||||
%1 = ivy.str.constant "Error "
|
||||
ivy.msg.send to %0, append:%1 -> void
|
||||
|
||||
ivy.msg.send to %0, append:%err -> void
|
||||
|
||||
%2 = ivy.str.constant " occurred ("
|
||||
ivy.msg.send to %0, append:%2 -> void
|
||||
|
||||
ivy.msg.send to %0, append:%data -> void
|
||||
|
||||
%3 = ivy.str.constant ")"
|
||||
|
||||
%4 = ivy.msg.send to %0, to-string -> #ivy.id
|
||||
|
||||
; cout put:'{key} -> {val}'
|
||||
%5 = ptr.load %cout : ptr -> #ivy.id
|
||||
ivy.msg.send to %5, put:%4 -> void
|
||||
}
|
||||
|
||||
%70 = ivy.atom "err:number-format"
|
||||
ivy.msg.send to %67, on:%70 do:%68 -> #ivy.id
|
||||
ivy.msg.send to %67, on-error:%69 -> void
|
||||
ivy.msg.send to %67, call -> void
|
||||
}
|
||||
}
|
||||
535
doc/mie/sample/Person.3.mie
Normal file
535
doc/mie/sample/Person.3.mie
Normal file
@@ -0,0 +1,535 @@
|
||||
meta.source-filename "Person.im"
|
||||
|
||||
ivy.package-scope "net.doorstuck.test"
|
||||
|
||||
ivy.package-ref "std.io"
|
||||
|
||||
ivy.module {
|
||||
%cout = ivy.global-ref @cout -> ptr
|
||||
%StringBuilder = ivy.global-ref @StringBuilder : ptr
|
||||
|
||||
ivy.class @Person {
|
||||
%self.name = ivy.object-var @name : #ivy.id -> ptr
|
||||
%self.age = ivy.object-var @age : #ivy.id -> ptr
|
||||
%self.val = ivy.object-var @val : #ivy.id -> ptr
|
||||
%self.__example-property-4 = ivy.object-var @val : #ivy.id -> ptr
|
||||
%self.__example-property-5 = ivy.object-var @val : #ivy.id -> ptr
|
||||
|
||||
%lambda.0 = ivy.lambda.body <%env> (%i: #ivy.id) -> void {
|
||||
%StringBuilder = ivy.global-ref @StringBuilder -> ptr
|
||||
%0 = ivy.msg.send to %StringBuilder, new -> #ivy.id
|
||||
|
||||
%1 = ivy.str.constant "Count is "
|
||||
ivy.msg.send to %0, append:%1 -> void
|
||||
|
||||
ivy.msg.send to %0, append:%i -> void
|
||||
|
||||
%2 = ivy.msg.send to %0, to-string -> #ivy.id
|
||||
|
||||
%cout = ivy.global-ref @cout -> ptr
|
||||
%3 = ptr.load %cout : ptr -> #ivy.id
|
||||
ivy.msg.send to %3, put:%2 -> void
|
||||
|
||||
func.return : ()
|
||||
}
|
||||
|
||||
%lambda.1 = ivy.lambda.body <%env> () -> void {
|
||||
%env.q = ivy.pkg.get %env[@q] : #ivy.id -> #ivy.id
|
||||
|
||||
%StringBuilder = ivy.global-ref @StringBuilder -> ptr
|
||||
%0 = ivy.msg.send to %StringBuilder, new -> #ivy.id
|
||||
|
||||
%1 = ivy.str.constant "Value of q is "
|
||||
ivy.msg.send to %0, append:%1 -> void
|
||||
|
||||
ivy.msg.send to %0, append:%env.q -> void
|
||||
|
||||
%2 = ivy.msg.send to %0, to-string -> #ivy.id
|
||||
|
||||
%cout = ivy.global-ref @cout -> ptr
|
||||
%3 = ptr.load %cout : ptr -> #ivy.id
|
||||
ivy.msg.send to %3, put:%2 -> void
|
||||
}
|
||||
|
||||
ivy.object.func init(name:%name, age:%age) -> void {
|
||||
ptr.store %name, %self.name : #ivy.id, ptr
|
||||
ptr.store %age, %self.age : #ivy.id, ptr
|
||||
func.return : ()
|
||||
}
|
||||
|
||||
ivy.object.func test(param:%data, _:%extra) -> void {
|
||||
%0 = ptr.load %StringBuilder : ptr -> #ivy.id
|
||||
%1 = ivy.msg.send to %0, new -> #ivy.id
|
||||
|
||||
%2 = ivy.str.constant "Received "
|
||||
ivy.msg.send to %1, append:%2 -> void
|
||||
|
||||
ivy.msg.send to %1, append:%data -> void
|
||||
|
||||
%3 = ivy.str.constant ", "
|
||||
ivy.msg.send to %1, append:%3 -> void
|
||||
|
||||
ivy.msg.send to %1, append:%extra -> void
|
||||
|
||||
%4 = ivy.msg.send to %1, to-string -> #ivy.id
|
||||
|
||||
%5 = ptr.load %cout : ptr -> #ivy.id
|
||||
ivy.msg.send to %5, put:%4 -> void
|
||||
func.return : ()
|
||||
}
|
||||
|
||||
ivy.object.func name -> #ivy.id {
|
||||
%0 = ptr.load %self.name : ptr -> #ivy.id
|
||||
func.return %0 : #ivy.id
|
||||
}
|
||||
|
||||
ivy.object.func age -> #ivy.id {
|
||||
%0 = ptr.load %self.age : ptr -> #ivy.id
|
||||
func.return %0 : #ivy.id
|
||||
}
|
||||
|
||||
ivy.object.func age-in-months -> #ivy.id {
|
||||
%0 = ptr.load %self.age : ptr -> #ivy.id
|
||||
%1 = i32.constant 12
|
||||
%multmp = ivy.mul %0, %1 : (#ivy.id, i32) -> #ivy.id
|
||||
func.return %multmp : #ivy.id
|
||||
}
|
||||
|
||||
ivy.object.func set-name:%name -> void {
|
||||
ptr.store %name, %self.name : #ivy.id, ptr
|
||||
func.return : ()
|
||||
}
|
||||
|
||||
ivy.object.func set-age:%age -> void {
|
||||
ptr.store %age, %self.age : #ivy.id, ptr
|
||||
func.return : ()
|
||||
}
|
||||
|
||||
ivy.object.func set-age:%age in-units:%units -> void {
|
||||
^switch.cond.0:
|
||||
%0 = ivy.atom "years"
|
||||
%cmptmp.0 = ivy.cmp eq %age, %0 : (#ivy.id, #ivy.atom) -> i1
|
||||
cf.br-cond %cmptmp.0, ^switch.body.0, ^switch.cond.1
|
||||
|
||||
^switch.body.0:
|
||||
ptr.store %age, %self.age : #ivy.id, ptr
|
||||
cf.br ^switch.end.0
|
||||
|
||||
^switch.cond.1:
|
||||
%1 = ivy.atom "months"
|
||||
%cmptmp.1 = ivy.cmp eq %age, %1 : (#ivy.id, #ivy.atom) -> i1
|
||||
cf.br-cond %cmptmp.1, ^switch.body.1, ^switch.cond.2
|
||||
|
||||
^switch.body.1:
|
||||
%d0 = i32.constant 12
|
||||
%divtmp.0 = ivy.div %age, %d0 : (#ivy.id, i32) -> #ivy.id
|
||||
ptr.store %divtmp.0, %self.age : #ivy.id, ptr
|
||||
cf.br ^switch.end.0
|
||||
|
||||
^switch.cond.2:
|
||||
%2 = ivy.atom "days"
|
||||
%cmptmp.2 = ivy.cmp eq %age, %2 : (#ivy.id, #ivy.atom) -> i1
|
||||
cf.br-cond %cmptmp.2, ^switch.body.2, ^switch.default
|
||||
|
||||
^switch.body.2:
|
||||
%d1 = i32.constant 365
|
||||
%divtmp.1 = ivy.div %age, %d1 : (#ivy.id, i32) -> #ivy.id
|
||||
ptr.store %divtmp.1, %self.age : #ivy.id, ptr
|
||||
cf.br ^switch.end.0
|
||||
|
||||
^switch.default:
|
||||
%d2 = i32.constant 0
|
||||
ptr.store %d2, %self.age : #ivy.id, ptr
|
||||
cf.br ^switch.end.0
|
||||
|
||||
^switch.end:
|
||||
func.return : ()
|
||||
}
|
||||
|
||||
ivy.object.func get-age-in-units:%units -> #ivy.id {
|
||||
^switch.cond.0:
|
||||
%0 = ivy.atom "years"
|
||||
%cmptmp.0 = ivy.cmp eq %age, %0 : (#ivy.id, #ivy.atom) -> i1
|
||||
cf.br-cond %cmptmp.0, ^switch.body.0, ^switch.cond.1
|
||||
|
||||
^switch.body.0:
|
||||
%v0 = ptr.load %self.age : ptr -> #ivy.id
|
||||
cf.br ^switch.end(%v0: #ivy.id)
|
||||
|
||||
^switch.cond.1:
|
||||
%1 = ivy.atom "months"
|
||||
%cmptmp.1 = ivy.cmp eq %age, %1 : (#ivy.id, #ivy.atom) -> i1
|
||||
cf.br-cond %cmptmp.1, ^switch.body.1, ^switch.cond.2
|
||||
|
||||
^switch.body.1:
|
||||
%v0 = ptr.load %self.age : ptr -> #ivy.id
|
||||
%d0 = i32.constant 12
|
||||
%divtmp.0 = ivy.div %v0, %d0 : (#ivy.id, i32) -> #ivy.id
|
||||
cf.br ^switch.end(%divtmp.0: #ivy.id)
|
||||
|
||||
^switch.cond.2:
|
||||
%2 = ivy.atom "days"
|
||||
%cmptmp.2 = ivy.cmp eq %age, %2 : (#ivy.id, #ivy.atom) -> i1
|
||||
cf.br-cond %cmptmp.2, ^switch.body.2, ^switch.default
|
||||
|
||||
^switch.body.2:
|
||||
%v1 = ptr.load %self.age : ptr -> #ivy.id
|
||||
%d1 = i32.constant 365
|
||||
%divtmp.1 = ivy.div %v1, %d1 : (#ivy.id, i32) -> #ivy.id
|
||||
cf.br ^switch.end(%divtmp.1: #ivy.id)
|
||||
|
||||
^switch.default:
|
||||
%d2 = i32.constant 0
|
||||
cf.br ^switch.end(%d2.1: i32)
|
||||
|
||||
^switch.end(%result: #ivy.id):
|
||||
func.return %result : #ivy.id
|
||||
}
|
||||
|
||||
ivy.object.prop example-property
|
||||
get {
|
||||
%0 = ptr.load %self.val : ptr -> #ivy.id
|
||||
func.return %0 : #ivy.id
|
||||
}
|
||||
set (%value: #ivy.id) {
|
||||
ptr.store %value, %self.val : #ivy.id, ptr
|
||||
func.return : ()
|
||||
}
|
||||
|
||||
ivy.object.prop example-property-2 get {
|
||||
%0 = ptr.load %self.val : ptr -> #ivy.id
|
||||
func.return %0 : #ivy.id
|
||||
} set (%x: #ivy.id) {
|
||||
ptr.store %x, %self.val : #ivy.id, ptr
|
||||
func.return : ()
|
||||
}
|
||||
|
||||
ivy.object.prop example-property-3 get {
|
||||
%0 = i32.constant 42
|
||||
func.return %0 : i32
|
||||
}
|
||||
|
||||
ivy.object.prop example-property-4 get {
|
||||
%0 = ptr.load %self.p-example-property-4 : ptr -> #ivy.id
|
||||
func.return %0 : #ivy.id
|
||||
} set (%0: #ivy.id) {
|
||||
ptr.store %0, %self.p-example-property-4 : #ivy.id, ptr
|
||||
func.return : ()
|
||||
}
|
||||
|
||||
ivy.object.prop example-property-5 get {
|
||||
%0 = ptr.load %self.p-example-property-5 : ptr -> #ivy.id
|
||||
func.return %0 : #ivy.id
|
||||
}
|
||||
}
|
||||
|
||||
ivy.init-text {
|
||||
; p1 = Person new(name:'John Doe', age:34).
|
||||
%Person = ivy.global-ref @Person : ptr
|
||||
%0 = ivy.str.constant "John Doe"
|
||||
%1 = i32.constant 34
|
||||
|
||||
%2 = ivy.msg.send to %Person, new(name:%0, age:%1) -> #ivy.id
|
||||
|
||||
%p1 = ptr.alloca #ivy.id -> ptr
|
||||
ptr.store %2, %p1 : #ivy.id, ptr
|
||||
|
||||
; p1 set-age:100 in-unit:$months.
|
||||
%3 = ptr.load %p1 : ptr -> #ivy.id
|
||||
%4 = i32.constant 100
|
||||
%5 = ivy.atom "months"
|
||||
ivy.msg.send to %3, set-age:%4 in-units:%5 -> void
|
||||
|
||||
; p1 test(param:'Hello', 'World').
|
||||
%6 = ptr.load %p1 : ptr -> #ivy.id
|
||||
%7 = ivy.str.constant "Hello"
|
||||
%8 = ivy.str.constant "World"
|
||||
ivy.msg.send to %6, test(param:%7, _:%8) -> void
|
||||
|
||||
; i = 0.
|
||||
%i = ptr.alloca i32 -> ptr
|
||||
%9 = i32.constant 0
|
||||
ptr.store %9, %i : i32, ptr
|
||||
cf.br ^while.cond
|
||||
|
||||
; while i < 100 do
|
||||
^while.cond:
|
||||
; i < 100
|
||||
%10 = ptr.load %i : ptr -> i32
|
||||
%11 = i32.constant 100
|
||||
%cmptmp = ivy.cmp lt %10, %11 : (i32, i32) -> i1
|
||||
scf.condition(%cmptmp)
|
||||
cf.br-cond %cmptmp, ^while.body, ^while.end
|
||||
|
||||
^while.body:
|
||||
; cout put:'Count is {i}'.
|
||||
%12 = ivy.msg.send to %StringBuilder, new -> #ivy.id
|
||||
|
||||
%13 = ivy.str.constant "Count is "
|
||||
ivy.msg.send to %12, append:%13 -> void
|
||||
|
||||
%14 = ptr.load %i : ptr -> i32
|
||||
ivy.msg.send to %12, append:14 -> void
|
||||
|
||||
%15 = ivy.msg.send to %12, to-string -> #ivy.id
|
||||
|
||||
%16 = ptr.load %cout : ptr -> #ivy.id
|
||||
ivy.msg.send to %16, put:%15 -> void
|
||||
|
||||
; i += 2
|
||||
%17 = ptr.load %i : ptr -> i32
|
||||
%18 = i32.constant 2
|
||||
%addtmp = ivy.add %17, %18 : (i32, i32) -> i32
|
||||
ptr.store %addtmp, %i : i32, ptr
|
||||
cf.br ^while.cond
|
||||
|
||||
^while.end:
|
||||
; 0 to:100 step:2
|
||||
%19 = i32.constant 0
|
||||
%20 = i32.constant 100
|
||||
%21 = i32.constant 2
|
||||
%22 = ivy.msg.send to %19, to:%20 step:%21 -> #ivy.id
|
||||
|
||||
cf.br ^for.init(%22: #ivy.id)
|
||||
|
||||
^for.init(%it: #ivy.id):
|
||||
%for.iv.0 = ivy.msg.send to %it, value -> #ivy.id
|
||||
cf.br ^for.cond(%it: #ivy.id, %for.iv.0: #ivy.id)
|
||||
|
||||
^for.step(%it: #ivy.id):
|
||||
ivy.msg.send to %22, move-next -> void
|
||||
%for.iv.next = ivy.msg.send to %22, value -> #ivy.id
|
||||
cf.br ^for.cond(%it: #ivy.id, %for.iv.next: #ivy.id)
|
||||
|
||||
^for.cond(%it: #ivy.id, %iv: #ivy.id):
|
||||
%for.valid = ivy.is-null-ref %iv : #ivy.id -> i1
|
||||
cf.br-cond %for.valid, ^for.body(%it: #ivy.id, %iv: #ivy.id), ^for.end
|
||||
|
||||
^for.body(%it: #ivy.id, %x: #ivy.id):
|
||||
; for x in 0 to:100 step:2 do
|
||||
%23 = ivy.msg.send to %StringBuilder, new -> #ivy.id
|
||||
|
||||
; 'Count is {x}'
|
||||
%24 = ivy.str.constant "Count is "
|
||||
ivy.msg.send to %23, append:%24 -> void
|
||||
|
||||
ivy.msg.send to %23, append:%x -> void
|
||||
|
||||
%25 = ivy.msg.send to %23, to-string -> #ivy.id
|
||||
|
||||
; cout put:"Count is {x}"
|
||||
%26 = ptr.load %cout : ptr -> #ivy.id
|
||||
ivy.msg.send to %26, put:%25 -> void
|
||||
|
||||
cf.br ^for.step(%it: #ivy.id)
|
||||
|
||||
^for.end:
|
||||
; 0 to:100 step:2 do:...
|
||||
%27 = i32.constant 0
|
||||
%28 = i32.constant 100
|
||||
%29 = i32.constant 2
|
||||
; [ :i | cout put:'Count: {i}' ]
|
||||
%30 = ivy.lambda.create %lambda.0 -> #ivy.id
|
||||
|
||||
; 0 to:100 step:2 do:[ :i | cout put:'Count: {i}' ].
|
||||
ivy.msg.send to %27, to:%28 step:%29 do:%30
|
||||
|
||||
; q = 32.
|
||||
%q = ptr.alloca i32 -> ptr
|
||||
%31 = i32.constant 32
|
||||
ptr.store %31, %q : i32, ptr
|
||||
|
||||
; l = [ cout put:'Value of q is {q}' ].
|
||||
%l = ptr.alloca #ivy.id
|
||||
%32 = ptr.load %q : ptr -> i32
|
||||
%lambda.env = ivy.pkg.create -> #ivy.id
|
||||
ivy.pkg.put %lambda.env[@q] = %32 : (#ivy.id, #ivy.id)
|
||||
|
||||
%33 = ivy.lambda.create <%lambda.env> %lambda.1 -> #ivy.id
|
||||
|
||||
ptr.store %33, %l : #ivy.id, ptr
|
||||
|
||||
; q = 64.
|
||||
%34 = i32.constant 64
|
||||
ptr.store %34, %q : i32, ptr
|
||||
|
||||
; l call.
|
||||
%35 = ptr.load %l : ptr -> #ivy.id
|
||||
ivy.msg.send to %35, call -> void
|
||||
|
||||
%j = ptr.alloca i32 -> ptr
|
||||
|
||||
%36 = i32.constant 32
|
||||
ptr.store %36, %j : i32, ptr
|
||||
|
||||
%37 = ptr.load %i : ptr -> i32
|
||||
%38 = ptr.load %j : ptr -> i32
|
||||
|
||||
%cmptmp = arith.cmp lt %37, %38 : (i32, i32) -> i1
|
||||
|
||||
%39 = ivy.lambda : () -> void {
|
||||
%cout = ivy.global-ref @cout -> ptr
|
||||
%0 = ivy.str.constant "True!"
|
||||
%1 = ptr.load %cout : ptr -> #ivy.id
|
||||
ivy.msg.send to %1, put:%0 -> void
|
||||
}
|
||||
|
||||
%40 = ivy.lambda : () -> void {
|
||||
%cout = ivy.global-ref @cout -> ptr
|
||||
%0 = ivy.str.constant "False!"
|
||||
%1 = ptr.load %cout : ptr -> #ivy.id
|
||||
ivy.msg.send to %1, put:%0 -> void
|
||||
}
|
||||
|
||||
ivy.msg.send to %cmptmp, if:%39 else:%40 -> void
|
||||
|
||||
%41 = ptr.load %i : ptr -> i32
|
||||
%42 = ptr.load %j : ptr -> i32
|
||||
|
||||
%cmptmp.0 = arith.cmp lt %41, %42 : (i32, i32) -> i1
|
||||
|
||||
scf.if %cmptmp.0 -> void {
|
||||
%43 = ivy.str.constant "True!"
|
||||
%44 = ptr.load %cout : ptr -> #ivy.id
|
||||
ivy.msg.send to %44, put:%43 -> void
|
||||
}
|
||||
|
||||
; pkg = {}.
|
||||
%pkg = ptr.alloca #ivy.id -> ptr
|
||||
|
||||
|
||||
%45 = ivy.pkg.create -> #ivy.id
|
||||
ptr.store %45, %pkg : #ivy.id, ptr
|
||||
|
||||
; pkg[0] = 16.
|
||||
%46 = ptr.load %pkg : ptr -> #ivy.id
|
||||
%47 = i32.constant 0
|
||||
%48 = i32.constant 16
|
||||
|
||||
ivy.msg.send to %46, at:%47 put:%48 -> void
|
||||
|
||||
; tuple = (32, 'a string')
|
||||
%tuple = ptr.alloca #ivy.id -> ptr
|
||||
|
||||
%49 = i32.constant 32
|
||||
%50 = ivy.str.constant "a string"
|
||||
|
||||
%51 = ivy.tuple.create %49, %50 : (i32, #ivy.id) -> #ivy.id
|
||||
|
||||
ptr.store %51, %tuple : #ivy.id, ptr
|
||||
|
||||
%52 = ptr.load %tuple : ptr -> #ivy.id
|
||||
%53 = ivy.msg.send to %52, get-iterator -> #ivy.id
|
||||
|
||||
ivy.for %54 in %53 -> void {
|
||||
%key = ivy.tuple.get-item %54[0] : #ivy.id -> #ivy.id
|
||||
%val = ivy.tuple.get-item %54[1] : #ivy.id -> #ivy.id
|
||||
|
||||
; '{key} -> {val}'
|
||||
%55 = ivy.msg.send to %StringBuilder, new -> #ivy.id
|
||||
|
||||
ivy.msg.send to %55, append:%key -> void
|
||||
|
||||
%56 = ivy.str.constant " -> "
|
||||
ivy.msg.send to %55, append:%56 -> void
|
||||
|
||||
ivy.msg.send to %55, append:%val -> void
|
||||
|
||||
%57 = ivy.msg.send to %23, to-string -> #ivy.id
|
||||
|
||||
; cout put:'{key} -> {val}'
|
||||
%58 = ptr.load %cout : ptr -> #ivy.id
|
||||
ivy.msg.send to %58, put:%57 -> void
|
||||
}
|
||||
|
||||
; _ = 3 * 2.
|
||||
%59 = i32.constant 3
|
||||
%60 = i32.constant 2
|
||||
%multmp = arith.mul %59, %60 : (i32, i32) -> i32
|
||||
|
||||
; a = (32, 64).
|
||||
%a = ptr.alloca #ivy.id -> ptr
|
||||
|
||||
%61 = i32.constant 32
|
||||
%62 = i32.constant 64
|
||||
%63 = ivy.tuple.create %61, %62 : (i32, i32) -> #ivy.id
|
||||
|
||||
ptr.store %63, %a : #ivy.id, ptr
|
||||
|
||||
%v = ptr.alloca #ivy.id -> ptr
|
||||
|
||||
%64 = ptr.load %a : ptr -> #ivy.id
|
||||
%65 = ivy.tuple.get-item %64[1] : #ivy.id -> #ivy.id
|
||||
|
||||
ptr.store %65, %v : #ivy.id, ptr
|
||||
|
||||
%66 = ivy.atom "err:number-format"
|
||||
|
||||
ivy.try -> void {
|
||||
|
||||
} catch (%ex = %66), %data {
|
||||
|
||||
} catch-all %ex, %data {
|
||||
|
||||
}
|
||||
|
||||
%67 = ivy.lambda : () -> void {
|
||||
%v = ptr.alloca #ivy.id -> ptr
|
||||
%Int = ivy.global-ref @Int -> ptr
|
||||
%0 = ivy.str.constant "342"
|
||||
|
||||
%1 = ivy.msg.send to %Int, parse:%0
|
||||
|
||||
ptr.store %1, %v : #ivy.id, ptr
|
||||
}
|
||||
|
||||
%68 = ivy.lambda %err, %data : (#ivy.id, #ivy.id) -> void {
|
||||
%0 = ivy.msg.send to %StringBuilder, new -> #ivy.id
|
||||
|
||||
ivy.msg.send to %0, append:%key -> void
|
||||
|
||||
%1 = ivy.str.constant "Cannot parse integer string ("
|
||||
ivy.msg.send to %0, append:%1 -> void
|
||||
|
||||
ivy.msg.send to %0, append:%err -> void
|
||||
|
||||
%2 = ivy.str.constant ")"
|
||||
ivy.msg.send to %0, append:%2 -> void
|
||||
|
||||
%3 = ivy.msg.send to %0, to-string -> #ivy.id
|
||||
|
||||
; cout put:'{key} -> {val}'
|
||||
%4 = ptr.load %cout : ptr -> #ivy.id
|
||||
ivy.msg.send to %4, put:%3 -> void
|
||||
}
|
||||
|
||||
%69 = ivy.lambda %err, %data : (#ivy.id, #ivy.id) -> void {
|
||||
%0 = ivy.msg.send to %StringBuilder, new -> #ivy.id
|
||||
|
||||
ivy.msg.send to %0, append:%key -> void
|
||||
|
||||
%1 = ivy.str.constant "Error "
|
||||
ivy.msg.send to %0, append:%1 -> void
|
||||
|
||||
ivy.msg.send to %0, append:%err -> void
|
||||
|
||||
%2 = ivy.str.constant " occurred ("
|
||||
ivy.msg.send to %0, append:%2 -> void
|
||||
|
||||
ivy.msg.send to %0, append:%data -> void
|
||||
|
||||
%3 = ivy.str.constant ")"
|
||||
|
||||
%4 = ivy.msg.send to %0, to-string -> #ivy.id
|
||||
|
||||
; cout put:'{key} -> {val}'
|
||||
%5 = ptr.load %cout : ptr -> #ivy.id
|
||||
ivy.msg.send to %5, put:%4 -> void
|
||||
}
|
||||
|
||||
%70 = ivy.atom "err:number-format"
|
||||
ivy.msg.send to %67, on:%70 do:%68 -> #ivy.id
|
||||
ivy.msg.send to %67, on-error:%69 -> void
|
||||
ivy.msg.send to %67, call -> void
|
||||
}
|
||||
}
|
||||
@@ -1,146 +1,460 @@
|
||||
record package_scope = str "net.doorstuck.test"
|
||||
meta.source-filename "Person.im"
|
||||
|
||||
record import = { str "std.io" }
|
||||
ivy.package-scope "net.doorstuck.test"
|
||||
|
||||
data @cout = external global id
|
||||
data @StringBuffer = external global id
|
||||
ivy.package-ref "std.io"
|
||||
|
||||
data @.str.0 = str "Received "
|
||||
data @.str.1 = str ", "
|
||||
ivy.module {
|
||||
%cout = ivy.global-ref @cout -> ptr
|
||||
|
||||
data @.atom.0 = atom "years"
|
||||
data @.atom.1 = atom "months"
|
||||
data @.atom.2 = atom "days"
|
||||
ivy.class @Person {
|
||||
%self.name = ivy.object-var @name : #ivy.id -> ptr
|
||||
%self.age = ivy.object-var @age : #ivy.id -> ptr
|
||||
%self.val = ivy.object-var @val : #ivy.id -> ptr
|
||||
%self.__example-property-4 = ivy.object-var @val : #ivy.id -> ptr
|
||||
%self.__example-property-5 = ivy.object-var @val : #ivy.id -> ptr
|
||||
|
||||
type @_ZN3net9doorstuck4testC6PersonE = class {
|
||||
id @name,
|
||||
id @age,
|
||||
id @val
|
||||
}
|
||||
|
||||
define void @_ZN3net9doorstuck4testC6PersonM4init4name3ageE(id %self, id %0) instance {
|
||||
entry:
|
||||
%1 = getelementptr class @_ZN3net9doorstuck4testC6PersonE, id %self, i32 #0
|
||||
store id %0, ptr %1
|
||||
|
||||
%2 = getelementptr class @_ZN33net9doorstuck4testC6PersonE, id %self, i32 #1
|
||||
store id %1, ptr %2
|
||||
|
||||
ret void
|
||||
}
|
||||
|
||||
define void @_ZN3net9doorstuck4testC6PersonM4test5param0E(id %0, id %1) instance {
|
||||
entry:
|
||||
%2 = load id, ptr @cout
|
||||
|
||||
; %4 = StringBuilder new
|
||||
%3 = load id, ptr @StringBuilder
|
||||
%4 = msg id %3, @_M3newE
|
||||
|
||||
; (void) tempstr append:'Received '
|
||||
%5 = load id, ptr @.str.0
|
||||
msg void, id %3, @_M06appendE [id %5]
|
||||
|
||||
; (void) tempstr append:data (param 0)
|
||||
msg void, id %3, @_M06appendE [id %0]
|
||||
|
||||
; (void) tempstr append:', '
|
||||
%6 = load id, ptr @.str.1
|
||||
msg void, id %3, @_M06appendE [id %6]
|
||||
|
||||
; [void] tempstr append:extra (param 1)
|
||||
msg void, id %3, @_M06appendE [id %1]
|
||||
|
||||
; %7 = tempstr toString
|
||||
%7 = msg id, id %3, @_M8toStringE
|
||||
|
||||
; cout put:'Received {data}, {extra}'
|
||||
msg void, id %2, @_M03put [id %7]
|
||||
|
||||
ret void
|
||||
}
|
||||
|
||||
define id @_ZN3net9doorstuck4testC6PersonM4nameE(id %self) instance {
|
||||
entry:
|
||||
%0 = getelementptr class @_ZN33net9doorstuck4testC6PersonE, id %self, i32 #0
|
||||
%1 = load id, ptr %0
|
||||
ret id %1
|
||||
}
|
||||
|
||||
define id @_ZN3net9doorstuck4testC6PersonM3ageE(id %self) instance {
|
||||
entry:
|
||||
%0 = getelementptr class @_ZN33net9doorstuck4testC6PersonE, id %self, i32 #1
|
||||
%1 = load id, ptr %0
|
||||
ret id %1
|
||||
}
|
||||
|
||||
define id @_ZN3net9doorstuck4testC6PersonM11ageInMonthsE(id %self, id %0) instance {
|
||||
entry:
|
||||
%1 = getelementptr class @_ZN33net9doorstuck4testC6PersonE, id %self, i32 #1
|
||||
%2 = load id, ptr %1
|
||||
ret id %1
|
||||
}
|
||||
|
||||
define void @_ZN3net9doorstuck4testC6PersonM07setNameE(id %self, id %1) instance {
|
||||
entry:
|
||||
%2 = getelementptr class @_ZN33net9doorstuck4testC6PersonE, id %self, i32 #1
|
||||
store id %1, ptr %2
|
||||
ret void
|
||||
}
|
||||
|
||||
define void @_ZN3net9doorstuck4testC6PersonM06setAge6inUnitE(id %self, i32 %1, id %2) instance {
|
||||
entry:
|
||||
%3 = load atom, ptr @.atom.0
|
||||
%4 = load atom, ptr @.atom.1
|
||||
%5 = load atom, ptr @.atom.2
|
||||
|
||||
switch id %2, label %default [
|
||||
atom %3, label %years
|
||||
atom %4, label %months
|
||||
atom %5, label %days
|
||||
]
|
||||
|
||||
years:
|
||||
%6 = getelementptr class @_ZN33net9doorstuck4testC6PersonE, id %self, i32 #1
|
||||
store i32 %2, ptr %6
|
||||
br label %end
|
||||
|
||||
months:
|
||||
%7 = getelementptr class @_ZN33net9doorstuck4testC6PersonE, id %self, i32 #1
|
||||
%8 = div i32 %2, #12
|
||||
store i32 %8, ptr %7
|
||||
br label %end
|
||||
|
||||
days:
|
||||
%9 = getelementptr class @_ZN33net9doorstuck4testC6PersonE, id %self, i32 #1
|
||||
%10 = div i32 %2, #365
|
||||
store i32 %10, ptr %9
|
||||
br label %end
|
||||
|
||||
default:
|
||||
%11 = getelementptr class @_ZN33net9doorstuck4testC6PersonE, id %self, i32 #1
|
||||
store i32 #0, ptr %11
|
||||
br label %end
|
||||
|
||||
end:
|
||||
ret void
|
||||
}
|
||||
|
||||
define id @_ZN3net9doorstuck4testC6PersonM012getAgeInUnitE(id %0, id %1) instance {
|
||||
entry:
|
||||
|
||||
}
|
||||
|
||||
define id @_ZN3net9doorstuck4testC6PersonP15examplePropertyG(id %self) instance {
|
||||
entry:
|
||||
%0 = getelementptr class @_ZN33net9doorstuck4testC6PersonE, id %self, i32 #2
|
||||
%1 = load id, ptr %0
|
||||
ret id %1
|
||||
}
|
||||
|
||||
define void @_ZN3net9doorstuck4testC6PersonP15examplePropertyS(id %self, id %0) instance {
|
||||
entry:
|
||||
%1 = getelementptr class @_ZN33net9doorstuck4testC6PersonE, id %self, i32 #2
|
||||
store id %0, ptr %1
|
||||
ret void
|
||||
ivy.msgh.object init(name:%name, age:%age) -> void {
|
||||
ptr.store %name, %self.name : #ivy.id, ptr
|
||||
ptr.store %age, %self.age : #ivy.id, ptr
|
||||
func.return : ()
|
||||
}
|
||||
|
||||
ivy.msgh.object test(param:%data, _:%extra) -> void {
|
||||
%0 = ivy.string-builder.begin
|
||||
|
||||
ivy.string-builder.add %0 << "Received "
|
||||
ivy.string-builder.add %0 << %data : #ivy.id
|
||||
ivy.string-builder.add %0 << ", "
|
||||
ivy.string-builder.add %0 << %extra : #ivy.id
|
||||
|
||||
%1 = ivy.string-builder.end %0 -> #ivy.id
|
||||
|
||||
%2 = ptr.load %cout : ptr -> #ivy.id
|
||||
ivy.msg.send to %2, put:%1 -> void
|
||||
func.return : ()
|
||||
}
|
||||
|
||||
ivy.msgh.object name -> #ivy.id {
|
||||
%0 = ptr.load %self.name : ptr -> #ivy.id
|
||||
func.return %0 : #ivy.id
|
||||
}
|
||||
|
||||
ivy.msgh.object age -> #ivy.id {
|
||||
%0 = ptr.load %self.age : ptr -> #ivy.id
|
||||
func.return %0 : #ivy.id
|
||||
}
|
||||
|
||||
ivy.msgh.object age-in-months -> #ivy.id {
|
||||
%0 = ptr.load %self.age : ptr -> #ivy.id
|
||||
%1 = i32.constant 12
|
||||
%multmp = ivy.mul %0, %1 : (#ivy.id, i32) -> #ivy.id
|
||||
func.return %multmp : #ivy.id
|
||||
}
|
||||
|
||||
ivy.msgh.object set-name:%name -> void {
|
||||
ptr.store %name, %self.name : #ivy.id, ptr
|
||||
func.return : ()
|
||||
}
|
||||
|
||||
ivy.msgh.object set-age:%age -> void {
|
||||
ptr.store %age, %self.age : #ivy.id, ptr
|
||||
func.return : ()
|
||||
}
|
||||
|
||||
ivy.msgh.object set-age:%age in-units:%units -> void {
|
||||
scf.switch : () -> void
|
||||
case {
|
||||
%0 = ivy.atom "years"
|
||||
%cmptmp.0 = ivy.cmp eq %age, %0 : (#ivy.id, #ivy.atom) -> i1
|
||||
scf.switch-condition %cmptmp.0
|
||||
} then {
|
||||
ptr.store %age, %self.age : #ivy.id, ptr
|
||||
scf.switch-break : ()
|
||||
} case {
|
||||
%1 = ivy.atom "months"
|
||||
%cmptmp.1 = ivy.cmp eq %age, %1 : (#ivy.id, #ivy.atom) -> i1
|
||||
scf.condition %cmptmp.1
|
||||
} then {
|
||||
%d0 = i32.constant 12
|
||||
%divtmp.0 = ivy.div %age, %d0 : (#ivy.id, i32) -> #ivy.id
|
||||
ptr.store %divtmp.0, %self.age : #ivy.id, ptr
|
||||
scf.switch-break : ()
|
||||
} case {
|
||||
%2 = ivy.atom "days"
|
||||
%cmptmp.2 = ivy.cmp eq %age, %2 : (#ivy.id, #ivy.atom) -> i1
|
||||
scf.condition %cmptmp.2
|
||||
} then {
|
||||
%d1 = i32.constant 365
|
||||
%divtmp.1 = ivy.div %age, %d1 : (#ivy.id, i32) -> #ivy.id
|
||||
ptr.store %divtmp.1, %self.age : #ivy.id, ptr
|
||||
scf.switch-break : ()
|
||||
} default {
|
||||
%d2 = i32.constant 0
|
||||
scf.switch-break : ()
|
||||
}
|
||||
|
||||
func.return : ()
|
||||
}
|
||||
|
||||
ivy.msgh.object get-age-in-units:%units -> #ivy.id {
|
||||
%result = scf.switch : () -> #ivy.id
|
||||
case {
|
||||
%0 = ivy.atom "years"
|
||||
%cmptmp.0 = ivy.cmp eq %age, %0 : (#ivy.id, #ivy.atom) -> i1
|
||||
scf.switch-condition %cmptmp.0
|
||||
} then {
|
||||
%v0 = ptr.load %self.age : ptr -> #ivy.id
|
||||
scf.switch-break %v0 : #ivy.id
|
||||
} case {
|
||||
%1 = ivy.atom "months"
|
||||
%cmptmp.1 = ivy.cmp eq %age, %1 : (#ivy.id, #ivy.atom) -> i1
|
||||
scf.condition %cmptmp.1
|
||||
} then {
|
||||
%v0 = ptr.load %self.age : ptr -> #ivy.id
|
||||
%d0 = i32.constant 12
|
||||
%divtmp.0 = ivy.div %v0, %d0 : (#ivy.id, i32) -> #ivy.id
|
||||
scf.switch-break %divtmp.0 : #ivy.id
|
||||
} case {
|
||||
%2 = ivy.atom "days"
|
||||
%cmptmp.2 = ivy.cmp eq %age, %2 : (#ivy.id, #ivy.atom) -> i1
|
||||
scf.condition %cmptmp.2
|
||||
} then {
|
||||
%v1 = ptr.load %self.age : ptr -> #ivy.id
|
||||
%d1 = i32.constant 365
|
||||
%divtmp.1 = ivy.div %v1, %d1 : (#ivy.id, i32) -> #ivy.id
|
||||
scf.switch-break %divtmp.1 : #ivy.id
|
||||
} default {
|
||||
%d2 = i32.constant 0
|
||||
scf.switch-break %d2 : #ivy.id
|
||||
}
|
||||
|
||||
func.return %result : #ivy.id
|
||||
}
|
||||
|
||||
ivy.object-prop example-property
|
||||
get {
|
||||
%0 = ptr.load %self.val : ptr -> #ivy.id
|
||||
func.return %0 : #ivy.id
|
||||
}
|
||||
set (%value: #ivy.id) {
|
||||
ptr.store %value, %self.val : #ivy.id, ptr
|
||||
func.return : ()
|
||||
}
|
||||
|
||||
ivy.object-prop example-property-2 get {
|
||||
%0 = ptr.load %self.val : ptr -> #ivy.id
|
||||
func.return %0 : #ivy.id
|
||||
} set (%x: #ivy.id) {
|
||||
ptr.store %x, %self.val : #ivy.id, ptr
|
||||
func.return : ()
|
||||
}
|
||||
|
||||
ivy.object-prop example-property-3 get {
|
||||
%0 = i32.constant 42
|
||||
func.return %0 : i32
|
||||
}
|
||||
|
||||
ivy.object-prop example-property-4 get {
|
||||
%0 = ptr.load %self.__example-property-4 : ptr -> #ivy.id
|
||||
func.return %0 : #ivy.id
|
||||
} set (%0: #ivy.id) {
|
||||
ptr.store %0, %self.__example-property-4 : #ivy.id, ptr
|
||||
func.return : ()
|
||||
}
|
||||
|
||||
ivy.object-prop example-property-5 get {
|
||||
%0 = ptr.load %self.__example-property-5 : ptr -> #ivy.id
|
||||
func.return %0 : #ivy.id
|
||||
}
|
||||
}
|
||||
|
||||
ivy.init-text {
|
||||
; p1 = Person new(name:'John Doe', age:34).
|
||||
%Person = ivy.global-ref @Person : ptr
|
||||
%0 = ivy.str.constant "John Doe"
|
||||
%1 = i32.constant 34
|
||||
|
||||
%2 = ivy.msg.send to %Person, new(name:%0, age:%1) -> #ivy.id
|
||||
|
||||
%p1 = ptr.alloca #ivy.id -> ptr
|
||||
ptr.store %2, %p1 : #ivy.id, ptr
|
||||
|
||||
; p1 set-age:100 in-unit:$months.
|
||||
%3 = ptr.load %p1 : ptr -> #ivy.id
|
||||
%4 = i32.constant 100
|
||||
%5 = ivy.atom "months"
|
||||
ivy.msg.send to %3, set-age:%4 in-units:%5 -> void
|
||||
|
||||
; p1 test(param:'Hello', 'World').
|
||||
%6 = ptr.load %p1 : ptr -> #ivy.id
|
||||
%7 = ivy.str.constant "Hello"
|
||||
%8 = ivy.str.constant "World"
|
||||
ivy.msg.send to %6, test(param:%7, _:%8) -> void
|
||||
|
||||
; i = 0.
|
||||
%i = ptr.alloca i32 -> ptr
|
||||
%9 = i32.constant 0
|
||||
ptr.store %9, %i : i32, ptr
|
||||
|
||||
; while i < 100 do
|
||||
scf.while -> void {
|
||||
; i < 100
|
||||
%10 = ptr.load %i : ptr -> i32
|
||||
%11 = i32.constant 100
|
||||
%cmptmp = ivy.cmp lt %10, %11 : (i32, i32) -> i1
|
||||
scf.condition(%cmptmp)
|
||||
} do {
|
||||
; cout put:'Count is {i}'.
|
||||
%12 = ivy.string-builder.begin
|
||||
|
||||
ivy.string-builder.add %12 << "Count is "
|
||||
|
||||
%14 = ptr.load %i : ptr -> i32
|
||||
ivy.string-builder.add %12 << %14 : i32
|
||||
|
||||
%15 = ivy.string-builder.end %12 -> #ivy.id
|
||||
|
||||
%16 = ptr.load %cout : ptr -> #ivy.id
|
||||
ivy.msg.send to %16, put:%15 -> void
|
||||
|
||||
; i += 2
|
||||
%17 = ptr.load %i : ptr -> i32
|
||||
%18 = i32.constant 2
|
||||
%addtmp = ivy.add %17, %18 : (i32, i32) -> i32
|
||||
ptr.store %addtmp, %i : i32, ptr
|
||||
}
|
||||
|
||||
; 0 to:100 step:2
|
||||
%19 = i32.constant 0
|
||||
%20 = i32.constant 100
|
||||
%21 = i32.constant 2
|
||||
%22 = ivy.msg.send to %19, to:%20 step:%21 -> #ivy.id
|
||||
|
||||
; for x in 0 to:100 step:2 do
|
||||
ivy.for %x in %22 -> void {
|
||||
%23 = ivy.string-builder.begin
|
||||
|
||||
; 'Count is {x}'
|
||||
ivy.string-builder.add %23 << "Count is "
|
||||
ivy.string-builder.add %23 << %x : #ivy.id
|
||||
|
||||
%25 = ivy.string-builder.end %23 -> #ivy.id
|
||||
|
||||
; cout put:"Count is {x}"
|
||||
%26 = ptr.load %cout : ptr -> #ivy.id
|
||||
ivy.msg.send to %26, put:%25 -> void
|
||||
}
|
||||
|
||||
; 0 to:100 step:2 do:...
|
||||
%27 = i32.constant 0
|
||||
%28 = i32.constant 100
|
||||
%29 = i32.constant 2
|
||||
; [ :i | cout put:'Count: {i}' ]
|
||||
%30 = ivy.lambda %i : (#ivy.id) -> void {
|
||||
%0 = ivy.string-builder.begin
|
||||
|
||||
ivy.string-builder.add %0 << "Count is "
|
||||
ivy.string-builder.add %0 << %i : #ivy.id
|
||||
|
||||
%2 = ivy.string-builder.end %0 -> #ivy.id
|
||||
|
||||
%cout = ivy.global-ref @cout -> ptr
|
||||
%3 = ptr.load %cout : ptr -> #ivy.id
|
||||
ivy.msg.send to %3, put:%2 -> void
|
||||
}
|
||||
|
||||
; 0 to:100 step:2 do:[ :i | cout put:'Count: {i}' ].
|
||||
ivy.msg.send to %27, to:%28 step:%29 do:%30
|
||||
|
||||
; q = 32.
|
||||
%q = ptr.alloca i32 -> ptr
|
||||
%31 = i32.constant 32
|
||||
ptr.store %31, %q : i32, ptr
|
||||
|
||||
; l = [ cout put:'Value of q is {q}' ].
|
||||
%l = ptr.alloca #ivy.id
|
||||
%32 = ptr.load %q : ptr -> i32
|
||||
%33 = ivy.lambda (%env.q = %32) : () -> void {
|
||||
%0 = ivy.string-builder.begin
|
||||
|
||||
ivy.string-builder.add %0 << "Value of q is "
|
||||
ivy.string-builder.add %0 << %env.q : #ivy.id
|
||||
|
||||
%2 = ivy.string-builder.end %0 -> #ivy.id
|
||||
|
||||
%cout = ivy.global-ref @cout -> ptr
|
||||
%3 = ptr.load %cout : ptr -> #ivy.id
|
||||
ivy.msg.send to %3, put:%2 -> void
|
||||
}
|
||||
|
||||
ptr.store %33, %l : #ivy.id, ptr
|
||||
|
||||
; q = 64.
|
||||
%34 = i32.constant 64
|
||||
ptr.store %34, %q : i32, ptr
|
||||
|
||||
; l call.
|
||||
%35 = ptr.load %l : ptr -> #ivy.id
|
||||
ivy.msg.send to %35, call -> void
|
||||
|
||||
%j = ptr.alloca i32 -> ptr
|
||||
|
||||
%36 = i32.constant 32
|
||||
ptr.store %36, %j : i32, ptr
|
||||
|
||||
%37 = ptr.load %i : ptr -> i32
|
||||
%38 = ptr.load %j : ptr -> i32
|
||||
|
||||
%cmptmp = arith.cmp lt %37, %38 : (i32, i32) -> i1
|
||||
|
||||
%39 = ivy.lambda : () -> void {
|
||||
%cout = ivy.global-ref @cout -> ptr
|
||||
%0 = ivy.str.constant "True!"
|
||||
%1 = ptr.load %cout : ptr -> #ivy.id
|
||||
ivy.msg.send to %1, put:%0 -> void
|
||||
}
|
||||
|
||||
%40 = ivy.lambda : () -> void {
|
||||
%cout = ivy.global-ref @cout -> ptr
|
||||
%0 = ivy.str.constant "False!"
|
||||
%1 = ptr.load %cout : ptr -> #ivy.id
|
||||
ivy.msg.send to %1, put:%0 -> void
|
||||
}
|
||||
|
||||
ivy.msg.send to %cmptmp, if:%39 else:%40 -> void
|
||||
|
||||
%41 = ptr.load %i : ptr -> i32
|
||||
%42 = ptr.load %j : ptr -> i32
|
||||
|
||||
%cmptmp.0 = arith.cmp lt %41, %42 : (i32, i32) -> i1
|
||||
|
||||
scf.if %cmptmp.0 -> void {
|
||||
%43 = ivy.str.constant "True!"
|
||||
%44 = ptr.load %cout : ptr -> #ivy.id
|
||||
ivy.msg.send to %44, put:%43 -> void
|
||||
}
|
||||
|
||||
; pkg = {}.
|
||||
%pkg = ptr.alloca #ivy.id -> ptr
|
||||
|
||||
%Package = ivy.global-ref @std.lang.Package -> ptr
|
||||
|
||||
%45 = ivy.msg.send to %Package, new -> #ivy.id
|
||||
ptr.store %45, %pkg : #ivy.id, ptr
|
||||
|
||||
; pkg[0] = 16.
|
||||
%46 = ptr.load %pkg : ptr -> #ivy.id
|
||||
%47 = i32.constant 0
|
||||
%48 = i32.constant 16
|
||||
|
||||
ivy.msg.send to %46, at:%47 put:%48 -> void
|
||||
|
||||
; tuple = (32, 'a string')
|
||||
%tuple = ptr.alloca #ivy.id -> ptr
|
||||
|
||||
%49 = i32.constant 32
|
||||
%50 = ivy.str.constant "a string"
|
||||
|
||||
%51 = ivy.tuple.create %49, %50 : (i32, #ivy.id) -> #ivy.id
|
||||
|
||||
ptr.store %51, %tuple : #ivy.id, ptr
|
||||
|
||||
%52 = ptr.load %tuple : ptr -> #ivy.id
|
||||
%53 = ivy.msg.send to %52, get-iterator -> #ivy.id
|
||||
|
||||
ivy.for %54 in %53 -> void {
|
||||
%key = ivy.tuple.get-item %54[0] : (#ivy.id, i32) -> #ivy.id
|
||||
%val = ivy.tuple.get-item %54[1] : (#ivy.id, i32) -> #ivy.id
|
||||
|
||||
; '{key} -> {val}'
|
||||
%55 = ivy.string-builder.begin
|
||||
|
||||
ivy.string-builder.add %55 << %key : #ivy.id
|
||||
ivy.string-builder.add %55 << " -> "
|
||||
ivy.string-builder.add %55 << %val : #ivy.id
|
||||
|
||||
%57 = ivy.string-builder.end %55 -> #ivy.id
|
||||
|
||||
; cout put:'{key} -> {val}'
|
||||
%58 = ptr.load %cout : ptr -> #ivy.id
|
||||
ivy.msg.send to %58, put:%57 -> void
|
||||
}
|
||||
|
||||
; _ = 3 * 2.
|
||||
%59 = i32.constant 3
|
||||
%60 = i32.constant 2
|
||||
%multmp = arith.mul %59, %60 : (i32, i32) -> i32
|
||||
|
||||
; a = (32, 64).
|
||||
%a = ptr.alloca #ivy.id -> ptr
|
||||
|
||||
%61 = i32.constant 32
|
||||
%62 = i32.constant 64
|
||||
%63 = ivy.tuple.create %61, %62 : (i32, i32) -> #ivy.id
|
||||
|
||||
ptr.store %63, %a : #ivy.id, ptr
|
||||
|
||||
%v = ptr.alloca #ivy.id -> ptr
|
||||
|
||||
%64 = ptr.load %a : ptr -> #ivy.id
|
||||
%65 = ivy.tuple.get-item %64[1] : #ivy.id -> #ivy.id
|
||||
|
||||
ptr.store %65, %v : #ivy.id, ptr
|
||||
|
||||
%66 = ivy.atom "err:number-format"
|
||||
|
||||
ivy.try -> void {
|
||||
|
||||
} catch (%ex = %66), %data {
|
||||
|
||||
} catch-all %ex, %data {
|
||||
|
||||
}
|
||||
|
||||
%67 = ivy.lambda : () -> void {
|
||||
%v = ptr.alloca #ivy.id -> ptr
|
||||
%Int = ivy.global-ref @Int -> ptr
|
||||
%0 = ivy.str.constant "342"
|
||||
|
||||
%1 = ivy.msg.send to %Int, parse:%0
|
||||
|
||||
ptr.store %1, %v : #ivy.id, ptr
|
||||
}
|
||||
|
||||
%68 = ivy.lambda %err, %data : (#ivy.id, #ivy.id) -> void {
|
||||
%0 = ivy.string-builder.begin
|
||||
|
||||
ivy.string-builder.add %0 << "Cannot parse integer string ("
|
||||
ivy.string-builder.add %0 << %err : #ivy.id
|
||||
ivy.string-builder.add %0 << ")"
|
||||
|
||||
%3 = ivy.string-builder.end %0 -> #ivy.id
|
||||
|
||||
; cout put:'{key} -> {val}'
|
||||
%4 = ptr.load %cout : ptr -> #ivy.id
|
||||
ivy.msg.send to %4, put:%3 -> void
|
||||
}
|
||||
|
||||
%69 = ivy.lambda %err, %data : (#ivy.id, #ivy.id) -> void {
|
||||
%0 = ivy.string-builder.create
|
||||
|
||||
ivy.string-builder.add %0 << "Error "
|
||||
ivy.string-builder.add %0 << %err : #ivy.id
|
||||
ivy.string-builder.add %0 << " occurred ("
|
||||
ivy.string-builder.add %0 << %data : #ivy.id
|
||||
ivy.string-builder.add %0 << ")"
|
||||
|
||||
%4 = ivy.string-builder.end %0 -> #ivy.id
|
||||
|
||||
; cout put:'{key} -> {val}'
|
||||
%5 = ptr.load %cout : ptr -> #ivy.id
|
||||
ivy.msg.send to %5, put:%4 -> void
|
||||
}
|
||||
|
||||
%70 = ivy.atom "err:number-format"
|
||||
ivy.msg.send to %67, on:%70 do:%68 -> #ivy.id
|
||||
ivy.msg.send to %67, on-error:%69 -> void
|
||||
ivy.msg.send to %67, call -> void
|
||||
}
|
||||
}
|
||||
|
||||
46
doc/mie/sample/Simple.1.mie
Normal file
46
doc/mie/sample/Simple.1.mie
Normal file
@@ -0,0 +1,46 @@
|
||||
meta.source-filename "Simple.im"
|
||||
|
||||
ivy.package-scope "net.doorstuck.test"
|
||||
|
||||
ivy.package-ref "std.io"
|
||||
|
||||
ivy.module {
|
||||
ivy.init-text {
|
||||
%0 = i32.constant 32
|
||||
%1 = i32.constant 64
|
||||
%multmp = arith.mul %0, %1 : (i32, i32) -> i32
|
||||
|
||||
%y = ptr.alloca i32
|
||||
ptr.store %multmp, %y : i32, ptr
|
||||
|
||||
%2 = i32.constant 64
|
||||
%3 = i32.constant 4
|
||||
%divtmp = arith.div %2, %3 : (i32, i32) -> i32
|
||||
|
||||
%z = ptr.alloca i32
|
||||
ptr.store %divtmp, %z : i32, ptr
|
||||
|
||||
%4 = ptr.load %y : ptr -> i32
|
||||
%5 = ptr.load %z : ptr -> i32
|
||||
%addtmp = arith.add %4, %5 : (i32, i32) -> i32
|
||||
|
||||
%x = ptr.alloca i32
|
||||
ptr.store %addtmp, %x : i32, ptr
|
||||
|
||||
%cout = ivy.global-ref @cout -> ptr
|
||||
|
||||
%6 = ivy.string-builder.begin
|
||||
ivy.string-builder.add %6 << "Answer: "
|
||||
|
||||
%7 = ptr.load %x : ptr -> i32
|
||||
ivy.string-builder.add %6 << %7 : i32
|
||||
|
||||
%8 = ivy.string-builder.end %6 -> #ivy.id
|
||||
|
||||
%9 = ptr.load %cout : ptr -> #ivy.id
|
||||
|
||||
ivy.msg.send to %9, put:%8 -> void
|
||||
|
||||
func.return : ()
|
||||
}
|
||||
}
|
||||
50
doc/mie/sample/Simple.2.mie
Normal file
50
doc/mie/sample/Simple.2.mie
Normal file
@@ -0,0 +1,50 @@
|
||||
meta.source-filename "Simple.im"
|
||||
|
||||
ivy.package-scope "net.doorstuck.test"
|
||||
|
||||
ivy.package-ref "std.io"
|
||||
|
||||
ivy.module {
|
||||
%cout = ivy.global-ref @cout -> ptr
|
||||
%StringBuilder = ivy.global-ref @std.lang.StringBuilder -> ptr
|
||||
|
||||
%.str.0 = ivy.str.constant "Answer: "
|
||||
|
||||
ivy.init-text {
|
||||
%0 = i32.constant 32
|
||||
%1 = i32.constant 64
|
||||
%multmp = arith.mul %0, %1 : (i32, i32) -> i32
|
||||
|
||||
%y = ptr.alloca i32
|
||||
ptr.store %multmp, %y : i32, ptr
|
||||
|
||||
%2 = i32.constant 64
|
||||
%3 = i32.constant 4
|
||||
%divtmp = arith.div %2, %3 : (i32, i32) -> i32
|
||||
|
||||
%z = ptr.alloca i32
|
||||
ptr.store %divtmp, %z : i32, ptr
|
||||
|
||||
%4 = ptr.load %y : ptr -> i32
|
||||
%5 = ptr.load %z : ptr -> i32
|
||||
%addtmp = arith.add %4, %5 : (i32, i32) -> i32
|
||||
|
||||
%x = ptr.alloca i32
|
||||
ptr.store %addtmp, %x : i32, ptr
|
||||
|
||||
%10 = ptr.load %StringBuilder : ptr -> #ivy.id
|
||||
|
||||
ivy.msg.send to %10, append:%.str.0 -> void
|
||||
|
||||
%7 = ptr.load %x : ptr -> i32
|
||||
ivy.msg.send to %10, append:%7 -> void
|
||||
|
||||
%8 = ivy.msg.send to %10, to-string -> #ivy.id
|
||||
|
||||
%9 = ptr.load %cout : ptr -> #ivy.id
|
||||
|
||||
ivy.msg.send to %9, put:%8 -> void
|
||||
|
||||
func.return : ()
|
||||
}
|
||||
}
|
||||
63
doc/mie/sample/Simple.3.mie
Normal file
63
doc/mie/sample/Simple.3.mie
Normal file
@@ -0,0 +1,63 @@
|
||||
meta.source-filename "Simple.im"
|
||||
|
||||
ivy.package-scope "net.doorstuck.test"
|
||||
|
||||
ivy.package-ref "std.io"
|
||||
|
||||
ivy.module {
|
||||
%cout = ivy.pool.ident @cout -> #ivy.pool-slot
|
||||
%StringBuilder = ivy.pool.ident @std.lang.StringBuilder -> #ivy.pool-slot
|
||||
|
||||
%.str.0 = ivy.pool.string "Answer: " -> #ivy.pool-slot
|
||||
|
||||
%.sel.o-append = ivy.pool.selector append -> #ivy.pool-slot
|
||||
%.sel.o-to-string = ivy.pool.selector to-string -> #ivy.pool-slot
|
||||
%.sel.o-put = ivy.pool.selector put -> #ivy.pool-slot
|
||||
|
||||
ivy.init-text {
|
||||
%0 = i32.constant 32
|
||||
%1 = i32.constant 64
|
||||
%multmp = *ivy.MUL %0, %1 : (i32, i32) -> i32
|
||||
|
||||
*ivy.PUSH %multmp : i32
|
||||
%y = ivy.bp-slot 0 -> #ivy.bp-slot
|
||||
|
||||
%2 = i32.constant 64
|
||||
%3 = i32.constant 4
|
||||
%divtmp = *ivy.DIV %2, %3 : (i32, i32) -> i32
|
||||
|
||||
*ivy.PUSH %divtmp : i32
|
||||
%z = ivy.bp-slot 1 -> #ivy.bp-slot
|
||||
|
||||
%4 = *ivy.LDR-BP %y : #ivy.bp-slot -> i32
|
||||
%5 = *ivy.LDR-BP %z : #ivy.bp-slot -> i32
|
||||
%addtmp = *ivy.ADD %4, %5 : (i32, i32) -> i32
|
||||
|
||||
*ivy.PUSH %addtmp : i32
|
||||
%x = ivy.bp-slot 2 -> #ivy.bp-slot
|
||||
|
||||
%10 = *ivy.LDR-POOL %StringBuilder : #ivy.pool-slot -> #ivy.id
|
||||
|
||||
%20 = *ivy.LDR-POOL %.sel.o-append : #ivy.pool-slot -> #ivy.id
|
||||
%21 = *ivy.LDR-POOL %.str.0 : #ivy.pool-slot -> #ivy.id
|
||||
*ivy.PUSH %21 : #ivy.id
|
||||
*ivy.MSG-I %10, %20, 1 : (#ivy.id, #ivy.id, i32) -> void
|
||||
|
||||
%7 = *ivy.LDR-BP %x : ptr -> i32
|
||||
*ivy.PUSH %7 : i32
|
||||
%22 = *ivy.LDR-POOL %.sel.o-append : #ivy.pool-slot -> #ivy.id
|
||||
*ivy.MSG-I %10, %22, 1 : (#ivy.id, #ivy.id, i32) -> void
|
||||
|
||||
%23 = *ivy.LDR-POOL %.sel.o-to-string : #ivy.pool-slot -> #ivy.id
|
||||
%8 = *ivy.MSG-I %10, %23, 0 : (#ivy.id, #ivy.id, i32) -> #ivy.id
|
||||
|
||||
%9 = *ivy.LDR-POOL %cout : #ivy.pool-slot -> #ivy.id
|
||||
%24 = *ivy.LDR-POOL %.sel.o-put : #ivy.pool-slot -> #ivy.id
|
||||
|
||||
*ivy.PUSH %8 : #ivy.id
|
||||
|
||||
*ivy.MSG-I %9, %24, 1 : (#ivy.id, #ivy.id, i32) -> void
|
||||
|
||||
*ivy.RET-N : ()
|
||||
}
|
||||
}
|
||||
62
doc/mie/sample/Simple.4.mie
Normal file
62
doc/mie/sample/Simple.4.mie
Normal file
@@ -0,0 +1,62 @@
|
||||
meta.source-filename "Simple.im"
|
||||
|
||||
ivy.package-scope "net.doorstuck.test"
|
||||
|
||||
ivy.package-ref "std.io"
|
||||
|
||||
ivy.module {
|
||||
%cout = ivy.pool.ident @cout -> #ivy.pool-slot
|
||||
%StringBuilder = ivy.pool.ident @std.lang.StringBuilder -> #ivy.pool-slot
|
||||
|
||||
%.str.0 = ivy.pool.string "Answer: " -> #ivy.pool-slot
|
||||
|
||||
%.sel.o-append = ivy.pool.selector append -> #ivy.pool-slot
|
||||
%.sel.o-to-string = ivy.pool.selector to-string -> #ivy.pool-slot
|
||||
%.sel.o-put = ivy.pool.selector put -> #ivy.pool-slot
|
||||
|
||||
ivy.init-text {
|
||||
%0 = i32.constant 32
|
||||
%1 = i32.constant 64
|
||||
%multmp = *ivy.MUL %0, %1 : (i32, i32) -> i32
|
||||
|
||||
*ivy.PUSH %multmp : i32
|
||||
%y = ivy.bp-slot 0 -> #ivy.bp-slot
|
||||
|
||||
%2 = i32.constant 64
|
||||
%3 = i32.constant 4
|
||||
%divtmp = *ivy.DIV %2, %3 : (i32, i32) -> i32
|
||||
|
||||
*ivy.PUSH %divtmp : i32
|
||||
%z = ivy.bp-slot 1 -> #ivy.bp-slot
|
||||
|
||||
%4 = *ivy.LDR %y : #ivy.bp-slot -> i32
|
||||
%5 = *ivy.LDR %z : #ivy.bp-slot -> i32
|
||||
%addtmp = *ivy.ADD %4, %5 : (i32, i32) -> i32
|
||||
|
||||
*ivy.PUSH %addtmp : i32
|
||||
%x = ivy.bp-slot 2 -> #ivy.bp-slot
|
||||
|
||||
%10 = *ivy.LDR %StringBuilder : #ivy.pool-slot -> #ivy.id
|
||||
|
||||
%20 = *ivy.LDR %.sel.o-append : #ivy.pool-slot -> #ivy.id
|
||||
%21 = *ivy.LDR %.str.0 : #ivy.pool-slot -> #ivy.id
|
||||
*ivy.PUSH %21 : #ivy.id
|
||||
*ivy.MSG %10, %20, 1 : (#ivy.id, #ivy.id, i32) -> void
|
||||
|
||||
%7 = *ivy.LDR %x : ptr -> i32
|
||||
*ivy.PUSH %7 : i32
|
||||
*ivy.MSG %10, %20, 1 : (#ivy.id, #ivy.id, i32) -> void
|
||||
|
||||
%23 = *ivy.LDR %.sel.o-to-string : #ivy.pool-slot -> #ivy.id
|
||||
%8 = *ivy.MSG %10, %23, 0 : (#ivy.id, #ivy.id, i32) -> #ivy.id
|
||||
|
||||
%9 = *ivy.LDR %cout : #ivy.pool-slot -> #ivy.id
|
||||
%24 = *ivy.LDR %.sel.o-put : #ivy.pool-slot -> #ivy.id
|
||||
|
||||
*ivy.PUSH %8 : #ivy.id
|
||||
|
||||
*ivy.MSG %9, %24, 1 : (#ivy.id, #ivy.id, i32) -> void
|
||||
|
||||
*ivy.RET-N : ()
|
||||
}
|
||||
}
|
||||
68
doc/mie/sample/Simple.5.mie
Normal file
68
doc/mie/sample/Simple.5.mie
Normal file
@@ -0,0 +1,68 @@
|
||||
meta.source-filename "Simple.im"
|
||||
|
||||
ivy.package-scope "net.doorstuck.test"
|
||||
|
||||
ivy.package-ref "std.io"
|
||||
|
||||
ivy.module {
|
||||
%cout = ivy.pool.ident @cout -> #ivy.pool-slot
|
||||
%StringBuilder = ivy.pool.ident @std.lang.StringBuilder -> #ivy.pool-slot
|
||||
|
||||
%.str.0 = ivy.pool.string "Answer: " -> #ivy.pool-slot
|
||||
|
||||
%.sel.o-append = ivy.pool.selector append -> #ivy.pool-slot
|
||||
%.sel.o-to-string = ivy.pool.selector to-string -> #ivy.pool-slot
|
||||
%.sel.o-put = ivy.pool.selector put -> #ivy.pool-slot
|
||||
|
||||
%.i.0 = i32.constant 0
|
||||
%.i.1 = i32.constant 1
|
||||
%.i.4 = i32.constant 4
|
||||
%.i.32 = i32.constant 32
|
||||
%.i.64 = i32.constant 64
|
||||
|
||||
ivy.init-text {
|
||||
$X0 = *ivy.LDR %.i.32 -> i32
|
||||
$X1 = *ivy.LDR %.i.64 -> i32
|
||||
$X2 = *ivy.MUL $X0, $X1 : (i32, i32) -> i32
|
||||
|
||||
*ivy.PUSH $X2 : i32
|
||||
%.bp.0 = ivy.bp-slot 0 -> #ivy.bp-slot
|
||||
|
||||
$X4 = *ivy.LDR %.i.64 -> i32
|
||||
$X5 = *ivy.LDR %.i.4 -> i32
|
||||
$X6 = *ivy.DIV $X4, $X5 : (i32, i32) -> i32
|
||||
|
||||
*ivy.PUSH $X6 : i32
|
||||
%.bp.1 = ivy.bp-slot 1 -> #ivy.bp-slot
|
||||
|
||||
$X8 = *ivy.LDR %.bp.0 : #ivy.bp-slot -> i32
|
||||
$X9 = *ivy.LDR %.bp.1 : #ivy.bp-slot -> i32
|
||||
$X10 = *ivy.ADD $X8, $X9 : (i32, i32) -> i32
|
||||
|
||||
*ivy.PUSH $X10 : i32
|
||||
%.bp.2 = ivy.bp-slot 2 -> #ivy.bp-slot
|
||||
|
||||
%10 = *ivy.LDR %StringBuilder : #ivy.pool-slot -> #ivy.id
|
||||
|
||||
%20 = *ivy.LDR %.sel.o-append : #ivy.pool-slot -> #ivy.id
|
||||
%21 = *ivy.LDR %.str.0 : #ivy.pool-slot -> #ivy.id
|
||||
*ivy.PUSH %21 : #ivy.id
|
||||
*ivy.MSG %10, %20, %.i.1 : (#ivy.id, #ivy.id, i32) -> void
|
||||
|
||||
%7 = *ivy.LDR %.bp.2 : ptr -> i32
|
||||
*ivy.PUSH %7 : i32
|
||||
*ivy.MSG %10, %20, %.i.1 : (#ivy.id, #ivy.id, i32) -> void
|
||||
|
||||
%23 = *ivy.LDR %.sel.o-to-string : #ivy.pool-slot -> #ivy.id
|
||||
%8 = *ivy.MSG %10, %23, %.i.0 : (#ivy.id, #ivy.id, i32) -> #ivy.id
|
||||
|
||||
%9 = *ivy.LDR %cout : #ivy.pool-slot -> #ivy.id
|
||||
%24 = *ivy.LDR %.sel.o-put : #ivy.pool-slot -> #ivy.id
|
||||
|
||||
*ivy.PUSH %8 : #ivy.id
|
||||
|
||||
*ivy.MSG %9, %24, %.i.1 : (#ivy.id, #ivy.id, i32) -> void
|
||||
|
||||
*ivy.RET-N : ()
|
||||
}
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
data @cout = external global id
|
||||
|
||||
data @.str.0 = str "less"
|
||||
data @.str.1 = str "more"
|
||||
data @.str.2 = str "equal"
|
||||
|
||||
define void @init(id %self, id %0) static {
|
||||
entry:
|
||||
%x = alloca id
|
||||
store i32 #2, ptr %x
|
||||
|
||||
%y = alloca id
|
||||
store i32 #3, ptr %y
|
||||
|
||||
%1 = load i32, ptr %x
|
||||
%2 = load i32, ptr %y
|
||||
%3 = cmp lt i32 %1, %2
|
||||
br i1 %3, label %if.true, label %if.false
|
||||
|
||||
if.true:
|
||||
%4 = load id, ptr @cout
|
||||
%5 = load str, ptr @.str.0
|
||||
msg void, id %4, @_M03putE [str %5]
|
||||
br label %if.end
|
||||
|
||||
if.false:
|
||||
%6 = load i32, ptr %x
|
||||
%7 = load i32, ptr %y
|
||||
%8 = cmp gt i32 %6, %7
|
||||
br i1 %8, label %if.true.0, label %if.false.0
|
||||
|
||||
if.true.0:
|
||||
%9 = load id, ptr @cout
|
||||
%10 = load str, ptr @.str.1
|
||||
msg void, id %9, @_M03putE [str %10]
|
||||
br label %if.end
|
||||
|
||||
if.false.0:
|
||||
%11 = load id, ptr @cout
|
||||
%12 = load str, ptr @.str.2
|
||||
msg void, id %11, @_M03putE [str %12]
|
||||
br label %if.end
|
||||
|
||||
if.end:
|
||||
ret void
|
||||
}
|
||||
Reference in New Issue
Block a user