expose slot_new_wrapper as its base type

This commit is contained in:
Jeong YunWon
2023-04-06 01:42:59 +09:00
parent 18044abbb6
commit 798b3bc158
3 changed files with 10 additions and 9 deletions

View File

@@ -3,7 +3,7 @@
use crate::{
builtins::{PyBaseObject, PyBoundMethod, PyType, PyTypeRef},
identifier,
object::{Py, PyObjectRef},
object::Py,
types::{hash_not_implemented, PyTypeFlags, PyTypeSlots},
vm::Context,
};
@@ -99,10 +99,12 @@ pub trait PyClassImpl: PyClassDef {
);
}
if class.slots.new.load().is_some() {
let bound: PyObjectRef =
PyBoundMethod::new_ref(class.to_owned().into(), ctx.slot_new_wrapper.clone(), ctx)
.into();
class.set_attr(identifier!(ctx, __new__), bound);
let bound = PyBoundMethod::new_ref(
class.to_owned().into(),
ctx.slot_new_wrapper.clone().into(),
ctx,
);
class.set_attr(identifier!(ctx, __new__), bound.into());
}
if class.slots.hash.load().map_or(0, |h| h as usize) == hash_not_implemented as usize {

View File

@@ -45,7 +45,7 @@ pub struct Context {
pub int_cache_pool: Vec<PyIntRef>,
// there should only be exact objects of str in here, no non-str objects and no subclasses
pub(crate) string_pool: StringPool,
pub(crate) slot_new_wrapper: PyObjectRef,
pub(crate) slot_new_wrapper: PyRef<PyBuiltinFunction>,
pub names: ConstName,
}
@@ -290,8 +290,7 @@ impl Context {
let slot_new_wrapper = create_object(
PyNativeFuncDef::new(PyType::__new__.into_func(), names.__new__).into_function(),
types.builtin_function_or_method_type,
)
.into();
);
let empty_str = unsafe { string_pool.intern("", types.str_type.to_owned()) }.to_owned();
let empty_bytes = create_object(PyBytes::from(Vec::new()), types.bytes_type);

View File

@@ -216,7 +216,7 @@ pub fn js_to_py(vm: &VirtualMachine, js_val: JsValue) -> PyObjectRef {
let func = js_sys::Function::from(js_val);
vm.ctx
.new_function(
String::from(func.name()),
String::from(func.name()).as_str(),
move |args: FuncArgs, vm: &VirtualMachine| -> PyResult {
let this = Object::new();
for (k, v) in args.kwargs {