diff --git a/examples/op_prec.dm b/examples/op_prec.dm index f110f8f..9f6a953 100644 --- a/examples/op_prec.dm +++ b/examples/op_prec.dm @@ -1,3 +1,4 @@ fn main() - 1 + 2 * 3 + 4 + let n = 1 + 2 * 3 + 4 + println n end \ No newline at end of file diff --git a/examples/op_prec.dvm_ir b/examples/op_prec.dvm_ir new file mode 100644 index 0000000..e782b99 --- /dev/null +++ b/examples/op_prec.dvm_ir @@ -0,0 +1,5 @@ +fn main() -> Void + $0 = 2 * 3 + $1 = 1 + $0 + $2 = $1 + 4 + call std::core::println($2) \ No newline at end of file diff --git a/examples/worlds.dvm_ir b/examples/worlds.dvm_ir new file mode 100644 index 0000000..bccf6bf --- /dev/null +++ b/examples/worlds.dvm_ir @@ -0,0 +1,89 @@ +struct World + pub String* name + pub String* color +end + +void World::ctor(World *self, String* name, String* color) + self.name = move name + self.color = move color +end + +const String %s0 = 'Mercury' +const String %s1 = 'Red' +const String %s2 = 'Earth' +const String %s3 = 'Blue' +const String %s4 = 'Jupiter' +const String %s5 = 'Orange' + +List *getWorlds() + List *$0 = alloc std::list::ArrayList + call std::list::ArrayList::ctor($0) + World *$1 = alloc World + call World::ctor($1, %s0, %s1) + call std::list::ArrayList::add($0, $1) + World *$2 = alloc World + call World::ctor($2, %s2, %s3) + call std::list::ArrayList::add($0, $2) + World *$3 = alloc World + call World::ctor($3, %s4, %s5) + call std::list::ArrayList::add($0, $3) + ret $0 +end + +struct __findWorldByColor__cl0_captures + pub String* color +end + +Boolean __findWorldByColor_cl0(__findWorldByColor__cl0_captures *__captures, World *it) + String *$0 = it.color + String *$1 = __captures.color + Boolean $2 = *$0 == *$1 + ret $2 +end + +String* __findWorldByColor_cl1(World* it) + $0 = it.name + ret $0 +end + + +String *findWorldByColor(List *worlds, String *color) + __findWorldByColor__cl0_captures *$0 = alloc __findWorldByColor__cl0_captures + $0.color = color + Closure(__findWorldByColor__cl0_captures*)(World*) $1 + = closure(__findWorldByColor_cl0, $0) + List $2 = call std::list::ArrayList_impl_Find::find(worlds, $1) + Closure()(World*) $3 = closure(__findWorldByColor_cl1) + Option $4 = call std::list::ArrayList_impl_Monad($2, $3) + + Display*[1] $5 = alloc Display[1] + $5[0] = color + DString *$6 = alloc DString + call DString::ctor($6, { }, $5) + String *$7 = call DString::toString($6) + + String* $8 = call option::Option::expect($4, $7) + + drop $0 + drop $1 + drop $2 + drop $3 + drop $5 + drop $6 + + ret $8 +end + +const String %s7 = 'Blue' +const String[2] %sa0 = { 'Hello, ', '!' } + +void main() + List *$0 = call getWorlds() + World *$1 = call findWorldByColor($0, %s7) + Display[1] $2 = alloc Display[1] + $2[0] = move $1 + std::string::DString *$3 = alloc std::string::DString + call std::string::DString::ctor($3, %sa0, $2) + String *$4 = call std::DString::toString($3) + call std::core::println($4) +end