json-as 1.0.0-alpha.3 → 1.0.0-beta.1
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.
- package/CHANGELOG +14 -0
- package/README.md +76 -59
- package/assembly/__benches__/misc.bench.ts +48 -0
- package/assembly/__benches__/schemas.ts +25 -0
- package/assembly/__tests__/arbitrary.spec.ts +19 -0
- package/assembly/__tests__/box.spec.ts +37 -0
- package/assembly/__tests__/date.spec.ts +38 -0
- package/assembly/__tests__/types.ts +3 -3
- package/assembly/deserialize/simd/string.ts +1 -1
- package/assembly/deserialize/simple/arbitrary.ts +1 -1
- package/assembly/deserialize/simple/array/arbitrary.ts +47 -24
- package/assembly/deserialize/simple/array/{object.ts → struct.ts} +1 -1
- package/assembly/deserialize/simple/array.ts +4 -9
- package/assembly/deserialize/simple/bool.ts +4 -7
- package/assembly/deserialize/simple/date.ts +2 -2
- package/assembly/deserialize/simple/integer.ts +2 -1
- package/assembly/deserialize/simple/map.ts +1 -1
- package/assembly/deserialize/simple/object.ts +13 -17
- package/assembly/deserialize/simple/struct.ts +158 -0
- package/assembly/index.ts +143 -24
- package/assembly/serialize/simd/string.ts +11 -11
- package/assembly/serialize/simple/arbitrary.ts +15 -2
- package/assembly/serialize/simple/array.ts +4 -3
- package/assembly/serialize/simple/float.ts +1 -1
- package/assembly/serialize/simple/integer.ts +7 -2
- package/assembly/serialize/simple/object.ts +43 -6
- package/assembly/serialize/simple/struct.ts +7 -0
- package/assembly/test.ts +84 -4
- package/assembly/util/atoi.ts +1 -1
- package/assembly/util/snp.ts +2 -2
- package/bench.js +11 -2
- package/modules/as-bs/assembly/index.ts +63 -32
- package/modules/as-bs/assembly/state.ts +8 -0
- package/package.json +7 -6
- package/transform/lib/builder.js +1340 -1262
- package/transform/lib/index.js +577 -512
- package/transform/lib/index.js.map +1 -1
- package/transform/lib/linker.js +12 -10
- package/transform/lib/types.js +19 -19
- package/transform/lib/util.js +34 -34
- package/transform/lib/visitor.js +529 -526
- package/transform/src/index.ts +25 -23
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { JSON } from "../..";
|
|
2
2
|
import { serializeArray } from "./array";
|
|
3
3
|
import { serializeBool } from "./bool";
|
|
4
|
+
import { serializeFloat } from "./float";
|
|
4
5
|
import { serializeInteger } from "./integer";
|
|
6
|
+
import { serializeObject } from "./object";
|
|
5
7
|
import { serializeString } from "./string";
|
|
6
8
|
|
|
7
9
|
export function serializeArbitrary(src: JSON.Value): void {
|
|
@@ -18,19 +20,30 @@ export function serializeArbitrary(src: JSON.Value): void {
|
|
|
18
20
|
case JSON.Types.U64:
|
|
19
21
|
serializeInteger<u64>(src.get<u64>());
|
|
20
22
|
break;
|
|
23
|
+
case JSON.Types.F32:
|
|
24
|
+
serializeFloat<f32>(src.get<f32>());
|
|
25
|
+
break;
|
|
26
|
+
case JSON.Types.F64:
|
|
27
|
+
serializeFloat<f64>(src.get<f64>());
|
|
28
|
+
break;
|
|
21
29
|
case JSON.Types.String:
|
|
22
30
|
serializeString(src.get<string>());
|
|
23
31
|
break;
|
|
24
32
|
case JSON.Types.Bool:
|
|
25
33
|
serializeBool(src.get<bool>());
|
|
34
|
+
break;
|
|
26
35
|
case JSON.Types.Array: {
|
|
27
36
|
serializeArray(src.get<JSON.Value[]>());
|
|
28
37
|
break;
|
|
29
38
|
}
|
|
39
|
+
case JSON.Types.Object: {
|
|
40
|
+
serializeObject(src.get<JSON.Obj>());
|
|
41
|
+
break;
|
|
42
|
+
}
|
|
30
43
|
default: {
|
|
31
44
|
const fn = JSON.Value.METHODS.get(src.type - JSON.Types.Struct);
|
|
32
|
-
const
|
|
33
|
-
call_indirect<
|
|
45
|
+
const ptr = src.get<usize>();
|
|
46
|
+
call_indirect<void>(fn, 0, ptr);
|
|
34
47
|
}
|
|
35
48
|
}
|
|
36
49
|
}
|
|
@@ -3,15 +3,16 @@ import { COMMA, BRACKET_RIGHT, BRACKET_LEFT } from "../../custom/chars";
|
|
|
3
3
|
import { JSON } from "../..";
|
|
4
4
|
|
|
5
5
|
export function serializeArray<T extends any[]>(src: T): void {
|
|
6
|
+
bs.proposeSize(4);
|
|
6
7
|
const end = src.length - 1;
|
|
7
8
|
let i = 0;
|
|
8
9
|
if (end == -1) {
|
|
9
|
-
bs.proposeSize(4);
|
|
10
10
|
store<u32>(bs.offset, 6094939);
|
|
11
11
|
bs.offset += 4;
|
|
12
12
|
return;
|
|
13
13
|
}
|
|
14
|
-
|
|
14
|
+
// {} = 4
|
|
15
|
+
// xi, = n << 1
|
|
15
16
|
|
|
16
17
|
store<u16>(bs.offset, BRACKET_LEFT);
|
|
17
18
|
bs.offset += 2;
|
|
@@ -26,7 +27,7 @@ export function serializeArray<T extends any[]>(src: T): void {
|
|
|
26
27
|
|
|
27
28
|
const lastBlock = unchecked(src[end]);
|
|
28
29
|
JSON.__serialize<valueof<T>>(lastBlock);
|
|
29
|
-
bs.
|
|
30
|
+
bs.growSize(2);
|
|
30
31
|
store<u16>(bs.offset, BRACKET_RIGHT);
|
|
31
32
|
bs.offset += 2;
|
|
32
33
|
}
|
|
@@ -2,6 +2,11 @@ import { itoa_buffered } from "util/number";
|
|
|
2
2
|
import { bs } from "../../../modules/as-bs";
|
|
3
3
|
|
|
4
4
|
export function serializeInteger<T extends number>(data: T): void {
|
|
5
|
-
bs.
|
|
6
|
-
|
|
5
|
+
bs.ensureSize(sizeof<T>() << 3);
|
|
6
|
+
const bytesWritten = itoa_buffered(bs.offset, data) << 1;
|
|
7
|
+
bs.offset += bytesWritten;
|
|
8
|
+
bs.growSize(bytesWritten);
|
|
7
9
|
}
|
|
10
|
+
|
|
11
|
+
// 32 {"x":,"y":,"z"}
|
|
12
|
+
// 18 3.41.28.3
|
|
@@ -1,7 +1,44 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
}
|
|
1
|
+
import { JSON } from "../..";
|
|
2
|
+
import { bs } from "../../../modules/as-bs/assembly";
|
|
3
|
+
import { BRACE_LEFT, BRACE_RIGHT, QUOTE } from "../../custom/chars";
|
|
4
|
+
import { bytes } from "../../util";
|
|
4
5
|
|
|
5
|
-
export function serializeObject
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
export function serializeObject(data: JSON.Obj): void {
|
|
7
|
+
if (!data.size) {
|
|
8
|
+
store<u32>(bs.offset, 0);
|
|
9
|
+
bs.offset += 4;
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// This grabs `JSON.Obj.stackSize` which is private
|
|
14
|
+
bs.ensureSize(load<u32>(changetype<usize>(data), offsetof<JSON.Obj>("stackSize")) - 2);
|
|
15
|
+
const keys = data.keys();
|
|
16
|
+
const values = data.values();
|
|
17
|
+
|
|
18
|
+
// console.log(" Keys " + keys.join(" "));
|
|
19
|
+
// console.log(" Values " + values.map<string>(v => v.toString()).join(" "))
|
|
20
|
+
|
|
21
|
+
store<u16>(bs.offset, BRACE_LEFT);
|
|
22
|
+
bs.offset += 2;
|
|
23
|
+
|
|
24
|
+
const firstKey = unchecked(keys[0]);
|
|
25
|
+
const keySize = bytes(firstKey);
|
|
26
|
+
store<u16>(bs.offset, QUOTE);
|
|
27
|
+
memory.copy(bs.offset + 2, changetype<usize>(firstKey), keySize);
|
|
28
|
+
store<u32>(bs.offset += keySize + 2, 3801122); // ":
|
|
29
|
+
bs.offset += 4;
|
|
30
|
+
JSON.__serialize(unchecked(values[0]));
|
|
31
|
+
|
|
32
|
+
for (let i = 1; i < keys.length; i++) {
|
|
33
|
+
const key = unchecked(keys[i]);
|
|
34
|
+
const keySize = bytes(key);
|
|
35
|
+
store<u32>(bs.offset, 2228268); // ,"
|
|
36
|
+
memory.copy(bs.offset + 4, changetype<usize>(key), keySize);
|
|
37
|
+
store<u32>(bs.offset += keySize + 4, 3801122); // ":
|
|
38
|
+
bs.offset += 4;
|
|
39
|
+
JSON.__serialize(unchecked(values[i]));
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
store<u16>(bs.offset, BRACE_RIGHT);
|
|
43
|
+
bs.offset += 2;
|
|
44
|
+
}
|
package/assembly/test.ts
CHANGED
|
@@ -1,5 +1,85 @@
|
|
|
1
|
-
import { JSON } from "
|
|
2
|
-
import {
|
|
1
|
+
import { JSON } from ".";
|
|
2
|
+
import { bs } from "../modules/as-bs/assembly";
|
|
3
|
+
import { deserializeArbitraryArray } from "./deserialize/simple/array/arbitrary";
|
|
4
|
+
import { serializeObject } from "./serialize/simple/object";
|
|
5
|
+
import { bytes } from "./util";
|
|
3
6
|
|
|
4
|
-
|
|
5
|
-
|
|
7
|
+
@json
|
|
8
|
+
class Obj {
|
|
9
|
+
public a: string = "hello";
|
|
10
|
+
public b: string = "world";
|
|
11
|
+
public c: string = "\"\t\f\u0000\u0001";
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
@json
|
|
15
|
+
class Vec3 {
|
|
16
|
+
x: f32 = 0.0;
|
|
17
|
+
y: f32 = 0.0;
|
|
18
|
+
z: f32 = 0.0;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
@json
|
|
22
|
+
class Player {
|
|
23
|
+
@alias("first name")
|
|
24
|
+
firstName!: string;
|
|
25
|
+
lastName!: string;
|
|
26
|
+
lastActive!: i32[];
|
|
27
|
+
// Drop in a code block, function, or expression that evaluates to a boolean
|
|
28
|
+
@omitif((self: Player) => self.age < 18)
|
|
29
|
+
age!: i32;
|
|
30
|
+
@omitnull()
|
|
31
|
+
pos!: Vec3 | null;
|
|
32
|
+
isVerified!: boolean;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const player: Player = {
|
|
36
|
+
firstName: "Jairus",
|
|
37
|
+
lastName: "Tanaka",
|
|
38
|
+
lastActive: [2, 7, 2025],
|
|
39
|
+
age: 18,
|
|
40
|
+
pos: {
|
|
41
|
+
x: 3.4,
|
|
42
|
+
y: 1.2,
|
|
43
|
+
z: 8.3
|
|
44
|
+
},
|
|
45
|
+
isVerified: true
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const a1 = JSON.stringify("\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007\u0008\u0009\u000a\u000b\u000c\u000d\u000e\u000f\u000f\u0011\u0012\u0013\u0014\u0015\u0016\u0017\u0018\u0019\u001a\u001b\u001c\u001d\u001e\u001f");
|
|
49
|
+
// console.log("Bytes " + bytes(a1).toString());
|
|
50
|
+
console.log("a1: " + a1);
|
|
51
|
+
|
|
52
|
+
const obj = new Obj();
|
|
53
|
+
const a2 = JSON.stringify(obj);
|
|
54
|
+
// console.log("Bytes " + bytes(a2).toString());
|
|
55
|
+
console.log("a2: " + a2);
|
|
56
|
+
|
|
57
|
+
const a3 = JSON.stringify(player);
|
|
58
|
+
// console.log("Bytes " + bytes(a3).toString());
|
|
59
|
+
console.log("a3: " + a3);
|
|
60
|
+
|
|
61
|
+
const a4 = new JSON.Obj();
|
|
62
|
+
|
|
63
|
+
a4.set("x", 1.5);
|
|
64
|
+
a4.set("y", 5.4);
|
|
65
|
+
a4.set("z", 9.8);
|
|
66
|
+
a4.set("obj", obj)
|
|
67
|
+
a4.set<boolean>("bool", false);
|
|
68
|
+
|
|
69
|
+
console.log("a4: " + JSON.stringify(a4));
|
|
70
|
+
|
|
71
|
+
const a5 = JSON.parse<JSON.Obj>('{"foo":"bar"}');
|
|
72
|
+
|
|
73
|
+
console.log("a5: " + JSON.stringify(a5));
|
|
74
|
+
|
|
75
|
+
const a6 = JSON.parse<JSON.Obj>('{"x":1.5,"y":5.4,"z":9.8,"obj":{"foo":"bar"}}');
|
|
76
|
+
|
|
77
|
+
console.log("a6: " + JSON.stringify(a6));
|
|
78
|
+
|
|
79
|
+
const a7 = JSON.parse<JSON.Value[]>('["string",true,3.14,{"x":1.0,"y":2.0,"z":3.0},[1,2,3,true]]');
|
|
80
|
+
|
|
81
|
+
console.log("a7: " + JSON.stringify(a7));
|
|
82
|
+
|
|
83
|
+
const a8 = JSON.stringify(["hello", JSON.stringify("world"),"working?"]);
|
|
84
|
+
|
|
85
|
+
console.log("a8: " + a8);
|
package/assembly/util/atoi.ts
CHANGED
package/assembly/util/snp.ts
CHANGED
|
@@ -7,7 +7,7 @@ import { POW_TEN_TABLE_32, POW_TEN_TABLE_64 } from "../globals/tables";
|
|
|
7
7
|
import { atoi } from "./atoi";
|
|
8
8
|
|
|
9
9
|
// @ts-ignore: Decorator valid here
|
|
10
|
-
@inline function snp<T extends number>(srcStart: usize, srcEnd: usize): T {
|
|
10
|
+
@inline export function snp<T extends number>(srcStart: usize, srcEnd: usize): T {
|
|
11
11
|
// @ts-ignore: type
|
|
12
12
|
let val: T = 0;
|
|
13
13
|
let char = load<u16>(srcStart) - 48;
|
|
@@ -46,7 +46,7 @@ import { atoi } from "./atoi";
|
|
|
46
46
|
char = load<u16>(srcStart);
|
|
47
47
|
if (char == 45) {
|
|
48
48
|
// @ts-ignore: type
|
|
49
|
-
return val / pow10(atoi(srcStart + 2, srcEnd));
|
|
49
|
+
return val / pow10(atoi<u8>(srcStart + 2, srcEnd));
|
|
50
50
|
} else {
|
|
51
51
|
// @ts-ignore: type
|
|
52
52
|
return val * pow10(atoi(srcStart, srcEnd));
|
package/bench.js
CHANGED
|
@@ -34,8 +34,17 @@ const vec = {
|
|
|
34
34
|
let data;
|
|
35
35
|
|
|
36
36
|
const bench = new Bench({ time: 1000 })
|
|
37
|
-
.add("
|
|
38
|
-
data = JSON.stringify(
|
|
37
|
+
.add("serialize vec3", () =>
|
|
38
|
+
data = JSON.stringify(vec)
|
|
39
|
+
)
|
|
40
|
+
.add("deserialize vec3", () => {
|
|
41
|
+
data = JSON.parse('{"x":3,"y":1,"z":8}');
|
|
42
|
+
})
|
|
43
|
+
.add("serialize alphabet string", () => {
|
|
44
|
+
data = JSON.stringify("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789~`!@#$%^&*()-_=+{[}]|\\:;\"'?/>.<,'\"}");
|
|
45
|
+
})
|
|
46
|
+
.add("deserialize alphabet string", () => {
|
|
47
|
+
data = JSON.parse('"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789~`!@#$%^&*()-_=+{[}]|\\\\:;\\"\'?/>.<,\'\\"}"')
|
|
39
48
|
}) /*
|
|
40
49
|
.add("parse float", () => {
|
|
41
50
|
data = JSON.parse("1.2345")
|
|
@@ -5,46 +5,77 @@ import { OBJECT, TOTAL_OVERHEAD } from "rt/common";
|
|
|
5
5
|
*/
|
|
6
6
|
export namespace bs {
|
|
7
7
|
/** Current buffer pointer. */ // @ts-ignore
|
|
8
|
-
export let buffer:
|
|
8
|
+
export let buffer: ArrayBuffer = new ArrayBuffer(32);//__new(32, idof<ArrayBuffer>());
|
|
9
9
|
|
|
10
10
|
/** Current offset within the buffer. */
|
|
11
|
-
export let offset: usize = buffer;
|
|
11
|
+
export let offset: usize = changetype<usize>(buffer);
|
|
12
12
|
|
|
13
13
|
/** Byte length of the buffer. */
|
|
14
|
-
|
|
14
|
+
let bufferSize: usize = 32;
|
|
15
15
|
|
|
16
16
|
/** Proposed size of output */
|
|
17
|
-
export let
|
|
17
|
+
export let stackSize: usize = 0;
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
20
|
* Proposes that the buffer size is should be greater than or equal to the proposed size.
|
|
21
21
|
* If necessary, reallocates the buffer to the exact new size.
|
|
22
22
|
* @param size - The size to propose.
|
|
23
23
|
*/
|
|
24
|
-
// @ts-ignore:
|
|
24
|
+
// @ts-ignore: decorator
|
|
25
|
+
@inline export function ensureSize(size: u32): void {
|
|
26
|
+
// console.log("Ensure " + (stackSize).toString() + " -> " + (stackSize + size).toString() + " (" + size.toString() + ") " + (((stackSize + size) > bufferSize) ? "+" : ""));
|
|
27
|
+
if (offset + size > bufferSize + changetype<usize>(buffer)) {
|
|
28
|
+
const deltaBytes = nextPowerOf2(size + 64);
|
|
29
|
+
bufferSize += deltaBytes;
|
|
30
|
+
// @ts-ignore: exists
|
|
31
|
+
const newPtr = changetype<ArrayBuffer>(__renew(
|
|
32
|
+
changetype<usize>(buffer),
|
|
33
|
+
bufferSize
|
|
34
|
+
));
|
|
35
|
+
offset = offset + changetype<usize>(newPtr) - changetype<usize>(buffer);
|
|
36
|
+
buffer = newPtr;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Proposes that the buffer size is should be greater than or equal to the proposed size.
|
|
42
|
+
* If necessary, reallocates the buffer to the exact new size.
|
|
43
|
+
* @param size - The size to propose.
|
|
44
|
+
*/
|
|
45
|
+
// @ts-ignore: decorator
|
|
25
46
|
@inline export function proposeSize(size: u32): void {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
47
|
+
// console.log("Propose " + (stackSize).toString() + " -> " + (stackSize + size).toString() + " (" + size.toString() + ") " + (((stackSize + size) > bufferSize) ? "+" : ""));
|
|
48
|
+
if ((stackSize += size) > bufferSize) {
|
|
49
|
+
const deltaBytes = nextPowerOf2(size);
|
|
50
|
+
bufferSize += deltaBytes;
|
|
51
|
+
// @ts-ignore: exists
|
|
52
|
+
const newPtr = changetype<ArrayBuffer>(__renew(
|
|
53
|
+
changetype<usize>(buffer),
|
|
54
|
+
bufferSize
|
|
55
|
+
));
|
|
56
|
+
offset = offset + changetype<usize>(newPtr) - changetype<usize>(buffer);
|
|
31
57
|
buffer = newPtr;
|
|
32
58
|
}
|
|
33
59
|
}
|
|
34
60
|
|
|
35
61
|
/**
|
|
36
|
-
* Increases the proposed size by nextPowerOf2(n +
|
|
62
|
+
* Increases the proposed size by nextPowerOf2(n + 64) if necessary.
|
|
37
63
|
* If necessary, reallocates the buffer to the exact new size.
|
|
38
64
|
* @param size - The size to grow by.
|
|
39
65
|
*/
|
|
40
|
-
// @ts-ignore:
|
|
66
|
+
// @ts-ignore: decorator
|
|
41
67
|
@inline export function growSize(size: u32): void {
|
|
42
|
-
|
|
43
|
-
if (
|
|
44
|
-
|
|
68
|
+
// console.log("Grow " + (stackSize).toString() + " -> " + (stackSize + size).toString() + " (" + size.toString() + ") " + (((stackSize + size) > bufferSize) ? "+" : ""));
|
|
69
|
+
if ((stackSize += size) > bufferSize) {
|
|
70
|
+
const deltaBytes = nextPowerOf2(size + 64);
|
|
71
|
+
bufferSize += deltaBytes;
|
|
45
72
|
// @ts-ignore
|
|
46
|
-
const newPtr = __renew(
|
|
47
|
-
|
|
73
|
+
const newPtr = changetype<ArrayBuffer>(__renew(
|
|
74
|
+
changetype<usize>(buffer),
|
|
75
|
+
bufferSize
|
|
76
|
+
));
|
|
77
|
+
// if (buffer != newPtr) console.log(" Old: " + changetype<usize>(buffer).toString() + "\n New: " + changetype<usize>(newPtr).toString());
|
|
78
|
+
offset = offset + changetype<usize>(newPtr) - changetype<usize>(buffer);
|
|
48
79
|
buffer = newPtr;
|
|
49
80
|
}
|
|
50
81
|
}
|
|
@@ -55,12 +86,12 @@ export namespace bs {
|
|
|
55
86
|
*/
|
|
56
87
|
// @ts-ignore: Decorator valid here
|
|
57
88
|
@inline export function resize(newSize: u32): void {
|
|
58
|
-
// @ts-ignore
|
|
59
|
-
const newPtr = __renew(buffer, newSize);
|
|
60
|
-
|
|
89
|
+
// @ts-ignore: exists
|
|
90
|
+
const newPtr = changetype<ArrayBuffer>(__renew(changetype<usize>(buffer), newSize));
|
|
91
|
+
bufferSize = newSize;
|
|
92
|
+
offset = changetype<usize>(newPtr);
|
|
61
93
|
buffer = newPtr;
|
|
62
|
-
|
|
63
|
-
realSize = newPtr;
|
|
94
|
+
stackSize = 0;
|
|
64
95
|
}
|
|
65
96
|
|
|
66
97
|
/**
|
|
@@ -69,13 +100,13 @@ export namespace bs {
|
|
|
69
100
|
*/
|
|
70
101
|
// @ts-ignore: Decorator valid here
|
|
71
102
|
@inline export function out<T>(): T {
|
|
72
|
-
const len = offset - buffer;
|
|
73
|
-
// @ts-ignore
|
|
103
|
+
const len = offset - changetype<usize>(buffer);
|
|
104
|
+
// @ts-ignore: exists
|
|
74
105
|
const _out = __new(len, idof<T>());
|
|
75
|
-
memory.copy(_out, buffer, len);
|
|
106
|
+
memory.copy(_out, changetype<usize>(buffer), len);
|
|
76
107
|
|
|
77
|
-
offset = buffer;
|
|
78
|
-
|
|
108
|
+
offset = changetype<usize>(buffer);
|
|
109
|
+
stackSize = 0;
|
|
79
110
|
return changetype<T>(_out);
|
|
80
111
|
}
|
|
81
112
|
|
|
@@ -88,13 +119,13 @@ export namespace bs {
|
|
|
88
119
|
*/
|
|
89
120
|
// @ts-ignore: Decorator valid here
|
|
90
121
|
@inline export function outTo<T>(dst: usize): T {
|
|
91
|
-
const len = offset - buffer;
|
|
92
|
-
// @ts-ignore
|
|
122
|
+
const len = offset - changetype<usize>(buffer);
|
|
123
|
+
// @ts-ignore: exists
|
|
93
124
|
if (len != changetype<OBJECT>(dst - TOTAL_OVERHEAD).rtSize) __renew(len, idof<T>());
|
|
94
|
-
memory.copy(dst, buffer, len);
|
|
125
|
+
memory.copy(dst, changetype<usize>(buffer), len);
|
|
95
126
|
|
|
96
|
-
offset = buffer;
|
|
97
|
-
|
|
127
|
+
offset = changetype<usize>(buffer);
|
|
128
|
+
stackSize = 0;
|
|
98
129
|
return changetype<T>(dst);
|
|
99
130
|
}
|
|
100
131
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "json-as",
|
|
3
|
-
"version": "1.0.0-
|
|
3
|
+
"version": "1.0.0-beta.1",
|
|
4
4
|
"author": "Jairus Tanaka",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -9,12 +9,13 @@
|
|
|
9
9
|
"main": "transform/lib/index.js",
|
|
10
10
|
"devDependencies": {
|
|
11
11
|
"@assemblyscript/wasi-shim": "^0.1.0",
|
|
12
|
-
"@types/node": "
|
|
12
|
+
"@types/node": "^22.13.1",
|
|
13
|
+
"as-bench": "JairusSW/as-bench",
|
|
13
14
|
"as-console": "^7.0.0",
|
|
14
|
-
"assemblyscript": "^0.27.
|
|
15
|
+
"assemblyscript": "^0.27.34",
|
|
15
16
|
"assemblyscript-prettier": "^3.0.1",
|
|
16
|
-
"prettier": "^3.
|
|
17
|
-
"typescript": "
|
|
17
|
+
"prettier": "^3.5.0",
|
|
18
|
+
"typescript": "^5.7.3"
|
|
18
19
|
},
|
|
19
20
|
"bugs": {
|
|
20
21
|
"url": "https://github.com/JairusSW/as-json/issues"
|
|
@@ -52,7 +53,7 @@
|
|
|
52
53
|
},
|
|
53
54
|
"scripts": {
|
|
54
55
|
"test": "bash ./run-tests.sh",
|
|
55
|
-
"build:bench": "rm -rf ./build/ && asc assembly/__benches__/misc.bench.ts -o ./build/bench.wasm --textFile ./build/bench.wat --transform ./transform --optimizeLevel 3 --shrinkLevel 0 --converge --noAssert --uncheckedBehavior always --runtime
|
|
56
|
+
"build:bench": "rm -rf ./build/ && JSON_DEBUG=true asc assembly/__benches__/misc.bench.ts -o ./build/bench.wasm --textFile ./build/bench.wat --transform ./transform --optimizeLevel 3 --shrinkLevel 0 --converge --noAssert --uncheckedBehavior always --runtime stub --enable simd --enable bulk-memory",
|
|
56
57
|
"build:test": "rm -rf ./build/ && JSON_DEBUG=true asc assembly/test.ts --transform ./transform -o ./build/test.wasm --textFile ./build/test.wat --optimizeLevel 3 --shrinkLevel 0",
|
|
57
58
|
"build:test:simd": "rm -rf ./build/ && JSON_DEBUG=true asc assembly/test.ts --transform ./transform -o ./build/test.wasm --textFile ./build/test.wat --optimizeLevel 3 --shrinkLevel 0 --enable simd",
|
|
58
59
|
"test:wasmtime": "wasmtime ./build/test.wasm",
|