Skip to content

Commit a73657f

Browse files
authored
refactor(codemode): flatten the VM into src and remove two-engine leftovers (#63377)
1 parent 3cfe63a commit a73657f

115 files changed

Lines changed: 239 additions & 306 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎packages/codemode/AGENTS.md‎

Lines changed: 2 additions & 1 deletion

‎packages/codemode/README.md‎

Lines changed: 1 addition & 1 deletion

‎packages/codemode/script/bench.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import { numberOfDFGCompiles, reoptimizationRetryCount } from "bun:jsc"
77
import { Effect, Schema } from "effect"
88
import { CodeMode, Tool } from "../src/index.js"
9-
import { Vm } from "../src/vm/vm.js"
9+
import { Vm } from "../src/vm.js"
1010

1111
const cases: ReadonlyArray<readonly [name: string, code: string]> = [
1212
[

‎packages/codemode/script/disasm.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#!/usr/bin/env bun
22

33
// The bytecode disassembler: pcs, ops, constants, handler and finally tables, local names, source lines.
4-
import { sourceLocation } from "../src/vm/runtime/model.js"
5-
import type { Code } from "../src/vm/code.js"
6-
import { compileSource } from "../src/vm/compiler/compile.js"
4+
import { sourceLocation } from "../src/runtime/model.js"
5+
import type { Code } from "../src/code.js"
6+
import { compileSource } from "../src/compiler/compile.js"
77
import {
88
BinOpSymbols,
99
CheckBaseKind,
@@ -13,8 +13,8 @@ import {
1313
OpNames,
1414
PutKind,
1515
UnaryOpSymbols,
16-
} from "../src/vm/opcodes.js"
17-
import { parseProgram } from "../src/vm/runtime/execute.js"
16+
} from "../src/opcodes.js"
17+
import { parseProgram } from "../src/runtime/execute.js"
1818

1919
const formatFlags = (flags: number): string => {
2020
const names: Array<string> = []
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
#!/usr/bin/env bun
22

3-
// Compiles the built-in sources (the prelude, the VM's internal helpers) ahead of time into src/vm/prelude/bytecode.json,
4-
// which a process loads instead of parsing and compiling them (see src/vm/prelude/bytecode.ts). Run it after changing
5-
// either source or the compiler; test/vm/prelude-bytecode.test.ts fails until then.
3+
// Compiles the built-in sources (the prelude, the VM's internal helpers) ahead of time into src/prelude/bytecode.json,
4+
// which a process loads instead of parsing and compiling them (see src/prelude/bytecode.ts). Run it after changing
5+
// either source or the compiler; test/prelude-bytecode.test.ts fails until then.
66

77
import { parse } from "acorn"
8-
import { Source } from "../src/vm/runtime/source.js"
9-
import { saveCodes } from "../src/vm/prelude/bytecode.js"
10-
import { code } from "../src/vm/prelude/source.js"
11-
import { compileSource } from "../src/vm/compiler/compile.js"
12-
import { INTERNAL_SOURCE } from "../src/vm/internal-prelude.js"
8+
import { Source } from "../src/runtime/source.js"
9+
import { saveCodes } from "../src/prelude/bytecode.js"
10+
import { code } from "../src/prelude/source.js"
11+
import { compileSource } from "../src/compiler/compile.js"
12+
import { INTERNAL_SOURCE } from "../src/internal-prelude.js"
1313

1414
export const compileBuiltins = () =>
1515
Object.fromEntries(
@@ -23,5 +23,5 @@ export const compileBuiltins = () =>
2323
)
2424

2525
if (import.meta.main) {
26-
await Bun.write(new URL("../src/vm/prelude/bytecode.json", import.meta.url), `${JSON.stringify(compileBuiltins())}\n`)
26+
await Bun.write(new URL("../src/prelude/bytecode.json", import.meta.url), `${JSON.stringify(compileBuiltins())}\n`)
2727
}

‎packages/codemode/script/setup.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
import { Effect } from "effect"
77
import { CodeMode } from "../src/index.js"
8-
import { Interpreter } from "../src/vm/runtime/interpreter.js"
9-
import { createBuiltins } from "../src/vm/runtime/intrinsics.js"
8+
import { Interpreter } from "../src/runtime/interpreter.js"
9+
import { createBuiltins } from "../src/runtime/intrinsics.js"
1010
import { ToolRuntime } from "../src/tool-runtime.js"
1111

1212
const index = process.argv.indexOf("--iterations")
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Diagnostic } from "../codemode.js"
1+
import type { Diagnostic } from "./codemode.js"
22
import { normalizeError, locate } from "./runtime/errors.js"
33
import { MAX_PENDING_PROMISES } from "./runtime/limits.js"
44
import { type AstNode, IteratorSymbol, rangeError, typeError } from "./runtime/model.js"

‎packages/codemode/src/codemode.ts‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ import type { Extension } from "./extension.js"
33
import { scanTools } from "./scan.js"
44
import { type Services, type ToolDescription, ToolRuntime } from "./tool-runtime.js"
55
import type { Tools } from "./tools.js"
6-
import { fromJson } from "./vm/data.js"
7-
import { finishExecution, resumeProgram, type Running, type Setup, startProgram, SuspendError } from "./vm/runtime/execute.js"
8-
import { extensionGlobals } from "./vm/runtime/extensions.js"
9-
import { globalNames } from "./vm/runtime/globals.js"
10-
import { fromBytes, type Snapshot, SnapshotError, type SnapshotHeader, toBytes } from "./vm/snapshot/snapshot.js"
6+
import { fromJson } from "./data.js"
7+
import { finishExecution, resumeProgram, type Running, type Setup, startProgram, SuspendError } from "./runtime/execute.js"
8+
import { extensionGlobals } from "./runtime/extensions.js"
9+
import { globalNames } from "./runtime/globals.js"
10+
import { fromBytes, type Snapshot, SnapshotError, type SnapshotHeader, toBytes } from "./snapshot/snapshot.js"
1111

1212
export { fromBytes, scanTools, SnapshotError, SuspendError, toBytes }
1313
export type { Snapshot, SnapshotHeader }
@@ -173,7 +173,7 @@ export type Runtime<R = never> = {
173173
}
174174

175175
/**
176-
* One run of a program on the VM. `run()` runs it in the current fiber until it ends or is suspended, and owns its host
176+
* One run of a program. `run()` runs it in the current fiber until it ends or is suspended, and owns its host
177177
* calls: interrupting `run()` interrupts them. A program runs once: running it again is a defect.
178178
*/
179179
export type Program<R = never, E = never> = {
File renamed without changes.

0 commit comments

Comments
 (0)