style: 减少自动格式化换行

This commit is contained in:
爱特每羊队
2026-06-09 00:53:46 +08:00
parent 4713b46d5c
commit 5d1d25074e
86 changed files with 672 additions and 2645 deletions
+41 -169
View File
@@ -202,11 +202,7 @@ fn intern_label(string_forge: &StringForge, label: &str) -> u32 {
}
fn make_pair(
string_forge: &StringForge,
shape_forge: &ShapeForge,
name: &str,
si_prototype: u32,
si_constructor: u32,
string_forge: &StringForge, shape_forge: &ShapeForge, name: &str, si_prototype: u32, si_constructor: u32,
si_name: u32,
) -> (P<JsObject>, P<JsObject>) {
intern_label(string_forge, name);
@@ -226,13 +222,9 @@ fn make_pair(
// Pre-allocate Vec slots so wire_ctor_proto can overwrite vec[0] later.
// Proto: 1 property ("constructor"), Ctor: 2 properties ("prototype", "name").
proto
.ensure_hash_props()
.push(Box::new(JsValue::undefined())); // slot 0: "constructor" placeholder
ctor.ensure_hash_props()
.push(Box::new(JsValue::undefined())); // slot 0: "prototype" placeholder
ctor.ensure_hash_props()
.push(Box::new(JsValue::undefined())); // slot 1: "name" placeholder
proto.ensure_hash_props().push(Box::new(JsValue::undefined())); // slot 0: "constructor" placeholder
ctor.ensure_hash_props().push(Box::new(JsValue::undefined())); // slot 0: "prototype" placeholder
ctor.ensure_hash_props().push(Box::new(JsValue::undefined())); // slot 1: "name" placeholder
(P::new(proto), P::new(ctor))
}
@@ -250,70 +242,22 @@ impl BuiltinWorld {
intern_label(string_forge, "toString");
intern_label(string_forge, "valueOf");
let (object_proto, object_constructor) = make_pair(
string_forge,
shape_forge,
"Object",
si_prototype,
si_constructor,
si_name,
);
let (array_proto, array_constructor) = make_pair(
string_forge,
shape_forge,
"Array",
si_prototype,
si_constructor,
si_name,
);
let (function_proto, function_constructor) = make_pair(
string_forge,
shape_forge,
"Function",
si_prototype,
si_constructor,
si_name,
);
let (string_proto, string_constructor) = make_pair(
string_forge,
shape_forge,
"String",
si_prototype,
si_constructor,
si_name,
);
let (number_proto, number_constructor) = make_pair(
string_forge,
shape_forge,
"Number",
si_prototype,
si_constructor,
si_name,
);
let (boolean_proto, boolean_constructor) = make_pair(
string_forge,
shape_forge,
"Boolean",
si_prototype,
si_constructor,
si_name,
);
let (error_proto, error_constructor) = make_pair(
string_forge,
shape_forge,
"Error",
si_prototype,
si_constructor,
si_name,
);
let (symbol_proto, symbol_constructor) = make_pair(
string_forge,
shape_forge,
"Symbol",
si_prototype,
si_constructor,
si_name,
);
let (object_proto, object_constructor) =
make_pair(string_forge, shape_forge, "Object", si_prototype, si_constructor, si_name);
let (array_proto, array_constructor) =
make_pair(string_forge, shape_forge, "Array", si_prototype, si_constructor, si_name);
let (function_proto, function_constructor) =
make_pair(string_forge, shape_forge, "Function", si_prototype, si_constructor, si_name);
let (string_proto, string_constructor) =
make_pair(string_forge, shape_forge, "String", si_prototype, si_constructor, si_name);
let (number_proto, number_constructor) =
make_pair(string_forge, shape_forge, "Number", si_prototype, si_constructor, si_name);
let (boolean_proto, boolean_constructor) =
make_pair(string_forge, shape_forge, "Boolean", si_prototype, si_constructor, si_name);
let (error_proto, error_constructor) =
make_pair(string_forge, shape_forge, "Error", si_prototype, si_constructor, si_name);
let (symbol_proto, symbol_constructor) =
make_pair(string_forge, shape_forge, "Symbol", si_prototype, si_constructor, si_name);
let error_proto_val = JsValue::from_js_object(error_proto.as_ptr() as *mut JsObject);
let type_error_proto = P::new(JsObject::new_empty(EMPTY_SHAPE_ID, error_proto_val));
@@ -327,38 +271,14 @@ impl BuiltinWorld {
let json_object = P::new(JsObject::new_empty(EMPTY_SHAPE_ID, JsValue::null()));
let (date_proto, date_constructor) = make_pair(
string_forge,
shape_forge,
"Date",
si_prototype,
si_constructor,
si_name,
);
let (set_proto, set_constructor) = make_pair(
string_forge,
shape_forge,
"Set",
si_prototype,
si_constructor,
si_name,
);
let (map_proto, map_constructor) = make_pair(
string_forge,
shape_forge,
"Map",
si_prototype,
si_constructor,
si_name,
);
let (regexp_proto, regexp_constructor) = make_pair(
string_forge,
shape_forge,
"RegExp",
si_prototype,
si_constructor,
si_name,
);
let (date_proto, date_constructor) =
make_pair(string_forge, shape_forge, "Date", si_prototype, si_constructor, si_name);
let (set_proto, set_constructor) =
make_pair(string_forge, shape_forge, "Set", si_prototype, si_constructor, si_name);
let (map_proto, map_constructor) =
make_pair(string_forge, shape_forge, "Map", si_prototype, si_constructor, si_name);
let (regexp_proto, regexp_constructor) =
make_pair(string_forge, shape_forge, "RegExp", si_prototype, si_constructor, si_name);
let sym_match = P::new(JsObject::new_empty(EMPTY_SHAPE_ID, JsValue::null()));
let sym_replace = P::new(JsObject::new_empty(EMPTY_SHAPE_ID, JsValue::null()));
@@ -458,12 +378,7 @@ impl BuiltinWorld {
}
}
pub fn bind_object_methods(
&self,
methods: &ObjectMethods,
string_forge: &StringForge,
shape_forge: &ShapeForge,
) {
pub fn bind_object_methods(&self, methods: &ObjectMethods, string_forge: &StringForge, shape_forge: &ShapeForge) {
let ctor_ptr = P::as_ptr(&self.object_constructor) as *mut JsObject;
let ctor = unsafe { &mut *ctor_ptr };
bind_methods!(
@@ -475,11 +390,7 @@ impl BuiltinWorld {
("create", methods.create, 2),
("assign", methods.assign, 2),
("defineProperty", methods.define_property, 3),
(
"getOwnPropertyDescriptor",
methods.get_own_property_descriptor,
2
),
("getOwnPropertyDescriptor", methods.get_own_property_descriptor, 2),
("freeze", methods.freeze, 1),
("seal", methods.seal, 1),
("preventExtensions", methods.prevent_extensions, 1),
@@ -496,12 +407,7 @@ impl BuiltinWorld {
);
}
pub fn bind_array_methods(
&self,
methods: &ArrayMethods,
string_forge: &StringForge,
shape_forge: &ShapeForge,
) {
pub fn bind_array_methods(&self, methods: &ArrayMethods, string_forge: &StringForge, shape_forge: &ShapeForge) {
let proto_ptr = P::as_ptr(&self.array_proto) as *mut JsObject;
let proto = unsafe { &mut *proto_ptr };
bind_methods!(
@@ -540,12 +446,7 @@ impl BuiltinWorld {
);
}
pub fn bind_error_methods(
&self,
methods: &ErrorMethods,
string_forge: &StringForge,
shape_forge: &ShapeForge,
) {
pub fn bind_error_methods(&self, methods: &ErrorMethods, string_forge: &StringForge, shape_forge: &ShapeForge) {
let ctor_ptr = P::as_ptr(&self.error_constructor) as *mut JsObject;
let ctor = unsafe { &mut *ctor_ptr };
bind_methods!(
@@ -574,12 +475,7 @@ impl BuiltinWorld {
);
}
pub fn bind_string_methods(
&self,
methods: &StringMethods,
string_forge: &StringForge,
shape_forge: &ShapeForge,
) {
pub fn bind_string_methods(&self, methods: &StringMethods, string_forge: &StringForge, shape_forge: &ShapeForge) {
let proto_ptr = P::as_ptr(&self.string_proto) as *mut JsObject;
let proto = unsafe { &mut *proto_ptr };
bind_methods!(
@@ -615,12 +511,7 @@ impl BuiltinWorld {
);
}
pub fn bind_number_methods(
&self,
methods: &NumberMethods,
string_forge: &StringForge,
shape_forge: &ShapeForge,
) {
pub fn bind_number_methods(&self, methods: &NumberMethods, string_forge: &StringForge, shape_forge: &ShapeForge) {
let ctor_ptr = P::as_ptr(&self.number_constructor) as *mut JsObject;
let ctor = unsafe { &mut *ctor_ptr };
let proto_ptr = P::as_ptr(&self.number_proto) as *mut JsObject;
@@ -651,10 +542,7 @@ impl BuiltinWorld {
}
pub fn bind_function_methods(
&self,
methods: &FunctionMethods,
string_forge: &StringForge,
shape_forge: &ShapeForge,
&self, methods: &FunctionMethods, string_forge: &StringForge, shape_forge: &ShapeForge,
) {
let proto_ptr = P::as_ptr(&self.function_proto) as *mut JsObject;
let proto = unsafe { &mut *proto_ptr };
@@ -672,13 +560,8 @@ impl BuiltinWorld {
}
pub fn bind_method(
&self,
proto: &mut JsObject,
shape_forge: &ShapeForge,
string_forge: &StringForge,
method_name: &str,
native_fn_ptr: *const (),
arg_count: u8,
&self, proto: &mut JsObject, shape_forge: &ShapeForge, string_forge: &StringForge, method_name: &str,
native_fn_ptr: *const (), arg_count: u8,
) -> Result<(), String> {
Self::bind_method_static(
proto,
@@ -692,13 +575,8 @@ impl BuiltinWorld {
}
pub fn bind_method_static(
proto: &mut JsObject,
shape_forge: &ShapeForge,
string_forge: &StringForge,
method_name: &str,
native_fn_ptr: *const (),
arg_count: u8,
wrapper_proto: JsValue,
proto: &mut JsObject, shape_forge: &ShapeForge, string_forge: &StringForge, method_name: &str,
native_fn_ptr: *const (), arg_count: u8, wrapper_proto: JsValue,
) -> Result<(), String> {
let si = string_forge.intern(method_name).0;
let wrapper_proto_ptr = if wrapper_proto.is_object() {
@@ -748,10 +626,7 @@ mod tests {
&w.symbol_proto,
];
for p in protos {
assert!(
p.shape_id() > EMPTY_SHAPE_ID,
"proto should have a non-empty shape"
);
assert!(p.shape_id() > EMPTY_SHAPE_ID, "proto should have a non-empty shape");
}
}
@@ -803,9 +678,6 @@ mod tests {
w.object_constructor.shape_id() > EMPTY_SHAPE_ID,
"constructor should have prototype + name shape"
);
assert!(
w.object_proto.shape_id() > EMPTY_SHAPE_ID,
"prototype should have constructor shape"
);
assert!(w.object_proto.shape_id() > EMPTY_SHAPE_ID, "prototype should have constructor shape");
}
}
+5 -16
View File
@@ -13,15 +13,11 @@ pub struct CodeForge {
impl CodeForge {
pub fn new() -> Self {
Self {
map: DashMap::new(),
}
Self { map: DashMap::new() }
}
pub fn get_or_compile(
&self,
program: &oxide_parser::Program,
compiler: &Compiler,
&self, program: &oxide_parser::Program, compiler: &Compiler,
) -> Result<Arc<CompiledModule>, String> {
let hash = structural_hash(program);
@@ -81,17 +77,10 @@ mod tests {
let allocator = Allocator::default();
let program = oxide_parser::parse(&allocator, "1 + 2").expect("parse failed");
let first = forge
.get_or_compile(&program, &compiler)
.expect("first compile");
let second = forge
.get_or_compile(&program, &compiler)
.expect("second compile");
let first = forge.get_or_compile(&program, &compiler).expect("first compile");
let second = forge.get_or_compile(&program, &compiler).expect("second compile");
assert_eq!(
(first.bytecode.len(), first.n_registers),
(second.bytecode.len(), second.n_registers)
);
assert_eq!((first.bytecode.len(), first.n_registers), (second.bytecode.len(), second.n_registers));
}
#[test]
+3 -9
View File
@@ -96,21 +96,15 @@ impl OxideKernel {
let nan_shape = shape_forge.make_shape(EMPTY_SHAPE_ID, si_nan);
global_obj.set_shape_id(nan_shape);
global_obj
.ensure_hash_props()
.push(Box::new(JsValue::float(f64::NAN)));
global_obj.ensure_hash_props().push(Box::new(JsValue::float(f64::NAN)));
let undef_shape = shape_forge.make_shape(nan_shape, si_undef);
global_obj.set_shape_id(undef_shape);
global_obj
.ensure_hash_props()
.push(Box::new(JsValue::undefined()));
global_obj.ensure_hash_props().push(Box::new(JsValue::undefined()));
let inf_shape = shape_forge.make_shape(undef_shape, si_infinity);
global_obj.set_shape_id(inf_shape);
global_obj
.ensure_hash_props()
.push(Box::new(JsValue::float(f64::INFINITY)));
global_obj.ensure_hash_props().push(Box::new(JsValue::float(f64::INFINITY)));
let global_object = P::new(global_obj);
+1 -3
View File
@@ -18,9 +18,7 @@ pub struct PropForge {
impl PropForge {
pub fn new() -> Self {
Self {
templates: DashMap::new(),
}
Self { templates: DashMap::new() }
}
pub fn get_template(&self, shape_id: ShapeId) -> Option<Arc<PropTemplate>> {
+1 -2
View File
@@ -98,8 +98,7 @@ impl StringForge {
return;
}
let mut new_map: HashMap<String, u32, FxBuildHasher> =
HashMap::with_hasher(FxBuildHasher::default());
let mut new_map: HashMap<String, u32, FxBuildHasher> = HashMap::with_hasher(FxBuildHasher::default());
let mut new_entries = Vec::with_capacity(inner.entries.len() - dead_count);
for entry in inner.entries.drain(..) {