mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-06-13 15:01:28 +00:00
Update dist files; Unify some examples
This commit is contained in:
@ -9,7 +9,7 @@ Instructions
|
||||
To build [assembly/pson.ts](./assembly/pson.ts) to an untouched and an optimized `.wasm` including their respective `.wat` representations, run:
|
||||
|
||||
```
|
||||
$> npm run build
|
||||
$> npm run asbuild
|
||||
```
|
||||
|
||||
Afterwards, to run the included [test](./tests/index.js):
|
||||
|
@ -40,10 +40,8 @@ var offset: usize = 0;
|
||||
|
||||
export function decode(length: usize): void {
|
||||
offset = 0;
|
||||
while (offset < length) {
|
||||
decodeValue();
|
||||
}
|
||||
assert(offset == length);
|
||||
while (offset < length) decodeValue();
|
||||
if (offset != length) unreachable();
|
||||
}
|
||||
|
||||
function decodeValue(): void {
|
||||
@ -51,96 +49,94 @@ function decodeValue(): void {
|
||||
var size: u32;
|
||||
var long: u64;
|
||||
switch (token) {
|
||||
|
||||
case Token.NULL:
|
||||
case Token.NULL: {
|
||||
pson.onNull();
|
||||
break;
|
||||
|
||||
case Token.TRUE:
|
||||
}
|
||||
case Token.TRUE: {
|
||||
pson.onTrue();
|
||||
break;
|
||||
|
||||
case Token.FALSE:
|
||||
}
|
||||
case Token.FALSE: {
|
||||
pson.onFalse();
|
||||
break;
|
||||
|
||||
case Token.EOBJECT:
|
||||
}
|
||||
case Token.EOBJECT: {
|
||||
pson.onEObject();
|
||||
break;
|
||||
|
||||
case Token.EARRAY:
|
||||
}
|
||||
case Token.EARRAY: {
|
||||
pson.onEArray();
|
||||
break;
|
||||
|
||||
case Token.ESTRING:
|
||||
}
|
||||
case Token.ESTRING: {
|
||||
pson.onEString();
|
||||
break;
|
||||
|
||||
case Token.OBJECT:
|
||||
}
|
||||
case Token.OBJECT: {
|
||||
pson.onObject(size = readVarint32());
|
||||
while (size--) {
|
||||
decodeValue();
|
||||
decodeValue();
|
||||
}
|
||||
break;
|
||||
|
||||
case Token.ARRAY:
|
||||
}
|
||||
case Token.ARRAY: {
|
||||
pson.onArray(size = readVarint32());
|
||||
while (size--) {
|
||||
decodeValue();
|
||||
}
|
||||
while (size--) decodeValue();
|
||||
break;
|
||||
|
||||
case Token.INTEGER:
|
||||
}
|
||||
case Token.INTEGER: {
|
||||
pson.onInteger(((size = readVarint32()) >> 1) ^ -(size & 1));
|
||||
break;
|
||||
|
||||
case Token.LONG:
|
||||
}
|
||||
case Token.LONG: {
|
||||
long = ((long = readVarint64()) >> 1) ^ -(long & 1);
|
||||
pson.onLong(<i32>long, <i32>(long >>> 32));
|
||||
break;
|
||||
|
||||
case Token.FLOAT:
|
||||
}
|
||||
case Token.FLOAT: {
|
||||
pson.onFloat(load<f32>(offset));
|
||||
offset += 4;
|
||||
break;
|
||||
|
||||
case Token.DOUBLE:
|
||||
}
|
||||
case Token.DOUBLE: {
|
||||
pson.onDouble(load<f64>(offset));
|
||||
offset += 8;
|
||||
break;
|
||||
|
||||
case Token.STRING:
|
||||
}
|
||||
case Token.STRING: {
|
||||
size = readVarint32();
|
||||
pson.onString(offset, size);
|
||||
offset += size;
|
||||
break;
|
||||
|
||||
}
|
||||
case Token.STRING_ADD:
|
||||
case Token.STRING_GET:
|
||||
case Token.STRING_GET: {
|
||||
// could be implemented via imports as well, but isn't necessary for this example
|
||||
throw new Error("not implemented");
|
||||
|
||||
case Token.BINARY:
|
||||
unreachable();
|
||||
break;
|
||||
}
|
||||
case Token.BINARY: {
|
||||
size = readVarint32();
|
||||
pson.onBinary(offset, size);
|
||||
offset += size;
|
||||
break;
|
||||
|
||||
default: // small integer?
|
||||
if (token > <u32>Token.MAX) {
|
||||
throw new Error("unexpected token");
|
||||
}
|
||||
}
|
||||
default: { // small integer?
|
||||
if (token > <u32>Token.MAX) unreachable();
|
||||
pson.onInteger((token >> 1) ^ -(token & 1));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function readVarint32(): u32 {
|
||||
var value: u32 = 0;
|
||||
var shift: u32 = 0;
|
||||
var b: u8;
|
||||
do {
|
||||
var b = load<u8>(offset++);
|
||||
b = load<u8>(offset++);
|
||||
value |= <u32>(b & 0x7f) << (7 * shift++);
|
||||
} while (b & 0x80);
|
||||
return value;
|
||||
@ -149,8 +145,9 @@ function readVarint32(): u32 {
|
||||
function readVarint64(): u64 {
|
||||
var value: u64 = 0;
|
||||
var shift: u64 = 0;
|
||||
var b: u8;
|
||||
do {
|
||||
var b = load<u8>(offset++);
|
||||
b = load<u8>(offset++);
|
||||
value |= <u64>(b & 0x7f) << (7 * shift++);
|
||||
} while (b & 0x80);
|
||||
return value;
|
||||
|
3
examples/pson/build/.gitignore
vendored
Normal file
3
examples/pson/build/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
*.wasm
|
||||
*.wasm.map
|
||||
*.asm.js
|
@ -1,12 +1,11 @@
|
||||
(module
|
||||
(type $v (func))
|
||||
(type $i (func (result i32)))
|
||||
(type $iv (func (param i32)))
|
||||
(type $i (func (result i32)))
|
||||
(type $v (func))
|
||||
(type $I (func (result i64)))
|
||||
(type $iiv (func (param i32 i32)))
|
||||
(type $fv (func (param f32)))
|
||||
(type $Fv (func (param f64)))
|
||||
(type $iiiiv (func (param i32 i32 i32 i32)))
|
||||
(import "pson" "onNull" (func $assembly/pson/pson.onNull))
|
||||
(import "pson" "onTrue" (func $assembly/pson/pson.onTrue))
|
||||
(import "pson" "onFalse" (func $assembly/pson/pson.onFalse))
|
||||
@ -21,22 +20,20 @@
|
||||
(import "pson" "onDouble" (func $assembly/pson/pson.onDouble (param f64)))
|
||||
(import "pson" "onString" (func $assembly/pson/pson.onString (param i32 i32)))
|
||||
(import "pson" "onBinary" (func $assembly/pson/pson.onBinary (param i32 i32)))
|
||||
(import "env" "abort" (func $abort (param i32 i32 i32 i32)))
|
||||
(global $assembly/pson/offset (mut i32) (i32.const 0))
|
||||
(memory $0 1)
|
||||
(data (i32.const 4) "\10\00\00\00a\00s\00s\00e\00m\00b\00l\00y\00/\00p\00s\00o\00n\00.\00t\00s")
|
||||
(export "decode" (func $assembly/pson/decode))
|
||||
(export "memory" (memory $0))
|
||||
(func $assembly/pson/readVarint32 (; 15 ;) (type $i) (result i32)
|
||||
(func $assembly/pson/readVarint32 (; 14 ;) (type $i) (result i32)
|
||||
(local $0 i32)
|
||||
(local $1 i32)
|
||||
(local $2 i32)
|
||||
(loop $continue|0
|
||||
;;@ assembly/pson.ts:144:4
|
||||
;;@ assembly/pson.ts:140:4
|
||||
(set_local $0
|
||||
(i32.or
|
||||
(get_local $0)
|
||||
;;@ assembly/pson.ts:143:21
|
||||
;;@ assembly/pson.ts:139:17
|
||||
(block (result i32)
|
||||
(set_global $assembly/pson/offset
|
||||
(i32.add
|
||||
@ -46,20 +43,20 @@
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
;;@ assembly/pson.ts:144:13
|
||||
;;@ assembly/pson.ts:140:13
|
||||
(i32.shl
|
||||
(i32.and
|
||||
;;@ assembly/pson.ts:143:4
|
||||
;;@ assembly/pson.ts:139:4
|
||||
(tee_local $2
|
||||
;;@ assembly/pson.ts:143:12
|
||||
;;@ assembly/pson.ts:139:8
|
||||
(i32.load8_u
|
||||
(get_local $0)
|
||||
)
|
||||
)
|
||||
;;@ assembly/pson.ts:144:23
|
||||
;;@ assembly/pson.ts:140:23
|
||||
(i32.const 127)
|
||||
)
|
||||
;;@ assembly/pson.ts:144:37
|
||||
;;@ assembly/pson.ts:140:37
|
||||
(block (result i32)
|
||||
(set_local $1
|
||||
(i32.add
|
||||
@ -69,10 +66,10 @@
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
;;@ assembly/pson.ts:144:32
|
||||
;;@ assembly/pson.ts:140:32
|
||||
(i32.mul
|
||||
(get_local $0)
|
||||
;;@ assembly/pson.ts:144:33
|
||||
;;@ assembly/pson.ts:140:33
|
||||
(i32.const 7)
|
||||
)
|
||||
)
|
||||
@ -81,27 +78,27 @@
|
||||
)
|
||||
)
|
||||
(br_if $continue|0
|
||||
;;@ assembly/pson.ts:141:11
|
||||
(i32.and
|
||||
;;@ assembly/pson.ts:145:11
|
||||
(get_local $2)
|
||||
;;@ assembly/pson.ts:145:15
|
||||
;;@ assembly/pson.ts:141:15
|
||||
(i32.const 128)
|
||||
)
|
||||
)
|
||||
)
|
||||
;;@ assembly/pson.ts:146:9
|
||||
;;@ assembly/pson.ts:142:9
|
||||
(get_local $0)
|
||||
)
|
||||
(func $assembly/pson/readVarint64 (; 16 ;) (type $I) (result i64)
|
||||
(func $assembly/pson/readVarint64 (; 15 ;) (type $I) (result i64)
|
||||
(local $0 i64)
|
||||
(local $1 i32)
|
||||
(local $2 i64)
|
||||
(loop $continue|0
|
||||
;;@ assembly/pson.ts:154:4
|
||||
;;@ assembly/pson.ts:151:4
|
||||
(set_local $0
|
||||
(i64.or
|
||||
(get_local $0)
|
||||
;;@ assembly/pson.ts:153:21
|
||||
;;@ assembly/pson.ts:150:17
|
||||
(block (result i64)
|
||||
(set_global $assembly/pson/offset
|
||||
(i32.add
|
||||
@ -114,31 +111,32 @@
|
||||
(set_local $2
|
||||
(i64.add
|
||||
(tee_local $0
|
||||
;;@ assembly/pson.ts:154:37
|
||||
;;@ assembly/pson.ts:151:37
|
||||
(get_local $2)
|
||||
)
|
||||
(i64.const 1)
|
||||
)
|
||||
)
|
||||
;;@ assembly/pson.ts:154:13
|
||||
;;@ assembly/pson.ts:151:13
|
||||
(i64.shl
|
||||
(i64.extend_u/i32
|
||||
;;@ assembly/pson.ts:151:19
|
||||
(i32.and
|
||||
;;@ assembly/pson.ts:153:4
|
||||
;;@ assembly/pson.ts:150:4
|
||||
(tee_local $1
|
||||
;;@ assembly/pson.ts:153:12
|
||||
;;@ assembly/pson.ts:150:8
|
||||
(i32.load8_u
|
||||
(get_local $1)
|
||||
)
|
||||
)
|
||||
;;@ assembly/pson.ts:154:23
|
||||
;;@ assembly/pson.ts:151:23
|
||||
(i32.const 127)
|
||||
)
|
||||
)
|
||||
;;@ assembly/pson.ts:154:32
|
||||
;;@ assembly/pson.ts:151:32
|
||||
(i64.mul
|
||||
(get_local $0)
|
||||
;;@ assembly/pson.ts:154:33
|
||||
;;@ assembly/pson.ts:151:33
|
||||
(i64.const 7)
|
||||
)
|
||||
)
|
||||
@ -146,22 +144,22 @@
|
||||
)
|
||||
)
|
||||
(br_if $continue|0
|
||||
;;@ assembly/pson.ts:152:11
|
||||
(i32.and
|
||||
;;@ assembly/pson.ts:155:11
|
||||
(get_local $1)
|
||||
;;@ assembly/pson.ts:155:15
|
||||
;;@ assembly/pson.ts:152:15
|
||||
(i32.const 128)
|
||||
)
|
||||
)
|
||||
)
|
||||
;;@ assembly/pson.ts:156:9
|
||||
;;@ assembly/pson.ts:153:9
|
||||
(get_local $0)
|
||||
)
|
||||
(func $assembly/pson/decodeValue (; 17 ;) (type $v)
|
||||
(func $assembly/pson/decodeValue (; 16 ;) (type $v)
|
||||
(local $0 i32)
|
||||
(local $1 i32)
|
||||
(local $2 i64)
|
||||
;;@ assembly/pson.ts:53:2
|
||||
;;@ assembly/pson.ts:51:2
|
||||
(block $break|0
|
||||
(block $case16|0
|
||||
(block $case15|0
|
||||
@ -183,7 +181,7 @@
|
||||
(set_global $assembly/pson/offset
|
||||
(i32.add
|
||||
(tee_local $1
|
||||
;;@ assembly/pson.ts:50:28
|
||||
;;@ assembly/pson.ts:48:28
|
||||
(get_global $assembly/pson/offset)
|
||||
)
|
||||
(i32.const 1)
|
||||
@ -192,9 +190,9 @@
|
||||
(br_table $case0|0 $case1|0 $case2|0 $case3|0 $case4|0 $case5|0 $case6|0 $case7|0 $case8|0 $case9|0 $case10|0 $case11|0 $case12|0 $tablify|0
|
||||
(i32.sub
|
||||
(tee_local $1
|
||||
;;@ assembly/pson.ts:50:2
|
||||
;;@ assembly/pson.ts:48:2
|
||||
(tee_local $0
|
||||
;;@ assembly/pson.ts:50:19
|
||||
;;@ assembly/pson.ts:48:19
|
||||
(i32.load8_u
|
||||
(get_local $1)
|
||||
)
|
||||
@ -208,12 +206,12 @@
|
||||
(i32.or
|
||||
(i32.eq
|
||||
(get_local $1)
|
||||
;;@ assembly/pson.ts:119:9
|
||||
;;@ assembly/pson.ts:114:9
|
||||
(i32.const 253)
|
||||
)
|
||||
(i32.eq
|
||||
(get_local $1)
|
||||
;;@ assembly/pson.ts:120:9
|
||||
;;@ assembly/pson.ts:115:9
|
||||
(i32.const 254)
|
||||
)
|
||||
)
|
||||
@ -221,53 +219,53 @@
|
||||
(br_if $case15|0
|
||||
(i32.eq
|
||||
(get_local $1)
|
||||
;;@ assembly/pson.ts:124:9
|
||||
;;@ assembly/pson.ts:120:9
|
||||
(i32.const 255)
|
||||
)
|
||||
)
|
||||
(br $case16|0)
|
||||
)
|
||||
;;@ assembly/pson.ts:56:11
|
||||
;;@ assembly/pson.ts:53:11
|
||||
(call $assembly/pson/pson.onNull)
|
||||
;;@ assembly/pson.ts:57:6
|
||||
;;@ assembly/pson.ts:54:6
|
||||
(br $break|0)
|
||||
)
|
||||
;;@ assembly/pson.ts:60:11
|
||||
;;@ assembly/pson.ts:57:11
|
||||
(call $assembly/pson/pson.onTrue)
|
||||
;;@ assembly/pson.ts:61:6
|
||||
;;@ assembly/pson.ts:58:6
|
||||
(br $break|0)
|
||||
)
|
||||
;;@ assembly/pson.ts:64:11
|
||||
;;@ assembly/pson.ts:61:11
|
||||
(call $assembly/pson/pson.onFalse)
|
||||
;;@ assembly/pson.ts:65:6
|
||||
;;@ assembly/pson.ts:62:6
|
||||
(br $break|0)
|
||||
)
|
||||
;;@ assembly/pson.ts:68:11
|
||||
;;@ assembly/pson.ts:65:11
|
||||
(call $assembly/pson/pson.onEObject)
|
||||
;;@ assembly/pson.ts:69:6
|
||||
;;@ assembly/pson.ts:66:6
|
||||
(br $break|0)
|
||||
)
|
||||
;;@ assembly/pson.ts:72:11
|
||||
;;@ assembly/pson.ts:69:11
|
||||
(call $assembly/pson/pson.onEArray)
|
||||
;;@ assembly/pson.ts:73:6
|
||||
;;@ assembly/pson.ts:70:6
|
||||
(br $break|0)
|
||||
)
|
||||
;;@ assembly/pson.ts:76:11
|
||||
;;@ assembly/pson.ts:73:11
|
||||
(call $assembly/pson/pson.onEString)
|
||||
;;@ assembly/pson.ts:77:6
|
||||
;;@ assembly/pson.ts:74:6
|
||||
(br $break|0)
|
||||
)
|
||||
;;@ assembly/pson.ts:80:11
|
||||
;;@ assembly/pson.ts:77:11
|
||||
(call $assembly/pson/pson.onObject
|
||||
;;@ assembly/pson.ts:80:20
|
||||
;;@ assembly/pson.ts:77:20
|
||||
(tee_local $0
|
||||
;;@ assembly/pson.ts:80:27
|
||||
;;@ assembly/pson.ts:77:27
|
||||
(call $assembly/pson/readVarint32)
|
||||
)
|
||||
)
|
||||
(loop $continue|1
|
||||
(if
|
||||
;;@ assembly/pson.ts:81:13
|
||||
;;@ assembly/pson.ts:78:13
|
||||
(block (result i32)
|
||||
(set_local $0
|
||||
(i32.sub
|
||||
@ -280,28 +278,28 @@
|
||||
(get_local $1)
|
||||
)
|
||||
(block
|
||||
;;@ assembly/pson.ts:82:8
|
||||
;;@ assembly/pson.ts:79:8
|
||||
(call $assembly/pson/decodeValue)
|
||||
;;@ assembly/pson.ts:83:8
|
||||
;;@ assembly/pson.ts:80:8
|
||||
(call $assembly/pson/decodeValue)
|
||||
(br $continue|1)
|
||||
)
|
||||
)
|
||||
)
|
||||
;;@ assembly/pson.ts:85:6
|
||||
;;@ assembly/pson.ts:82:6
|
||||
(br $break|0)
|
||||
)
|
||||
;;@ assembly/pson.ts:88:11
|
||||
;;@ assembly/pson.ts:85:11
|
||||
(call $assembly/pson/pson.onArray
|
||||
;;@ assembly/pson.ts:88:19
|
||||
;;@ assembly/pson.ts:85:19
|
||||
(tee_local $0
|
||||
;;@ assembly/pson.ts:88:26
|
||||
;;@ assembly/pson.ts:85:26
|
||||
(call $assembly/pson/readVarint32)
|
||||
)
|
||||
)
|
||||
(loop $continue|2
|
||||
(if
|
||||
;;@ assembly/pson.ts:89:13
|
||||
;;@ assembly/pson.ts:86:13
|
||||
(block (result i32)
|
||||
(set_local $0
|
||||
(i32.sub
|
||||
@ -314,204 +312,204 @@
|
||||
(get_local $1)
|
||||
)
|
||||
(block
|
||||
;;@ assembly/pson.ts:90:8
|
||||
;;@ assembly/pson.ts:86:21
|
||||
(call $assembly/pson/decodeValue)
|
||||
(br $continue|2)
|
||||
)
|
||||
)
|
||||
)
|
||||
;;@ assembly/pson.ts:92:6
|
||||
;;@ assembly/pson.ts:87:6
|
||||
(br $break|0)
|
||||
)
|
||||
;;@ assembly/pson.ts:95:11
|
||||
;;@ assembly/pson.ts:90:11
|
||||
(call $assembly/pson/pson.onInteger
|
||||
;;@ assembly/pson.ts:95:21
|
||||
;;@ assembly/pson.ts:90:21
|
||||
(i32.xor
|
||||
(i32.shr_u
|
||||
;;@ assembly/pson.ts:95:22
|
||||
;;@ assembly/pson.ts:90:22
|
||||
(tee_local $0
|
||||
;;@ assembly/pson.ts:95:30
|
||||
;;@ assembly/pson.ts:90:30
|
||||
(call $assembly/pson/readVarint32)
|
||||
)
|
||||
;;@ assembly/pson.ts:95:49
|
||||
;;@ assembly/pson.ts:90:49
|
||||
(i32.const 1)
|
||||
)
|
||||
;;@ assembly/pson.ts:95:54
|
||||
;;@ assembly/pson.ts:90:54
|
||||
(i32.sub
|
||||
(i32.const 0)
|
||||
;;@ assembly/pson.ts:95:55
|
||||
;;@ assembly/pson.ts:90:55
|
||||
(i32.and
|
||||
;;@ assembly/pson.ts:95:56
|
||||
;;@ assembly/pson.ts:90:56
|
||||
(get_local $0)
|
||||
;;@ assembly/pson.ts:95:63
|
||||
;;@ assembly/pson.ts:90:63
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
;;@ assembly/pson.ts:96:6
|
||||
;;@ assembly/pson.ts:91:6
|
||||
(br $break|0)
|
||||
)
|
||||
;;@ assembly/pson.ts:100:11
|
||||
;;@ assembly/pson.ts:95:11
|
||||
(call $assembly/pson/pson.onLong
|
||||
;;@ assembly/pson.ts:100:18
|
||||
;;@ assembly/pson.ts:95:18
|
||||
(i32.wrap/i64
|
||||
;;@ assembly/pson.ts:99:6
|
||||
;;@ assembly/pson.ts:94:6
|
||||
(tee_local $2
|
||||
;;@ assembly/pson.ts:99:13
|
||||
;;@ assembly/pson.ts:94:13
|
||||
(i64.xor
|
||||
(i64.shr_u
|
||||
;;@ assembly/pson.ts:99:14
|
||||
;;@ assembly/pson.ts:94:14
|
||||
(tee_local $2
|
||||
;;@ assembly/pson.ts:99:22
|
||||
;;@ assembly/pson.ts:94:22
|
||||
(call $assembly/pson/readVarint64)
|
||||
)
|
||||
;;@ assembly/pson.ts:99:41
|
||||
;;@ assembly/pson.ts:94:41
|
||||
(i64.const 1)
|
||||
)
|
||||
;;@ assembly/pson.ts:99:46
|
||||
;;@ assembly/pson.ts:94:46
|
||||
(i64.sub
|
||||
(i64.const 0)
|
||||
;;@ assembly/pson.ts:99:47
|
||||
;;@ assembly/pson.ts:94:47
|
||||
(i64.and
|
||||
;;@ assembly/pson.ts:99:48
|
||||
;;@ assembly/pson.ts:94:48
|
||||
(get_local $2)
|
||||
;;@ assembly/pson.ts:99:55
|
||||
;;@ assembly/pson.ts:94:55
|
||||
(i64.const 1)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
;;@ assembly/pson.ts:100:29
|
||||
;;@ assembly/pson.ts:95:29
|
||||
(i32.wrap/i64
|
||||
;;@ assembly/pson.ts:100:35
|
||||
;;@ assembly/pson.ts:95:35
|
||||
(i64.shr_u
|
||||
(get_local $2)
|
||||
;;@ assembly/pson.ts:100:44
|
||||
;;@ assembly/pson.ts:95:44
|
||||
(i64.const 32)
|
||||
)
|
||||
)
|
||||
)
|
||||
;;@ assembly/pson.ts:101:6
|
||||
;;@ assembly/pson.ts:96:6
|
||||
(br $break|0)
|
||||
)
|
||||
;;@ assembly/pson.ts:104:11
|
||||
;;@ assembly/pson.ts:99:11
|
||||
(call $assembly/pson/pson.onFloat
|
||||
;;@ assembly/pson.ts:104:19
|
||||
;;@ assembly/pson.ts:99:19
|
||||
(f32.load
|
||||
;;@ assembly/pson.ts:104:29
|
||||
;;@ assembly/pson.ts:99:29
|
||||
(get_global $assembly/pson/offset)
|
||||
)
|
||||
)
|
||||
;;@ assembly/pson.ts:105:6
|
||||
;;@ assembly/pson.ts:100:6
|
||||
(set_global $assembly/pson/offset
|
||||
(i32.add
|
||||
(get_global $assembly/pson/offset)
|
||||
;;@ assembly/pson.ts:105:16
|
||||
;;@ assembly/pson.ts:100:16
|
||||
(i32.const 4)
|
||||
)
|
||||
)
|
||||
;;@ assembly/pson.ts:106:6
|
||||
;;@ assembly/pson.ts:101:6
|
||||
(br $break|0)
|
||||
)
|
||||
;;@ assembly/pson.ts:109:11
|
||||
;;@ assembly/pson.ts:104:11
|
||||
(call $assembly/pson/pson.onDouble
|
||||
;;@ assembly/pson.ts:109:20
|
||||
;;@ assembly/pson.ts:104:20
|
||||
(f64.load
|
||||
;;@ assembly/pson.ts:109:30
|
||||
;;@ assembly/pson.ts:104:30
|
||||
(get_global $assembly/pson/offset)
|
||||
)
|
||||
)
|
||||
;;@ assembly/pson.ts:110:6
|
||||
;;@ assembly/pson.ts:105:6
|
||||
(set_global $assembly/pson/offset
|
||||
(i32.add
|
||||
(get_global $assembly/pson/offset)
|
||||
;;@ assembly/pson.ts:110:16
|
||||
;;@ assembly/pson.ts:105:16
|
||||
(i32.const 8)
|
||||
)
|
||||
)
|
||||
;;@ assembly/pson.ts:111:6
|
||||
;;@ assembly/pson.ts:106:6
|
||||
(br $break|0)
|
||||
)
|
||||
;;@ assembly/pson.ts:114:6
|
||||
;;@ assembly/pson.ts:109:6
|
||||
(set_local $0
|
||||
;;@ assembly/pson.ts:114:13
|
||||
;;@ assembly/pson.ts:109:13
|
||||
(call $assembly/pson/readVarint32)
|
||||
)
|
||||
;;@ assembly/pson.ts:115:11
|
||||
;;@ assembly/pson.ts:110:11
|
||||
(call $assembly/pson/pson.onString
|
||||
;;@ assembly/pson.ts:115:20
|
||||
;;@ assembly/pson.ts:110:20
|
||||
(get_global $assembly/pson/offset)
|
||||
;;@ assembly/pson.ts:115:28
|
||||
;;@ assembly/pson.ts:110:28
|
||||
(get_local $0)
|
||||
)
|
||||
;;@ assembly/pson.ts:116:6
|
||||
;;@ assembly/pson.ts:111:6
|
||||
(set_global $assembly/pson/offset
|
||||
(i32.add
|
||||
(get_global $assembly/pson/offset)
|
||||
;;@ assembly/pson.ts:116:16
|
||||
;;@ assembly/pson.ts:111:16
|
||||
(get_local $0)
|
||||
)
|
||||
)
|
||||
;;@ assembly/pson.ts:117:6
|
||||
;;@ assembly/pson.ts:112:6
|
||||
(br $break|0)
|
||||
)
|
||||
;;@ assembly/pson.ts:122:6
|
||||
;;@ assembly/pson.ts:117:6
|
||||
(unreachable)
|
||||
)
|
||||
;;@ assembly/pson.ts:125:6
|
||||
;;@ assembly/pson.ts:121:6
|
||||
(set_local $0
|
||||
;;@ assembly/pson.ts:125:13
|
||||
;;@ assembly/pson.ts:121:13
|
||||
(call $assembly/pson/readVarint32)
|
||||
)
|
||||
;;@ assembly/pson.ts:126:11
|
||||
;;@ assembly/pson.ts:122:11
|
||||
(call $assembly/pson/pson.onBinary
|
||||
;;@ assembly/pson.ts:126:20
|
||||
;;@ assembly/pson.ts:122:20
|
||||
(get_global $assembly/pson/offset)
|
||||
;;@ assembly/pson.ts:126:28
|
||||
;;@ assembly/pson.ts:122:28
|
||||
(get_local $0)
|
||||
)
|
||||
;;@ assembly/pson.ts:127:6
|
||||
;;@ assembly/pson.ts:123:6
|
||||
(set_global $assembly/pson/offset
|
||||
(i32.add
|
||||
(get_global $assembly/pson/offset)
|
||||
;;@ assembly/pson.ts:127:16
|
||||
;;@ assembly/pson.ts:123:16
|
||||
(get_local $0)
|
||||
)
|
||||
)
|
||||
;;@ assembly/pson.ts:128:6
|
||||
;;@ assembly/pson.ts:124:6
|
||||
(br $break|0)
|
||||
)
|
||||
;;@ assembly/pson.ts:131:6
|
||||
;;@ assembly/pson.ts:127:6
|
||||
(if
|
||||
;;@ assembly/pson.ts:131:10
|
||||
;;@ assembly/pson.ts:127:10
|
||||
(i32.gt_u
|
||||
(get_local $0)
|
||||
;;@ assembly/pson.ts:131:18
|
||||
;;@ assembly/pson.ts:127:18
|
||||
(i32.const 239)
|
||||
)
|
||||
;;@ assembly/pson.ts:132:8
|
||||
;;@ assembly/pson.ts:127:34
|
||||
(unreachable)
|
||||
)
|
||||
;;@ assembly/pson.ts:134:11
|
||||
;;@ assembly/pson.ts:128:11
|
||||
(call $assembly/pson/pson.onInteger
|
||||
;;@ assembly/pson.ts:134:21
|
||||
;;@ assembly/pson.ts:128:21
|
||||
(i32.xor
|
||||
(i32.shr_u
|
||||
;;@ assembly/pson.ts:134:22
|
||||
;;@ assembly/pson.ts:128:22
|
||||
(get_local $0)
|
||||
;;@ assembly/pson.ts:134:31
|
||||
;;@ assembly/pson.ts:128:31
|
||||
(i32.const 1)
|
||||
)
|
||||
;;@ assembly/pson.ts:134:36
|
||||
;;@ assembly/pson.ts:128:36
|
||||
(i32.sub
|
||||
(i32.const 0)
|
||||
;;@ assembly/pson.ts:134:37
|
||||
;;@ assembly/pson.ts:128:37
|
||||
(i32.and
|
||||
;;@ assembly/pson.ts:134:38
|
||||
;;@ assembly/pson.ts:128:38
|
||||
(get_local $0)
|
||||
;;@ assembly/pson.ts:134:46
|
||||
;;@ assembly/pson.ts:128:46
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
@ -519,7 +517,7 @@
|
||||
)
|
||||
)
|
||||
)
|
||||
(func $assembly/pson/decode (; 18 ;) (type $iv) (param $0 i32)
|
||||
(func $assembly/pson/decode (; 17 ;) (type $iv) (param $0 i32)
|
||||
;;@ assembly/pson.ts:42:2
|
||||
(set_global $assembly/pson/offset
|
||||
;;@ assembly/pson.ts:42:11
|
||||
@ -534,29 +532,22 @@
|
||||
(get_local $0)
|
||||
)
|
||||
(block
|
||||
;;@ assembly/pson.ts:44:4
|
||||
;;@ assembly/pson.ts:43:26
|
||||
(call $assembly/pson/decodeValue)
|
||||
(br $continue|0)
|
||||
)
|
||||
)
|
||||
)
|
||||
;;@ assembly/pson.ts:46:2
|
||||
;;@ assembly/pson.ts:44:2
|
||||
(if
|
||||
;;@ assembly/pson.ts:46:9
|
||||
;;@ assembly/pson.ts:44:6
|
||||
(i32.ne
|
||||
(get_global $assembly/pson/offset)
|
||||
;;@ assembly/pson.ts:46:19
|
||||
;;@ assembly/pson.ts:44:16
|
||||
(get_local $0)
|
||||
)
|
||||
(block
|
||||
(call $abort
|
||||
(i32.const 0)
|
||||
(i32.const 4)
|
||||
(i32.const 46)
|
||||
(i32.const 2)
|
||||
)
|
||||
(unreachable)
|
||||
)
|
||||
;;@ assembly/pson.ts:44:24
|
||||
(unreachable)
|
||||
)
|
||||
)
|
||||
)
|
File diff suppressed because it is too large
Load Diff
@ -39,7 +39,7 @@ var pson = {
|
||||
console.log("double: " + value);
|
||||
},
|
||||
onString: function(offset, length) {
|
||||
console.log("string(length=" + length + "): " + new Buffer(mem.slice(offset, offset + length)).toString());
|
||||
console.log("string(length=" + length + "): " + Buffer.from(mem.slice(offset, offset + length)).toString());
|
||||
},
|
||||
onBinary: function(offset, length) {
|
||||
console.log("binary(length=" + length + "): " + mem.slice(offset, offset + length));
|
||||
@ -47,7 +47,7 @@ var pson = {
|
||||
};
|
||||
|
||||
// Instantiate the module
|
||||
var mod = new WebAssembly.Module(fs.readFileSync(__dirname + "/pson.optimized.wasm"));
|
||||
var mod = new WebAssembly.Module(fs.readFileSync(__dirname + "/build/optimized.wasm"));
|
||||
var ins = new WebAssembly.Instance(mod, { pson: pson });
|
||||
var mem = new Uint8Array(ins.exports.memory.buffer);
|
||||
|
||||
|
@ -3,9 +3,9 @@
|
||||
"version": "1.0.0",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"build": "npm run build:untouched && npm run build:optimized",
|
||||
"build:untouched": "asc assembly/pson.ts -b pson.untouched.wasm -t pson.untouched.wat --validate --sourceMap --measure",
|
||||
"build:optimized": "asc -O assembly/pson.ts -b pson.optimized.wasm -t pson.optimized.wat --validate --sourceMap --measure",
|
||||
"asbuild": "npm run asbuild:untouched && npm run asbuild:optimized",
|
||||
"asbuild:untouched": "asc assembly/pson.ts -b build/untouched.wasm -t build/untouched.wat --validate --sourceMap --measure",
|
||||
"asbuild:optimized": "asc -O assembly/pson.ts -b build/optimized.wasm -t build/optimized.wat --validate --sourceMap --measure",
|
||||
"test": "node tests"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
Reference in New Issue
Block a user