summaryrefslogtreecommitdiff
path: root/matrix-stdlib
diff options
context:
space:
mode:
Diffstat (limited to 'matrix-stdlib')
-rw-r--r--matrix-stdlib/Cargo.toml2
-rw-r--r--matrix-stdlib/src/io.rs36
-rw-r--r--matrix-stdlib/src/lib.rs15
3 files changed, 42 insertions, 11 deletions
diff --git a/matrix-stdlib/Cargo.toml b/matrix-stdlib/Cargo.toml
index 5140bfa..a892c04 100644
--- a/matrix-stdlib/Cargo.toml
+++ b/matrix-stdlib/Cargo.toml
@@ -6,3 +6,5 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
+matrix = { path = "../matrix" }
+matrix-macros = { path = "../matrix-macros" }
diff --git a/matrix-stdlib/src/io.rs b/matrix-stdlib/src/io.rs
new file mode 100644
index 0000000..288e99e
--- /dev/null
+++ b/matrix-stdlib/src/io.rs
@@ -0,0 +1,36 @@
+use matrix::{value::Value, self, vm::Vm, Result};
+use matrix_macros::native_func;
+
+#[native_func(1, true)]
+fn print(_vm: &mut Vm, args: Vec<Value>) -> Result<Value> {
+ let [values] = args.try_into().unwrap();
+ if let Value::List(list) = values {
+ for (i, value) in list.iter().enumerate() {
+ print!("{}", value.boring_print());
+ if i != 0 {
+ print!(" ");
+ }
+ }
+ }
+ Ok(Value::Nil)
+}
+
+#[native_func(1, true)]
+fn println(_vm: &mut Vm, args: Vec<Value>) -> Result<Value> {
+ let [values] = args.try_into().unwrap();
+ if let Value::List(list) = values {
+ for (i, value) in list.iter().enumerate() {
+ print!("{}", value.boring_print());
+ if i != 0 {
+ print!(" ");
+ }
+ }
+ }
+ print!("\n");
+ Ok(Value::Nil)
+}
+
+pub fn load(vm: &mut Vm) {
+ vm.load_native_fn(print());
+ vm.load_native_fn(println());
+}
diff --git a/matrix-stdlib/src/lib.rs b/matrix-stdlib/src/lib.rs
index 7d12d9a..312d397 100644
--- a/matrix-stdlib/src/lib.rs
+++ b/matrix-stdlib/src/lib.rs
@@ -1,14 +1,7 @@
-pub fn add(left: usize, right: usize) -> usize {
- left + right
-}
+use matrix::vm::Vm;
-#[cfg(test)]
-mod tests {
- use super::*;
+mod io;
- #[test]
- fn it_works() {
- let result = add(2, 2);
- assert_eq!(result, 4);
- }
+pub fn load(compiler: &mut Vm) {
+ io::load(compiler);
}