kei-lisp 2.0.0 → 2.2.0
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/README.md +30 -14
- package/dist/cli.cjs +3774 -3023
- package/dist/cli.d.cts +1 -0
- package/dist/index.cjs +3778 -2904
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +947 -332
- package/dist/index.d.ts +947 -332
- package/dist/index.js +3746 -2895
- package/dist/index.js.map +1 -1
- package/package.json +28 -30
package/dist/index.d.ts
CHANGED
|
@@ -1,198 +1,6 @@
|
|
|
1
|
-
import { Interface } from
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @class
|
|
5
|
-
* @classdesc Iterator class for Cons.
|
|
6
|
-
* @author Keisuke Ikeda
|
|
7
|
-
* @this {Loop}
|
|
8
|
-
*/
|
|
9
|
-
declare class Loop {
|
|
10
|
-
aCons: Cons;
|
|
11
|
-
length: number;
|
|
12
|
-
index: number;
|
|
13
|
-
/**
|
|
14
|
-
* Constructor.
|
|
15
|
-
* @param aCons the Cons to iterate over
|
|
16
|
-
*/
|
|
17
|
-
constructor(aCons: Cons);
|
|
18
|
-
/**
|
|
19
|
-
* Returns this instance.
|
|
20
|
-
*/
|
|
21
|
-
iterator(): this;
|
|
22
|
-
/**
|
|
23
|
-
* Returns whether a next element exists.
|
|
24
|
-
*/
|
|
25
|
-
hasNext(): boolean;
|
|
26
|
-
/**
|
|
27
|
-
* Returns the next element.
|
|
28
|
-
*/
|
|
29
|
-
next(): LispValue;
|
|
30
|
-
/**
|
|
31
|
-
* Implementation of the iterable protocol.
|
|
32
|
-
* Enables iteration with for...of and similar constructs.
|
|
33
|
-
*/
|
|
34
|
-
[Symbol.iterator](): Iterator<LispValue>;
|
|
35
|
-
/**
|
|
36
|
-
* Implementation of the async iterable protocol.
|
|
37
|
-
* Enables iteration with for await...of and similar constructs.
|
|
38
|
-
*/
|
|
39
|
-
[Symbol.asyncIterator](): AsyncIterator<LispValue>;
|
|
40
|
-
/**
|
|
41
|
-
* Advances to the next element.
|
|
42
|
-
*/
|
|
43
|
-
remove(): null;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* @class
|
|
48
|
-
* @classdesc Class that mimics a Cons cell.
|
|
49
|
-
* @author Keisuke Ikeda
|
|
50
|
-
* @this {Cons}
|
|
51
|
-
*/
|
|
52
|
-
declare class Cons {
|
|
53
|
-
static readonly nil: Cons;
|
|
54
|
-
car: LispValue;
|
|
55
|
-
cdr: LispValue;
|
|
56
|
-
/**
|
|
57
|
-
* Constructor.
|
|
58
|
-
* @constructor
|
|
59
|
-
* @param car the car; defaults to nil when no argument is given.
|
|
60
|
-
* @param cdr the cdr; defaults to nil when no argument is given.
|
|
61
|
-
*/
|
|
62
|
-
constructor(car?: LispValue, cdr?: LispValue);
|
|
63
|
-
/**
|
|
64
|
-
* Appends the given element to the end of this Cons.
|
|
65
|
-
* @param anObject the object to append
|
|
66
|
-
* @return the Cons with the element appended
|
|
67
|
-
*/
|
|
68
|
-
add(anObject: LispValue): this;
|
|
69
|
-
/**
|
|
70
|
-
* Clones this Cons and returns the clone.
|
|
71
|
-
* @return the cloned Cons
|
|
72
|
-
*/
|
|
73
|
-
clone(): Cons;
|
|
74
|
-
/**
|
|
75
|
-
* Clones the given value (a Cons element) and returns the clone.
|
|
76
|
-
* @param value a Cons element
|
|
77
|
-
* @return the cloned element
|
|
78
|
-
*/
|
|
79
|
-
static cloneValue(value: LispValue): LispValue;
|
|
80
|
-
/**
|
|
81
|
-
* Returns whether this Cons equals the given object.
|
|
82
|
-
* @param anObject the object to compare against
|
|
83
|
-
* @return a boolean
|
|
84
|
-
*/
|
|
85
|
-
equals(anObject: LispValue): boolean;
|
|
86
|
-
/**
|
|
87
|
-
* Returns whether both arguments are Cons cells and are equal.
|
|
88
|
-
* @param left the object to compare
|
|
89
|
-
* @param right the object to compare
|
|
90
|
-
* @return a boolean
|
|
91
|
-
*/
|
|
92
|
-
equalsAUX(left: LispValue, right: LispValue): boolean;
|
|
93
|
-
/**
|
|
94
|
-
* Returns whether the given argument is an Atom.
|
|
95
|
-
*/
|
|
96
|
-
static isAtom(anObject: LispValue): boolean;
|
|
97
|
-
/**
|
|
98
|
-
* Returns whether the given argument is a Cons.
|
|
99
|
-
*/
|
|
100
|
-
static isCons(anObject: LispValue): anObject is Cons;
|
|
101
|
-
/**
|
|
102
|
-
* Returns whether the given argument is a List.
|
|
103
|
-
*/
|
|
104
|
-
static isList(anObject: LispValue): boolean;
|
|
105
|
-
/**
|
|
106
|
-
* Returns whether the given argument is Nil.
|
|
107
|
-
*/
|
|
108
|
-
static isNil(anObject: LispValue): boolean;
|
|
109
|
-
/**
|
|
110
|
-
* Returns whether the given argument is not a Cons.
|
|
111
|
-
*/
|
|
112
|
-
static isNotCons(anObject: LispValue): boolean;
|
|
113
|
-
/**
|
|
114
|
-
* Returns whether the given argument is not a List.
|
|
115
|
-
*/
|
|
116
|
-
static isNotList(anObject: LispValue): boolean;
|
|
117
|
-
/**
|
|
118
|
-
* Returns whether the given argument is not Nil.
|
|
119
|
-
*/
|
|
120
|
-
static isNotNil(anObject: LispValue): boolean;
|
|
121
|
-
/**
|
|
122
|
-
* Returns whether the given argument is not an interpreted symbol.
|
|
123
|
-
*/
|
|
124
|
-
static isNotSymbol(anObject: LispValue): boolean;
|
|
125
|
-
/**
|
|
126
|
-
* Returns whether the given argument is a number.
|
|
127
|
-
*/
|
|
128
|
-
static isNumber(anObject: LispValue): anObject is number;
|
|
129
|
-
/**
|
|
130
|
-
* Returns whether the given argument is a string.
|
|
131
|
-
*/
|
|
132
|
-
static isString(anObject: LispValue): anObject is string;
|
|
133
|
-
/**
|
|
134
|
-
* Returns whether the given argument is an interpreted symbol.
|
|
135
|
-
*/
|
|
136
|
-
static isSymbol(anObject: LispValue): anObject is InterpretedSymbol;
|
|
137
|
-
/**
|
|
138
|
-
* Returns whether the given argument is an environment.
|
|
139
|
-
*/
|
|
140
|
-
static isTable(anObject: LispValue): anObject is Table;
|
|
141
|
-
/**
|
|
142
|
-
* Returns the last cell of this Cons.
|
|
143
|
-
* @return this Cons's last cell
|
|
144
|
-
*/
|
|
145
|
-
last(): Cons;
|
|
146
|
-
/**
|
|
147
|
-
* Returns an iterator over this Cons.
|
|
148
|
-
* @return an iterator over this Cons
|
|
149
|
-
*/
|
|
150
|
-
loop(): Loop;
|
|
151
|
-
/**
|
|
152
|
-
* Returns the length (depth) of this Cons.
|
|
153
|
-
* @return the length (depth) of this Cons
|
|
154
|
-
*/
|
|
155
|
-
length(): number;
|
|
156
|
-
/**
|
|
157
|
-
* Concatenates the given Cons and returns this Cons.
|
|
158
|
-
* @param aCons the Cons to concatenate
|
|
159
|
-
* @return this Cons
|
|
160
|
-
*/
|
|
161
|
-
nconc(aCons: Cons): this;
|
|
162
|
-
/**
|
|
163
|
-
* Returns the nth element of this Cons.
|
|
164
|
-
* @param aNumber the index to retrieve
|
|
165
|
-
* @return the element at the given index
|
|
166
|
-
*/
|
|
167
|
-
nth(aNumber: number): LispValue;
|
|
168
|
-
/**
|
|
169
|
-
* Lexes the given string into a Cons and returns it.
|
|
170
|
-
* @param aString the string to lex
|
|
171
|
-
*/
|
|
172
|
-
static parse(aString: string): LispValue;
|
|
173
|
-
/**
|
|
174
|
-
* Sets the car.
|
|
175
|
-
*/
|
|
176
|
-
setCar(anObject: LispValue): null;
|
|
177
|
-
/**
|
|
178
|
-
* Sets the cdr.
|
|
179
|
-
*/
|
|
180
|
-
setCdr(anObject: LispValue): null;
|
|
181
|
-
/**
|
|
182
|
-
* Sets both the car and the cdr.
|
|
183
|
-
*/
|
|
184
|
-
setCons(car: LispValue, cdr: LispValue): this;
|
|
185
|
-
/**
|
|
186
|
-
* Returns a formatted string representation of this Cons.
|
|
187
|
-
*/
|
|
188
|
-
toString(): string;
|
|
189
|
-
/**
|
|
190
|
-
* Returns a formatted string representation of the given object.
|
|
191
|
-
* @param anObject the object to format
|
|
192
|
-
*/
|
|
193
|
-
static toString(anObject: LispValue): string;
|
|
194
|
-
}
|
|
1
|
+
import { Interface } from "node:readline";
|
|
195
2
|
|
|
3
|
+
//#region src/types/index.d.ts
|
|
196
4
|
/**
|
|
197
5
|
* Union of every value the interpreter can store or evaluate.
|
|
198
6
|
*
|
|
@@ -203,7 +11,8 @@ declare class Cons {
|
|
|
203
11
|
* - `null` — internal sentinel, distinct from Lisp `nil` (which is `Cons.nil`)
|
|
204
12
|
*/
|
|
205
13
|
type LispValue = Cons | InterpretedSymbol | Table | number | string | null;
|
|
206
|
-
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region src/runtime/Table/index.d.ts
|
|
207
16
|
/**
|
|
208
17
|
* @class
|
|
209
18
|
* @classdesc Class that manages bindings of interpreted symbols.
|
|
@@ -211,158 +20,947 @@ type LispValue = Cons | InterpretedSymbol | Table | number | string | null;
|
|
|
211
20
|
* @this {Table}
|
|
212
21
|
*/
|
|
213
22
|
declare class Table extends Map<unknown, LispValue> {
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
23
|
+
/**
|
|
24
|
+
* The enclosing (parent) environment, or null when this is the root.
|
|
25
|
+
*/
|
|
26
|
+
source: Table | null;
|
|
27
|
+
/**
|
|
28
|
+
* Whether this environment is the root of its chain.
|
|
29
|
+
*/
|
|
30
|
+
root: boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Constructor.
|
|
33
|
+
* @constructor
|
|
34
|
+
* @param aTable the environment in which this environment was created
|
|
35
|
+
*/
|
|
36
|
+
constructor(aTable?: Table | null);
|
|
37
|
+
/**
|
|
38
|
+
* Clones this Table and returns the clone.
|
|
39
|
+
* @return the cloned Table
|
|
40
|
+
*/
|
|
41
|
+
clone(): Table;
|
|
42
|
+
/**
|
|
43
|
+
* Returns whether anything is bound to the given property (key).
|
|
44
|
+
* @param aSymbol the symbol to look up
|
|
45
|
+
* @return true if a binding exists in this scope or any enclosing scope
|
|
46
|
+
*/
|
|
47
|
+
has(aSymbol: unknown): boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Returns whether this instance equals the given object.
|
|
50
|
+
* @param anObject the object to compare against
|
|
51
|
+
* @return true when the underlying Map.equals would return true
|
|
52
|
+
*/
|
|
53
|
+
equals(anObject: unknown): boolean;
|
|
54
|
+
/**
|
|
55
|
+
* Returns the value bound to the given interpreted symbol, walking up the scope chain.
|
|
56
|
+
* @param aSymbol the symbol to look up
|
|
57
|
+
* @return the bound value, or null when no binding exists
|
|
58
|
+
*/
|
|
59
|
+
get(aSymbol: unknown): LispValue;
|
|
60
|
+
/**
|
|
61
|
+
* Returns whether this instance is the root of the environment chain.
|
|
62
|
+
* @return true if this is the root environment
|
|
63
|
+
*/
|
|
64
|
+
isRoot(): boolean;
|
|
65
|
+
/**
|
|
66
|
+
* Reassigns the symbol bound in the innermost scope (equivalent to Common Lisp's setq). If a binding exists in the current scope, update it and return; otherwise recurse into the parent scope.
|
|
67
|
+
* @param aSymbol the symbol to update
|
|
68
|
+
* @param anObject the new bound value
|
|
69
|
+
* @return the new bound value, or null when no enclosing scope has a binding
|
|
70
|
+
*/
|
|
71
|
+
setIfExist(aSymbol: unknown, anObject: LispValue): LispValue;
|
|
72
|
+
/**
|
|
73
|
+
* Sets whether this instance is the root of its environment chain.
|
|
74
|
+
* @param aBoolean the new root flag
|
|
75
|
+
* @return null
|
|
76
|
+
*/
|
|
77
|
+
setRoot(aBoolean: boolean): null;
|
|
78
|
+
/**
|
|
79
|
+
* Sets the parent environment.
|
|
80
|
+
* @param aTable the new parent environment (or null)
|
|
81
|
+
* @return null
|
|
82
|
+
*/
|
|
83
|
+
setSource(aTable: Table | null): null;
|
|
84
|
+
/**
|
|
85
|
+
* Returns a formatted string representation of this instance.
|
|
86
|
+
* @return the formatted string
|
|
87
|
+
*/
|
|
88
|
+
toString(): string;
|
|
258
89
|
}
|
|
259
|
-
|
|
90
|
+
//#endregion
|
|
91
|
+
//#region src/value/InterpretedSymbol/index.d.ts
|
|
260
92
|
/**
|
|
261
93
|
* @class
|
|
262
94
|
* @classdesc Interpreted symbol with uniqueness, where each printed name maps to a single canonical instance (identity equals equality). A class that mimics canonical strings, distinct from JS's standard Symbol.
|
|
263
95
|
* @author Keisuke Ikeda
|
|
264
96
|
* @this {InterpretedSymbol}
|
|
265
97
|
*/
|
|
266
|
-
declare class InterpretedSymbol {
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
98
|
+
declare class InterpretedSymbol extends Object {
|
|
99
|
+
#private;
|
|
100
|
+
/**
|
|
101
|
+
* Lazy accessor for the intern table that holds every InterpretedSymbol instance.
|
|
102
|
+
* @return the intern Table (created on first access)
|
|
103
|
+
*/
|
|
104
|
+
static get table(): Table;
|
|
105
|
+
/**
|
|
106
|
+
* The printed name of this symbol.
|
|
107
|
+
*/
|
|
108
|
+
name: string;
|
|
109
|
+
/**
|
|
110
|
+
* Constructor.
|
|
111
|
+
* @constructor
|
|
112
|
+
* @param name printed name
|
|
113
|
+
*/
|
|
114
|
+
constructor(name?: string);
|
|
115
|
+
/**
|
|
116
|
+
* Compares this interpreted symbol with the given one by printed name.
|
|
117
|
+
* @param aSymbol the symbol to compare against
|
|
118
|
+
* @return the difference in string length
|
|
119
|
+
*/
|
|
120
|
+
compareTo(aSymbol: InterpretedSymbol): number;
|
|
121
|
+
/**
|
|
122
|
+
* Returns whether this symbol equals the given object.
|
|
123
|
+
* @param anObject the object to compare against
|
|
124
|
+
* @return true when identity-equal (since intern guarantees uniqueness)
|
|
125
|
+
*/
|
|
126
|
+
equals(anObject: unknown): boolean;
|
|
127
|
+
/**
|
|
128
|
+
* Returns the same interpreted symbol for a given printed name.
|
|
129
|
+
* @param aString printed name
|
|
130
|
+
* @return the canonical InterpretedSymbol for that name
|
|
131
|
+
*/
|
|
132
|
+
static of(aString: string): InterpretedSymbol;
|
|
133
|
+
/**
|
|
134
|
+
* Returns the string representation of this symbol.
|
|
135
|
+
* @return the printed name
|
|
136
|
+
*/
|
|
137
|
+
toString(): string;
|
|
294
138
|
}
|
|
295
|
-
|
|
139
|
+
//#endregion
|
|
140
|
+
//#region src/value/Loop/index.d.ts
|
|
141
|
+
/**
|
|
142
|
+
* @class
|
|
143
|
+
* @classdesc Iterator class for Cons.
|
|
144
|
+
* @author Keisuke Ikeda
|
|
145
|
+
* @this {Loop}
|
|
146
|
+
*/
|
|
147
|
+
declare class Loop extends Object {
|
|
148
|
+
/**
|
|
149
|
+
* The Cons being iterated over.
|
|
150
|
+
*/
|
|
151
|
+
aCons: Cons;
|
|
152
|
+
/**
|
|
153
|
+
* The number of elements in the underlying Cons (computed once at construction time).
|
|
154
|
+
*/
|
|
155
|
+
length: number;
|
|
156
|
+
/**
|
|
157
|
+
* The 1-based index of the next element to return.
|
|
158
|
+
*/
|
|
159
|
+
index: number;
|
|
160
|
+
/**
|
|
161
|
+
* Constructor.
|
|
162
|
+
* @constructor
|
|
163
|
+
* @param aCons the Cons to iterate over
|
|
164
|
+
*/
|
|
165
|
+
constructor(aCons: Cons);
|
|
166
|
+
/**
|
|
167
|
+
* Returns this instance so it can be used as its own iterator.
|
|
168
|
+
* @return this Loop instance
|
|
169
|
+
*/
|
|
170
|
+
iterator(): this;
|
|
171
|
+
/**
|
|
172
|
+
* Returns whether a next element exists.
|
|
173
|
+
* @return true if there is at least one more element
|
|
174
|
+
*/
|
|
175
|
+
hasNext(): boolean;
|
|
176
|
+
/**
|
|
177
|
+
* Returns the next element and advances the cursor.
|
|
178
|
+
* @return the element at the current index
|
|
179
|
+
*/
|
|
180
|
+
next(): LispValue;
|
|
181
|
+
/**
|
|
182
|
+
* Implementation of the iterable protocol. Enables iteration with for...of and similar constructs.
|
|
183
|
+
* @return an iterator over the Cons elements
|
|
184
|
+
*/
|
|
185
|
+
[Symbol.iterator](): Iterator<LispValue>;
|
|
186
|
+
/**
|
|
187
|
+
* Implementation of the async iterable protocol. Enables iteration with for await...of and similar constructs.
|
|
188
|
+
* @return an async iterator over the Cons elements
|
|
189
|
+
*/
|
|
190
|
+
[Symbol.asyncIterator](): AsyncIterator<LispValue>;
|
|
191
|
+
/**
|
|
192
|
+
* Advances the cursor to the next element.
|
|
193
|
+
* @return null
|
|
194
|
+
*/
|
|
195
|
+
remove(): null;
|
|
196
|
+
}
|
|
197
|
+
//#endregion
|
|
198
|
+
//#region src/value/Cons/index.d.ts
|
|
199
|
+
/**
|
|
200
|
+
* @class
|
|
201
|
+
* @classdesc Class that mimics a Cons cell.
|
|
202
|
+
* @author Keisuke Ikeda
|
|
203
|
+
* @this {Cons}
|
|
204
|
+
*/
|
|
205
|
+
declare class Cons extends Object {
|
|
206
|
+
/**
|
|
207
|
+
* The shared empty-list sentinel. A Cons whose car and cdr are both itself, representing Lisp `nil`.
|
|
208
|
+
*/
|
|
209
|
+
static readonly nil: Cons;
|
|
210
|
+
/**
|
|
211
|
+
* The head element of this Cons cell.
|
|
212
|
+
*/
|
|
213
|
+
car: LispValue;
|
|
214
|
+
/**
|
|
215
|
+
* The tail of this Cons cell (typically another Cons or nil).
|
|
216
|
+
*/
|
|
217
|
+
cdr: LispValue;
|
|
218
|
+
/**
|
|
219
|
+
* Constructor.
|
|
220
|
+
* @constructor
|
|
221
|
+
* @param car the car; defaults to nil when no argument is given.
|
|
222
|
+
* @param cdr the cdr; defaults to nil when no argument is given.
|
|
223
|
+
*/
|
|
224
|
+
constructor(car?: LispValue, cdr?: LispValue);
|
|
225
|
+
/**
|
|
226
|
+
* Appends the given element to the end of this Cons.
|
|
227
|
+
* @param anObject the object to append
|
|
228
|
+
* @return the Cons with the element appended
|
|
229
|
+
*/
|
|
230
|
+
add(anObject: LispValue): this;
|
|
231
|
+
/**
|
|
232
|
+
* Clones this Cons and returns the clone.
|
|
233
|
+
* @return the cloned Cons
|
|
234
|
+
*/
|
|
235
|
+
clone(): Cons;
|
|
236
|
+
/**
|
|
237
|
+
* Clones the given value (a Cons element) and returns the clone.
|
|
238
|
+
* @param value a Cons element
|
|
239
|
+
* @return the cloned element
|
|
240
|
+
*/
|
|
241
|
+
static cloneValue(value: LispValue): LispValue;
|
|
242
|
+
/**
|
|
243
|
+
* Returns whether this Cons equals the given object.
|
|
244
|
+
* @param anObject the object to compare against
|
|
245
|
+
* @return a boolean
|
|
246
|
+
*/
|
|
247
|
+
equals(anObject: LispValue): boolean;
|
|
248
|
+
/**
|
|
249
|
+
* Returns whether both arguments are Cons cells and are equal.
|
|
250
|
+
* @param left the object to compare
|
|
251
|
+
* @param right the object to compare
|
|
252
|
+
* @return a boolean
|
|
253
|
+
*/
|
|
254
|
+
equalsAUX(left: LispValue, right: LispValue): boolean;
|
|
255
|
+
/**
|
|
256
|
+
* Returns whether the given argument is an Atom.
|
|
257
|
+
*/
|
|
258
|
+
static isAtom(anObject: LispValue): boolean;
|
|
259
|
+
/**
|
|
260
|
+
* Returns whether the given argument is a Cons.
|
|
261
|
+
*/
|
|
262
|
+
static isCons(anObject: LispValue): anObject is Cons;
|
|
263
|
+
/**
|
|
264
|
+
* Returns whether the given argument is a List.
|
|
265
|
+
*/
|
|
266
|
+
static isList(anObject: LispValue): boolean;
|
|
267
|
+
/**
|
|
268
|
+
* Returns whether the given argument is Nil.
|
|
269
|
+
*/
|
|
270
|
+
static isNil(anObject: LispValue): boolean;
|
|
271
|
+
/**
|
|
272
|
+
* Returns whether the given argument is not a Cons.
|
|
273
|
+
*/
|
|
274
|
+
static isNotCons(anObject: LispValue): boolean;
|
|
275
|
+
/**
|
|
276
|
+
* Returns whether the given argument is not a List.
|
|
277
|
+
*/
|
|
278
|
+
static isNotList(anObject: LispValue): boolean;
|
|
279
|
+
/**
|
|
280
|
+
* Returns whether the given argument is not Nil.
|
|
281
|
+
*/
|
|
282
|
+
static isNotNil(anObject: LispValue): boolean;
|
|
283
|
+
/**
|
|
284
|
+
* Returns whether the given argument is not an interpreted symbol.
|
|
285
|
+
*/
|
|
286
|
+
static isNotSymbol(anObject: LispValue): boolean;
|
|
287
|
+
/**
|
|
288
|
+
* Returns whether the given argument is a number.
|
|
289
|
+
*/
|
|
290
|
+
static isNumber(anObject: LispValue): anObject is number;
|
|
291
|
+
/**
|
|
292
|
+
* Returns whether the given argument is a string.
|
|
293
|
+
*/
|
|
294
|
+
static isString(anObject: LispValue): anObject is string;
|
|
295
|
+
/**
|
|
296
|
+
* Returns whether the given argument is an interpreted symbol.
|
|
297
|
+
*/
|
|
298
|
+
static isSymbol(anObject: LispValue): anObject is InterpretedSymbol;
|
|
299
|
+
/**
|
|
300
|
+
* Returns whether the given argument is an environment.
|
|
301
|
+
*/
|
|
302
|
+
static isTable(anObject: LispValue): anObject is Table;
|
|
303
|
+
/**
|
|
304
|
+
* Returns the last cell of this Cons.
|
|
305
|
+
* @return this Cons's last cell
|
|
306
|
+
*/
|
|
307
|
+
last(): Cons;
|
|
308
|
+
/**
|
|
309
|
+
* Returns an iterator over this Cons.
|
|
310
|
+
* @return an iterator over this Cons
|
|
311
|
+
*/
|
|
312
|
+
loop(): Loop;
|
|
313
|
+
/**
|
|
314
|
+
* Returns the length (depth) of this Cons.
|
|
315
|
+
* @return the length (depth) of this Cons
|
|
316
|
+
*/
|
|
317
|
+
length(): number;
|
|
318
|
+
/**
|
|
319
|
+
* Concatenates the given Cons and returns this Cons.
|
|
320
|
+
* @param aCons the Cons to concatenate
|
|
321
|
+
* @return this Cons
|
|
322
|
+
*/
|
|
323
|
+
nconc(aCons: Cons): this;
|
|
324
|
+
/**
|
|
325
|
+
* Returns the nth element of this Cons.
|
|
326
|
+
* @param aNumber the index to retrieve
|
|
327
|
+
* @return the element at the given index
|
|
328
|
+
*/
|
|
329
|
+
nth(aNumber: number): LispValue;
|
|
330
|
+
/**
|
|
331
|
+
* Lexes the given string into a Cons and returns it.
|
|
332
|
+
* @param aString the string to lex
|
|
333
|
+
*/
|
|
334
|
+
static parse(aString: string): LispValue;
|
|
335
|
+
/**
|
|
336
|
+
* Sets the car.
|
|
337
|
+
*/
|
|
338
|
+
setCar(anObject: LispValue): null;
|
|
339
|
+
/**
|
|
340
|
+
* Sets the cdr.
|
|
341
|
+
*/
|
|
342
|
+
setCdr(anObject: LispValue): null;
|
|
343
|
+
/**
|
|
344
|
+
* Sets both the car and the cdr.
|
|
345
|
+
*/
|
|
346
|
+
setCons(car: LispValue, cdr: LispValue): this;
|
|
347
|
+
/**
|
|
348
|
+
* Returns a formatted string representation of this Cons.
|
|
349
|
+
*/
|
|
350
|
+
toString(): string;
|
|
351
|
+
/**
|
|
352
|
+
* Returns a formatted string representation of the given object.
|
|
353
|
+
* @param anObject the object to format
|
|
354
|
+
*/
|
|
355
|
+
static toString(anObject: LispValue): string;
|
|
356
|
+
}
|
|
357
|
+
//#endregion
|
|
358
|
+
//#region src/runtime/StreamManager/index.d.ts
|
|
296
359
|
type Stream = NodeJS.WritableStream | null;
|
|
297
360
|
/**
|
|
298
361
|
* @class
|
|
299
|
-
* @classdesc
|
|
362
|
+
* @classdesc Manages output streams (stdout / stderr / spy / trace) used by the interpreter.
|
|
300
363
|
* @author Keisuke Ikeda
|
|
301
364
|
* @this {StreamManager}
|
|
302
365
|
*/
|
|
303
|
-
declare class StreamManager {
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
366
|
+
declare class StreamManager extends Object {
|
|
367
|
+
/**
|
|
368
|
+
* Whether tracing is currently enabled.
|
|
369
|
+
*/
|
|
370
|
+
isTrace: boolean;
|
|
371
|
+
/**
|
|
372
|
+
* Map from a named stream key (e.g. "default", "stdout", "stderr") to a WritableStream.
|
|
373
|
+
*/
|
|
374
|
+
streamTable: Map<string, Stream>;
|
|
375
|
+
/**
|
|
376
|
+
* Map from a spied symbol to the stream key used for that symbol's output.
|
|
377
|
+
*/
|
|
378
|
+
spyTable: Map<InterpretedSymbol, string>;
|
|
379
|
+
/**
|
|
380
|
+
* The stream that receives trace output while tracing is on.
|
|
381
|
+
*/
|
|
382
|
+
traceStream: Stream;
|
|
383
|
+
/**
|
|
384
|
+
* Constructor.
|
|
385
|
+
* @constructor
|
|
386
|
+
*/
|
|
387
|
+
constructor();
|
|
388
|
+
/**
|
|
389
|
+
* Returns the currently selected output stream (trace stream when tracing, otherwise the default).
|
|
390
|
+
* @return the active stream, or null when none is available
|
|
391
|
+
*/
|
|
392
|
+
getStream(): Stream;
|
|
393
|
+
/**
|
|
394
|
+
* Initializes the instance variables.
|
|
395
|
+
* @return null
|
|
396
|
+
*/
|
|
397
|
+
initialize(): null;
|
|
398
|
+
/**
|
|
399
|
+
* Returns whether the given symbol is being spied (or whether tracing is on, in which case every symbol is "spied").
|
|
400
|
+
* @param aSymbol the symbol to check, or null
|
|
401
|
+
* @return true if the symbol is spied or tracing is on
|
|
402
|
+
*/
|
|
403
|
+
isSpy(aSymbol: InterpretedSymbol | null): boolean;
|
|
404
|
+
/**
|
|
405
|
+
* Removes the given symbol from the spy table.
|
|
406
|
+
* @param aSymbol the symbol to stop spying
|
|
407
|
+
* @return null
|
|
408
|
+
*/
|
|
409
|
+
noSpy(aSymbol: InterpretedSymbol): null;
|
|
410
|
+
/**
|
|
411
|
+
* Turns tracing off and clears the spy table.
|
|
412
|
+
* @return null
|
|
413
|
+
*/
|
|
414
|
+
noTrace(): null;
|
|
415
|
+
/**
|
|
416
|
+
* Sets the tracing flag.
|
|
417
|
+
* @param aBoolean the new value for the tracing flag
|
|
418
|
+
* @return null
|
|
419
|
+
*/
|
|
420
|
+
setIsTrace(aBoolean: boolean): null;
|
|
421
|
+
/**
|
|
422
|
+
* Sets the trace output stream.
|
|
423
|
+
* @param aStream the stream to send trace output to
|
|
424
|
+
* @return null
|
|
425
|
+
*/
|
|
426
|
+
setTraceStream(aStream: Stream): null;
|
|
427
|
+
/**
|
|
428
|
+
* Registers the given symbol as spied with the given stream key.
|
|
429
|
+
* @param aSymbol the symbol to spy on
|
|
430
|
+
* @param aString the stream key (e.g. "default")
|
|
431
|
+
* @return null
|
|
432
|
+
*/
|
|
433
|
+
spy(aSymbol: InterpretedSymbol, aString: string): null;
|
|
434
|
+
/**
|
|
435
|
+
* Returns the stream (or stream-key string) used for the given symbol's spy output.
|
|
436
|
+
* @param aSymbol the symbol whose spy stream is requested, or null
|
|
437
|
+
* @return the trace stream, the registered key string, or throws if none is found
|
|
438
|
+
*/
|
|
439
|
+
spyStream(aSymbol: InterpretedSymbol | null): Stream | string;
|
|
440
|
+
/**
|
|
441
|
+
* Returns a copy of the spy table (defensive copy so callers do not mutate the internal map).
|
|
442
|
+
* @return a new map containing the same entries as the internal spy table
|
|
443
|
+
*/
|
|
444
|
+
spyTable_(): Map<InterpretedSymbol, string>;
|
|
445
|
+
/**
|
|
446
|
+
* Turns tracing on, routing trace output to the currently active stream.
|
|
447
|
+
* @return null
|
|
448
|
+
*/
|
|
449
|
+
trace(): null;
|
|
323
450
|
}
|
|
324
|
-
|
|
451
|
+
//#endregion
|
|
452
|
+
//#region src/plugin/types.d.ts
|
|
453
|
+
/**
|
|
454
|
+
* Context passed to a plugin's `apply` call. Holds the live interpreter state
|
|
455
|
+
* needed to perform recursive evaluation or to read / write the environment.
|
|
456
|
+
*/
|
|
457
|
+
interface PluginContext {
|
|
458
|
+
/**
|
|
459
|
+
* The current variable binding environment.
|
|
460
|
+
*/
|
|
461
|
+
environment: Table;
|
|
462
|
+
/**
|
|
463
|
+
* The stream manager that owns the interpreter's I/O / spy / trace streams.
|
|
464
|
+
*/
|
|
465
|
+
streamManager: StreamManager;
|
|
466
|
+
/**
|
|
467
|
+
* The current call depth (used for spy indentation).
|
|
468
|
+
*/
|
|
469
|
+
depth: number;
|
|
470
|
+
/**
|
|
471
|
+
* Re-evaluates the given form using the current environment / stream manager / depth.
|
|
472
|
+
* Use this to evaluate a sub-form (e.g. when the plugin received a lambda value).
|
|
473
|
+
* @param form the form to evaluate
|
|
474
|
+
* @return the evaluation result
|
|
475
|
+
*/
|
|
476
|
+
eval(form: LispValue): LispValue;
|
|
477
|
+
}
|
|
478
|
+
/**
|
|
479
|
+
* A kei-lisp plugin contributes additional Lisp-callable functions to the
|
|
480
|
+
* interpreter. Register one with `LispInterpreter.use(plugin)`. When the
|
|
481
|
+
* evaluator encounters `(symbol ...)` and `symbol` is not a special form,
|
|
482
|
+
* registered plugins are consulted in registration order; the first plugin
|
|
483
|
+
* whose `has(symbol)` returns true handles the call.
|
|
484
|
+
*
|
|
485
|
+
* Arguments are pre-evaluated by the interpreter before being passed to
|
|
486
|
+
* `apply`, matching the calling convention of built-in functions.
|
|
487
|
+
*/
|
|
488
|
+
interface KeiLispPlugin {
|
|
489
|
+
/**
|
|
490
|
+
* Plugin identifier, used for diagnostics and collision messages.
|
|
491
|
+
*/
|
|
492
|
+
readonly name: string;
|
|
493
|
+
/**
|
|
494
|
+
* Returns true if this plugin handles the given symbol.
|
|
495
|
+
* @param symbol the call symbol to check
|
|
496
|
+
* @return true if `apply` should be called for this symbol
|
|
497
|
+
*/
|
|
498
|
+
has(symbol: InterpretedSymbol): boolean;
|
|
499
|
+
/**
|
|
500
|
+
* Applies the plugin function to the (already-evaluated) arguments.
|
|
501
|
+
* @param symbol the call symbol
|
|
502
|
+
* @param args the evaluated argument list (a Cons, possibly Cons.nil)
|
|
503
|
+
* @param ctx the interpreter context for recursive evaluation
|
|
504
|
+
* @return the result value
|
|
505
|
+
*/
|
|
506
|
+
apply(symbol: InterpretedSymbol, args: Cons, ctx: PluginContext): LispValue;
|
|
507
|
+
}
|
|
508
|
+
//#endregion
|
|
509
|
+
//#region src/interpreter/LispInterpreter/index.d.ts
|
|
325
510
|
/**
|
|
326
511
|
* @class
|
|
327
512
|
* @classdesc Class for the interpreter.
|
|
328
513
|
* @author Keisuke Ikeda
|
|
329
514
|
* @this {LispInterpreter}
|
|
330
515
|
*/
|
|
331
|
-
declare class LispInterpreter {
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
516
|
+
declare class LispInterpreter extends Object {
|
|
517
|
+
/**
|
|
518
|
+
* The root (top-level) environment table, pre-populated with built-in symbols.
|
|
519
|
+
*/
|
|
520
|
+
root: Table;
|
|
521
|
+
/**
|
|
522
|
+
* The stream manager that owns the interpreter's output / spy streams.
|
|
523
|
+
*/
|
|
524
|
+
streamManager: StreamManager;
|
|
525
|
+
/**
|
|
526
|
+
* Registered plugins consulted by the evaluator on every call. See `use`.
|
|
527
|
+
*/
|
|
528
|
+
plugins: KeiLispPlugin[];
|
|
529
|
+
/**
|
|
530
|
+
* Constructor.
|
|
531
|
+
* @constructor
|
|
532
|
+
*/
|
|
533
|
+
constructor();
|
|
534
|
+
/**
|
|
535
|
+
* Registers a plugin. Subsequent `eval` calls will consult the plugin chain
|
|
536
|
+
* (in registration order, first match wins) when no special form matches a
|
|
537
|
+
* symbol, before falling through to the Applier built-ins.
|
|
538
|
+
* @param plugin the plugin to register
|
|
539
|
+
* @return this interpreter, for chaining
|
|
540
|
+
*/
|
|
541
|
+
use(plugin: KeiLispPlugin): this;
|
|
542
|
+
/**
|
|
543
|
+
* Evaluates the given expression and returns the result. Throws `ParseError`,
|
|
544
|
+
* `EvalError`, or `ExitError` on failure; library users are expected to catch
|
|
545
|
+
* these (see the `KeiLispError` base class for the parse/eval family).
|
|
546
|
+
* @param aCons the expression to evaluate
|
|
547
|
+
* @return the evaluation result
|
|
548
|
+
*/
|
|
549
|
+
eval(aCons: LispValue): LispValue;
|
|
550
|
+
/**
|
|
551
|
+
* Parses the source string, evaluates every expression it contains, and returns the results as an array.
|
|
552
|
+
* @param source the Lisp source string
|
|
553
|
+
* @return the array of evaluation results, one per top-level expression
|
|
554
|
+
*/
|
|
555
|
+
evalAll(source: string): LispValue[];
|
|
556
|
+
/**
|
|
557
|
+
* Parses and evaluates the source string and returns the value of the last expression.
|
|
558
|
+
* @param source the Lisp source string
|
|
559
|
+
* @return the value of the last expression, or `Cons.nil` for empty input
|
|
560
|
+
*/
|
|
561
|
+
evalString(source: string): LispValue;
|
|
562
|
+
/**
|
|
563
|
+
* Parses the given string into a list of top-level expressions and returns
|
|
564
|
+
* it. The result is always a `Cons` (possibly `Cons.nil` for empty input)
|
|
565
|
+
* because the source is wrapped in an outer list before parsing. Throws
|
|
566
|
+
* `ParseError` if the source cannot be parsed.
|
|
567
|
+
* @param aString the Lisp source string
|
|
568
|
+
* @return a Cons containing the parsed top-level expressions
|
|
569
|
+
*/
|
|
570
|
+
parse(aString: string): Cons;
|
|
571
|
+
/**
|
|
572
|
+
* Sets the given environment as the root of the environment chain.
|
|
573
|
+
* @param environment the environment table to install as root
|
|
574
|
+
* @return null
|
|
575
|
+
*/
|
|
576
|
+
setRoot(environment: Table): null;
|
|
577
|
+
/**
|
|
578
|
+
* Builds the root environment table by pre-registering every built-in symbol and the small set of bootstrap lambdas (append / butlast / nthcdr / reverse).
|
|
579
|
+
* @return the freshly initialized root environment
|
|
580
|
+
*/
|
|
581
|
+
initializeTable(): Table;
|
|
364
582
|
}
|
|
365
|
-
|
|
583
|
+
//#endregion
|
|
584
|
+
//#region src/interpreter/Repl/index.d.ts
|
|
585
|
+
/**
|
|
586
|
+
* @class
|
|
587
|
+
* @classdesc Interactive REPL wrapper around LispInterpreter. Handles line accumulation, parenthesis balancing, and prompt I/O.
|
|
588
|
+
* @author Keisuke Ikeda
|
|
589
|
+
* @this {Repl}
|
|
590
|
+
*/
|
|
591
|
+
declare class Repl extends Object {
|
|
592
|
+
/**
|
|
593
|
+
* The underlying interpreter used to parse and evaluate user input.
|
|
594
|
+
*/
|
|
595
|
+
interpreter: LispInterpreter;
|
|
596
|
+
/**
|
|
597
|
+
* The Node.js readline interface that supplies prompt I/O.
|
|
598
|
+
*/
|
|
599
|
+
rl: Interface;
|
|
600
|
+
/**
|
|
601
|
+
* Constructor.
|
|
602
|
+
* @constructor
|
|
603
|
+
* @param interpreter the interpreter to evaluate input against (defaults to a fresh one)
|
|
604
|
+
*/
|
|
605
|
+
constructor(interpreter?: LispInterpreter);
|
|
606
|
+
/**
|
|
607
|
+
* Starts the REPL loop.
|
|
608
|
+
* @return void
|
|
609
|
+
*/
|
|
610
|
+
run(): void;
|
|
611
|
+
}
|
|
612
|
+
//#endregion
|
|
613
|
+
//#region src/runtime/Evaluator/index.d.ts
|
|
614
|
+
/**
|
|
615
|
+
* @class
|
|
616
|
+
* @classdesc Class that mimics Lisp's universal function Evaluate.
|
|
617
|
+
* @author Keisuke Ikeda
|
|
618
|
+
* @this {Evaluator}
|
|
619
|
+
*/
|
|
620
|
+
declare class Evaluator extends Object {
|
|
621
|
+
/**
|
|
622
|
+
* Lisp-name to method-name dispatch map for special forms.
|
|
623
|
+
*/
|
|
624
|
+
static readonly buildInFunctions: Map<InterpretedSymbol, string>;
|
|
625
|
+
/**
|
|
626
|
+
* The variable binding environment used during evaluation.
|
|
627
|
+
*/
|
|
628
|
+
environment: Table;
|
|
629
|
+
/**
|
|
630
|
+
* The stream manager used for trace and spy output.
|
|
631
|
+
*/
|
|
632
|
+
streamManager: StreamManager;
|
|
633
|
+
/**
|
|
634
|
+
* The current call depth, used for indenting trace/spy output.
|
|
635
|
+
*/
|
|
636
|
+
depth: number;
|
|
637
|
+
/**
|
|
638
|
+
* Registered plugins consulted by `eval` when no special form matches.
|
|
639
|
+
*/
|
|
640
|
+
plugins: KeiLispPlugin[];
|
|
641
|
+
/**
|
|
642
|
+
* Constructor.
|
|
643
|
+
* @param aTable the variable binding environment
|
|
644
|
+
* @param aStreamManager the stream manager for trace and spy output
|
|
645
|
+
* @param aNumber the initial call depth
|
|
646
|
+
* @param plugins the plugin chain consulted before falling through to Applier
|
|
647
|
+
*/
|
|
648
|
+
constructor(aTable: Table, aStreamManager: StreamManager, aNumber: number, plugins?: KeiLispPlugin[]);
|
|
649
|
+
/**
|
|
650
|
+
* Implementation of the Lisp `and` special form.
|
|
651
|
+
* @param aCons the argument Cons containing the expressions to evaluate
|
|
652
|
+
* @return nil if any expression evaluates to nil, otherwise t
|
|
653
|
+
*/
|
|
654
|
+
and(aCons: Cons): LispValue;
|
|
655
|
+
/**
|
|
656
|
+
* Implementation of the Lisp `apply` special form.
|
|
657
|
+
* @param aCons the argument Cons containing the procedure and its argument list
|
|
658
|
+
* @return the result of applying the procedure to the arguments
|
|
659
|
+
*/
|
|
660
|
+
apply_lisp(aCons: Cons): LispValue;
|
|
661
|
+
/**
|
|
662
|
+
* Implementation of the Lisp `bind` special form.
|
|
663
|
+
* @param aCons the argument Cons whose car is the symbol to look up
|
|
664
|
+
* @return the binding count for the symbol, or nil if unbound
|
|
665
|
+
*/
|
|
666
|
+
bind(aCons: Cons): LispValue;
|
|
667
|
+
/**
|
|
668
|
+
* Counts the number of distinct bindings for the given symbol along the environment chain.
|
|
669
|
+
* @param aSymbol the symbol whose bindings are inspected
|
|
670
|
+
* @return the number of distinct bindings found
|
|
671
|
+
*/
|
|
672
|
+
bindAUX(aSymbol: InterpretedSymbol): number;
|
|
673
|
+
/**
|
|
674
|
+
* Sequentially evaluates and binds each (symbol value) pair into the given table; used by let*.
|
|
675
|
+
* @param parameters the Cons of (symbol value) pairs to bind
|
|
676
|
+
* @param aTable the table into which the bindings are written
|
|
677
|
+
*/
|
|
678
|
+
binding(parameters: Cons, aTable: Table): null;
|
|
679
|
+
/**
|
|
680
|
+
* Evaluates all (symbol value) pairs first and then writes them into the given table in parallel; used by let.
|
|
681
|
+
* @param parameters the Cons of (symbol value) pairs to bind
|
|
682
|
+
* @param aTable the table into which the bindings are written
|
|
683
|
+
*/
|
|
684
|
+
bindingParallel(parameters: Cons, aTable: Table): null;
|
|
685
|
+
/**
|
|
686
|
+
* Implementation of the Lisp `cond` special form.
|
|
687
|
+
* @param aCons the argument Cons of (test consequent...) clauses
|
|
688
|
+
* @return the result of the first clause whose test is non-nil, or nil
|
|
689
|
+
*/
|
|
690
|
+
cond(aCons: LispValue): LispValue;
|
|
691
|
+
/**
|
|
692
|
+
* Implementation of the Lisp `defun` special form.
|
|
693
|
+
* @param aCons the argument Cons containing the function name, parameter list, and body
|
|
694
|
+
* @return the function name symbol
|
|
695
|
+
*/
|
|
696
|
+
defun(aCons: Cons): LispValue;
|
|
697
|
+
/**
|
|
698
|
+
* Implementation of the Lisp `do` special form (parallel binding update).
|
|
699
|
+
* @param aCons the argument Cons containing bindings, termination clause, and body
|
|
700
|
+
* @return the value of the termination clause's result form
|
|
701
|
+
*/
|
|
702
|
+
do_(aCons: Cons): LispValue;
|
|
703
|
+
/**
|
|
704
|
+
* Implementation of the Lisp `dolist` special form.
|
|
705
|
+
* @param aCons the argument Cons containing the binding clause and body
|
|
706
|
+
* @return the value of the result form
|
|
707
|
+
*/
|
|
708
|
+
doList(aCons: Cons): LispValue;
|
|
709
|
+
/**
|
|
710
|
+
* Implementation of the Lisp `do*` special form (sequential binding update).
|
|
711
|
+
* @param aCons the argument Cons containing bindings, termination clause, and body
|
|
712
|
+
* @return the value of the termination clause's result form
|
|
713
|
+
*/
|
|
714
|
+
doStar(aCons: Cons): LispValue;
|
|
715
|
+
/**
|
|
716
|
+
* Evaluates a procedure call by delegating to the Applier after evaluating each argument.
|
|
717
|
+
* @param form the call form whose car is the procedure and whose cdr is the argument list
|
|
718
|
+
* @return the result of applying the procedure
|
|
719
|
+
*/
|
|
720
|
+
entrustApplier(form: Cons): LispValue;
|
|
721
|
+
/**
|
|
722
|
+
* Evaluates the given form in the given environment.
|
|
723
|
+
* @param form the form to evaluate
|
|
724
|
+
* @param environment the variable binding environment
|
|
725
|
+
* @param aStreamManager the stream manager for trace and spy output
|
|
726
|
+
* @param depth the current call depth
|
|
727
|
+
* @param plugins the plugin chain consulted before falling through to Applier
|
|
728
|
+
* @return the evaluation result
|
|
729
|
+
*/
|
|
730
|
+
static eval(form: LispValue, environment: Table, aStreamManager?: StreamManager, depth?: number, plugins?: KeiLispPlugin[]): LispValue;
|
|
731
|
+
/**
|
|
732
|
+
* Evaluates the given form using this Evaluator's environment.
|
|
733
|
+
* @param form the form to evaluate
|
|
734
|
+
* @return the evaluation result
|
|
735
|
+
*/
|
|
736
|
+
eval(form: LispValue): LispValue;
|
|
737
|
+
/**
|
|
738
|
+
* Evaluates the argument list (the same way `entrustApplier` does), then
|
|
739
|
+
* delegates the call to the matched plugin with a context that allows
|
|
740
|
+
* recursive evaluation.
|
|
741
|
+
* @param plugin the plugin that claimed the call symbol
|
|
742
|
+
* @param form the call form whose car is the symbol and whose cdr is the argument list
|
|
743
|
+
* @return the result returned by the plugin
|
|
744
|
+
*/
|
|
745
|
+
entrustPlugin(plugin: KeiLispPlugin, form: Cons): LispValue;
|
|
746
|
+
/**
|
|
747
|
+
* Implementation of the Lisp `eval` special form.
|
|
748
|
+
* @param aCons the argument Cons whose car is the form to evaluate twice
|
|
749
|
+
* @return the result of evaluating the form
|
|
750
|
+
*/
|
|
751
|
+
eval_lisp(aCons: Cons): LispValue;
|
|
752
|
+
/**
|
|
753
|
+
* Resolves the value bound to the given symbol in the current environment.
|
|
754
|
+
* @param aSymbol the symbol to resolve
|
|
755
|
+
* @return the value bound to the symbol
|
|
756
|
+
*/
|
|
757
|
+
evaluateSymbol(aSymbol: InterpretedSymbol): LispValue;
|
|
758
|
+
/**
|
|
759
|
+
* Implementation of the Lisp `exit` special form; terminates the REPL by throwing an ExitError.
|
|
760
|
+
*/
|
|
761
|
+
exit(): never;
|
|
762
|
+
/**
|
|
763
|
+
* Implementation of the Lisp `gc` special form; triggers garbage collection and returns memory usage.
|
|
764
|
+
* @return an association list of memory usage statistics
|
|
765
|
+
*/
|
|
766
|
+
gc(): Cons;
|
|
767
|
+
/**
|
|
768
|
+
* Implementation of the Lisp `if` special form.
|
|
769
|
+
* @param aCons the argument Cons containing the test, then-form, and else-form
|
|
770
|
+
* @return the result of evaluating the selected branch
|
|
771
|
+
*/
|
|
772
|
+
if_(aCons: Cons): LispValue;
|
|
773
|
+
/**
|
|
774
|
+
* Returns the indentation string used for trace and spy output at the current depth.
|
|
775
|
+
* @return the indentation string
|
|
776
|
+
*/
|
|
777
|
+
indent(): string;
|
|
778
|
+
/**
|
|
779
|
+
* Returns whether the given symbol is currently being spied on.
|
|
780
|
+
* @param aSymbol the symbol to check
|
|
781
|
+
* @return a boolean
|
|
782
|
+
*/
|
|
783
|
+
isSpy(aSymbol: InterpretedSymbol | null): boolean;
|
|
784
|
+
/**
|
|
785
|
+
* Implementation of the Lisp `lambda` special form; captures the current environment as a closure.
|
|
786
|
+
* @param args the argument Cons containing the parameter list and body
|
|
787
|
+
* @return a lambda form with the captured environment appended
|
|
788
|
+
*/
|
|
789
|
+
lambda(args: Cons): LispValue;
|
|
790
|
+
/**
|
|
791
|
+
* Implementation of the Lisp `let` special form (parallel binding).
|
|
792
|
+
* @param aCons the argument Cons containing bindings and body
|
|
793
|
+
* @return the value of the last body form
|
|
794
|
+
*/
|
|
795
|
+
let(aCons: Cons): LispValue;
|
|
796
|
+
/**
|
|
797
|
+
* Implementation of the Lisp `let*` special form (sequential binding).
|
|
798
|
+
* @param aCons the argument Cons containing bindings and body
|
|
799
|
+
* @return the value of the last body form
|
|
800
|
+
*/
|
|
801
|
+
letStar(aCons: Cons): LispValue;
|
|
802
|
+
/**
|
|
803
|
+
* Implementation of the Lisp `not` special form.
|
|
804
|
+
* @param aCons the argument Cons whose car is the expression to negate
|
|
805
|
+
* @return t if the expression evaluates to nil, otherwise nil
|
|
806
|
+
*/
|
|
807
|
+
not(aCons: Cons): LispValue;
|
|
808
|
+
/**
|
|
809
|
+
* Implementation of the Lisp `notrace` special form; disables tracing.
|
|
810
|
+
* @return the symbol t
|
|
811
|
+
*/
|
|
812
|
+
notrace(): InterpretedSymbol;
|
|
813
|
+
/**
|
|
814
|
+
* Implementation of the Lisp `or` special form.
|
|
815
|
+
* @param aCons the argument Cons containing the expressions to evaluate
|
|
816
|
+
* @return t if any expression evaluates to non-nil, otherwise nil
|
|
817
|
+
*/
|
|
818
|
+
or(aCons: Cons): LispValue;
|
|
819
|
+
/**
|
|
820
|
+
* Implementation of the Lisp `pop` special form.
|
|
821
|
+
* @param aCons the argument Cons whose car is the symbol bound to a list
|
|
822
|
+
* @return the popped element, or nil if the binding is not a Cons
|
|
823
|
+
*/
|
|
824
|
+
pop_(aCons: Cons): LispValue;
|
|
825
|
+
/**
|
|
826
|
+
* Implementation of the Lisp `progn` special form.
|
|
827
|
+
* @param aCons the argument Cons containing the body expressions
|
|
828
|
+
* @return the value of the last body form, or nil if there are none
|
|
829
|
+
*/
|
|
830
|
+
progn(aCons: Cons): LispValue;
|
|
831
|
+
/**
|
|
832
|
+
* Implementation of the Lisp `princ` special form; writes the evaluated argument without a trailing newline.
|
|
833
|
+
* @param aCons the argument Cons whose car is the expression to print
|
|
834
|
+
* @return the printed value
|
|
835
|
+
*/
|
|
836
|
+
princ(aCons: Cons): LispValue;
|
|
837
|
+
/**
|
|
838
|
+
* Implementation of the Lisp `print` special form; writes the evaluated argument followed by a newline.
|
|
839
|
+
* @param aCons the argument Cons whose car is the expression to print
|
|
840
|
+
* @return the printed value
|
|
841
|
+
*/
|
|
842
|
+
print(aCons: Cons): LispValue;
|
|
843
|
+
/**
|
|
844
|
+
* Implementation of the Lisp `push` special form.
|
|
845
|
+
* @param aCons the argument Cons containing the value to push and the target symbol
|
|
846
|
+
* @return the new Cons stored in the symbol
|
|
847
|
+
*/
|
|
848
|
+
push_(aCons: Cons): LispValue;
|
|
849
|
+
/**
|
|
850
|
+
* Implementation of the Lisp `quote` special form.
|
|
851
|
+
* @param aCons the argument Cons whose car is the form to return unevaluated
|
|
852
|
+
* @return the quoted form
|
|
853
|
+
*/
|
|
854
|
+
quote(aCons: Cons): LispValue;
|
|
855
|
+
/**
|
|
856
|
+
* Implementation of the Lisp `rplaca` special form; destructively replaces the car of a Cons.
|
|
857
|
+
* @param args the argument Cons containing the target Cons expression and the new car value
|
|
858
|
+
* @return the modified Cons
|
|
859
|
+
*/
|
|
860
|
+
rplaca(args: Cons): LispValue;
|
|
861
|
+
/**
|
|
862
|
+
* Implementation of the Lisp `rplacd` special form; destructively replaces the cdr of a Cons.
|
|
863
|
+
* @param args the argument Cons containing the target Cons expression and the new cdr value
|
|
864
|
+
* @return the modified Cons
|
|
865
|
+
*/
|
|
866
|
+
rplacd(args: Cons): LispValue;
|
|
867
|
+
/**
|
|
868
|
+
* Implementation of the Lisp `setq` special form; assigns values in the local environment.
|
|
869
|
+
* @param args the argument Cons containing alternating (symbol value) pairs
|
|
870
|
+
* @return the last assigned value
|
|
871
|
+
*/
|
|
872
|
+
setq(args: Cons): LispValue;
|
|
873
|
+
/**
|
|
874
|
+
* Implementation of the Lisp `set-allq` special form; assigns values in the binding's owning scope.
|
|
875
|
+
* @param args the argument Cons containing alternating (symbol value) pairs
|
|
876
|
+
* @return the last assigned value
|
|
877
|
+
*/
|
|
878
|
+
set_allq(args: Cons): LispValue;
|
|
879
|
+
/**
|
|
880
|
+
* Sets the current call depth used for trace and spy indentation.
|
|
881
|
+
* @param aNumber the new depth
|
|
882
|
+
*/
|
|
883
|
+
setDepth(aNumber: number): null;
|
|
884
|
+
/**
|
|
885
|
+
* Builds and returns the Lisp-name to method-name dispatch map for special forms.
|
|
886
|
+
* @return the dispatch map
|
|
887
|
+
*/
|
|
888
|
+
static setup(): Map<InterpretedSymbol, string>;
|
|
889
|
+
/**
|
|
890
|
+
* Dispatches a special-form call to the corresponding method via the build-in dispatch map.
|
|
891
|
+
* @param form the form whose car is the special-form symbol
|
|
892
|
+
* @return the result of the special-form method
|
|
893
|
+
*/
|
|
894
|
+
specialForm(form: Cons): LispValue;
|
|
895
|
+
/**
|
|
896
|
+
* Writes a trace/spy line to the given stream (or stdout) with the current indentation.
|
|
897
|
+
* @param aStream the destination stream, or null/string to fall back to stdout
|
|
898
|
+
* @param line the line to write
|
|
899
|
+
*/
|
|
900
|
+
spyPrint(aStream: NodeJS.WritableStream | string | null, line: string): null;
|
|
901
|
+
/**
|
|
902
|
+
* Implementation of the Lisp `terpri` special form; writes a newline to stdout.
|
|
903
|
+
* @return the symbol t
|
|
904
|
+
*/
|
|
905
|
+
terpri(): InterpretedSymbol;
|
|
906
|
+
/**
|
|
907
|
+
* Implementation of the Lisp `time` special form; measures evaluation time in milliseconds.
|
|
908
|
+
* @param aCons the argument Cons whose car is the form to time
|
|
909
|
+
* @return the elapsed time in milliseconds
|
|
910
|
+
*/
|
|
911
|
+
time(aCons: Cons): number;
|
|
912
|
+
/**
|
|
913
|
+
* Implementation of the Lisp `trace` special form; enables tracing.
|
|
914
|
+
* @return the symbol t
|
|
915
|
+
*/
|
|
916
|
+
trace(): InterpretedSymbol;
|
|
917
|
+
/**
|
|
918
|
+
* Implementation of the Lisp `unless` special form.
|
|
919
|
+
* @param aCons the argument Cons containing the test and body
|
|
920
|
+
* @return the value of the last body form if the test is nil, otherwise nil
|
|
921
|
+
*/
|
|
922
|
+
unless(aCons: Cons): LispValue;
|
|
923
|
+
/**
|
|
924
|
+
* Implementation of the Lisp `when` special form.
|
|
925
|
+
* @param aCons the argument Cons containing the test and body
|
|
926
|
+
* @return the value of the last body form if the test is non-nil, otherwise nil
|
|
927
|
+
*/
|
|
928
|
+
when(aCons: Cons): LispValue;
|
|
929
|
+
}
|
|
930
|
+
//#endregion
|
|
931
|
+
//#region src/errors/KeiLispError/index.d.ts
|
|
932
|
+
/**
|
|
933
|
+
* @class
|
|
934
|
+
* @classdesc Base class for all errors raised by kei-lisp during parsing or evaluation. Catch this to handle any Lisp-level failure without intercepting an unrelated runtime error or an `ExitError` (which signals a graceful `(exit)` and is intentionally not a subclass).
|
|
935
|
+
* @author Keisuke Ikeda
|
|
936
|
+
* @this {KeiLispError}
|
|
937
|
+
*/
|
|
938
|
+
declare class KeiLispError extends Error {
|
|
939
|
+
/**
|
|
940
|
+
* Constructor.
|
|
941
|
+
* @constructor
|
|
942
|
+
* @param message human-readable diagnostic message
|
|
943
|
+
*/
|
|
944
|
+
constructor(message: string);
|
|
945
|
+
}
|
|
946
|
+
//#endregion
|
|
947
|
+
//#region src/errors/EvalError/index.d.ts
|
|
948
|
+
/**
|
|
949
|
+
* @class
|
|
950
|
+
* @classdesc Error raised when evaluation or application of a Lisp expression fails (type mismatch, unbound symbol, arity error, etc.). Subclass of `KeiLispError`.
|
|
951
|
+
* @author Keisuke Ikeda
|
|
952
|
+
* @this {EvalError}
|
|
953
|
+
*/
|
|
954
|
+
declare class EvalError extends KeiLispError {
|
|
955
|
+
/**
|
|
956
|
+
* Constructor.
|
|
957
|
+
* @constructor
|
|
958
|
+
* @param message human-readable diagnostic message
|
|
959
|
+
*/
|
|
960
|
+
constructor(message: string);
|
|
961
|
+
}
|
|
962
|
+
//#endregion
|
|
963
|
+
//#region src/errors/ExitError/index.d.ts
|
|
366
964
|
/**
|
|
367
965
|
* @class
|
|
368
966
|
* @classdesc Error class representing a graceful exit triggered by a Lisp (exit) call. Catch it at the REPL or library boundary to run cleanup before terminating.
|
|
@@ -370,11 +968,28 @@ declare class LispInterpreter {
|
|
|
370
968
|
* @this {ExitError}
|
|
371
969
|
*/
|
|
372
970
|
declare class ExitError extends Error {
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
971
|
+
/**
|
|
972
|
+
* Constructor.
|
|
973
|
+
* @constructor
|
|
974
|
+
*/
|
|
975
|
+
constructor();
|
|
378
976
|
}
|
|
379
|
-
|
|
380
|
-
|
|
977
|
+
//#endregion
|
|
978
|
+
//#region src/errors/ParseError/index.d.ts
|
|
979
|
+
/**
|
|
980
|
+
* @class
|
|
981
|
+
* @classdesc Error raised when the parser cannot turn a source string into an AST. Subclass of `KeiLispError`.
|
|
982
|
+
* @author Keisuke Ikeda
|
|
983
|
+
* @this {ParseError}
|
|
984
|
+
*/
|
|
985
|
+
declare class ParseError extends KeiLispError {
|
|
986
|
+
/**
|
|
987
|
+
* Constructor.
|
|
988
|
+
* @constructor
|
|
989
|
+
* @param message human-readable diagnostic message
|
|
990
|
+
*/
|
|
991
|
+
constructor(message: string);
|
|
992
|
+
}
|
|
993
|
+
//#endregion
|
|
994
|
+
export { Cons, EvalError, Evaluator, ExitError, InterpretedSymbol, KeiLispError, type KeiLispPlugin, LispInterpreter, type LispValue, ParseError, type PluginContext, Repl, StreamManager, Table };
|
|
995
|
+
//# sourceMappingURL=index.d.ts.map
|