feat: num-bigint 接入任意精度 BigInt(字面量、算术、toString、asIntN/asUintN)

This commit is contained in:
2026-08-12 03:15:18 +08:00
parent 4474702735
commit 1824ef0df1
18 changed files with 227 additions and 212 deletions
+6 -4
View File
@@ -37,10 +37,12 @@ impl Emitter {
fn emit_bigint_literal_expression(
&self, b: &oxide_parser::BigIntLiteral, ctx: &mut CompileCtx,
) -> Result<u32, String> {
let value = b
.value
.parse::<i128>()
.map_err(|_| format!("BigInt literal out of range: {}", b.value))?;
let value = if let Ok(v) = b.value.parse::<i128>() {
num_bigint::BigInt::from(v)
} else {
num_bigint::BigInt::parse_bytes(b.value.as_bytes(), 10)
.ok_or_else(|| format!("BigInt literal out of range: {}", b.value))?
};
let idx = ctx.add_constant(Constant::BigInt(value));
let r = ctx.alloc_reg();
ctx.inst(Inst::load_const(Operand::Reg(r), idx));