Sketching DVM IR.

This commit is contained in:
Jesse Brault 2025-10-04 09:07:49 -05:00
parent 8969186467
commit 9731bb38fe
3 changed files with 96 additions and 1 deletions

View File

@ -1,3 +1,4 @@
fn main()
1 + 2 * 3 + 4
let n = 1 + 2 * 3 + 4
println n
end

5
examples/op_prec.dvm_ir Normal file
View File

@ -0,0 +1,5 @@
fn main() -> Void
$0 = 2 * 3
$1 = 1 + $0
$2 = $1 + 4
call std::core::println($2)

89
examples/worlds.dvm_ir Normal file
View File

@ -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<World> *getWorlds()
List<World> *$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<World> *worlds, String *color)
__findWorldByColor__cl0_captures *$0 = alloc __findWorldByColor__cl0_captures
$0.color = color
Closure(__findWorldByColor__cl0_captures*)(World*)<Boolean> $1
= closure(__findWorldByColor_cl0, $0)
List<World> $2 = call std::list::ArrayList_impl_Find::find(worlds, $1)
Closure()(World*)<String*> $3 = closure(__findWorldByColor_cl1)
Option<String*> $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<World> *$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