@quenk/potoo 4.0.7 → 4.0.11

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.
Files changed (89) hide show
  1. package/lib/actor/address.js.map +1 -1
  2. package/lib/actor/api.d.ts +2 -2
  3. package/lib/actor/api.js.map +1 -1
  4. package/lib/actor/framework/index.js +2 -2
  5. package/lib/actor/framework/index.js.map +1 -1
  6. package/lib/actor/framework/process.d.ts +3 -2
  7. package/lib/actor/framework/process.js.map +1 -1
  8. package/lib/actor/framework/resident.d.ts +5 -3
  9. package/lib/actor/framework/resident.js +2 -0
  10. package/lib/actor/framework/resident.js.map +1 -1
  11. package/lib/actor/index.js.map +1 -1
  12. package/lib/actor/system/vm/allocator/index.js.map +1 -1
  13. package/lib/actor/system/vm/allocator/map.js +7 -4
  14. package/lib/actor/system/vm/allocator/map.js.map +1 -1
  15. package/lib/actor/system/vm/conf.js.map +1 -1
  16. package/lib/actor/system/vm/event/dispatcher.d.ts +31 -12
  17. package/lib/actor/system/vm/event/dispatcher.js +72 -20
  18. package/lib/actor/system/vm/event/dispatcher.js.map +1 -1
  19. package/lib/actor/system/vm/event/index.js.map +1 -1
  20. package/lib/actor/system/vm/frame.js.map +1 -1
  21. package/lib/actor/system/vm/group.js.map +1 -1
  22. package/lib/actor/system/vm/index.js +2 -2
  23. package/lib/actor/system/vm/index.js.map +1 -1
  24. package/lib/actor/system/vm/log/index.js.map +1 -1
  25. package/lib/actor/system/vm/log/writer.js.map +1 -1
  26. package/lib/actor/system/vm/object/foreign.js.map +1 -1
  27. package/lib/actor/system/vm/object/index.js.map +1 -1
  28. package/lib/actor/system/vm/object/list.js.map +1 -1
  29. package/lib/actor/system/vm/op/actor.js.map +1 -1
  30. package/lib/actor/system/vm/op/base.js.map +1 -1
  31. package/lib/actor/system/vm/op/index.js.map +1 -1
  32. package/lib/actor/system/vm/op/object.js.map +1 -1
  33. package/lib/actor/system/vm/registry.js.map +1 -1
  34. package/lib/actor/system/vm/runtime/error.js.map +1 -1
  35. package/lib/actor/system/vm/runtime.js.map +1 -1
  36. package/lib/actor/system/vm/scheduler.js.map +1 -1
  37. package/lib/actor/system/vm/script/index.js.map +1 -1
  38. package/lib/actor/system/vm/script/info.js.map +1 -1
  39. package/lib/actor/system/vm/strategy/error.js.map +1 -1
  40. package/lib/actor/system/vm/thread/factory.js.map +1 -1
  41. package/lib/actor/system/vm/thread/index.js.map +1 -1
  42. package/lib/actor/system/vm/thread/process.js.map +1 -1
  43. package/lib/actor/system/vm/thread/shared/index.js.map +1 -1
  44. package/lib/actor/system/vm/thread/shared/js.d.ts +2 -2
  45. package/lib/actor/system/vm/thread/shared/js.js +3 -3
  46. package/lib/actor/system/vm/thread/shared/js.js.map +1 -1
  47. package/lib/actor/system/vm/type.js.map +1 -1
  48. package/lib/actor/template.d.ts +20 -0
  49. package/lib/actor/template.js +17 -1
  50. package/lib/actor/template.js.map +1 -1
  51. package/package.json +11 -9
  52. package/lib/actor/address.ts +0 -90
  53. package/lib/actor/api.ts +0 -57
  54. package/lib/actor/framework/index.ts +0 -1
  55. package/lib/actor/framework/process.ts +0 -87
  56. package/lib/actor/framework/resident.ts +0 -90
  57. package/lib/actor/index.ts +0 -35
  58. package/lib/actor/system/vm/allocator/index.ts +0 -43
  59. package/lib/actor/system/vm/allocator/map.ts +0 -256
  60. package/lib/actor/system/vm/conf.ts +0 -33
  61. package/lib/actor/system/vm/event/dispatcher.ts +0 -85
  62. package/lib/actor/system/vm/event/index.ts +0 -143
  63. package/lib/actor/system/vm/frame.ts +0 -484
  64. package/lib/actor/system/vm/group.ts +0 -46
  65. package/lib/actor/system/vm/index.ts +0 -230
  66. package/lib/actor/system/vm/log/index.ts +0 -73
  67. package/lib/actor/system/vm/log/writer.ts +0 -96
  68. package/lib/actor/system/vm/object/foreign.ts +0 -10
  69. package/lib/actor/system/vm/object/index.ts +0 -4
  70. package/lib/actor/system/vm/object/list.ts +0 -8
  71. package/lib/actor/system/vm/op/actor.ts +0 -126
  72. package/lib/actor/system/vm/op/base.ts +0 -243
  73. package/lib/actor/system/vm/op/index.ts +0 -388
  74. package/lib/actor/system/vm/op/object.ts +0 -81
  75. package/lib/actor/system/vm/registry.ts +0 -223
  76. package/lib/actor/system/vm/runtime/error.ts +0 -248
  77. package/lib/actor/system/vm/runtime.ts +0 -31
  78. package/lib/actor/system/vm/scheduler.ts +0 -108
  79. package/lib/actor/system/vm/script/index.ts +0 -64
  80. package/lib/actor/system/vm/script/info.ts +0 -359
  81. package/lib/actor/system/vm/strategy/error.ts +0 -88
  82. package/lib/actor/system/vm/thread/factory.ts +0 -29
  83. package/lib/actor/system/vm/thread/index.ts +0 -29
  84. package/lib/actor/system/vm/thread/process.ts +0 -134
  85. package/lib/actor/system/vm/thread/shared/index.ts +0 -50
  86. package/lib/actor/system/vm/thread/shared/js.ts +0 -151
  87. package/lib/actor/system/vm/type.ts +0 -115
  88. package/lib/actor/template.ts +0 -170
  89. package/lib/tsconfig.json +0 -22
@@ -1,484 +0,0 @@
1
- import * as indexes from './script';
2
- import * as error from './runtime/error';
3
-
4
- import { Either, left, right } from '@quenk/noni/lib/data/either';
5
- import { Err } from '@quenk/noni/lib/control/error';
6
- import { Type } from '@quenk/noni/lib/data/type';
7
- import { Maybe, fromNullable, nothing } from '@quenk/noni/lib/data/maybe';
8
-
9
- import { FunInfo, Info } from './script/info';
10
- import { JSThread } from './thread/shared/js';
11
- import { Script } from './script';
12
- import { PTObject } from './object';
13
- import { Instruction, Operand } from './op';
14
- import { PTValue, BYTE_TYPE, TYPE_FUN } from './type';
15
-
16
- export const DATA_RANGE_TYPE_HIGH = 0xf0000000;
17
- export const DATA_RANGE_TYPE_LOW = 0x1000000;
18
- export const DATA_RANGE_TYPE_STEP = 0x1000000;
19
-
20
- // Used to extract the desired part via &
21
- export const DATA_MASK_TYPE = 0xff000000;
22
- export const DATA_MASK_VALUE8 = 0xff;
23
- export const DATA_MASK_VALUE16 = 0xffff;
24
- export const DATA_MASK_VALUE24 = 0xffffff;
25
- export const DATA_MASK_VALUE32 = 0xffffffff;
26
-
27
- export const DATA_MAX_SIZE = 0xffffffff;
28
- export const DATA_MAX_SAFE_UINT32 = 0x7fffffff;
29
-
30
- //These really indicate where the actual value of an operand is stored.
31
- //They are not meant to be used to check the actual type of the underlying value.
32
- export const DATA_TYPE_STRING = DATA_RANGE_TYPE_STEP * 3;
33
- export const DATA_TYPE_INFO = DATA_RANGE_TYPE_STEP * 4;
34
- export const DATA_TYPE_HEAP_STRING = DATA_RANGE_TYPE_STEP * 6;
35
- export const DATA_TYPE_HEAP_OBJECT = DATA_RANGE_TYPE_STEP * 7;
36
- export const DATA_TYPE_HEAP_FOREIGN = DATA_RANGE_TYPE_STEP * 8;
37
- export const DATA_TYPE_HEAP_FUN = DATA_RANGE_TYPE_STEP * 9;
38
- export const DATA_TYPE_LOCAL = DATA_RANGE_TYPE_STEP * 10;
39
- export const DATA_TYPE_MAILBOX = DATA_RANGE_TYPE_STEP * 11;
40
- export const DATA_TYPE_SELF = DATA_RANGE_TYPE_STEP * 12;
41
- export const DATA_TYPE_VOID = DATA_RANGE_TYPE_STEP * 13;
42
-
43
- export const BYTE_CONSTANT_NUM = 0x10000;
44
- export const BYTE_CONSTANT_STR = 0x20000;
45
- export const BYTE_CONSTANT_INFO = 0x30000;
46
-
47
- /**
48
- * Data is the type of values that can appear on a Frame's data stack.
49
- *
50
- * It is a 32bit unsigned integer in the range 0x00000000-0x7FFFFFFF
51
- *
52
- * Typically, the highest byte is used to indicate the type of the data
53
- * in realtion to storage location and the remaining 3 bytes, value.
54
- *
55
- * 11111111 11111111 11111111 11111111
56
- * <type/location> < value >
57
- *
58
- * The actual interpretation of the location and value part are dependant on
59
- * the type.
60
- */
61
- export type Data = number;
62
-
63
- /**
64
- * Used to identity frames via a specific format:
65
- * <templateid>@<actorid>#<callstack>
66
- *
67
- * Where <callstack> is a list of function names in the callstack up to the
68
- * Frame's own function separated by '/'.
69
- */
70
- export type FrameName = string;
71
-
72
- /**
73
- * Frame is the context for currently executing op codes.
74
- *
75
- * It provides methods for manipulating the stack common to each op code as
76
- * well as access to other components of the system.
77
- */
78
- export interface Frame {
79
- /**
80
- * name of the Frame used to identity it.
81
- */
82
- name: FrameName;
83
-
84
- /**
85
- * script the routine is defined in.
86
- */
87
- script: Script;
88
-
89
- /**
90
- * thread for the actor.
91
- */
92
- thread: JSThread;
93
-
94
- /**
95
- * parent Frame that created this Frame (if any).
96
- */
97
- parent: Maybe<Frame>;
98
-
99
- /**
100
- * code the frame executes as part of the routine.
101
- */
102
- code: Instruction[];
103
-
104
- /**
105
- * data stack or operand stack.
106
- */
107
- data: Data[];
108
-
109
- /**
110
- * locals contains variables local to the routine.
111
- */
112
- locals: Data[];
113
-
114
- /**
115
- * getPosition of the internal instruction pointer.
116
- */
117
- getPosition(): number;
118
-
119
- /**
120
- * push an operand onto the data stack.
121
- *
122
- * Values not in the range 0 - 2^32 (integer only) may yield unexpected
123
- * results during computation. Care should be taken when using this method
124
- * directly to ensure the desired value is actual on the stack.
125
- */
126
- push(d: Data): Frame;
127
-
128
- /**
129
- * pushUInt8 pushes an unsigned 8bit integer onto the data stack.
130
- */
131
- pushUInt8(value: Operand): Frame;
132
-
133
- /**
134
- * pushUInt16 pushes an unsigned 16bit integer onto the data stack.
135
- */
136
- pushUInt16(value: Operand): Frame;
137
-
138
- /**
139
- * pushUInt32 pushes an unsigned 32bit integer onto the data stack.
140
- */
141
- pushUInt32(value: Operand): Frame;
142
-
143
- /**
144
- * pushString from the constant pool onto the data stack.
145
- */
146
- pushString(idx: Operand): Frame;
147
-
148
- /**
149
- * pushName pushes a named constant from the info section onto the stack.
150
- */
151
- pushName(idx: Operand): Frame;
152
-
153
- /**
154
- * pushMessage from the mailbox onto the stack.
155
- */
156
- pushMessage(): Frame;
157
-
158
- /**
159
- * pushSelf pushes the address of the executing actor on to the stack.
160
- */
161
- pushSelf(): Frame;
162
-
163
- /**
164
- * peek at the top of the data stack.
165
- *
166
- * An offset can be specified to peek further down the stack.
167
- */
168
- peek(n?: number): Maybe<Data>;
169
-
170
- /**
171
- * resolve a value from its reference.
172
- *
173
- * An error will be produced if the value cannot be resolved.
174
- * Do not use this method to retreive uint8,uint16 or uint32.
175
- */
176
- resolve(data: Data): Either<Err, PTValue>;
177
-
178
- /**
179
- * pop the top most value from the data stack.
180
- *
181
- * If the stack is empty the value 0 is returned.
182
- */
183
- pop(): Data;
184
-
185
- /**
186
- * popValue pops and attempts to resolve the top most value of the data stack.
187
- */
188
- popValue(): Either<Err, Type>;
189
-
190
- /**
191
- * popString from the top of the data stack.
192
- */
193
- popString(): Either<Err, string>;
194
-
195
- /**
196
- * popName pops a named object from the top of the data stack.
197
- */
198
- popName(): Either<Err, Info>;
199
-
200
- /**
201
- * popFunction from the top of the data stack.
202
- */
203
- popFunction(): Either<Err, FunInfo>;
204
-
205
- /**
206
- * popObject provides the entry for an object in the heap.
207
- */
208
- popObject(): Either<Err, PTObject>;
209
-
210
- /**
211
- * popForeign provides the entry for a foreign object in the heap.
212
- */
213
- popForeign(): Either<Err, Type>;
214
-
215
- /**
216
- * duplicate the top of the stack.
217
- */
218
- duplicate(): Frame;
219
-
220
- /**
221
- * advance the internal instruction pointer by 1 place.
222
- */
223
- advance(): Frame;
224
-
225
- /**
226
- * seek advances the instruction pointer to the specified location.
227
- */
228
- seek(loc: number): Frame;
229
-
230
- /**
231
- * isFinished returns true if the instruction pointer for the frame has
232
- * reached the end of the code section.
233
- */
234
- isFinished(): boolean;
235
- }
236
-
237
- /**
238
- * StackFrame (Frame implementation).
239
- */
240
- export class StackFrame implements Frame {
241
- constructor(
242
- public name: string,
243
- public script: Script,
244
- public thread: JSThread,
245
- public parent: Maybe<Frame> = nothing(),
246
- public code: Instruction[] = [],
247
- public data: Data[] = [],
248
- public locals: Data[] = [],
249
- public ip = 0
250
- ) {}
251
-
252
- getPosition(): number {
253
- return this.ip;
254
- }
255
-
256
- push(d: Data): Frame {
257
- this.data.push(d);
258
- return this;
259
- }
260
-
261
- pushUInt8(value: Operand): Frame {
262
- return this.push((value >>> 0) & DATA_MASK_VALUE8);
263
- }
264
-
265
- pushUInt16(value: Operand): Frame {
266
- return this.push((value >>> 0) & DATA_MASK_VALUE16);
267
- }
268
-
269
- pushUInt32(value: Operand): Frame {
270
- return this.push(value >>> 0);
271
- }
272
-
273
- pushString(idx: Operand): Frame {
274
- return this.push(idx | DATA_TYPE_STRING);
275
- }
276
-
277
- pushName(idx: Operand): Frame {
278
- return this.push(idx | DATA_TYPE_INFO);
279
- }
280
-
281
- pushMessage(): Frame {
282
- return this.push(0 | DATA_TYPE_MAILBOX);
283
- }
284
-
285
- pushSelf(): Frame {
286
- return this.push(DATA_TYPE_SELF);
287
- }
288
-
289
- peek(n = 0): Maybe<Data> {
290
- return fromNullable(this.data.length - (n + 1));
291
- }
292
-
293
- resolve(data: Data): Either<Err, Type> {
294
- let typ = data & DATA_MASK_TYPE;
295
-
296
- let value = data & DATA_MASK_VALUE24;
297
-
298
- switch (typ) {
299
- case DATA_TYPE_STRING:
300
- case DATA_TYPE_HEAP_STRING:
301
- this.push(data);
302
- return this.popString();
303
-
304
- case DATA_TYPE_HEAP_FUN:
305
- this.push(data);
306
- return this.popFunction();
307
-
308
- case DATA_TYPE_HEAP_OBJECT:
309
- this.push(data);
310
- return this.popObject();
311
-
312
- case DATA_TYPE_HEAP_FOREIGN:
313
- this.push(data);
314
- return this.popForeign();
315
-
316
- case DATA_TYPE_INFO:
317
- this.push(data);
318
- return this.popName();
319
-
320
- //TODO: This is probably not needed.
321
- case DATA_TYPE_LOCAL:
322
- let mRef = fromNullable(this.locals[value]);
323
-
324
- if (mRef.isNothing()) return nullErr(data);
325
-
326
- //TODO: review call stack safety of this recursive call.
327
- return this.resolve(mRef.get());
328
-
329
- case DATA_TYPE_MAILBOX:
330
- if (this.thread.mailbox.length === 0) return nullErr(data);
331
-
332
- //messages are always accessed sequentially FIFO
333
- return right<Err, PTValue>(this.thread.mailbox.shift());
334
-
335
- case DATA_TYPE_SELF:
336
- return right<Err, PTValue>(this.thread.address);
337
-
338
- //TODO: This sometimes results in us treating 0 as a legitimate
339
- //value whereas it should be an error. However, 0 is a valid value
340
- //for numbers, and booleans. Needs review, solution may be in ops
341
- //rather than here.
342
- default:
343
- return right(value);
344
- }
345
- }
346
-
347
- pop(): Data {
348
- return (<Data>this.data.pop()) | 0;
349
- }
350
-
351
- popValue(): Either<Err, PTValue> {
352
- return this.data.length === 0
353
- ? left(new error.StackEmptyErr())
354
- : this.resolve(this.pop());
355
- }
356
-
357
- popString(): Either<Err, string> {
358
- let data = this.pop();
359
- let typ = data & DATA_MASK_TYPE;
360
- let idx = data & DATA_MASK_VALUE24;
361
-
362
- if (typ === DATA_TYPE_STRING) {
363
- let s = this.script.constants[indexes.CONSTANTS_INDEX_STRING][idx];
364
-
365
- if (s == null) return missingSymbol(data);
366
-
367
- return right(s);
368
- } else if (typ === DATA_TYPE_HEAP_STRING) {
369
- return right(this.thread.vm.registry.getString(data).get());
370
- } else if (typ === DATA_TYPE_SELF) {
371
- return right(this.thread.address);
372
- } else {
373
- return wrongType(DATA_TYPE_STRING, typ);
374
- }
375
- }
376
-
377
- popName(): Either<Err, Info> {
378
- let data = this.pop();
379
- let typ = data & DATA_MASK_TYPE;
380
- let idx = data & DATA_MASK_VALUE24;
381
-
382
- if (typ === DATA_TYPE_INFO) {
383
- let info = this.script.info[idx];
384
-
385
- if (info == null) return nullErr(data);
386
-
387
- return right(info);
388
- } else {
389
- return wrongType(DATA_TYPE_INFO, data);
390
- }
391
- }
392
-
393
- popFunction(): Either<Err, FunInfo> {
394
- let data = this.pop();
395
-
396
- /* TODO: Heap functions are no longer supported right now.
397
- let typ = data & DATA_MASK_TYPE;
398
- if (typ === DATA_TYPE_HEAP_FUN) {
399
- let mFun = this.thread.vm.heap.getObject(data);
400
-
401
- return mFun.isJust() ? right(mFun.get()) : nullFunPtr(data);
402
- } else {
403
- */
404
- this.push(data);
405
-
406
- return <Either<Err, FunInfo>>this.popName().chain(nfo => {
407
- if (((<FunInfo>nfo).descriptor & BYTE_TYPE) !== TYPE_FUN)
408
- return notAFunction(nfo.name);
409
-
410
- return right(nfo);
411
- });
412
- }
413
-
414
- popObject(): Either<Err, PTObject> {
415
- let data = this.pop();
416
- let typ = data & DATA_MASK_TYPE;
417
-
418
- if (typ === DATA_TYPE_HEAP_OBJECT) {
419
- let mho = this.thread.vm.registry.getObject(data);
420
-
421
- if (mho.isNothing()) return nullErr(data);
422
-
423
- // TODO: review how this works.
424
- return <any>right(mho.get());
425
- } else {
426
- return wrongType(DATA_TYPE_HEAP_OBJECT, typ);
427
- }
428
- }
429
-
430
- popForeign(): Either<Err, Type> {
431
- let data = this.pop();
432
- let typ = data & DATA_MASK_TYPE;
433
-
434
- if (typ === DATA_TYPE_HEAP_FOREIGN) {
435
- let mho = this.thread.vm.registry.getObject(data);
436
-
437
- if (mho.isNothing()) return nullErr(data);
438
-
439
- return right(mho.get());
440
- } else {
441
- return wrongType(DATA_TYPE_HEAP_FOREIGN, typ);
442
- }
443
- }
444
-
445
- duplicate(): Frame {
446
- let top = <number>this.data.pop();
447
-
448
- this.data.push(top);
449
- this.data.push(top);
450
-
451
- return this;
452
- }
453
-
454
- advance(): Frame {
455
- this.ip = this.ip + 1;
456
-
457
- return this;
458
- }
459
-
460
- seek(loc: number): Frame {
461
- this.ip = loc;
462
-
463
- return this;
464
- }
465
-
466
- isFinished(): boolean {
467
- return this.ip >= this.code.length;
468
- }
469
- }
470
-
471
- const nullErr = <T>(data: Data): Either<Err, T> =>
472
- left(new error.NullPointerErr(data));
473
-
474
- const wrongType = <T>(expect: number, got: number): Either<Err, T> =>
475
- left(new error.UnexpectedDataType(expect, got));
476
-
477
- const notAFunction = <T>(name: string): Either<Err, T> =>
478
- left(new error.InvalidFunctionErr(name));
479
-
480
- //const nullFunPtr = <T>(addr: Data): Either<Err, T> =>
481
- // left(new error.NullFunctionPointerErr(addr));
482
-
483
- const missingSymbol = <T>(data: Data): Either<Err, T> =>
484
- left(new error.MissingSymbolErr(data));
@@ -1,46 +0,0 @@
1
- import { Address } from '../../address';
2
-
3
- /**
4
- * GroupName is the name of a group complying to the regex [a-z][a-z0-9_]* .
5
- */
6
- export type GroupName = string;
7
-
8
- /**
9
- * GroupMap is a mapping of group names to the addresses that form part of the
10
- * group.
11
- */
12
- export class GroupMap {
13
- constructor(public groups = new Map()) {}
14
-
15
- /**
16
- * enroll an actor address into one or more groups.
17
- *
18
- * If the target group(s) do not exist, they are created.
19
- */
20
- enroll(actor: Address, target: GroupName | GroupName[]) {
21
- let targets = Array.isArray(target) ? target : [target];
22
- for (let target of targets) {
23
- let group = this.groups.get(target) ?? new Set();
24
- group.add(actor);
25
- this.groups.set(target, group);
26
- }
27
- return this;
28
- }
29
-
30
- /**
31
- * getMembers returns the addresses for members of a group.
32
- */
33
- getMembers(key: GroupName): Address[] {
34
- return [...(this.groups.get(key) ?? [])];
35
- }
36
-
37
- /**
38
- * unenroll removes an actor address from any groups it is a member of.
39
- */
40
- unenroll(actor: Address) {
41
- for (let group of this.groups.values()) {
42
- if (group.has(actor)) group.delete(actor);
43
- }
44
- return this;
45
- }
46
- }