Refactored stdlib to its own crate
parent
7173c5dda1
commit
08c0cd9173
@ -1,2 +1,2 @@
|
||||
[workspace]
|
||||
members = [ "complexpr-bin", "complexpr" ]
|
||||
members = [ "complexpr-bin", "complexpr", "complexpr-stdlib" ]
|
||||
|
@ -0,0 +1,12 @@
|
||||
[package]
|
||||
name = "complexpr-stdlib"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
complexpr = { path = "../complexpr"}
|
||||
num-traits = "0.2.15"
|
||||
paste = "1.0.9"
|
||||
lazy_static = "1.4.0"
|
@ -1,6 +1,8 @@
|
||||
use std::{rc::Rc, cell::RefCell};
|
||||
|
||||
use crate::{value::{Value, func::Func}, RuntimeError, env::Environment, declare_fn};
|
||||
use complexpr::{value::{Value, func::Func}, RuntimeError, env::Environment};
|
||||
|
||||
use crate::declare_fn;
|
||||
|
||||
pub fn load(env: &mut Environment) {
|
||||
declare_fn!(env, take, 2);
|
@ -0,0 +1,16 @@
|
||||
pub mod prelude;
|
||||
pub mod io;
|
||||
pub mod iter;
|
||||
pub mod math;
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! declare_fn {
|
||||
($env:ident, $name:ident, $arg_count:literal) => {::paste::paste!{{
|
||||
let s: ::std::rc::Rc<str> = ::std::rc::Rc::from(stringify!($name));
|
||||
$env.declare(s.clone(), ::complexpr::value::Value::Func(::complexpr::value::func::Func::Builtin { func: [<fn_ $name>], arg_count: $arg_count, name: s }));
|
||||
}}};
|
||||
($env:ident, $name:literal, $rust_name:ident, $arg_count:literal) => {{
|
||||
let s: ::std::rc::Rc<str> = ::std::rc::Rc::from($name);
|
||||
$env.declare(s.clone(), ::complexpr::value::Value::Func(::complexpr::value::func::Func::Builtin { func: $rust_name, arg_count: $arg_count, name: s }));
|
||||
}};
|
||||
}
|
@ -1,22 +1,8 @@
|
||||
pub mod io;
|
||||
pub mod iter;
|
||||
pub mod math;
|
||||
|
||||
use std::{time::{SystemTime, UNIX_EPOCH}, rc::Rc, cell::RefCell};
|
||||
|
||||
use crate::{value::{Value, func::Func}, RuntimeError, env::Environment};
|
||||
use complexpr::{value::{Value, func::Func}, RuntimeError, env::Environment};
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! declare_fn {
|
||||
($env:ident, $name:ident, $arg_count:literal) => {::paste::paste!{{
|
||||
let s: ::std::rc::Rc<str> = ::std::rc::Rc::from(stringify!($name));
|
||||
$env.declare(s.clone(), $crate::value::Value::Func($crate::value::func::Func::Builtin { func: [<fn_ $name>], arg_count: $arg_count, name: s }));
|
||||
}}};
|
||||
($env:ident, $name:literal, $rust_name:ident, $arg_count:literal) => {{
|
||||
let s: ::std::rc::Rc<str> = ::std::rc::Rc::from($name);
|
||||
$env.declare(s.clone(), $crate::value::Value::Func($crate::value::func::Func::Builtin { func: $rust_name, arg_count: $arg_count, name: s }));
|
||||
}};
|
||||
}
|
||||
use crate::declare_fn;
|
||||
|
||||
pub fn load(env: &mut Environment) {
|
||||
declare_fn!(env, "type", fn_type, 1);
|
Loading…
Reference in New Issue