Skip to content

Commit 80802e1

Browse files
feat: add I64LEB128 (#12)
Co-authored-by: Elias Sjögreen <eliassjogreen1@gmail.com>
1 parent dc59df0 commit 80802e1

22 files changed

+481
-110
lines changed

.github/workflows/checks.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ jobs:
77
runs-on: ubuntu-latest
88
steps:
99
- name: Checkout sources
10-
uses: actions/checkout@v2
10+
uses: actions/checkout@v3
1111

1212
- name: Setup latest deno version
1313
uses: denoland/setup-deno@main
@@ -22,7 +22,7 @@ jobs:
2222
runs-on: ubuntu-latest
2323
steps:
2424
- name: Checkout sources
25-
uses: actions/checkout@v2
25+
uses: actions/checkout@v3
2626

2727
- name: Setup latest deno version
2828
uses: denoland/setup-deno@main

benchmarks/string.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { FixedUTF8String } from "../types/string/mod.ts";
1+
import { FixedLengthString } from "../mod.ts";
22

3-
const stringThing = new FixedUTF8String(12);
3+
const stringThing = new FixedLengthString(12);
44

55
const ab = new TextEncoder().encode("Hello World!").buffer;
66
const dt = new DataView(ab);

benchmarks/struct.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { AlignedStruct } from "../types/struct/mod.ts";
2-
import { u32 } from "../types/primitive/mod.ts";
1+
import { AlignedStruct, u32 } from "../mod.ts";
32

43
const data = new DataView(new ArrayBuffer(8));
54

benchmarks/tuple.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { Tuple } from "../types/tuple/mod.ts";
2-
import { u32 } from "../types/primitive/u32.ts";
1+
import { Tuple, u32 } from "../mod.ts";
32

43
const benchTuple = new Tuple([u32, u32]);
54
const u32arr = new Uint32Array([2, 4]);

deno.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"imports": {
3+
"std/": "https://deno.land/std@0.184.0/",
4+
"wabt": "npm:wabt@1.0.32"
5+
},
6+
"tasks": {
7+
"build": "deno task build_i64leb128",
8+
"build_i64leb128": "deno run --allow-read --allow-write ./scripts/build_i64leb128.ts"
9+
}
10+
}

deno.lock

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mod.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export * from "./types/mod.ts";
2+
export * from "./utils.ts";

scripts/build_i64leb128.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import wabt from "wabt";
2+
3+
const { parseWat } = await wabt();
4+
5+
const source = "./types/leb128/_i64leb128.wat";
6+
const destination = "./types/leb128/_i64leb128.ts";
7+
8+
const wat = await Deno.readTextFile(source);
9+
const module = parseWat(source, wat);
10+
const wasm = module.toBinary({}).buffer;
11+
const encoded = btoa(String.fromCharCode(...wasm));
12+
13+
const content = `\
14+
// Copyright 2023 the Blocktopus authors. All rights reserved. MIT license.
15+
// Copyright 2023 the denosaurs team. All rights reserved. MIT license.
16+
17+
const bytes = Uint8Array.from(
18+
atob(
19+
"${encoded}"
20+
),
21+
(c) => c.charCodeAt(0)
22+
);
23+
const { instance } = await WebAssembly.instantiate(bytes);
24+
25+
const exports = instance.exports as {
26+
memory: WebAssembly.Memory;
27+
read: (pointer: number) => [bigint, number];
28+
write: (value: bigint) => number;
29+
};
30+
31+
const memory = new Uint8Array(exports.memory.buffer);
32+
33+
export function read(buffer: Uint8Array): [bigint, number] {
34+
memory.set(buffer, 0);
35+
return exports.read(0);
36+
}
37+
38+
export function write(value: bigint): Uint8Array {
39+
return memory.subarray(0, exports.write(value));
40+
}
41+
`;
42+
43+
await Deno.writeTextFile(destination, content);
File renamed without changes.

types/array/mod.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
export * from "./array.ts";
2-
export * from "./arrayBuffer.ts";
3-
export * from "./typedArray.ts";
2+
export * from "./array_buffer.ts";
3+
export * from "./typed_array.ts";

0 commit comments

Comments
 (0)