feat: 实现最小 BigInt 子集(字面量/算术/比较/构造器,Temporal 前置)
This commit is contained in:
@@ -242,6 +242,7 @@ impl ParamSpec<'_> {
|
||||
enum ConstantKey {
|
||||
Number(u64),
|
||||
Int(i32),
|
||||
BigInt(i128),
|
||||
String(String),
|
||||
Boolean(bool),
|
||||
Null,
|
||||
@@ -642,6 +643,7 @@ impl ConstantKey {
|
||||
match value {
|
||||
Constant::Number(v) => Some(Self::Number(v.to_bits())),
|
||||
Constant::Int(v) => Some(Self::Int(*v)),
|
||||
Constant::BigInt(v) => Some(Self::BigInt(*v)),
|
||||
Constant::String(v) => Some(Self::String(v.clone())),
|
||||
Constant::Boolean(v) => Some(Self::Boolean(*v)),
|
||||
Constant::Null => Some(Self::Null),
|
||||
@@ -1255,6 +1257,7 @@ impl Emitter {
|
||||
pub(crate) fn emit_expression(&self, expr: &Expression, ctx: &mut CompileCtx) -> Result<u32, String> {
|
||||
match expr {
|
||||
Expression::NumericLiteral(_)
|
||||
| Expression::BigIntLiteral(_)
|
||||
| Expression::StringLiteral(_)
|
||||
| Expression::BooleanLiteral(_)
|
||||
| Expression::NullLiteral(_)
|
||||
|
||||
@@ -12,6 +12,7 @@ impl Emitter {
|
||||
pub(crate) fn emit_literal(&self, expr: &Expression, ctx: &mut CompileCtx) -> Result<u32, String> {
|
||||
match expr {
|
||||
Expression::NumericLiteral(n) => self.emit_numeric_literal_expression(n, ctx),
|
||||
Expression::BigIntLiteral(b) => self.emit_bigint_literal_expression(b, ctx),
|
||||
Expression::StringLiteral(s) => self.emit_string_literal_expression(s, ctx),
|
||||
Expression::BooleanLiteral(b) => self.emit_boolean_literal_expression(b, ctx),
|
||||
Expression::NullLiteral(_) => self.emit_null_literal_expression(ctx),
|
||||
@@ -33,6 +34,19 @@ impl Emitter {
|
||||
Ok(r)
|
||||
}
|
||||
|
||||
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 idx = ctx.add_constant(Constant::BigInt(value));
|
||||
let r = ctx.alloc_reg();
|
||||
ctx.inst(Inst::load_const(Operand::Reg(r), idx));
|
||||
Ok(r)
|
||||
}
|
||||
|
||||
fn emit_string_literal_expression(
|
||||
&self, s: &oxide_parser::StringLiteral, ctx: &mut CompileCtx,
|
||||
) -> Result<u32, String> {
|
||||
|
||||
Reference in New Issue
Block a user