Skip to content

Commit 324462b

Browse files
committed
re-org ADT
1 parent a03e20c commit 324462b

File tree

3 files changed

+33
-84
lines changed

3 files changed

+33
-84
lines changed

src/lang/neutral/Neutral.ts

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import { type FnRec, type Value } from "../value/index.ts"
22

33
export type Neutral = Var | Ap | ApRecursive
4-
5-
export type Var = {
6-
kind: "Var"
7-
name: string
8-
}
4+
export type Var = { kind: "Var"; name: string }
5+
export type Ap = { kind: "Ap"; target: Neutral; arg: Value }
6+
export type ApRecursive = { kind: "ApRecursive"; fn: FnRec; arg: Neutral }
97

108
export function Var(name: string): Var {
119
return {
@@ -14,12 +12,6 @@ export function Var(name: string): Var {
1412
}
1513
}
1614

17-
export type Ap = {
18-
kind: "Ap"
19-
target: Neutral
20-
arg: Value
21-
}
22-
2315
export function Ap(target: Neutral, arg: Value): Ap {
2416
return {
2517
kind: "Ap",
@@ -28,12 +20,6 @@ export function Ap(target: Neutral, arg: Value): Ap {
2820
}
2921
}
3022

31-
export type ApRecursive = {
32-
kind: "ApRecursive"
33-
fn: FnRec
34-
arg: Neutral
35-
}
36-
3723
export function ApRecursive(fn: FnRec, arg: Neutral): ApRecursive {
3824
return {
3925
kind: "ApRecursive",

src/lang/stmt/Stmt.ts

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
import { type Exp } from "../exp/Exp.ts"
22

33
export type Stmt = AssertEqual | AssertNotEqual | Compute | Define | Import
4+
export type AssertEqual = { kind: "AssertEqual"; exps: Array<Exp> }
5+
export type AssertNotEqual = { kind: "AssertNotEqual"; exps: Array<Exp> }
6+
export type Compute = { kind: "Compute"; exp: Exp }
7+
export type Define = { kind: "Define"; name: string; exp: Exp }
8+
export type Import = {
9+
kind: "Import"
10+
path: string
11+
entries: Array<ImportEntry>
12+
}
413

5-
export type AssertEqual = {
6-
kind: "AssertEqual"
7-
exps: Array<Exp>
14+
export type ImportEntry = {
15+
name: string
16+
rename?: string
817
}
918

1019
export function AssertEqual(exps: Array<Exp>): AssertEqual {
@@ -14,36 +23,20 @@ export function AssertEqual(exps: Array<Exp>): AssertEqual {
1423
}
1524
}
1625

17-
export type AssertNotEqual = {
18-
kind: "AssertNotEqual"
19-
exps: Array<Exp>
20-
}
21-
2226
export function AssertNotEqual(exps: Array<Exp>): AssertNotEqual {
2327
return {
2428
kind: "AssertNotEqual",
2529
exps,
2630
}
2731
}
2832

29-
export type Compute = {
30-
kind: "Compute"
31-
exp: Exp
32-
}
33-
3433
export function Compute(exp: Exp): Compute {
3534
return {
3635
kind: "Compute",
3736
exp,
3837
}
3938
}
4039

41-
export type Define = {
42-
kind: "Define"
43-
name: string
44-
exp: Exp
45-
}
46-
4740
export function Define(name: string, exp: Exp): Define {
4841
return {
4942
kind: "Define",
@@ -52,17 +45,6 @@ export function Define(name: string, exp: Exp): Define {
5245
}
5346
}
5447

55-
export type ImportEntry = {
56-
name: string
57-
rename?: string
58-
}
59-
60-
export type Import = {
61-
kind: "Import"
62-
path: string
63-
entries: Array<ImportEntry>
64-
}
65-
6648
export function Import(path: string, entries: Array<ImportEntry>): Import {
6749
return {
6850
kind: "Import",

src/lang/value/Value.ts

Lines changed: 18 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,16 @@ import { type Mod } from "../mod/index.ts"
44
import { type Neutral } from "../neutral/index.ts"
55

66
export type Value = NotYet | Fn | FnRec | Lazy
7-
8-
export type NotYet = {
9-
kind: "NotYet"
10-
neutral: Neutral
7+
export type NotYet = { kind: "NotYet"; neutral: Neutral }
8+
export type Lazy = { kind: "Lazy"; mod: Mod; env: Env; exp: Exp; cache?: Value }
9+
export type Fn = { kind: "Fn"; mod: Mod; env: Env; name: string; ret: Exp }
10+
export type FnRec = {
11+
kind: "FnRec"
12+
mod: Mod
13+
env: Env
14+
recName: string
15+
name: string
16+
ret: Exp
1117
}
1218

1319
export function NotYet(neutral: Neutral): NotYet {
@@ -17,12 +23,14 @@ export function NotYet(neutral: Neutral): NotYet {
1723
}
1824
}
1925

20-
export type Fn = {
21-
kind: "Fn"
22-
mod: Mod
23-
env: Env
24-
name: string
25-
ret: Exp
26+
export function Lazy(mod: Mod, env: Env, exp: Exp, cache?: Value): Lazy {
27+
return {
28+
kind: "Lazy",
29+
mod,
30+
env,
31+
exp,
32+
cache,
33+
}
2634
}
2735

2836
export function Fn(mod: Mod, env: Env, name: string, ret: Exp): Fn {
@@ -35,15 +43,6 @@ export function Fn(mod: Mod, env: Env, name: string, ret: Exp): Fn {
3543
}
3644
}
3745

38-
export type FnRec = {
39-
kind: "FnRec"
40-
mod: Mod
41-
env: Env
42-
recName: string
43-
name: string
44-
ret: Exp
45-
}
46-
4746
export function FnRec(
4847
mod: Mod,
4948
env: Env,
@@ -60,21 +59,3 @@ export function FnRec(
6059
ret,
6160
}
6261
}
63-
64-
export type Lazy = {
65-
kind: "Lazy"
66-
mod: Mod
67-
env: Env
68-
exp: Exp
69-
cache?: Value
70-
}
71-
72-
export function Lazy(mod: Mod, env: Env, exp: Exp, cache?: Value): Lazy {
73-
return {
74-
kind: "Lazy",
75-
mod,
76-
env,
77-
exp,
78-
cache,
79-
}
80-
}

0 commit comments

Comments
 (0)