Refactor native function registration and instantiation

Introduces `register_native` for direct registration of `NativeFunction`
and `register_native_fn` for convenience from closures. The
`Environment::run`
method is removed, and its functionality is now handled by
`Environment::instantiate`,
which packages the linked AST into an invokable `NativeFunction`. This
streamlines
the execution path and better separates compilation/linking from runtime
execution.
This commit is contained in:
Michael Schimmel
2026-02-22 11:56:46 +01:00
parent a726b79d8a
commit cb94f20c0b
7 changed files with 143 additions and 65 deletions
+2 -2
View File
@@ -8,7 +8,7 @@ pub fn register(env: &Environment) {
ret: StaticType::DateTime,
}));
env.register_native("date", date_ty, Purity::Pure, |args| {
env.register_native_fn("date", date_ty, Purity::Pure, |args| {
if let Value::Text(s) = &args[0] {
// Try parse YYYY-MM-DD
if let Ok(dt) = NaiveDate::parse_from_str(s, "%Y-%m-%d") {
@@ -32,7 +32,7 @@ pub fn register(env: &Environment) {
ret: StaticType::DateTime,
}));
env.register_native("now", now_ty, Purity::SideEffectFree, |_| {
env.register_native_fn("now", now_ty, Purity::SideEffectFree, |_| {
let ts = chrono::Utc::now().timestamp_millis();
Value::DateTime(ts)
});