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
|
// BaseObjInst
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#[derive(Default, Debug, Trace)]
|
#[derive(Default, Debug, Trace, Finalize)]
|
||||||
pub(crate) struct BaseObjInst {
|
pub(crate) struct BaseObjInst {
|
||||||
attrs: Attrs,
|
attrs: Attrs,
|
||||||
is_instantiated: bool,
|
is_instantiated: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Finalize for BaseObjInst {
|
|
||||||
fn finalize(&self) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Clone for BaseObjInst {
|
impl Clone for BaseObjInst {
|
||||||
fn clone(&self) -> Self {
|
fn clone(&self) -> Self {
|
||||||
Self {
|
Self {
|
||||||
@@ -371,7 +367,7 @@ impl Obj for BaseObjInst {
|
|||||||
// ObjInst
|
// ObjInst
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#[derive(Debug, Trace)]
|
#[derive(Debug, Trace, Finalize)]
|
||||||
pub struct ObjInst {
|
pub struct ObjInst {
|
||||||
base: BaseObjInst,
|
base: BaseObjInst,
|
||||||
}
|
}
|
||||||
@@ -386,10 +382,6 @@ impl ObjInst {
|
|||||||
impl_create!();
|
impl_create!();
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Finalize for ObjInst {
|
|
||||||
fn finalize(&self) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Display for ObjInst {
|
impl Display for ObjInst {
|
||||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||||
write!(fmt, "<ObjInst at {:x}>", (self as *const _ as usize))
|
write!(fmt, "<ObjInst at {:x}>", (self as *const _ as usize))
|
||||||
@@ -412,18 +404,14 @@ impl Obj for ObjInst {
|
|||||||
// TypeInst
|
// TypeInst
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#[derive(Trace)]
|
#[derive(Trace, Finalize)]
|
||||||
pub struct TypeInst {
|
pub struct TypeInst {
|
||||||
|
base: BaseObjInst,
|
||||||
#[unsafe_ignore_trace]
|
#[unsafe_ignore_trace]
|
||||||
name: Rc<String>,
|
name: Rc<String>,
|
||||||
base: BaseObjInst,
|
|
||||||
vtable: HashMap<String, ObjP>,
|
vtable: HashMap<String, ObjP>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Finalize for TypeInst {
|
|
||||||
fn finalize(&self) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl TypeInst {
|
impl TypeInst {
|
||||||
pub fn new(name: impl ToString) -> Self {
|
pub fn new(name: impl ToString) -> Self {
|
||||||
Self {
|
Self {
|
||||||
@@ -484,18 +472,18 @@ impl Obj for TypeInst {
|
|||||||
// StrInst
|
// StrInst
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#[derive(Debug, Trace)]
|
#[derive(Debug, Trace, Finalize)]
|
||||||
pub struct StrInst {
|
pub struct StrInst {
|
||||||
|
base: BaseObjInst,
|
||||||
#[unsafe_ignore_trace]
|
#[unsafe_ignore_trace]
|
||||||
str_value: Rc<String>,
|
str_value: Rc<String>,
|
||||||
base: BaseObjInst,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl StrInst {
|
impl StrInst {
|
||||||
pub fn new(str_value: impl ToString) -> Self {
|
pub fn new(str_value: impl ToString) -> Self {
|
||||||
Self {
|
Self {
|
||||||
str_value: Rc::new(str_value.to_string()),
|
|
||||||
base: Default::default(),
|
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 {
|
impl Display for StrInst {
|
||||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||||
write!(fmt, "{}", self.str_value)
|
write!(fmt, "{}", self.str_value)
|
||||||
@@ -536,10 +520,10 @@ impl Obj for StrInst {
|
|||||||
// IntInst
|
// IntInst
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#[derive(Debug, Trace)]
|
#[derive(Debug, Trace, Finalize)]
|
||||||
pub struct IntInst {
|
pub struct IntInst {
|
||||||
int_value: i64,
|
|
||||||
base: BaseObjInst,
|
base: BaseObjInst,
|
||||||
|
int_value: i64,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl IntInst {
|
impl IntInst {
|
||||||
@@ -557,10 +541,6 @@ impl IntInst {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Finalize for IntInst {
|
|
||||||
fn finalize(&self) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Display for IntInst {
|
impl Display for IntInst {
|
||||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||||
write!(fmt, "{}", self.int_value)
|
write!(fmt, "{}", self.int_value)
|
||||||
@@ -589,10 +569,10 @@ impl Obj for IntInst {
|
|||||||
// FloatInst
|
// FloatInst
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#[derive(Debug, Trace)]
|
#[derive(Debug, Trace, Finalize)]
|
||||||
pub struct FloatInst {
|
pub struct FloatInst {
|
||||||
float_value: f64,
|
|
||||||
base: BaseObjInst,
|
base: BaseObjInst,
|
||||||
|
float_value: f64,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FloatInst {
|
impl FloatInst {
|
||||||
@@ -610,10 +590,6 @@ impl FloatInst {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Finalize for FloatInst {
|
|
||||||
fn finalize(&self) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Display for FloatInst {
|
impl Display for FloatInst {
|
||||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||||
// we want to force the .0 if it's a whole number
|
// we want to force the .0 if it's a whole number
|
||||||
@@ -647,10 +623,10 @@ impl Obj for FloatInst {
|
|||||||
// BoolInst
|
// BoolInst
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#[derive(Debug, Trace)]
|
#[derive(Debug, Trace, Finalize)]
|
||||||
pub struct BoolInst {
|
pub struct BoolInst {
|
||||||
bool_value: bool,
|
|
||||||
base: BaseObjInst,
|
base: BaseObjInst,
|
||||||
|
bool_value: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BoolInst {
|
impl BoolInst {
|
||||||
@@ -668,10 +644,6 @@ impl BoolInst {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Finalize for BoolInst {
|
|
||||||
fn finalize(&self) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Display for BoolInst {
|
impl Display for BoolInst {
|
||||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||||
write!(fmt, "{}", self.bool_value)
|
write!(fmt, "{}", self.bool_value)
|
||||||
@@ -698,7 +670,7 @@ impl Obj for BoolInst {
|
|||||||
// NilInst
|
// NilInst
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#[derive(Debug, Default, Trace)]
|
#[derive(Debug, Default, Trace, Finalize)]
|
||||||
pub struct NilInst {
|
pub struct NilInst {
|
||||||
base: BaseObjInst,
|
base: BaseObjInst,
|
||||||
}
|
}
|
||||||
@@ -711,10 +683,6 @@ impl NilInst {
|
|||||||
impl_create!();
|
impl_create!();
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Finalize for NilInst {
|
|
||||||
fn finalize(&self) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Display for NilInst {
|
impl Display for NilInst {
|
||||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||||
write!(fmt, "nil")
|
write!(fmt, "nil")
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ pub enum FunctionState {
|
|||||||
|
|
||||||
pub type BuiltinFunctionPtr = fn(vm: &mut Vm, function_state: FunctionState) -> FunctionResult;
|
pub type BuiltinFunctionPtr = fn(vm: &mut Vm, function_state: FunctionState) -> FunctionResult;
|
||||||
|
|
||||||
#[derive(Debug, Trace)]
|
#[derive(Debug, Trace, Finalize)]
|
||||||
pub struct BuiltinFunctionInst {
|
pub struct BuiltinFunctionInst {
|
||||||
base: BaseObjInst,
|
base: BaseObjInst,
|
||||||
#[unsafe_ignore_trace]
|
#[unsafe_ignore_trace]
|
||||||
@@ -85,10 +85,6 @@ impl BuiltinFunctionInst {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Finalize for BuiltinFunctionInst {
|
|
||||||
fn finalize(&self) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Display for BuiltinFunctionInst {
|
impl Display for BuiltinFunctionInst {
|
||||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||||
write!(
|
write!(
|
||||||
@@ -132,7 +128,7 @@ impl Obj for BuiltinFunctionInst {
|
|||||||
// UserFunctionInst
|
// UserFunctionInst
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#[derive(Debug, Clone, Trace)]
|
#[derive(Debug, Clone, Trace, Finalize)]
|
||||||
pub struct UserFunctionInst {
|
pub struct UserFunctionInst {
|
||||||
base: BaseObjInst,
|
base: BaseObjInst,
|
||||||
#[unsafe_ignore_trace]
|
#[unsafe_ignore_trace]
|
||||||
@@ -173,10 +169,6 @@ impl UserFunctionInst {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Finalize for UserFunctionInst {
|
|
||||||
fn finalize(&self) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Display for UserFunctionInst {
|
impl Display for UserFunctionInst {
|
||||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||||
write!(
|
write!(
|
||||||
@@ -223,7 +215,7 @@ impl Obj for UserFunctionInst {
|
|||||||
// MethodInst
|
// MethodInst
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#[derive(Trace)]
|
#[derive(Trace, Finalize)]
|
||||||
pub struct MethodInst {
|
pub struct MethodInst {
|
||||||
base: BaseObjInst,
|
base: BaseObjInst,
|
||||||
self_binding: ObjP,
|
self_binding: ObjP,
|
||||||
@@ -260,10 +252,6 @@ impl MethodInst {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Finalize for MethodInst {
|
|
||||||
fn finalize(&self) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Display for MethodInst {
|
impl Display for MethodInst {
|
||||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||||
write!(fmt, "{}", self.function.borrow())
|
write!(fmt, "{}", self.function.borrow())
|
||||||
|
|||||||
Reference in New Issue
Block a user