Skip to content

Commit c38290e

Browse files
committed
run should be async
1 parent a93673e commit c38290e

File tree

6 files changed

+15
-12
lines changed

6 files changed

+15
-12
lines changed

TODO.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
`run` should be async
21
call `run` in `load`
32
rename `run/` to `load/`
43

src/commands/runCommand.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export const runCommand: Command = {
2020

2121
try {
2222
const mod = await load(url)
23-
run(mod)
23+
await run(mod)
2424
} catch (error) {
2525
if (error instanceof Error) {
2626
console.error(error.message)

src/lang/run/handleDefine.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { modDefine } from "../mod/index.ts"
44
import type { Mod } from "../mod/Mod.ts"
55
import type { Stmt } from "../stmt/Stmt.ts"
66

7-
export function handleDefine(mod: Mod, stmt: Stmt): void {
7+
export async function handleDefine(mod: Mod, stmt: Stmt): Promise<void> {
88
if (stmt.kind === "Define") {
99
const value = evaluate(mod, emptyEnv(), stmt.exp)
1010
if (value.kind === "Lambda") {

src/lang/run/handleEffect.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { readback } from "../readback/index.ts"
88
import { same } from "../same/index.ts"
99
import type { Stmt } from "../stmt/Stmt.ts"
1010

11-
export function handleEffect(mod: Mod, stmt: Stmt): void {
11+
export async function handleEffect(mod: Mod, stmt: Stmt): Promise<void> {
1212
if (stmt.kind === "AssertEqual") {
1313
if (
1414
equal(

src/lang/run/handleImport.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,21 @@ import type { ImportEntry, Stmt } from "../stmt/Stmt.ts"
44
import { globalLoadedMods } from "./globalLoadedMods.ts"
55
import { run } from "./run.ts"
66

7-
export function handleImport(mod: Mod, stmt: Stmt): void {
7+
export async function handleImport(mod: Mod, stmt: Stmt): Promise<void> {
88
if (stmt.kind === "Import") {
99
for (const entry of stmt.entries) {
10-
importOne(mod, stmt.path, entry)
10+
await importOne(mod, stmt.path, entry)
1111
}
1212

1313
return
1414
}
1515
}
1616

17-
function importOne(mod: Mod, path: string, entry: ImportEntry): void {
17+
async function importOne(
18+
mod: Mod,
19+
path: string,
20+
entry: ImportEntry,
21+
): Promise<void> {
1822
const url = modResolve(mod, path)
1923
if (url.href === mod.url.href) {
2024
throw new Error(`I can not circular import: ${path}`)
@@ -25,7 +29,7 @@ function importOne(mod: Mod, path: string, entry: ImportEntry): void {
2529
throw new Error(`Mod is not loaded: ${path}`)
2630
}
2731

28-
run(found.mod)
32+
await run(found.mod)
2933

3034
const { name, rename } = entry
3135

src/lang/run/run.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ import { handleDefine } from "./handleDefine.ts"
55
import { handleEffect } from "./handleEffect.ts"
66
import { handleImport } from "./handleImport.ts"
77

8-
export function run(mod: Mod): void {
8+
export async function run(mod: Mod): Promise<void> {
99
if (mod.isFinished) return
1010

11-
for (const stmt of mod.stmts) handleImport(mod, stmt)
12-
for (const stmt of mod.stmts) handleDefine(mod, stmt)
11+
for (const stmt of mod.stmts) await handleImport(mod, stmt)
12+
for (const stmt of mod.stmts) await handleDefine(mod, stmt)
1313

1414
for (const def of modOwnDefs(mod).values()) assertAllNamesDefined(mod, def)
1515

16-
for (const stmt of mod.stmts) handleEffect(mod, stmt)
16+
for (const stmt of mod.stmts) await handleEffect(mod, stmt)
1717

1818
mod.isFinished = true
1919
}

0 commit comments

Comments
 (0)