Fine tune Engine size.
This commit is contained in:
parent
3e784d592d
commit
fa4096e91e
@ -402,7 +402,8 @@ 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
|
||||||
}
|
}
|
||||||
|
@ -363,7 +363,7 @@ impl Engine {
|
|||||||
+ SendSync
|
+ SendSync
|
||||||
+ 'static,
|
+ 'static,
|
||||||
) -> &mut Self {
|
) -> &mut Self {
|
||||||
self.debugger_interface = Some(Box::new((Box::new(init), Box::new(callback))));
|
self.debugger_interface = Some((Box::new(init), Box::new(callback)));
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -115,7 +115,7 @@ pub struct Engine {
|
|||||||
/// Custom syntax.
|
/// Custom syntax.
|
||||||
#[cfg(not(feature = "no_custom_syntax"))]
|
#[cfg(not(feature = "no_custom_syntax"))]
|
||||||
pub(crate) custom_syntax: Option<
|
pub(crate) custom_syntax: Option<
|
||||||
Box<std::collections::BTreeMap<Identifier, crate::api::custom_syntax::CustomSyntax>>,
|
Box<std::collections::BTreeMap<Identifier, Box<crate::api::custom_syntax::CustomSyntax>>>,
|
||||||
>,
|
>,
|
||||||
/// Callback closure for filtering variable definition.
|
/// Callback closure for filtering variable definition.
|
||||||
pub(crate) def_var_filter: Option<Box<OnDefVarCallback>>,
|
pub(crate) def_var_filter: Option<Box<OnDefVarCallback>>,
|
||||||
@ -147,12 +147,10 @@ pub struct Engine {
|
|||||||
|
|
||||||
/// Callback closure for debugging.
|
/// Callback closure for debugging.
|
||||||
#[cfg(feature = "debugging")]
|
#[cfg(feature = "debugging")]
|
||||||
pub(crate) debugger_interface: Option<
|
pub(crate) debugger_interface: Option<(
|
||||||
Box<(
|
|
||||||
Box<crate::eval::OnDebuggingInit>,
|
Box<crate::eval::OnDebuggingInit>,
|
||||||
Box<crate::eval::OnDebuggerCallback>,
|
Box<crate::eval::OnDebuggerCallback>,
|
||||||
)>,
|
)>,
|
||||||
>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Debug for Engine {
|
impl fmt::Debug for Engine {
|
||||||
|
@ -205,9 +205,13 @@ impl Engine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Report progress
|
// Report progress
|
||||||
self.progress
|
if let Some(ref progress) = self.progress {
|
||||||
.as_ref()
|
match progress(global.num_operations) {
|
||||||
.and_then(|p| p(global.num_operations))
|
None => Ok(()),
|
||||||
.map_or(Ok(()), |token| Err(ERR::ErrorTerminated(token, pos).into()))
|
Some(token) => Err(ERR::ErrorTerminated(token, pos).into()),
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -510,7 +510,7 @@ impl Engine {
|
|||||||
let src = global.source_raw().cloned();
|
let src = global.source_raw().cloned();
|
||||||
let src = src.as_ref().map(|s| s.as_str());
|
let src = src.as_ref().map(|s| s.as_str());
|
||||||
let context = EvalContext::new(self, global, caches, scope, this_ptr);
|
let context = EvalContext::new(self, global, caches, scope, this_ptr);
|
||||||
let (.., ref on_debugger) = **x;
|
let (.., ref on_debugger) = *x;
|
||||||
|
|
||||||
let command = on_debugger(context, event, node, src, node.position());
|
let command = on_debugger(context, event, node, src, node.position());
|
||||||
|
|
||||||
|
@ -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)
|
||||||
})?;
|
})?;
|
||||||
((print)(&text).into(), false)
|
(print(&text).into(), false)
|
||||||
} else {
|
} else {
|
||||||
(Dynamic::UNIT, false)
|
(Dynamic::UNIT, false)
|
||||||
}
|
}
|
||||||
@ -475,7 +475,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)
|
||||||
})?;
|
})?;
|
||||||
((debug)(&text, global.source(), pos).into(), false)
|
(debug(&text, global.source(), pos).into(), false)
|
||||||
} else {
|
} else {
|
||||||
(Dynamic::UNIT, false)
|
(Dynamic::UNIT, false)
|
||||||
}
|
}
|
||||||
|
@ -1139,7 +1139,7 @@ fn optimize_expr(expr: &mut Expr, state: &mut OptimizerState, _chaining: bool) {
|
|||||||
.and_then(|(f, ctx)| {
|
.and_then(|(f, ctx)| {
|
||||||
let context = ctx.then(|| (state.engine, x.name.as_str(), None, &state.global, *pos).into());
|
let context = ctx.then(|| (state.engine, x.name.as_str(), None, &state.global, *pos).into());
|
||||||
let (first, second) = arg_values.split_first_mut().unwrap();
|
let (first, second) = arg_values.split_first_mut().unwrap();
|
||||||
(f)(context, &mut [ first, &mut second[0] ]).ok()
|
f(context, &mut [ first, &mut second[0] ]).ok()
|
||||||
}) {
|
}) {
|
||||||
state.set_dirty();
|
state.set_dirty();
|
||||||
*expr = Expr::from_dynamic(result, *pos);
|
*expr = Expr::from_dynamic(result, *pos);
|
||||||
|
43
src/tests.rs
43
src/tests.rs
@ -13,6 +13,7 @@ fn check_struct_sizes() {
|
|||||||
feature = "only_i32",
|
feature = "only_i32",
|
||||||
any(feature = "no_float", feature = "f32_float")
|
any(feature = "no_float", feature = "f32_float")
|
||||||
));
|
));
|
||||||
|
const WORD_SIZE: usize = size_of::<usize>();
|
||||||
|
|
||||||
assert_eq!(size_of::<Dynamic>(), if PACKED { 8 } else { 16 });
|
assert_eq!(size_of::<Dynamic>(), if PACKED { 8 } else { 16 });
|
||||||
assert_eq!(size_of::<Option<Dynamic>>(), if PACKED { 8 } else { 16 });
|
assert_eq!(size_of::<Option<Dynamic>>(), if PACKED { 8 } else { 16 });
|
||||||
@ -20,10 +21,7 @@ fn check_struct_sizes() {
|
|||||||
size_of::<Position>(),
|
size_of::<Position>(),
|
||||||
if cfg!(feature = "no_position") { 0 } else { 4 }
|
if cfg!(feature = "no_position") { 0 } else { 4 }
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(size_of::<tokenizer::Token>(), 2 * WORD_SIZE);
|
||||||
size_of::<tokenizer::Token>(),
|
|
||||||
if IS_32_BIT { 8 } else { 16 }
|
|
||||||
);
|
|
||||||
assert_eq!(size_of::<ast::Expr>(), if PACKED { 12 } else { 16 });
|
assert_eq!(size_of::<ast::Expr>(), if PACKED { 12 } else { 16 });
|
||||||
assert_eq!(size_of::<Option<ast::Expr>>(), if PACKED { 12 } else { 16 });
|
assert_eq!(size_of::<Option<ast::Expr>>(), if PACKED { 12 } else { 16 });
|
||||||
assert_eq!(size_of::<ast::Stmt>(), if IS_32_BIT { 12 } else { 16 });
|
assert_eq!(size_of::<ast::Stmt>(), if IS_32_BIT { 12 } else { 16 });
|
||||||
@ -34,40 +32,41 @@ fn check_struct_sizes() {
|
|||||||
|
|
||||||
#[cfg(feature = "internals")]
|
#[cfg(feature = "internals")]
|
||||||
{
|
{
|
||||||
assert_eq!(
|
assert_eq!(size_of::<CallableFunction>(), 3 * WORD_SIZE);
|
||||||
size_of::<CallableFunction>(),
|
assert_eq!(size_of::<module::FuncInfo>(), 4 * WORD_SIZE);
|
||||||
if IS_32_BIT { 12 } else { 24 }
|
}
|
||||||
);
|
|
||||||
assert_eq!(
|
// The following only on 64-bit platforms
|
||||||
size_of::<module::FuncInfo>(),
|
|
||||||
if IS_32_BIT { 16 } else { 32 }
|
if !cfg!(target_pointer_width = "64") {
|
||||||
);
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_pointer_width = "64")]
|
|
||||||
{
|
|
||||||
assert_eq!(size_of::<Scope>(), 536);
|
assert_eq!(size_of::<Scope>(), 536);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
size_of::<FnPtr>(),
|
size_of::<FnPtr>(),
|
||||||
if cfg!(feature = "no_function") {
|
80 - if cfg!(feature = "no_function") {
|
||||||
72
|
WORD_SIZE
|
||||||
} else {
|
} else {
|
||||||
80
|
0
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
assert_eq!(size_of::<LexError>(), 56);
|
assert_eq!(size_of::<LexError>(), 56);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
size_of::<ParseError>(),
|
size_of::<ParseError>(),
|
||||||
if cfg!(feature = "no_position") { 8 } else { 16 }
|
16 - if cfg!(feature = "no_position") {
|
||||||
|
WORD_SIZE
|
||||||
|
} else {
|
||||||
|
0
|
||||||
|
}
|
||||||
);
|
);
|
||||||
assert_eq!(size_of::<EvalAltResult>(), 64);
|
assert_eq!(size_of::<EvalAltResult>(), 64);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
size_of::<NativeCallContext>(),
|
size_of::<NativeCallContext>(),
|
||||||
if cfg!(feature = "no_position") {
|
56 - if cfg!(feature = "no_position") {
|
||||||
48
|
WORD_SIZE
|
||||||
} else {
|
} else {
|
||||||
56
|
0
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user