json-as 0.9.22 → 0.9.23
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 +1 -0
- package/README.md +1 -1
- package/assembly/serialize/string.ts +199 -197
- package/package.json +2 -2
- package/transform/package.json +1 -1
package/CHANGELOG
CHANGED
|
@@ -29,6 +29,7 @@ v0.9.18 - Should be able to use @alias and @omit*** or JSON.Raw
|
|
|
29
29
|
v0.9.19 - Fix arguments in @omitif declarations not working properly
|
|
30
30
|
v0.9.20 - Strings were being received with quotes attached via the toString functionality. Removed that.
|
|
31
31
|
v0.9.22 - Fix #89 and #93. Several bug fixes some severe such as ",null" being prepended when using @omit. Properly warn when a schema has fields that are not compatible with json
|
|
32
|
+
v0.9.23 - Comment out SIMD-related code for now
|
|
32
33
|
|
|
33
34
|
[UNRELEASED] v1.0.0
|
|
34
35
|
- Allow nullable primitives
|
package/README.md
CHANGED
|
@@ -12,153 +12,154 @@ import { bs } from "../custom/bs";
|
|
|
12
12
|
import { _intTo16, intTo16, unsafeCharCodeAt } from "../custom/util";
|
|
13
13
|
import { Sink } from "../custom/sink";
|
|
14
14
|
|
|
15
|
-
function needsEscaping(data: string): bool {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
// if (len < 16) {
|
|
19
|
-
// while (len--) {
|
|
20
|
-
// const char = load<u16>(changetype<usize>(data) + len);
|
|
21
|
-
// if (char == 34 || char == 92 || char <= 31) {
|
|
22
|
-
// return true;
|
|
23
|
-
// }
|
|
24
|
-
// }
|
|
25
|
-
// return false;
|
|
26
|
-
// }
|
|
15
|
+
// function needsEscaping(data: string): bool {
|
|
16
|
+
// let len = data.length;
|
|
27
17
|
|
|
28
|
-
|
|
29
|
-
|
|
18
|
+
// // if (len < 16) {
|
|
19
|
+
// // while (len--) {
|
|
20
|
+
// // const char = load<u16>(changetype<usize>(data) + len);
|
|
21
|
+
// // if (char == 34 || char == 92 || char <= 31) {
|
|
22
|
+
// // return true;
|
|
23
|
+
// // }
|
|
24
|
+
// // }
|
|
25
|
+
// // return false;
|
|
26
|
+
// // }
|
|
30
27
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
running = v128.or(running, v128.eq<i16>(w, i16x8.splat(34)));
|
|
34
|
-
running = v128.or(running, v128.eq<i16>(w, i16x8.splat(92)));
|
|
28
|
+
// let running = v128.splat<i64>(0);
|
|
29
|
+
// //let i = 0;
|
|
35
30
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
31
|
+
// //while (i + 15 < len) {
|
|
32
|
+
// let w = v128.load(changetype<usize>(data));
|
|
33
|
+
// running = v128.or(running, v128.eq<i16>(w, i16x8.splat(34)));
|
|
34
|
+
// running = v128.or(running, v128.eq<i16>(w, i16x8.splat(92)));
|
|
40
35
|
|
|
41
|
-
|
|
42
|
-
|
|
36
|
+
// let subtracted = v128.sub<i16>(w, i8x16.splat(31));
|
|
37
|
+
// running = v128.or(running, v128.eq<i16>(subtracted, v128.splat<i64>(0)));
|
|
38
|
+
// //i += 16;
|
|
39
|
+
// //}
|
|
43
40
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
*
|
|
47
|
-
* A faster version could perhaps look like the following:
|
|
48
|
-
*/
|
|
49
|
-
// @ts-ignore: Decorator
|
|
50
|
-
@inline export function serialize_simd_v1(src: string, dst: usize): void {
|
|
51
|
-
let src_ptr = changetype<usize>(src);
|
|
52
|
-
let dst_ptr = changetype<usize>(dst) + 2;
|
|
41
|
+
// return v128.any_true(running);
|
|
42
|
+
// }
|
|
53
43
|
|
|
54
|
-
|
|
44
|
+
// /**
|
|
45
|
+
// * A prototype SIMD implementation for string serialization which can only work in 128-byte (or 16 chars with wtf-16).
|
|
46
|
+
// *
|
|
47
|
+
// * A faster version could perhaps look like the following:
|
|
48
|
+
// */
|
|
49
|
+
// // @ts-ignore: Decorator
|
|
50
|
+
// @inline export function serialize_simd_v1(src: string, dst: usize): void {
|
|
51
|
+
// let src_ptr = changetype<usize>(src);
|
|
52
|
+
// let dst_ptr = changetype<usize>(dst) + 2;
|
|
55
53
|
|
|
56
|
-
|
|
57
|
-
const src_end_15 = src_end - 15;
|
|
54
|
+
// store<u16>(changetype<usize>(dst), 34); /* " */
|
|
58
55
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
const backslash_indices = i16x8.eq(currentBlock, i16x8.splat(92));
|
|
62
|
-
const quote_indices = i16x8.eq(currentBlock, i16x8.splat(34));
|
|
63
|
-
const concat_indices = v128.or(quote_indices, backslash_indices);
|
|
56
|
+
// const src_end = src_ptr + u32(src.length << 1);
|
|
57
|
+
// const src_end_15 = src_end - 15;
|
|
64
58
|
|
|
65
|
-
|
|
59
|
+
// while (src_ptr < src_end_15) {
|
|
60
|
+
// const currentBlock = v128.load(src_ptr);
|
|
61
|
+
// const backslash_indices = i16x8.eq(currentBlock, i16x8.splat(92));
|
|
62
|
+
// const quote_indices = i16x8.eq(currentBlock, i16x8.splat(34));
|
|
63
|
+
// const concat_indices = v128.or(quote_indices, backslash_indices);
|
|
66
64
|
|
|
67
|
-
|
|
68
|
-
const mask = i16x8.bitmask(concat_indices);
|
|
65
|
+
// const escape_indices = i16x8.lt_u(currentBlock, i16x8.splat(32));
|
|
69
66
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
if (anomalies === 1) {
|
|
73
|
-
memory.copy(dst_ptr, src_ptr, start_index >> 1);
|
|
74
|
-
store<u16>(dst_ptr + start_index, 34);
|
|
75
|
-
memory.copy(dst_ptr + start_index + 2, src_ptr + start_index, (32 - start_index) >> 1)
|
|
76
|
-
}
|
|
67
|
+
// if (v128.any_true(v128.or(escape_indices, concat_indices))) {
|
|
68
|
+
// const mask = i16x8.bitmask(concat_indices);
|
|
77
69
|
|
|
78
|
-
|
|
70
|
+
// const anomalies = popcnt(mask);
|
|
71
|
+
// const start_index = (clz(mask) & ~1) + 2 // This essentially floors to the nearest even integer
|
|
72
|
+
// if (anomalies === 1) {
|
|
73
|
+
// memory.copy(dst_ptr, src_ptr, start_index >> 1);
|
|
74
|
+
// store<u16>(dst_ptr + start_index, 34);
|
|
75
|
+
// memory.copy(dst_ptr + start_index + 2, src_ptr + start_index, (32 - start_index) >> 1)
|
|
76
|
+
// }
|
|
79
77
|
|
|
80
|
-
|
|
81
|
-
dst_ptr += 16;
|
|
82
|
-
src_ptr += 16;
|
|
83
|
-
} else {
|
|
84
|
-
v128.store(dst_ptr, currentBlock);
|
|
85
|
-
src_ptr += 16;
|
|
86
|
-
dst_ptr += 16;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
}
|
|
78
|
+
// if (v128.any_true(escape_indices)) {
|
|
90
79
|
|
|
91
|
-
|
|
92
|
-
|
|
80
|
+
// }
|
|
81
|
+
// dst_ptr += 16;
|
|
82
|
+
// src_ptr += 16;
|
|
83
|
+
// } else {
|
|
84
|
+
// v128.store(dst_ptr, currentBlock);
|
|
85
|
+
// src_ptr += 16;
|
|
86
|
+
// dst_ptr += 16;
|
|
87
|
+
// }
|
|
88
|
+
// }
|
|
89
|
+
// }
|
|
93
90
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
91
|
+
|
|
92
|
+
// const back_slash_reg = i16x8.splat(92); // "\"
|
|
93
|
+
// const quote_reg = i16x8.splat(34); // "\""
|
|
94
|
+
|
|
95
|
+
// // @ts-ignore: Decorator
|
|
96
|
+
// @inline export function serialize_simd_v2(src: string, dst: usize): void {
|
|
97
|
+
// let src_ptr = changetype<usize>(src);
|
|
98
|
+
// let dst_ptr = changetype<usize>(dst);
|
|
99
|
+
|
|
100
|
+
// let i = 0;
|
|
101
|
+
// const len = src.length;
|
|
102
|
+
|
|
103
|
+
// while (i < len) {
|
|
104
|
+
// const block = v128.load16x4_u(src_ptr);
|
|
105
|
+
// console.log("block: " + prt(block));
|
|
106
|
+
// const backslash_mask = i16x8.eq(block, back_slash_reg);
|
|
107
|
+
// const quote_mask = i16x8.eq(block, quote_reg);
|
|
108
|
+
// const is_quote_or_backslash = v128.or(quote_mask, backslash_mask);
|
|
109
|
+
// console.log("mask: " + prt10(is_quote_or_backslash))
|
|
109
110
|
|
|
110
111
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
}
|
|
112
|
+
// // store<v128>(dst_ptr, expanded);
|
|
113
|
+
// src_ptr += 8;
|
|
114
|
+
// dst_ptr += 16;
|
|
115
|
+
// i += 8;
|
|
116
|
+
// }
|
|
117
|
+
// }
|
|
117
118
|
|
|
118
|
-
function prt(obj: v128): string {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
}
|
|
119
|
+
// function prt(obj: v128): string {
|
|
120
|
+
// let out = "";
|
|
121
|
+
// out += i16x8.extract_lane_u(obj, 0).toString() + " ";
|
|
122
|
+
// out += i16x8.extract_lane_u(obj, 1).toString() + " ";
|
|
123
|
+
// out += i16x8.extract_lane_u(obj, 2).toString() + " ";
|
|
124
|
+
// out += i16x8.extract_lane_u(obj, 3).toString() + " ";
|
|
125
|
+
// out += i16x8.extract_lane_u(obj, 4).toString() + " ";
|
|
126
|
+
// out += i16x8.extract_lane_u(obj, 5).toString() + " ";
|
|
127
|
+
// out += i16x8.extract_lane_u(obj, 6).toString() + " ";
|
|
128
|
+
// out += i16x8.extract_lane_u(obj, 7).toString();
|
|
129
|
+
// return out;
|
|
130
|
+
// }
|
|
130
131
|
|
|
131
|
-
function prt10(obj: v128): string {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
}
|
|
132
|
+
// function prt10(obj: v128): string {
|
|
133
|
+
// let out = "";
|
|
134
|
+
// out += (i16x8.extract_lane_u(obj, 0) ? "1" : "0") + " ";
|
|
135
|
+
// out += (i16x8.extract_lane_u(obj, 1) ? "1" : "0") + " ";
|
|
136
|
+
// out += (i16x8.extract_lane_u(obj, 2) ? "1" : "0") + " ";
|
|
137
|
+
// out += (i16x8.extract_lane_u(obj, 3) ? "1" : "0") + " ";
|
|
138
|
+
// out += (i16x8.extract_lane_u(obj, 4) ? "1" : "0") + " ";
|
|
139
|
+
// out += (i16x8.extract_lane_u(obj, 5) ? "1" : "0") + " ";
|
|
140
|
+
// out += (i16x8.extract_lane_u(obj, 6) ? "1" : "0") + " ";
|
|
141
|
+
// out += i16x8.extract_lane_u(obj, 7) ? "1" : "0";
|
|
142
|
+
// return out;
|
|
143
|
+
// }
|
|
143
144
|
|
|
144
|
-
function vis(src_ptr: usize, mask: i32): void {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
}
|
|
145
|
+
// function vis(src_ptr: usize, mask: i32): void {
|
|
146
|
+
// let chars = "";
|
|
147
|
+
// let bits = "";
|
|
148
|
+
// for (let i = 0; i < 8; i++) {
|
|
149
|
+
// const char = load<u16>(src_ptr + (i << 1));
|
|
150
|
+
// const bit = (mask >> i) & 1;
|
|
151
|
+
// chars += String.fromCharCode(char) + " ";
|
|
152
|
+
// bits += bit.toString() + " ";
|
|
153
|
+
// }
|
|
154
|
+
// console.log(chars);
|
|
155
|
+
// console.log(bits);
|
|
156
|
+
// }
|
|
156
157
|
|
|
157
158
|
// @ts-ignore: Decorator
|
|
158
159
|
@inline export function serializeString(data: string): string {
|
|
159
|
-
if (!needsEscaping(data)) {
|
|
160
|
-
|
|
161
|
-
}
|
|
160
|
+
// if (!needsEscaping(data)) {
|
|
161
|
+
// return "\"" + data + "\"";
|
|
162
|
+
// }
|
|
162
163
|
|
|
163
164
|
if (data.length === 0) {
|
|
164
165
|
return "\"\"";
|
|
@@ -217,80 +218,81 @@ function vis(src_ptr: usize, mask: i32): void {
|
|
|
217
218
|
result.writeCodePoint(34);
|
|
218
219
|
return result.toString();
|
|
219
220
|
}
|
|
220
|
-
// @ts-ignore: Decorator valid here
|
|
221
|
-
@inline export function serializeString_BS(data: string): void {
|
|
222
|
-
const len = data.length << 1;
|
|
223
|
-
if (len === 0) {
|
|
224
|
-
bs.write_32(2228258); /* "" */
|
|
225
|
-
return;
|
|
226
|
-
}
|
|
227
221
|
|
|
228
|
-
|
|
222
|
+
// // @ts-ignore: Decorator valid here
|
|
223
|
+
// @inline export function serializeString_BS(data: string): void {
|
|
224
|
+
// const len = data.length << 1;
|
|
225
|
+
// if (len === 0) {
|
|
226
|
+
// bs.write_32(2228258); /* "" */
|
|
227
|
+
// return;
|
|
228
|
+
// }
|
|
229
229
|
|
|
230
|
+
// bs.write_16(QUOTE);
|
|
230
231
|
|
|
231
|
-
let last: i32 = 0;
|
|
232
|
-
for (let i = 0; i < len; i += 2) {
|
|
233
|
-
const char = load<u16>(changetype<usize>(data) + i);
|
|
234
|
-
if (char < 35) {
|
|
235
|
-
if (char === QUOTE) {
|
|
236
|
-
bs.write_s_se(<string>data, last, i);
|
|
237
|
-
bs.write_16(BACK_SLASH);
|
|
238
|
-
last = i;
|
|
239
|
-
continue;
|
|
240
|
-
} else if (char < 32) {
|
|
241
|
-
if (char < 16) {
|
|
242
|
-
bs.write_s_se(<string>data, last, i);
|
|
243
|
-
last = i + 2;
|
|
244
|
-
switch (char) {
|
|
245
|
-
case BACKSPACE: {
|
|
246
|
-
bs.write_32(6422620);
|
|
247
|
-
continue;
|
|
248
|
-
}
|
|
249
|
-
case TAB: {
|
|
250
|
-
bs.write_32(7602268);
|
|
251
|
-
continue;
|
|
252
|
-
}
|
|
253
|
-
case NEW_LINE: {
|
|
254
|
-
bs.write_32(7209052);
|
|
255
|
-
continue;
|
|
256
|
-
}
|
|
257
|
-
case FORM_FEED: {
|
|
258
|
-
bs.write_32(6684764);
|
|
259
|
-
continue;
|
|
260
|
-
}
|
|
261
|
-
case CARRIAGE_RETURN: {
|
|
262
|
-
bs.write_32(7471196);
|
|
263
|
-
continue;
|
|
264
|
-
}
|
|
265
|
-
default: {
|
|
266
|
-
// all chars 0-31 must be encoded as a four digit unicode escape sequence
|
|
267
|
-
// \u0000 to \u000f handled here
|
|
268
|
-
bs.write_64(13511005048209500) /* \\u00 */
|
|
269
|
-
bs.write_32((_intTo16(char) << 16) | 48); /* 0_ */
|
|
270
|
-
continue;
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
} else {
|
|
274
|
-
bs.write_s_se(<string>data, last, i);
|
|
275
|
-
last = i + 2;
|
|
276
|
-
// all chars 0-31 must be encoded as a four digit unicode escape sequence
|
|
277
|
-
// \u0010 to \u001f handled here
|
|
278
|
-
bs.write_64(13511005048209500) /* \\u00 */
|
|
279
|
-
bs.write_32((intTo16(char) << 16) | 48); /* 0_ */
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
} else if (char === BACK_SLASH) {
|
|
283
|
-
bs.write_s_se(<string>data, last, i);
|
|
284
|
-
bs.write_16(BACK_SLASH);
|
|
285
|
-
last = i;
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
232
|
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
233
|
+
// let last: i32 = 0;
|
|
234
|
+
// for (let i = 0; i < len; i += 2) {
|
|
235
|
+
// const char = load<u16>(changetype<usize>(data) + i);
|
|
236
|
+
// if (char < 35) {
|
|
237
|
+
// if (char === QUOTE) {
|
|
238
|
+
// bs.write_s_se(<string>data, last, i);
|
|
239
|
+
// bs.write_16(BACK_SLASH);
|
|
240
|
+
// last = i;
|
|
241
|
+
// continue;
|
|
242
|
+
// } else if (char < 32) {
|
|
243
|
+
// if (char < 16) {
|
|
244
|
+
// bs.write_s_se(<string>data, last, i);
|
|
245
|
+
// last = i + 2;
|
|
246
|
+
// switch (char) {
|
|
247
|
+
// case BACKSPACE: {
|
|
248
|
+
// bs.write_32(6422620);
|
|
249
|
+
// continue;
|
|
250
|
+
// }
|
|
251
|
+
// case TAB: {
|
|
252
|
+
// bs.write_32(7602268);
|
|
253
|
+
// continue;
|
|
254
|
+
// }
|
|
255
|
+
// case NEW_LINE: {
|
|
256
|
+
// bs.write_32(7209052);
|
|
257
|
+
// continue;
|
|
258
|
+
// }
|
|
259
|
+
// case FORM_FEED: {
|
|
260
|
+
// bs.write_32(6684764);
|
|
261
|
+
// continue;
|
|
262
|
+
// }
|
|
263
|
+
// case CARRIAGE_RETURN: {
|
|
264
|
+
// bs.write_32(7471196);
|
|
265
|
+
// continue;
|
|
266
|
+
// }
|
|
267
|
+
// default: {
|
|
268
|
+
// // all chars 0-31 must be encoded as a four digit unicode escape sequence
|
|
269
|
+
// // \u0000 to \u000f handled here
|
|
270
|
+
// bs.write_64(13511005048209500) /* \\u00 */
|
|
271
|
+
// bs.write_32((_intTo16(char) << 16) | 48); /* 0_ */
|
|
272
|
+
// continue;
|
|
273
|
+
// }
|
|
274
|
+
// }
|
|
275
|
+
// } else {
|
|
276
|
+
// bs.write_s_se(<string>data, last, i);
|
|
277
|
+
// last = i + 2;
|
|
278
|
+
// // all chars 0-31 must be encoded as a four digit unicode escape sequence
|
|
279
|
+
// // \u0010 to \u001f handled here
|
|
280
|
+
// bs.write_64(13511005048209500) /* \\u00 */
|
|
281
|
+
// bs.write_32((intTo16(char) << 16) | 48); /* 0_ */
|
|
282
|
+
// }
|
|
283
|
+
// }
|
|
284
|
+
// } else if (char === BACK_SLASH) {
|
|
285
|
+
// bs.write_s_se(<string>data, last, i);
|
|
286
|
+
// bs.write_16(BACK_SLASH);
|
|
287
|
+
// last = i;
|
|
288
|
+
// }
|
|
289
|
+
// }
|
|
290
|
+
|
|
291
|
+
// if (last === 0) {
|
|
292
|
+
// bs.write_s(data);
|
|
293
|
+
// bs.write_16(QUOTE)
|
|
294
|
+
// } else {
|
|
295
|
+
// bs.write_s_se(<string>data, last, changetype<OBJECT>(changetype<usize>(data) - TOTAL_OVERHEAD).rtSize);
|
|
296
|
+
// bs.write_16(QUOTE);
|
|
297
|
+
// }
|
|
298
|
+
// }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "json-as",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.23",
|
|
4
4
|
"description": "The only JSON library you'll need for AssemblyScript. SIMD enabled",
|
|
5
5
|
"types": "assembly/index.ts",
|
|
6
6
|
"author": "Jairus Tanaka",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"test": "ast test && rm -rf ./build/",
|
|
20
20
|
"pretest": "rm -rf ./build/ && ast build",
|
|
21
21
|
"bench": "astral --enable simd --runtime stub",
|
|
22
|
-
"build:test": "rm -rf ./build/ && asc assembly/test.ts --transform ./transform -o ./build/test.wasm
|
|
22
|
+
"build:test": "rm -rf ./build/ && asc assembly/test.ts --transform ./transform -o ./build/test.wasm",
|
|
23
23
|
"build:transform": "tsc -p ./transform",
|
|
24
24
|
"test:wasmtime": "wasmtime ./build/test.wasm",
|
|
25
25
|
"test:wavm": "wavm run ./build/test.wasm",
|