aontu 0.30.1 → 0.30.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ctx.d.ts +51 -0
- package/dist/ctx.js +105 -0
- package/dist/ctx.js.map +1 -0
- package/dist/err.d.ts +12 -0
- package/dist/err.js +123 -0
- package/dist/err.js.map +1 -0
- package/dist/hints.d.ts +8 -0
- package/dist/hints.js +84 -0
- package/dist/hints.js.map +1 -0
- package/dist/lang.d.ts +11 -0
- package/dist/lang.js +569 -0
- package/dist/lang.js.map +1 -0
- package/dist/site.d.ts +12 -0
- package/dist/site.js +27 -0
- package/dist/site.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/type.d.ts +32 -0
- package/dist/type.js +16 -0
- package/dist/type.js.map +1 -0
- package/dist/unify.d.ts +14 -0
- package/dist/unify.js +156 -0
- package/dist/unify.js.map +1 -0
- package/dist/utility.d.ts +14 -0
- package/dist/utility.js +122 -0
- package/dist/utility.js.map +1 -0
- package/dist/val/BagVal.d.ts +10 -0
- package/dist/val/BagVal.js +15 -0
- package/dist/val/BagVal.js.map +1 -0
- package/dist/val/BooleanVal.d.ts +9 -0
- package/dist/val/BooleanVal.js +16 -0
- package/dist/val/BooleanVal.js.map +1 -0
- package/dist/val/CloseFuncVal.d.ts +11 -0
- package/dist/val/CloseFuncVal.js +32 -0
- package/dist/val/CloseFuncVal.js.map +1 -0
- package/dist/val/ConjunctVal.d.ts +14 -0
- package/dist/val/ConjunctVal.js +187 -0
- package/dist/val/ConjunctVal.js.map +1 -0
- package/dist/val/CopyFuncVal.d.ts +13 -0
- package/dist/val/CopyFuncVal.js +35 -0
- package/dist/val/CopyFuncVal.js.map +1 -0
- package/dist/val/DisjunctVal.d.ts +19 -0
- package/dist/val/DisjunctVal.js +194 -0
- package/dist/val/DisjunctVal.js.map +1 -0
- package/dist/val/FeatureVal.d.ts +10 -0
- package/dist/val/FeatureVal.js +29 -0
- package/dist/val/FeatureVal.js.map +1 -0
- package/dist/val/FuncBaseVal.d.ts +15 -0
- package/dist/val/FuncBaseVal.js +127 -0
- package/dist/val/FuncBaseVal.js.map +1 -0
- package/dist/val/HideFuncVal.d.ts +12 -0
- package/dist/val/HideFuncVal.js +48 -0
- package/dist/val/HideFuncVal.js.map +1 -0
- package/dist/val/IntegerVal.d.ts +9 -0
- package/dist/val/IntegerVal.js +46 -0
- package/dist/val/IntegerVal.js.map +1 -0
- package/dist/val/JunctionVal.d.ts +12 -0
- package/dist/val/JunctionVal.js +31 -0
- package/dist/val/JunctionVal.js.map +1 -0
- package/dist/val/KeyFuncVal.d.ts +12 -0
- package/dist/val/KeyFuncVal.js +34 -0
- package/dist/val/KeyFuncVal.js.map +1 -0
- package/dist/val/ListVal.d.ts +17 -0
- package/dist/val/ListVal.js +186 -0
- package/dist/val/ListVal.js.map +1 -0
- package/dist/val/LowerFuncVal.d.ts +12 -0
- package/dist/val/LowerFuncVal.js +40 -0
- package/dist/val/LowerFuncVal.js.map +1 -0
- package/dist/val/MapVal.d.ts +16 -0
- package/dist/val/MapVal.js +211 -0
- package/dist/val/MapVal.js.map +1 -0
- package/dist/val/MoveFuncVal.d.ts +11 -0
- package/dist/val/MoveFuncVal.js +41 -0
- package/dist/val/MoveFuncVal.js.map +1 -0
- package/dist/val/NilVal.d.ts +25 -0
- package/dist/val/NilVal.js +92 -0
- package/dist/val/NilVal.js.map +1 -0
- package/dist/val/NullVal.d.ts +9 -0
- package/dist/val/NullVal.js +18 -0
- package/dist/val/NullVal.js.map +1 -0
- package/dist/val/NumberVal.d.ts +9 -0
- package/dist/val/NumberVal.js +44 -0
- package/dist/val/NumberVal.js.map +1 -0
- package/dist/val/OpBaseVal.d.ts +18 -0
- package/dist/val/OpBaseVal.js +152 -0
- package/dist/val/OpBaseVal.js.map +1 -0
- package/dist/val/OpenFuncVal.d.ts +11 -0
- package/dist/val/OpenFuncVal.js +30 -0
- package/dist/val/OpenFuncVal.js.map +1 -0
- package/dist/val/PathFuncVal.d.ts +13 -0
- package/dist/val/PathFuncVal.js +42 -0
- package/dist/val/PathFuncVal.js.map +1 -0
- package/dist/val/PlusOpVal.d.ts +16 -0
- package/dist/val/PlusOpVal.js +59 -0
- package/dist/val/PlusOpVal.js.map +1 -0
- package/dist/val/PrefFuncVal.d.ts +11 -0
- package/dist/val/PrefFuncVal.js +39 -0
- package/dist/val/PrefFuncVal.js.map +1 -0
- package/dist/val/PrefVal.d.ts +15 -0
- package/dist/val/PrefVal.js +104 -0
- package/dist/val/PrefVal.js.map +1 -0
- package/dist/val/RefVal.d.ts +22 -0
- package/dist/val/RefVal.js +276 -0
- package/dist/val/RefVal.js.map +1 -0
- package/dist/val/ScalarKindVal.d.ts +16 -0
- package/dist/val/ScalarKindVal.js +76 -0
- package/dist/val/ScalarKindVal.js.map +1 -0
- package/dist/val/ScalarVal.d.ts +16 -0
- package/dist/val/ScalarVal.js +61 -0
- package/dist/val/ScalarVal.js.map +1 -0
- package/dist/val/StringVal.d.ts +10 -0
- package/dist/val/StringVal.js +19 -0
- package/dist/val/StringVal.js.map +1 -0
- package/dist/val/SuperFuncVal.d.ts +11 -0
- package/dist/val/SuperFuncVal.js +22 -0
- package/dist/val/SuperFuncVal.js.map +1 -0
- package/dist/val/TopVal.d.ts +16 -0
- package/dist/val/TopVal.js +38 -0
- package/dist/val/TopVal.js.map +1 -0
- package/dist/val/TypeFuncVal.d.ts +12 -0
- package/dist/val/TypeFuncVal.js +35 -0
- package/dist/val/TypeFuncVal.js.map +1 -0
- package/dist/val/UpperFuncVal.d.ts +12 -0
- package/dist/val/UpperFuncVal.js +40 -0
- package/dist/val/UpperFuncVal.js.map +1 -0
- package/dist/val/Val.d.ts +89 -0
- package/dist/val/Val.js +186 -0
- package/dist/val/Val.js.map +1 -0
- package/dist/val/VarVal.d.ts +13 -0
- package/dist/val/VarVal.js +109 -0
- package/dist/val/VarVal.js.map +1 -0
- package/dist/val/top.d.ts +2 -0
- package/dist/val/top.js +10 -0
- package/dist/val/top.js.map +1 -0
- package/dist/val/valutil.d.ts +2 -0
- package/dist/val/valutil.js +30 -0
- package/dist/val/valutil.js.map +1 -0
- package/package.json +3 -5
- package/src/aontu.ts +218 -0
- package/src/ctx.ts +201 -0
- package/src/err.ts +172 -0
- package/src/hints.ts +119 -0
- package/src/lang.ts +782 -0
- package/src/site.ts +34 -0
- package/src/tsconfig.json +16 -0
- package/src/type.ts +72 -0
- package/src/unify.ts +225 -0
- package/src/utility.ts +179 -0
- package/src/val/BagVal.ts +33 -0
- package/src/val/BooleanVal.ts +32 -0
- package/src/val/CloseFuncVal.ts +61 -0
- package/src/val/ConjunctVal.ts +285 -0
- package/src/val/CopyFuncVal.ts +69 -0
- package/src/val/DisjunctVal.ts +288 -0
- package/src/val/FeatureVal.ts +56 -0
- package/src/val/FuncBaseVal.ts +198 -0
- package/src/val/HideFuncVal.ts +85 -0
- package/src/val/IntegerVal.ts +75 -0
- package/src/val/JunctionVal.ts +54 -0
- package/src/val/KeyFuncVal.ts +67 -0
- package/src/val/ListVal.ts +286 -0
- package/src/val/LowerFuncVal.ts +73 -0
- package/src/val/MapVal.ts +316 -0
- package/src/val/MoveFuncVal.ts +79 -0
- package/src/val/NilVal.ts +156 -0
- package/src/val/NullVal.ts +38 -0
- package/src/val/NumberVal.ts +75 -0
- package/src/val/OpBaseVal.ts +231 -0
- package/src/val/OpenFuncVal.ts +60 -0
- package/src/val/PathFuncVal.ts +75 -0
- package/src/val/PlusOpVal.ts +92 -0
- package/src/val/PrefFuncVal.ts +73 -0
- package/src/val/PrefVal.ts +159 -0
- package/src/val/RefVal.ts +384 -0
- package/src/val/ScalarKindVal.ts +125 -0
- package/src/val/ScalarVal.ts +105 -0
- package/src/val/StringVal.ts +37 -0
- package/src/val/SuperFuncVal.ts +46 -0
- package/src/val/TopVal.ts +69 -0
- package/src/val/TypeFuncVal.ts +69 -0
- package/src/val/UpperFuncVal.ts +72 -0
- package/src/val/Val.ts +294 -0
- package/src/val/VarVal.ts +171 -0
- package/src/val/top.ts +12 -0
- package/src/val/valutil.ts +31 -0
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/* Copyright (c) 2021-2025 Richard Rodger, MIT License */
|
|
2
|
+
|
|
3
|
+
import type {
|
|
4
|
+
Val,
|
|
5
|
+
ValSpec,
|
|
6
|
+
} from '../type'
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
DONE,
|
|
10
|
+
} from '../type'
|
|
11
|
+
|
|
12
|
+
import {
|
|
13
|
+
AontuContext,
|
|
14
|
+
} from '../ctx'
|
|
15
|
+
|
|
16
|
+
import {
|
|
17
|
+
explainOpen,
|
|
18
|
+
explainClose,
|
|
19
|
+
} from '../utility'
|
|
20
|
+
|
|
21
|
+
import { makeNilErr, AontuError } from '../err'
|
|
22
|
+
|
|
23
|
+
// import { BaseVal } from './BaseVal'
|
|
24
|
+
import { FeatureVal } from './FeatureVal'
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
// A ScalarKind for integers. Number includes floats.
|
|
28
|
+
class Integer { }
|
|
29
|
+
|
|
30
|
+
// A ScalarKind for null.
|
|
31
|
+
class Null { }
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
type ScalarConstructor =
|
|
35
|
+
StringConstructor |
|
|
36
|
+
NumberConstructor |
|
|
37
|
+
BooleanConstructor |
|
|
38
|
+
(typeof Integer.constructor)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
// class ScalarKindVal extends BaseVal {
|
|
42
|
+
class ScalarKindVal extends FeatureVal {
|
|
43
|
+
isScalarKind = true
|
|
44
|
+
|
|
45
|
+
constructor(
|
|
46
|
+
spec: ValSpec,
|
|
47
|
+
ctx?: AontuContext
|
|
48
|
+
) {
|
|
49
|
+
super(spec, ctx)
|
|
50
|
+
|
|
51
|
+
if (null == this.peg) {
|
|
52
|
+
throw new AontuError('ScalarKindVal spec.peg undefined')
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
this.dc = DONE
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
unify(peer: Val, ctx: AontuContext): Val {
|
|
60
|
+
const te = ctx.explain && explainOpen(ctx, ctx.explain, 'ScalarKind', this, peer)
|
|
61
|
+
|
|
62
|
+
const peerIsScalarVal = peer.isScalar
|
|
63
|
+
const peerIsScalarKind = (peer as ScalarKindVal).isScalarKind
|
|
64
|
+
|
|
65
|
+
let out: Val = this
|
|
66
|
+
|
|
67
|
+
if (peerIsScalarVal) {
|
|
68
|
+
let peerKind = (peer as any).kind
|
|
69
|
+
|
|
70
|
+
if (peerKind === this.peg) {
|
|
71
|
+
out = peer
|
|
72
|
+
}
|
|
73
|
+
else if (Number === this.peg && Integer === peerKind) {
|
|
74
|
+
out = peer
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
out = makeNilErr(ctx, 'no-scalar-unify', this, peer)
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
else if (peerIsScalarKind) {
|
|
81
|
+
if (Number === this.peg && Integer === peer.peg) {
|
|
82
|
+
out = peer
|
|
83
|
+
}
|
|
84
|
+
else if (Number === peer.peg && Integer === this.peg) {
|
|
85
|
+
out = this
|
|
86
|
+
}
|
|
87
|
+
else if (this.peg === peer.peg) {
|
|
88
|
+
out = this
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
out = makeNilErr(ctx, 'scalar-type', this, peer)
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
out = makeNilErr(ctx, 'not-scalar-type', this, peer)
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
ctx.explain && explainClose(te, out)
|
|
99
|
+
|
|
100
|
+
// console.log('SCALARKINDVAL', this.canon.peer.canon, '->', out.canon)
|
|
101
|
+
return out
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
get canon() {
|
|
106
|
+
let ctor = (this.peg as any)
|
|
107
|
+
return ctor.name.toLowerCase()
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
same(peer: any): boolean {
|
|
112
|
+
let out = peer?.isScalarKind ? this.peg === peer?.peg : super.same(peer)
|
|
113
|
+
return out
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
export {
|
|
121
|
+
Integer,
|
|
122
|
+
Null,
|
|
123
|
+
ScalarConstructor,
|
|
124
|
+
ScalarKindVal,
|
|
125
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/* Copyright (c) 2021-2025 Richard Rodger, MIT License */
|
|
2
|
+
|
|
3
|
+
import type {
|
|
4
|
+
ValSpec,
|
|
5
|
+
} from '../type'
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
DONE,
|
|
9
|
+
} from '../type'
|
|
10
|
+
|
|
11
|
+
import {
|
|
12
|
+
AontuContext,
|
|
13
|
+
} from '../ctx'
|
|
14
|
+
|
|
15
|
+
import {
|
|
16
|
+
explainOpen,
|
|
17
|
+
explainClose,
|
|
18
|
+
} from '../utility'
|
|
19
|
+
|
|
20
|
+
import { makeNilErr } from '../err'
|
|
21
|
+
|
|
22
|
+
import { Val } from './Val'
|
|
23
|
+
import { ScalarKindVal } from './ScalarKindVal'
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class ScalarVal extends Val {
|
|
28
|
+
kind: any
|
|
29
|
+
isScalar = true
|
|
30
|
+
src: string
|
|
31
|
+
|
|
32
|
+
constructor(
|
|
33
|
+
spec: ValSpec,
|
|
34
|
+
ctx?: AontuContext
|
|
35
|
+
) {
|
|
36
|
+
super(spec, ctx)
|
|
37
|
+
this.kind = spec.kind
|
|
38
|
+
this.src = spec.src ?? ''
|
|
39
|
+
this.dc = DONE
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
clone(ctx: AontuContext, spec?: ValSpec): Val {
|
|
44
|
+
let out = super.clone(ctx, {
|
|
45
|
+
peg: this.peg,
|
|
46
|
+
kind: this.kind,
|
|
47
|
+
...(spec || {})
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
return out
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
unify(peer: Val, ctx: AontuContext): Val {
|
|
55
|
+
const te = ctx.explain && explainOpen(ctx, ctx.explain, 'Scalar', this, peer)
|
|
56
|
+
|
|
57
|
+
let out: Val
|
|
58
|
+
|
|
59
|
+
// Exactly equal scalars are handled in unify.unite
|
|
60
|
+
if (peer.isScalarKind) {
|
|
61
|
+
out = peer.unify(this, ctx)
|
|
62
|
+
}
|
|
63
|
+
else if (peer.isTop) {
|
|
64
|
+
out = this
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
out = makeNilErr(ctx, 'scalar_' +
|
|
68
|
+
((peer as any).kind === this.kind ? 'value' : 'kind'), this, peer)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
explainClose(te, out)
|
|
72
|
+
|
|
73
|
+
return out
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
get canon() {
|
|
78
|
+
return null === this.peg ? 'null' :
|
|
79
|
+
undefined === this.peg ? 'undefined' :
|
|
80
|
+
(this.peg as any).toString()
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
same(peer: any): boolean {
|
|
85
|
+
return peer?.isScalar ? peer.peg === this.peg : super.same(peer)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
gen(_ctx?: AontuContext) {
|
|
90
|
+
return this.peg
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
superior() {
|
|
95
|
+
return this.place(new ScalarKindVal({
|
|
96
|
+
peg: this.kind
|
|
97
|
+
}))
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
export {
|
|
104
|
+
ScalarVal,
|
|
105
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/* Copyright (c) 2021-2025 Richard Rodger, MIT License */
|
|
2
|
+
|
|
3
|
+
import type {
|
|
4
|
+
Val,
|
|
5
|
+
ValSpec,
|
|
6
|
+
} from '../type'
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
AontuContext,
|
|
10
|
+
} from '../ctx'
|
|
11
|
+
|
|
12
|
+
import { ScalarVal } from './ScalarVal'
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class StringVal extends ScalarVal {
|
|
16
|
+
isString = true
|
|
17
|
+
|
|
18
|
+
constructor(
|
|
19
|
+
spec: ValSpec,
|
|
20
|
+
ctx?: AontuContext
|
|
21
|
+
) {
|
|
22
|
+
super({ peg: spec.peg, kind: String }, ctx)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
unify(peer: Val, ctx: AontuContext): Val {
|
|
26
|
+
return super.unify(peer, ctx)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
get canon() {
|
|
30
|
+
return JSON.stringify(this.peg)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export {
|
|
36
|
+
StringVal,
|
|
37
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/* Copyright (c) 2021-2025 Richard Rodger, MIT License */
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
import type {
|
|
5
|
+
Val,
|
|
6
|
+
ValSpec,
|
|
7
|
+
} from '../type'
|
|
8
|
+
|
|
9
|
+
import {
|
|
10
|
+
AontuContext,
|
|
11
|
+
} from '../ctx'
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
import { FuncBaseVal } from './FuncBaseVal'
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class SuperFuncVal extends FuncBaseVal {
|
|
18
|
+
isSuperFunc = true
|
|
19
|
+
|
|
20
|
+
constructor(
|
|
21
|
+
spec: ValSpec,
|
|
22
|
+
ctx?: AontuContext
|
|
23
|
+
) {
|
|
24
|
+
super(spec, ctx)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
make(_ctx: AontuContext, spec: ValSpec): Val {
|
|
29
|
+
return new SuperFuncVal(spec)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
funcname() {
|
|
33
|
+
return 'super'
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
resolve(_ctx: AontuContext, _args: Val[]) {
|
|
38
|
+
return this.place(this.superior())
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
export {
|
|
45
|
+
SuperFuncVal,
|
|
46
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/* Copyright (c) 2021-2025 Richard Rodger, MIT License */
|
|
2
|
+
|
|
3
|
+
import { inspect } from 'node:util'
|
|
4
|
+
|
|
5
|
+
import type {
|
|
6
|
+
ValSpec,
|
|
7
|
+
} from '../type'
|
|
8
|
+
|
|
9
|
+
import {
|
|
10
|
+
DONE,
|
|
11
|
+
} from '../type'
|
|
12
|
+
|
|
13
|
+
import {
|
|
14
|
+
AontuContext,
|
|
15
|
+
} from '../ctx'
|
|
16
|
+
|
|
17
|
+
import {
|
|
18
|
+
Val
|
|
19
|
+
} from './Val'
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
// There can be only one.
|
|
23
|
+
class TopVal extends Val {
|
|
24
|
+
isTop = true
|
|
25
|
+
|
|
26
|
+
id = 0
|
|
27
|
+
dc = DONE
|
|
28
|
+
|
|
29
|
+
constructor(
|
|
30
|
+
spec: ValSpec,
|
|
31
|
+
ctx?: AontuContext
|
|
32
|
+
) {
|
|
33
|
+
super(spec, ctx)
|
|
34
|
+
|
|
35
|
+
// TOP is always DONE, by definition.
|
|
36
|
+
this.dc = DONE
|
|
37
|
+
this.mark.type = false
|
|
38
|
+
this.mark.hide = false
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
same(peer: Val): boolean {
|
|
42
|
+
// return this === peer
|
|
43
|
+
return peer.isTop
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
unify(peer: Val, _ctx?: AontuContext): Val {
|
|
47
|
+
return peer
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
get canon() { return 'top' }
|
|
51
|
+
|
|
52
|
+
superior(): Val {
|
|
53
|
+
return this
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
clone(_ctx: AontuContext, _spec?: ValSpec) {
|
|
57
|
+
return this
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
gen(_ctx?: AontuContext) {
|
|
61
|
+
return undefined
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
export {
|
|
68
|
+
TopVal,
|
|
69
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/* Copyright (c) 2021-2025 Richard Rodger, MIT License */
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
import type {
|
|
5
|
+
Val,
|
|
6
|
+
ValSpec,
|
|
7
|
+
} from '../type'
|
|
8
|
+
|
|
9
|
+
import {
|
|
10
|
+
AontuContext,
|
|
11
|
+
} from '../ctx'
|
|
12
|
+
|
|
13
|
+
import { makeNilErr } from '../err'
|
|
14
|
+
|
|
15
|
+
import {
|
|
16
|
+
walk,
|
|
17
|
+
explainOpen,
|
|
18
|
+
explainClose,
|
|
19
|
+
} from '../utility'
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
import { FuncBaseVal } from './FuncBaseVal'
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class TypeFuncVal extends FuncBaseVal {
|
|
26
|
+
isTypeFunc = true
|
|
27
|
+
|
|
28
|
+
resolved?: Val
|
|
29
|
+
|
|
30
|
+
constructor(
|
|
31
|
+
spec: ValSpec,
|
|
32
|
+
ctx?: AontuContext
|
|
33
|
+
) {
|
|
34
|
+
super(spec, ctx)
|
|
35
|
+
|
|
36
|
+
// The function does not mark itself!
|
|
37
|
+
this.mark.type = false
|
|
38
|
+
this.mark.hide = false
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
make(_ctx: AontuContext, spec: ValSpec): Val {
|
|
43
|
+
return new TypeFuncVal(spec)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
funcname() {
|
|
47
|
+
return 'type'
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
resolve(ctx: AontuContext, args: Val[]) {
|
|
52
|
+
let out = args[0] ?? makeNilErr(ctx, 'arg', this)
|
|
53
|
+
if (!out.isNil) {
|
|
54
|
+
out = out.clone(ctx)
|
|
55
|
+
|
|
56
|
+
walk(out, (_key: string | number | undefined, val: Val) => {
|
|
57
|
+
val.mark.type = true
|
|
58
|
+
return val
|
|
59
|
+
})
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return out
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
export {
|
|
68
|
+
TypeFuncVal,
|
|
69
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/* Copyright (c) 2021-2025 Richard Rodger, MIT License */
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
import type {
|
|
5
|
+
Val,
|
|
6
|
+
ValSpec,
|
|
7
|
+
} from '../type'
|
|
8
|
+
|
|
9
|
+
import {
|
|
10
|
+
AontuContext,
|
|
11
|
+
} from '../ctx'
|
|
12
|
+
|
|
13
|
+
import { makeNilErr } from '../err'
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
import { NilVal } from '../val/NilVal'
|
|
17
|
+
import { ScalarKindVal } from '../val/ScalarKindVal'
|
|
18
|
+
import { makeScalar } from '../val/valutil'
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
import { FuncBaseVal } from './FuncBaseVal'
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class UpperFuncVal extends FuncBaseVal {
|
|
26
|
+
isUpperFunc = true
|
|
27
|
+
|
|
28
|
+
constructor(
|
|
29
|
+
spec: ValSpec,
|
|
30
|
+
ctx?: AontuContext
|
|
31
|
+
) {
|
|
32
|
+
super(spec, ctx)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
make(_ctx: AontuContext, spec: ValSpec): Val {
|
|
37
|
+
return new UpperFuncVal(spec)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
funcname() {
|
|
41
|
+
return 'upper'
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
resolve(ctx: AontuContext | undefined, args: Val[]) {
|
|
46
|
+
const oldpeg = args?.[0].peg
|
|
47
|
+
const peg = 'string' === typeof oldpeg ? oldpeg.toUpperCase() :
|
|
48
|
+
'number' === typeof oldpeg ? Math.ceil(oldpeg) :
|
|
49
|
+
undefined
|
|
50
|
+
const out = this.place(
|
|
51
|
+
null == peg ?
|
|
52
|
+
makeNilErr(ctx, 'invalid-arg', this) :
|
|
53
|
+
makeScalar(peg)
|
|
54
|
+
)
|
|
55
|
+
return out
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
superior() {
|
|
60
|
+
const arg = this.peg?.[0]
|
|
61
|
+
return arg?.isScalar ?
|
|
62
|
+
this.place(new ScalarKindVal({
|
|
63
|
+
peg: arg.kind
|
|
64
|
+
})) :
|
|
65
|
+
super.superior()
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
export {
|
|
71
|
+
UpperFuncVal,
|
|
72
|
+
}
|