From f66b87708d10dd22e415e1eaab2feae80a6b0ad7 Mon Sep 17 00:00:00 2001 From: Yura Dupyn <2153100+omedusyo@users.noreply.github.com> Date: Wed, 18 Feb 2026 01:33:46 +0100 Subject: [PATCH] Update Program.udpate to hot-swap --- src/lang/program.ts | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/src/lang/program.ts b/src/lang/program.ts index 61d9ed0..ed7de18 100644 --- a/src/lang/program.ts +++ b/src/lang/program.ts @@ -3,7 +3,7 @@ import { Env, Value } from "./eval/value"; import { Expr, FunctionName, SignalName, ProductPattern, SignalExpr } from "./expr"; import { installPrimitives } from "./primitive"; import { eval_expr } from "./eval/evaluator"; -import { eval_signal_expression, spawnTick, spawnSignal, SignalRuntime, getNode, spawnSource } from "./eval/signalValue" +import { eval_signal_expression, spawnTick, spawnSignal, SignalRuntime, getNode, spawnSource, hotSwapSignal } from "./eval/signalValue" export type Timestamp = number; @@ -350,7 +350,7 @@ export namespace Program { program.signal_definitions.set(name, { tag: "user", def: newSignal }); program.signal_definition_order.push(name); - // TODO: Note that this doesn't actually evaluate the signal and doesn't insert it into signal-runtime. + // Note that this doesn't actually evaluate the signal and doesn't insert it into signal-runtime. // For that we will use `get_or_create_signal` return Result.ok(name); @@ -385,15 +385,9 @@ export namespace Program { def.raw_body = raw_body; def.lastModifiedAt = Date.now(); - // TODO: When to recompile? - // 2. CRITICAL: Invalidate the Runtime Cache - // We clear the ID so the next 'read' forces a re-compile. - // Note: This does NOT automatically update other signals that - // are currently holding a reference to the *old* signal ID. - // That requires a more complex hot-reload strategy, but this - // is the correct first step. - def.signalId = undefined; - def.is_initializing = false; + if (def.signalId !== undefined) { + hotSwapSignal(program, def.signalId, body); + } return Result.ok(undefined); }