mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-26 13:29:12 +00:00
add code to trigger an expect failure
This commit is contained in:
parent
d33beedcd0
commit
d657a8cadc
1 changed files with 117 additions and 9 deletions
|
@ -2847,18 +2847,16 @@ pub fn build_exp_stmt<'a, 'ctx, 'env>(
|
|||
}
|
||||
|
||||
Expect {
|
||||
condition: cond,
|
||||
region: _,
|
||||
lookups: _,
|
||||
condition: cond_symbol,
|
||||
region,
|
||||
lookups,
|
||||
layouts: _,
|
||||
remainder,
|
||||
} => {
|
||||
// do stuff
|
||||
|
||||
let bd = env.builder;
|
||||
let context = env.context;
|
||||
|
||||
let (cond, _cond_layout) = load_symbol_and_layout(scope, cond);
|
||||
let (cond, _cond_layout) = load_symbol_and_layout(scope, cond_symbol);
|
||||
|
||||
let condition = bd.build_int_compare(
|
||||
IntPredicate::EQ,
|
||||
|
@ -2872,19 +2870,129 @@ pub fn build_exp_stmt<'a, 'ctx, 'env>(
|
|||
|
||||
bd.build_conditional_branch(condition, then_block, throw_block);
|
||||
|
||||
{
|
||||
// if let OptLevel::Development = env.opt_level {
|
||||
if false {
|
||||
bd.position_at_end(throw_block);
|
||||
|
||||
match env.target_info.ptr_width() {
|
||||
roc_target::PtrWidth::Bytes8 => {
|
||||
// temporary native implementation
|
||||
throw_exception(env, "An expectation failed!");
|
||||
let func = env
|
||||
.module
|
||||
.get_function(bitcode::UTILS_EXPECT_FAILED_START)
|
||||
.unwrap();
|
||||
|
||||
let call_result = bd.build_call(func, &[], "call_expect_start_failed");
|
||||
|
||||
let mut ptr = call_result
|
||||
.try_as_basic_value()
|
||||
.left()
|
||||
.unwrap()
|
||||
.into_pointer_value();
|
||||
|
||||
{
|
||||
let value = env
|
||||
.context
|
||||
.i32_type()
|
||||
.const_int(region.start().offset as _, false);
|
||||
|
||||
let cast_ptr = env.builder.build_pointer_cast(
|
||||
ptr,
|
||||
value.get_type().ptr_type(AddressSpace::Generic),
|
||||
"to_store_pointer",
|
||||
);
|
||||
|
||||
env.builder.build_store(cast_ptr, value);
|
||||
|
||||
// let increment = layout.stack_size(env.target_info);
|
||||
let increment = 4;
|
||||
let increment = env.ptr_int().const_int(increment as _, false);
|
||||
|
||||
ptr = unsafe {
|
||||
env.builder.build_gep(ptr, &[increment], "increment_ptr")
|
||||
};
|
||||
}
|
||||
|
||||
{
|
||||
let value = env
|
||||
.context
|
||||
.i32_type()
|
||||
.const_int(region.end().offset as _, false);
|
||||
|
||||
let cast_ptr = env.builder.build_pointer_cast(
|
||||
ptr,
|
||||
value.get_type().ptr_type(AddressSpace::Generic),
|
||||
"to_store_pointer",
|
||||
);
|
||||
|
||||
env.builder.build_store(cast_ptr, value);
|
||||
|
||||
// let increment = layout.stack_size(env.target_info);
|
||||
let increment = 4;
|
||||
let increment = env.ptr_int().const_int(increment as _, false);
|
||||
|
||||
ptr = unsafe {
|
||||
env.builder.build_gep(ptr, &[increment], "increment_ptr")
|
||||
};
|
||||
}
|
||||
|
||||
{
|
||||
let region_bytes: u32 =
|
||||
unsafe { std::mem::transmute(cond_symbol.module_id()) };
|
||||
let value = env.context.i32_type().const_int(region_bytes as _, false);
|
||||
|
||||
let cast_ptr = env.builder.build_pointer_cast(
|
||||
ptr,
|
||||
value.get_type().ptr_type(AddressSpace::Generic),
|
||||
"to_store_pointer",
|
||||
);
|
||||
|
||||
env.builder.build_store(cast_ptr, value);
|
||||
|
||||
// let increment = layout.stack_size(env.target_info);
|
||||
let increment = 4;
|
||||
let increment = env.ptr_int().const_int(increment as _, false);
|
||||
|
||||
ptr = unsafe {
|
||||
env.builder.build_gep(ptr, &[increment], "increment_ptr")
|
||||
};
|
||||
}
|
||||
|
||||
for lookup in lookups.iter() {
|
||||
let (value, layout) = load_symbol_and_layout(scope, lookup);
|
||||
|
||||
let cast_ptr = env.builder.build_pointer_cast(
|
||||
ptr,
|
||||
value.get_type().ptr_type(AddressSpace::Generic),
|
||||
"to_store_pointer",
|
||||
);
|
||||
|
||||
store_roc_value(env, *layout, cast_ptr, value);
|
||||
|
||||
let increment = layout.stack_size(env.target_info);
|
||||
let increment = env.ptr_int().const_int(increment as _, false);
|
||||
|
||||
ptr = unsafe {
|
||||
env.builder.build_gep(ptr, &[increment], "increment_ptr")
|
||||
};
|
||||
}
|
||||
|
||||
let func = env
|
||||
.module
|
||||
.get_function(bitcode::UTILS_EXPECT_FAILED_FINALIZE)
|
||||
.unwrap();
|
||||
|
||||
bd.build_call(func, &[], "call_expect_finalize_failed");
|
||||
|
||||
bd.build_unconditional_branch(then_block);
|
||||
}
|
||||
roc_target::PtrWidth::Bytes4 => {
|
||||
// temporary WASM implementation
|
||||
throw_exception(env, "An expectation failed!");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
bd.position_at_end(throw_block);
|
||||
bd.build_unconditional_branch(then_block);
|
||||
}
|
||||
|
||||
bd.position_at_end(then_block);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue