style: 自动格式化

This commit is contained in:
2026-10-12 12:47:12 +00:00
parent 84bcebee53
commit 0aa7bf83c1
5 changed files with 19 additions and 27 deletions
+1 -3
View File
@@ -9,9 +9,7 @@
use oxide_bytecode::module::Constant;
use oxide_parser::{BinaryOperator, Expression, UnaryOperator};
use oxide_runtime_api::{
abstract_eq_primitives, relational_compare, strict_equality, to_int32, to_number, to_uint32,
};
use oxide_runtime_api::{abstract_eq_primitives, relational_compare, strict_equality, to_int32, to_number, to_uint32};
use oxide_types::value::JsValue;
use crate::is_int_literal;
+2 -8
View File
@@ -419,12 +419,6 @@ fn binary_literal_fold_entry() {
let ir = emit_ir("var a = 2 * 3; var b = 1 + 2;");
assert_eq!(count_op(&ir.insts, OpCode::MUL), 0, "双字面量乘法应折叠,MUL 计数为 0");
assert_eq!(count_op(&ir.insts, OpCode::ADD), 0, "双字面量加法应折叠,ADD 计数为 0");
assert!(
ir.constants.contains(&Constant::Number(6.0)),
"常量池应含乘法折值 Number(6.0)"
);
assert!(
ir.constants.contains(&Constant::Int(3)),
"常量池应含加法折值 Int(3)"
);
assert!(ir.constants.contains(&Constant::Number(6.0)), "常量池应含乘法折值 Number(6.0)");
assert!(ir.constants.contains(&Constant::Int(3)), "常量池应含加法折值 Int(3)");
}
+1 -2
View File
@@ -128,8 +128,7 @@ fn fold_deterministic() {
let mut fingerprints: Vec<(String, String)> = Vec::new();
for _ in 0..8 {
let alloc = oxide_parser::Allocator::default();
let program =
oxide_parser::parse(&alloc, src).unwrap_or_else(|e| panic!("parse 失败 {src:?}: {e:?}"));
let program = oxide_parser::parse(&alloc, src).unwrap_or_else(|e| panic!("parse 失败 {src:?}: {e:?}"));
let ir = Emitter::new()
.emit_program(&program, false, false)
.unwrap_or_else(|e| panic!("emit 失败 {src:?}: {e}"));
+10 -8
View File
@@ -473,12 +473,8 @@ pub fn abstract_eq_primitives(lhs: JsValue, rhs: JsValue) -> bool {
// Number 混合表示(int vs double):同属 ECMAScript Number,按严格相等。
(JsType::Int | JsType::Double, JsType::Int | JsType::Double) => strict_equality(lhs, rhs),
// BigInt 与 Number:转 f64 比较(精度内精确;超出精度近似)。
(JsType::BigInt, JsType::Int | JsType::Double) => {
bigint_to_f64(unsafe { bigint_data(lhs) }) == to_number(rhs)
}
(JsType::Int | JsType::Double, JsType::BigInt) => {
to_number(lhs) == bigint_to_f64(unsafe { bigint_data(rhs) })
}
(JsType::BigInt, JsType::Int | JsType::Double) => bigint_to_f64(unsafe { bigint_data(lhs) }) == to_number(rhs),
(JsType::Int | JsType::Double, JsType::BigInt) => to_number(lhs) == bigint_to_f64(unsafe { bigint_data(rhs) }),
// BigInt 与 String:字符串解析为数字后比较(lossy 文本口径,见 to_number)。
(JsType::BigInt, JsType::String) => {
let r = parse_js_number(&unsafe { string_data(rhs) });
@@ -536,7 +532,10 @@ pub fn abstract_eq<H: VmHost>(lhs: JsValue, rhs: JsValue, host: &mut H) -> Resul
// Object 与原始值:ToPrimitive 后重入。to_primitive 必返原始值,
// 重入即收敛到原始值核心,与单次委托等价。
match (tl, tr) {
(JsType::Object, JsType::Int | JsType::Double | JsType::String | JsType::BigInt | JsType::Symbol | JsType::Bool) => {
(
JsType::Object,
JsType::Int | JsType::Double | JsType::String | JsType::BigInt | JsType::Symbol | JsType::Bool,
) => {
let rhs = if tr == JsType::Bool {
// Boolean 先 ToNumber(int(0/1) 轻量编码),与原始值核心
// 的 Boolean 重入口径一致。
@@ -547,7 +546,10 @@ pub fn abstract_eq<H: VmHost>(lhs: JsValue, rhs: JsValue, host: &mut H) -> Resul
let prim = to_primitive(lhs, ToPrimitiveHint::Default, host)?;
abstract_eq(prim, rhs, host)
}
(JsType::Int | JsType::Double | JsType::String | JsType::BigInt | JsType::Symbol | JsType::Bool, JsType::Object) => {
(
JsType::Int | JsType::Double | JsType::String | JsType::BigInt | JsType::Symbol | JsType::Bool,
JsType::Object,
) => {
let lhs = if tl == JsType::Bool {
// 同上。
JsValue::int(lhs.as_bool() as i32)
+5 -6
View File
@@ -24,12 +24,11 @@ mod runtime_api_log;
pub use coercion::{
abstract_eq, abstract_eq_primitives, bigint_data, bigint_to_f64, bigint_to_string, format_error_message,
js_number_to_string,
materialize_string_box, push_to_string, push_units_to, relational_compare, same_value, same_value_zero,
strict_equality, string_concat, string_value_eq, to_bigint_full, to_boolean, to_int32, to_integer_or_infinity,
to_length, to_number, to_number_full, to_object, to_primitive, to_string, to_string_for_string_constructor,
to_string_full, to_string_value_full, to_uint32, to_units_full, well_known_symbol_name, write_number_into,
ToPrimitiveHint,
js_number_to_string, materialize_string_box, push_to_string, push_units_to, relational_compare, same_value,
same_value_zero, strict_equality, string_concat, string_value_eq, to_bigint_full, to_boolean, to_int32,
to_integer_or_infinity, to_length, to_number, to_number_full, to_object, to_primitive, to_string,
to_string_for_string_constructor, to_string_full, to_string_value_full, to_uint32, to_units_full,
well_known_symbol_name, write_number_into, ToPrimitiveHint,
};
pub use compiler_service::CompilerService;
pub use event_target::{EventTargetState, ListenerEntry};