@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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { mkdirSync, rmSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import { basename, dirname, join, relative, resolve } from 'node:path';
|
|
4
|
+
import { Command } from 'commander';
|
|
5
|
+
import { compile } from './compile.js';
|
|
6
|
+
import { formatDiagnostic } from './diagnostic.js';
|
|
7
|
+
import { fileSystemHost } from './host.js';
|
|
8
|
+
import { findManifest } from './manifest.js';
|
|
9
|
+
import { checkProgram } from './program.js';
|
|
10
|
+
/** A path as people read it: relative to where the command was run, if that is shorter. */
|
|
11
|
+
const shown = (path) => relative(process.cwd(), path) || path;
|
|
12
|
+
/** Print each problem, with the line of source it points to, and how many there are. */
|
|
13
|
+
const printProblems = (problems) => {
|
|
14
|
+
for (const diagnostic of problems) {
|
|
15
|
+
const file = diagnostic.file ?? '';
|
|
16
|
+
const source = fileSystemHost.readFile(file) ?? '';
|
|
17
|
+
console.error(`${formatDiagnostic(shown(file), source, diagnostic)}\n`);
|
|
18
|
+
}
|
|
19
|
+
if (problems.length > 0) {
|
|
20
|
+
console.error(`${String(problems.length)} ${problems.length === 1 ? 'problem' : 'problems'} found.`);
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
/** Whether an entry file couldn't be read, which exits with 2 rather than 1. */
|
|
24
|
+
const unreadable = (problems, entry) => problems.some((diagnostic) => diagnostic.code === 'module-not-found' && diagnostic.file === entry);
|
|
25
|
+
/**
|
|
26
|
+
* Check each file as the entry module of a program, following its imports, and print every
|
|
27
|
+
* problem found in any module it uses. Exit with 1 if there is a problem, or 2 if an entry file
|
|
28
|
+
* can't be read.
|
|
29
|
+
*/
|
|
30
|
+
const checkFiles = (files) => {
|
|
31
|
+
const seen = new Set();
|
|
32
|
+
const problems = [];
|
|
33
|
+
let missing = false;
|
|
34
|
+
for (const file of files) {
|
|
35
|
+
const program = checkProgram(file, fileSystemHost);
|
|
36
|
+
if (unreadable(program.diagnostics, program.entry))
|
|
37
|
+
missing = true;
|
|
38
|
+
for (const diagnostic of program.diagnostics) {
|
|
39
|
+
// A module imported by several entry files is only reported once.
|
|
40
|
+
const key = `${diagnostic.file ?? ''}:${String(diagnostic.position.start.offset)}:${diagnostic.code}:${diagnostic.message}`;
|
|
41
|
+
if (seen.has(key))
|
|
42
|
+
continue;
|
|
43
|
+
seen.add(key);
|
|
44
|
+
problems.push(diagnostic);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
printProblems(problems);
|
|
48
|
+
process.exitCode = missing ? 2 : problems.length > 0 ? 1 : 0;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Compile a program and write the compiled program, and its source map beside it, as JSON
|
|
52
|
+
* (docs/adr/0039-compiled-programs.md). If the program has problems, report them, write
|
|
53
|
+
* nothing, and remove what an earlier build wrote, so what is on disk always matches the source.
|
|
54
|
+
*/
|
|
55
|
+
const build = (file, options) => {
|
|
56
|
+
const entry = resolve(file);
|
|
57
|
+
const root = dirname(findManifest(entry, fileSystemHost).manifest?.path ?? entry);
|
|
58
|
+
const output = options.output === undefined ? join(root, `${basename(entry, '.cant')}.compiled.json`) : resolve(options.output);
|
|
59
|
+
const map = `${output}.map`;
|
|
60
|
+
const result = compile(entry, fileSystemHost);
|
|
61
|
+
if ('diagnostics' in result) {
|
|
62
|
+
rmSync(output, { force: true });
|
|
63
|
+
rmSync(map, { force: true });
|
|
64
|
+
printProblems(result.diagnostics);
|
|
65
|
+
process.exitCode = unreadable(result.diagnostics, entry) ? 2 : 1;
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
mkdirSync(dirname(output), { recursive: true });
|
|
69
|
+
writeFileSync(output, `${JSON.stringify(result.program)}\n`);
|
|
70
|
+
if (options.sourceMap)
|
|
71
|
+
writeFileSync(map, `${JSON.stringify(result.sourceMap)}\n`);
|
|
72
|
+
else
|
|
73
|
+
rmSync(map, { force: true });
|
|
74
|
+
console.log(`Wrote ${shown(output)}${options.sourceMap ? ` and ${shown(map)}` : ''}.`);
|
|
75
|
+
};
|
|
76
|
+
const program = new Command().name('cant').description('The Cant compiler');
|
|
77
|
+
program
|
|
78
|
+
.command('check')
|
|
79
|
+
.description('Check Cant programs: parse each file and the modules it imports, and report every problem the compiler finds')
|
|
80
|
+
.argument('<files...>', 'the entry .cant file of each program to check')
|
|
81
|
+
.action(checkFiles);
|
|
82
|
+
program
|
|
83
|
+
.command('build')
|
|
84
|
+
.description("Compile a Cant program, and write the compiled program and its source map, which the interpreter runs")
|
|
85
|
+
.argument('<file>', "the program's entry .cant file")
|
|
86
|
+
.option('-o, --output <file>', 'where to write the compiled program (default: <entry>.compiled.json in the program\'s root)')
|
|
87
|
+
.option('--no-source-map', "don't write a source map, so the interpreter reports positions without source")
|
|
88
|
+
.action(build);
|
|
89
|
+
program.parse();
|
|
90
|
+
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC3D,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACvE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,gBAAgB,EAAmB,MAAM,iBAAiB,CAAC;AACpE,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE5C,2FAA2F;AAC3F,MAAM,KAAK,GAAG,CAAC,IAAY,EAAU,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,IAAI,CAAC,IAAI,IAAI,CAAC;AAE9E,wFAAwF;AACxF,MAAM,aAAa,GAAG,CAAC,QAAsB,EAAQ,EAAE;IACrD,KAAK,MAAM,UAAU,IAAI,QAAQ,EAAE,CAAC;QAClC,MAAM,IAAI,GAAG,UAAU,CAAC,IAAI,IAAI,EAAE,CAAC;QACnC,MAAM,MAAM,GAAG,cAAc,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;QACnD,OAAO,CAAC,KAAK,CAAC,GAAG,gBAAgB,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,IAAI,CAAC,CAAC;IAC1E,CAAC;IACD,IAAI,QAAQ,CAAC,MAAM,GAAG,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
import { type CompiledProgram, type SourceMap } from '@dancrumb/cant-shared';
|
|
2
|
+
import type { Diagnostic } from './diagnostic.ts';
|
|
3
|
+
import { type Host } from './host.ts';
|
|
4
|
+
import { type CheckedProgram } from './program.ts';
|
|
5
|
+
export type CompileResult = {
|
|
6
|
+
program: CompiledProgram;
|
|
7
|
+
sourceMap: SourceMap;
|
|
8
|
+
root: string;
|
|
9
|
+
} | {
|
|
10
|
+
diagnostics: Diagnostic[];
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Compile a program, starting from its entry module: check it, and if it has no compile-time
|
|
14
|
+
* errors, give the compiled program the interpreter runs, and its source map
|
|
15
|
+
* (docs/adr/0039-compiled-programs.md). Otherwise, give the diagnostics that stopped it.
|
|
16
|
+
*/
|
|
17
|
+
export declare function compile(entry: string, host?: Host): CompileResult;
|
|
18
|
+
/** The program's root: the directory that holds its `cant.json`, or the entry module's directory. */
|
|
19
|
+
export declare const rootOf: (program: CheckedProgram) => string;
|
|
20
|
+
//# sourceMappingURL=compile.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../src/compile.ts"],"names":[],"mappings":"AAEA,OAAO,EAQL,KAAK,eAAe,EAapB,KAAK,SAAS,EAMf,MAAM,uBAAuB,CAAC;AAG/B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAElD,OAAO,EAAkB,KAAK,IAAI,EAAE,MAAM,WAAW,CAAC;AAEtD,OAAO,EAAgB,KAAK,cAAc,EAAE,MAAM,cAAc,CAAC;AAIjE,MAAM,MAAM,aAAa,GAAG;IAAE,OAAO,EAAE,eAAe,CAAC;IAAC,SAAS,EAAE,SAAS,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,WAAW,EAAE,UAAU,EAAE,CAAA;CAAE,CAAC;AAE7H;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,GAAE,IAAqB,GAAG,aAAa,CAIjF;AAED,qGAAqG;AACrG,eAAO,MAAM,MAAM,YAAa,cAAc,KAAG,MAA0D,CAAC"}
|