Last active
June 2, 2023 17:26
-
-
Save cowboyd/063afc68dd3b52b4056d4853c12ddd8a to your computer and use it in GitHub Desktop.
A more data oriented instruction set that allows wrapping interpreters.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import type { Operation, Provide, Resolve, Reject, Result } from "./deps.ts"; | |
export type ActionFn = (resolve: Resolve, reject: Reject) => Operation<void>; | |
export type Instruction = | |
| { | |
name: "spawn"; | |
operation(): Operation<unknown>; | |
} | |
| { | |
name: "resource"; | |
definition(provide: Provide<unknown>): Operation<unknown>; | |
} | |
| { | |
name: "action"; | |
operation(fn: ActionFn): Operation<unknown>; | |
} | |
| { | |
name: "suspend"; | |
} | |
| { | |
name: "getframe"; | |
}; | |
export interface InstructionCall { | |
// the instruction being called | |
instruction: Instruction; | |
// the frame in which this instruction is being evaluated | |
frame: Frame; | |
// the block in which this instruction is being evaluated; | |
block: Block; | |
// the nth instruction to be evaluated as part of this block. | |
index: number; | |
// a signal which will be fired if the computation is cancelled while | |
// the instruction is being evaluated. | |
signal: AbortSignal; | |
} | |
// this is the middleware, this lets you put whatever pauses, enhancements | |
// anything around every instruction that is executed by the runtime. | |
export interface Interpreter { | |
(call: InstructionCall, next: Interpreter): Computation<Result<unknown>>; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment