@harmoniclabs/pebble 0.1.5 → 0.1.6

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.
@@ -43,6 +43,8 @@ import { TirArrayLikeDeconstr } from "../../tir/statements/TirVarDecl/TirArrayLi
43
43
  import { TirNamedDeconstructVarDecl } from "../../tir/statements/TirVarDecl/TirNamedDeconstructVarDecl.js";
44
44
  import { TirSimpleVarDecl } from "../../tir/statements/TirVarDecl/TirSimpleVarDecl.js";
45
45
  import { TirAliasType } from "../../tir/types/TirAliasType.js";
46
+ import { TirBytesT } from "../../tir/types/TirNativeType/native/bytes.js";
47
+ import { TirStringT } from "../../tir/types/TirNativeType/native/string.js";
46
48
  import { TirFuncT, TirListT, TirPairDataT } from "../../tir/types/TirNativeType/index.js";
47
49
  import { TirLinearMapT } from "../../tir/types/TirNativeType/native/linearMap.js";
48
50
  import { TirLinearMapEntryT } from "../../tir/types/TirNativeType/native/linearMapEntry.js";
@@ -471,6 +473,18 @@ function expressifyMethodCall(ctx, methodCall) {
471
473
  if (result)
472
474
  return result;
473
475
  }
476
+ if (objectType instanceof TirBytesT || objectType instanceof TirStringT) {
477
+ const exprRange = SourceRange.join(methodIdentifierProp.range, methodCall.range.atEnd());
478
+ if (methodName === "length") {
479
+ return new TirCallExpr(TirNativeFunc.lengthOfByteString, [objectExpr], int_t, exprRange);
480
+ }
481
+ if (methodName === "subByteString" || methodName === "slice") {
482
+ return new TirCallExpr(TirNativeFunc.sliceByteString, [methodCall.args[0], methodCall.args[1], objectExpr], bytes_t, exprRange);
483
+ }
484
+ if (methodName === "prepend") {
485
+ return new TirCallExpr(TirNativeFunc.consByteString, [methodCall.args[0], objectExpr], bytes_t, exprRange);
486
+ }
487
+ }
474
488
  throw new Error(`not implemented::expressifyMethodCall for type '${objectType.toString()}' (method name: '${methodName}')`);
475
489
  // const tsEnsureExhautstiveCheck: never = objectType;
476
490
  throw new Error(`Cannot call method '${methodName}' on non-struct type '${objectType.toString()}'`);
@@ -67,10 +67,8 @@ export function canCastTo(a, b) {
67
67
  return true;
68
68
  if (a instanceof TirStringT)
69
69
  return true; // string -> bytes // decode utf8
70
- // how do we handle this?
71
- // in theory we can encode but only fixed size
72
- // we have no idea of the size of ints
73
- // if( a instanceof TirIntT ) return true;
70
+ if (a instanceof TirIntT)
71
+ return true; // int -> bytes // big endian encoding
74
72
  return false;
75
73
  }
76
74
  if (b instanceof TirStringT) {
@@ -1,11 +1,14 @@
1
1
  import { TirAliasType } from "../TirAliasType.js";
2
2
  import { TirLinearMapT } from "../TirNativeType/native/linearMap.js";
3
+ import { TirLinearMapEntryT } from "../TirNativeType/native/linearMapEntry.js";
3
4
  import { TirListT } from "../TirNativeType/native/list.js";
4
5
  export function getListTypeArg(list_t) {
5
6
  while (list_t instanceof TirAliasType)
6
7
  list_t = list_t.aliased;
7
8
  if (list_t instanceof TirListT)
8
9
  return list_t.typeArg;
10
+ if (list_t instanceof TirLinearMapT)
11
+ return new TirLinearMapEntryT(list_t.keyTypeArg, list_t.valTypeArg);
9
12
  return undefined;
10
13
  }
11
14
  export function getLinearMapTypeArgs(map_t) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@harmoniclabs/pebble",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
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",