toilscript 0.1.7 → 0.1.9
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/dist/cli.generated.d.ts +40 -2
- package/dist/cli.js +172 -5
- package/dist/cli.js.map +2 -2
- package/dist/importmap.json +2 -2
- package/dist/toilscript.generated.d.ts +40 -2
- package/dist/toilscript.js +110 -51
- package/dist/toilscript.js.map +4 -4
- package/dist/web.js +3 -3
- package/package.json +3 -2
- package/std/assembly/data.ts +167 -0
- package/std/assembly/json.ts +1 -1
package/dist/web.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
var ASSEMBLYSCRIPT_VERSION = "0.1.
|
|
1
|
+
var ASSEMBLYSCRIPT_VERSION = "0.1.9";
|
|
2
2
|
var ASSEMBLYSCRIPT_IMPORTMAP = {
|
|
3
3
|
"imports": {
|
|
4
|
-
"toilscript": "https://cdn.jsdelivr.net/npm/toilscript@0.1.
|
|
5
|
-
"toilscript/cli": "https://cdn.jsdelivr.net/npm/toilscript@0.1.
|
|
4
|
+
"toilscript": "https://cdn.jsdelivr.net/npm/toilscript@0.1.9/dist/toilscript.js",
|
|
5
|
+
"toilscript/cli": "https://cdn.jsdelivr.net/npm/toilscript@0.1.9/dist/cli.js",
|
|
6
6
|
"binaryen": "https://cdn.jsdelivr.net/npm/binaryen@129.0.0-nightly.20260428/index.js",
|
|
7
7
|
"long": "https://cdn.jsdelivr.net/npm/long@5.3.2/index.js"
|
|
8
8
|
}
|
package/package.json
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"toilscript",
|
|
9
9
|
"wasm"
|
|
10
10
|
],
|
|
11
|
-
"version": "0.1.
|
|
11
|
+
"version": "0.1.9",
|
|
12
12
|
"author": "Daniel Wirtz <dcode+assemblyscript@dcode.io>",
|
|
13
13
|
"license": "Apache-2.0",
|
|
14
14
|
"homepage": "https://github.com/dacely-cloud/toilscript",
|
|
@@ -80,7 +80,7 @@
|
|
|
80
80
|
"prepublishOnly": "node scripts/build",
|
|
81
81
|
"watch": "node scripts/build --watch",
|
|
82
82
|
"coverage": "npx c8 -- npm test",
|
|
83
|
-
"test": "npm run test:parser && npm run test:compiler -- --parallel && npm run test:browser && npm run test:toilconfig && npm run test:transform && npm run test:cli && npm run test:json",
|
|
83
|
+
"test": "npm run test:parser && npm run test:compiler -- --parallel && npm run test:browser && npm run test:toilconfig && npm run test:transform && npm run test:cli && npm run test:json && npm run test:data",
|
|
84
84
|
"test:parser": "node --enable-source-maps tests/parser",
|
|
85
85
|
"test:compiler": "node --enable-source-maps --no-warnings tests/compiler",
|
|
86
86
|
"test:browser": "node --enable-source-maps tests/browser",
|
|
@@ -90,6 +90,7 @@
|
|
|
90
90
|
"test:transform:cjs": "node bin/toilscript tests/compiler/empty --transform ./tests/transform/cjs/index.js --noEmit && node bin/toilscript tests/compiler/empty --transform ./tests/transform/cjs/simple.js --noEmit",
|
|
91
91
|
"test:cli": "node tests/cli/options.js",
|
|
92
92
|
"test:json": "node tests/json/run.mjs",
|
|
93
|
+
"test:data": "node tests/data/run.mjs",
|
|
93
94
|
"asbuild": "npm run asbuild:debug && npm run asbuild:release",
|
|
94
95
|
"asbuild:debug": "node bin/toilscript --config src/toilconfig.json --target debug",
|
|
95
96
|
"asbuild:release": "node bin/toilscript --config src/toilconfig.json --target release",
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Binary buffers for the `@data` tagged codec.
|
|
3
|
+
*
|
|
4
|
+
* `DataWriter` is a growable little-endian byte buffer written through direct
|
|
5
|
+
* linear-memory stores (wasm `store`/`load` are little-endian, so scalar writes
|
|
6
|
+
* are near native, no `DataView`). `DataReader` reads them back, tracking an
|
|
7
|
+
* `ok` flag so malformed input yields safe defaults instead of a trap.
|
|
8
|
+
*
|
|
9
|
+
* Both are zero-import globals (this is a top-level library entry), so the
|
|
10
|
+
* compiler-generated `encode`/`decode` reference them with no imports. The
|
|
11
|
+
* 128/256-bit integer types are the native std ones.
|
|
12
|
+
*
|
|
13
|
+
* Wire layout: fixed-width little-endian scalars; `bool` is one byte; strings
|
|
14
|
+
* and raw byte blobs are a `u32` byte-length prefix followed by the bytes;
|
|
15
|
+
* `u128`/`i128` are two 64-bit limbs (lo then hi), `u256`/`i256` are four.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
export class DataWriter {
|
|
19
|
+
private buf: Uint8Array;
|
|
20
|
+
private off: i32 = 0;
|
|
21
|
+
|
|
22
|
+
constructor(capacity: i32 = 64) {
|
|
23
|
+
this.buf = new Uint8Array(capacity > 0 ? capacity : 1);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** Reserve `extra` bytes, growing if needed, and return the write pointer. */
|
|
27
|
+
private reserve(extra: i32): usize {
|
|
28
|
+
const need = this.off + extra;
|
|
29
|
+
const cap = this.buf.length;
|
|
30
|
+
if (need > cap) {
|
|
31
|
+
let n = cap;
|
|
32
|
+
while (n < need) n = n << 1;
|
|
33
|
+
const bigger = new Uint8Array(n);
|
|
34
|
+
memory.copy(bigger.dataStart, this.buf.dataStart, <usize>this.off);
|
|
35
|
+
this.buf = bigger;
|
|
36
|
+
}
|
|
37
|
+
const ptr = this.buf.dataStart + <usize>this.off;
|
|
38
|
+
this.off += extra;
|
|
39
|
+
return ptr;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
writeU8(value: u8): DataWriter { store<u8>(this.reserve(1), value); return this; }
|
|
43
|
+
writeU16(value: u16): DataWriter { store<u16>(this.reserve(2), value); return this; }
|
|
44
|
+
writeU32(value: u32): DataWriter { store<u32>(this.reserve(4), value); return this; }
|
|
45
|
+
writeU64(value: u64): DataWriter { store<u64>(this.reserve(8), value); return this; }
|
|
46
|
+
writeI8(value: i8): DataWriter { store<i8>(this.reserve(1), value); return this; }
|
|
47
|
+
writeI16(value: i16): DataWriter { store<i16>(this.reserve(2), value); return this; }
|
|
48
|
+
writeI32(value: i32): DataWriter { store<i32>(this.reserve(4), value); return this; }
|
|
49
|
+
writeI64(value: i64): DataWriter { store<i64>(this.reserve(8), value); return this; }
|
|
50
|
+
writeF32(value: f32): DataWriter { store<f32>(this.reserve(4), value); return this; }
|
|
51
|
+
writeF64(value: f64): DataWriter { store<f64>(this.reserve(8), value); return this; }
|
|
52
|
+
writeBool(value: bool): DataWriter { return this.writeU8(value ? 1 : 0); }
|
|
53
|
+
|
|
54
|
+
writeBytes(bytes: Uint8Array): DataWriter {
|
|
55
|
+
const len = bytes.length;
|
|
56
|
+
this.writeU32(<u32>len);
|
|
57
|
+
if (len > 0) memory.copy(this.reserve(len), bytes.dataStart, <usize>len);
|
|
58
|
+
return this;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
writeString(value: string): DataWriter {
|
|
62
|
+
const utf8 = String.UTF8.encode(value);
|
|
63
|
+
const len = <i32>utf8.byteLength;
|
|
64
|
+
this.writeU32(<u32>len);
|
|
65
|
+
if (len > 0) memory.copy(this.reserve(len), changetype<usize>(utf8), <usize>len);
|
|
66
|
+
return this;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
writeU128(value: u128): DataWriter { return this.writeU64(value.lo).writeU64(value.hi); }
|
|
70
|
+
writeI128(value: i128): DataWriter { return this.writeU64(value.lo).writeI64(value.hi); }
|
|
71
|
+
|
|
72
|
+
writeU256(value: u256): DataWriter {
|
|
73
|
+
return this.writeU64(value.lo1).writeU64(value.lo2).writeU64(value.hi1).writeU64(value.hi2);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
writeI256(value: i256): DataWriter {
|
|
77
|
+
return this.writeI64(value.lo1).writeI64(value.lo2).writeI64(value.hi1).writeI64(value.hi2);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** Number of bytes written so far. */
|
|
81
|
+
length(): i32 { return this.off; }
|
|
82
|
+
|
|
83
|
+
/** A copy of exactly the bytes written. */
|
|
84
|
+
toBytes(): Uint8Array {
|
|
85
|
+
const out = new Uint8Array(this.off);
|
|
86
|
+
if (this.off > 0) memory.copy(out.dataStart, this.buf.dataStart, <usize>this.off);
|
|
87
|
+
return out;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export class DataReader {
|
|
92
|
+
private buf: Uint8Array;
|
|
93
|
+
private off: i32 = 0;
|
|
94
|
+
/** Cleared to false if any read ran past the end of the buffer. */
|
|
95
|
+
ok: bool = true;
|
|
96
|
+
|
|
97
|
+
constructor(bytes: Uint8Array) {
|
|
98
|
+
this.buf = bytes;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
private has(n: i32): bool {
|
|
102
|
+
if (n < 0 || this.off + n > this.buf.length) {
|
|
103
|
+
this.ok = false;
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
return true;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
private at(n: i32): usize {
|
|
110
|
+
const ptr = this.buf.dataStart + <usize>this.off;
|
|
111
|
+
this.off += n;
|
|
112
|
+
return ptr;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
readU8(): u8 { return this.has(1) ? load<u8>(this.at(1)) : 0; }
|
|
116
|
+
readU16(): u16 { return this.has(2) ? load<u16>(this.at(2)) : 0; }
|
|
117
|
+
readU32(): u32 { return this.has(4) ? load<u32>(this.at(4)) : 0; }
|
|
118
|
+
readU64(): u64 { return this.has(8) ? load<u64>(this.at(8)) : 0; }
|
|
119
|
+
readI8(): i8 { return this.has(1) ? load<i8>(this.at(1)) : 0; }
|
|
120
|
+
readI16(): i16 { return this.has(2) ? load<i16>(this.at(2)) : 0; }
|
|
121
|
+
readI32(): i32 { return this.has(4) ? load<i32>(this.at(4)) : 0; }
|
|
122
|
+
readI64(): i64 { return this.has(8) ? load<i64>(this.at(8)) : 0; }
|
|
123
|
+
readF32(): f32 { return this.has(4) ? load<f32>(this.at(4)) : 0; }
|
|
124
|
+
readF64(): f64 { return this.has(8) ? load<f64>(this.at(8)) : 0; }
|
|
125
|
+
readBool(): bool { return this.readU8() != 0; }
|
|
126
|
+
|
|
127
|
+
readBytes(): Uint8Array {
|
|
128
|
+
const len = <i32>this.readU32();
|
|
129
|
+
if (!this.has(len)) return new Uint8Array(0);
|
|
130
|
+
const out = new Uint8Array(len);
|
|
131
|
+
if (len > 0) memory.copy(out.dataStart, this.at(len), <usize>len);
|
|
132
|
+
return out;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
readString(): string {
|
|
136
|
+
const len = <i32>this.readU32();
|
|
137
|
+
if (!this.has(len)) return "";
|
|
138
|
+
return String.UTF8.decodeUnsafe(this.at(len), <usize>len);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
readU128(): u128 {
|
|
142
|
+
const lo = this.readU64();
|
|
143
|
+
return new u128(lo, this.readU64());
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
readI128(): i128 {
|
|
147
|
+
const lo = this.readU64();
|
|
148
|
+
return new i128(lo, this.readI64());
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
readU256(): u256 {
|
|
152
|
+
const lo1 = this.readU64();
|
|
153
|
+
const lo2 = this.readU64();
|
|
154
|
+
const hi1 = this.readU64();
|
|
155
|
+
return new u256(lo1, lo2, hi1, this.readU64());
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
readI256(): i256 {
|
|
159
|
+
const lo1 = this.readI64();
|
|
160
|
+
const lo2 = this.readI64();
|
|
161
|
+
const hi1 = this.readI64();
|
|
162
|
+
return new i256(lo1, lo2, hi1, this.readI64());
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/** Bytes left to read. */
|
|
166
|
+
remaining(): i32 { return this.buf.length - this.off; }
|
|
167
|
+
}
|
package/std/assembly/json.ts
CHANGED
|
@@ -217,7 +217,7 @@ export class JSON {
|
|
|
217
217
|
}
|
|
218
218
|
}
|
|
219
219
|
|
|
220
|
-
// ---- typed serializer:
|
|
220
|
+
// ---- typed serializer: a typed value to JSON text, by compile-time type ----
|
|
221
221
|
static stringify<T>(value: T): string {
|
|
222
222
|
if (isBoolean<T>()) {
|
|
223
223
|
return value ? "true" : "false";
|