@harmoniclabs/pebble 0.1.0-dev6 → 0.1.0-dev8

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 (76) hide show
  1. package/dist/IR/IRNodes/IRConst.js +1 -1
  2. package/dist/IR/IRNodes/IRNative/IRNativeTag.d.ts +6 -3
  3. package/dist/IR/IRNodes/IRNative/IRNativeTag.js +12 -4
  4. package/dist/IR/IRNodes/IRNative/index.d.ts +5 -2
  5. package/dist/IR/IRNodes/IRNative/index.js +6 -2
  6. package/dist/IR/toUPLC/CompilerOptions.d.ts +6 -1
  7. package/dist/IR/toUPLC/CompilerOptions.js +11 -1
  8. package/dist/IR/toUPLC/compileIRToUPLC.js +34 -35
  9. package/dist/IR/toUPLC/ctx/ToUplcCtx.js +2 -10
  10. package/dist/IR/toUPLC/subRoutines/handleLetted/groupByScope.js +0 -2
  11. package/dist/IR/toUPLC/subRoutines/handleLetted/index.js +69 -3
  12. package/dist/IR/toUPLC/subRoutines/replaceNatives/nativeToIR.d.ts +3 -1
  13. package/dist/IR/toUPLC/subRoutines/replaceNatives/nativeToIR.js +42 -10
  14. package/dist/IR/toUPLC/subRoutines/rewriteNativesAppliedToConstantsAndReturnRoot.js +292 -17
  15. package/dist/IR/utils/isClosedIRTerm.js +1 -1
  16. package/dist/IR/utils/positiveIntAsBytes.js +1 -5
  17. package/dist/compiler/AstCompiler/AstCompiler.d.ts +3 -0
  18. package/dist/compiler/AstCompiler/AstCompiler.js +66 -3
  19. package/dist/compiler/AstCompiler/internal/_deriveContractBody/_deriveContractBody.js +1 -1
  20. package/dist/compiler/AstCompiler/internal/exprs/_compileExpr.js +4 -0
  21. package/dist/compiler/AstCompiler/internal/exprs/_compileFuncExpr.js +13 -4
  22. package/dist/compiler/AstCompiler/internal/exprs/_compileTypeConversionExpr.js +0 -1
  23. package/dist/compiler/AstCompiler/internal/exprs/_compileVarAccessExpr.js +3 -1
  24. package/dist/compiler/AstCompiler/internal/statements/_compileAssignmentStmt.js +7 -7
  25. package/dist/compiler/AstCompiler/internal/statements/_compileVarStmt.d.ts +2 -1
  26. package/dist/compiler/AstCompiler/internal/statements/_compileVarStmt.js +2 -1
  27. package/dist/compiler/AstCompiler/scope/AstScope.d.ts +1 -0
  28. package/dist/compiler/AstCompiler/scope/AstScope.js +5 -0
  29. package/dist/compiler/Compiler.d.ts +8 -1
  30. package/dist/compiler/Compiler.js +38 -1
  31. package/dist/compiler/TirCompiler/compileTirProgram.js +2 -1
  32. package/dist/compiler/TirCompiler/expressify/ExpressifyCtx.d.ts +4 -2
  33. package/dist/compiler/TirCompiler/expressify/ExpressifyCtx.js +42 -16
  34. package/dist/compiler/TirCompiler/expressify/determineReassignedVariablesAndReturn.js +2 -0
  35. package/dist/compiler/TirCompiler/expressify/expressify.js +26 -9
  36. package/dist/compiler/TirCompiler/expressify/expressifyForStmt.js +23 -7
  37. package/dist/compiler/TirCompiler/expressify/expressifyVarAssignmentStmt.d.ts +1 -2
  38. package/dist/compiler/TirCompiler/expressify/expressifyVarAssignmentStmt.js +15 -8
  39. package/dist/compiler/TirCompiler/expressify/expressifyVarDecl.js +6 -9
  40. package/dist/compiler/TirCompiler/expressify/expressifyVars.js +51 -16
  41. package/dist/compiler/TirCompiler/expressify/flattenSopNamedDeconstructInplace_addTopDestructToCtx_getNestedDeconstruct.js +1 -0
  42. package/dist/compiler/internalVar.d.ts +1 -1
  43. package/dist/compiler/internalVar.js +31 -24
  44. package/dist/compiler/io/CompilerIoApi.d.ts +1 -1
  45. package/dist/compiler/tir/expressions/TirCallExpr.d.ts +1 -1
  46. package/dist/compiler/tir/expressions/TirCallExpr.js +1 -1
  47. package/dist/compiler/tir/expressions/TirCaseExpr.js +2 -0
  48. package/dist/compiler/tir/expressions/TirFromDataExpr.js +2 -2
  49. package/dist/compiler/tir/expressions/TirFuncExpr.d.ts +1 -1
  50. package/dist/compiler/tir/expressions/TirFuncExpr.js +1 -1
  51. package/dist/compiler/tir/expressions/TirLettedExpr.d.ts +2 -2
  52. package/dist/compiler/tir/expressions/TirLettedExpr.js +4 -6
  53. package/dist/compiler/tir/expressions/TirNativeFunc.d.ts +3 -2
  54. package/dist/compiler/tir/expressions/TirNativeFunc.js +33 -12
  55. package/dist/compiler/tir/expressions/TirPropAccessExpr.js +1 -2
  56. package/dist/compiler/tir/expressions/TirVariableAccessExpr.d.ts +0 -1
  57. package/dist/compiler/tir/expressions/TirVariableAccessExpr.js +9 -5
  58. package/dist/compiler/tir/expressions/ToIRTermCtx.d.ts +3 -0
  59. package/dist/compiler/tir/expressions/ToIRTermCtx.js +8 -1
  60. package/dist/compiler/tir/expressions/binary/TirBinaryExpr.d.ts +1 -0
  61. package/dist/compiler/tir/expressions/binary/TirBinaryExpr.js +6 -1
  62. package/dist/compiler/tir/program/TypedProgram.d.ts +2 -2
  63. package/dist/compiler/tir/program/stdScope/stdScope.js +9 -23
  64. package/dist/compiler/tir/statements/TirIfStmt.d.ts +0 -1
  65. package/dist/compiler/tir/statements/TirIfStmt.js +0 -3
  66. package/dist/parser/Parser.js +18 -2
  67. package/dist/parser/Precedence.js +1 -0
  68. package/dist/utils/BitUtils/index.d.ts +1 -1
  69. package/dist/utils/BitUtils/index.js +1 -1
  70. package/dist/utils/IsSingleKey.d.ts +1 -1
  71. package/dist/utils/UPLCFlatUtils/index.d.ts +1 -1
  72. package/dist/utils/UPLCFlatUtils/index.js +2 -2
  73. package/dist/utils/array/keepSortedArrInplace.js +1 -0
  74. package/package.json +7 -6
  75. package/dist/compiler/TirCompiler/internal/_compileHoistedDeps.d.ts +0 -5
  76. package/dist/compiler/TirCompiler/internal/_compileHoistedDeps.js +0 -39
@@ -6,7 +6,6 @@ export declare class TirIfStmt implements ITirStmt {
6
6
  thenBranch: TirStmt;
7
7
  elseBranch: TirStmt | undefined;
8
8
  readonly range: SourceRange;
9
- private _creationStack?;
10
9
  constructor(condition: TirExpr, thenBranch: TirStmt, elseBranch: TirStmt | undefined, range: SourceRange);
11
10
  toString(): string;
12
11
  pretty(indent: number): string;
@@ -4,13 +4,11 @@ export class TirIfStmt {
4
4
  thenBranch;
5
5
  elseBranch;
6
6
  range;
7
- _creationStack;
8
7
  constructor(condition, thenBranch, elseBranch, range) {
9
8
  this.condition = condition;
10
9
  this.thenBranch = thenBranch;
11
10
  this.elseBranch = elseBranch;
12
11
  this.range = range;
13
- this._creationStack = new Error().stack;
14
12
  }
15
13
  toString() {
16
14
  return (`if( ${this.condition.toString()} ) ` +
@@ -29,7 +27,6 @@ export class TirIfStmt {
29
27
  (this.elseBranch ? ` else ${this.elseBranch.pretty(indent)}` : ""));
30
28
  }
31
29
  definitelyTerminates() {
32
- console.log(this._creationStack);
33
30
  return (this.thenBranch.definitelyTerminates()
34
31
  && (this.elseBranch?.definitelyTerminates() ?? false));
35
32
  }
@@ -1139,7 +1139,9 @@ export class Parser extends DiagnosticEmitter {
1139
1139
  // precedence climbing
1140
1140
  // see: http://www.engr.mun.ca/~theo/Misc/exp_parsing.htm#climbing
1141
1141
  let nextPrecedence;
1142
- while ((nextPrecedence = determinePrecedence(tn.peek())) >= precedence) {
1142
+ let prevState;
1143
+ outer_while: while ((nextPrecedence = determinePrecedence(tn.peek())) >= precedence) {
1144
+ prevState = tn.mark();
1143
1145
  const token = tn.next();
1144
1146
  // DO NOT DIRECTLY RETURN FROM HERE
1145
1147
  // we need to loop to support right associative operators
@@ -1320,6 +1322,11 @@ export class Parser extends DiagnosticEmitter {
1320
1322
  expr = makeBinaryExpr(token, expr, next, tn.range(startPos, tn.pos));
1321
1323
  break;
1322
1324
  }
1325
+ // comma operator handled in caller (only valid in for statements)
1326
+ case Token.Comma: {
1327
+ tn.reset(prevState);
1328
+ break outer_while;
1329
+ }
1323
1330
  default: {
1324
1331
  return this.error(DiagnosticCode.Expression_expected, tn.range());
1325
1332
  }
@@ -2016,6 +2023,12 @@ export class Parser extends DiagnosticEmitter {
2016
2023
  case Token.Question_Question_Equals: {
2017
2024
  return this.error(DiagnosticCode.Not_implemented_0, tn.range(), "??=");
2018
2025
  }
2026
+ case Token.Plus_Plus: {
2027
+ return makeAssignmentStmt(varIdentifier, Token.Plus_Equals, new LitIntExpr(BigInt(1), tn.range()), tn.range(startPos, tn.pos));
2028
+ }
2029
+ case Token.Minus_Minus: {
2030
+ return makeAssignmentStmt(varIdentifier, Token.Minus_Equals, new LitIntExpr(BigInt(1), tn.range()), tn.range(startPos, tn.pos));
2031
+ }
2019
2032
  default: {
2020
2033
  return this.error(DiagnosticCode._0_expected, tn.range(), "=");
2021
2034
  }
@@ -2180,8 +2193,11 @@ export class Parser extends DiagnosticEmitter {
2180
2193
  return this.error(DiagnosticCode.Invalid_for_statement_update, update.range);
2181
2194
  updates.push(update);
2182
2195
  } while (tn.skip(Token.Comma)); // comma expression (allowed only in for update part)
2183
- if (!tn.skip(Token.CloseParen))
2196
+ if (!tn.skip(Token.CloseParen)) {
2197
+ const next = tn.peek();
2198
+ console.error('next token after for updates:', Token[next]);
2184
2199
  return this.error(DiagnosticCode._0_expected, tn.range(), ")");
2200
+ }
2185
2201
  }
2186
2202
  const body = this.parseStatement();
2187
2203
  if (!body)
@@ -89,6 +89,7 @@ export function determinePrecedence(kind) {
89
89
  case Token.Plus_Plus:
90
90
  case Token.Minus_Minus: return Precedence.UnaryPostfix;
91
91
  case Token.Dot:
92
+ case Token.Exclamation_Dot:
92
93
  case Token.Question_Dot:
93
94
  case Token.OpenBracket:
94
95
  case Token.Exclamation: return Precedence.MemberAccess;
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @static
3
3
  */
4
- export default class BitUtils {
4
+ export declare class BitUtils {
5
5
  private constructor();
6
6
  /**
7
7
  * @deprecated not sure it has ever made sense to have it
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @static
3
3
  */
4
- export default class BitUtils {
4
+ export class BitUtils {
5
5
  constructor() { }
6
6
  /**
7
7
  * @deprecated not sure it has ever made sense to have it
@@ -3,5 +3,5 @@ type SingleKeyObj<K extends string | number | symbol, V = any> = {
3
3
  [Q in keyof O]: O[Q];
4
4
  } : never;
5
5
  }[K];
6
- export default SingleKeyObj;
7
6
  export type IsSingleKey<Obj extends object> = Obj extends SingleKeyObj<keyof Obj> ? true : false;
7
+ export {};
@@ -8,7 +8,7 @@ export interface BitStreamPadToByteOptions {
8
8
  /**
9
9
  * @static
10
10
  */
11
- export default class UPLCFlatUtils {
11
+ export declare class UPLCFlatUtils {
12
12
  /**
13
13
  * @deprecated this is a @static class, it is not supposed to have instances
14
14
  */
@@ -1,6 +1,6 @@
1
1
  import { BitStream } from "@harmoniclabs/bitstream";
2
- import BitUtils from "../BitUtils/index.js";
3
2
  import { assert } from "../assert.js";
3
+ import { BitUtils } from "../BitUtils/index.js";
4
4
  export function isInByteOffset(offset) {
5
5
  return (offset === 0 ||
6
6
  offset === 1 ||
@@ -14,7 +14,7 @@ export function isInByteOffset(offset) {
14
14
  /**
15
15
  * @static
16
16
  */
17
- export default class UPLCFlatUtils {
17
+ export class UPLCFlatUtils {
18
18
  /**
19
19
  * @deprecated this is a @static class, it is not supposed to have instances
20
20
  */
@@ -21,6 +21,7 @@ export function keepSortedStrArrInplace(target, source) {
21
21
  target.length = i + 1; // truncate target to current index
22
22
  return target; // no more elements to keep
23
23
  }
24
+ continue; // element is in source, check next without removing this
24
25
  }
25
26
  // not equal, remove the element
26
27
  target.splice(i, 1);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@harmoniclabs/pebble",
3
- "version": "0.1.0-dev6",
3
+ "version": "0.1.0-dev8",
4
4
  "description": "A simple, yet rock solid, functional language with an imperative bias, targeting UPLC",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -20,6 +20,7 @@
20
20
  "build-and-replace": "npm run build && cp -r ./dist ../pebble-cli/node_modules/@harmoniclabs/pebble",
21
21
  "genDiagnosticMessages": "node ./scripts/genDiagnosticMessages.js",
22
22
  "test": "jest",
23
+ "test-dbg": "node --nolazy --inspect-brk ./node_modules/jest/bin/jest.js --runInBand --colors --verbose",
23
24
  "test:debug": "node --nolazy --inspect-brk ./node_modules/jest/bin/jest.js --runInBand --colors --verbose",
24
25
  "clear-jest": "jest --clearCache",
25
26
  "test-watch": "jest --watchman",
@@ -51,14 +52,14 @@
51
52
  "dependencies": {
52
53
  "@harmoniclabs/bigint-utils": "^1.0.0",
53
54
  "@harmoniclabs/bytestring": "^1.0.0",
54
- "@harmoniclabs/cbor": "^1.6.0",
55
- "@harmoniclabs/crypto": "^0.2.5",
55
+ "@harmoniclabs/cbor": "^1.6.6",
56
+ "@harmoniclabs/crypto": "^0.3.0",
56
57
  "@harmoniclabs/obj-utils": "^1.0.0",
57
58
  "@harmoniclabs/pair": "^1.0.0",
58
- "@harmoniclabs/plutus-data": "^1.2.4",
59
- "@harmoniclabs/plutus-machine": "^2.1.0",
59
+ "@harmoniclabs/plutus-data": "^1.2.6",
60
+ "@harmoniclabs/plutus-machine": "^2.1.1",
60
61
  "@harmoniclabs/uint8array-utils": "^1.0.4",
61
- "@harmoniclabs/uplc": "^1.4.0"
62
+ "@harmoniclabs/uplc": "^1.4.1"
62
63
  },
63
64
  "devDependencies": {
64
65
  "@babel/preset-env": "^7.18.6",
@@ -1,5 +0,0 @@
1
- import { TirHoistedExpr } from "../../tir/expressions/TirHoistedExpr.js";
2
- import { TirNativeFunc } from "../../tir/expressions/TirNativeFunc.js";
3
- import { TypedProgram } from "../../tir/program/TypedProgram.js";
4
- import { DepsNode } from "./deps/DepsNode.js";
5
- export declare function _compileHoistedDeps(program: TypedProgram, hoistedMap: Map<string, TirHoistedExpr | TirNativeFunc>, deps: string[], depsStack: DepsNode): void;
@@ -1,39 +0,0 @@
1
- import { TirHoistedExpr } from "../../tir/expressions/TirHoistedExpr.js";
2
- import { ExpressifyCtx } from "../expressify/ExpressifyCtx.js";
3
- import { expressifyVars } from "../expressify/expressifyVars.js";
4
- export function _compileHoistedDeps(program, hoistedMap, deps, depsStack) {
5
- let depName;
6
- if (deps.some(dep => depsStack.includes(dep)))
7
- throw new Error("Circular dependency in hoisted expressions NOT YET IMPLEMENTED");
8
- while (depName = deps.pop()) {
9
- const funcDecl = program.functions.get(depName);
10
- if (funcDecl) {
11
- _compileHoistedDeps(program, hoistedMap, funcDecl.deps(), depsStack.getNext(depName));
12
- /*
13
- const funcExpr = funcDecl instanceof TirInlineClosedIR ? funcDecl : expressify(
14
- funcDecl,
15
- undefined, // loopReplacements
16
- program,
17
- new ExpressifyCtx(
18
- undefined,
19
- funcDecl.returnType,
20
- program,
21
- hoistedMap
22
- )
23
- );
24
- //*/
25
- const hoistedExpr = new TirHoistedExpr(depName, funcDecl);
26
- hoistedMap.set(depName, hoistedExpr);
27
- continue;
28
- }
29
- const constDecl = program.constants.get(depName);
30
- if (constDecl) {
31
- _compileHoistedDeps(program, hoistedMap, constDecl.deps(), depsStack.getNext(depName));
32
- const expr = expressifyVars(new ExpressifyCtx(undefined, constDecl.type, program, hoistedMap), constDecl);
33
- const hoistedExpr = new TirHoistedExpr(depName, expr);
34
- hoistedMap.set(depName, hoistedExpr);
35
- continue;
36
- }
37
- throw new Error(`Hoisted dependency "${depName}" not found in program`);
38
- }
39
- }