@abaplint/runtime 2.8.13 → 2.8.15

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.
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ABAPRegExp = void 0;
4
+ // https://github.com/TooTallNate/pcre-to-regexp/blob/master/src/index.ts
4
5
  class ABAPRegExp {
5
6
  // converts from ABAP specific regex to javascript regex
6
7
  static convert(input) {
@@ -18,6 +18,12 @@ function clone(obj) {
18
18
  // @ts-ignore
19
19
  return n;
20
20
  }
21
+ else if (obj instanceof types_1.HexUInt8) {
22
+ const n = new types_1.HexUInt8({ length: obj.getLength(), qualifiedName: obj.getQualifiedName() });
23
+ n.set(obj.get());
24
+ // @ts-ignore
25
+ return n;
26
+ }
21
27
  // @ts-ignore
22
28
  const copy = new obj.constructor();
23
29
  for (const attr in obj) {
@@ -54,6 +54,7 @@ function eq(left, right) {
54
54
  else if (left instanceof types_1.String
55
55
  || left instanceof types_1.XString
56
56
  || left instanceof types_1.Numc
57
+ || left instanceof types_1.HexUInt8
57
58
  || left instanceof types_1.Hex) {
58
59
  return right.getTrimEnd() === left.get();
59
60
  }
@@ -105,13 +106,8 @@ function eq(left, right) {
105
106
  return false;
106
107
  }
107
108
  }
108
- else if (right instanceof types_1.Hex) {
109
- if (left instanceof types_1.Hex || left instanceof types_1.XString) {
110
- return right.get() === left.get();
111
- }
112
- }
113
- else if (right instanceof types_1.XString) {
114
- if (left instanceof types_1.Hex || left instanceof types_1.XString) {
109
+ else if (right instanceof types_1.Hex || right instanceof types_1.HexUInt8 || right instanceof types_1.XString) {
110
+ if (left instanceof types_1.Hex || left instanceof types_1.XString || left instanceof types_1.HexUInt8) {
115
111
  return right.get() === left.get();
116
112
  }
117
113
  }
@@ -203,10 +199,12 @@ function eq(left, right) {
203
199
  else {
204
200
  r = right;
205
201
  }
206
- if (right instanceof types_1.Hex && typeof l === "number") {
202
+ if ((right instanceof types_1.Hex || right instanceof types_1.HexUInt8) && typeof l === "number") {
203
+ // todo, handle this case earlier
207
204
  r = parseInt(right.get(), 16);
208
205
  }
209
- else if (left instanceof types_1.Hex && typeof r === "number") {
206
+ else if ((left instanceof types_1.Hex || left instanceof types_1.HexUInt8) && typeof r === "number") {
207
+ // todo, handle this case earlier
210
208
  l = parseInt(left.get(), 16);
211
209
  }
212
210
  if (right instanceof types_1.Float && left instanceof types_1.Float) {
@@ -20,7 +20,7 @@ function gt(left, right) {
20
20
  if (left instanceof types_1.Table || right instanceof types_1.Table || left instanceof types_1.HashedTable || right instanceof types_1.HashedTable) {
21
21
  throw new Error("runtime_todo, gt TABLE");
22
22
  }
23
- if (left instanceof types_1.Hex || right instanceof types_1.Hex) {
23
+ if (left instanceof types_1.Hex || right instanceof types_1.Hex || left instanceof types_1.HexUInt8 || right instanceof types_1.HexUInt8) {
24
24
  return gt_with_hex(left, right);
25
25
  }
26
26
  if (left instanceof types_1.Integer8 || right instanceof types_1.Integer8) {
@@ -79,6 +79,7 @@ function gt_with_hex(left, right) {
79
79
  return left_hex > right_hex;
80
80
  }
81
81
  function get_hex_from_parameter(comparison_part) {
82
+ // todo: optimize?
82
83
  let hex_from_parameter = "";
83
84
  switch (typeof comparison_part) {
84
85
  case "number":
@@ -90,7 +91,10 @@ function get_hex_from_parameter(comparison_part) {
90
91
  .join("");
91
92
  break;
92
93
  case "object":
93
- if (comparison_part instanceof types_1.Hex) {
94
+ if (comparison_part instanceof types_1.Hex
95
+ || comparison_part instanceof types_1.XString
96
+ || comparison_part instanceof types_1.HexUInt8
97
+ || comparison_part instanceof types_1.Character) {
94
98
  hex_from_parameter = comparison_part.get();
95
99
  }
96
100
  else if (comparison_part instanceof integer_1.Integer) {
@@ -99,12 +103,6 @@ function get_hex_from_parameter(comparison_part) {
99
103
  hex_from_parameter = "0" + hex_from_parameter;
100
104
  }
101
105
  }
102
- else if (comparison_part instanceof types_1.Character) {
103
- hex_from_parameter = comparison_part.get();
104
- }
105
- else if (comparison_part instanceof types_1.XString) {
106
- hex_from_parameter = comparison_part.get();
107
- }
108
106
  else {
109
107
  throw new Error("runtime_todo, gt hex1");
110
108
  }
@@ -21,7 +21,7 @@ function initial(val) {
21
21
  else if (val instanceof types_1.Numc) {
22
22
  return val.get().match(REGEX_ZEROS) !== null;
23
23
  }
24
- else if (val instanceof types_1.Hex) {
24
+ else if (val instanceof types_1.Hex || val instanceof types_1.HexUInt8) {
25
25
  return val.get().match(REGEX_ZEROS) !== null;
26
26
  }
27
27
  else if (val instanceof types_1.Time) {
@@ -11,7 +11,7 @@ class OffsetLength {
11
11
  throw new Error("GETWA_NOT_ASSIGNED");
12
12
  }
13
13
  }
14
- this.isHex = this.obj instanceof types_1.Hex || this.obj instanceof types_1.XString;
14
+ this.isHex = this.obj instanceof types_1.Hex || this.obj instanceof types_1.XString || this.obj instanceof types_1.HexUInt8;
15
15
  if (options.offset) {
16
16
  if (typeof options.offset === "number") {
17
17
  this.offset = options.offset;
@@ -77,17 +77,27 @@ class OffsetLength {
77
77
  val = val.padEnd(this.length, " ");
78
78
  }
79
79
  }
80
- let old = this.obj instanceof types_1.Structure ? this.obj.getCharacter() : this.obj.get();
81
- if (this.length && this.offset) {
82
- old = old.substr(0, this.offset) + val + old.substr(this.offset + this.length);
83
- }
84
- else if (this.length) {
85
- old = val + old.substr(this.length);
80
+ if (this.isHex === true && this.obj instanceof types_1.HexUInt8) {
81
+ let base = this.offset ? this.offset / 2 : 0;
82
+ for (let current = 0; current < val.length; current += 2) {
83
+ const v = Number.parseInt(val.substr(current, 2), 16);
84
+ this.obj.setOffset(base, v);
85
+ base++;
86
+ }
86
87
  }
87
- else if (this.offset) {
88
- old = old.substr(0, this.offset) + val;
88
+ else {
89
+ let old = this.obj instanceof types_1.Structure ? this.obj.getCharacter() : this.obj.get();
90
+ if (this.length && this.offset) {
91
+ old = old.substr(0, this.offset) + val + old.substr(this.offset + this.length);
92
+ }
93
+ else if (this.length) {
94
+ old = val + old.substr(this.length);
95
+ }
96
+ else if (this.offset) {
97
+ old = old.substr(0, this.offset) + val;
98
+ }
99
+ this.obj.set(old);
89
100
  }
90
- this.obj.set(old);
91
101
  }
92
102
  }
93
103
  exports.OffsetLength = OffsetLength;
@@ -22,13 +22,16 @@ function parse(val) {
22
22
  else if (val instanceof types_1.Float) {
23
23
  return val.getRaw();
24
24
  }
25
- else if (val instanceof xstring_1.XString || val instanceof types_1.Hex) {
25
+ else if (val instanceof xstring_1.XString) {
26
26
  if (val.get() === "") {
27
27
  return 0;
28
28
  }
29
+ return parseInt(val.get(), 16);
30
+ }
31
+ else if (val instanceof types_1.Hex || val instanceof types_1.HexUInt8) {
29
32
  let num = parseInt(val.get(), 16);
30
33
  // handle two complement,
31
- if (val instanceof types_1.Hex && val.getLength() >= 4) {
34
+ if (val.getLength() >= 4) {
32
35
  const maxVal = Math.pow(2, val.get().length / 2 * 8);
33
36
  if (num > maxVal / 2 - 1) {
34
37
  num = num - maxVal;
@@ -1,4 +1,4 @@
1
1
  import { Float, Integer, Integer8 } from "../types";
2
2
  import { ICharacter } from "../types/_character";
3
3
  import { INumeric } from "../types/_numeric";
4
- export declare function divide(left: INumeric | ICharacter | Integer8 | string | number, right: INumeric | ICharacter | Integer8 | string | number): Integer | Float | Integer8;
4
+ export declare function divide(left: INumeric | ICharacter | Integer8 | string | number, right: INumeric | ICharacter | Integer8 | string | number): Integer | Integer8 | Float;
@@ -1,4 +1,4 @@
1
1
  import { Float, Integer, Integer8 } from "../types";
2
2
  import { ICharacter } from "../types/_character";
3
3
  import { INumeric } from "../types/_numeric";
4
- export declare function multiply(left: INumeric | ICharacter | string | Integer8 | number, right: INumeric | ICharacter | string | Integer8 | number): Integer | Float | Integer8;
4
+ export declare function multiply(left: INumeric | ICharacter | string | Integer8 | number, right: INumeric | ICharacter | string | Integer8 | number): Integer | Integer8 | Float;
@@ -1,4 +1,4 @@
1
1
  import { Float, Integer8 } from "../types";
2
2
  import { ICharacter } from "../types/_character";
3
3
  import { INumeric } from "../types/_numeric";
4
- export declare function power(left: INumeric | ICharacter | Integer8 | string | number, right: INumeric | ICharacter | Integer8 | string | number): Float | Integer8;
4
+ export declare function power(left: INumeric | ICharacter | Integer8 | string | number, right: INumeric | ICharacter | Integer8 | string | number): Integer8 | Float;
@@ -33,7 +33,7 @@ function describe(input) {
33
33
  else if (input.field instanceof types_1.Numc) {
34
34
  input.type.set("N");
35
35
  }
36
- else if (input.field instanceof types_1.Hex) {
36
+ else if (input.field instanceof types_1.Hex || input.field instanceof types_1.HexUInt8) {
37
37
  input.type.set("X");
38
38
  }
39
39
  else if (input.field instanceof types_1.Packed) {
@@ -68,6 +68,7 @@ function describe(input) {
68
68
  if (input.field instanceof types_1.Character
69
69
  || input.field instanceof types_1.Packed
70
70
  || input.field instanceof types_1.Numc
71
+ || input.field instanceof types_1.HexUInt8
71
72
  || input.field instanceof types_1.Hex) {
72
73
  input.length.set(input.field.getLength());
73
74
  }
@@ -1,4 +1,4 @@
1
- import { Hex, XString } from "../types";
1
+ import { Hex, HexUInt8, XString } from "../types";
2
2
  import { ICharacter } from "../types/_character";
3
3
  import { INumeric } from "../types/_numeric";
4
- export declare function getBit(number: INumeric, hex: XString | Hex, output: ICharacter): void;
4
+ export declare function getBit(number: INumeric, hex: XString | Hex | HexUInt8, output: ICharacter): void;
@@ -1,16 +1,27 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getBit = void 0;
4
+ /* eslint-disable no-bitwise */
5
+ const types_1 = require("../types");
4
6
  function getBit(number, hex, output) {
5
- const charIndex = Math.floor((number.get() - 1) / 8);
7
+ const byteIndex = Math.floor((number.get() - 1) / 8);
6
8
  const bitIndex = (number.get() - 1) % 8;
7
- if (bitIndex < 0) {
8
- throw new Error("BIT_OFFSET_NOT_POSITIVE");
9
+ if (hex instanceof types_1.HexUInt8) {
10
+ let int = hex.getOffsetRaw(byteIndex);
11
+ int >>= (8 - bitIndex - 1);
12
+ int &= 1;
13
+ // @ts-ignore
14
+ output.set(int);
15
+ }
16
+ else {
17
+ if (bitIndex < 0) {
18
+ throw new Error("BIT_OFFSET_NOT_POSITIVE");
19
+ }
20
+ const h = hex.get().substr(byteIndex * 2, 2);
21
+ const parsed = parseInt(h, 16).toString(2);
22
+ const bits = parsed.padStart(8, "0");
23
+ output.set(bits.substr(bitIndex, 1));
9
24
  }
10
- const h = hex.get().substr(charIndex * 2, 2);
11
- const parsed = parseInt(h, 16).toString(2);
12
- const bits = parsed.padStart(8, "0");
13
- output.set(bits.substr(bitIndex, 1));
14
25
  }
15
26
  exports.getBit = getBit;
16
27
  //# sourceMappingURL=get_bit.js.map
@@ -1,4 +1,4 @@
1
- import { Hex, XString } from "../types";
1
+ import { Hex, HexUInt8, XString } from "../types";
2
2
  import { ICharacter } from "../types/_character";
3
3
  import { INumeric } from "../types/_numeric";
4
- export declare function setBit(number: INumeric, hex: XString | Hex, val?: INumeric | ICharacter): void;
4
+ export declare function setBit(number: INumeric, hex: XString | Hex | HexUInt8, val?: INumeric | ICharacter): void;
@@ -1,41 +1,58 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.setBit = void 0;
4
+ /* eslint-disable no-bitwise */
5
+ const types_1 = require("../types");
4
6
  function setBit(number, hex, val) {
5
7
  if (number.get() <= 0) {
6
8
  throw new Error("BIT_OFFSET_NOT_POSITIVE");
7
9
  }
8
- const hexFull = hex.get();
9
- const fullByteLength = Math.ceil(hexFull.length / 2);
10
- const byteNum = Math.ceil(number.get() / 8);
11
- if (byteNum > fullByteLength) {
12
- return;
13
- }
14
- let pre = "";
15
- let byte = "";
16
- let post = "";
17
- if (hexFull.length > 2) {
18
- if (byteNum > 1) {
19
- pre = hexFull.substr(0, (byteNum - 1) * 2);
10
+ else if (hex instanceof types_1.HexUInt8) {
11
+ const byteIndex = Math.floor((number.get() - 1) / 8);
12
+ const bitIndex = (number.get() - 1) % 8;
13
+ let bits = hex.getOffsetRaw(byteIndex);
14
+ const bitMask = 1 << (8 - bitIndex - 1);
15
+ if (val?.get() === 0 || val?.get() === "0") {
16
+ bits &= ~bitMask;
20
17
  }
21
- byte = hexFull.substr((byteNum - 1) * 2, 2);
22
- if (fullByteLength > byteNum) {
23
- post = hexFull.substr(byteNum * 2, (fullByteLength - byteNum) * 2);
18
+ else {
19
+ bits |= bitMask;
24
20
  }
21
+ hex.setOffset(byteIndex, bits);
25
22
  }
26
23
  else {
27
- byte = hexFull;
28
- }
29
- let bits = parseInt(byte, 16);
30
- const bitMask = 1 << 8 - (number.get() - (byteNum - 1) * 8);
31
- if (val?.get() === 0 || val?.get() === "0") {
32
- bits = bits &= ~bitMask;
33
- }
34
- else {
35
- bits = bits |= bitMask;
24
+ const hexFull = hex.get();
25
+ const fullByteLength = Math.ceil(hexFull.length / 2);
26
+ const byteNum = Math.ceil(number.get() / 8);
27
+ if (byteNum > fullByteLength) {
28
+ return;
29
+ }
30
+ let pre = "";
31
+ let byte = "";
32
+ let post = "";
33
+ if (hexFull.length > 2) {
34
+ if (byteNum > 1) {
35
+ pre = hexFull.substr(0, (byteNum - 1) * 2);
36
+ }
37
+ byte = hexFull.substr((byteNum - 1) * 2, 2);
38
+ if (fullByteLength > byteNum) {
39
+ post = hexFull.substr(byteNum * 2, (fullByteLength - byteNum) * 2);
40
+ }
41
+ }
42
+ else {
43
+ byte = hexFull;
44
+ }
45
+ let bits = parseInt(byte, 16);
46
+ const bitMask = 1 << 8 - (number.get() - (byteNum - 1) * 8);
47
+ if (val?.get() === 0 || val?.get() === "0") {
48
+ bits &= ~bitMask;
49
+ }
50
+ else {
51
+ bits |= bitMask;
52
+ }
53
+ const reconstructed = pre + bits.toString(16).toUpperCase().padStart(2, "0") + post;
54
+ hex.set(reconstructed);
36
55
  }
37
- const reconstructed = pre + bits.toString(16).toUpperCase().padStart(2, "0") + post;
38
- hex.set(reconstructed);
39
56
  }
40
57
  exports.setBit = setBit;
41
58
  //# sourceMappingURL=set_bit.js.map
@@ -28,9 +28,12 @@ class Character {
28
28
  if (this.constant === true) {
29
29
  throw new Error("Changing constant");
30
30
  }
31
- if (typeof value === "string" || typeof value === "number") {
31
+ if (typeof value === "string") {
32
32
  this.value = value;
33
33
  }
34
+ else if (typeof value === "number") {
35
+ this.value = value + "";
36
+ }
34
37
  else if (value instanceof field_symbol_1.FieldSymbol) {
35
38
  if (value.getPointer() === undefined) {
36
39
  throw new Error("GETWA_NOT_ASSIGNED");
@@ -21,7 +21,7 @@ export declare class DataReference {
21
21
  get(): any;
22
22
  array(): any;
23
23
  getArrayLength(): any;
24
- set(value: any): void | Float | Integer8 | ABAPObject | this | Table | Structure;
24
+ set(value: any): void | Integer8 | Float | ABAPObject | this | Table | Structure;
25
25
  getOffset(input: {
26
26
  offset?: number | INumeric | Hex;
27
27
  length?: number | INumeric | Hex;
@@ -17,7 +17,7 @@ export declare class FieldSymbol {
17
17
  unassign(): void;
18
18
  isAssigned(): boolean;
19
19
  getPointer(): any;
20
- dereference(): INumeric | ICharacter | Float | import("packages/runtime/src/types").Integer8 | ABAPObject | Table | Structure | undefined;
20
+ dereference(): INumeric | ICharacter | import("packages/runtime/src/types").Integer8 | Float | ABAPObject | Table | Structure | undefined;
21
21
  clear(): void | Structure | undefined;
22
22
  get(): any;
23
23
  appendInitial(): import("./table").TableRowType | undefined;
@@ -6,6 +6,7 @@ const string_1 = require("./string");
6
6
  const hex_1 = require("./hex");
7
7
  const float_1 = require("./float");
8
8
  const data_reference_1 = require("./data_reference");
9
+ const hex_uint8_1 = require("./hex_uint8");
9
10
  class FieldSymbol {
10
11
  constructor(type) {
11
12
  this.pointer = undefined;
@@ -49,7 +50,7 @@ class FieldSymbol {
49
50
  }
50
51
  get() {
51
52
  if (this.casting) {
52
- if (this.type instanceof hex_1.Hex) {
53
+ if (this.type instanceof hex_1.Hex || this.type instanceof hex_uint8_1.HexUInt8) {
53
54
  const pt = this.pointer;
54
55
  if (pt instanceof float_1.Float) {
55
56
  const buf = Buffer.allocUnsafe(8);
@@ -0,0 +1,27 @@
1
+ import { Float } from "./float";
2
+ import { Integer } from "./integer";
3
+ import { XString } from "./xstring";
4
+ import { ICharacter } from "./_character";
5
+ import { INumeric } from "./_numeric";
6
+ import { Integer8 } from "./integer8";
7
+ import { Hex } from "./hex";
8
+ export declare class HexUInt8 implements ICharacter {
9
+ private value;
10
+ private readonly length;
11
+ private readonly qualifiedName;
12
+ constructor(input?: {
13
+ length?: number;
14
+ qualifiedName?: string;
15
+ });
16
+ getQualifiedName(): string | undefined;
17
+ setOffset(offset: number, value: number): void;
18
+ getOffsetRaw(offset: number): number;
19
+ set(value: ICharacter | INumeric | string | number | Integer | Integer8 | Float | Hex | XString): HexUInt8;
20
+ getLength(): number;
21
+ clear(): void;
22
+ get(): string;
23
+ getOffset(input: {
24
+ offset?: number | INumeric | Hex | Integer8;
25
+ length?: number | INumeric | Hex | Integer8;
26
+ }): XString;
27
+ }
@@ -0,0 +1,152 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HexUInt8 = void 0;
4
+ const _parse_1 = require("../operators/_parse");
5
+ const float_1 = require("./float");
6
+ const xstring_1 = require("./xstring");
7
+ const throw_error_1 = require("../throw_error");
8
+ const integer8_1 = require("./integer8");
9
+ const REGEXP = /^(?![A-F0-9])/;
10
+ class HexUInt8 {
11
+ constructor(input) {
12
+ this.length = input?.length ? input?.length : 1;
13
+ this.qualifiedName = input?.qualifiedName;
14
+ this.value = new Uint8Array(this.length);
15
+ }
16
+ getQualifiedName() {
17
+ return this.qualifiedName;
18
+ }
19
+ setOffset(offset, value) {
20
+ // caller must validate offset
21
+ this.value[offset] = value;
22
+ }
23
+ getOffsetRaw(offset) {
24
+ // caller must validate offset
25
+ return this.value[offset];
26
+ }
27
+ set(value) {
28
+ let hexString = "";
29
+ if (typeof value === "string") {
30
+ hexString = value;
31
+ if (hexString.length < this.length * 2) {
32
+ hexString = hexString.padEnd(this.length * 2, "0");
33
+ }
34
+ }
35
+ else if (typeof value === "number") {
36
+ const maxVal = Math.pow(2, this.length * 8);
37
+ if (value < 0) {
38
+ hexString = Math.round(value + 0x100000000).toString(16).toUpperCase();
39
+ }
40
+ else if (value >= maxVal) {
41
+ const sub = value % maxVal;
42
+ hexString = Math.round(sub).toString(16).toUpperCase();
43
+ }
44
+ else {
45
+ hexString = Math.round(value).toString(16).toUpperCase();
46
+ }
47
+ if (hexString.length > this.length * 2) {
48
+ hexString = hexString.substring(hexString.length - this.length * 2);
49
+ }
50
+ else if (hexString.length < this.length * 2) {
51
+ hexString = hexString.padStart(this.length * 2, "0");
52
+ }
53
+ }
54
+ else if (value instanceof integer8_1.Integer8) {
55
+ if (value.get() < 0) {
56
+ hexString = (value.get() + 0x10000000000000000n).toString(16).toUpperCase();
57
+ }
58
+ else {
59
+ hexString = value.get().toString(16).toUpperCase();
60
+ }
61
+ if (hexString.length > this.length * 2) {
62
+ hexString = hexString.substring(hexString.length - this.length * 2);
63
+ }
64
+ else if (hexString.length < this.length * 2) {
65
+ hexString = hexString.padStart(this.length * 2, "0");
66
+ }
67
+ }
68
+ else {
69
+ const v = value.get();
70
+ if (value instanceof float_1.Float) {
71
+ return this.set(value.getRaw());
72
+ }
73
+ else if (typeof v === "number") {
74
+ return this.set(v);
75
+ }
76
+ else {
77
+ hexString = v;
78
+ if (hexString.match(REGEXP)) {
79
+ hexString = "";
80
+ }
81
+ if (hexString.length < this.length * 2) {
82
+ hexString = hexString.padEnd(this.length * 2, "0");
83
+ }
84
+ }
85
+ }
86
+ if (hexString.length > this.length * 2) {
87
+ hexString = hexString.substring(0, this.length * 2);
88
+ }
89
+ this.value = Uint8Array.from(Buffer.from(hexString, "hex"));
90
+ return this;
91
+ }
92
+ getLength() {
93
+ return this.length;
94
+ }
95
+ clear() {
96
+ // optimize? https://gist.github.com/chrisj/872283d15e1bb460a4766a52f50ebcf6
97
+ for (let i = 0; i < this.value.length; i++) {
98
+ this.value[i] = 0;
99
+ }
100
+ }
101
+ get() {
102
+ return Buffer.from(this.value).toString("hex").toUpperCase();
103
+ }
104
+ getOffset(input) {
105
+ let offset = input?.offset;
106
+ if (offset) {
107
+ if (offset instanceof integer8_1.Integer8) {
108
+ offset = Number(offset.get());
109
+ }
110
+ else {
111
+ offset = (0, _parse_1.parse)(offset);
112
+ }
113
+ if (offset > this.length
114
+ || offset < 0) {
115
+ (0, throw_error_1.throwError)("CX_SY_RANGE_OUT_OF_BOUNDS");
116
+ }
117
+ }
118
+ else {
119
+ offset = 0;
120
+ }
121
+ let length = input?.length;
122
+ if (length) {
123
+ if (length instanceof integer8_1.Integer8) {
124
+ length = Number(length.get());
125
+ }
126
+ else {
127
+ length = (0, _parse_1.parse)(length);
128
+ }
129
+ if (length > this.length
130
+ || length < 0) {
131
+ (0, throw_error_1.throwError)("CX_SY_RANGE_OUT_OF_BOUNDS");
132
+ }
133
+ }
134
+ if (offset !== undefined && length !== undefined) {
135
+ if (offset + length > this.length) {
136
+ (0, throw_error_1.throwError)("CX_SY_RANGE_OUT_OF_BOUNDS");
137
+ }
138
+ }
139
+ // not sure how this works: without copying, https://nodejs.org/api/buffer.html#static-method-bufferfromarraybuffer-byteoffset-length
140
+ /*
141
+ console.dir(offset);
142
+ console.dir(length);
143
+ console.dir(this.value.subarray(offset, length ? offset + length : undefined));
144
+ console.dir(Buffer.from(this.value.subarray(offset, length ? offset + length : undefined)));
145
+ */
146
+ const str = Buffer.from(this.value.subarray(offset, length ? offset + length : undefined)).toString("hex")
147
+ .toUpperCase();
148
+ return new xstring_1.XString().set(str);
149
+ }
150
+ }
151
+ exports.HexUInt8 = HexUInt8;
152
+ //# sourceMappingURL=hex_uint8.js.map
@@ -6,6 +6,7 @@ export * from "./decfloat34";
6
6
  export * from "./field_symbol";
7
7
  export * from "./float";
8
8
  export * from "./hex";
9
+ export * from "./hex_uint8";
9
10
  export * from "./integer";
10
11
  export * from "./integer8";
11
12
  export * from "./numc";
@@ -22,6 +22,7 @@ __exportStar(require("./decfloat34"), exports);
22
22
  __exportStar(require("./field_symbol"), exports);
23
23
  __exportStar(require("./float"), exports);
24
24
  __exportStar(require("./hex"), exports);
25
+ __exportStar(require("./hex_uint8"), exports);
25
26
  __exportStar(require("./integer"), exports);
26
27
  __exportStar(require("./integer8"), exports);
27
28
  __exportStar(require("./numc"), exports);
@@ -6,6 +6,7 @@ const float_1 = require("./float");
6
6
  const hex_1 = require("./hex");
7
7
  const xstring_1 = require("./xstring");
8
8
  const integer8_1 = require("./integer8");
9
+ const hex_uint8_1 = require("./hex_uint8");
9
10
  exports.DIGITS = new RegExp(/^\s*-?\+?\d+\.?\d* *$/i);
10
11
  exports.MAX_INTEGER = 2147483647;
11
12
  exports.MIN_INTEGER = -2147483648;
@@ -56,10 +57,11 @@ class Integer {
56
57
  else if (value instanceof float_1.Float) {
57
58
  this.set(Math.round(value.getRaw()));
58
59
  }
59
- else if (value instanceof hex_1.Hex || value instanceof xstring_1.XString) {
60
+ else if (value instanceof hex_1.Hex || value instanceof xstring_1.XString || value instanceof hex_uint8_1.HexUInt8) {
60
61
  let num = parseInt(value.get(), 16);
61
62
  // handle two complement,
62
- if (value instanceof hex_1.Hex && value.getLength() >= 4) {
63
+ if ((value instanceof hex_1.Hex || value instanceof hex_uint8_1.HexUInt8)
64
+ && value.getLength() >= 4) {
63
65
  const maxVal = Math.pow(2, value.get().length / 2 * 8);
64
66
  if (num > maxVal / 2 - 1) {
65
67
  num = num - maxVal;
@@ -8,6 +8,7 @@ const xstring_1 = require("./xstring");
8
8
  const integer_1 = require("./integer");
9
9
  const get_bit_1 = require("../statements/get_bit");
10
10
  const character_1 = require("./character");
11
+ const hex_uint8_1 = require("./hex_uint8");
11
12
  const digits = new RegExp(/^\s*-?\+?\d+\.?\d* *$/i);
12
13
  class Integer8 {
13
14
  constructor(input) {
@@ -39,7 +40,7 @@ class Integer8 {
39
40
  else if (value instanceof float_1.Float) {
40
41
  this.set(Math.round(value.getRaw()));
41
42
  }
42
- else if (value instanceof hex_1.Hex || value instanceof xstring_1.XString) {
43
+ else if (value instanceof hex_1.Hex || value instanceof xstring_1.XString || value instanceof hex_uint8_1.HexUInt8) {
43
44
  if (value.get().length === 16) {
44
45
  const lv_bit = new character_1.Character();
45
46
  (0, get_bit_1.getBit)(new integer_1.Integer().set(1), value, lv_bit);
@@ -11,6 +11,7 @@ const insert_internal_1 = require("../statements/insert_internal");
11
11
  const sort_1 = require("../statements/sort");
12
12
  const character_1 = require("./character");
13
13
  const hex_1 = require("./hex");
14
+ const hex_uint8_1 = require("./hex_uint8");
14
15
  // const FEATURE_SHARED_TABLES = true;
15
16
  var TableAccessType;
16
17
  (function (TableAccessType) {
@@ -155,6 +156,9 @@ class HashedTable {
155
156
  else if (field instanceof hex_1.Hex && val instanceof hex_1.Hex && field.getLength() === val.getLength()) {
156
157
  val = val.get();
157
158
  }
159
+ else if (field instanceof hex_uint8_1.HexUInt8 && val instanceof hex_uint8_1.HexUInt8 && field.getLength() === val.getLength()) {
160
+ val = val.get();
161
+ }
158
162
  else {
159
163
  // convert
160
164
  const rowType = (0, clone_1.clone)(field);
@@ -17,8 +17,9 @@ class XString {
17
17
  set(value) {
18
18
  if (typeof value === "string") {
19
19
  this.value = value;
20
- const finalLength = Math.ceil(this.value.length / 2) * 2;
21
- this.value = this.value.padEnd(finalLength, "0");
20
+ if (this.value.length % 2 === 1) {
21
+ this.value = this.value + "0";
22
+ }
22
23
  }
23
24
  else if (typeof value === "number") {
24
25
  this.value = Math.round(value).toString(16).toUpperCase();
@@ -37,8 +38,9 @@ class XString {
37
38
  }
38
39
  else if (typeof v === "number") {
39
40
  this.value = v.toString(16).toUpperCase();
40
- const finalLength = Math.ceil(this.value.length / 2) * 2;
41
- this.value = this.value.padStart(finalLength, "0");
41
+ if (this.value.length % 2 === 1) {
42
+ this.value = "0" + this.value;
43
+ }
42
44
  }
43
45
  else {
44
46
  this.set(v);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abaplint/runtime",
3
- "version": "2.8.13",
3
+ "version": "2.8.15",
4
4
  "description": "Transpiler - Runtime",
5
5
  "main": "build/src/index.js",
6
6
  "typings": "build/src/index.d.ts",