Shuffle object implementation stuff
* Finalize is implemented using the procmacro (I didn't realize this was available) * The `base` BaseObjInst member for objects is now the first member in the structure. It will probably be shuffled around by the optimizer but I prefer it is the first thing so it is clear what these things are. Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
60
src/obj.rs
60
src/obj.rs
@@ -301,16 +301,12 @@ pub trait Obj: Debug + Display + Any + Trace {
|
||||
// BaseObjInst
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#[derive(Default, Debug, Trace)]
|
||||
#[derive(Default, Debug, Trace, Finalize)]
|
||||
pub(crate) struct BaseObjInst {
|
||||
attrs: Attrs,
|
||||
is_instantiated: bool,
|
||||
}
|
||||
|
||||
impl Finalize for BaseObjInst {
|
||||
fn finalize(&self) {}
|
||||
}
|
||||
|
||||
impl Clone for BaseObjInst {
|
||||
fn clone(&self) -> Self {
|
||||
Self {
|
||||
@@ -371,7 +367,7 @@ impl Obj for BaseObjInst {
|
||||
// ObjInst
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#[derive(Debug, Trace)]
|
||||
#[derive(Debug, Trace, Finalize)]
|
||||
pub struct ObjInst {
|
||||
base: BaseObjInst,
|
||||
}
|
||||
@@ -386,10 +382,6 @@ impl ObjInst {
|
||||
impl_create!();
|
||||
}
|
||||
|
||||
impl Finalize for ObjInst {
|
||||
fn finalize(&self) {}
|
||||
}
|
||||
|
||||
impl Display for ObjInst {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(fmt, "<ObjInst at {:x}>", (self as *const _ as usize))
|
||||
@@ -412,18 +404,14 @@ impl Obj for ObjInst {
|
||||
// TypeInst
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#[derive(Trace)]
|
||||
#[derive(Trace, Finalize)]
|
||||
pub struct TypeInst {
|
||||
base: BaseObjInst,
|
||||
#[unsafe_ignore_trace]
|
||||
name: Rc<String>,
|
||||
base: BaseObjInst,
|
||||
vtable: HashMap<String, ObjP>,
|
||||
}
|
||||
|
||||
impl Finalize for TypeInst {
|
||||
fn finalize(&self) {}
|
||||
}
|
||||
|
||||
impl TypeInst {
|
||||
pub fn new(name: impl ToString) -> Self {
|
||||
Self {
|
||||
@@ -484,18 +472,18 @@ impl Obj for TypeInst {
|
||||
// StrInst
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#[derive(Debug, Trace)]
|
||||
#[derive(Debug, Trace, Finalize)]
|
||||
pub struct StrInst {
|
||||
base: BaseObjInst,
|
||||
#[unsafe_ignore_trace]
|
||||
str_value: Rc<String>,
|
||||
base: BaseObjInst,
|
||||
}
|
||||
|
||||
impl StrInst {
|
||||
pub fn new(str_value: impl ToString) -> Self {
|
||||
Self {
|
||||
str_value: Rc::new(str_value.to_string()),
|
||||
base: Default::default(),
|
||||
str_value: Rc::new(str_value.to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -506,10 +494,6 @@ impl StrInst {
|
||||
}
|
||||
}
|
||||
|
||||
impl Finalize for StrInst {
|
||||
fn finalize(&self) {}
|
||||
}
|
||||
|
||||
impl Display for StrInst {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(fmt, "{}", self.str_value)
|
||||
@@ -536,10 +520,10 @@ impl Obj for StrInst {
|
||||
// IntInst
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#[derive(Debug, Trace)]
|
||||
#[derive(Debug, Trace, Finalize)]
|
||||
pub struct IntInst {
|
||||
int_value: i64,
|
||||
base: BaseObjInst,
|
||||
int_value: i64,
|
||||
}
|
||||
|
||||
impl IntInst {
|
||||
@@ -557,10 +541,6 @@ impl IntInst {
|
||||
}
|
||||
}
|
||||
|
||||
impl Finalize for IntInst {
|
||||
fn finalize(&self) {}
|
||||
}
|
||||
|
||||
impl Display for IntInst {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(fmt, "{}", self.int_value)
|
||||
@@ -589,10 +569,10 @@ impl Obj for IntInst {
|
||||
// FloatInst
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#[derive(Debug, Trace)]
|
||||
#[derive(Debug, Trace, Finalize)]
|
||||
pub struct FloatInst {
|
||||
float_value: f64,
|
||||
base: BaseObjInst,
|
||||
float_value: f64,
|
||||
}
|
||||
|
||||
impl FloatInst {
|
||||
@@ -610,10 +590,6 @@ impl FloatInst {
|
||||
}
|
||||
}
|
||||
|
||||
impl Finalize for FloatInst {
|
||||
fn finalize(&self) {}
|
||||
}
|
||||
|
||||
impl Display for FloatInst {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
// we want to force the .0 if it's a whole number
|
||||
@@ -647,10 +623,10 @@ impl Obj for FloatInst {
|
||||
// BoolInst
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#[derive(Debug, Trace)]
|
||||
#[derive(Debug, Trace, Finalize)]
|
||||
pub struct BoolInst {
|
||||
bool_value: bool,
|
||||
base: BaseObjInst,
|
||||
bool_value: bool,
|
||||
}
|
||||
|
||||
impl BoolInst {
|
||||
@@ -668,10 +644,6 @@ impl BoolInst {
|
||||
}
|
||||
}
|
||||
|
||||
impl Finalize for BoolInst {
|
||||
fn finalize(&self) {}
|
||||
}
|
||||
|
||||
impl Display for BoolInst {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(fmt, "{}", self.bool_value)
|
||||
@@ -698,7 +670,7 @@ impl Obj for BoolInst {
|
||||
// NilInst
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#[derive(Debug, Default, Trace)]
|
||||
#[derive(Debug, Default, Trace, Finalize)]
|
||||
pub struct NilInst {
|
||||
base: BaseObjInst,
|
||||
}
|
||||
@@ -711,10 +683,6 @@ impl NilInst {
|
||||
impl_create!();
|
||||
}
|
||||
|
||||
impl Finalize for NilInst {
|
||||
fn finalize(&self) {}
|
||||
}
|
||||
|
||||
impl Display for NilInst {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(fmt, "nil")
|
||||
|
||||
@@ -54,7 +54,7 @@ pub enum FunctionState {
|
||||
|
||||
pub type BuiltinFunctionPtr = fn(vm: &mut Vm, function_state: FunctionState) -> FunctionResult;
|
||||
|
||||
#[derive(Debug, Trace)]
|
||||
#[derive(Debug, Trace, Finalize)]
|
||||
pub struct BuiltinFunctionInst {
|
||||
base: BaseObjInst,
|
||||
#[unsafe_ignore_trace]
|
||||
@@ -85,10 +85,6 @@ impl BuiltinFunctionInst {
|
||||
}
|
||||
}
|
||||
|
||||
impl Finalize for BuiltinFunctionInst {
|
||||
fn finalize(&self) {}
|
||||
}
|
||||
|
||||
impl Display for BuiltinFunctionInst {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(
|
||||
@@ -132,7 +128,7 @@ impl Obj for BuiltinFunctionInst {
|
||||
// UserFunctionInst
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#[derive(Debug, Clone, Trace)]
|
||||
#[derive(Debug, Clone, Trace, Finalize)]
|
||||
pub struct UserFunctionInst {
|
||||
base: BaseObjInst,
|
||||
#[unsafe_ignore_trace]
|
||||
@@ -173,10 +169,6 @@ impl UserFunctionInst {
|
||||
}
|
||||
}
|
||||
|
||||
impl Finalize for UserFunctionInst {
|
||||
fn finalize(&self) {}
|
||||
}
|
||||
|
||||
impl Display for UserFunctionInst {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(
|
||||
@@ -223,7 +215,7 @@ impl Obj for UserFunctionInst {
|
||||
// MethodInst
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#[derive(Trace)]
|
||||
#[derive(Trace, Finalize)]
|
||||
pub struct MethodInst {
|
||||
base: BaseObjInst,
|
||||
self_binding: ObjP,
|
||||
@@ -260,10 +252,6 @@ impl MethodInst {
|
||||
}
|
||||
}
|
||||
|
||||
impl Finalize for MethodInst {
|
||||
fn finalize(&self) {}
|
||||
}
|
||||
|
||||
impl Display for MethodInst {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(fmt, "{}", self.function.borrow())
|
||||
|
||||
Reference in New Issue
Block a user