septima-lang 0.0.1
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/src/ast-node.d.ts +85 -0
- package/dist/src/ast-node.js +114 -0
- package/dist/src/cdl.d.ts +33 -0
- package/dist/src/cdl.js +63 -0
- package/dist/src/extract-message.d.ts +1 -0
- package/dist/src/extract-message.js +10 -0
- package/dist/src/fail-me.d.ts +1 -0
- package/dist/src/fail-me.js +11 -0
- package/dist/src/find-array-method.d.ts +15 -0
- package/dist/src/find-array-method.js +104 -0
- package/dist/src/find-string-method.d.ts +2 -0
- package/dist/src/find-string-method.js +88 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.js +18 -0
- package/dist/src/location.d.ts +11 -0
- package/dist/src/location.js +3 -0
- package/dist/src/parser.d.ts +37 -0
- package/dist/src/parser.js +345 -0
- package/dist/src/result.d.ts +24 -0
- package/dist/src/result.js +29 -0
- package/dist/src/runtime.d.ts +25 -0
- package/dist/src/runtime.js +287 -0
- package/dist/src/scanner.d.ts +22 -0
- package/dist/src/scanner.js +76 -0
- package/dist/src/should-never-happen.d.ts +1 -0
- package/dist/src/should-never-happen.js +9 -0
- package/dist/src/source-code.d.ts +19 -0
- package/dist/src/source-code.js +90 -0
- package/dist/src/stack.d.ts +11 -0
- package/dist/src/stack.js +19 -0
- package/dist/src/switch-on.d.ts +1 -0
- package/dist/src/switch-on.js +9 -0
- package/dist/src/symbol-table.d.ts +5 -0
- package/dist/src/symbol-table.js +3 -0
- package/dist/src/value.d.ts +128 -0
- package/dist/src/value.js +634 -0
- package/dist/tests/cdl.spec.d.ts +1 -0
- package/dist/tests/cdl.spec.js +692 -0
- package/dist/tests/parser.spec.d.ts +1 -0
- package/dist/tests/parser.spec.js +39 -0
- package/dist/tests/value.spec.d.ts +1 -0
- package/dist/tests/value.spec.js +355 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/jest-output.json +1 -0
- package/package.json +17 -0
- package/src/ast-node.ts +205 -0
- package/src/cdl.ts +78 -0
- package/src/extract-message.ts +5 -0
- package/src/fail-me.ts +7 -0
- package/src/find-array-method.ts +115 -0
- package/src/find-string-method.ts +84 -0
- package/src/index.ts +1 -0
- package/src/location.ts +13 -0
- package/src/parser.ts +399 -0
- package/src/result.ts +45 -0
- package/src/runtime.ts +295 -0
- package/src/scanner.ts +94 -0
- package/src/should-never-happen.ts +4 -0
- package/src/source-code.ts +101 -0
- package/src/stack.ts +18 -0
- package/src/switch-on.ts +4 -0
- package/src/symbol-table.ts +6 -0
- package/src/value.ts +742 -0
- package/tests/cdl.spec.ts +755 -0
- package/tests/parser.spec.ts +14 -0
- package/tests/value.spec.ts +387 -0
- package/tsconfig.json +11 -0
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { AstNode, Lambda } from './ast-node';
|
|
2
|
+
import { CallEvaluator } from './find-array-method';
|
|
3
|
+
import { Span } from './location';
|
|
4
|
+
import * as Stack from './stack';
|
|
5
|
+
import { SymbolTable } from './symbol-table';
|
|
6
|
+
declare type LambdaEvaluator = (names: string[], ast: AstNode, table: SymbolTable) => Value;
|
|
7
|
+
declare type Inner = {
|
|
8
|
+
tag: 'arr';
|
|
9
|
+
val: Value[];
|
|
10
|
+
} | {
|
|
11
|
+
tag: 'bool';
|
|
12
|
+
val: boolean;
|
|
13
|
+
} | {
|
|
14
|
+
tag: 'foreign';
|
|
15
|
+
val: (...args: Value[]) => unknown;
|
|
16
|
+
} | {
|
|
17
|
+
tag: 'lambda';
|
|
18
|
+
val: {
|
|
19
|
+
ast: Lambda;
|
|
20
|
+
table: SymbolTable;
|
|
21
|
+
};
|
|
22
|
+
} | {
|
|
23
|
+
tag: 'num';
|
|
24
|
+
val: number;
|
|
25
|
+
} | {
|
|
26
|
+
tag: 'obj';
|
|
27
|
+
val: Record<string, Value>;
|
|
28
|
+
} | {
|
|
29
|
+
tag: 'sink';
|
|
30
|
+
val: undefined;
|
|
31
|
+
span?: Span;
|
|
32
|
+
trace?: Stack.T;
|
|
33
|
+
symbols?: SymbolTable;
|
|
34
|
+
} | {
|
|
35
|
+
tag: 'str';
|
|
36
|
+
val: string;
|
|
37
|
+
};
|
|
38
|
+
export declare class Value {
|
|
39
|
+
readonly inner: Inner;
|
|
40
|
+
private constructor();
|
|
41
|
+
static bool(val: boolean): Value;
|
|
42
|
+
static num(val: number): Value;
|
|
43
|
+
/**
|
|
44
|
+
* Returns a Value which is essentially a "sink": (almost) every computation involving a sink evaluates to sink. A few
|
|
45
|
+
* quick examples: `5+sink`, `sink.x`, `sink()`, `Object.keys(sink)`, `if (sink) 4 else 8` all evaluate to `sink`. The
|
|
46
|
+
* raitonale is that once an expression evaluates to `sink` all expressions depending on it also evaluate to `sink`.
|
|
47
|
+
*
|
|
48
|
+
* There are however a few (intentional) exemptions:
|
|
49
|
+
* (i) a sink can be passed as an actual parameter in a function call. Hence `(fun (x,y) y)(sink, 5)` will evaluate
|
|
50
|
+
* to `5`.
|
|
51
|
+
* (ii) a sink can be compared with itself.
|
|
52
|
+
* (iii) in `if()` expressions, only one of the branches is evlauated (based on the condition's value). As a result,
|
|
53
|
+
* evluation of a sink-producing branch can be skipping. Specifically, `if (true) 5 else sink` evaluates to `5`.
|
|
54
|
+
* (iv) in `||` and `&&` expressions, the evaluation of the right hand side can be skipped. Specifically,
|
|
55
|
+
* `true || sink` evaluates to `true` and `false && sink` evaluates to `false`.
|
|
56
|
+
*/
|
|
57
|
+
static sink(span?: Span, trace?: Stack.T, symbols?: SymbolTable): Value;
|
|
58
|
+
static str(val: string): Value;
|
|
59
|
+
static arr(val: Value[]): Value;
|
|
60
|
+
static obj(val: Record<string, Value>): Value;
|
|
61
|
+
static lambda(ast: Lambda, table: SymbolTable): Value;
|
|
62
|
+
static foreign(f: (...args: Value[]) => unknown): Value;
|
|
63
|
+
isSink(): boolean;
|
|
64
|
+
unwrap(): unknown;
|
|
65
|
+
assertBool(): boolean;
|
|
66
|
+
assertNum(): number;
|
|
67
|
+
assertStr(): string;
|
|
68
|
+
assertArr(): Value[];
|
|
69
|
+
assertObj(): Record<string, Value>;
|
|
70
|
+
assertLambda(): {
|
|
71
|
+
ast: Lambda;
|
|
72
|
+
table: SymbolTable;
|
|
73
|
+
};
|
|
74
|
+
isLambda(): boolean;
|
|
75
|
+
ifElse(positive: () => Value, negative: () => Value): Value;
|
|
76
|
+
bindToSpan(span: Span): Value;
|
|
77
|
+
trace(): AstNode[] | undefined;
|
|
78
|
+
symbols(): SymbolTable | undefined;
|
|
79
|
+
span(): Span | undefined;
|
|
80
|
+
or(that: () => Value): Value;
|
|
81
|
+
and(that: () => Value): Value;
|
|
82
|
+
unsink(that: () => Value): Value;
|
|
83
|
+
equalsTo(that: Value): Value;
|
|
84
|
+
not(): Value;
|
|
85
|
+
private binaryNumericOperator;
|
|
86
|
+
plus(that: Value): Value;
|
|
87
|
+
minus(that: Value): Value;
|
|
88
|
+
times(that: Value): Value;
|
|
89
|
+
power(that: Value): Value;
|
|
90
|
+
over(that: Value): Value;
|
|
91
|
+
modulo(that: Value): Value;
|
|
92
|
+
negate(): Value;
|
|
93
|
+
isToZero(comparator: '<' | '<=' | '==' | '!=' | '>=' | '>'): Value;
|
|
94
|
+
isTrue(): boolean;
|
|
95
|
+
isZero(): boolean;
|
|
96
|
+
/**
|
|
97
|
+
* Determines the order beteween `this` and the given argument (`that`). The behavior of this method is dictated by
|
|
98
|
+
* the following principles:
|
|
99
|
+
*
|
|
100
|
+
* (i) if a < b then b >= a (i.e., it provides a consistent answer regardless of the whether `this` is `a`
|
|
101
|
+
* and `that` is `b` or vice versa)
|
|
102
|
+
* (ii) ordering two values of different type result in runtime error.
|
|
103
|
+
* (iii) orderingg a value with itself evaluates to `0`
|
|
104
|
+
*
|
|
105
|
+
* Principles (i) and (iii) realizes the intuitive behavior of comparisons. (ii) realizes the idea that
|
|
106
|
+
* "one cannot compare oranges and apples". This is essentially a design decision. We could have gone with defining
|
|
107
|
+
* some order between types (the tag of a Value object), but we feel that a saner approach is to say "we do not know
|
|
108
|
+
* how to sort an array containing numbers and booleans".
|
|
109
|
+
*
|
|
110
|
+
* IMPORTANT: these principles overpower other principles. In parituclar, the principles that "an expression with
|
|
111
|
+
* sink evaluates to sink" is trumped by comparison principle (ii)
|
|
112
|
+
*
|
|
113
|
+
* @param that
|
|
114
|
+
* @returns
|
|
115
|
+
*/
|
|
116
|
+
order(that: Value): Value;
|
|
117
|
+
static toStringOrNumber(input: string | Value): string | number;
|
|
118
|
+
access(indexValue: string | Value, callEvaluator: CallEvaluator): Value;
|
|
119
|
+
call(args: Value[], evaluator: LambdaEvaluator): Value;
|
|
120
|
+
keys(): Value;
|
|
121
|
+
entries(): Value;
|
|
122
|
+
fromEntries(): Value;
|
|
123
|
+
toString(): string;
|
|
124
|
+
toJSON(): unknown;
|
|
125
|
+
export(): unknown;
|
|
126
|
+
static from(u: unknown): Value;
|
|
127
|
+
}
|
|
128
|
+
export {};
|