@harmoniclabs/pebble-cli 0.1.3-dev3 → 0.1.3-dev4

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/index.js CHANGED
@@ -7,6 +7,7 @@ import { completeCompileOptions } from "./compile/completeCompileOptions.js";
7
7
  import { completeExportOptions } from "./export/completeExportOptions.js";
8
8
  import { exportPebbleFunction } from "./export/exportPebbleFunction.js";
9
9
  import { prettyPrintUplcFromFile } from "./uplc/pretty/prettyPrintUplcFromFile.js";
10
+ import { pebbleRepl } from "./repl/pebbleRepl.js";
10
11
  const program = new Command();
11
12
  const versionOutput = (`pebble-cli version: ${PEBBLE_VERSION}
12
13
  pebble language version: ${PEBBLE_LIB_VERSION}
@@ -73,7 +74,8 @@ program.command("init")
73
74
  /*
74
75
  // TODO
75
76
  defineVersionManager( program );
76
-
77
- program.command("repl");
78
77
  //*/
78
+ program.command("repl")
79
+ .description("Start an interactive Pebble REPL")
80
+ .action(pebbleRepl);
79
81
  program.parse();
@@ -0,0 +1 @@
1
+ export declare function pebbleRepl(): Promise<void>;
@@ -0,0 +1,86 @@
1
+ import * as readline from "node:readline/promises";
2
+ import { stdin, stdout } from "node:process";
3
+ import chalk from "chalk";
4
+ import { Compiler, createMemoryCompilerIoApi, defaultOptions, fromUtf8, toHex, ConstTyTag, constTypeToStirng, } from "@harmoniclabs/pebble";
5
+ function formatCEKValue(val) {
6
+ if (val.tag === 5 /* CEKValueTag.Error */) {
7
+ return chalk.red("error") + (val.msg ? `: ${val.msg}` : "");
8
+ }
9
+ if (val.tag === 0 /* CEKValueTag.Const */) {
10
+ switch (val.typeTag) {
11
+ case ConstTyTag.unit: return chalk.blue("void");
12
+ case ConstTyTag.int: return chalk.yellow(val.value.toString());
13
+ case ConstTyTag.bool: return chalk.blue(val.value ? "true" : "false");
14
+ case ConstTyTag.str: return chalk.green(`"${val.value}"`);
15
+ case ConstTyTag.byteStr: return chalk.cyan(`#${toHex(val.value)}`);
16
+ case ConstTyTag.data: return `(data ${JSON.stringify(val.value)})`;
17
+ case ConstTyTag.list:
18
+ case ConstTyTag.pair:
19
+ default:
20
+ return `(${constTypeToStirng(val.type)} ${JSON.stringify(val.value, (_k, v) => typeof v === "bigint" ? v.toString() : v)})`;
21
+ }
22
+ }
23
+ if (val.tag === 3 /* CEKValueTag.Constr */) {
24
+ const fields = val.values.map(formatCEKValue).join(", ");
25
+ return `Constr ${val.index}${fields ? ` [${fields}]` : ""}`;
26
+ }
27
+ return "(lambda)";
28
+ }
29
+ export async function pebbleRepl() {
30
+ const rl = readline.createInterface({ input: stdin, output: stdout });
31
+ console.log(chalk.bold("Pebble REPL"));
32
+ console.log("Type pebble expressions to evaluate them. Use :quit to exit.\n");
33
+ const entryFile = "__repl__.pebble";
34
+ while (true) {
35
+ let input;
36
+ try {
37
+ input = await rl.question(chalk.blue("pebble> "));
38
+ }
39
+ catch {
40
+ // EOF (ctrl+D)
41
+ break;
42
+ }
43
+ const trimmed = input.trim();
44
+ if (!trimmed)
45
+ continue;
46
+ if (trimmed === ":quit" || trimmed === ":q" || trimmed === ":exit") {
47
+ break;
48
+ }
49
+ const ioApi = createMemoryCompilerIoApi({
50
+ sources: new Map([
51
+ [entryFile, fromUtf8(trimmed)],
52
+ ]),
53
+ useConsoleAsOutput: true,
54
+ });
55
+ const compiler = new Compiler(ioApi, {
56
+ ...defaultOptions,
57
+ silent: true,
58
+ });
59
+ try {
60
+ const { result, budgetSpent, logs } = await compiler.runRepl({
61
+ entry: entryFile,
62
+ root: "/",
63
+ });
64
+ // print trace logs
65
+ for (const log of logs) {
66
+ console.log(chalk.magenta("trace:"), log);
67
+ }
68
+ // print result
69
+ console.log(formatCEKValue(result));
70
+ console.log(chalk.dim(`cpu: ${budgetSpent.cpu} | mem: ${budgetSpent.mem}`));
71
+ }
72
+ catch (e) {
73
+ const diagnostics = compiler.diagnostics;
74
+ if (diagnostics.length > 0) {
75
+ for (const d of diagnostics) {
76
+ console.error(chalk.red(String(d)));
77
+ }
78
+ }
79
+ else {
80
+ console.error(chalk.red(e?.message ?? String(e)));
81
+ }
82
+ }
83
+ }
84
+ rl.close();
85
+ console.log("\nBye!");
86
+ }
@@ -1,3 +1,3 @@
1
- export declare const PEBBLE_VERSION = "0.1.3-dev3";
2
- export declare const PEBBLE_LIB_VERSION = "0.1.3-dev3";
3
- export declare const PEBBLE_COMMIT_HASH = "7e8a13d347e9cb0a226abfe5f6c58319358b18d8";
1
+ export declare const PEBBLE_VERSION = "0.1.3-dev4";
2
+ export declare const PEBBLE_LIB_VERSION = "0.1.3-dev4";
3
+ export declare const PEBBLE_COMMIT_HASH = "a29d13ab47da3ed8bd8f3fbf597fd7e27a105cc9";
@@ -1,4 +1,4 @@
1
1
  // This file is auto-generated by scripts/genVersions.js. Do not edit.
2
- export const PEBBLE_VERSION = "0.1.3-dev3";
3
- export const PEBBLE_LIB_VERSION = "0.1.3-dev3";
4
- export const PEBBLE_COMMIT_HASH = "7e8a13d347e9cb0a226abfe5f6c58319358b18d8";
2
+ export const PEBBLE_VERSION = "0.1.3-dev4";
3
+ export const PEBBLE_LIB_VERSION = "0.1.3-dev4";
4
+ export const PEBBLE_COMMIT_HASH = "a29d13ab47da3ed8bd8f3fbf597fd7e27a105cc9";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@harmoniclabs/pebble-cli",
3
- "version": "0.1.3-dev3",
3
+ "version": "0.1.3-dev4",
4
4
  "description": "A simple, yet rock solid, functional language with an imperative bias, targeting UPLC",
5
5
  "bin": {
6
6
  "pebble": "./dist/index.js",
@@ -50,7 +50,7 @@
50
50
  "dependencies": {
51
51
  "@harmoniclabs/crypto": "^0.3.0",
52
52
  "@harmoniclabs/obj-utils": "^1.0.0",
53
- "@harmoniclabs/pebble": "^0.1.3-dev3",
53
+ "@harmoniclabs/pebble": "^0.1.3-dev4",
54
54
  "@harmoniclabs/plutus-machine": "^3.0.0",
55
55
  "@harmoniclabs/uint8array-utils": "^1.0.4",
56
56
  "@harmoniclabs/uplc": "^2.0.5",