Skip to content

Commit

Permalink
Fix builds.
Browse files Browse the repository at this point in the history
  • Loading branch information
schungx committed Feb 19, 2024
1 parent 6fbd4fc commit 21d289a
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 35 deletions.
26 changes: 20 additions & 6 deletions src/api/compile.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Module that defines the public compilation API of [`Engine`].
use crate::parser::{ParseResult, ParseState};
use crate::{Engine, OptimizationLevel, Scope, AST};
use crate::{Engine, Scope, AST};
#[cfg(feature = "no_std")]
use std::prelude::v1::*;

Expand Down Expand Up @@ -200,28 +200,37 @@ impl Engine {
scope: &Scope,
scripts: impl AsRef<[S]>,
) -> ParseResult<AST> {
self.compile_scripts_with_scope_raw(Some(scope), scripts, self.optimization_level)
self.compile_scripts_with_scope_raw(
Some(scope),
scripts,
#[cfg(not(feature = "no_optimize"))]
self.optimization_level,
)
}
/// Join a list of strings and compile into an [`AST`] using own scope at a specific optimization level.
///
/// ## Constants Propagation
///
/// If not [`OptimizationLevel::None`], constants defined within the scope are propagated
/// If not [`OptimizationLevel::None`][`crate::OptimizationLevel::None`], constants defined within the scope are propagated
/// throughout the script _including_ functions. This allows functions to be optimized based on
/// dynamic global constants.
#[inline]
pub(crate) fn compile_scripts_with_scope_raw<S: AsRef<str>>(
&self,
scope: Option<&Scope>,
scripts: impl AsRef<[S]>,
optimization_level: OptimizationLevel,
#[cfg(not(feature = "no_optimize"))] optimization_level: crate::OptimizationLevel,
) -> ParseResult<AST> {
let (stream, tc) = self.lex(scripts.as_ref());

let input = &mut stream.peekable();
let lib = &mut <_>::default();
let state = ParseState::new(scope, input, tc.clone(), lib);
let mut _ast = self.parse(state, optimization_level)?;
let mut _ast = self.parse(
state,
#[cfg(not(feature = "no_optimize"))]
optimization_level,
)?;
#[cfg(feature = "metadata")]
{
let global_comments = &tc.borrow().global_comments;
Expand Down Expand Up @@ -296,6 +305,11 @@ impl Engine {
let lib = &mut <_>::default();
let state = ParseState::new(Some(scope), input, t, lib);

self.parse_global_expr(state, |_| {}, self.optimization_level)
self.parse_global_expr(
state,
|_| {},
#[cfg(not(feature = "no_optimize"))]
self.optimization_level,
)
}
}
10 changes: 6 additions & 4 deletions src/api/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,12 @@ impl Engine {
scope: &mut Scope,
script: &str,
) -> RhaiResultOf<T> {
let ast =
self.compile_scripts_with_scope_raw(Some(scope), [script], self.optimization_level)?;
let ast = self.compile_scripts_with_scope_raw(
Some(scope),
[script],
#[cfg(not(feature = "no_optimize"))]
self.optimization_level,
)?;
self.eval_ast_with_scope(scope, &ast)
}
/// Evaluate a string containing an expression, returning the result value or an error.
Expand Down Expand Up @@ -125,8 +129,6 @@ impl Engine {
|_| {},
#[cfg(not(feature = "no_optimize"))]
crate::OptimizationLevel::None,
#[cfg(feature = "no_optimize")]
<_>::default(),
)?
};

Expand Down
2 changes: 0 additions & 2 deletions src/api/formatting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,6 @@ impl Engine {
state,
#[cfg(not(feature = "no_optimize"))]
crate::OptimizationLevel::None,
#[cfg(feature = "no_optimize")]
(),
)?;

let guard = tc.borrow();
Expand Down
2 changes: 0 additions & 2 deletions src/api/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,6 @@ impl Engine {
|s| s.flags |= ParseSettingFlags::DISALLOW_UNQUOTED_MAP_PROPERTIES,
#[cfg(not(feature = "no_optimize"))]
crate::OptimizationLevel::None,
#[cfg(feature = "no_optimize")]
<_>::default(),
)?
};

Expand Down
6 changes: 5 additions & 1 deletion src/api/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ impl Engine {
let lib = &mut <_>::default();
let state = ParseState::new(Some(scope), input, tc, lib);

self.parse(state, self.optimization_level)?
self.parse(
state,
#[cfg(not(feature = "no_optimize"))]
self.optimization_level,
)?
};
self.run_ast_with_scope(scope, &ast)
}
Expand Down
1 change: 1 addition & 0 deletions src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ pub use stmt::{
/// _(internals)_ Empty placeholder for a script-defined function.
/// Exported under the `internals` feature only.
#[cfg(feature = "no_function")]
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash, Default)]
pub struct ScriptFuncDef;
9 changes: 4 additions & 5 deletions src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::func::native::{
use crate::packages::{Package, StandardPackage};
use crate::tokenizer::Token;
use crate::types::StringsInterner;
use crate::{Dynamic, Identifier, ImmutableString, Locked, OptimizationLevel, SharedModule};
use crate::{Dynamic, Identifier, ImmutableString, Locked, SharedModule};
#[cfg(feature = "no_std")]
use std::prelude::v1::*;
use std::{collections::BTreeSet, fmt, num::NonZeroU8};
Expand Down Expand Up @@ -131,7 +131,8 @@ pub struct Engine {
pub(crate) def_tag: Dynamic,

/// Script optimization level.
pub(crate) optimization_level: OptimizationLevel,
#[cfg(not(feature = "no_optimize"))]
pub(crate) optimization_level: crate::OptimizationLevel,

/// Max limits.
#[cfg(not(feature = "unchecked"))]
Expand Down Expand Up @@ -254,9 +255,7 @@ impl Engine {
def_tag: Dynamic::UNIT,

#[cfg(not(feature = "no_optimize"))]
optimization_level: OptimizationLevel::Simple,
#[cfg(feature = "no_optimize")]
optimization_level: (),
optimization_level: crate::OptimizationLevel::Simple,

#[cfg(not(feature = "unchecked"))]
limits: crate::api::limits::Limits::new(),
Expand Down
2 changes: 0 additions & 2 deletions src/func/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1621,8 +1621,6 @@ impl Engine {
[script],
#[cfg(not(feature = "no_optimize"))]
crate::OptimizationLevel::None,
#[cfg(feature = "no_optimize")]
<_>::default(),
)?;

// If new functions are defined within the eval string, it is an error
Expand Down
4 changes: 0 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,10 +323,6 @@ pub use module::resolvers as module_resolvers;
#[cfg(not(feature = "no_optimize"))]
pub use optimizer::OptimizationLevel;

/// Empty placeholder for the optimization level.
#[cfg(feature = "no_optimize")]
struct OptimizationLevel;

// Expose internal data structures.

#[cfg(feature = "internals")]
Expand Down
18 changes: 9 additions & 9 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ use crate::tokenizer::{
use crate::types::dynamic::{AccessMode, Union};
use crate::{
calc_fn_hash, Dynamic, Engine, EvalAltResult, EvalContext, ExclusiveRange, FnArgsVec,
ImmutableString, InclusiveRange, LexError, OptimizationLevel, ParseError, Position, Scope,
Shared, SmartString, StaticVec, ThinVec, VarDefInfo, AST, PERR,
ImmutableString, InclusiveRange, LexError, ParseError, Position, Scope, Shared, SmartString,
StaticVec, ThinVec, VarDefInfo, AST, PERR,
};
use bitflags::bitflags;
#[cfg(feature = "no_std")]
Expand Down Expand Up @@ -2156,7 +2156,7 @@ impl Engine {
(.., Expr::Variable(x, ..)) if !x.2.is_empty() => unreachable!("lhs.ns::id"),
// lhs.id
(lhs, var_expr @ Expr::Variable(..)) => {
let rhs = self.convert_expr_into_property( var_expr);
let rhs = self.convert_expr_into_property(var_expr);
Ok(Expr::Dot(BinaryExpr { lhs, rhs }.into(), op_flags, op_pos))
}
// lhs.prop
Expand Down Expand Up @@ -2232,7 +2232,7 @@ impl Engine {
// lhs.id.dot_rhs or lhs.id[idx_rhs]
Expr::Variable(..) | Expr::Property(..) => {
let new_binary = BinaryExpr {
lhs: self.convert_expr_into_property( x.lhs),
lhs: self.convert_expr_into_property(x.lhs),
rhs: x.rhs,
}
.into();
Expand Down Expand Up @@ -3796,7 +3796,7 @@ impl Engine {
&self,
mut state: ParseState,
process_settings: impl FnOnce(&mut ParseSettings),
_optimization_level: OptimizationLevel,
#[cfg(not(feature = "no_optimize"))] optimization_level: crate::OptimizationLevel,
) -> ParseResult<AST> {
let options = self.options & !LangOptions::STMT_EXPR & !LangOptions::LOOP_EXPR;

Expand Down Expand Up @@ -3828,14 +3828,14 @@ impl Engine {
statements,
#[cfg(not(feature = "no_function"))]
state.lib.values().cloned().collect::<Vec<_>>(),
_optimization_level,
optimization_level,
));

#[cfg(feature = "no_optimize")]
return Ok(AST::new(
statements,
#[cfg(not(feature = "no_function"))]
crate::Module::from(state.lib.into_values()),
crate::Module::from(state.lib.values().cloned()),
));
}

Expand Down Expand Up @@ -3906,7 +3906,7 @@ impl Engine {
pub(crate) fn parse(
&self,
mut state: ParseState,
_optimization_level: OptimizationLevel,
#[cfg(not(feature = "no_optimize"))] optimization_level: crate::OptimizationLevel,
) -> ParseResult<AST> {
let (statements, _lib) = self.parse_global_level(&mut state, |_| {})?;

Expand All @@ -3916,7 +3916,7 @@ impl Engine {
statements,
#[cfg(not(feature = "no_function"))]
_lib,
_optimization_level,
optimization_level,
));

#[cfg(feature = "no_optimize")]
Expand Down

0 comments on commit 21d289a

Please sign in to comment.