Most object types get their own file now
This is hopefully going to make navigating the source tree easier. Hopefully. The only types that don't get their own files are: * function types (UserFunction, BuiltinFunction, Method), which all live in obj/function.rs * Nil, which lives in obj.rs * Obj, which lives in obj.rs Type definitions and init_types now live in obj/ty.rs. New obj::prelude module for common imports. Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
@@ -38,13 +38,54 @@ macro_rules! impl_base_obj {
|
||||
|
||||
macro_rules! impl_create {
|
||||
($($arg:ident : $ty:ty),* $(,)?) => {
|
||||
// TODO - obj::macros::impl_create - remove this #[allow(dead_code)] designator
|
||||
#[allow(dead_code)]
|
||||
pub fn create($($arg : $ty ),*) -> $crate::obj::ObjP {
|
||||
let ptr = make_ptr(Self::new($($arg),*));
|
||||
let ptr = $crate::obj::make_ptr(Self::new($($arg),*));
|
||||
ptr.borrow_mut().instantiate();
|
||||
ptr
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! impl_do_call {
|
||||
($name:ident) => {
|
||||
pub(crate) fn do_call(
|
||||
vm: &mut $crate::vm::Vm,
|
||||
state: $crate::obj::function::FunctionState,
|
||||
) -> $crate::obj::function::FunctionResult {
|
||||
match state {
|
||||
$crate::obj::function::FunctionState::Begin => {
|
||||
// get the top item off the stack and call to_float on it
|
||||
let arg = vm.peek();
|
||||
let method = if let Some(method) =
|
||||
arg.borrow().get_vtable_attr(arg.clone(), stringify!($name))
|
||||
{
|
||||
method
|
||||
} else {
|
||||
// TODO builtins::do_call - throw exception when target doesn't have a
|
||||
// to_$name method
|
||||
// BLOCKED-ON: exceptions
|
||||
todo!(
|
||||
concat!("{} does not have a ", stringify!($name), " method"),
|
||||
arg.borrow().ty_name()
|
||||
);
|
||||
};
|
||||
vm.push(method.clone());
|
||||
method.borrow().call(vm, 0);
|
||||
|
||||
// resume execution
|
||||
$crate::obj::function::FunctionResult::Yield(0)
|
||||
}
|
||||
$crate::obj::function::FunctionState::Resume(0) => {
|
||||
$crate::obj::function::FunctionResult::Return
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
pub(crate) use impl_base_obj;
|
||||
pub(crate) use impl_create;
|
||||
pub(crate) use impl_do_call;
|
||||
|
||||
Reference in New Issue
Block a user