json-as 1.0.0-alpha.3 → 1.0.0-alpha.4
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 +31 -19
- package/assembly/__tests__/box.spec.ts +37 -0
- package/assembly/__tests__/date.spec.ts +38 -0
- package/assembly/deserialize/simple/bool.ts +4 -7
- package/assembly/deserialize/simple/date.ts +2 -2
- package/assembly/deserialize/simple/object.ts +3 -1
- package/assembly/index.ts +31 -8
- package/assembly/serialize/simd/string.ts +11 -11
- 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/test.ts +58 -4
- package/assembly/util/snp.ts +2 -2
- package/modules/as-bs/assembly/index.ts +61 -30
- package/package.json +5 -5
- package/transform/lib/builder.js +1340 -1262
- package/transform/lib/index.js +582 -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 +22 -16
|
@@ -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
|
|
89
|
+
// @ts-ignore: exists
|
|
59
90
|
const newPtr = __renew(buffer, newSize);
|
|
60
|
-
|
|
91
|
+
bufferSize = newSize;
|
|
61
92
|
buffer = newPtr;
|
|
62
93
|
offset = newPtr + newSize;
|
|
63
|
-
|
|
94
|
+
stackSize = newPtr;
|
|
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-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.4",
|
|
4
4
|
"author": "Jairus Tanaka",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -9,12 +9,12 @@
|
|
|
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
13
|
"as-console": "^7.0.0",
|
|
14
|
-
"assemblyscript": "^0.27.
|
|
14
|
+
"assemblyscript": "^0.27.34",
|
|
15
15
|
"assemblyscript-prettier": "^3.0.1",
|
|
16
|
-
"prettier": "^3.
|
|
17
|
-
"typescript": "
|
|
16
|
+
"prettier": "^3.5.0",
|
|
17
|
+
"typescript": "^5.7.3"
|
|
18
18
|
},
|
|
19
19
|
"bugs": {
|
|
20
20
|
"url": "https://github.com/JairusSW/as-json/issues"
|