@mojir/dvala 0.0.18 → 0.0.19

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 (2) hide show
  1. package/dist/cli/cli.js +68 -20
  2. package/package.json +7 -3
package/dist/cli/cli.js CHANGED
@@ -478,7 +478,7 @@ function findAllOccurrences(input, pattern) {
478
478
  }
479
479
  //#endregion
480
480
  //#region package.json
481
- var version = "0.0.18";
481
+ var version = "0.0.19";
482
482
  //#endregion
483
483
  //#region src/typeGuards/string.ts
484
484
  function isString(value, options = {}) {
@@ -5232,7 +5232,7 @@ function generateDocString(reference) {
5232
5232
  ${argStrings(reference).join("\n ")}
5233
5233
 
5234
5234
  Examples:
5235
- ${reference.examples.map((example) => smartTrim(example, 4)).join("\n\n")}`);
5235
+ ${reference.examples.map((example) => smartTrim(typeof example === "string" ? example : example.code, 4)).join("\n\n")}`);
5236
5236
  }
5237
5237
  function isEffectRef(ref) {
5238
5238
  return "effect" in ref;
@@ -24391,7 +24391,13 @@ const standardEffects = {
24391
24391
  description: "Value to print."
24392
24392
  } },
24393
24393
  variants: [{ argumentNames: ["value"] }],
24394
- examples: ["perform(effect(dvala.io.print), \"hello\")", "perform(effect(dvala.io.print), 42)"],
24394
+ examples: [{
24395
+ code: "perform(effect(dvala.io.print), \"hello\")",
24396
+ noRun: true
24397
+ }, {
24398
+ code: "perform(effect(dvala.io.print), 42)",
24399
+ noRun: true
24400
+ }],
24395
24401
  seeAlso: [
24396
24402
  "-effect-dvala.io.println",
24397
24403
  "-effect-dvala.io.error",
@@ -24413,7 +24419,13 @@ const standardEffects = {
24413
24419
  description: "Value to print."
24414
24420
  } },
24415
24421
  variants: [{ argumentNames: ["value"] }],
24416
- examples: ["perform(effect(dvala.io.println), \"hello\")", "perform(effect(dvala.io.println), [1, 2, 3])"],
24422
+ examples: [{
24423
+ code: "perform(effect(dvala.io.println), \"hello\")",
24424
+ noRun: true
24425
+ }, {
24426
+ code: "perform(effect(dvala.io.println), [1, 2, 3])",
24427
+ noRun: true
24428
+ }],
24417
24429
  seeAlso: [
24418
24430
  "-effect-dvala.io.print",
24419
24431
  "-effect-dvala.io.error",
@@ -24445,7 +24457,10 @@ const standardEffects = {
24445
24457
  description: "Value to write to stderr."
24446
24458
  } },
24447
24459
  variants: [{ argumentNames: ["value"] }],
24448
- examples: ["perform(effect(dvala.io.error), \"something went wrong\")"],
24460
+ examples: [{
24461
+ code: "perform(effect(dvala.io.error), \"something went wrong\")",
24462
+ noRun: true
24463
+ }],
24449
24464
  seeAlso: [
24450
24465
  "-effect-dvala.io.print",
24451
24466
  "-effect-dvala.io.println",
@@ -25331,14 +25346,11 @@ function deriveEffectReference() {
25331
25346
  return result;
25332
25347
  }
25333
25348
  const effectReference = deriveEffectReference();
25334
- const allReference = sortByCategory({
25349
+ sortByCategory({
25335
25350
  ...apiReference,
25336
25351
  ...moduleReference,
25337
25352
  ...effectReference
25338
25353
  });
25339
- Object.values(allReference).forEach((ref) => {
25340
- ref.title = ref.title.replace(/"/g, """);
25341
- });
25342
25354
  function sortByCategory(ref) {
25343
25355
  return Object.fromEntries(Object.entries(ref).sort(([keyA, refA], [keyB, refB]) => {
25344
25356
  const catA = refA.category === "special-expression" ? "" : refA.category;
@@ -28110,6 +28122,22 @@ var ResumeFromSignal = class {
28110
28122
  function isResumeFromSignal(value) {
28111
28123
  return value instanceof ResumeFromSignal;
28112
28124
  }
28125
+ /**
28126
+ * Thrown (as a promise rejection) by `halt()` inside a host handler.
28127
+ * Caught by the effect trampoline loop — NOT by Dvala-level try/catch.
28128
+ * Terminates execution immediately and returns a halted result.
28129
+ */
28130
+ var HaltSignal = class {
28131
+ _brand = "HaltSignal";
28132
+ constructor(value, snapshots, nextSnapshotIndex) {
28133
+ this.value = value;
28134
+ this.snapshots = snapshots;
28135
+ this.nextSnapshotIndex = nextSnapshotIndex;
28136
+ }
28137
+ };
28138
+ function isHaltSignal(value) {
28139
+ return value instanceof HaltSignal;
28140
+ }
28113
28141
  //#endregion
28114
28142
  //#region src/evaluator/effectRef.ts
28115
28143
  const internMap = /* @__PURE__ */ new Map();
@@ -30671,6 +30699,8 @@ function dispatchHostHandler(effectName, matchingHandlers, args, k, signal, sour
30671
30699
  }
30672
30700
  function tryHandler(index) {
30673
30701
  if (index >= matchingHandlers.length) {
30702
+ const standardHandler = getStandardEffectHandler(effectName);
30703
+ if (standardHandler) return standardHandler(args, k, sourceCodeInfo);
30674
30704
  if (effectName === "dvala.error") throw new UserDefinedError(typeof argsArray[0] === "string" ? argsArray[0] : String(argsArray[0] ?? "Unknown error"), sourceCodeInfo);
30675
30705
  if (effectName === "dvala.checkpoint") return {
30676
30706
  type: "Value",
@@ -30679,11 +30709,7 @@ function dispatchHostHandler(effectName, matchingHandlers, args, k, signal, sour
30679
30709
  };
30680
30710
  throw new DvalaError(`Unhandled effect: '${effectName}'`, sourceCodeInfo);
30681
30711
  }
30682
- const [pattern, handler] = matchingHandlers[index];
30683
- if (pattern === "*") {
30684
- const standardHandler = getStandardEffectHandler(effectName);
30685
- if (standardHandler) return standardHandler(args, k, sourceCodeInfo);
30686
- }
30712
+ const [_pattern, handler] = matchingHandlers[index];
30687
30713
  let outcome;
30688
30714
  let settled = false;
30689
30715
  function assertNotSettled(operation) {
@@ -30758,10 +30784,17 @@ function dispatchHostHandler(effectName, matchingHandlers, args, k, signal, sour
30758
30784
  kind: "throw",
30759
30785
  error: new ResumeFromSignal(found.continuation, value, found.index)
30760
30786
  };
30787
+ },
30788
+ halt: (value = null) => {
30789
+ assertNotSettled("halt");
30790
+ outcome = {
30791
+ kind: "throw",
30792
+ error: new HaltSignal(value, snapshotState ? snapshotState.snapshots : [], snapshotState ? snapshotState.nextSnapshotIndex : 0)
30793
+ };
30761
30794
  }
30762
30795
  });
30763
30796
  if (!(handlerResult instanceof Promise)) {
30764
- if (!outcome) throw new DvalaError(`Effect handler for '${effectName}' did not call resume(), fail(), suspend(), or next()`, sourceCodeInfo);
30797
+ if (!outcome) throw new DvalaError(`Effect handler for '${effectName}' did not call resume(), fail(), suspend(), halt(), or next()`, sourceCodeInfo);
30765
30798
  return resolveOutcome(outcome, index + 1);
30766
30799
  }
30767
30800
  if (outcome) {
@@ -30769,11 +30802,11 @@ function dispatchHostHandler(effectName, matchingHandlers, args, k, signal, sour
30769
30802
  return resolveOutcome(outcome, index + 1);
30770
30803
  }
30771
30804
  return handlerResult.then(() => {
30772
- if (!outcome) throw new DvalaError(`Effect handler for '${effectName}' did not call resume(), fail(), suspend(), or next()`, sourceCodeInfo);
30805
+ if (!outcome) throw new DvalaError(`Effect handler for '${effectName}' did not call resume(), fail(), suspend(), halt(), or next()`, sourceCodeInfo);
30773
30806
  return resolveOutcome(outcome, index + 1);
30774
30807
  }, (e) => {
30775
30808
  if (outcome) return resolveOutcome(outcome, index + 1);
30776
- if (isSuspensionSignal(e) || isResumeFromSignal(e)) throw e;
30809
+ if (isSuspensionSignal(e) || isResumeFromSignal(e) || isHaltSignal(e)) throw e;
30777
30810
  return {
30778
30811
  type: "Error",
30779
30812
  error: e instanceof DvalaError ? e : new DvalaError(e instanceof Error ? e : `${e}`, sourceCodeInfo),
@@ -31697,7 +31730,7 @@ function tick(step, handlers, signal, snapshotState) {
31697
31730
  }
31698
31731
  }
31699
31732
  } catch (error) {
31700
- if (isSuspensionSignal(error)) throw error;
31733
+ if (isSuspensionSignal(error) || isHaltSignal(error)) throw error;
31701
31734
  if (error instanceof DvalaError) {
31702
31735
  const effectStep = tryDispatchDvalaError(error, step.type === "Value" ? step.k.slice(1) : step.k, handlers, signal, snapshotState);
31703
31736
  if (effectStep !== null) return effectStep;
@@ -31833,8 +31866,9 @@ async function runEffectLoop(initial, handlers, signal, initialSnapshotState, ma
31833
31866
  const continuation = serializeTerminalSnapshot(snapshotState.snapshots, snapshotState.nextSnapshotIndex);
31834
31867
  const meta = {};
31835
31868
  if (options?.error) meta.error = options.error.toJSON();
31869
+ if (options?.halted) meta.halted = true;
31836
31870
  if (options?.result !== void 0) meta.result = options.result;
31837
- const message = options?.error ? "Run failed with error" : "Run completed successfully";
31871
+ const message = options?.error ? "Run failed with error" : options?.halted ? "Program halted" : "Run completed successfully";
31838
31872
  return createSnapshot({
31839
31873
  continuation,
31840
31874
  timestamp: Date.now(),
@@ -31901,6 +31935,20 @@ async function runEffectLoop(initial, handlers, signal, initialSnapshotState, ma
31901
31935
  effectArgs: error.effectArgs
31902
31936
  })
31903
31937
  };
31938
+ if (isHaltSignal(error)) {
31939
+ const snapshot = createTerminalSnapshot({
31940
+ result: error.value,
31941
+ halted: true
31942
+ });
31943
+ return snapshot ? {
31944
+ type: "halted",
31945
+ value: error.value,
31946
+ snapshot
31947
+ } : {
31948
+ type: "halted",
31949
+ value: error.value
31950
+ };
31951
+ }
31904
31952
  if (error instanceof DvalaError) {
31905
31953
  const snapshot = createTerminalSnapshot({ error });
31906
31954
  return snapshot ? {
@@ -33910,7 +33958,7 @@ function getArgumentInfo(fmt, reference) {
33910
33958
  const dvala = createDvala({ debug: false });
33911
33959
  function getCliFunctionExamples(fmt, reference) {
33912
33960
  const { examples } = reference;
33913
- return examples.map((example) => example.trim()).map((example) => {
33961
+ return examples.map((example) => (typeof example === "string" ? example : example.code).trim()).map((example) => {
33914
33962
  const oldLog = console.log;
33915
33963
  console.log = function() {};
33916
33964
  let result;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mojir/dvala",
3
- "version": "0.0.18",
3
+ "version": "0.0.19",
4
4
  "description": "dvala",
5
5
  "author": "Albert Mojir",
6
6
  "license": "MIT",
@@ -136,7 +136,7 @@
136
136
  "build-playground": "wireit",
137
137
  "build-vscode-ext": "wireit",
138
138
  "dvala": "node ./dist/cli/cli.js",
139
- "dev": "npx serve docs -p 9901",
139
+ "dev": "npx serve docs -p 9901 --single",
140
140
  "test:e2e": "npx playwright test",
141
141
  "test:e2e:prod": "E2E_BASE_URL=https://mojir.github.io/dvala npx playwright test",
142
142
  "test:e2e:headed": "npx playwright test --headed",
@@ -157,7 +157,7 @@
157
157
  "@vscode/vsce": "^3.7.1",
158
158
  "esbuild": "^0.27.3",
159
159
  "eslint": "^10.0.3",
160
- "open-cli": "8.0.0",
160
+ "open-cli": "^5.0.0",
161
161
  "rolldown": "^1.0.0-rc.8",
162
162
  "serve": "^14.2.6",
163
163
  "tslib": "^2.8.1",
@@ -298,6 +298,7 @@
298
298
  "src/**",
299
299
  "common/**",
300
300
  "reference/**/*.ts",
301
+ "tutorials/**",
301
302
  "rolldown.config.playground-builder.mjs",
302
303
  "rolldown.config.playground-www.mjs",
303
304
  "rolldown.plugins.mjs",
@@ -326,5 +327,8 @@
326
327
  ],
327
328
  "clean": "if-file-deleted"
328
329
  }
330
+ },
331
+ "dependencies": {
332
+ "marked": "^17.0.4"
329
333
  }
330
334
  }