From fe5f88c95ef5e5996ba0f7cb42acfd2fa046e1da Mon Sep 17 00:00:00 2001 From: Tangent Wantwight Date: Wed, 18 Oct 2023 22:54:38 -0400 Subject: [PATCH] Make Vm generic over augmented information --- src/vm.ts | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/vm.ts b/src/vm.ts index 9294a35..e0b122e 100644 --- a/src/vm.ts +++ b/src/vm.ts @@ -11,22 +11,25 @@ import { */ export type ScriptType = "action" | "render"; -export type Proc = (state: Vm, argv: TextPiece[]) => TextPiece; +export type Proc = ( + state: Vm, + argv: TextPiece[] +) => TextPiece; /** * State for running a script in. */ -export type Vm = { +export type Vm = { /** Mutability status */ mode: ScriptType; /** Implementations of commands scripts can run */ - commands: Record; + commands: Record>; /** Markup to render / output */ output: string; -}; +} & Context; -function evaluateWord( - state: Vm, +function evaluateWord( + state: Vm, word: Word | InterpolatedPiece ): TextWord | BareWord | HtmlWord { if ("bare" in word || "text" in word || "html" in word) { @@ -50,8 +53,8 @@ function evaluateWord( * @param onReturn callback optionally invoked with the return word for each top-level command (not triggered by command substitutions) * @returns the return word of the final command in the script, or empty text if the script is empty. */ -export function runNoctl( - state: Vm, +export function runNoctl( + state: Vm, script: Script, onReturn?: (word: TextPiece) => void ): TextPiece {