Skip to content

Commit

Permalink
last touches for 0.3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
WeirdConstructor committed Sep 15, 2019
1 parent b94a85e commit 91c6fe0
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "wlambda"
version = "0.3.0"
version = "0.3.1"
authors = ["Weird Constructor <[email protected]>"]
license = "GPL-3.0-or-later"
edition = "2018"
Expand Down
21 changes: 10 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<img align="left" width="60" height="60" src="http://m8geil.de/data/git/wlambda/res/wlambda_logo_60.png">


WLambda - Embeddable Scripting Language for Rust
================================================

Expand Down Expand Up @@ -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[];
Expand All @@ -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:<wlambda::eval>(Err)] \"ok\"";
_? 10; # passes the value through
!report_my_error = { displayln _ };
!report_my_error = { std:displayln _ };
!some_erroring_func = {
on_error {
Expand All @@ -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 = {
Expand Down Expand Up @@ -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| {
Expand Down Expand Up @@ -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);
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, VVal>,
}
Expand Down
12 changes: 6 additions & 6 deletions src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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 {
Expand All @@ -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) }
Expand Down Expand Up @@ -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())))
}
Expand Down
3 changes: 2 additions & 1 deletion src/vval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -1143,6 +1143,7 @@ impl VVal {
VVal::Sym(String::from(s))
}

#[allow(clippy::cast_ptr_alignment)]
pub fn ref_id(&self) -> Option<i64> {
Some(match self {
VVal::Err(r) => { &*r.borrow() as *const (VVal, SynPos) as i64 },
Expand Down

0 comments on commit 91c6fe0

Please sign in to comment.