mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-30 07:14:46 +00:00
WIP things seem to work in theory
This commit is contained in:
parent
845e30658e
commit
53bd47221c
6 changed files with 213 additions and 137 deletions
|
@ -681,10 +681,11 @@ fn path_to_expr<'a>(
|
|||
env: &mut Env<'a, '_>,
|
||||
symbol: Symbol,
|
||||
path: &Path,
|
||||
is_unwrapped: bool,
|
||||
field_layouts: Layout<'a>,
|
||||
) -> Expr<'a> {
|
||||
match path {
|
||||
Path::Unbox(ref path) => path_to_expr(env, symbol, path, field_layouts),
|
||||
Path::Unbox(ref path) => path_to_expr(env, symbol, path, true, field_layouts),
|
||||
|
||||
// TODO make this work with AccessAtIndex.
|
||||
// that already works for structs, but not for basic types for some reason
|
||||
|
@ -702,6 +703,7 @@ fn path_to_expr<'a>(
|
|||
.arena
|
||||
.alloc([Layout::Builtin(Builtin::Byte(MutMap::default()))]),
|
||||
expr: env.arena.alloc(Expr::Load(symbol)),
|
||||
is_unwrapped,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -733,8 +735,8 @@ fn decide_to_branching<'a>(
|
|||
|
||||
for (path, test) in test_chain {
|
||||
match test {
|
||||
Test::IsCtor { tag_id, .. } => {
|
||||
let lhs = Expr::Byte(tag_id);
|
||||
Test::IsCtor { tag_id, union, .. } => {
|
||||
let lhs = Expr::Int(tag_id as i64);
|
||||
|
||||
let field_layouts = env.arena.alloc([
|
||||
Layout::Builtin(Builtin::Byte(MutMap::default())),
|
||||
|
@ -744,15 +746,15 @@ fn decide_to_branching<'a>(
|
|||
index: 0,
|
||||
field_layouts,
|
||||
expr: env.arena.alloc(Expr::Load(cond_symbol)),
|
||||
is_unwrapped: union.alternatives.len() == 1,
|
||||
};
|
||||
// let rhs = Expr::Byte(tag_id);
|
||||
let fake = MutMap::default();
|
||||
|
||||
let cond = env.arena.alloc(Expr::CallByName(
|
||||
Symbol::INT_EQ_I8,
|
||||
Symbol::INT_EQ_I64,
|
||||
env.arena.alloc([
|
||||
(lhs, Layout::Builtin(Builtin::Byte(fake.clone()))),
|
||||
(rhs, Layout::Builtin(Builtin::Byte(fake))),
|
||||
(lhs, Layout::Builtin(Builtin::Int64)),
|
||||
(rhs, Layout::Builtin(Builtin::Int64)),
|
||||
]),
|
||||
));
|
||||
|
||||
|
@ -760,8 +762,13 @@ fn decide_to_branching<'a>(
|
|||
}
|
||||
Test::IsInt(test_int) => {
|
||||
let lhs = Expr::Int(test_int);
|
||||
let rhs =
|
||||
path_to_expr(env, cond_symbol, &path, Layout::Builtin(Builtin::Int64));
|
||||
let rhs = path_to_expr(
|
||||
env,
|
||||
cond_symbol,
|
||||
&path,
|
||||
false,
|
||||
Layout::Builtin(Builtin::Int64),
|
||||
);
|
||||
|
||||
let cond = env.arena.alloc(Expr::CallByName(
|
||||
Symbol::INT_EQ_I64,
|
||||
|
@ -782,6 +789,7 @@ fn decide_to_branching<'a>(
|
|||
env,
|
||||
cond_symbol,
|
||||
&path,
|
||||
false,
|
||||
Layout::Builtin(Builtin::Float64),
|
||||
);
|
||||
|
||||
|
@ -806,6 +814,7 @@ fn decide_to_branching<'a>(
|
|||
env,
|
||||
cond_symbol,
|
||||
&path,
|
||||
false,
|
||||
Layout::Builtin(Builtin::Byte(MutMap::default())),
|
||||
);
|
||||
|
||||
|
@ -863,9 +872,13 @@ fn decide_to_branching<'a>(
|
|||
tests,
|
||||
fallback,
|
||||
} => {
|
||||
let cond = env
|
||||
.arena
|
||||
.alloc(path_to_expr(env, cond_symbol, &path, cond_layout.clone()));
|
||||
let cond = env.arena.alloc(path_to_expr(
|
||||
env,
|
||||
cond_symbol,
|
||||
&path,
|
||||
false,
|
||||
cond_layout.clone(),
|
||||
));
|
||||
|
||||
let default_branch = env.arena.alloc(decide_to_branching(
|
||||
env,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue