Merge branch 'main' of https://github.com/rhaiscript/rhai
This commit is contained in:
commit
8215c75a17
@ -150,7 +150,7 @@ impl Parse for Module {
|
|||||||
name: ident.to_string(),
|
name: ident.to_string(),
|
||||||
typ: ty.clone(),
|
typ: ty.clone(),
|
||||||
expr: expr.as_ref().clone(),
|
expr: expr.as_ref().clone(),
|
||||||
cfg_attrs: crate::attrs::collect_cfg_attr(&attrs),
|
cfg_attrs: crate::attrs::collect_cfg_attr(attrs),
|
||||||
}),
|
}),
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
@ -167,7 +167,7 @@ impl Parse for Module {
|
|||||||
}) => custom_types.push(ExportedType {
|
}) => custom_types.push(ExportedType {
|
||||||
name: ident.to_string(),
|
name: ident.to_string(),
|
||||||
typ: ty.clone(),
|
typ: ty.clone(),
|
||||||
cfg_attrs: crate::attrs::collect_cfg_attr(&attrs),
|
cfg_attrs: crate::attrs::collect_cfg_attr(attrs),
|
||||||
}),
|
}),
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
@ -45,8 +45,8 @@ pub fn generate_body(
|
|||||||
..
|
..
|
||||||
} in consts
|
} in consts
|
||||||
{
|
{
|
||||||
let const_literal = syn::LitStr::new(&const_name, Span::call_site());
|
let const_literal = syn::LitStr::new(const_name, Span::call_site());
|
||||||
let const_ref = syn::Ident::new(&const_name, Span::call_site());
|
let const_ref = syn::Ident::new(const_name, Span::call_site());
|
||||||
|
|
||||||
let cfg_attrs: Vec<_> = cfg_attrs
|
let cfg_attrs: Vec<_> = cfg_attrs
|
||||||
.iter()
|
.iter()
|
||||||
@ -69,7 +69,7 @@ pub fn generate_body(
|
|||||||
..
|
..
|
||||||
} in custom_types
|
} in custom_types
|
||||||
{
|
{
|
||||||
let const_literal = syn::LitStr::new(&name, Span::call_site());
|
let const_literal = syn::LitStr::new(name, Span::call_site());
|
||||||
|
|
||||||
let cfg_attrs: Vec<_> = cfg_attrs
|
let cfg_attrs: Vec<_> = cfg_attrs
|
||||||
.iter()
|
.iter()
|
||||||
@ -86,7 +86,7 @@ pub fn generate_body(
|
|||||||
}
|
}
|
||||||
|
|
||||||
for item_mod in sub_modules {
|
for item_mod in sub_modules {
|
||||||
item_mod.update_scope(&parent_scope);
|
item_mod.update_scope(parent_scope);
|
||||||
if item_mod.skipped() {
|
if item_mod.skipped() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -117,7 +117,7 @@ pub fn generate_body(
|
|||||||
let mut gen_fn_tokens = Vec::new();
|
let mut gen_fn_tokens = Vec::new();
|
||||||
|
|
||||||
for function in fns {
|
for function in fns {
|
||||||
function.update_scope(&parent_scope);
|
function.update_scope(parent_scope);
|
||||||
if function.skipped() {
|
if function.skipped() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -268,7 +268,7 @@ impl Engine {
|
|||||||
|
|
||||||
// Check for data race.
|
// Check for data race.
|
||||||
#[cfg(not(feature = "no_closure"))]
|
#[cfg(not(feature = "no_closure"))]
|
||||||
crate::func::call::ensure_no_data_race(name, &mut args, false)?;
|
crate::func::call::ensure_no_data_race(name, &args, false)?;
|
||||||
|
|
||||||
let lib = &[ast.as_ref()];
|
let lib = &[ast.as_ref()];
|
||||||
let fn_def = ast
|
let fn_def = ast
|
||||||
|
@ -149,7 +149,7 @@ impl Expression<'_> {
|
|||||||
impl AsRef<Expr> for Expression<'_> {
|
impl AsRef<Expr> for Expression<'_> {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn as_ref(&self) -> &Expr {
|
fn as_ref(&self) -> &Expr {
|
||||||
&self.0
|
self.0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -158,7 +158,7 @@ impl Deref for Expression<'_> {
|
|||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn deref(&self) -> &Self::Target {
|
fn deref(&self) -> &Self::Target {
|
||||||
&self.0
|
self.0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -365,8 +365,7 @@ impl Engine {
|
|||||||
parse: Box::new(parse),
|
parse: Box::new(parse),
|
||||||
func: Box::new(func),
|
func: Box::new(func),
|
||||||
scope_may_be_changed,
|
scope_may_be_changed,
|
||||||
}
|
},
|
||||||
.into(),
|
|
||||||
);
|
);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
@ -102,8 +102,8 @@ fn map_std_type_name(name: &str, shorthands: bool) -> &str {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if name.starts_with("rhai::") {
|
if let Some(stripped) = name.strip_prefix("rhai::") {
|
||||||
map_std_type_name(&name[6..], shorthands)
|
map_std_type_name(stripped, shorthands)
|
||||||
} else {
|
} else {
|
||||||
name
|
name
|
||||||
}
|
}
|
||||||
|
@ -793,11 +793,8 @@ impl AST {
|
|||||||
|| !options.contains(ASTFlags::CONSTANT) && include_variables =>
|
|| !options.contains(ASTFlags::CONSTANT) && include_variables =>
|
||||||
{
|
{
|
||||||
let (name, expr, ..) = &**x;
|
let (name, expr, ..) = &**x;
|
||||||
if let Some(value) = expr.get_literal_value() {
|
expr.get_literal_value()
|
||||||
Some((name.as_str(), options.contains(ASTFlags::CONSTANT), value))
|
.map(|value| (name.as_str(), options.contains(ASTFlags::CONSTANT), value))
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
_ => None,
|
_ => None,
|
||||||
})
|
})
|
||||||
|
@ -215,8 +215,8 @@ impl IntoIterator for RangeCase {
|
|||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn into_iter(self) -> Self::IntoIter {
|
fn into_iter(self) -> Self::IntoIter {
|
||||||
match self {
|
match self {
|
||||||
Self::ExclusiveInt(r, ..) => Box::new(r.into_iter()),
|
Self::ExclusiveInt(r, ..) => Box::new(r),
|
||||||
Self::InclusiveInt(r, ..) => Box::new(r.into_iter()),
|
Self::InclusiveInt(r, ..) => Box::new(r),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -507,8 +507,7 @@ impl<'a> IntoIterator for &'a StmtBlock {
|
|||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn into_iter(self) -> Self::IntoIter {
|
fn into_iter(self) -> Self::IntoIter {
|
||||||
let x = self.block.iter();
|
self.block.iter()
|
||||||
x
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -335,7 +335,7 @@ impl Engine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(feature = "unchecked"))]
|
#[cfg(not(feature = "unchecked"))]
|
||||||
self.check_data_size(&r, _pos)?;
|
self.check_data_size(r, _pos)?;
|
||||||
}
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
|
@ -190,7 +190,7 @@ impl<'a, 's, 'ps, 'g, 'pg, 'c, 'pc, 't, 'pt> EvalContext<'a, 's, 'ps, 'g, 'pg, '
|
|||||||
caches,
|
caches,
|
||||||
self.lib,
|
self.lib,
|
||||||
self.this_ptr,
|
self.this_ptr,
|
||||||
&statements,
|
statements,
|
||||||
rewind_scope,
|
rewind_scope,
|
||||||
self.level,
|
self.level,
|
||||||
),
|
),
|
||||||
|
@ -99,7 +99,7 @@ impl Engine {
|
|||||||
let mut target: Target = value.clone().into();
|
let mut target: Target = value.clone().into();
|
||||||
// Module variables are constant
|
// Module variables are constant
|
||||||
target.set_access_mode(AccessMode::ReadOnly);
|
target.set_access_mode(AccessMode::ReadOnly);
|
||||||
return Ok((target.into(), *_var_pos));
|
return Ok((target, *_var_pos));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -518,6 +518,6 @@ impl Engine {
|
|||||||
#[cfg(feature = "debugging")]
|
#[cfg(feature = "debugging")]
|
||||||
global.debugger.reset_status(reset_debugger);
|
global.debugger.reset_status(reset_debugger);
|
||||||
|
|
||||||
return result;
|
result
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -161,7 +161,7 @@ impl Engine {
|
|||||||
) {
|
) {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
#[cfg(not(feature = "unchecked"))]
|
#[cfg(not(feature = "unchecked"))]
|
||||||
self.check_data_size(&args[0], root.1)?;
|
self.check_data_size(args[0], root.1)?;
|
||||||
}
|
}
|
||||||
Err(err) if matches!(*err, ERR::ErrorFunctionNotFound(ref f, ..) if f.starts_with(op_assign)) =>
|
Err(err) if matches!(*err, ERR::ErrorFunctionNotFound(ref f, ..) if f.starts_with(op_assign)) =>
|
||||||
{
|
{
|
||||||
@ -577,7 +577,7 @@ impl Engine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let condition = self
|
let condition = self
|
||||||
.eval_expr(scope, global, caches, lib, this_ptr, &expr, level)
|
.eval_expr(scope, global, caches, lib, this_ptr, expr, level)
|
||||||
.and_then(|v| {
|
.and_then(|v| {
|
||||||
v.as_bool().map_err(|typ| {
|
v.as_bool().map_err(|typ| {
|
||||||
self.make_type_mismatch_err::<bool>(typ, expr.position())
|
self.make_type_mismatch_err::<bool>(typ, expr.position())
|
||||||
@ -943,7 +943,7 @@ impl Engine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let path_result = self
|
let path_result = self
|
||||||
.eval_expr(scope, global, caches, lib, this_ptr, &expr, level)
|
.eval_expr(scope, global, caches, lib, this_ptr, expr, level)
|
||||||
.and_then(|v| {
|
.and_then(|v| {
|
||||||
let typ = v.type_name();
|
let typ = v.type_name();
|
||||||
v.try_cast::<crate::ImmutableString>().ok_or_else(|| {
|
v.try_cast::<crate::ImmutableString>().ok_or_else(|| {
|
||||||
@ -1036,6 +1036,6 @@ impl Engine {
|
|||||||
#[cfg(feature = "debugging")]
|
#[cfg(feature = "debugging")]
|
||||||
global.debugger.reset_status(reset_debugger);
|
global.debugger.reset_status(reset_debugger);
|
||||||
|
|
||||||
return result;
|
result
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -281,7 +281,7 @@ impl Engine {
|
|||||||
|
|
||||||
return args.and_then(|args| {
|
return args.and_then(|args| {
|
||||||
if !is_op_assignment {
|
if !is_op_assignment {
|
||||||
get_builtin_binary_op_fn(fn_name, &args[0], &args[1]).map(|f| {
|
get_builtin_binary_op_fn(fn_name, args[0], args[1]).map(|f| {
|
||||||
FnResolutionCacheEntry {
|
FnResolutionCacheEntry {
|
||||||
func: CallableFunction::from_method(
|
func: CallableFunction::from_method(
|
||||||
Box::new(f) as Box<FnAny>
|
Box::new(f) as Box<FnAny>
|
||||||
@ -454,7 +454,7 @@ impl Engine {
|
|||||||
// Check the data size of any `&mut` object, which may be changed.
|
// Check the data size of any `&mut` object, which may be changed.
|
||||||
#[cfg(not(feature = "unchecked"))]
|
#[cfg(not(feature = "unchecked"))]
|
||||||
if is_ref_mut && args.len() > 0 {
|
if is_ref_mut && args.len() > 0 {
|
||||||
self.check_data_size(&args[0], pos)?;
|
self.check_data_size(args[0], pos)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
// See if the function match print/debug (which requires special processing)
|
// See if the function match print/debug (which requires special processing)
|
||||||
@ -464,7 +464,7 @@ impl Engine {
|
|||||||
let t = self.map_type_name(type_name::<ImmutableString>()).into();
|
let t = self.map_type_name(type_name::<ImmutableString>()).into();
|
||||||
ERR::ErrorMismatchOutputType(t, typ.into(), pos)
|
ERR::ErrorMismatchOutputType(t, typ.into(), pos)
|
||||||
})?;
|
})?;
|
||||||
((&*self.print)(&text).into(), false)
|
((*self.print)(&text).into(), false)
|
||||||
}
|
}
|
||||||
KEYWORD_DEBUG => {
|
KEYWORD_DEBUG => {
|
||||||
let text = result.into_immutable_string().map_err(|typ| {
|
let text = result.into_immutable_string().map_err(|typ| {
|
||||||
@ -476,7 +476,7 @@ impl Engine {
|
|||||||
} else {
|
} else {
|
||||||
Some(global.source.as_str())
|
Some(global.source.as_str())
|
||||||
};
|
};
|
||||||
((&*self.debug)(&text, source, pos).into(), false)
|
((*self.debug)(&text, source, pos).into(), false)
|
||||||
}
|
}
|
||||||
_ => (result, is_method),
|
_ => (result, is_method),
|
||||||
});
|
});
|
||||||
|
@ -693,7 +693,7 @@ impl Module {
|
|||||||
#[cfg(feature = "metadata")]
|
#[cfg(feature = "metadata")]
|
||||||
comments: Box::default(),
|
comments: Box::default(),
|
||||||
},
|
},
|
||||||
func: Into::<CallableFunction>::into(fn_def).into(),
|
func: fn_def.into(),
|
||||||
param_types: StaticVec::new_const(),
|
param_types: StaticVec::new_const(),
|
||||||
}
|
}
|
||||||
.into(),
|
.into(),
|
||||||
@ -1029,7 +1029,7 @@ impl Module {
|
|||||||
#[cfg(feature = "metadata")]
|
#[cfg(feature = "metadata")]
|
||||||
comments: Box::default(),
|
comments: Box::default(),
|
||||||
},
|
},
|
||||||
func: func.into(),
|
func,
|
||||||
param_types,
|
param_types,
|
||||||
}
|
}
|
||||||
.into(),
|
.into(),
|
||||||
@ -1860,7 +1860,7 @@ impl Module {
|
|||||||
let orig_constants = std::mem::take(&mut global.constants);
|
let orig_constants = std::mem::take(&mut global.constants);
|
||||||
|
|
||||||
// Run the script
|
// Run the script
|
||||||
let result = engine.eval_ast_with_scope_raw(&mut scope, global, &ast, 0);
|
let result = engine.eval_ast_with_scope_raw(&mut scope, global, ast, 0);
|
||||||
|
|
||||||
// Create new module
|
// Create new module
|
||||||
let mut module = Module::new();
|
let mut module = Module::new();
|
||||||
|
@ -151,7 +151,7 @@ impl<'a> OptimizerState<'a> {
|
|||||||
&mut self.caches,
|
&mut self.caches,
|
||||||
lib,
|
lib,
|
||||||
fn_name,
|
fn_name,
|
||||||
calc_fn_hash(&fn_name, arg_values.len()),
|
calc_fn_hash(fn_name, arg_values.len()),
|
||||||
&mut arg_values.iter_mut().collect::<StaticVec<_>>(),
|
&mut arg_values.iter_mut().collect::<StaticVec<_>>(),
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
@ -1421,7 +1421,7 @@ pub fn optimize_into_ast(
|
|||||||
OptimizationLevel::Simple | OptimizationLevel::Full => optimize_top_level(
|
OptimizationLevel::Simple | OptimizationLevel::Full => optimize_top_level(
|
||||||
statements,
|
statements,
|
||||||
engine,
|
engine,
|
||||||
&scope,
|
scope,
|
||||||
#[cfg(not(feature = "no_function"))]
|
#[cfg(not(feature = "no_function"))]
|
||||||
&[&lib],
|
&[&lib],
|
||||||
optimization_level,
|
optimization_level,
|
||||||
|
@ -1485,7 +1485,7 @@ fn get_next_token_inner(
|
|||||||
let return_comment = return_comment || is_doc_comment(comment.as_ref().expect("`Some`"));
|
let return_comment = return_comment || is_doc_comment(comment.as_ref().expect("`Some`"));
|
||||||
|
|
||||||
if return_comment {
|
if return_comment {
|
||||||
return Some((Token::Comment(comment.expect("`Some`").into()), start_pos));
|
return Some((Token::Comment(comment.expect("`Some`")), start_pos));
|
||||||
}
|
}
|
||||||
if state.comment_level > 0 {
|
if state.comment_level > 0 {
|
||||||
// Reached EOF without ending comment block
|
// Reached EOF without ending comment block
|
||||||
|
@ -218,7 +218,7 @@ impl<'d, T: Any + Clone> Deref for DynamicReadLock<'d, T> {
|
|||||||
#[inline]
|
#[inline]
|
||||||
fn deref(&self) -> &Self::Target {
|
fn deref(&self) -> &Self::Target {
|
||||||
match self.0 {
|
match self.0 {
|
||||||
DynamicReadLockInner::Reference(ref reference) => *reference,
|
DynamicReadLockInner::Reference(reference) => reference,
|
||||||
#[cfg(not(feature = "no_closure"))]
|
#[cfg(not(feature = "no_closure"))]
|
||||||
DynamicReadLockInner::Guard(ref guard) => guard.downcast_ref().expect(CHECKED),
|
DynamicReadLockInner::Guard(ref guard) => guard.downcast_ref().expect(CHECKED),
|
||||||
}
|
}
|
||||||
|
@ -181,7 +181,7 @@ impl FnPtr {
|
|||||||
let mut arg_values = crate::StaticVec::new_const();
|
let mut arg_values = crate::StaticVec::new_const();
|
||||||
args.parse(&mut arg_values);
|
args.parse(&mut arg_values);
|
||||||
|
|
||||||
let result = self.call_raw(&context, None, arg_values)?;
|
let result = self.call_raw(context, None, arg_values)?;
|
||||||
|
|
||||||
let typ = context.engine().map_type_name(result.type_name());
|
let typ = context.engine().map_type_name(result.type_name());
|
||||||
|
|
||||||
|
@ -81,9 +81,9 @@ impl fmt::Display for Scope<'_> {
|
|||||||
#[cfg(feature = "no_closure")]
|
#[cfg(feature = "no_closure")]
|
||||||
let value_is_shared = "";
|
let value_is_shared = "";
|
||||||
|
|
||||||
write!(
|
writeln!(
|
||||||
f,
|
f,
|
||||||
"[{}] {}{}{} = {:?}\n",
|
"[{}] {}{}{} = {:?}",
|
||||||
i + 1,
|
i + 1,
|
||||||
if constant { "const " } else { "" },
|
if constant { "const " } else { "" },
|
||||||
name,
|
name,
|
||||||
|
Loading…
Reference in New Issue
Block a user