Skip to content

Commit

Permalink
[lang0] simplify assertAllNamesDefined
Browse files Browse the repository at this point in the history
  • Loading branch information
xieyuheng committed Apr 5, 2024
1 parent d63c68c commit 859dae7
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
3 changes: 2 additions & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

> 支持直接递归函数与相互递归函数,不能判断等价的地方就不判断。
[lang0] add a pass to handle `checkOccur` -- check occur to create `FnRecursive` instead of `Fn`
[lang0] add a pass to handle `checkOccur`

- check occur to create `FnRecursive` instead of `Fn`
- only in the same module for now

[lang0] `equivalent` -- `FnRecursive`
Expand Down
5 changes: 1 addition & 4 deletions src/lang0/run/assertAllNamesDefined.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import type { Definition } from "../definition/Definition.js"
import { expFreeNames } from "../exp/expFreeNames.js"
import { formatExp } from "../format/formatExp.js"
import { modFind, type Mod } from "../mod/index.js"

export function assertAllNamesDefined(mod: Mod, definition: Definition): void {
const freeNames = expFreeNames(new Set([definition.name]), definition.exp)

for (const name of freeNames) {
for (const name of definition.freeNames) {
if (modFind(mod, name) === undefined) {
throw new Error(
[
Expand Down
6 changes: 6 additions & 0 deletions src/lang0/run/checkOccur.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import type { Definition } from "../definition/index.js"
import type { Mod } from "../mod/index.js"

export function checkOccur(mod: Mod, definition: Definition): void {
//
}
4 changes: 4 additions & 0 deletions src/lang0/run/runMod.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { modOwnDefinitions, type Mod } from "../mod/index.js"
import { assertAllNamesDefined } from "./assertAllNamesDefined.js"
import { checkOccur } from "./checkOccur.js"
import { define } from "./define.js"
import { execute } from "./execute.js"

Expand All @@ -11,6 +12,9 @@ export function runMod(mod: Mod): void {
for (const definition of modOwnDefinitions(mod).values())
assertAllNamesDefined(mod, definition)

for (const definition of modOwnDefinitions(mod).values())
checkOccur(mod, definition)

for (const stmt of mod.stmts) {
const output = execute(mod, stmt)
if (output) console.log(output)
Expand Down

0 comments on commit 859dae7

Please sign in to comment.