doc: update ir sample files

This commit is contained in:
2026-01-19 13:59:43 +00:00
parent 4700ce7778
commit abf43a9022
2 changed files with 144 additions and 124 deletions

View File

@@ -8,15 +8,15 @@ ivy.module {
%cout = ivy.global-ref @cout -> ptr %cout = ivy.global-ref @cout -> ptr
ivy.class @Person { ivy.class @Person {
%self.name = ivy.object-var @name : #ivy.id -> ptr %self.name = ivy.object-var @name : !ivy.id -> ptr
%self.age = ivy.object-var @age : #ivy.id -> ptr %self.age = ivy.object-var @age : !ivy.id -> ptr
%self.val = ivy.object-var @val : #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-4 = ivy.object-var @val : !ivy.id -> ptr
%self.__example-property-5 = ivy.object-var @val : #ivy.id -> ptr %self.__example-property-5 = ivy.object-var @val : !ivy.id -> ptr
ivy.msgh.object init(name:%name, age:%age) -> void { ivy.msgh.object init(name:%name, age:%age) -> void {
ptr.store %name, %self.name : #ivy.id, ptr ptr.store %name, %self.name : !ivy.id, ptr
ptr.store %age, %self.age : #ivy.id, ptr ptr.store %age, %self.age : !ivy.id, ptr
func.return : () func.return : ()
} }
@@ -24,41 +24,41 @@ ivy.module {
%0 = ivy.string-builder.begin %0 = ivy.string-builder.begin
ivy.string-builder.add %0 << "Received " ivy.string-builder.add %0 << "Received "
ivy.string-builder.add %0 << %data : #ivy.id ivy.string-builder.add %0 << %data : !ivy.id
ivy.string-builder.add %0 << ", " ivy.string-builder.add %0 << ", "
ivy.string-builder.add %0 << %extra : #ivy.id ivy.string-builder.add %0 << %extra : !ivy.id
%1 = ivy.string-builder.end %0 -> #ivy.id %1 = ivy.string-builder.end %0 -> !ivy.id
%2 = ptr.load %cout : ptr -> #ivy.id %2 = ptr.load %cout : ptr -> !ivy.id
ivy.msg.send to %2, put:%1 -> void ivy.msg.send to %2, put:%1 -> void
func.return : () func.return : ()
} }
ivy.msgh.object name -> #ivy.id { ivy.msgh.object name -> !ivy.id {
%0 = ptr.load %self.name : ptr -> #ivy.id %0 = ptr.load %self.name : ptr -> !ivy.id
func.return %0 : #ivy.id func.return %0 : !ivy.id
} }
ivy.msgh.object age -> #ivy.id { ivy.msgh.object age -> !ivy.id {
%0 = ptr.load %self.age : ptr -> #ivy.id %0 = ptr.load %self.age : ptr -> !ivy.id
func.return %0 : #ivy.id func.return %0 : !ivy.id
} }
ivy.msgh.object age-in-months -> #ivy.id { ivy.msgh.object age-in-months -> !ivy.id {
%0 = ptr.load %self.age : ptr -> #ivy.id %0 = ptr.load %self.age : ptr -> !ivy.id
%1 = arith.constant 12 : i32 %1 = arith.constant 12 : i32
%multmp = ivy.mul %0, %1 : (#ivy.id, i32) -> #ivy.id %multmp = ivy.mul %0, %1 : (!ivy.id, i32) -> !ivy.id
func.return %multmp : #ivy.id func.return %multmp : !ivy.id
} }
ivy.msgh.object set-name:%name -> void { ivy.msgh.object set-name:%name -> void {
ptr.store %name, %self.name : #ivy.id, ptr ptr.store %name, %self.name : !ivy.id, ptr
func.return : () func.return : ()
} }
ivy.msgh.object set-age:%age -> void { ivy.msgh.object set-age:%age -> void {
ptr.store %age, %self.age : #ivy.id, ptr ptr.store %age, %self.age : !ivy.id, ptr
func.return : () func.return : ()
} }
@@ -66,28 +66,28 @@ ivy.module {
scf.switch : () -> void scf.switch : () -> void
case { case {
%0 = ivy.atom "years" %0 = ivy.atom "years"
%cmptmp.0 = ivy.cmp eq %age, %0 : (#ivy.id, #ivy.atom) -> i1 %cmptmp.0 = ivy.cmp eq %age, %0 : (!ivy.id, !ivy.atom) -> i1
scf.switch-condition %cmptmp.0 scf.switch-condition %cmptmp.0
} then { } then {
ptr.store %age, %self.age : #ivy.id, ptr ptr.store %age, %self.age : !ivy.id, ptr
scf.switch-break : () scf.switch-break : ()
} case { } case {
%1 = ivy.atom "months" %1 = ivy.atom "months"
%cmptmp.1 = ivy.cmp eq %age, %1 : (#ivy.id, #ivy.atom) -> i1 %cmptmp.1 = ivy.cmp eq %age, %1 : (!ivy.id, !ivy.atom) -> i1
scf.condition %cmptmp.1 scf.condition %cmptmp.1
} then { } then {
%d0 = arith.constant 12 : i32 %d0 = arith.constant 12 : i32
%divtmp.0 = ivy.div %age, %d0 : (#ivy.id, i32) -> #ivy.id %divtmp.0 = ivy.div %age, %d0 : (!ivy.id, i32) -> !ivy.id
ptr.store %divtmp.0, %self.age : #ivy.id, ptr ptr.store %divtmp.0, %self.age : !ivy.id, ptr
scf.switch-break : () scf.switch-break : ()
} case { } case {
%2 = ivy.atom "days" %2 = ivy.atom "days"
%cmptmp.2 = ivy.cmp eq %age, %2 : (#ivy.id, #ivy.atom) -> i1 %cmptmp.2 = ivy.cmp eq %age, %2 : (!ivy.id, !ivy.atom) -> i1
scf.condition %cmptmp.2 scf.condition %cmptmp.2
} then { } then {
%d1 = arith.constant 365 : i32 %d1 = arith.constant 365 : i32
%divtmp.1 = ivy.div %age, %d1 : (#ivy.id, i32) -> #ivy.id %divtmp.1 = ivy.div %age, %d1 : (!ivy.id, i32) -> !ivy.id
ptr.store %divtmp.1, %self.age : #ivy.id, ptr ptr.store %divtmp.1, %self.age : !ivy.id, ptr
scf.switch-break : () scf.switch-break : ()
} default { } default {
%d2 = arith.constant 0 : i32 %d2 = arith.constant 0 : i32
@@ -97,56 +97,56 @@ ivy.module {
func.return : () func.return : ()
} }
ivy.msgh.object get-age-in-units:%units -> #ivy.id { ivy.msgh.object get-age-in-units:%units -> !ivy.id {
%result = scf.switch : () -> #ivy.id %result = scf.switch : () -> !ivy.id
case { case {
%0 = ivy.atom "years" %0 = ivy.atom "years"
%cmptmp.0 = ivy.cmp eq %age, %0 : (#ivy.id, #ivy.atom) -> i1 %cmptmp.0 = ivy.cmp eq %age, %0 : (!ivy.id, !ivy.atom) -> i1
scf.switch-condition %cmptmp.0 scf.switch-condition %cmptmp.0
} then { } then {
%v0 = ptr.load %self.age : ptr -> #ivy.id %v0 = ptr.load %self.age : ptr -> !ivy.id
scf.switch-break %v0 : #ivy.id scf.switch-break %v0 : !ivy.id
} case { } case {
%1 = ivy.atom "months" %1 = ivy.atom "months"
%cmptmp.1 = ivy.cmp eq %age, %1 : (#ivy.id, #ivy.atom) -> i1 %cmptmp.1 = ivy.cmp eq %age, %1 : (!ivy.id, !ivy.atom) -> i1
scf.condition %cmptmp.1 scf.condition %cmptmp.1
} then { } then {
%v0 = ptr.load %self.age : ptr -> #ivy.id %v0 = ptr.load %self.age : ptr -> !ivy.id
%d0 = arith.constant 12 : i32 %d0 = arith.constant 12 : i32
%divtmp.0 = ivy.div %v0, %d0 : (#ivy.id, i32) -> #ivy.id %divtmp.0 = ivy.div %v0, %d0 : (!ivy.id, i32) -> !ivy.id
scf.switch-break %divtmp.0 : #ivy.id scf.switch-break %divtmp.0 : !ivy.id
} case { } case {
%2 = ivy.atom "days" %2 = ivy.atom "days"
%cmptmp.2 = ivy.cmp eq %age, %2 : (#ivy.id, #ivy.atom) -> i1 %cmptmp.2 = ivy.cmp eq %age, %2 : (!ivy.id, !ivy.atom) -> i1
scf.condition %cmptmp.2 scf.condition %cmptmp.2
} then { } then {
%v1 = ptr.load %self.age : ptr -> #ivy.id %v1 = ptr.load %self.age : ptr -> !ivy.id
%d1 = arith.constant 365 : i32 %d1 = arith.constant 365 : i32
%divtmp.1 = ivy.div %v1, %d1 : (#ivy.id, i32) -> #ivy.id %divtmp.1 = ivy.div %v1, %d1 : (!ivy.id, i32) -> !ivy.id
scf.switch-break %divtmp.1 : #ivy.id scf.switch-break %divtmp.1 : !ivy.id
} default { } default {
%d2 = arith.constant 0 : i32 %d2 = arith.constant 0 : i32
scf.switch-break %d2 : #ivy.id scf.switch-break %d2 : !ivy.id
} }
func.return %result : #ivy.id func.return %result : !ivy.id
} }
ivy.object-prop example-property ivy.object-prop example-property
get { get {
%0 = ptr.load %self.val : ptr -> #ivy.id %0 = ptr.load %self.val : ptr -> !ivy.id
func.return %0 : #ivy.id func.return %0 : !ivy.id
} }
set (%value: #ivy.id) { set (%value: !ivy.id) {
ptr.store %value, %self.val : #ivy.id, ptr ptr.store %value, %self.val : !ivy.id, ptr
func.return : () func.return : ()
} }
ivy.object-prop example-property-2 get { ivy.object-prop example-property-2 get {
%0 = ptr.load %self.val : ptr -> #ivy.id %0 = ptr.load %self.val : ptr -> !ivy.id
func.return %0 : #ivy.id func.return %0 : !ivy.id
} set (%x: #ivy.id) { } set (%x: !ivy.id) {
ptr.store %x, %self.val : #ivy.id, ptr ptr.store %x, %self.val : !ivy.id, ptr
func.return : () func.return : ()
} }
@@ -156,16 +156,16 @@ ivy.module {
} }
ivy.object-prop example-property-4 get { ivy.object-prop example-property-4 get {
%0 = ptr.load %self.__example-property-4 : ptr -> #ivy.id %0 = ptr.load %self.__example-property-4 : ptr -> !ivy.id
func.return %0 : #ivy.id func.return %0 : !ivy.id
} set (%0: #ivy.id) { } set (%0: !ivy.id) {
ptr.store %0, %self.__example-property-4 : #ivy.id, ptr ptr.store %0, %self.__example-property-4 : !ivy.id, ptr
func.return : () func.return : ()
} }
ivy.object-prop example-property-5 get { ivy.object-prop example-property-5 get {
%0 = ptr.load %self.__example-property-5 : ptr -> #ivy.id %0 = ptr.load %self.__example-property-5 : ptr -> !ivy.id
func.return %0 : #ivy.id func.return %0 : !ivy.id
} }
} }
@@ -175,19 +175,19 @@ ivy.module {
%0 = ivy.str.constant "John Doe" %0 = ivy.str.constant "John Doe"
%1 = arith.constant 34 : i32 %1 = arith.constant 34 : i32
%2 = ivy.msg.send to %Person, new(name:%0, age:%1) -> #ivy.id %2 = ivy.msg.send to %Person, new(name:%0, age:%1) -> !ivy.id
%p1 = ptr.alloca #ivy.id -> ptr %p1 = ptr.alloca !ivy.id -> ptr
ptr.store %2, %p1 : #ivy.id, ptr ptr.store %2, %p1 : !ivy.id, ptr
; p1 set-age:100 in-unit:$months. ; p1 set-age:100 in-unit:$months.
%3 = ptr.load %p1 : ptr -> #ivy.id %3 = ptr.load %p1 : ptr -> !ivy.id
%4 = arith.constant 100 : i32 %4 = arith.constant 100 : i32
%5 = ivy.atom "months" %5 = ivy.atom "months"
ivy.msg.send to %3, set-age:%4 in-units:%5 -> void ivy.msg.send to %3, set-age:%4 in-units:%5 -> void
; p1 test(param:'Hello', 'World'). ; p1 test(param:'Hello', 'World').
%6 = ptr.load %p1 : ptr -> #ivy.id %6 = ptr.load %p1 : ptr -> !ivy.id
%7 = ivy.str.constant "Hello" %7 = ivy.str.constant "Hello"
%8 = ivy.str.constant "World" %8 = ivy.str.constant "World"
ivy.msg.send to %6, test(param:%7, _:%8) -> void ivy.msg.send to %6, test(param:%7, _:%8) -> void
@@ -213,9 +213,9 @@ ivy.module {
%14 = ptr.load %i : ptr -> i32 %14 = ptr.load %i : ptr -> i32
ivy.string-builder.add %12 << %14 : i32 ivy.string-builder.add %12 << %14 : i32
%15 = ivy.string-builder.end %12 -> #ivy.id %15 = ivy.string-builder.end %12 -> !ivy.id
%16 = ptr.load %cout : ptr -> #ivy.id %16 = ptr.load %cout : ptr -> !ivy.id
ivy.msg.send to %16, put:%15 -> void ivy.msg.send to %16, put:%15 -> void
; i += 2 ; i += 2
@@ -229,7 +229,7 @@ ivy.module {
%19 = arith.constant 0 : i32 %19 = arith.constant 0 : i32
%20 = arith.constant 100 : i32 %20 = arith.constant 100 : i32
%21 = arith.constant 2 : i32 %21 = arith.constant 2 : i32
%22 = ivy.msg.send to %19, to:%20 step:%21 -> #ivy.id %22 = ivy.msg.send to %19, to:%20 step:%21 -> !ivy.id
; for x in 0 to:100 step:2 do ; for x in 0 to:100 step:2 do
ivy.for %x in %22 -> void { ivy.for %x in %22 -> void {
@@ -237,12 +237,12 @@ ivy.module {
; 'Count is {x}' ; 'Count is {x}'
ivy.string-builder.add %23 << "Count is " ivy.string-builder.add %23 << "Count is "
ivy.string-builder.add %23 << %x : #ivy.id ivy.string-builder.add %23 << %x : !ivy.id
%25 = ivy.string-builder.end %23 -> #ivy.id %25 = ivy.string-builder.end %23 -> !ivy.id
; cout put:"Count is {x}" ; cout put:"Count is {x}"
%26 = ptr.load %cout : ptr -> #ivy.id %26 = ptr.load %cout : ptr -> !ivy.id
ivy.msg.send to %26, put:%25 -> void ivy.msg.send to %26, put:%25 -> void
} }
@@ -251,16 +251,16 @@ ivy.module {
%28 = arith.constant 100 : i32 %28 = arith.constant 100 : i32
%29 = arith.constant 2 : i32 %29 = arith.constant 2 : i32
; [ :i | cout put:'Count: {i}' ] ; [ :i | cout put:'Count: {i}' ]
%30 = ivy.lambda %i : (#ivy.id) -> void { %30 = ivy.lambda %i : (!ivy.id) -> void {
%0 = ivy.string-builder.begin %0 = ivy.string-builder.begin
ivy.string-builder.add %0 << "Count is " ivy.string-builder.add %0 << "Count is "
ivy.string-builder.add %0 << %i : #ivy.id ivy.string-builder.add %0 << %i : !ivy.id
%2 = ivy.string-builder.end %0 -> #ivy.id %2 = ivy.string-builder.end %0 -> !ivy.id
%cout = ivy.global-ref @cout -> ptr %cout = ivy.global-ref @cout -> ptr
%3 = ptr.load %cout : ptr -> #ivy.id %3 = ptr.load %cout : ptr -> !ivy.id
ivy.msg.send to %3, put:%2 -> void ivy.msg.send to %3, put:%2 -> void
} }
@@ -273,29 +273,29 @@ ivy.module {
ptr.store %31, %q : i32, ptr ptr.store %31, %q : i32, ptr
; l = [ cout put:'Value of q is {q}' ]. ; l = [ cout put:'Value of q is {q}' ].
%l = ptr.alloca #ivy.id %l = ptr.alloca !ivy.id
%32 = ptr.load %q : ptr -> i32 %32 = ptr.load %q : ptr -> i32
%33 = ivy.lambda (%env.q = %32) : () -> void { %33 = ivy.lambda (%env.q = %32) : () -> void {
%0 = ivy.string-builder.begin %0 = ivy.string-builder.begin
ivy.string-builder.add %0 << "Value of q is " ivy.string-builder.add %0 << "Value of q is "
ivy.string-builder.add %0 << %env.q : #ivy.id ivy.string-builder.add %0 << %env.q : !ivy.id
%2 = ivy.string-builder.end %0 -> #ivy.id %2 = ivy.string-builder.end %0 -> !ivy.id
%cout = ivy.global-ref @cout -> ptr %cout = ivy.global-ref @cout -> ptr
%3 = ptr.load %cout : ptr -> #ivy.id %3 = ptr.load %cout : ptr -> !ivy.id
ivy.msg.send to %3, put:%2 -> void ivy.msg.send to %3, put:%2 -> void
} }
ptr.store %33, %l : #ivy.id, ptr ptr.store %33, %l : !ivy.id, ptr
; q = 64. ; q = 64.
%34 = arith.constant 64 : i32 %34 = arith.constant 64 : i32
ptr.store %34, %q : i32, ptr ptr.store %34, %q : i32, ptr
; l call. ; l call.
%35 = ptr.load %l : ptr -> #ivy.id %35 = ptr.load %l : ptr -> !ivy.id
ivy.msg.send to %35, call -> void ivy.msg.send to %35, call -> void
%j = ptr.alloca i32 -> ptr %j = ptr.alloca i32 -> ptr
@@ -311,14 +311,14 @@ ivy.module {
%39 = ivy.lambda : () -> void { %39 = ivy.lambda : () -> void {
%cout = ivy.global-ref @cout -> ptr %cout = ivy.global-ref @cout -> ptr
%0 = ivy.str.constant "True!" %0 = ivy.str.constant "True!"
%1 = ptr.load %cout : ptr -> #ivy.id %1 = ptr.load %cout : ptr -> !ivy.id
ivy.msg.send to %1, put:%0 -> void ivy.msg.send to %1, put:%0 -> void
} }
%40 = ivy.lambda : () -> void { %40 = ivy.lambda : () -> void {
%cout = ivy.global-ref @cout -> ptr %cout = ivy.global-ref @cout -> ptr
%0 = ivy.str.constant "False!" %0 = ivy.str.constant "False!"
%1 = ptr.load %cout : ptr -> #ivy.id %1 = ptr.load %cout : ptr -> !ivy.id
ivy.msg.send to %1, put:%0 -> void ivy.msg.send to %1, put:%0 -> void
} }
@@ -331,53 +331,53 @@ ivy.module {
scf.if %cmptmp.0 -> void { scf.if %cmptmp.0 -> void {
%43 = ivy.str.constant "True!" %43 = ivy.str.constant "True!"
%44 = ptr.load %cout : ptr -> #ivy.id %44 = ptr.load %cout : ptr -> !ivy.id
ivy.msg.send to %44, put:%43 -> void ivy.msg.send to %44, put:%43 -> void
} }
; pkg = {}. ; pkg = {}.
%pkg = ptr.alloca #ivy.id -> ptr %pkg = ptr.alloca !ivy.id -> ptr
%Package = ivy.global-ref @std.lang.Package -> ptr %Package = ivy.global-ref @std.lang.Package -> ptr
%45 = ivy.msg.send to %Package, new -> #ivy.id %45 = ivy.msg.send to %Package, new -> !ivy.id
ptr.store %45, %pkg : #ivy.id, ptr ptr.store %45, %pkg : !ivy.id, ptr
; pkg[0] = 16. ; pkg[0] = 16.
%46 = ptr.load %pkg : ptr -> #ivy.id %46 = ptr.load %pkg : ptr -> !ivy.id
%47 = arith.constant 0 : i32 %47 = arith.constant 0 : i32
%48 = arith.constant 16 : i32 %48 = arith.constant 16 : i32
ivy.msg.send to %46, at:%47 put:%48 -> void ivy.msg.send to %46, at:%47 put:%48 -> void
; tuple = (32, 'a string') ; tuple = (32, 'a string')
%tuple = ptr.alloca #ivy.id -> ptr %tuple = ptr.alloca !ivy.id -> ptr
%49 = arith.constant 32 : i32 %49 = arith.constant 32 : i32
%50 = ivy.str.constant "a string" %50 = ivy.str.constant "a string"
%51 = ivy.tuple.create %49, %50 : (i32, #ivy.id) -> #ivy.id %51 = ivy.tuple.create %49, %50 : (i32, !ivy.id) -> !ivy.id
ptr.store %51, %tuple : #ivy.id, ptr ptr.store %51, %tuple : !ivy.id, ptr
%52 = ptr.load %tuple : ptr -> #ivy.id %52 = ptr.load %tuple : ptr -> !ivy.id
%53 = ivy.msg.send to %52, get-iterator -> #ivy.id %53 = ivy.msg.send to %52, get-iterator -> !ivy.id
ivy.for %54 in %53 -> void { ivy.for %54 in %53 -> void {
%key = ivy.tuple.get-item %54[0] : (#ivy.id, i32) -> #ivy.id %key = ivy.tuple.get-item %54[0] : (!ivy.id, i32) -> !ivy.id
%val = ivy.tuple.get-item %54[1] : (#ivy.id, i32) -> #ivy.id %val = ivy.tuple.get-item %54[1] : (!ivy.id, i32) -> !ivy.id
; '{key} -> {val}' ; '{key} -> {val}'
%55 = ivy.string-builder.begin %55 = ivy.string-builder.begin
ivy.string-builder.add %55 << %key : #ivy.id ivy.string-builder.add %55 << %key : !ivy.id
ivy.string-builder.add %55 << " -> " ivy.string-builder.add %55 << " -> "
ivy.string-builder.add %55 << %val : #ivy.id ivy.string-builder.add %55 << %val : !ivy.id
%57 = ivy.string-builder.end %55 -> #ivy.id %57 = ivy.string-builder.end %55 -> !ivy.id
; cout put:'{key} -> {val}' ; cout put:'{key} -> {val}'
%58 = ptr.load %cout : ptr -> #ivy.id %58 = ptr.load %cout : ptr -> !ivy.id
ivy.msg.send to %58, put:%57 -> void ivy.msg.send to %58, put:%57 -> void
} }
@@ -387,20 +387,20 @@ ivy.module {
%multmp = arith.mul %59, %60 : (i32, i32) -> i32 %multmp = arith.mul %59, %60 : (i32, i32) -> i32
; a = (32, 64). ; a = (32, 64).
%a = ptr.alloca #ivy.id -> ptr %a = ptr.alloca !ivy.id -> ptr
%61 = arith.constant 32 : i32 %61 = arith.constant 32 : i32
%62 = arith.constant 64 : i32 %62 = arith.constant 64 : i32
%63 = ivy.tuple.create %61, %62 : (i32, i32) -> #ivy.id %63 = ivy.tuple.create %61, %62 : (i32, i32) -> !ivy.id
ptr.store %63, %a : #ivy.id, ptr ptr.store %63, %a : !ivy.id, ptr
%v = ptr.alloca #ivy.id -> ptr %v = ptr.alloca !ivy.id -> ptr
%64 = ptr.load %a : ptr -> #ivy.id %64 = ptr.load %a : ptr -> !ivy.id
%65 = ivy.tuple.get-item %64[1] : #ivy.id -> #ivy.id %65 = ivy.tuple.get-item %64[1] : !ivy.id -> !ivy.id
ptr.store %65, %v : #ivy.id, ptr ptr.store %65, %v : !ivy.id, ptr
%66 = ivy.atom "err:number-format" %66 = ivy.atom "err:number-format"
@@ -413,47 +413,47 @@ ivy.module {
} }
%67 = ivy.lambda : () -> void { %67 = ivy.lambda : () -> void {
%v = ptr.alloca #ivy.id -> ptr %v = ptr.alloca !ivy.id -> ptr
%Int = ivy.global-ref @Int -> ptr %Int = ivy.global-ref @Int -> ptr
%0 = ivy.str.constant "342" %0 = ivy.str.constant "342"
%1 = ivy.msg.send to %Int, parse:%0 %1 = ivy.msg.send to %Int, parse:%0
ptr.store %1, %v : #ivy.id, ptr ptr.store %1, %v : !ivy.id, ptr
} }
%68 = ivy.lambda %err, %data : (#ivy.id, #ivy.id) -> void { %68 = ivy.lambda %err, %data : (!ivy.id, !ivy.id) -> void {
%0 = ivy.string-builder.begin %0 = ivy.string-builder.begin
ivy.string-builder.add %0 << "Cannot parse integer string (" ivy.string-builder.add %0 << "Cannot parse integer string ("
ivy.string-builder.add %0 << %err : #ivy.id ivy.string-builder.add %0 << %err : !ivy.id
ivy.string-builder.add %0 << ")" ivy.string-builder.add %0 << ")"
%3 = ivy.string-builder.end %0 -> #ivy.id %3 = ivy.string-builder.end %0 -> !ivy.id
; cout put:'{key} -> {val}' ; cout put:'{key} -> {val}'
%4 = ptr.load %cout : ptr -> #ivy.id %4 = ptr.load %cout : ptr -> !ivy.id
ivy.msg.send to %4, put:%3 -> void ivy.msg.send to %4, put:%3 -> void
} }
%69 = ivy.lambda %err, %data : (#ivy.id, #ivy.id) -> void { %69 = ivy.lambda %err, %data : (!ivy.id, !ivy.id) -> void {
%0 = ivy.string-builder.create %0 = ivy.string-builder.create
ivy.string-builder.add %0 << "Error " ivy.string-builder.add %0 << "Error "
ivy.string-builder.add %0 << %err : #ivy.id ivy.string-builder.add %0 << %err : !ivy.id
ivy.string-builder.add %0 << " occurred (" ivy.string-builder.add %0 << " occurred ("
ivy.string-builder.add %0 << %data : #ivy.id ivy.string-builder.add %0 << %data : !ivy.id
ivy.string-builder.add %0 << ")" ivy.string-builder.add %0 << ")"
%4 = ivy.string-builder.end %0 -> #ivy.id %4 = ivy.string-builder.end %0 -> !ivy.id
; cout put:'{key} -> {val}' ; cout put:'{key} -> {val}'
%5 = ptr.load %cout : ptr -> #ivy.id %5 = ptr.load %cout : ptr -> !ivy.id
ivy.msg.send to %5, put:%4 -> void ivy.msg.send to %5, put:%4 -> void
} }
%70 = ivy.atom "err:number-format" %70 = ivy.atom "err:number-format"
ivy.msg.send to %67, on:%70 do:%68 -> #ivy.id 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, on-error:%69 -> void
ivy.msg.send to %67, call -> void ivy.msg.send to %67, call -> void
} }

View File

@@ -1,6 +1,26 @@
%1, %reg.2, $X0 = ~scf.for(%a, %b) ({ ~builtin.module() ({
^b0: ~func.func() ({
~arith.constant() : () -> () ^entry(%buffer: i32, %lb: index, %ub: index, %step: index):
^b1: ; Initial sum set to 0.
~arith.constant() : () -> () %sum.0 = ~arith.constant() {value = 0.0 : f32} : () -> f32
}) {test_attrib = 2 : i32 } : (i8, i1) -> (i32, i32, i32) ; iter_args binds initial values to the loop's region arguments.
;%sum = "scf.for"(%lb, %ub, %step) -> (f32) {
~cf.br() [ ^for.entry:(%lb: index, %sum.0: f32) ] : () -> ()
^for.entry(%iv: index, %sum.iter: f32):
%t, %x, %z = ~memref.load(%buffer, %iv) : (i32, index) -> (f32, i1, i1)
%sum.next = ~arith.addf(%sum.iter, %t) : (f32, f32) -> f32
~cf.br() [ ^for.cond:(%iv: index, %sum.next: f32) ] : () -> ()
^for.cond(%iv2: index, %sum.next2: f32):
; Yield current iteration sum to next iteration %sum.iter or to %sum
; if final iteration.
%iv.next = ~arith.addi(%iv, %step) : (index, index) -> index
%stop = ~arith.cmpi(%iv.next, %ub) { predicate = 9 } : (index, index) -> i1
~cf.br-cond(%stop) [ ^for.end, ^for.entry:(%iv.next: index, %sum.next: f32) ] : (i1) -> ()
^for.end(%sum: f32):
~func.return(%sum) : (f32) -> ()
}) {sym_name = "reduce", function_type = (i32, index, index, index) -> f32 } : () -> ()
}) : () -> ()