Update script context handler to do less work with only fallback. Also optimize wrapped builtins too.

This commit is contained in:
microproofs
2025-01-15 18:27:43 +07:00
parent 6d2e38851e
commit a9bedda5ed
2 changed files with 79 additions and 46 deletions

View File

@@ -567,7 +567,7 @@ impl TypedValidator {
let var_purpose_arg = "__purpose_arg__";
let var_datum = "__datum__";
TypedExpr::sequence(&[
let context_handler = TypedExpr::sequence(&[
TypedExpr::let_(
TypedExpr::local_var(var_context, Type::script_context(), self.location),
TypedPattern::Constructor {
@@ -746,7 +746,29 @@ impl TypedValidator {
}))
.collect(),
},
])
]);
if self.handlers.is_empty() {
let fallback = &self.fallback;
let arg = fallback.arguments.first().unwrap();
let then = match arg.get_variable_name() {
Some(arg_name) => TypedExpr::sequence(&[
TypedExpr::let_(
TypedExpr::local_var(var_context, arg.tipo.clone(), arg.location),
TypedPattern::var(arg_name),
arg.tipo.clone(),
arg.location,
),
fallback.body.clone(),
]),
None => fallback.body.clone(),
};
then
} else {
context_handler
}
}
pub fn find_node(&self, byte_index: usize) -> Option<Located<'_>> {