diff options
author | Freya Murphy <freya@freyacat.org> | 2024-02-29 17:04:28 -0500 |
---|---|---|
committer | Freya Murphy <freya@freyacat.org> | 2024-02-29 17:04:28 -0500 |
commit | 5d2747e26f51cc2344a6bd95f93457248fdfebd8 (patch) | |
tree | 8755b4068166c3854d26817683ce438a771ab319 /matrix-std/src/lib.rs | |
parent | more mat, sys, and os stdlib functions, better matrix printing, other fixes (diff) | |
download | matrix-5d2747e26f51cc2344a6bd95f93457248fdfebd8.tar.gz matrix-5d2747e26f51cc2344a6bd95f93457248fdfebd8.tar.bz2 matrix-5d2747e26f51cc2344a6bd95f93457248fdfebd8.zip |
fin prob
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); +} |