Big Object naming refactor
* trait Obj -> Object * Remove *Inst suffix from all object types. ObjInst -> Obj, IntInst -> Int, etc * Type -> Ty, type_inst() -> ty(), type_name() -> ty_name() Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
@@ -5,7 +5,7 @@ use std::rc::Rc;
|
||||
use gc::{Finalize, Trace};
|
||||
|
||||
use crate::obj::macros::*;
|
||||
use crate::obj::{make_ptr, BaseObjInst, Obj, ObjP};
|
||||
use crate::obj::{make_ptr, BaseObj, ObjP, Object};
|
||||
use crate::vm::{Argc, Chunk, Frame, Function, Vm};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -49,14 +49,14 @@ pub enum FunctionState {
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// BuiltinFunctionInst
|
||||
// BuiltinFunction
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
pub type BuiltinFunctionPtr = fn(vm: &mut Vm, function_state: FunctionState) -> FunctionResult;
|
||||
|
||||
#[derive(Debug, Trace, Finalize)]
|
||||
pub struct BuiltinFunctionInst {
|
||||
base: BaseObjInst,
|
||||
pub struct BuiltinFunction {
|
||||
base: BaseObj,
|
||||
#[unsafe_ignore_trace]
|
||||
name: Rc<String>,
|
||||
#[unsafe_ignore_trace]
|
||||
@@ -64,7 +64,7 @@ pub struct BuiltinFunctionInst {
|
||||
arity: Argc,
|
||||
}
|
||||
|
||||
impl BuiltinFunctionInst {
|
||||
impl BuiltinFunction {
|
||||
pub fn new(name: impl ToString, function: BuiltinFunctionPtr, arity: Argc) -> Self {
|
||||
Self {
|
||||
base: Default::default(),
|
||||
@@ -85,7 +85,7 @@ impl BuiltinFunctionInst {
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for BuiltinFunctionInst {
|
||||
impl Display for BuiltinFunction {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(
|
||||
fmt,
|
||||
@@ -97,7 +97,7 @@ impl Display for BuiltinFunctionInst {
|
||||
}
|
||||
}
|
||||
|
||||
impl Obj for BuiltinFunctionInst {
|
||||
impl Object for BuiltinFunction {
|
||||
fn arity(&self) -> Option<Argc> {
|
||||
Some(self.arity)
|
||||
}
|
||||
@@ -111,10 +111,10 @@ impl Obj for BuiltinFunctionInst {
|
||||
vm.push_frame(new_frame);
|
||||
}
|
||||
|
||||
fn equals(&self, other: &dyn Obj) -> bool {
|
||||
// TODO BuiltinFunctionInst::equals : need something more robust than checking addr_eq,
|
||||
fn equals(&self, other: &dyn Object) -> bool {
|
||||
// TODO BuiltinFunction::equals : need something more robust than checking addr_eq,
|
||||
// maybe check the self_binding pointer too?
|
||||
if let Some(other) = other.as_any().downcast_ref::<BuiltinFunctionInst>() {
|
||||
if let Some(other) = other.as_any().downcast_ref::<BuiltinFunction>() {
|
||||
ptr::addr_eq(self, other)
|
||||
} else {
|
||||
false
|
||||
@@ -125,12 +125,12 @@ impl Obj for BuiltinFunctionInst {
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// UserFunctionInst
|
||||
// UserFunction
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#[derive(Debug, Clone, Trace, Finalize)]
|
||||
pub struct UserFunctionInst {
|
||||
base: BaseObjInst,
|
||||
pub struct UserFunction {
|
||||
base: BaseObj,
|
||||
#[unsafe_ignore_trace]
|
||||
name: Rc<String>,
|
||||
#[unsafe_ignore_trace]
|
||||
@@ -139,7 +139,7 @@ pub struct UserFunctionInst {
|
||||
captures: Vec<ObjP>,
|
||||
}
|
||||
|
||||
impl UserFunctionInst {
|
||||
impl UserFunction {
|
||||
pub fn new(chunk: Chunk, arity: Argc) -> Self {
|
||||
Self {
|
||||
base: Default::default(),
|
||||
@@ -169,7 +169,7 @@ impl UserFunctionInst {
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for UserFunctionInst {
|
||||
impl Display for UserFunction {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(
|
||||
fmt,
|
||||
@@ -181,7 +181,7 @@ impl Display for UserFunctionInst {
|
||||
}
|
||||
}
|
||||
|
||||
impl Obj for UserFunctionInst {
|
||||
impl Object for UserFunction {
|
||||
fn arity(&self) -> Option<Argc> {
|
||||
Some(self.arity)
|
||||
}
|
||||
@@ -199,9 +199,9 @@ impl Obj for UserFunctionInst {
|
||||
}
|
||||
}
|
||||
|
||||
fn equals(&self, other: &dyn Obj) -> bool {
|
||||
if let Some(other) = other.as_any().downcast_ref::<UserFunctionInst>() {
|
||||
// TODO UserFunctionInst::equals : need something more robust than checking addr_eq.
|
||||
fn equals(&self, other: &dyn Object) -> bool {
|
||||
if let Some(other) = other.as_any().downcast_ref::<UserFunction>() {
|
||||
// TODO UserFunction::equals : need something more robust than checking addr_eq.
|
||||
ptr::addr_eq(self, other)
|
||||
} else {
|
||||
false
|
||||
@@ -212,19 +212,19 @@ impl Obj for UserFunctionInst {
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// MethodInst
|
||||
// Method
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#[derive(Trace, Finalize)]
|
||||
pub struct MethodInst {
|
||||
base: BaseObjInst,
|
||||
pub struct Method {
|
||||
base: BaseObj,
|
||||
self_binding: ObjP,
|
||||
function: ObjP,
|
||||
}
|
||||
|
||||
impl Debug for MethodInst {
|
||||
impl Debug for Method {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
fmt.debug_struct("MethodInst")
|
||||
fmt.debug_struct("Method")
|
||||
.field("base", &self.base)
|
||||
.field("self_binding", &format!("{}", self.self_binding.borrow()))
|
||||
.field("function", &self.function)
|
||||
@@ -232,7 +232,7 @@ impl Debug for MethodInst {
|
||||
}
|
||||
}
|
||||
|
||||
impl MethodInst {
|
||||
impl Method {
|
||||
pub fn new(self_binding: ObjP, function: ObjP) -> Self {
|
||||
Self {
|
||||
base: Default::default(),
|
||||
@@ -252,13 +252,13 @@ impl MethodInst {
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for MethodInst {
|
||||
impl Display for Method {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(fmt, "{}", self.function.borrow())
|
||||
}
|
||||
}
|
||||
|
||||
impl Obj for MethodInst {
|
||||
impl Object for Method {
|
||||
fn arity(&self) -> Option<Argc> {
|
||||
// Subtract one from the arity - this is because the VM uses arity() to check against the
|
||||
// number of arguments passed.
|
||||
@@ -273,8 +273,8 @@ impl Obj for MethodInst {
|
||||
self.function.borrow().call(vm, argc)
|
||||
}
|
||||
|
||||
fn equals(&self, other: &dyn Obj) -> bool {
|
||||
if let Some(other) = other.as_any().downcast_ref::<MethodInst>() {
|
||||
fn equals(&self, other: &dyn Object) -> bool {
|
||||
if let Some(other) = other.as_any().downcast_ref::<Method>() {
|
||||
ptr::addr_eq(&*self.self_binding, &*other.self_binding)
|
||||
&& ptr::addr_eq(&*self.function, &*other.function)
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user