cashc 0.13.1 → 0.13.2

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.
@@ -42,7 +42,9 @@ export default class GenerateTargetTraversalWithLocation extends AstTraversal {
42
42
  visitDoWhile(node: DoWhileNode): Node;
43
43
  visitWhile(node: WhileNode): Node;
44
44
  visitFor(node: ForNode): Node;
45
+ private emitLoopCondition;
45
46
  removeScopedVariables(depthBeforeScope: number, node: Node): void;
47
+ private tagScopeCleanup;
46
48
  visitCast(node: CastNode): Node;
47
49
  visitFunctionCall(node: FunctionCallNode): Node;
48
50
  visitMultiSig(node: FunctionCallNode): Node;
@@ -151,11 +151,13 @@ export default class GenerateTargetTraversalWithLocation extends AstTraversal {
151
151
  }
152
152
  cleanStack(functionBodyNode) {
153
153
  // Keep final verification value, OP_NIP the other stack values
154
+ const tagStartIndex = this.output.length;
154
155
  const stackSize = this.stack.length;
155
156
  for (let i = 0; i < stackSize - 1; i += 1) {
156
157
  this.emit(Op.OP_NIP, { location: functionBodyNode.location, positionHint: PositionHint.END });
157
158
  this.nipFromStack();
158
159
  }
160
+ this.tagScopeCleanup(tagStartIndex);
159
161
  }
160
162
  enforceFunctionParameterTypes(node) {
161
163
  node.parameters.forEach((parameter) => this.enforceFunctionParameterType(parameter));
@@ -349,12 +351,7 @@ export default class GenerateTargetTraversalWithLocation extends AstTraversal {
349
351
  const bodyStackDepth = this.stack.length;
350
352
  node.block = this.visit(node.block);
351
353
  this.removeScopedVariables(bodyStackDepth, node.block);
352
- this.emit(Op.OP_ENDIF, { location: node.block.location, positionHint: PositionHint.END });
353
- this.emit(Op.OP_FROMALTSTACK, { location: node.block.location, positionHint: PositionHint.END });
354
- this.pushToStack('(value)');
355
- this.emit(Op.OP_NOT, { location: node.location, positionHint: PositionHint.END });
356
- this.emit(Op.OP_UNTIL, { location: node.location, positionHint: PositionHint.END });
357
- this.popFromStack();
354
+ this.emitLoopCondition(node);
358
355
  this.scopeDepth -= 1;
359
356
  return node;
360
357
  }
@@ -377,22 +374,46 @@ export default class GenerateTargetTraversalWithLocation extends AstTraversal {
377
374
  const updateEndIndex = this.output.length - 1;
378
375
  this.sourceTags.push({ startIndex: updateStartIndex, endIndex: updateEndIndex, kind: SourceTagKind.FOR_UPDATE });
379
376
  this.removeScopedVariables(bodyStackDepth, node.block);
377
+ this.emitLoopCondition(node);
378
+ this.scopeDepth -= 1;
379
+ this.removeScopedVariables(forScopeStackDepth, node);
380
+ return node;
381
+ }
382
+ // Emits the loop-back epilogue shared by while- and for-loops: OP_ENDIF closes the body branch,
383
+ // then OP_FROMALTSTACK OP_NOT OP_UNTIL re-checks the saved condition and jumps back. These are
384
+ // compiler-injected and map to the closing brace; tag them so the debug reconstruction renders a
385
+ // ">>> loop condition check" annotation line (and the following loop-variable cleanup) before the brace.
386
+ emitLoopCondition(node) {
387
+ const tagStartIndex = this.output.length;
380
388
  this.emit(Op.OP_ENDIF, { location: node.block.location, positionHint: PositionHint.END });
381
389
  this.emit(Op.OP_FROMALTSTACK, { location: node.block.location, positionHint: PositionHint.END });
382
390
  this.pushToStack('(value)');
383
391
  this.emit(Op.OP_NOT, { location: node.location, positionHint: PositionHint.END });
384
392
  this.emit(Op.OP_UNTIL, { location: node.location, positionHint: PositionHint.END });
385
393
  this.popFromStack();
386
- this.scopeDepth -= 1;
387
- this.removeScopedVariables(forScopeStackDepth, node);
388
- return node;
394
+ this.sourceTags.push({
395
+ startIndex: tagStartIndex,
396
+ endIndex: this.output.length - 1,
397
+ kind: SourceTagKind.LOOP_CONDITION,
398
+ });
389
399
  }
390
400
  removeScopedVariables(depthBeforeScope, node) {
401
+ const tagStartIndex = this.output.length;
391
402
  const dropCount = this.stack.length - depthBeforeScope;
392
403
  for (let i = 0; i < dropCount; i += 1) {
393
404
  this.emit(Op.OP_DROP, { location: node.location, positionHint: PositionHint.END });
394
405
  this.popFromStack();
395
406
  }
407
+ this.tagScopeCleanup(tagStartIndex);
408
+ }
409
+ tagScopeCleanup(tagStartIndex) {
410
+ if (this.output.length <= tagStartIndex)
411
+ return;
412
+ this.sourceTags.push({
413
+ startIndex: tagStartIndex,
414
+ endIndex: this.output.length - 1,
415
+ kind: SourceTagKind.SCOPE_CLEANUP,
416
+ });
396
417
  }
397
418
  visitCast(node) {
398
419
  node.expression = this.visit(node.expression);
package/dist/index.d.ts CHANGED
@@ -3,4 +3,4 @@ export * as utils from '@cashscript/utils';
3
3
  export { compileFile, compileString, type CompileOptions } from './compiler.js';
4
4
  export * from './ast/Location.js';
5
5
  export * from './ast/error-listeners.js';
6
- export declare const version = "0.13.1";
6
+ export declare const version = "0.13.2";
package/dist/index.js CHANGED
@@ -3,5 +3,5 @@ export * as utils from '@cashscript/utils';
3
3
  export { compileFile, compileString } from './compiler.js';
4
4
  export * from './ast/Location.js';
5
5
  export * from './ast/error-listeners.js';
6
- export const version = '0.13.1';
6
+ export const version = '0.13.2';
7
7
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cashc",
3
- "version": "0.13.1",
3
+ "version": "0.13.2",
4
4
  "description": "Compile Bitcoin Cash contracts to Bitcoin Cash Script or artifacts",
5
5
  "keywords": [
6
6
  "bitcoin",
@@ -48,7 +48,7 @@
48
48
  },
49
49
  "dependencies": {
50
50
  "@bitauth/libauth": "^3.1.0-next.8",
51
- "@cashscript/utils": "^0.13.1",
51
+ "@cashscript/utils": "^0.13.2",
52
52
  "antlr4": "^4.13.2",
53
53
  "commander": "^14.0.0",
54
54
  "semver": "^7.7.2"
@@ -64,5 +64,5 @@
64
64
  "typescript": "^5.9.2",
65
65
  "vitest": "^4.0.15"
66
66
  },
67
- "gitHead": "b5248b51a2ef93d750dcf916743eac9b79f62b5b"
67
+ "gitHead": "a4f112abb0d035ecf018ebc694e2b081f25b3409"
68
68
  }