Move optimization_level into Options.
This commit is contained in:
parent
1b6de25007
commit
56f6b181db
@ -201,7 +201,11 @@ impl Engine {
|
|||||||
scope: &Scope,
|
scope: &Scope,
|
||||||
scripts: impl AsRef<[S]>,
|
scripts: impl AsRef<[S]>,
|
||||||
) -> ParseResult<AST> {
|
) -> ParseResult<AST> {
|
||||||
self.compile_with_scope_and_optimization_level(scope, scripts, self.optimization_level)
|
self.compile_with_scope_and_optimization_level(
|
||||||
|
scope,
|
||||||
|
scripts,
|
||||||
|
self.options.optimization_level,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
/// Join a list of strings and compile into an [`AST`] using own scope at a specific optimization level.
|
/// Join a list of strings and compile into an [`AST`] using own scope at a specific optimization level.
|
||||||
///
|
///
|
||||||
@ -297,7 +301,12 @@ impl Engine {
|
|||||||
|
|
||||||
let mut peekable = stream.peekable();
|
let mut peekable = stream.peekable();
|
||||||
let mut state = ParseState::new(self, tokenizer_control);
|
let mut state = ParseState::new(self, tokenizer_control);
|
||||||
self.parse_global_expr(&mut peekable, &mut state, scope, self.optimization_level)
|
self.parse_global_expr(
|
||||||
|
&mut peekable,
|
||||||
|
&mut state,
|
||||||
|
scope,
|
||||||
|
self.options.optimization_level,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
/// Parse a JSON string into an [object map][crate::Map].
|
/// Parse a JSON string into an [object map][crate::Map].
|
||||||
/// This is a light-weight alternative to using, say,
|
/// This is a light-weight alternative to using, say,
|
||||||
|
@ -67,7 +67,7 @@ impl Engine {
|
|||||||
let ast = self.compile_with_scope_and_optimization_level(
|
let ast = self.compile_with_scope_and_optimization_level(
|
||||||
scope,
|
scope,
|
||||||
&[script],
|
&[script],
|
||||||
self.optimization_level,
|
self.options.optimization_level,
|
||||||
)?;
|
)?;
|
||||||
self.eval_ast_with_scope(scope, &ast)
|
self.eval_ast_with_scope(scope, &ast)
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ impl Engine {
|
|||||||
/// Not available under `no_optimize`.
|
/// Not available under `no_optimize`.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn set_optimization_level(&mut self, optimization_level: OptimizationLevel) -> &mut Self {
|
pub fn set_optimization_level(&mut self, optimization_level: OptimizationLevel) -> &mut Self {
|
||||||
self.optimization_level = optimization_level;
|
self.options.optimization_level = optimization_level;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -20,7 +20,7 @@ impl Engine {
|
|||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub const fn optimization_level(&self) -> OptimizationLevel {
|
pub const fn optimization_level(&self) -> OptimizationLevel {
|
||||||
self.optimization_level
|
self.options.optimization_level
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Optimize the [`AST`] with constants defined in an external Scope.
|
/// Optimize the [`AST`] with constants defined in an external Scope.
|
||||||
|
@ -1,12 +1,14 @@
|
|||||||
//! Settings for [`Engine`]'s language options.
|
//! Settings for [`Engine`]'s language options.
|
||||||
|
|
||||||
use crate::Engine;
|
use crate::{Engine, OptimizationLevel};
|
||||||
#[cfg(feature = "no_std")]
|
#[cfg(feature = "no_std")]
|
||||||
use std::prelude::v1::*;
|
use std::prelude::v1::*;
|
||||||
|
|
||||||
/// A type containing all language options for the [`Engine`].
|
/// A type containing all language options for the [`Engine`].
|
||||||
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
|
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
|
||||||
pub struct LanguageOptions {
|
pub struct LanguageOptions {
|
||||||
|
/// Script optimization level.
|
||||||
|
pub optimization_level: OptimizationLevel,
|
||||||
/// Is `if`-expression allowed?
|
/// Is `if`-expression allowed?
|
||||||
pub allow_if_expr: bool,
|
pub allow_if_expr: bool,
|
||||||
/// Is `switch` expression allowed?
|
/// Is `switch` expression allowed?
|
||||||
@ -33,6 +35,11 @@ impl LanguageOptions {
|
|||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub const fn new() -> Self {
|
pub const fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
#[cfg(not(feature = "no_optimize"))]
|
||||||
|
optimization_level: OptimizationLevel::Simple,
|
||||||
|
#[cfg(feature = "no_optimize")]
|
||||||
|
optimization_level: (),
|
||||||
|
|
||||||
allow_if_expr: true,
|
allow_if_expr: true,
|
||||||
allow_switch_expr: true,
|
allow_switch_expr: true,
|
||||||
allow_stmt_expr: true,
|
allow_stmt_expr: true,
|
||||||
|
@ -30,7 +30,7 @@ impl Engine {
|
|||||||
&mut stream.peekable(),
|
&mut stream.peekable(),
|
||||||
&mut state,
|
&mut state,
|
||||||
scope,
|
scope,
|
||||||
self.optimization_level,
|
self.options.optimization_level,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
self.run_ast_with_scope(scope, &ast)
|
self.run_ast_with_scope(scope, &ast)
|
||||||
|
@ -9,8 +9,7 @@ use crate::packages::{Package, StandardPackage};
|
|||||||
use crate::tokenizer::Token;
|
use crate::tokenizer::Token;
|
||||||
use crate::types::dynamic::Union;
|
use crate::types::dynamic::Union;
|
||||||
use crate::{
|
use crate::{
|
||||||
Dynamic, Identifier, ImmutableString, Module, OptimizationLevel, Position, RhaiResult, Shared,
|
Dynamic, Identifier, ImmutableString, Module, Position, RhaiResult, Shared, StaticVec,
|
||||||
StaticVec,
|
|
||||||
};
|
};
|
||||||
#[cfg(feature = "no_std")]
|
#[cfg(feature = "no_std")]
|
||||||
use std::prelude::v1::*;
|
use std::prelude::v1::*;
|
||||||
@ -129,9 +128,6 @@ pub struct Engine {
|
|||||||
#[cfg(not(feature = "unchecked"))]
|
#[cfg(not(feature = "unchecked"))]
|
||||||
pub(crate) progress: Option<Box<crate::func::native::OnProgressCallback>>,
|
pub(crate) progress: Option<Box<crate::func::native::OnProgressCallback>>,
|
||||||
|
|
||||||
/// Optimize the [`AST`][crate::AST] after compilation.
|
|
||||||
pub(crate) optimization_level: OptimizationLevel,
|
|
||||||
|
|
||||||
/// Language options.
|
/// Language options.
|
||||||
pub(crate) options: LanguageOptions,
|
pub(crate) options: LanguageOptions,
|
||||||
|
|
||||||
@ -167,9 +163,6 @@ impl fmt::Debug for Engine {
|
|||||||
#[cfg(not(feature = "unchecked"))]
|
#[cfg(not(feature = "unchecked"))]
|
||||||
f.field("progress", &self.progress.is_some());
|
f.field("progress", &self.progress.is_some());
|
||||||
|
|
||||||
#[cfg(not(feature = "no_optimize"))]
|
|
||||||
f.field("optimization_level", &self.optimization_level);
|
|
||||||
|
|
||||||
f.field("options", &self.options);
|
f.field("options", &self.options);
|
||||||
|
|
||||||
#[cfg(not(feature = "unchecked"))]
|
#[cfg(not(feature = "unchecked"))]
|
||||||
@ -274,8 +267,6 @@ impl Engine {
|
|||||||
#[cfg(not(feature = "unchecked"))]
|
#[cfg(not(feature = "unchecked"))]
|
||||||
progress: None,
|
progress: None,
|
||||||
|
|
||||||
optimization_level: OptimizationLevel::default(),
|
|
||||||
|
|
||||||
options: LanguageOptions::new(),
|
options: LanguageOptions::new(),
|
||||||
|
|
||||||
#[cfg(not(feature = "unchecked"))]
|
#[cfg(not(feature = "unchecked"))]
|
||||||
|
Loading…
Reference in New Issue
Block a user