feat: 创建对象原型链最小接口
This commit is contained in:
@@ -5,7 +5,7 @@ use oxide_compiler::module::CompiledModule;
|
|||||||
use oxide_compiler::opcode::{self, OpCode};
|
use oxide_compiler::opcode::{self, OpCode};
|
||||||
|
|
||||||
use crate::coercion;
|
use crate::coercion;
|
||||||
use crate::mem::Epoch;
|
use crate::mem::{Epoch, P};
|
||||||
use crate::object::JsObject;
|
use crate::object::JsObject;
|
||||||
use crate::shape::{self, EMPTY_SHAPE_ID};
|
use crate::shape::{self, EMPTY_SHAPE_ID};
|
||||||
use crate::value::JsValue;
|
use crate::value::JsValue;
|
||||||
@@ -25,6 +25,7 @@ pub struct Vm {
|
|||||||
string_table: HashMap<String, u32>,
|
string_table: HashMap<String, u32>,
|
||||||
string_reverse: Vec<String>,
|
string_reverse: Vec<String>,
|
||||||
pub epoch: Epoch,
|
pub epoch: Epoch,
|
||||||
|
pub object_prototype: P<JsObject>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Vm {
|
impl Vm {
|
||||||
@@ -38,6 +39,7 @@ impl Vm {
|
|||||||
string_table: HashMap::with_capacity(64),
|
string_table: HashMap::with_capacity(64),
|
||||||
string_reverse: Vec::with_capacity(64),
|
string_reverse: Vec::with_capacity(64),
|
||||||
epoch: Epoch::new(),
|
epoch: Epoch::new(),
|
||||||
|
object_prototype: P::new(JsObject::new_empty(EMPTY_SHAPE_ID, JsValue::null())),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -382,17 +384,22 @@ impl Vm {
|
|||||||
}
|
}
|
||||||
|
|
||||||
OpCode::NEW_OBJECT => {
|
OpCode::NEW_OBJECT => {
|
||||||
let obj = self
|
let proto_ptr = &*self.object_prototype as *const JsObject as *mut JsObject;
|
||||||
.epoch
|
let obj = self.epoch.alloc(JsObject::new_empty(
|
||||||
.alloc(JsObject::new_empty(EMPTY_SHAPE_ID, JsValue::null()));
|
EMPTY_SHAPE_ID,
|
||||||
|
JsValue::from_js_object(proto_ptr),
|
||||||
|
));
|
||||||
self.regs[rd] = JsValue::object(obj as *mut u8);
|
self.regs[rd] = JsValue::object(obj as *mut u8);
|
||||||
}
|
}
|
||||||
|
|
||||||
OpCode::NEW_ARRAY => {
|
OpCode::NEW_ARRAY => {
|
||||||
|
let proto_ptr = &*self.object_prototype as *const JsObject as *mut JsObject;
|
||||||
let n = opcode::imm16(instr) as usize;
|
let n = opcode::imm16(instr) as usize;
|
||||||
let obj =
|
let obj = self.epoch.alloc(JsObject::new_array(
|
||||||
self.epoch
|
EMPTY_SHAPE_ID,
|
||||||
.alloc(JsObject::new_array(EMPTY_SHAPE_ID, JsValue::null(), n));
|
JsValue::from_js_object(proto_ptr),
|
||||||
|
n,
|
||||||
|
));
|
||||||
self.regs[rd] = JsValue::object(obj as *mut u8);
|
self.regs[rd] = JsValue::object(obj as *mut u8);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user