@dancrumb/cant-compiler 0.0.0-stage → 0.10.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/dist/bodies.d.ts +33 -0
- package/dist/bodies.d.ts.map +1 -0
- package/dist/bodies.js +512 -0
- package/dist/bodies.js.map +1 -0
- package/dist/check.d.ts +18 -0
- package/dist/check.d.ts.map +1 -0
- package/dist/check.js +30 -0
- package/dist/check.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +90 -0
- package/dist/cli.js.map +1 -0
- package/dist/compile.d.ts +20 -0
- package/dist/compile.d.ts.map +1 -0
- package/dist/compile.js +777 -0
- package/dist/compile.js.map +1 -0
- package/dist/constants.d.ts +22 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +262 -0
- package/dist/constants.js.map +1 -0
- package/dist/declarations.d.ts +54 -0
- package/dist/declarations.d.ts.map +1 -0
- package/dist/declarations.js +202 -0
- package/dist/declarations.js.map +1 -0
- package/dist/diagnostic.d.ts +19 -0
- package/dist/diagnostic.d.ts.map +1 -0
- package/dist/diagnostic.js +27 -0
- package/dist/diagnostic.js.map +1 -0
- package/dist/entities.d.ts +32 -0
- package/dist/entities.d.ts.map +1 -0
- package/dist/entities.js +235 -0
- package/dist/entities.js.map +1 -0
- package/dist/evaluate.d.ts +30 -0
- package/dist/evaluate.d.ts.map +1 -0
- package/dist/evaluate.js +79 -0
- package/dist/evaluate.js.map +1 -0
- package/dist/host.d.ts +8 -0
- package/dist/host.d.ts.map +1 -0
- package/dist/host.js +13 -0
- package/dist/host.js.map +1 -0
- package/dist/index.d.ts +31 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +16 -0
- package/dist/index.js.map +1 -0
- package/dist/manifest.d.ts +23 -0
- package/dist/manifest.d.ts.map +1 -0
- package/dist/manifest.js +93 -0
- package/dist/manifest.js.map +1 -0
- package/dist/modules.d.ts +84 -0
- package/dist/modules.d.ts.map +1 -0
- package/dist/modules.js +259 -0
- package/dist/modules.js.map +1 -0
- package/dist/program.d.ts +24 -0
- package/dist/program.d.ts.map +1 -0
- package/dist/program.js +38 -0
- package/dist/program.js.map +1 -0
- package/dist/resolve.d.ts +24 -0
- package/dist/resolve.d.ts.map +1 -0
- package/dist/resolve.js +203 -0
- package/dist/resolve.js.map +1 -0
- package/dist/stdlib.d.ts +12 -0
- package/dist/stdlib.d.ts.map +1 -0
- package/dist/stdlib.js +38 -0
- package/dist/stdlib.js.map +1 -0
- package/dist/typecheck.d.ts +52 -0
- package/dist/typecheck.d.ts.map +1 -0
- package/dist/typecheck.js +1408 -0
- package/dist/typecheck.js.map +1 -0
- package/dist/types.d.ts +130 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +199 -0
- package/dist/types.js.map +1 -0
- package/dist/weave.d.ts +3 -0
- package/dist/weave.d.ts.map +1 -0
- package/dist/weave.js +40 -0
- package/dist/weave.js.map +1 -0
- package/package.json +47 -3
- package/README.md +0 -3
package/dist/stdlib.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The modules of the `cant` scope, which are built into the interpreter
|
|
3
|
+
* (docs/adr/0031-module-resolution.md). They are native modules whose declarations can use
|
|
4
|
+
* internal types that Cant source can't write (docs/adr/0036-native-modules.md), so the compiler
|
|
5
|
+
* describes them here, by the names they export, rather than reading them from Cant files.
|
|
6
|
+
*
|
|
7
|
+
* Only names are listed for now: their signatures arrive with type checking.
|
|
8
|
+
*/
|
|
9
|
+
export const STANDARD_LIBRARY = new Map([
|
|
10
|
+
// docs/adr/0021-collections.md
|
|
11
|
+
[
|
|
12
|
+
'Collections',
|
|
13
|
+
actions('length', 'size', 'concat', 'join', 'keys', 'values', 'add', 'remove', 'intersect', 'difference', 'isSubset'),
|
|
14
|
+
],
|
|
15
|
+
// docs/adr/0023-error-handling.md, docs/adr/0035-entity-relationships.md
|
|
16
|
+
[
|
|
17
|
+
'Errors',
|
|
18
|
+
errors('DivisionByZero', 'FractionalModulo', 'InvalidEnumValue', 'IndexBeforeStart', 'DefaultUnavailable', 'RequiredField', 'UnknownField', 'CardinalityViolation'),
|
|
19
|
+
],
|
|
20
|
+
// docs/adr/0026-dates-and-times.md
|
|
21
|
+
[
|
|
22
|
+
'Time',
|
|
23
|
+
new Map([
|
|
24
|
+
...actions('addDays', 'addMonths', 'addYears', 'format', 'parse'),
|
|
25
|
+
...errors('UnknownTimeZone', 'NotWholeNumber', 'InvalidDateTime'),
|
|
26
|
+
]),
|
|
27
|
+
],
|
|
28
|
+
// docs/adr/0015-files.md leaves `cant::IO` to be designed. `write` is the one action the ADRs'
|
|
29
|
+
// examples use (docs/adr/0006-imports.md, 0012).
|
|
30
|
+
['IO', actions('write')],
|
|
31
|
+
]);
|
|
32
|
+
function actions(...names) {
|
|
33
|
+
return new Map(names.map((name) => [name, 'action']));
|
|
34
|
+
}
|
|
35
|
+
function errors(...names) {
|
|
36
|
+
return new Map(names.map((name) => [name, 'error']));
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=stdlib.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stdlib.js","sourceRoot":"","sources":["../src/stdlib.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAKH,MAAM,CAAC,MAAM,gBAAgB,GAA2D,IAAI,GAAG,CAAC;IAC9F,+BAA+B;IAC/B;QACE,aAAa;QACb,OAAO,CACL,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EACpD,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,YAAY,EAAE,UAAU,CACvD;KACF;IACD,yEAAyE;IACzE;QACE,QAAQ;QACR,MAAM,CACJ,gBAAgB,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,kBAAkB,EAC5E,oBAAoB,EAAE,eAAe,EAAE,cAAc,EAAE,sBAAsB,CAC9E;KACF;IACD,mCAAmC;IACnC;QACE,MAAM;QACN,IAAI,GAAG,CAAC;YACN,GAAG,OAAO,CAAC,SAAS,EAAE,WAAW,EAAE,UAAU,EAAE,QAAQ,EAAE,OAAO,CAAC;YACjE,GAAG,MAAM,CAAC,iBAAiB,EAAE,gBAAgB,EAAE,iBAAiB,CAAC;SAClE,CAAC;KACH;IACD,+FAA+F;IAC/F,iDAAiD;IACjD,CAAC,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;CACzB,CAAC,CAAC;AAEH,SAAS,OAAO,CAAC,GAAG,KAAe;IACjC,OAAO,IAAI,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC;AACxD,CAAC;AAED,SAAS,MAAM,CAAC,GAAG,KAAe;IAChC,OAAO,IAAI,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;AACvD,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { Expression } from '@dancrumb/cant-shared';
|
|
2
|
+
import type { Locals } from './bodies.ts';
|
|
3
|
+
import { type Diagnostic } from './diagnostic.ts';
|
|
4
|
+
import type { NavigationField } from './entities.ts';
|
|
5
|
+
import type { LoadedProgram } from './modules.ts';
|
|
6
|
+
import type { References } from './resolve.ts';
|
|
7
|
+
import { type ModelFields, type Type } from './types.ts';
|
|
8
|
+
/** What the type checker needs from the earlier passes. */
|
|
9
|
+
export interface ResolvedProgram extends LoadedProgram {
|
|
10
|
+
references: References;
|
|
11
|
+
locals: Locals;
|
|
12
|
+
navigation: Map<string, Map<string, NavigationField>>;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Check the types of every expression and statement in a program (docs/adr/0012-base-types.md
|
|
16
|
+
* and the ADRs that build on it), and report what doesn't fit:
|
|
17
|
+
*
|
|
18
|
+
* - operators given operands they don't take (docs/adr/0019-operators.md, 0026);
|
|
19
|
+
* - conditions that aren't `BOOLEAN`, and messages that aren't `TEXT`;
|
|
20
|
+
* - values given where they don't fit: arguments, returns, assignments, defaults and constants,
|
|
21
|
+
* including enum compatibility (docs/adr/0013-enums.md) and object values matched against
|
|
22
|
+
* models (docs/adr/0027-object-shapes.md);
|
|
23
|
+
* - fields and members a value doesn't have;
|
|
24
|
+
* - optionals used before they are checked, and `isEmpty` and `orElse` on values that aren't
|
|
25
|
+
* optional, with narrowing by `isEmpty`, `instanceOf` and `@subject is`, through `!`, `and`,
|
|
26
|
+
* `or`, early returns and `assert` (docs/adr/0014-optionals.md, 0016, 0033, 0010);
|
|
27
|
+
* - values that can't be interpolated into text (docs/adr/0011-converting-values-to-text.md);
|
|
28
|
+
* - actions that can end without returning a value;
|
|
29
|
+
* - error handling (docs/adr/0023-error-handling.md): `raises` and `passes` clauses, results
|
|
30
|
+
* that are never handled, unchecked results returned, errors raised or passed that the action
|
|
31
|
+
* doesn't declare, `raise` data, errors from `/` and `%` and from statements, and the types of
|
|
32
|
+
* `@result` and `@error`.
|
|
33
|
+
*/
|
|
34
|
+
/**
|
|
35
|
+
* What the type checker found about expressions, which the compiler needs to make the runtime
|
|
36
|
+
* behaviour that depends on types explicit (docs/adr/0039-compiled-programs.md).
|
|
37
|
+
*/
|
|
38
|
+
export interface TypeRecord {
|
|
39
|
+
/** Each expression's type, without using a result it may give. */
|
|
40
|
+
types: Map<Expression, Type>;
|
|
41
|
+
/** The type each expression's value must fit, where one is expected. */
|
|
42
|
+
expected: Map<Expression, Type>;
|
|
43
|
+
/** The expressions whose result is used unchecked, which panics if it holds an error. */
|
|
44
|
+
unwrapped: Set<Expression>;
|
|
45
|
+
/** The fields of named models, as the type checker reads them. */
|
|
46
|
+
modelFields: ModelFields;
|
|
47
|
+
}
|
|
48
|
+
export declare function checkTypes(program: ResolvedProgram): {
|
|
49
|
+
diagnostics: Diagnostic[];
|
|
50
|
+
record: TypeRecord;
|
|
51
|
+
};
|
|
52
|
+
//# sourceMappingURL=typecheck.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typecheck.d.ts","sourceRoot":"","sources":["../src/typecheck.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAMV,UAAU,EASX,MAAM,uBAAuB,CAAC;AAE/B,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAS,KAAK,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAEzD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,KAAK,EAAE,aAAa,EAAwB,MAAM,cAAc,CAAC;AACxE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAsBL,KAAK,WAAW,EAChB,KAAK,IAAI,EACV,MAAM,YAAY,CAAC;AAEpB,2DAA2D;AAC3D,MAAM,WAAW,eAAgB,SAAQ,aAAa;IACpD,UAAU,EAAE,UAAU,CAAC;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC,CAAC;CACvD;AAsCD;;;;;;;;;;;;;;;;;;;GAmBG;AACH;;;GAGG;AACH,MAAM,WAAW,UAAU;IACzB,kEAAkE;IAClE,KAAK,EAAE,GAAG,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;IAC7B,wEAAwE;IACxE,QAAQ,EAAE,GAAG,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;IAChC,yFAAyF;IACzF,SAAS,EAAE,GAAG,CAAC,UAAU,CAAC,CAAC;IAC3B,kEAAkE;IAClE,WAAW,EAAE,WAAW,CAAC;CAC1B;AAED,wBAAgB,UAAU,CAAC,OAAO,EAAE,eAAe,GAAG;IAAE,WAAW,EAAE,UAAU,EAAE,CAAC;IAAC,MAAM,EAAE,UAAU,CAAA;CAAE,CAStG"}
|