mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-20 18:57:17 +03:00
refactor(codemode): remove the import cycle in interpreter (#62886)
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import type { Cause } from "effect"
|
||||
import type { Interpreter } from "./interpreter.js"
|
||||
import { primitivePrototype } from "./intrinsics.js"
|
||||
import { GeneratorReturn, typeError } from "./model.js"
|
||||
@@ -14,7 +15,20 @@ import {
|
||||
type Value,
|
||||
} from "./objects.js"
|
||||
import { isOpaque, typeofValue } from "./references.js"
|
||||
import { type Eval, Interruption, isEval } from "./runner.js"
|
||||
import type { Eval } from "./runner.js"
|
||||
|
||||
/**
|
||||
* Host work that was interrupted on its own. It settles its promise like a rejection, but program code cannot catch
|
||||
* it: handlers, `catch`, and `finally` are skipped, an unobserved one is not reported, and one that reaches the
|
||||
* program's body interrupts the execution.
|
||||
*/
|
||||
export class Interruption {
|
||||
constructor(readonly cause: Cause.Cause<unknown>) {}
|
||||
}
|
||||
|
||||
// Program values never have a `next` method of their own: an object's properties live in its property map.
|
||||
export const isEval = <A>(value: A | Eval<A>): value is Eval<A> =>
|
||||
typeof value === "object" && value !== null && typeof (value as { readonly next?: unknown }).next === "function"
|
||||
|
||||
/** IteratorClose: a consumer failure closes the iterator and wins over any close failure, except that a generator's
|
||||
* return() is a return completion, so a failing close wins over it, as after `break`. */
|
||||
|
||||
@@ -107,15 +107,13 @@ import {
|
||||
type Step,
|
||||
type Value,
|
||||
} from "./objects.js"
|
||||
import { type Hint, preserveConsumerError, toPrimitive } from "./callback.js"
|
||||
import { Interruption, isEval, type Hint, preserveConsumerError, toPrimitive } from "./callback.js"
|
||||
import {
|
||||
AsyncBoundary,
|
||||
Await,
|
||||
Call,
|
||||
type Eval,
|
||||
type GeneratorRequest,
|
||||
Interruption,
|
||||
isEval,
|
||||
MAX_CALL_DEPTH,
|
||||
Runner,
|
||||
Slice,
|
||||
|
||||
@@ -3,9 +3,9 @@ import { Callable, define, get, hidden, Arr, Fn, Obj, PromiseObj, record, type V
|
||||
import { constructor, fn, methods, native, receiver, requiresNew } from "./native.js"
|
||||
import { createAggregateErrorValue, materialize } from "./errors.js"
|
||||
import { describeValue, typeofValue } from "./references.js"
|
||||
import { isSupportedCallback } from "./callback.js"
|
||||
import { Interruption, isSupportedCallback } from "./callback.js"
|
||||
import type { Interpreter } from "./interpreter.js"
|
||||
import { type Completion, type Eval, Interruption, normal, type Reaction, type Resolving, Task } from "./runner.js"
|
||||
import { type Completion, type Eval, normal, type Reaction, type Resolving, Task } from "./runner.js"
|
||||
|
||||
// A `resolve`/`reject` handed to an executor or thenable: calling it settles the capability.
|
||||
const resolvingFunctions = <R>(ctx: Interpreter<R>, resolving: Resolving) => ({
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { Cause, type Context, Effect, Exit, Fiber } from "effect"
|
||||
import type { Diagnostic } from "../codemode.js"
|
||||
import { Interruption } from "./callback.js"
|
||||
import { locate, normalizeError } from "./errors.js"
|
||||
import type { Interpreter } from "./interpreter.js"
|
||||
import { MAX_PENDING_PROMISES } from "./limits.js"
|
||||
@@ -56,15 +57,6 @@ export class Host {
|
||||
constructor(readonly effect: Effect.Effect<unknown, unknown>) {}
|
||||
}
|
||||
|
||||
/**
|
||||
* Host work that was interrupted on its own. It settles its promise like a rejection, but program code cannot catch
|
||||
* it: handlers, `catch`, and `finally` are skipped, an unobserved one is not reported, and one that reaches the
|
||||
* program's body interrupts the execution.
|
||||
*/
|
||||
export class Interruption {
|
||||
constructor(readonly cause: Cause.Cause<unknown>) {}
|
||||
}
|
||||
|
||||
/** Let the host run; the current job continues before any other job. */
|
||||
export const Slice: unique symbol = Symbol("codemode.slice")
|
||||
|
||||
@@ -134,10 +126,6 @@ export const MAX_CALL_DEPTH = 10_000
|
||||
const FUEL = 64
|
||||
const SLICE_MS = 1
|
||||
|
||||
// Program values never have a `next` method of their own: an object's properties live in its property map.
|
||||
export const isEval = <A>(value: A | Eval<A>): value is Eval<A> =>
|
||||
typeof value === "object" && value !== null && typeof (value as { readonly next?: unknown }).next === "function"
|
||||
|
||||
/**
|
||||
* One execution's job queue. Program code runs only inside a job, one job at a time and each to completion, as in a
|
||||
* JavaScript engine: promise reactions and resumed awaits queue in order, host work runs concurrently and settles its
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { applyCollectionCallback } from "../interpreter/callback.js"
|
||||
import { applyCollectionCallback, Interruption } from "../interpreter/callback.js"
|
||||
import type { Interpreter } from "../interpreter/interpreter.js"
|
||||
import { rangeError, typeError } from "../interpreter/model.js"
|
||||
import { constructor, fn, methods, receiver, requiresNew } from "../interpreter/native.js"
|
||||
@@ -16,7 +16,7 @@ import {
|
||||
type Value,
|
||||
} from "../interpreter/objects.js"
|
||||
import { describeValue } from "../interpreter/references.js"
|
||||
import { type Eval, Interruption } from "../interpreter/runner.js"
|
||||
import type { Eval } from "../interpreter/runner.js"
|
||||
|
||||
const finished: Step = { done: true, value: undefined }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user