Invert event loop

This commit is contained in:
2026-10-08 08:53:11 +00:00
parent c4d0bab3d9
commit 2f21347088
12 changed files with 142 additions and 33 deletions
+30
View File
@@ -97,6 +97,36 @@ impl<'a> Emitter<'a> {
let value = operand(self, FIRST_ARG as usize, self.rep(&self.cache.protos[kind as usize]));
(format!("({} = {value}, (undefined_t){{0}})", proto_global(kind)), Type::Undefined)
}
// Keeps the fn where `jsrt_complete` finds it
Code::HostLink => {
let value = operand(self, FIRST_ARG as usize, self.rep(&self.cache.host_complete));
(format!("({HOST_COMPLETE_GLOBAL} = {value}, (undefined_t){{0}})"), Type::Undefined)
}
}
}
/// The body of `jsrt_complete(h)`: a call of the fn that the stdlib links
/// for the host, with op `h` (see `infer::host_calls()`)
pub(super) fn host_complete(&mut self) -> String {
let ty = self.cache.host_complete.clone();
let mut out = String::new();
if ty == Type::Unknown {
return out;
}
let rep = self.rep(&ty);
let operands = [(HOST_COMPLETE_GLOBAL.to_string(), rep), ("(undefined_t){0}".into(), Rep::Undefined), ("h".into(), Rep::Int)];
self.dispatch(HOST_COMPLETE_GLOBAL, &ty, "jsrt_type_error();", &mut out, |e, member, callee, rep| {
let Type::Obj(cell) = member else { return None };
let mut operands = operands.clone();
operands[0] = (callee.into(), rep);
let arg_types = [member.clone(), Type::Undefined, Type::Int];
Some(format!("{};", e.call_code(cell.code()?, HOST_COMPLETE, &arg_types, &operands).0))
});
out
}
}