Skip to content

Commit

Permalink
fix(moonbit): update api following stdapi change
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-jerry-ye committed Sep 3, 2024
1 parent 519a1c9 commit 2d83eee
Showing 1 changed file with 27 additions and 9 deletions.
36 changes: 27 additions & 9 deletions crates/moonbit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1729,8 +1729,9 @@ impl Bindgen for FunctionBindgen<'_, '_> {
Instruction::CharFromI32 => results.push(format!("Char::from_int({})", operands[0])),
Instruction::I32FromChar => results.push(format!("({}).to_int()", operands[0])),

Instruction::I32FromU8 | Instruction::I32FromU16 => {
results.push(format!("({}).to_int()", operands[0]))
Instruction::I32FromU8 => results.push(format!("({}).to_int()", operands[0])),
Instruction::I32FromU16 => {
results.push(format!("({}).reinterpret_as_int()", operands[0]))
}
Instruction::U8FromI32 => results.push(format!("({}).to_byte()", operands[0])),

Expand All @@ -1742,11 +1743,16 @@ impl Bindgen for FunctionBindgen<'_, '_> {
Instruction::I32FromS16 => {
results.push(format!("{ffi_qualifier}extend16({})", operands[0]))
}
Instruction::U16FromI32 => {
results.push(format!("({}.land(0xFFFF).to_uint())", operands[0]))
Instruction::U16FromI32 => results.push(format!(
"({}.land(0xFFFF).reinterpret_as_uint())",
operands[0]
)),
Instruction::U32FromI32 => {
results.push(format!("({}).reinterpret_as_uint()", operands[0]))
}
Instruction::I32FromU32 => {
results.push(format!("({}).reinterpret_as_int()", operands[0]))
}
Instruction::U32FromI32 => results.push(format!("({}).to_uint()", operands[0])),
Instruction::I32FromU32 => results.push(format!("({}).to_int()", operands[0])),

Instruction::U64FromI64 => results.push(format!("({}).to_uint64()", operands[0])),
Instruction::I64FromU64 => results.push(format!("({}).to_int64()", operands[0])),
Expand All @@ -1757,7 +1763,7 @@ impl Bindgen for FunctionBindgen<'_, '_> {
Instruction::BoolFromI32 => results.push(format!("({} != 0)", operands[0])),

Instruction::FlagsLower { flags, ty, .. } => match flags_repr(flags) {
Int::U8 | Int::U16 | Int::U32 => {
Int::U8 => {
let op = &operands[0];
let flag = self.locals.tmp("flag");
let ty = self.gen.type_name(&Type::Id(*ty), false);
Expand All @@ -1769,6 +1775,18 @@ impl Bindgen for FunctionBindgen<'_, '_> {
);
results.push(format!("{flag}.to_int()"));
}
Int::U16 | Int::U32 => {
let op = &operands[0];
let flag = self.locals.tmp("flag");
let ty = self.gen.type_name(&Type::Id(*ty), false);
uwriteln!(
self.src,
r#"
let {ty}({flag}) = {op}
"#
);
results.push(format!("{flag}.reinterpret_as_int()"));
}
Int::U64 => {
let op = &operands[0];
let flag = self.locals.tmp("flag");
Expand All @@ -1794,14 +1812,14 @@ impl Bindgen for FunctionBindgen<'_, '_> {
}
Int::U16 | Int::U32 => {
results.push(format!(
"{}({}.to_uint())",
"{}({}.reinterpret_as_uint())",
self.gen.type_name(&Type::Id(*ty), true),
operands[0]
));
}
Int::U64 => {
results.push(format!(
"{}(({}).to_uint().to_uint64().lor(({}).to_uint().to_uint64.lsl(32)))",
"{}(({}).reinterpret_as_uint().to_uint64().lor(({}).reinterpret_as_uint().to_uint64.lsl(32)))",
self.gen.type_name(&Type::Id(*ty), true),
operands[0],
operands[1]
Expand Down

0 comments on commit 2d83eee

Please sign in to comment.