From 99020f3ed1c1fae123c8b8003f3644a4fc932aa3 Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Wed, 10 Mar 2021 23:37:04 +0800 Subject: [PATCH] Fix builds. --- src/ast.rs | 5 +++-- src/bin/rhai-repl.rs | 49 +++++++++++++++++--------------------------- 2 files changed, 22 insertions(+), 32 deletions(-) diff --git a/src/ast.rs b/src/ast.rs index 1e9f593c..a901ec82 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -11,6 +11,7 @@ use crate::stdlib::{ num::NonZeroUsize, ops::{Add, AddAssign}, string::String, + vec, vec::Vec, }; use crate::token::Token; @@ -244,7 +245,7 @@ impl AST { #[deprecated = "this method is volatile and may change"] #[inline(always)] pub fn statements(&self) -> &[Stmt] { - &self.statements + &self.body.statements } /// Get a mutable reference to the statements. #[cfg(not(feature = "no_optimize"))] @@ -711,7 +712,7 @@ impl AST { .chain({ #[cfg(not(feature = "no_function"))] { - self.iter_fn_def().map(|f| &f.body) + self.iter_fn_def().flat_map(|f| f.body.statements.iter()) } #[cfg(feature = "no_function")] { diff --git a/src/bin/rhai-repl.rs b/src/bin/rhai-repl.rs index 44fe90f0..fedd1dc0 100644 --- a/src/bin/rhai-repl.rs +++ b/src/bin/rhai-repl.rs @@ -1,9 +1,4 @@ -use rhai::{ - module_resolvers::FileModuleResolver, Dynamic, Engine, EvalAltResult, Module, Scope, AST, -}; - -#[cfg(not(feature = "no_optimize"))] -use rhai::OptimizationLevel; +use rhai::{Dynamic, Engine, EvalAltResult, Module, Scope, AST}; use std::{ env, @@ -65,35 +60,31 @@ fn main() { // Initialize scripting engine let mut engine = Engine::new(); - // Set a file module resolver without caching - let mut resolver = FileModuleResolver::new(); - resolver.enable_cache(false); - - engine.set_module_resolver(resolver); - - // Load init scripts - #[cfg(not(feature = "no_module"))] { + // Set a file module resolver without caching + let mut resolver = rhai::module_resolvers::FileModuleResolver::new(); + resolver.enable_cache(false); + engine.set_module_resolver(resolver); + + // Load init scripts let mut contents = String::new(); let mut has_init_scripts = false; for filename in env::args().skip(1) { - { - contents.clear(); + contents.clear(); - let mut f = match File::open(&filename) { - Err(err) => { - eprintln!("Error reading script file: {}\n{}", filename, err); - exit(1); - } - Ok(f) => f, - }; - - if let Err(err) = f.read_to_string(&mut contents) { - println!("Error reading script file: {}\n{}", filename, err); + let mut f = match File::open(&filename) { + Err(err) => { + eprintln!("Error reading script file: {}\n{}", filename, err); exit(1); } + Ok(f) => f, + }; + + if let Err(err) = f.read_to_string(&mut contents) { + println!("Error reading script file: {}\n{}", filename, err); + exit(1); } let module = match engine @@ -128,9 +119,8 @@ fn main() { } // Setup Engine - #[cfg(not(feature = "no_optimize"))] - engine.set_optimization_level(OptimizationLevel::None); + engine.set_optimization_level(rhai::OptimizationLevel::None); let mut scope = Scope::new(); @@ -143,7 +133,6 @@ fn main() { let engine = engine; // REPL loop - 'main_loop: loop { print!("rhai-repl> "); stdout().flush().expect("couldn't flush stdout"); @@ -245,7 +234,7 @@ fn main() { #[cfg(not(feature = "no_optimize"))] { - ast = engine.optimize_ast(&scope, r, OptimizationLevel::Simple); + ast = engine.optimize_ast(&scope, r, rhai::OptimizationLevel::Simple); } #[cfg(feature = "no_optimize")]