diff options
Diffstat (limited to 'matrix-std/src/lib.rs')
-rw-r--r-- | matrix-std/src/lib.rs | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/matrix-std/src/lib.rs b/matrix-std/src/lib.rs new file mode 100644 index 0000000..af4ecab --- /dev/null +++ b/matrix-std/src/lib.rs @@ -0,0 +1,50 @@ +mod core; +mod sys; +mod math; +mod io; +mod iter; + +use matrix_lang::prelude::*; +pub(crate) type VmArgs<'a, 'b> = (&'a mut Vm, &'b mut StackFrame); + +macro_rules! error { + ($($arg:tt)*) => { + Err(::matrix_lang::prelude::exception!(::matrix_lang::prelude::RUNTIME_EXCEPTION, $($arg)*)) + }; +} + +macro_rules! next { + ($vm:expr, $frame:expr, $iter:expr) => { + $vm.run_fn($frame, $iter.clone(), vec![]) + }; +} + +macro_rules! unpack_args { + ($e:expr) => { + $e.try_into().expect("bypassed arity check") + }; +} + +macro_rules! unpack_varargs { + ($e:expr) => {{ + let mut args = $e; + let matrix_lang::prelude::Value::List(varargs) = args.pop().expect("bypassed arity check") else { + panic!("bypassed arity check") + }; + let varargs = varargs.into_inner(); + (args.try_into().expect("bypassed arity check"), varargs) + }}; +} + +pub(crate) use error; +pub(crate) use next; +pub(crate) use unpack_args; +pub(crate) use unpack_varargs; + +pub fn load(vm: &mut Vm) { + core::load(vm); + sys::load(vm); + io::load(vm); + iter::load(vm); + math::load(vm); +} |