Update Program.udpate to hot-swap
This commit is contained in:
parent
49ef33f113
commit
f66b87708d
1 changed files with 5 additions and 11 deletions
|
|
@ -3,7 +3,7 @@ import { Env, Value } from "./eval/value";
|
||||||
import { Expr, FunctionName, SignalName, ProductPattern, SignalExpr } from "./expr";
|
import { Expr, FunctionName, SignalName, ProductPattern, SignalExpr } from "./expr";
|
||||||
import { installPrimitives } from "./primitive";
|
import { installPrimitives } from "./primitive";
|
||||||
import { eval_expr } from "./eval/evaluator";
|
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;
|
export type Timestamp = number;
|
||||||
|
|
||||||
|
|
@ -350,7 +350,7 @@ export namespace Program {
|
||||||
program.signal_definitions.set(name, { tag: "user", def: newSignal });
|
program.signal_definitions.set(name, { tag: "user", def: newSignal });
|
||||||
program.signal_definition_order.push(name);
|
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`
|
// For that we will use `get_or_create_signal`
|
||||||
|
|
||||||
return Result.ok(name);
|
return Result.ok(name);
|
||||||
|
|
@ -385,15 +385,9 @@ export namespace Program {
|
||||||
def.raw_body = raw_body;
|
def.raw_body = raw_body;
|
||||||
def.lastModifiedAt = Date.now();
|
def.lastModifiedAt = Date.now();
|
||||||
|
|
||||||
// TODO: When to recompile?
|
if (def.signalId !== undefined) {
|
||||||
// 2. CRITICAL: Invalidate the Runtime Cache
|
hotSwapSignal(program, def.signalId, body);
|
||||||
// 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;
|
|
||||||
|
|
||||||
return Result.ok(undefined);
|
return Result.ok(undefined);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue