Make Engine faster to create.

This commit is contained in:
Stephen Chung
2023-02-25 19:57:19 +08:00
parent c2a8c342bb
commit 51581cdef5
13 changed files with 184 additions and 115 deletions

View File

@@ -459,18 +459,26 @@ impl Engine {
// See if the function match print/debug (which requires special processing)
return Ok(match name {
KEYWORD_PRINT => {
let text = result.into_immutable_string().map_err(|typ| {
let t = self.map_type_name(type_name::<ImmutableString>()).into();
ERR::ErrorMismatchOutputType(t, typ.into(), pos)
})?;
((*self.print)(&text).into(), false)
if let Some(ref print) = self.print {
let text = result.into_immutable_string().map_err(|typ| {
let t = self.map_type_name(type_name::<ImmutableString>()).into();
ERR::ErrorMismatchOutputType(t, typ.into(), pos)
})?;
((print)(&text).into(), false)
} else {
(Dynamic::UNIT, false)
}
}
KEYWORD_DEBUG => {
let text = result.into_immutable_string().map_err(|typ| {
let t = self.map_type_name(type_name::<ImmutableString>()).into();
ERR::ErrorMismatchOutputType(t, typ.into(), pos)
})?;
((*self.debug)(&text, global.source(), pos).into(), false)
if let Some(ref debug) = self.debug {
let text = result.into_immutable_string().map_err(|typ| {
let t = self.map_type_name(type_name::<ImmutableString>()).into();
ERR::ErrorMismatchOutputType(t, typ.into(), pos)
})?;
((debug)(&text, global.source(), pos).into(), false)
} else {
(Dynamic::UNIT, false)
}
}
_ => (result, is_method),
});