Skip to content

Commit

Permalink
u64
Browse files Browse the repository at this point in the history
  • Loading branch information
evmar committed Jun 6, 2022
1 parent db743e5 commit 06db647
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */

/* Language and Environment */
"target": "es2016" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
"target": "es2020" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
"jsx": "react" /* Specify what JSX code is generated. */,
// "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */
Expand Down
13 changes: 9 additions & 4 deletions wasm/code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,10 +273,14 @@ interface InstrMem {
align: number;
offset: number;
}
interface InstrConstInt {
op: Instr.i32_const | Instr.i64_const;
interface InstrConstInt32 {
op: Instr.i32_const;
n: number;
}
interface InstrConstInt64 {
op: Instr.i64_const;
n: bigint;
}
interface InstrConstFloat {
op: Instr.f32_const | Instr.f64_const;
z: number;
Expand All @@ -300,7 +304,8 @@ type InstructionWithFields =
| InstrLocal
| InstrGlobal
| InstrMem
| InstrConstInt
| InstrConstInt32
| InstrConstInt64
| InstrConstFloat
| InstrRefNull
| InstrRefFunc;
Expand Down Expand Up @@ -475,7 +480,7 @@ function readInstruction(r: Reader): Instruction {
case 0x41:
return { op: Instr.i32_const, n: r.readUint() };
case 0x42:
return { op: Instr.i64_const, n: r.readUint() };
return { op: Instr.i64_const, n: r.readUintBig() };
case 0x43:
return { op: Instr.f32_const, z: r.readF32() };
case 0x44:
Expand Down
16 changes: 14 additions & 2 deletions wasm/reader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,20 @@ export class Reader {
let shift = 0;
while (true) {
const b = this.read8();
n |= (b & 0x7f) << shift;
if ((b & 0x80) === 0) break;
n |= (b & 0b0111_1111) << shift;
if ((b & 0b1000_0000) === 0) break;
shift += 7;
}
return n;
}

readUintBig(): bigint {
let n = 0n;
let shift = 0;
while (true) {
const b = this.read8();
n |= BigInt(b & 0b0111_1111) << BigInt(shift);
if ((b & 0b1000_0000) === 0) break;
shift += 7;
}
return n;
Expand Down

0 comments on commit 06db647

Please sign in to comment.