Skip to content

Commit

Permalink
Merge pull request #411 from schungx/master
Browse files Browse the repository at this point in the history
Prepare for 0.20.1.
  • Loading branch information
schungx authored May 2, 2021
2 parents d579c1b + b091113 commit ee6c11e
Show file tree
Hide file tree
Showing 20 changed files with 639 additions and 352 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ Bug fixes
---------

* Fixed bug when position is zero in `insert` and `split_at` methods for arrays.
* Indexing operations with pure index values are no longer considered pure due to the possibility of indexers.

Breaking changes
----------------

* `Dynamic::is_shared` and `Dynamic::is_locked` are removed under the `no_closure` feature. They used to always return `false`.
* `Engine::call_fn` now evaluates the `AST` before calling the function.
* `Engine::on_progress` is disabled with `unchecked`.

Enhancements
------------
Expand Down
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ Rhai - Embedded Scripting for Rust

![GitHub last commit](https://img.shields.io/github/last-commit/rhaiscript/rhai?logo=github)
[![Build Status](https://github.com/rhaiscript/rhai/workflows/Build/badge.svg)](https://github.com/rhaiscript/rhai/actions)
[![stars](https://img.shields.io/github/stars/rhaiscript/rhai?logo=github)](https://github.com/rhaiscript/rhai)
[![license](https://img.shields.io/crates/l/rhai)](https://github.com/license/rhaiscript/rhai)
[![Stars](https://img.shields.io/github/stars/rhaiscript/rhai?logo=github)](https://github.com/rhaiscript/rhai)
[![License](https://img.shields.io/crates/l/rhai)](https://github.com/license/rhaiscript/rhai)
[![crates.io](https://img.shields.io/crates/v/rhai?logo=rust)](https://crates.io/crates/rhai/)
[![crates.io](https://img.shields.io/crates/d/rhai?logo=rust)](https://crates.io/crates/rhai/)
[![API Docs](https://docs.rs/rhai/badge.svg?logo=docs.rs)](https://docs.rs/rhai/)
[![chat](https://img.shields.io/discord/767611025456889857.svg?logo=discord)](https://discord.gg/HquqbYFcZ9)
[![Reddit](https://img.shields.io/reddit/subreddit-subscribers/Rhai?logo=reddit)](https://www.reddit.com/r/Rhai)
[![API Docs](https://docs.rs/rhai/badge.svg?logo=docs-rs)](https://docs.rs/rhai/)
[![VS Code plugin installs](https://img.shields.io/visual-studio-marketplace/i/rhaiscript.vscode-rhai?logo=visual-studio-code&label=vs%20code)](https://marketplace.visualstudio.com/items?itemName=rhaiscript.vscode-rhai)
[![Sublime Text package downloads](https://img.shields.io/packagecontrol/dt/Rhai.svg?logo=sublime-text&label=sublime%20text)](https://packagecontrol.io/packages/Rhai)
[![Discord Chat](https://img.shields.io/discord/767611025456889857.svg?logo=discord&label=discord)](https://discord.gg/HquqbYFcZ9)
[![Reddit Channel](https://img.shields.io/reddit/subreddit-subscribers/Rhai?logo=reddit&label=reddit)](https://www.reddit.com/r/Rhai)

[![Rhai logo](https://rhai.rs/book/images/logo/rhai-banner-transparent-colour.svg)](https://rhai.rs)

Expand Down
8 changes: 4 additions & 4 deletions benches/eval_expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ fn bench_eval_loop_number(bench: &mut Bencher) {
#[bench]
fn bench_eval_loop_strings_build(bench: &mut Bencher) {
let script = r#"
let s = "hello";
let s;
for x in range(0, 10000) {
s += "x";
s = "hello, world!" + "hello, world!";
}
"#;

Expand All @@ -143,9 +143,9 @@ fn bench_eval_loop_strings_build(bench: &mut Bencher) {
#[bench]
fn bench_eval_loop_strings_no_build(bench: &mut Bencher) {
let script = r#"
let s = "hello";
let s;
for x in range(0, 10000) {
s += "";
s = "hello" + "";
}
"#;

Expand Down
4 changes: 2 additions & 2 deletions codegen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
name = "rhai_codegen"
version = "0.3.5"
edition = "2018"
authors = ["jhwgh1968"]
description = "Procedural macro support package for Rhai, a scripting language for Rust"
authors = ["jhwgh1968", "Stephen Chung"]
description = "Procedural macros support package for Rhai, a scripting language and engine for Rust"
homepage = "https://rhai.rs/book/plugins/index.html"
repository = "https://github.com/rhaiscript/rhai"
license = "MIT OR Apache-2.0"
Expand Down
181 changes: 71 additions & 110 deletions src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -780,12 +780,8 @@ pub struct Ident {
impl fmt::Debug for Ident {
#[inline(always)]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
#[cfg(not(feature = "no_position"))]
write!(f, "{:?} @ {:?}", self.name, self.pos)?;
#[cfg(feature = "no_position")]
write!(f, "{:?}", self.name)?;

Ok(())
self.pos.debug_print(f)
}
}

Expand Down Expand Up @@ -879,10 +875,7 @@ impl fmt::Debug for StmtBlock {
#[inline(always)]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Debug::fmt(&self.0, f)?;
if !self.1.is_none() {
write!(f, " @ {:?}", self.1)?;
}
Ok(())
self.1.debug_print(f)
}
}

Expand Down Expand Up @@ -1354,13 +1347,22 @@ pub struct OpAssignment {
}

impl OpAssignment {
pub fn new(op: &'static str) -> Self {
let op2 = &op[..op.len() - 1]; // extract operator without =
/// Create a new [`OpAssignment`].
///
/// # Panics
///
/// Panics if the operator name is not an op-assignment operator.
pub fn new(op: Token) -> Self {
let op_raw = op
.map_op_assignment()
.expect("token must be an op-assignment operator")
.keyword_syntax();
let op_assignment = op.keyword_syntax();

Self {
hash_op_assign: calc_fn_hash(empty(), op, 2),
hash_op: calc_fn_hash(empty(), op2, 2),
op,
hash_op_assign: calc_fn_hash(empty(), op_assignment, 2),
hash_op: calc_fn_hash(empty(), op_raw, 2),
op: op_assignment,
}
}
}
Expand Down Expand Up @@ -1691,60 +1693,33 @@ impl Default for Expr {

impl fmt::Debug for Expr {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let mut display_pos = self.position();

match self {
#[cfg(not(feature = "no_position"))]
Self::DynamicConstant(value, pos) => write!(f, "{:?} @ {:?}", value, pos),
#[cfg(not(feature = "no_position"))]
Self::BoolConstant(value, pos) => write!(f, "{:?} @ {:?}", value, pos),
#[cfg(not(feature = "no_position"))]
Self::IntegerConstant(value, pos) => write!(f, "{:?} @ {:?}", value, pos),
#[cfg(not(feature = "no_float"))]
#[cfg(not(feature = "no_position"))]
Self::FloatConstant(value, pos) => write!(f, "{:?} @ {:?}", value, pos),
#[cfg(not(feature = "no_position"))]
Self::CharConstant(value, pos) => write!(f, "{:?} @ {:?}", value, pos),
#[cfg(not(feature = "no_position"))]
Self::StringConstant(value, pos) => write!(f, "{:?} @ {:?}", value, pos),
#[cfg(not(feature = "no_position"))]
Self::Unit(pos) => write!(f, "() @ {:?}", pos),

#[cfg(feature = "no_position")]
Self::DynamicConstant(value, _) => write!(f, "{:?}", value),
#[cfg(feature = "no_position")]
Self::BoolConstant(value, _) => write!(f, "{:?}", value),
#[cfg(feature = "no_position")]
Self::IntegerConstant(value, _) => write!(f, "{:?}", value),
#[cfg(not(feature = "no_float"))]
#[cfg(feature = "no_position")]
Self::FloatConstant(value, _) => write!(f, "{:?}", value),
#[cfg(feature = "no_position")]
Self::CharConstant(value, _) => write!(f, "{:?}", value),
#[cfg(feature = "no_position")]
Self::StringConstant(value, _) => write!(f, "{:?}", value),
#[cfg(feature = "no_position")]
Self::Unit(_) => f.write_str("()"),

Self::InterpolatedString(x) => {
f.write_str("InterpolatedString")?;
f.debug_list().entries(x.iter()).finish()
return f.debug_list().entries(x.iter()).finish();
}
Self::Array(x, _pos) => {
Self::Array(x, _) => {
f.write_str("Array")?;
f.debug_list().entries(x.iter()).finish()?;
#[cfg(not(feature = "no_position"))]
write!(f, " @ {:?}", _pos)?;
Ok(())
f.debug_list().entries(x.iter()).finish()
}
Self::Map(x, _pos) => {
Self::Map(x, _) => {
f.write_str("Map")?;
f.debug_map()
.entries(x.0.iter().map(|(k, v)| (k, v)))
.finish()?;
#[cfg(not(feature = "no_position"))]
write!(f, " @ {:?}", _pos)?;
Ok(())
.finish()
}
Self::Variable(i, _pos, x) => {
Self::Variable(i, _, x) => {
f.write_str("Variable(")?;
match x.1 {
Some((_, ref namespace)) => write!(f, "{}", namespace)?,
Expand All @@ -1755,23 +1730,14 @@ impl fmt::Debug for Expr {
Some(n) => write!(f, ", {}", n)?,
_ => (),
}
f.write_str(")")?;
#[cfg(not(feature = "no_position"))]
write!(f, " @ {:?}", _pos)?;
Ok(())
f.write_str(")")
}
#[cfg(not(feature = "no_position"))]
Self::Property(x) => write!(f, "Property({:?} @ {:?})", x.2.name, x.2.pos),
#[cfg(feature = "no_position")]
Self::Property(x) => write!(f, "Property({:?})", x.2.name),
Self::Property(x) => write!(f, "Property({})", x.2.name),
Self::Stmt(x) => {
f.write_str("Stmt")?;
f.debug_list().entries(x.0.iter()).finish()?;
#[cfg(not(feature = "no_position"))]
write!(f, " @ {:?}", x.1)?;
Ok(())
f.debug_list().entries(x.0.iter()).finish()
}
Self::FnCall(x, _pos) => {
Self::FnCall(x, _) => {
let mut ff = f.debug_struct("FnCall");
if let Some(ref ns) = x.namespace {
ff.field("namespace", ns);
Expand All @@ -1785,12 +1751,9 @@ impl fmt::Debug for Expr {
if x.capture {
ff.field("capture", &x.capture);
}
ff.finish()?;
#[cfg(not(feature = "no_position"))]
write!(f, " @ {:?}", _pos)?;
Ok(())
ff.finish()
}
Self::Dot(x, _pos) | Self::Index(x, _pos) | Self::And(x, _pos) | Self::Or(x, _pos) => {
Self::Dot(x, pos) | Self::Index(x, pos) | Self::And(x, pos) | Self::Or(x, pos) => {
let op_name = match self {
Self::Dot(_, _) => "Dot",
Self::Index(_, _) => "Index",
Expand All @@ -1799,21 +1762,17 @@ impl fmt::Debug for Expr {
_ => unreachable!(),
};

display_pos = *pos;

f.debug_struct(op_name)
.field("lhs", &x.lhs)
.field("rhs", &x.rhs)
.finish()?;
#[cfg(not(feature = "no_position"))]
write!(f, " @ {:?}", _pos)?;
Ok(())
}
Self::Custom(x, _pos) => {
f.debug_tuple("Custom").field(x).finish()?;
#[cfg(not(feature = "no_position"))]
write!(f, " @ {:?}", _pos)?;
Ok(())
.finish()
}
}
Self::Custom(x, _) => f.debug_tuple("Custom").field(x).finish(),
}?;

display_pos.debug_print(f)
}
}

Expand Down Expand Up @@ -1875,26 +1834,26 @@ impl Expr {
#[cfg(not(feature = "no_float"))]
Self::FloatConstant(_, pos) => *pos,

Self::DynamicConstant(_, pos) => *pos,
Self::BoolConstant(_, pos) => *pos,
Self::IntegerConstant(_, pos) => *pos,
Self::CharConstant(_, pos) => *pos,
Self::StringConstant(_, pos) => *pos,
Self::DynamicConstant(_, pos)
| Self::BoolConstant(_, pos)
| Self::IntegerConstant(_, pos)
| Self::CharConstant(_, pos)
| Self::Unit(pos)
| Self::StringConstant(_, pos)
| Self::Array(_, pos)
| Self::Map(_, pos)
| Self::Variable(_, pos, _)
| Self::FnCall(_, pos)
| Self::Custom(_, pos) => *pos,

Self::InterpolatedString(x) => x.first().unwrap().position(),
Self::Array(_, pos) => *pos,
Self::Map(_, pos) => *pos,

Self::Property(x) => (x.2).pos,
Self::Stmt(x) => x.1,
Self::Variable(_, pos, _) => *pos,
Self::FnCall(_, pos) => *pos,

Self::And(x, _) | Self::Or(x, _) => x.lhs.position(),

Self::Unit(pos) => *pos,

Self::Dot(x, _) | Self::Index(x, _) => x.lhs.position(),

Self::Custom(_, pos) => *pos,
Self::And(x, _) | Self::Or(x, _) | Self::Dot(x, _) | Self::Index(x, _) => {
x.lhs.position()
}
}
}
/// Override the [position][Position] of the expression.
Expand All @@ -1904,24 +1863,28 @@ impl Expr {
#[cfg(not(feature = "no_float"))]
Self::FloatConstant(_, pos) => *pos = new_pos,

Self::DynamicConstant(_, pos) => *pos = new_pos,
Self::BoolConstant(_, pos) => *pos = new_pos,
Self::IntegerConstant(_, pos) => *pos = new_pos,
Self::CharConstant(_, pos) => *pos = new_pos,
Self::StringConstant(_, pos) => *pos = new_pos,
Self::DynamicConstant(_, pos)
| Self::BoolConstant(_, pos)
| Self::IntegerConstant(_, pos)
| Self::CharConstant(_, pos)
| Self::Unit(pos)
| Self::StringConstant(_, pos)
| Self::Array(_, pos)
| Self::Map(_, pos)
| Self::And(_, pos)
| Self::Or(_, pos)
| Self::Dot(_, pos)
| Self::Index(_, pos)
| Self::Variable(_, pos, _)
| Self::FnCall(_, pos)
| Self::Custom(_, pos) => *pos = new_pos,

Self::InterpolatedString(x) => {
x.first_mut().unwrap().set_position(new_pos);
}
Self::Array(_, pos) => *pos = new_pos,
Self::Map(_, pos) => *pos = new_pos,
Self::Variable(_, pos, _) => *pos = new_pos,

Self::Property(x) => (x.2).pos = new_pos,
Self::Stmt(x) => x.1 = new_pos,
Self::FnCall(_, pos) => *pos = new_pos,
Self::And(_, pos) | Self::Or(_, pos) => *pos = new_pos,
Self::Unit(pos) => *pos = new_pos,
Self::Dot(_, pos) | Self::Index(_, pos) => *pos = new_pos,
Self::Custom(_, pos) => *pos = new_pos,
}

self
Expand All @@ -1936,9 +1899,7 @@ impl Expr {

Self::Map(x, _) => x.0.iter().map(|(_, v)| v).all(Self::is_pure),

Self::Index(x, _) | Self::And(x, _) | Self::Or(x, _) => {
x.lhs.is_pure() && x.rhs.is_pure()
}
Self::And(x, _) | Self::Or(x, _) => x.lhs.is_pure() && x.rhs.is_pure(),

Self::Stmt(x) => x.0.iter().all(Stmt::is_pure),

Expand Down
Loading

0 comments on commit ee6c11e

Please sign in to comment.