-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
41 additions
and
2 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
[lang1] 支持 `(import)` | ||
[lang1] test `(import)` | ||
|
||
> [lang0] 支持直接递归函数与相互递归函数,不能判断等价的地方就不判断。 | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export * from "./Mod.js" | ||
export * from "./modResolve.js" | ||
export * from "./createMod.js" | ||
export * from "./modDefine.js" | ||
export * from "./modFind.js" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { type Mod } from "./index.js" | ||
|
||
export function modResolve(mod: Mod, href: string): URL { | ||
return new URL(href, mod.url) | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { modDefine, modFind, modResolve } from "../mod/index.js" | ||
import type { Mod } from "../mod/Mod.js" | ||
import type { ImportEntry } from "../stmt/Stmt.js" | ||
import { executeMod } from "./executeMod.js" | ||
|
||
export function importOne(mod: Mod, path: string, entry: ImportEntry): void { | ||
const url = modResolve(mod, path) | ||
if (url.href === mod.url.href) { | ||
throw new Error(`I can not circular import: ${path}`) | ||
} | ||
|
||
const found = mod.loadedMods.get(url.href) | ||
if (found === undefined) { | ||
throw new Error(`Mod is not loaded: ${path}`) | ||
} | ||
|
||
executeMod(found.mod) | ||
|
||
const { name, rename } = entry | ||
|
||
const def = modFind(found.mod, name) | ||
if (def === undefined) { | ||
throw new Error( | ||
`I can not import undefined name: ${name}, from path: ${path}`, | ||
) | ||
} | ||
|
||
modDefine(mod, rename || name, def) | ||
} |