File tree 5 files changed +82
-2
lines changed
5 files changed +82
-2
lines changed Original file line number Diff line number Diff line change 1
1
# module system
2
2
3
3
Mod -- has loader
4
-
5
4
Place and Transition -- has modId
6
5
7
6
Mod has definitions: Map<string, Definition>
8
7
9
8
# loader
10
9
11
- copy ` loader/ ` from inet-js
10
+ fix ` Loader ` -- parse and execute
12
11
13
12
# command-line
14
13
Original file line number Diff line number Diff line change
1
+ import { Loader } from "../../loader"
2
+ // import { defineBuiltins } from "../builtins/defineBuiltins"
3
+ // import { createChecking } from "../checking/createChecking"
4
+ // import { createEnv } from "../env/createEnv"
5
+ // import { Stmt } from "../stmt"
6
+ import { Mod } from "./Mod"
7
+
8
+ export function createMod ( options : {
9
+ url : URL
10
+ // text: string
11
+ // stmts: Array<Stmt>
12
+ // loader: Loader
13
+ } ) : Mod {
14
+ const mod = {
15
+ // loader: options.loader,
16
+ url : options . url ,
17
+ // text: options.text,
18
+ // stmts: options.stmts,
19
+ definitions : new Map ( ) ,
20
+ // builtins: new Map(),
21
+ // ruleEntries: new Map(),
22
+ // requiredMods: new Map(),
23
+ } as Mod
24
+
25
+ // mod.env = createEnv(mod)
26
+ // mod.checking = createChecking()
27
+
28
+ // defineBuiltins(mod)
29
+
30
+ return mod
31
+ }
Original file line number Diff line number Diff line change 1
1
export * from "./Mod"
2
+ export * from "./createMod"
Original file line number Diff line number Diff line change
1
+ import { Fetcher } from "../fetcher"
2
+ // import { execute } from "../lang/execute"
3
+ import { Mod } from "../lang/mod"
4
+ import { createMod } from "../lang/mod/createMod"
5
+ // import { parseStmts } from "../lang/syntax"
6
+
7
+ export class Loader {
8
+ loaded : Map < string , Mod > = new Map ( )
9
+ loading : Set < string > = new Set ( )
10
+ fetcher : Fetcher
11
+ onOutput = ( output : string ) => {
12
+ console . log ( output )
13
+ }
14
+
15
+ constructor ( options : { fetcher : Fetcher } ) {
16
+ this . fetcher = options . fetcher
17
+ }
18
+
19
+ async load ( url : URL , options ?: { text ?: string } ) : Promise < Mod > {
20
+ const found = this . loaded . get ( url . href )
21
+ if ( found !== undefined ) return found
22
+
23
+ const text =
24
+ options ?. text === undefined
25
+ ? await this . fetcher . fetchText ( url )
26
+ : options . text
27
+
28
+ // const stmts = parseStmts(text)
29
+ const mod = createMod ( {
30
+ // loader: this,
31
+ url,
32
+ // text,
33
+ // stmts,
34
+ } )
35
+
36
+ this . loading . add ( url . href )
37
+
38
+ // for (const stmt of stmts) {
39
+ // await execute(mod, stmt)
40
+ // }
41
+
42
+ this . loading . delete ( url . href )
43
+
44
+ this . loaded . set ( url . href , mod )
45
+
46
+ return mod
47
+ }
48
+ }
Original file line number Diff line number Diff line change
1
+ export * from "./Loader"
You can’t perform that action at this time.
0 commit comments