wasm: Fix Str.isEmpty for capacity

This commit is contained in:
Brian Carroll 2022-03-10 06:59:15 +00:00
parent 0c6fef0ba3
commit 20f6330f72

View file

@ -188,11 +188,17 @@ impl<'a> LowLevelCall<'a> {
// Str // Str
StrConcat => self.load_args_and_call_zig(backend, bitcode::STR_CONCAT), StrConcat => self.load_args_and_call_zig(backend, bitcode::STR_CONCAT),
StrJoinWith => self.load_args_and_call_zig(backend, bitcode::STR_JOIN_WITH), StrJoinWith => self.load_args_and_call_zig(backend, bitcode::STR_JOIN_WITH),
StrIsEmpty => { StrIsEmpty => match backend.storage.get(&self.arguments[0]) {
self.load_args(backend); StoredValue::StackMemory { location, .. } => {
backend.code_builder.i64_const(i64::MIN); let (local_id, offset) =
backend.code_builder.i64_eq(); location.local_and_offset(backend.storage.stack_frame_pointer);
backend.code_builder.get_local(local_id);
backend.code_builder.i32_load8_u(Align::Bytes1, offset + 11);
backend.code_builder.i32_const(0x80);
backend.code_builder.i32_eq();
} }
_ => internal_error!("invalid storage for Str"),
},
StrStartsWith => self.load_args_and_call_zig(backend, bitcode::STR_STARTS_WITH), StrStartsWith => self.load_args_and_call_zig(backend, bitcode::STR_STARTS_WITH),
StrStartsWithCodePt => { StrStartsWithCodePt => {
self.load_args_and_call_zig(backend, bitcode::STR_STARTS_WITH_CODE_PT) self.load_args_and_call_zig(backend, bitcode::STR_STARTS_WITH_CODE_PT)
@ -224,7 +230,7 @@ impl<'a> LowLevelCall<'a> {
&bitcode::STR_TO_FLOAT[float_width] &bitcode::STR_TO_FLOAT[float_width]
} }
Layout::Builtin(Builtin::Decimal) => bitcode::DEC_FROM_STR, Layout::Builtin(Builtin::Decimal) => bitcode::DEC_FROM_STR,
rest => internal_error!("Unexpected builtin {:?} for StrToNum", rest), rest => internal_error!("Unexpected layout {:?} for StrToNum", rest),
}; };
self.load_args_and_call_zig(backend, intrinsic); self.load_args_and_call_zig(backend, intrinsic);