diff --git a/Cargo.toml b/Cargo.toml index 76292ad..32dddcb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "wlambda" -version = "0.3.0" +version = "0.3.1" authors = ["Weird Constructor "] license = "GPL-3.0-or-later" edition = "2018" diff --git a/README.md b/README.md index 413810f..712860e 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,5 @@ - WLambda - Embeddable Scripting Language for Rust ================================================ @@ -118,10 +117,10 @@ range 0 10 1 { # This is a regular function. on_error { # handle error here, eg. report, or make a new error value !(err_value, line, col, file) = @; - displayln err_value; + std:displayln err_value; } value; - !handle_err = { displayln _ }; + !handle_err = { std:displayln _ }; # with the ~ operator, you can chain it nicely: on_error {|| handle_err[_] } ~ some_erroring_func[]; @@ -133,13 +132,13 @@ range 0 10 1 { # This is a regular function. # _? transforms an error value, and returns it from the current # function. optionally jumping outwards. - wl:assert_eq (str { + std:assert_eq (str { _? ~ $e "ok"; # is with an error value the same as: `return $e "ok"` - }[]) "$e \"ok\""; + }[]) "$e[98,17:(Err)] \"ok\""; _? 10; # passes the value through -!report_my_error = { displayln _ }; +!report_my_error = { std:displayln _ }; !some_erroring_func = { on_error { @@ -158,7 +157,7 @@ range 0 10 1 { # This is a regular function. }; # Basic OOP: -# wl:weaken to make any closure capture of some_obj a weak reference, so +# std:weaken to make any closure capture of some_obj a weak reference, so # we don't get any cyclic references: !some_obj = $&${}; some_obj.do_something = { @@ -190,7 +189,7 @@ you can use the GlobalEnv `add_func` method: ``` use wlambda::vval::{VVal, VValFun, Env}; -let global_env = wlambda::prelude::create_wlamba_prelude(); +let global_env = wlambda::GlobalEnv::new_default(); global_env.borrow_mut().add_func( "my_crazy_add", |env: &mut Env, _argc: usize| { @@ -243,7 +242,7 @@ Future plans could be: - Prototyped inheritance, sketched out like this: ```norun_wlambda - !proto = ${ print = { displayln _ }, }; + !proto = ${ print = { std:displayln _ }, }; !o = to_obj ${ _proto_ = proto }; o.print(123); @@ -266,8 +265,8 @@ Future plans could be: - There are currently no plans to change the internal evaluator from a closure tree to a VM and/or JIT speedup. -However, if someone is able to significantly speed up the -evaluation this can be changed. +However, help is appreachiated if someone is able to significantly speed up the +evaluation without too much breakage. # License diff --git a/src/compiler.rs b/src/compiler.rs index 5fb253e..ebe934d 100644 --- a/src/compiler.rs +++ b/src/compiler.rs @@ -89,7 +89,7 @@ impl LocalFileModuleResolver { /// /// assert_eq!(outbuf.borrow().clone(), "1337"); ///``` -#[derive(Debug, Clone)] +#[derive(Default, Debug, Clone)] pub struct SymbolTable { symbols: std::collections::HashMap, } diff --git a/src/prelude.rs b/src/prelude.rs index c01c383..7818d21 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -1091,7 +1091,7 @@ pub fn std_symbol_table() -> SymbolTable { func!(st, "uneg", |env: &mut Env, _argc: usize| { - Ok(VVal::Int((!(env.arg(0).i() as u32)) as i64)) + Ok(VVal::Int(i64::from(!(env.arg(0).i() as u32)))) }, Some(1), Some(1)); func!(st, "push", @@ -1304,7 +1304,7 @@ pub fn std_symbol_table() -> SymbolTable { |env: &mut Env, _argc: usize| { if let VVal::Byt(u) = env.arg(0) { Ok(VVal::vec_mv( - u.borrow().iter().map(|u| VVal::Int(*u as i64)) + u.borrow().iter().map(|u| VVal::Int(i64::from(*u))) .collect())) } else { @@ -1319,9 +1319,9 @@ pub fn std_symbol_table() -> SymbolTable { Ok(VVal::new_byt( s.chars() .map(|c| - match c { '0'..='9' => ( 9 - (b'9' - (c as u8))) as i16, - 'a'..='f' => (15 - (b'f' - (c as u8))) as i16, - 'A'..='F' => (15 - (b'F' - (c as u8))) as i16, + match c { '0'..='9' => i16::from( 9 - (b'9' - (c as u8))), + 'a'..='f' => i16::from(15 - (b'f' - (c as u8))), + 'A'..='F' => i16::from(15 - (b'F' - (c as u8))), _ => -1 }) .fold((256, out), |(last, mut out), c: i16| if c == -1 { (last, out) } @@ -1489,7 +1489,7 @@ pub fn std_symbol_table() -> SymbolTable { |env: &mut Env, _argc: usize| { if !env.arg(0).b() { if env.arg(1).is_none() { - Err(StackAction::panic_msg(format!("assertion failed"))) + Err(StackAction::panic_msg("assertion failed".to_string())) } else { Err(StackAction::panic_msg(format!("assertion failed '{}'", env.arg(1).s_raw()))) } diff --git a/src/vval.rs b/src/vval.rs index 8039691..bb2d9bf 100644 --- a/src/vval.rs +++ b/src/vval.rs @@ -781,7 +781,7 @@ impl CycleCheck { } fn touch_walk(&mut self, v: &VVal) { - if let Some(_) = self.touch(v) { return; } + if self.touch(v).is_some() { return; } match v { VVal::Err(e) => self.touch_walk(&(*e).borrow().0), @@ -1143,6 +1143,7 @@ impl VVal { VVal::Sym(String::from(s)) } + #[allow(clippy::cast_ptr_alignment)] pub fn ref_id(&self) -> Option { Some(match self { VVal::Err(r) => { &*r.borrow() as *const (VVal, SynPos) as i64 },