mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 22:34:45 +00:00
Change usage of Wasm if
instruction now that we don't support block results anymore
This commit is contained in:
parent
c3af4b1fb3
commit
1c20075d7b
3 changed files with 47 additions and 25 deletions
|
@ -766,7 +766,7 @@ impl<'a> WasmBackend<'a> {
|
|||
Expr::GetTagId {
|
||||
structure,
|
||||
union_layout,
|
||||
} => self.build_get_tag_id(*structure, union_layout),
|
||||
} => self.build_get_tag_id(*structure, union_layout, *sym, storage),
|
||||
|
||||
Expr::UnionAtIndex {
|
||||
structure,
|
||||
|
@ -860,35 +860,52 @@ impl<'a> WasmBackend<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
fn build_get_tag_id(&mut self, structure: Symbol, union_layout: &UnionLayout<'a>) {
|
||||
fn build_get_tag_id(
|
||||
&mut self,
|
||||
structure: Symbol,
|
||||
union_layout: &UnionLayout<'a>,
|
||||
tag_id_symbol: Symbol,
|
||||
stored_value: &StoredValue,
|
||||
) {
|
||||
use UnionLayout::*;
|
||||
|
||||
let mut need_to_close_block = false;
|
||||
match union_layout {
|
||||
NonRecursive(_) => {}
|
||||
Recursive(_) => {}
|
||||
let block_result_id = match union_layout {
|
||||
NonRecursive(_) => None,
|
||||
Recursive(_) => None,
|
||||
NonNullableUnwrapped(_) => {
|
||||
self.code_builder.i32_const(0);
|
||||
return;
|
||||
}
|
||||
NullableWrapped { nullable_id, .. } => {
|
||||
let stored_with_local = self.storage.ensure_value_has_local(
|
||||
&mut self.code_builder,
|
||||
tag_id_symbol,
|
||||
stored_value.to_owned(),
|
||||
);
|
||||
let local_id = match stored_with_local {
|
||||
StoredValue::Local { local_id, .. } => local_id,
|
||||
_ => internal_error!("ensure_value_has_local didn't work"),
|
||||
};
|
||||
|
||||
// load pointer
|
||||
self.storage
|
||||
.load_symbols(&mut self.code_builder, &[structure]);
|
||||
|
||||
// null check
|
||||
self.code_builder.i32_eqz();
|
||||
self.code_builder.if_(BlockType::Value(ValueType::I32));
|
||||
self.code_builder.if_(BlockType::NoResult);
|
||||
self.code_builder.i32_const(*nullable_id as i32);
|
||||
self.code_builder.set_local(local_id);
|
||||
self.code_builder.else_();
|
||||
need_to_close_block = true;
|
||||
Some(local_id)
|
||||
}
|
||||
NullableUnwrapped { nullable_id, .. } => {
|
||||
self.code_builder.i32_const(!(*nullable_id) as i32);
|
||||
self.code_builder.i32_const(*nullable_id as i32);
|
||||
self.storage
|
||||
.load_symbols(&mut self.code_builder, &[structure]);
|
||||
self.code_builder.i32_eqz();
|
||||
self.code_builder.if_(BlockType::Value(ValueType::I32));
|
||||
self.code_builder.i32_const(*nullable_id as i32);
|
||||
self.code_builder.else_();
|
||||
self.code_builder.i32_const(!(*nullable_id) as i32);
|
||||
self.code_builder.end();
|
||||
self.code_builder.select();
|
||||
None
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -916,7 +933,8 @@ impl<'a> WasmBackend<'a> {
|
|||
self.code_builder.i32_and();
|
||||
}
|
||||
|
||||
if need_to_close_block {
|
||||
if let Some(local_id) = block_result_id {
|
||||
self.code_builder.set_local(local_id);
|
||||
self.code_builder.end();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue