From aa38d06c31960df684612ac4a80bcb7756a6f4af Mon Sep 17 00:00:00 2001 From: dcode Date: Thu, 28 Mar 2019 18:57:35 +0100 Subject: [PATCH 1/2] Improve text encoding API --- std/assembly/encoding.ts | 194 ++ std/assembly/index.d.ts | 18 +- std/assembly/string.ts | 107 +- tests/compiler/number.optimized.wat | 2 +- tests/compiler/number.untouched.wat | 2 +- tests/compiler/std/array-access.optimized.wat | 2 +- tests/compiler/std/array-access.untouched.wat | 2 +- tests/compiler/std/array.optimized.wat | 2 +- tests/compiler/std/array.untouched.wat | 4 +- ...8.optimized.wat => encoding.optimized.wat} | 2363 ++++++++----- tests/compiler/std/encoding.ts | 73 + ...8.untouched.wat => encoding.untouched.wat} | 3068 +++++++++++------ tests/compiler/std/string-utf8.ts | 30 - tests/compiler/std/string.optimized.wat | 24 +- tests/compiler/std/string.untouched.wat | 24 +- 15 files changed, 3821 insertions(+), 2094 deletions(-) create mode 100644 std/assembly/encoding.ts rename tests/compiler/std/{string-utf8.optimized.wat => encoding.optimized.wat} (63%) create mode 100644 tests/compiler/std/encoding.ts rename tests/compiler/std/{string-utf8.untouched.wat => encoding.untouched.wat} (65%) delete mode 100644 tests/compiler/std/string-utf8.ts diff --git a/std/assembly/encoding.ts b/std/assembly/encoding.ts new file mode 100644 index 0000000000..8915f11a2d --- /dev/null +++ b/std/assembly/encoding.ts @@ -0,0 +1,194 @@ +import { ALLOCATE, REGISTER, REALLOCATE, MAX_BYTELENGTH } from "./runtime"; +import { E_INVALIDLENGTH } from "./util/error"; + +/** UTF16 encoding. */ +export namespace UTF16 { + + /** Calculates the length of a string when encoded as an UTF16 buffer. */ + export function length(str: string): i32 { + return str.length << 1; + } + + /** Encodes a string as an UTF16 buffer. */ + export function encode(str: string): ArrayBuffer { + var size = str.length << 1; + var buf = ALLOCATE(size); + memory.copy(buf, changetype(str), size); + return REGISTER(buf); + } + + /** Decodes an UTF16 buffer to a string.*/ + export function decode(buf: ArrayBuffer): string { + return decodeRaw(changetype(buf), buf.byteLength); + } + + // @ts-ignore: decorator + @unsafe + export function decodeRaw(buf: usize, len: i32): string { + if (len > MAX_BYTELENGTH) throw new RangeError(E_INVALIDLENGTH); + var size = len; + var str = ALLOCATE(size); + memory.copy(str, changetype(buf), size); + return REGISTER(str); + } +} + +/** UTF8 encoding. */ +export namespace UTF8 { + + /** Calculates the length of a string when encoded as an UTF8 buffer. */ + export function length(str: string, delimited: bool = false): i32 { + var strOff = changetype(str); + var strEnd = changetype(str) + (str.length << 1); + var bufLen = delimited ? 1 : 0; + while (strOff < strEnd) { + let c = load(strOff); + if (c < 128) { + bufLen += 1; strOff += 2; + } else if (c < 2048) { + bufLen += 2; strOff += 2; + } else { + if ((c & 0xFC00) == 0xD800 && strOff + 2 < strEnd) { + if ((load(strOff, 2) & 0xFC00) == 0xDC00) { + strOff += 4; bufLen += 4; + continue; + } + } + strOff += 2; bufLen += 3; + } + } + return bufLen; + } + + /** Encodes a string as an UTF8 buffer. */ + export function encode(str: string, delimited: bool = false): ArrayBuffer { + var strOff = changetype(str); + var strEnd = changetype(str) + (str.length << 1); + var buf = ALLOCATE(length(str, delimited)); + var bufOff = changetype(buf); + while (strOff < strEnd) { + let c1 = load(strOff); + if (c1 < 128) { + store(bufOff, c1); + bufOff += 1; strOff += 2; + } else if (c1 < 2048) { + store(bufOff, c1 >> 6 | 192); + store(bufOff, c1 & 63 | 128, 1); + bufOff += 2; strOff += 2; + } else { + if ((c1 & 0xFC00) == 0xD800 && strOff + 2 < strEnd) { + let c2 = load(strOff, 2); + if ((c2 & 0xFC00) == 0xDC00) { + c1 = 0x10000 + ((c1 & 0x03FF) << 10) + (c2 & 0x03FF); + store(bufOff, c1 >> 18 | 240); + store(bufOff, c1 >> 12 & 63 | 128, 1); + store(bufOff, c1 >> 6 & 63 | 128, 2); + store(bufOff, c1 & 63 | 128, 3); + strOff += 4; bufOff += 4; + continue; + } + } + store(bufOff, c1 >> 12 | 224); + store(bufOff, c1 >> 6 & 63 | 128, 1); + store(bufOff, c1 & 63 | 128, 2); + strOff += 2; bufOff += 3; + } + } + assert(strOff == strEnd); + if (delimited) store(bufOff, 0); + return REGISTER(buf); + } + + /** Decodes an UTF8 buffer to a string.*/ + export function decode(buf: ArrayBuffer, delimited: bool = false): string { + return delimited + ? decodeRawDelimited(changetype(buf), buf.byteLength) + : decodeRaw(changetype(buf), buf.byteLength); + } + + // @ts-ignore: decorator + @unsafe + export function decodeRaw(buf: usize, len: i32): string { + var bufOff = buf; + var bufEnd = buf + len; + var str = ALLOCATE(len << 1); // max is one u16 char per u8 byte + var strOff = str; + while (bufOff < bufEnd) { + let cp = load(bufOff++); + if (cp < 128) { + store(strOff, cp); + strOff += 2; + } else if (cp > 191 && cp < 224) { + store(strOff, (cp & 31) << 6 | load(bufOff++) & 63); + strOff += 2; + } else if (cp > 239 && cp < 365) { + cp = ( + (cp & 7) << 18 | + (load(bufOff) & 63) << 12 | + (load(bufOff, 1) & 63) << 6 | + load(bufOff, 2) & 63 + ) - 0x10000; + bufOff += 3; + store(strOff, 0xD800 + (cp >> 10)); + store(strOff, 0xDC00 + (cp & 1023), 2); + strOff += 4; + } else { + store(strOff, + (cp & 15) << 12 | + (load(bufOff) & 63) << 6 | + load(bufOff, 1) & 63 + ); + bufOff += 2; strOff += 2; + } + } + return REGISTER(REALLOCATE(str, strOff - str)); + } + + // @ts-ignore: decorator + @unsafe + export function decodeRawDelimited(buf: usize, maxLen: i32 = MAX_BYTELENGTH): string { + var bufOff = buf; + var bufLim = buf + maxLen; + assert(bufLim > bufOff); // guard wraparound + var str = ALLOCATE(16); // optimize for small strings + var strLen = 0; + while (bufOff < bufLim) { + let cp = load(bufOff++); + if (cp < 128) { + if (!cp) break; + str = REALLOCATE(str, strLen + 2); + store(str + strLen, cp); + strLen += 2; + } else if (cp > 191 && cp < 224) { + if (bufOff >= bufLim) break; + str = REALLOCATE(str, strLen + 2); + store(str + strLen, (cp & 31) << 6 | load(bufOff++) & 63); + strLen += 2; + } else if (cp > 239 && cp < 365) { + if (bufOff + 3 > bufLim) break; + cp = ( + (cp & 7) << 18 | + (load(bufOff) & 63) << 12 | + (load(bufOff, 1) & 63) << 6 | + load(bufOff, 2) & 63 + ) - 0x10000; + bufOff += 3; + str = REALLOCATE(str, strLen + 4); + let strOff = str + strLen; + store(strOff, 0xD800 + (cp >> 10)); + store(strOff, 0xDC00 + (cp & 1023), 2); + strLen += 4; + } else { + if (bufOff + 2 > bufLim) break; + str = REALLOCATE(str, strLen + 2); + store(str + strLen, + (cp & 15) << 12 | + (load(bufOff) & 63) << 6 | + load(bufOff, 1) & 63 + ); + bufOff += 2; strLen += 2; + } + } + return REGISTER(REALLOCATE(str, strLen)); + } +} diff --git a/std/assembly/index.d.ts b/std/assembly/index.d.ts index 67f655cb44..ffd00a96a7 100644 --- a/std/assembly/index.d.ts +++ b/std/assembly/index.d.ts @@ -1230,7 +1230,6 @@ declare class String { static fromCodePoints(arr: i32[]): string; readonly length: i32; - readonly lengthUTF8: i32; charAt(index: u32): string; charCodeAt(index: u32): u16; @@ -1253,8 +1252,21 @@ declare class String { slice(beginIndex: i32, endIndex?: i32): string; split(separator?: string, limit?: i32): string[]; toString(): string; - static fromUTF8(ptr: usize, len: usize): string; - toUTF8(): usize; +} + +declare namespace UTF16 { + export function length(str: string): i32; + export function encode(str: string): ArrayBuffer; + export function decode(buf: ArrayBuffer, delimited?: bool): string; + export function decodeRaw(buf: usize, len: i32): string; // unsafe +} + +declare namespace UTF8 { + export function length(str: string, delimited?: bool): i32; + export function encode(str: string, delimited?: bool): ArrayBuffer; + export function decode(buf: ArrayBuffer, delimited?: bool): string; + export function decodeRaw(buf: usize, len: i32): string; // unsafe + export function decodeRawDelimited(buf: usize, maxLen?: i32): string; // unsafe } /** Class for representing a runtime error. Base class of all errors. */ diff --git a/std/assembly/string.ts b/std/assembly/string.ts index cdf4e4c9d2..34c18a1374 100644 --- a/std/assembly/string.ts +++ b/std/assembly/string.ts @@ -4,6 +4,7 @@ import { ALLOCATE, REGISTER, HEADER, HEADER_SIZE, MAKEARRAY, ArrayBufferView } f import { MAX_SIZE_32 } from "./util/allocator"; import { compareImpl, parse, CharCode, isWhiteSpaceOrLineTerminator } from "./util/string"; import { E_INVALIDLENGTH } from "./util/error"; +import { UTF8 } from "./encoding"; @sealed export abstract class String { @@ -408,112 +409,6 @@ import { E_INVALIDLENGTH } from "./util/error"; toString(): String { return this; } - - get lengthUTF8(): i32 { - var len = 1; // null terminated - var pos: usize = 0; - var end = this.length; - while (pos < end) { - let c = load(changetype(this) + (pos << 1)); - if (c < 128) { - len += 1; ++pos; - } else if (c < 2048) { - len += 2; ++pos; - } else { - if ( - (c & 0xFC00) == 0xD800 && pos + 1 < end && - (load(changetype(this) + ((pos + 1) << 1)) & 0xFC00) == 0xDC00 - ) { - len += 4; pos += 2; - } else { - len += 3; ++pos; - } - } - } - return len; - } - - static fromUTF8(ptr: usize, len: usize): string { - if (len < 1) return changetype(""); - var ptrPos = 0; - var buf = memory.allocate(len << 1); - var bufPos = 0; - while (ptrPos < len) { - let cp = load(ptr + ptrPos++); - if (cp < 128) { - store(buf + bufPos, cp); - bufPos += 2; - } else if (cp > 191 && cp < 224) { - assert(ptrPos + 1 <= len); - store(buf + bufPos, (cp & 31) << 6 | load(ptr + ptrPos++) & 63); - bufPos += 2; - } else if (cp > 239 && cp < 365) { - assert(ptrPos + 3 <= len); - cp = ( - (cp & 7) << 18 | - (load(ptr + ptrPos++) & 63) << 12 | - (load(ptr + ptrPos++) & 63) << 6 | - load(ptr + ptrPos++) & 63 - ) - 0x10000; - store(buf + bufPos, 0xD800 + (cp >> 10)); - bufPos += 2; - store(buf + bufPos, 0xDC00 + (cp & 1023)); - bufPos += 2; - } else { - assert(ptrPos + 2 <= len); - store(buf + bufPos, - (cp & 15) << 12 | - (load(ptr + ptrPos++) & 63) << 6 | - load(ptr + ptrPos++) & 63 - ); - bufPos += 2; - } - } - assert(ptrPos == len); - var out = ALLOCATE(bufPos); - memory.copy(changetype(out), buf, bufPos); - memory.free(buf); - return REGISTER(out); - } - - toUTF8(): usize { - var buf = memory.allocate(this.lengthUTF8); - var pos: usize = 0; - var end = this.length; - var off: usize = 0; - while (pos < end) { - let c1 = load(changetype(this) + (pos << 1)); - if (c1 < 128) { - store(buf + off, c1); - ++off; ++pos; - } else if (c1 < 2048) { - let ptr = buf + off; - store(ptr, c1 >> 6 | 192); - store(ptr, c1 & 63 | 128, 1); - off += 2; ++pos; - } else { - let ptr = buf + off; - if ((c1 & 0xFC00) == 0xD800 && pos + 1 < end) { - let c2 = load(changetype(this) + ((pos + 1) << 1)); - if ((c2 & 0xFC00) == 0xDC00) { - c1 = 0x10000 + ((c1 & 0x03FF) << 10) + (c2 & 0x03FF); - store(ptr, c1 >> 18 | 240); - store(ptr, c1 >> 12 & 63 | 128, 1); - store(ptr, c1 >> 6 & 63 | 128, 2); - store(ptr, c1 & 63 | 128, 3); - off += 4; pos += 2; - continue; - } - } - store(ptr, c1 >> 12 | 224); - store(ptr, c1 >> 6 & 63 | 128, 1); - store(ptr, c1 & 63 | 128, 2); - off += 3; ++pos; - } - } - store(buf + off, 0); - return buf; - } } // @ts-ignore: nolib diff --git a/tests/compiler/number.optimized.wat b/tests/compiler/number.optimized.wat index 89aa758653..c1b84a5de3 100644 --- a/tests/compiler/number.optimized.wat +++ b/tests/compiler/number.optimized.wat @@ -2358,7 +2358,7 @@ if i32.const 0 i32.const 1648 - i32.const 189 + i32.const 190 i32.const 4 call $~lib/env/abort unreachable diff --git a/tests/compiler/number.untouched.wat b/tests/compiler/number.untouched.wat index 3032067b46..27d211e87a 100644 --- a/tests/compiler/number.untouched.wat +++ b/tests/compiler/number.untouched.wat @@ -3424,7 +3424,7 @@ if i32.const 0 i32.const 1648 - i32.const 189 + i32.const 190 i32.const 4 call $~lib/env/abort unreachable diff --git a/tests/compiler/std/array-access.optimized.wat b/tests/compiler/std/array-access.optimized.wat index c1ffc30d5a..7e9cbe252f 100644 --- a/tests/compiler/std/array-access.optimized.wat +++ b/tests/compiler/std/array-access.optimized.wat @@ -142,7 +142,7 @@ if i32.const 0 i32.const 64 - i32.const 164 + i32.const 165 i32.const 4 call $~lib/env/abort unreachable diff --git a/tests/compiler/std/array-access.untouched.wat b/tests/compiler/std/array-access.untouched.wat index 2d16c9f85b..e65829fd21 100644 --- a/tests/compiler/std/array-access.untouched.wat +++ b/tests/compiler/std/array-access.untouched.wat @@ -219,7 +219,7 @@ if i32.const 0 i32.const 64 - i32.const 164 + i32.const 165 i32.const 4 call $~lib/env/abort unreachable diff --git a/tests/compiler/std/array.optimized.wat b/tests/compiler/std/array.optimized.wat index 5ce6486507..9bc32116a2 100644 --- a/tests/compiler/std/array.optimized.wat +++ b/tests/compiler/std/array.optimized.wat @@ -6229,7 +6229,7 @@ if i32.const 0 i32.const 4376 - i32.const 189 + i32.const 190 i32.const 4 call $~lib/env/abort unreachable diff --git a/tests/compiler/std/array.untouched.wat b/tests/compiler/std/array.untouched.wat index 6c0bc57382..4cfd5bf98d 100644 --- a/tests/compiler/std/array.untouched.wat +++ b/tests/compiler/std/array.untouched.wat @@ -8951,7 +8951,7 @@ if i32.const 0 i32.const 4376 - i32.const 39 + i32.const 40 i32.const 4 call $~lib/env/abort unreachable @@ -9590,7 +9590,7 @@ if i32.const 0 i32.const 4376 - i32.const 189 + i32.const 190 i32.const 4 call $~lib/env/abort unreachable diff --git a/tests/compiler/std/string-utf8.optimized.wat b/tests/compiler/std/encoding.optimized.wat similarity index 63% rename from tests/compiler/std/string-utf8.optimized.wat rename to tests/compiler/std/encoding.optimized.wat index abc325672d..a16df4a6fb 100644 --- a/tests/compiler/std/string-utf8.optimized.wat +++ b/tests/compiler/std/encoding.optimized.wat @@ -1,139 +1,150 @@ (module + (type $FUNCSIG$v (func)) + (type $FUNCSIG$iii (func (param i32 i32) (result i32))) (type $FUNCSIG$ii (func (param i32) (result i32))) (type $FUNCSIG$viiii (func (param i32 i32 i32 i32))) - (type $FUNCSIG$iii (func (param i32 i32) (result i32))) (type $FUNCSIG$viii (func (param i32 i32 i32))) - (type $FUNCSIG$v (func)) + (type $FUNCSIG$vii (func (param i32 i32))) (type $FUNCSIG$iiii (func (param i32 i32 i32) (result i32))) (import "env" "abort" (func $~lib/env/abort (param i32 i32 i32 i32))) (memory $0 1) (data (i32.const 8) "\01\00\00\00\0c\00\00\00\01\d87\dch\00i\00R\d8b\df") - (data (i32.const 32) "\01\00\00\00$\00\00\00s\00t\00d\00/\00s\00t\00r\00i\00n\00g\00-\00u\00t\00f\008\00.\00t\00s") - (data (i32.const 80) "\01") - (data (i32.const 88) "\01\00\00\00\1c\00\00\00~\00l\00i\00b\00/\00s\00t\00r\00i\00n\00g\00.\00t\00s") - (data (i32.const 128) "\01\00\00\00\1e\00\00\00~\00l\00i\00b\00/\00r\00u\00n\00t\00i\00m\00e\00.\00t\00s") - (data (i32.const 168) "\01\00\00\00\04\00\00\00\01\d87\dc") - (data (i32.const 184) "\01\00\00\00\04\00\00\00h\00i") - (data (i32.const 200) "\01\00\00\00\04\00\00\00R\d8b\df") - (data (i32.const 216) "\01\00\00\00\02") + (data (i32.const 32) "\01\00\00\00\1e\00\00\00s\00t\00d\00/\00e\00n\00c\00o\00d\00i\00n\00g\00.\00t\00s") + (data (i32.const 72) "\01\00\00\00 \00\00\00~\00l\00i\00b\00/\00e\00n\00c\00o\00d\00i\00n\00g\00.\00t\00s") + (data (i32.const 112) "\01\00\00\00\1e\00\00\00~\00l\00i\00b\00/\00r\00u\00n\00t\00i\00m\00e\00.\00t\00s") + (data (i32.const 152) "\01") + (data (i32.const 160) "\01\00\00\00\04\00\00\00\01\d87\dc") + (data (i32.const 176) "\01\00\00\00\04\00\00\00h\00i") + (data (i32.const 192) "\01\00\00\00\04\00\00\00R\d8b\df") + (data (i32.const 208) "\01\00\00\00\08\00\00\00h\00i\00R\d8b\df") (table $0 1 funcref) (elem (i32.const 0) $null) - (global $std/string-utf8/str (mut i32) (i32.const 16)) - (global $std/string-utf8/len (mut i32) (i32.const 0)) + (global $std/encoding/str (mut i32) (i32.const 16)) (global $~lib/allocator/arena/startOffset (mut i32) (i32.const 0)) (global $~lib/allocator/arena/offset (mut i32) (i32.const 0)) - (global $std/string-utf8/ptr (mut i32) (i32.const 0)) (export "memory" (memory $0)) (export "table" (table $0)) (start $start) - (func $~lib/string/String#get:lengthUTF8 (; 1 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - (local $1 i32) + (func $~lib/encoding/UTF8.length (; 1 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) - (local $4 i32) - i32.const 1 - local.set $1 local.get $0 i32.const 8 i32.sub i32.load offset=4 i32.const 1 i32.shr_u - local.set $4 + i32.const 1 + i32.shl + local.get $0 + i32.add + local.set $3 + i32.const 1 + i32.const 0 + local.get $1 + select + local.set $1 loop $continue|0 - local.get $2 - local.get $4 + local.get $0 + local.get $3 i32.lt_u if - local.get $2 - i32.const 1 - i32.shl local.get $0 - i32.add i32.load16_u - local.tee $3 + local.tee $2 i32.const 128 i32.lt_u if (result i32) local.get $1 i32.const 1 i32.add - local.set $1 - local.get $2 - i32.const 1 - i32.add else - local.get $3 + local.get $2 i32.const 2048 i32.lt_u if (result i32) local.get $1 i32.const 2 i32.add - local.set $1 - local.get $2 - i32.const 1 - i32.add else - block (result i32) - local.get $3 - i32.const 64512 - i32.and - i32.const 55296 - i32.eq - local.tee $3 - if - local.get $2 - i32.const 1 - i32.add - local.get $4 - i32.lt_u - local.set $3 - end - local.get $3 - end + local.get $2 + i32.const 64512 + i32.and + i32.const 55296 + i32.eq + local.tee $2 if (result i32) - local.get $2 - i32.const 1 - i32.add - i32.const 1 - i32.shl local.get $0 + i32.const 2 i32.add - i32.load16_u + local.get $3 + i32.lt_u + else + local.get $2 + end + if + local.get $0 + i32.load16_u offset=2 i32.const 64512 i32.and i32.const 56320 i32.eq - else - local.get $3 - end - if (result i32) - local.get $1 - i32.const 4 - i32.add - local.set $1 - local.get $2 - i32.const 2 - i32.add - else - local.get $1 - i32.const 3 - i32.add - local.set $1 - local.get $2 - i32.const 1 - i32.add + if + local.get $0 + i32.const 4 + i32.add + local.set $0 + local.get $1 + i32.const 4 + i32.add + local.set $1 + br $continue|0 + end end + local.get $1 + i32.const 3 + i32.add end end - local.set $2 + local.set $1 + local.get $0 + i32.const 2 + i32.add + local.set $0 br $continue|0 end end local.get $1 ) - (func $~lib/allocator/arena/__mem_allocate (; 2 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $std/encoding/testUTF8Length (; 2 ;) (type $FUNCSIG$v) + global.get $std/encoding/str + i32.const 0 + call $~lib/encoding/UTF8.length + i32.const 10 + i32.ne + if + i32.const 0 + i32.const 40 + i32.const 6 + i32.const 2 + call $~lib/env/abort + unreachable + end + global.get $std/encoding/str + i32.const 1 + call $~lib/encoding/UTF8.length + i32.const 11 + i32.ne + if + i32.const 0 + i32.const 40 + i32.const 7 + i32.const 2 + call $~lib/env/abort + unreachable + end + ) + (func $~lib/allocator/arena/__mem_allocate (; 3 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) (local $3 i32) @@ -195,65 +206,114 @@ global.set $~lib/allocator/arena/offset local.get $1 ) - (func $~lib/string/String#toUTF8 (; 3 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/runtime/allocate (; 4 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) (local $1 i32) + i32.const 1 + i32.const 32 + local.get $0 + i32.const 7 + i32.add + i32.clz + i32.sub + i32.shl + call $~lib/allocator/arena/__mem_allocate + local.tee $1 + i32.const -1520547049 + i32.store + local.get $1 + local.get $0 + i32.store offset=4 + local.get $1 + i32.const 8 + i32.add + ) + (func $~lib/runtime/register (; 5 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (local $2 i32) + local.get $0 + i32.const 224 + i32.le_u + if + i32.const 0 + i32.const 120 + i32.const 149 + i32.const 4 + call $~lib/env/abort + unreachable + end + local.get $0 + i32.const 8 + i32.sub + local.tee $2 + i32.load + i32.const -1520547049 + i32.ne + if + i32.const 0 + i32.const 120 + i32.const 151 + i32.const 4 + call $~lib/env/abort + unreachable + end + local.get $2 + local.get $1 + i32.store + local.get $0 + ) + (func $~lib/encoding/UTF8.encode (; 6 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) (local $5 i32) (local $6 i32) - (local $7 i32) - local.get $0 - call $~lib/string/String#get:lengthUTF8 - call $~lib/allocator/arena/__mem_allocate - local.set $5 local.get $0 i32.const 8 i32.sub i32.load offset=4 i32.const 1 i32.shr_u - local.set $7 + i32.const 1 + i32.shl + local.get $0 + i32.add + local.set $4 + local.get $0 + local.get $1 + call $~lib/encoding/UTF8.length + call $~lib/runtime/allocate + local.tee $6 + local.set $2 loop $continue|0 + local.get $0 local.get $4 - local.get $7 i32.lt_u if - local.get $4 - i32.const 1 - i32.shl local.get $0 - i32.add i32.load16_u - local.tee $1 + local.tee $3 i32.const 128 i32.lt_u if (result i32) local.get $2 - local.get $5 - i32.add - local.get $1 + local.get $3 i32.store8 local.get $2 i32.const 1 i32.add else - local.get $1 + local.get $3 i32.const 2048 i32.lt_u if (result i32) local.get $2 - local.get $5 - i32.add - local.tee $3 - local.get $1 + local.get $3 i32.const 6 i32.shr_u i32.const 192 i32.or i32.store8 + local.get $2 local.get $3 - local.get $1 i32.const 63 i32.and i32.const 128 @@ -263,60 +323,50 @@ i32.const 2 i32.add else - local.get $2 - local.get $5 - i32.add - local.set $3 - local.get $1 + local.get $3 i32.const 64512 i32.and i32.const 55296 i32.eq - local.tee $6 + local.tee $5 if (result i32) - local.get $4 - i32.const 1 + local.get $0 + i32.const 2 i32.add - local.get $7 + local.get $4 i32.lt_u else - local.get $6 + local.get $5 end if - local.get $4 - i32.const 1 - i32.add - i32.const 1 - i32.shl local.get $0 - i32.add - i32.load16_u - local.tee $6 + i32.load16_u offset=2 + local.tee $5 i32.const 64512 i32.and i32.const 56320 i32.eq if + local.get $2 local.get $3 - local.get $1 i32.const 1023 i32.and i32.const 10 i32.shl i32.const 65536 i32.add - local.get $6 + local.get $5 i32.const 1023 i32.and i32.add - local.tee $1 + local.tee $3 i32.const 18 i32.shr_u i32.const 240 i32.or i32.store8 + local.get $2 local.get $3 - local.get $1 i32.const 12 i32.shr_u i32.const 63 @@ -324,8 +374,8 @@ i32.const 128 i32.or i32.store8 offset=1 + local.get $2 local.get $3 - local.get $1 i32.const 6 i32.shr_u i32.const 63 @@ -333,33 +383,33 @@ i32.const 128 i32.or i32.store8 offset=2 + local.get $2 local.get $3 - local.get $1 i32.const 63 i32.and i32.const 128 i32.or i32.store8 offset=3 + local.get $0 + i32.const 4 + i32.add + local.set $0 local.get $2 i32.const 4 i32.add local.set $2 - local.get $4 - i32.const 2 - i32.add - local.set $4 br $continue|0 end end + local.get $2 local.get $3 - local.get $1 i32.const 12 i32.shr_u i32.const 224 i32.or i32.store8 + local.get $2 local.get $3 - local.get $1 i32.const 6 i32.shr_u i32.const 63 @@ -367,8 +417,8 @@ i32.const 128 i32.or i32.store8 offset=1 + local.get $2 local.get $3 - local.get $1 i32.const 63 i32.and i32.const 128 @@ -380,42 +430,325 @@ end end local.set $2 - local.get $4 - i32.const 1 + local.get $0 + i32.const 2 i32.add - local.set $4 + local.set $0 br $continue|0 end end - local.get $2 - local.get $5 - i32.add + local.get $0 + local.get $4 + i32.ne + if + i32.const 0 + i32.const 80 + i32.const 97 + i32.const 4 + call $~lib/env/abort + unreachable + end + local.get $1 + if + local.get $2 + i32.const 0 + i32.store8 + end + local.get $6 + i32.const 2 + call $~lib/runtime/register + ) + (func $std/encoding/testUTF8Encode (; 7 ;) (type $FUNCSIG$v) + (local $0 i32) + global.get $std/encoding/str i32.const 0 - i32.store8 - local.get $5 + call $~lib/encoding/UTF8.encode + local.tee $0 + i32.const 8 + i32.sub + i32.load offset=4 + i32.const 10 + i32.ne + if + i32.const 0 + i32.const 40 + i32.const 14 + i32.const 2 + call $~lib/env/abort + unreachable + end + local.get $0 + i32.load8_u + i32.const 240 + i32.ne + if + i32.const 0 + i32.const 40 + i32.const 15 + i32.const 2 + call $~lib/env/abort + unreachable + end + local.get $0 + i32.load8_u offset=1 + i32.const 144 + i32.ne + if + i32.const 0 + i32.const 40 + i32.const 16 + i32.const 2 + call $~lib/env/abort + unreachable + end + local.get $0 + i32.load8_u offset=2 + i32.const 144 + i32.ne + if + i32.const 0 + i32.const 40 + i32.const 17 + i32.const 2 + call $~lib/env/abort + unreachable + end + local.get $0 + i32.load8_u offset=3 + i32.const 183 + i32.ne + if + i32.const 0 + i32.const 40 + i32.const 18 + i32.const 2 + call $~lib/env/abort + unreachable + end + local.get $0 + i32.load8_u offset=4 + i32.const 104 + i32.ne + if + i32.const 0 + i32.const 40 + i32.const 19 + i32.const 2 + call $~lib/env/abort + unreachable + end + local.get $0 + i32.load8_u offset=5 + i32.const 105 + i32.ne + if + i32.const 0 + i32.const 40 + i32.const 20 + i32.const 2 + call $~lib/env/abort + unreachable + end + local.get $0 + i32.load8_u offset=6 + i32.const 240 + i32.ne + if + i32.const 0 + i32.const 40 + i32.const 21 + i32.const 2 + call $~lib/env/abort + unreachable + end + local.get $0 + i32.load8_u offset=7 + i32.const 164 + i32.ne + if + i32.const 0 + i32.const 40 + i32.const 22 + i32.const 2 + call $~lib/env/abort + unreachable + end + local.get $0 + i32.load8_u offset=8 + i32.const 173 + i32.ne + if + i32.const 0 + i32.const 40 + i32.const 23 + i32.const 2 + call $~lib/env/abort + unreachable + end + local.get $0 + i32.load8_u offset=9 + i32.const 162 + i32.ne + if + i32.const 0 + i32.const 40 + i32.const 24 + i32.const 2 + call $~lib/env/abort + unreachable + end ) - (func $~lib/runtime/allocate (; 4 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - (local $1 i32) + (func $std/encoding/testUTF8EncodeDelimited (; 8 ;) (type $FUNCSIG$v) + (local $0 i32) + global.get $std/encoding/str i32.const 1 - i32.const 32 - local.get $0 - i32.const 7 - i32.add - i32.clz + call $~lib/encoding/UTF8.encode + local.tee $0 + i32.const 8 i32.sub - i32.shl - call $~lib/allocator/arena/__mem_allocate - local.tee $1 - i32.const -1520547049 - i32.store - local.get $1 + i32.load offset=4 + i32.const 11 + i32.ne + if + i32.const 0 + i32.const 40 + i32.const 31 + i32.const 2 + call $~lib/env/abort + unreachable + end local.get $0 - i32.store offset=4 - local.get $1 - i32.const 8 - i32.add + i32.load8_u + i32.const 240 + i32.ne + if + i32.const 0 + i32.const 40 + i32.const 32 + i32.const 2 + call $~lib/env/abort + unreachable + end + local.get $0 + i32.load8_u offset=1 + i32.const 144 + i32.ne + if + i32.const 0 + i32.const 40 + i32.const 33 + i32.const 2 + call $~lib/env/abort + unreachable + end + local.get $0 + i32.load8_u offset=2 + i32.const 144 + i32.ne + if + i32.const 0 + i32.const 40 + i32.const 34 + i32.const 2 + call $~lib/env/abort + unreachable + end + local.get $0 + i32.load8_u offset=3 + i32.const 183 + i32.ne + if + i32.const 0 + i32.const 40 + i32.const 35 + i32.const 2 + call $~lib/env/abort + unreachable + end + local.get $0 + i32.load8_u offset=4 + i32.const 104 + i32.ne + if + i32.const 0 + i32.const 40 + i32.const 36 + i32.const 2 + call $~lib/env/abort + unreachable + end + local.get $0 + i32.load8_u offset=5 + i32.const 105 + i32.ne + if + i32.const 0 + i32.const 40 + i32.const 37 + i32.const 2 + call $~lib/env/abort + unreachable + end + local.get $0 + i32.load8_u offset=6 + i32.const 240 + i32.ne + if + i32.const 0 + i32.const 40 + i32.const 38 + i32.const 2 + call $~lib/env/abort + unreachable + end + local.get $0 + i32.load8_u offset=7 + i32.const 164 + i32.ne + if + i32.const 0 + i32.const 40 + i32.const 39 + i32.const 2 + call $~lib/env/abort + unreachable + end + local.get $0 + i32.load8_u offset=8 + i32.const 173 + i32.ne + if + i32.const 0 + i32.const 40 + i32.const 40 + i32.const 2 + call $~lib/env/abort + unreachable + end + local.get $0 + i32.load8_u offset=9 + i32.const 162 + i32.ne + if + i32.const 0 + i32.const 40 + i32.const 41 + i32.const 2 + call $~lib/env/abort + unreachable + end + local.get $0 + i32.load8_u offset=10 + if + i32.const 0 + i32.const 40 + i32.const 42 + i32.const 2 + call $~lib/env/abort + unreachable + end ) - (func $~lib/util/memory/memcpy (; 5 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/util/memory/memcpy (; 9 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i32) (local $5 i32) @@ -1005,21 +1338,185 @@ local.get $0 i32.const 1 i32.add - local.tee $0 + local.tee $0 + local.get $1 + i32.const 1 + i32.add + local.tee $1 + i32.load8_u + i32.store8 + local.get $0 + i32.const 1 + i32.add + local.tee $0 + local.get $1 + i32.const 1 + i32.add + local.tee $1 + i32.load8_u + i32.store8 + local.get $0 + i32.const 1 + i32.add + local.tee $0 + local.get $1 + i32.const 1 + i32.add + local.tee $1 + i32.load8_u + i32.store8 + local.get $0 + i32.const 1 + i32.add + local.tee $0 + local.get $1 + i32.const 1 + i32.add + local.tee $1 + i32.load8_u + i32.store8 + local.get $0 + i32.const 1 + i32.add + local.tee $0 + local.get $1 + i32.const 1 + i32.add + local.tee $1 + i32.load8_u + i32.store8 + local.get $0 + i32.const 1 + i32.add + local.tee $0 + local.get $1 + i32.const 1 + i32.add + local.tee $1 + i32.load8_u + i32.store8 + local.get $0 + i32.const 1 + i32.add + local.tee $0 + local.get $1 + i32.const 1 + i32.add + local.tee $1 + i32.load8_u + i32.store8 + local.get $0 + i32.const 1 + i32.add + local.tee $3 + i32.const 1 + i32.add + local.set $0 + local.get $1 + i32.const 1 + i32.add + local.tee $4 + i32.const 1 + i32.add + local.set $1 + local.get $3 + local.get $4 + i32.load8_u + i32.store8 + end + local.get $2 + i32.const 8 + i32.and + if + local.get $0 + local.get $1 + i32.load8_u + i32.store8 + local.get $0 + i32.const 1 + i32.add + local.tee $0 + local.get $1 + i32.const 1 + i32.add + local.tee $1 + i32.load8_u + i32.store8 + local.get $0 + i32.const 1 + i32.add + local.tee $0 + local.get $1 + i32.const 1 + i32.add + local.tee $1 + i32.load8_u + i32.store8 + local.get $0 + i32.const 1 + i32.add + local.tee $0 + local.get $1 + i32.const 1 + i32.add + local.tee $1 + i32.load8_u + i32.store8 + local.get $0 + i32.const 1 + i32.add + local.tee $0 + local.get $1 + i32.const 1 + i32.add + local.tee $1 + i32.load8_u + i32.store8 + local.get $0 + i32.const 1 + i32.add + local.tee $0 + local.get $1 + i32.const 1 + i32.add + local.tee $1 + i32.load8_u + i32.store8 + local.get $0 + i32.const 1 + i32.add + local.tee $0 + local.get $1 + i32.const 1 + i32.add + local.tee $1 + i32.load8_u + i32.store8 + local.get $0 + i32.const 1 + i32.add + local.tee $3 + i32.const 1 + i32.add + local.set $0 local.get $1 i32.const 1 i32.add - local.tee $1 + local.tee $4 + i32.const 1 + i32.add + local.set $1 + local.get $3 + local.get $4 i32.load8_u i32.store8 + end + local.get $2 + i32.const 4 + i32.and + if local.get $0 - i32.const 1 - i32.add - local.tee $0 local.get $1 - i32.const 1 - i32.add - local.tee $1 i32.load8_u i32.store8 local.get $0 @@ -1045,708 +1542,983 @@ local.get $0 i32.const 1 i32.add - local.tee $0 + local.tee $3 + i32.const 1 + i32.add + local.set $0 local.get $1 i32.const 1 i32.add - local.tee $1 + local.tee $4 + i32.const 1 + i32.add + local.set $1 + local.get $3 + local.get $4 + i32.load8_u + i32.store8 + end + local.get $2 + i32.const 2 + i32.and + if + local.get $0 + local.get $1 i32.load8_u i32.store8 local.get $0 i32.const 1 i32.add - local.tee $0 + local.tee $3 + i32.const 1 + i32.add + local.set $0 local.get $1 i32.const 1 i32.add - local.tee $1 + local.tee $4 + i32.const 1 + i32.add + local.set $1 + local.get $3 + local.get $4 i32.load8_u i32.store8 + end + local.get $2 + i32.const 1 + i32.and + if local.get $0 - i32.const 1 + local.get $1 + i32.load8_u + i32.store8 + end + ) + (func $~lib/memory/memory.copy (; 10 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) + (local $3 i32) + (local $4 i32) + block $~lib/util/memory/memmove|inlined.0 + local.get $0 + local.get $1 + i32.eq + br_if $~lib/util/memory/memmove|inlined.0 + local.get $1 + local.get $2 i32.add - local.tee $0 + local.get $0 + i32.le_u + local.tee $3 + i32.eqz + if + local.get $0 + local.get $2 + i32.add + local.get $1 + i32.le_u + local.set $3 + end + local.get $3 + if + local.get $0 + local.get $1 + local.get $2 + call $~lib/util/memory/memcpy + br $~lib/util/memory/memmove|inlined.0 + end + local.get $0 + local.get $1 + i32.lt_u + if + local.get $1 + i32.const 7 + i32.and + local.get $0 + i32.const 7 + i32.and + i32.eq + if + loop $continue|0 + local.get $0 + i32.const 7 + i32.and + if + local.get $2 + i32.eqz + br_if $~lib/util/memory/memmove|inlined.0 + local.get $2 + i32.const 1 + i32.sub + local.set $2 + local.get $0 + local.tee $3 + i32.const 1 + i32.add + local.set $0 + local.get $1 + local.tee $4 + i32.const 1 + i32.add + local.set $1 + local.get $3 + local.get $4 + i32.load8_u + i32.store8 + br $continue|0 + end + end + loop $continue|1 + local.get $2 + i32.const 8 + i32.ge_u + if + local.get $0 + local.get $1 + i64.load + i64.store + local.get $2 + i32.const 8 + i32.sub + local.set $2 + local.get $0 + i32.const 8 + i32.add + local.set $0 + local.get $1 + i32.const 8 + i32.add + local.set $1 + br $continue|1 + end + end + end + loop $continue|2 + local.get $2 + if + local.get $0 + local.tee $3 + i32.const 1 + i32.add + local.set $0 + local.get $1 + local.tee $4 + i32.const 1 + i32.add + local.set $1 + local.get $3 + local.get $4 + i32.load8_u + i32.store8 + local.get $2 + i32.const 1 + i32.sub + local.set $2 + br $continue|2 + end + end + else + local.get $1 + i32.const 7 + i32.and + local.get $0 + i32.const 7 + i32.and + i32.eq + if + loop $continue|3 + local.get $0 + local.get $2 + i32.add + i32.const 7 + i32.and + if + local.get $2 + i32.eqz + br_if $~lib/util/memory/memmove|inlined.0 + local.get $2 + i32.const 1 + i32.sub + local.tee $2 + local.get $0 + i32.add + local.get $1 + local.get $2 + i32.add + i32.load8_u + i32.store8 + br $continue|3 + end + end + loop $continue|4 + local.get $2 + i32.const 8 + i32.ge_u + if + local.get $2 + i32.const 8 + i32.sub + local.tee $2 + local.get $0 + i32.add + local.get $1 + local.get $2 + i32.add + i64.load + i64.store + br $continue|4 + end + end + end + loop $continue|5 + local.get $2 + if + local.get $2 + i32.const 1 + i32.sub + local.tee $2 + local.get $0 + i32.add + local.get $1 + local.get $2 + i32.add + i32.load8_u + i32.store8 + br $continue|5 + end + end + end + end + ) + (func $~lib/memory/memory.fill (; 11 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + (local $2 i32) + block $~lib/util/memory/memset|inlined.0 local.get $1 - i32.const 1 - i32.add - local.tee $1 - i32.load8_u + i32.eqz + br_if $~lib/util/memory/memset|inlined.0 + local.get $0 + i32.const 0 i32.store8 local.get $0 - i32.const 1 - i32.add - local.tee $3 - i32.const 1 - i32.add - local.set $0 local.get $1 - i32.const 1 i32.add - local.tee $4 i32.const 1 - i32.add - local.set $1 - local.get $3 - local.get $4 - i32.load8_u + i32.sub + i32.const 0 i32.store8 - end - local.get $2 - i32.const 8 - i32.and - if - local.get $0 local.get $1 - i32.load8_u - i32.store8 + i32.const 2 + i32.le_u + br_if $~lib/util/memory/memset|inlined.0 local.get $0 i32.const 1 i32.add - local.tee $0 - local.get $1 - i32.const 1 - i32.add - local.tee $1 - i32.load8_u + i32.const 0 i32.store8 local.get $0 - i32.const 1 - i32.add - local.tee $0 - local.get $1 - i32.const 1 + i32.const 2 i32.add - local.tee $1 - i32.load8_u + i32.const 0 i32.store8 local.get $0 - i32.const 1 - i32.add - local.tee $0 local.get $1 - i32.const 1 i32.add - local.tee $1 - i32.load8_u + local.tee $2 + i32.const 2 + i32.sub + i32.const 0 + i32.store8 + local.get $2 + i32.const 3 + i32.sub + i32.const 0 i32.store8 - local.get $0 - i32.const 1 - i32.add - local.tee $0 local.get $1 - i32.const 1 + i32.const 6 + i32.le_u + br_if $~lib/util/memory/memset|inlined.0 + local.get $0 + i32.const 3 i32.add - local.tee $1 - i32.load8_u + i32.const 0 i32.store8 local.get $0 - i32.const 1 - i32.add - local.tee $0 local.get $1 - i32.const 1 i32.add - local.tee $1 - i32.load8_u + i32.const 4 + i32.sub + i32.const 0 i32.store8 + local.get $1 + i32.const 8 + i32.le_u + br_if $~lib/util/memory/memset|inlined.0 + local.get $1 + i32.const 0 + local.get $0 + i32.sub + i32.const 3 + i32.and + local.tee $1 + i32.sub + local.set $2 local.get $0 - i32.const 1 - i32.add - local.tee $0 local.get $1 - i32.const 1 i32.add + local.tee $0 + i32.const 0 + i32.store + local.get $2 + i32.const -4 + i32.and local.tee $1 - i32.load8_u - i32.store8 local.get $0 - i32.const 1 - i32.add - local.tee $3 - i32.const 1 i32.add - local.set $0 + i32.const 4 + i32.sub + i32.const 0 + i32.store local.get $1 - i32.const 1 + i32.const 8 + i32.le_u + br_if $~lib/util/memory/memset|inlined.0 + local.get $0 + i32.const 4 i32.add - local.tee $4 - i32.const 1 + i32.const 0 + i32.store + local.get $0 + i32.const 8 i32.add - local.set $1 - local.get $3 - local.get $4 - i32.load8_u - i32.store8 - end - local.get $2 - i32.const 4 - i32.and - if + i32.const 0 + i32.store local.get $0 local.get $1 - i32.load8_u - i32.store8 - local.get $0 - i32.const 1 i32.add - local.tee $0 + local.tee $2 + i32.const 12 + i32.sub + i32.const 0 + i32.store + local.get $2 + i32.const 8 + i32.sub + i32.const 0 + i32.store local.get $1 - i32.const 1 - i32.add - local.tee $1 - i32.load8_u - i32.store8 + i32.const 24 + i32.le_u + br_if $~lib/util/memory/memset|inlined.0 local.get $0 - i32.const 1 - i32.add - local.tee $0 - local.get $1 - i32.const 1 + i32.const 12 i32.add - local.tee $1 - i32.load8_u - i32.store8 + i32.const 0 + i32.store local.get $0 - i32.const 1 - i32.add - local.tee $3 - i32.const 1 + i32.const 16 i32.add - local.set $0 - local.get $1 - i32.const 1 + i32.const 0 + i32.store + local.get $0 + i32.const 20 i32.add - local.tee $4 - i32.const 1 + i32.const 0 + i32.store + local.get $0 + i32.const 24 i32.add - local.set $1 - local.get $3 - local.get $4 - i32.load8_u - i32.store8 - end - local.get $2 - i32.const 2 - i32.and - if + i32.const 0 + i32.store local.get $0 local.get $1 - i32.load8_u - i32.store8 + i32.add + local.tee $2 + i32.const 28 + i32.sub + i32.const 0 + i32.store + local.get $2 + i32.const 24 + i32.sub + i32.const 0 + i32.store + local.get $2 + i32.const 20 + i32.sub + i32.const 0 + i32.store + local.get $2 + i32.const 16 + i32.sub + i32.const 0 + i32.store local.get $0 - i32.const 1 + i32.const 4 + i32.and + i32.const 24 i32.add - local.tee $3 - i32.const 1 + local.tee $2 + local.get $0 i32.add local.set $0 local.get $1 - i32.const 1 - i32.add - local.tee $4 - i32.const 1 - i32.add + local.get $2 + i32.sub local.set $1 - local.get $3 - local.get $4 - i32.load8_u - i32.store8 - end - local.get $2 - i32.const 1 - i32.and - if - local.get $0 - local.get $1 - i32.load8_u - i32.store8 + loop $continue|0 + local.get $1 + i32.const 32 + i32.ge_u + if + local.get $0 + i64.const 0 + i64.store + local.get $0 + i32.const 8 + i32.add + i64.const 0 + i64.store + local.get $0 + i32.const 16 + i32.add + i64.const 0 + i64.store + local.get $0 + i32.const 24 + i32.add + i64.const 0 + i64.store + local.get $1 + i32.const 32 + i32.sub + local.set $1 + local.get $0 + i32.const 32 + i32.add + local.set $0 + br $continue|0 + end + end end ) - (func $~lib/memory/memory.copy (; 6 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/runtime/reallocate (; 12 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (local $2 i32) (local $3 i32) (local $4 i32) - block $~lib/util/memory/memmove|inlined.0 - local.get $0 - local.get $1 - i32.eq - br_if $~lib/util/memory/memmove|inlined.0 + (local $5 i32) + local.get $0 + i32.const 8 + i32.sub + local.tee $3 + i32.load offset=4 + local.tee $2 + local.get $1 + i32.lt_u + if + i32.const 1 + i32.const 32 local.get $1 + i32.const 7 + i32.add + i32.clz + i32.sub + i32.shl + local.tee $4 + local.set $5 + i32.const 1 + i32.const 32 local.get $2 + i32.const 7 i32.add + i32.clz + i32.sub + i32.shl + i32.const 0 local.get $0 - i32.le_u - local.tee $3 - i32.eqz + i32.const 224 + i32.gt_u + select + local.get $4 + i32.lt_u if + local.get $5 + call $~lib/allocator/arena/__mem_allocate + local.tee $4 + local.get $3 + i32.load + i32.store + local.get $4 + i32.const 8 + i32.add + local.tee $5 local.get $0 local.get $2 + call $~lib/memory/memory.copy + local.get $2 + local.get $5 i32.add local.get $1 - i32.le_u + local.get $2 + i32.sub + call $~lib/memory/memory.fill + local.get $3 + i32.load + i32.const -1520547049 + i32.eq + if + local.get $0 + i32.const 224 + i32.le_u + if + i32.const 0 + i32.const 120 + i32.const 113 + i32.const 8 + call $~lib/env/abort + unreachable + end + end + local.get $4 local.set $3 - end - local.get $3 - if + local.get $5 + local.set $0 + else local.get $0 + local.get $2 + i32.add local.get $1 local.get $2 - call $~lib/util/memory/memcpy - br $~lib/util/memory/memmove|inlined.0 + i32.sub + call $~lib/memory/memory.fill end + end + local.get $3 + local.get $1 + i32.store offset=4 + local.get $0 + ) + (func $~lib/encoding/UTF8.decodeRawDelimited (; 13 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (local $2 i32) + (local $3 i32) + (local $4 i32) + (local $5 i32) + local.get $0 + local.get $1 + i32.add + local.tee $5 + local.get $0 + i32.le_u + if + i32.const 0 + i32.const 80 + i32.const 152 + i32.const 4 + call $~lib/env/abort + unreachable + end + i32.const 16 + call $~lib/runtime/allocate + local.set $4 + loop $continue|0 local.get $0 - local.get $1 + local.get $5 i32.lt_u if - local.get $1 - i32.const 7 - i32.and - local.get $0 - i32.const 7 - i32.and - i32.eq - if - loop $continue|0 - local.get $0 - i32.const 7 - i32.and - if - local.get $2 - i32.eqz - br_if $~lib/util/memory/memmove|inlined.0 - local.get $2 - i32.const 1 - i32.sub - local.set $2 - local.get $0 - local.tee $3 - i32.const 1 - i32.add - local.set $0 - local.get $1 - local.tee $4 - i32.const 1 - i32.add - local.set $1 - local.get $3 - local.get $4 - i32.load8_u - i32.store8 - br $continue|0 - end - end - loop $continue|1 - local.get $2 - i32.const 8 - i32.ge_u - if - local.get $0 - local.get $1 - i64.load - i64.store - local.get $2 - i32.const 8 - i32.sub - local.set $2 - local.get $0 - i32.const 8 - i32.add - local.set $0 - local.get $1 - i32.const 8 - i32.add - local.set $1 - br $continue|1 - end - end - end - loop $continue|2 - local.get $2 + block $break|0 + local.get $0 + local.tee $1 + i32.const 1 + i32.add + local.set $0 + local.get $1 + i32.load8_u + local.tee $3 + i32.const 128 + i32.lt_u if - local.get $0 - local.tee $3 - i32.const 1 + local.get $3 + i32.eqz + br_if $break|0 + local.get $2 + local.get $4 + local.get $2 + i32.const 2 i32.add - local.set $0 - local.get $1 + call $~lib/runtime/reallocate local.tee $4 - i32.const 1 i32.add - local.set $1 local.get $3 - local.get $4 - i32.load8_u - i32.store8 - local.get $2 - i32.const 1 - i32.sub - local.set $2 - br $continue|2 - end - end - else - local.get $1 - i32.const 7 - i32.and - local.get $0 - i32.const 7 - i32.and - i32.eq - if - loop $continue|3 - local.get $0 + i32.store16 local.get $2 + i32.const 2 i32.add - i32.const 7 - i32.and + local.set $2 + else + local.get $3 + i32.const 191 + i32.gt_u + local.tee $1 + if + local.get $3 + i32.const 224 + i32.lt_u + local.set $1 + end + local.get $1 if - local.get $2 - i32.eqz - br_if $~lib/util/memory/memmove|inlined.0 - local.get $2 - i32.const 1 - i32.sub - local.tee $2 local.get $0 + local.get $5 + i32.ge_u + br_if $break|0 + local.get $0 + local.tee $1 + i32.const 1 i32.add - local.get $1 + local.set $0 + local.get $2 + local.get $4 local.get $2 + i32.const 2 + i32.add + call $~lib/runtime/reallocate + local.tee $4 i32.add + local.get $1 i32.load8_u - i32.store8 - br $continue|3 - end - end - loop $continue|4 - local.get $2 - i32.const 8 - i32.ge_u - if + i32.const 63 + i32.and + local.get $3 + i32.const 31 + i32.and + i32.const 6 + i32.shl + i32.or + i32.store16 local.get $2 - i32.const 8 - i32.sub - local.tee $2 - local.get $0 + i32.const 2 i32.add + local.set $2 + else + local.get $3 + i32.const 239 + i32.gt_u + local.tee $1 + if + local.get $3 + i32.const 365 + i32.lt_u + local.set $1 + end local.get $1 - local.get $2 - i32.add - i64.load - i64.store - br $continue|4 + if (result i32) + local.get $0 + i32.const 3 + i32.add + local.get $5 + i32.gt_u + br_if $break|0 + local.get $0 + i32.load8_u offset=2 + i32.const 63 + i32.and + local.get $3 + i32.const 7 + i32.and + i32.const 18 + i32.shl + local.get $0 + i32.load8_u + i32.const 63 + i32.and + i32.const 12 + i32.shl + i32.or + local.get $0 + i32.load8_u offset=1 + i32.const 63 + i32.and + i32.const 6 + i32.shl + i32.or + i32.or + i32.const 65536 + i32.sub + local.set $1 + local.get $2 + local.get $4 + local.get $2 + i32.const 4 + i32.add + call $~lib/runtime/reallocate + local.tee $4 + i32.add + local.tee $3 + local.get $1 + i32.const 10 + i32.shr_u + i32.const 55296 + i32.add + i32.store16 + local.get $3 + local.get $1 + i32.const 1023 + i32.and + i32.const 56320 + i32.add + i32.store16 offset=2 + local.get $2 + i32.const 4 + i32.add + local.set $2 + local.get $0 + i32.const 3 + i32.add + else + local.get $0 + i32.const 2 + i32.add + local.get $5 + i32.gt_u + br_if $break|0 + local.get $2 + local.get $4 + local.get $2 + i32.const 2 + i32.add + call $~lib/runtime/reallocate + local.tee $4 + i32.add + local.get $0 + i32.load8_u offset=1 + i32.const 63 + i32.and + local.get $3 + i32.const 15 + i32.and + i32.const 12 + i32.shl + local.get $0 + i32.load8_u + i32.const 63 + i32.and + i32.const 6 + i32.shl + i32.or + i32.or + i32.store16 + local.get $2 + i32.const 2 + i32.add + local.set $2 + local.get $0 + i32.const 2 + i32.add + end + local.set $0 end end - end - loop $continue|5 - local.get $2 - if - local.get $2 - i32.const 1 - i32.sub - local.tee $2 - local.get $0 - i32.add - local.get $1 - local.get $2 - i32.add - i32.load8_u - i32.store8 - br $continue|5 - end + br $continue|0 end end end - ) - (func $~lib/runtime/register (; 7 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - (local $1 i32) - local.get $0 - i32.const 228 - i32.le_u - if - i32.const 0 - i32.const 136 - i32.const 149 - i32.const 4 - call $~lib/env/abort - unreachable - end - local.get $0 - i32.const 8 - i32.sub - local.tee $1 - i32.load - i32.const -1520547049 - i32.ne - if - i32.const 0 - i32.const 136 - i32.const 151 - i32.const 4 - call $~lib/env/abort - unreachable - end - local.get $1 + local.get $4 + local.get $2 + call $~lib/runtime/reallocate i32.const 1 - i32.store - local.get $0 + call $~lib/runtime/register ) - (func $~lib/string/String.fromUTF8 (; 8 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/encoding/UTF8.decodeRaw (; 14 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) (local $5 i32) - (local $6 i32) + local.get $0 local.get $1 - i32.const 1 - i32.lt_u - if - i32.const 88 - return - end + i32.add + local.set $5 local.get $1 i32.const 1 i32.shl - call $~lib/allocator/arena/__mem_allocate - local.set $6 + call $~lib/runtime/allocate + local.tee $4 + local.set $2 loop $continue|0 - local.get $2 - local.get $1 + local.get $0 + local.get $5 i32.lt_u if - local.get $2 - local.tee $3 - i32.const 1 - i32.add - local.set $2 local.get $0 - local.get $3 + local.tee $1 + i32.const 1 i32.add + local.set $0 + local.get $1 i32.load8_u - local.tee $4 + local.tee $3 i32.const 128 i32.lt_u if - local.get $5 - local.get $6 - i32.add - local.get $4 + local.get $2 + local.get $3 i32.store16 + local.get $2 + i32.const 2 + i32.add + local.set $2 else - local.get $4 + local.get $3 i32.const 191 i32.gt_u - local.tee $3 + local.tee $1 if - local.get $4 + local.get $3 i32.const 224 i32.lt_u - local.set $3 + local.set $1 end - local.get $3 + local.get $1 if - local.get $2 + local.get $0 + local.tee $1 i32.const 1 i32.add - local.get $1 - i32.gt_u - if - i32.const 0 - i32.const 96 - i32.const 447 - i32.const 8 - call $~lib/env/abort - unreachable - end + local.set $0 local.get $2 - local.tee $3 - i32.const 1 - i32.add - local.set $2 - local.get $5 - local.get $6 - i32.add - local.get $0 - local.get $3 - i32.add + local.get $1 i32.load8_u i32.const 63 i32.and - local.get $4 + local.get $3 i32.const 31 i32.and i32.const 6 i32.shl i32.or i32.store16 + local.get $2 + i32.const 2 + i32.add + local.set $2 else - local.get $4 + local.get $3 i32.const 239 i32.gt_u - local.tee $3 + local.tee $1 if - local.get $4 + local.get $3 i32.const 365 i32.lt_u - local.set $3 + local.set $1 end - local.get $3 - if + local.get $1 + if (result i32) local.get $2 - i32.const 3 - i32.add - local.get $1 - i32.gt_u - if - i32.const 0 - i32.const 96 - i32.const 451 - i32.const 8 - call $~lib/env/abort - unreachable - end - local.get $4 + local.get $0 + i32.load8_u offset=2 + i32.const 63 + i32.and + local.get $3 i32.const 7 i32.and i32.const 18 i32.shl local.get $0 - local.get $2 - i32.add i32.load8_u i32.const 63 i32.and i32.const 12 i32.shl i32.or - local.get $2 - i32.const 1 - i32.add - local.tee $2 - local.get $0 - i32.add - i32.load8_u - i32.const 63 - i32.and - i32.const 6 - i32.shl - i32.or - local.set $3 - local.get $2 - i32.const 1 - i32.add - local.tee $4 - i32.const 1 - i32.add - local.set $2 - local.get $5 - local.get $6 - i32.add local.get $0 - local.get $4 - i32.add - i32.load8_u + i32.load8_u offset=1 i32.const 63 i32.and - local.get $3 + i32.const 6 + i32.shl + i32.or i32.or i32.const 65536 i32.sub - local.tee $3 + local.tee $1 i32.const 10 i32.shr_u i32.const 55296 i32.add i32.store16 - local.get $6 - local.get $5 - i32.const 2 - i32.add - local.tee $5 - i32.add - local.get $3 + local.get $2 + local.get $1 i32.const 1023 i32.and i32.const 56320 i32.add - i32.store16 - else + i32.store16 offset=2 local.get $2 - i32.const 2 + i32.const 4 i32.add - local.get $1 - i32.gt_u - if - i32.const 0 - i32.const 96 - i32.const 463 - i32.const 8 - call $~lib/env/abort - unreachable - end - local.get $4 + local.set $2 + local.get $0 + i32.const 3 + i32.add + else + local.get $2 + local.get $0 + i32.load8_u offset=1 + i32.const 63 + i32.and + local.get $3 i32.const 15 i32.and i32.const 12 i32.shl local.get $0 - local.get $2 - i32.add i32.load8_u i32.const 63 i32.and i32.const 6 i32.shl i32.or - local.set $3 + i32.or + i32.store16 local.get $2 - i32.const 1 - i32.add - local.tee $4 - i32.const 1 + i32.const 2 i32.add local.set $2 - local.get $5 - local.get $6 - i32.add local.get $0 - local.get $4 + i32.const 2 i32.add - i32.load8_u - i32.const 63 - i32.and - local.get $3 - i32.or - i32.store16 end + local.set $0 end end - local.get $5 - i32.const 2 - i32.add - local.set $5 br $continue|0 end end - local.get $1 + local.get $4 local.get $2 - i32.ne - if - i32.const 0 - i32.const 96 - i32.const 472 - i32.const 4 - call $~lib/env/abort - unreachable - end - local.get $5 - call $~lib/runtime/allocate - local.tee $0 - local.get $6 - local.get $5 - call $~lib/memory/memory.copy - local.get $0 + local.get $4 + i32.sub + call $~lib/runtime/reallocate + i32.const 1 call $~lib/runtime/register ) - (func $~lib/util/string/compareImpl (; 9 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $~lib/encoding/UTF8.decode (; 15 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + local.get $1 + if (result i32) + local.get $0 + local.get $0 + i32.const 8 + i32.sub + i32.load offset=4 + call $~lib/encoding/UTF8.decodeRawDelimited + else + local.get $0 + local.get $0 + i32.const 8 + i32.sub + i32.load offset=4 + call $~lib/encoding/UTF8.decodeRaw + end + ) + (func $~lib/util/string/compareImpl (; 16 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (local $3 i32) loop $continue|0 local.get $2 @@ -1779,7 +2551,7 @@ end local.get $3 ) - (func $~lib/string/String.__eq (; 10 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/string/String.__eq (; 17 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) local.get $0 local.get $1 @@ -1825,255 +2597,204 @@ call $~lib/util/string/compareImpl i32.eqz ) - (func $start:std/string-utf8 (; 11 ;) (type $FUNCSIG$v) - global.get $std/string-utf8/str - call $~lib/string/String#get:lengthUTF8 - global.set $std/string-utf8/len - global.get $std/string-utf8/len - i32.const 11 - i32.ne - if - i32.const 0 - i32.const 40 - i32.const 7 - i32.const 0 - call $~lib/env/abort - unreachable - end - i32.const 232 - global.set $~lib/allocator/arena/startOffset - global.get $~lib/allocator/arena/startOffset - global.set $~lib/allocator/arena/offset - global.get $std/string-utf8/str - call $~lib/string/String#toUTF8 - global.set $std/string-utf8/ptr - global.get $std/string-utf8/ptr - i32.load8_u - i32.const 240 - i32.ne - if - i32.const 0 - i32.const 40 - i32.const 11 - i32.const 0 - call $~lib/env/abort - unreachable - end - global.get $std/string-utf8/ptr - i32.load8_u offset=1 - i32.const 144 - i32.ne - if - i32.const 0 - i32.const 40 - i32.const 12 - i32.const 0 - call $~lib/env/abort - unreachable - end - global.get $std/string-utf8/ptr - i32.load8_u offset=2 - i32.const 144 - i32.ne - if - i32.const 0 - i32.const 40 - i32.const 13 - i32.const 0 - call $~lib/env/abort - unreachable - end - global.get $std/string-utf8/ptr - i32.load8_u offset=3 - i32.const 183 - i32.ne - if - i32.const 0 - i32.const 40 - i32.const 14 - i32.const 0 - call $~lib/env/abort - unreachable - end - global.get $std/string-utf8/ptr - i32.load8_u offset=4 - i32.const 104 - i32.ne - if - i32.const 0 - i32.const 40 - i32.const 15 - i32.const 0 - call $~lib/env/abort - unreachable - end - global.get $std/string-utf8/ptr - i32.load8_u offset=5 - i32.const 105 - i32.ne - if - i32.const 0 - i32.const 40 - i32.const 16 - i32.const 0 - call $~lib/env/abort - unreachable - end - global.get $std/string-utf8/ptr - i32.load8_u offset=6 - i32.const 240 - i32.ne + (func $std/encoding/testUTF8Decode (; 18 ;) (type $FUNCSIG$v) + global.get $std/encoding/str + i32.const 0 + call $~lib/encoding/UTF8.encode + i32.const 0 + call $~lib/encoding/UTF8.decode + global.get $std/encoding/str + call $~lib/string/String.__eq + i32.eqz if i32.const 0 i32.const 40 - i32.const 17 - i32.const 0 + i32.const 48 + i32.const 2 call $~lib/env/abort unreachable end - global.get $std/string-utf8/ptr - i32.load8_u offset=7 - i32.const 164 - i32.ne + ) + (func $std/encoding/testUTF8DecodeDelimited (; 19 ;) (type $FUNCSIG$v) + global.get $std/encoding/str + i32.const 1 + call $~lib/encoding/UTF8.encode + i32.const 1 + call $~lib/encoding/UTF8.decode + global.get $std/encoding/str + call $~lib/string/String.__eq + i32.eqz if i32.const 0 i32.const 40 - i32.const 18 - i32.const 0 + i32.const 54 + i32.const 2 call $~lib/env/abort unreachable end - global.get $std/string-utf8/ptr - i32.load8_u offset=8 - i32.const 173 - i32.ne + ) + (func $std/encoding/testUTF8Raw (; 20 ;) (type $FUNCSIG$v) + (local $0 i32) + global.get $std/encoding/str + i32.const 0 + call $~lib/encoding/UTF8.encode + local.tee $0 + i32.const 0 + call $~lib/encoding/UTF8.decodeRaw + i32.const 160 + call $~lib/string/String.__eq + i32.eqz if i32.const 0 i32.const 40 - i32.const 19 - i32.const 0 + i32.const 61 + i32.const 2 call $~lib/env/abort unreachable end - global.get $std/string-utf8/ptr - i32.load8_u offset=9 - i32.const 162 - i32.ne + local.get $0 + global.get $std/encoding/str + i32.const 0 + call $~lib/encoding/UTF8.length + call $~lib/encoding/UTF8.decodeRaw + global.get $std/encoding/str + call $~lib/string/String.__eq + i32.eqz if i32.const 0 i32.const 40 - i32.const 20 - i32.const 0 + i32.const 62 + i32.const 2 call $~lib/env/abort unreachable end - global.get $std/string-utf8/ptr - i32.load8_u offset=10 + local.get $0 + i32.const 4 + call $~lib/encoding/UTF8.decodeRaw + i32.const 168 + call $~lib/string/String.__eq + i32.eqz if i32.const 0 i32.const 40 - i32.const 21 - i32.const 0 + i32.const 63 + i32.const 2 call $~lib/env/abort unreachable end - global.get $std/string-utf8/ptr - i32.const 0 - call $~lib/string/String.fromUTF8 - i32.const 88 + local.get $0 + i32.const 4 + i32.add + i32.const 2 + call $~lib/encoding/UTF8.decodeRaw + i32.const 184 call $~lib/string/String.__eq i32.eqz if i32.const 0 i32.const 40 - i32.const 23 - i32.const 0 + i32.const 64 + i32.const 2 call $~lib/env/abort unreachable end - global.get $std/string-utf8/ptr - global.get $std/string-utf8/len - i32.const 1 - i32.sub - call $~lib/string/String.fromUTF8 - global.get $std/string-utf8/str + local.get $0 + i32.const 6 + i32.add + i32.const 4 + call $~lib/encoding/UTF8.decodeRaw + i32.const 200 call $~lib/string/String.__eq i32.eqz if i32.const 0 i32.const 40 - i32.const 24 - i32.const 0 + i32.const 65 + i32.const 2 call $~lib/env/abort unreachable end - global.get $std/string-utf8/ptr - i32.const 4 - call $~lib/string/String.fromUTF8 - i32.const 176 + local.get $0 + i32.const 10 + i32.add + i32.const 0 + call $~lib/encoding/UTF8.decodeRaw + i32.const 160 call $~lib/string/String.__eq i32.eqz if i32.const 0 i32.const 40 - i32.const 25 - i32.const 0 + i32.const 66 + i32.const 2 call $~lib/env/abort unreachable end - global.get $std/string-utf8/ptr + local.get $0 + i32.const 0 + i32.store8 offset=10 + local.get $0 i32.const 4 i32.add - i32.const 2 - call $~lib/string/String.fromUTF8 - i32.const 192 + i32.const 1073741816 + call $~lib/encoding/UTF8.decodeRawDelimited + i32.const 216 call $~lib/string/String.__eq i32.eqz if i32.const 0 i32.const 40 - i32.const 26 - i32.const 0 + i32.const 69 + i32.const 2 call $~lib/env/abort unreachable end - global.get $std/string-utf8/ptr + local.get $0 i32.const 6 i32.add - i32.const 4 - call $~lib/string/String.fromUTF8 - i32.const 208 + i32.const 1073741816 + call $~lib/encoding/UTF8.decodeRawDelimited + i32.const 200 call $~lib/string/String.__eq i32.eqz if i32.const 0 i32.const 40 - i32.const 27 - i32.const 0 + i32.const 70 + i32.const 2 call $~lib/env/abort unreachable end - global.get $std/string-utf8/ptr + local.get $0 i32.const 10 i32.add - i32.const 1 - call $~lib/string/String.fromUTF8 - i32.const 224 + i32.const 1073741816 + call $~lib/encoding/UTF8.decodeRawDelimited + i32.const 160 call $~lib/string/String.__eq i32.eqz if i32.const 0 i32.const 40 - i32.const 28 - i32.const 0 + i32.const 71 + i32.const 2 call $~lib/env/abort unreachable end ) - (func $start (; 12 ;) (type $FUNCSIG$v) - call $start:std/string-utf8 + (func $start (; 21 ;) (type $FUNCSIG$v) + call $std/encoding/testUTF8Length + i32.const 224 + global.set $~lib/allocator/arena/startOffset + global.get $~lib/allocator/arena/startOffset + global.set $~lib/allocator/arena/offset + call $std/encoding/testUTF8Encode + call $std/encoding/testUTF8EncodeDelimited + call $std/encoding/testUTF8Decode + call $std/encoding/testUTF8DecodeDelimited + call $std/encoding/testUTF8Raw ) - (func $null (; 13 ;) (type $FUNCSIG$v) + (func $null (; 22 ;) (type $FUNCSIG$v) nop ) ) diff --git a/tests/compiler/std/encoding.ts b/tests/compiler/std/encoding.ts new file mode 100644 index 0000000000..a2cc80b2c5 --- /dev/null +++ b/tests/compiler/std/encoding.ts @@ -0,0 +1,73 @@ +import "allocator/arena"; + +var str = "š·hiš¤­¢"; // -> f0 90 90 b7 68 69 f0 a4 ad a2 [00] + +function testUTF8Length(): void { + assert(UTF8.length(str) == 10); + assert(UTF8.length(str, true) == 11); +} +testUTF8Length(); + +function testUTF8Encode(): void { + var buf = UTF8.encode(str); + var ptr = changetype(buf); + assert(buf.byteLength == 10); + assert(load(ptr, 0) == 0xf0); + assert(load(ptr, 1) == 0x90); + assert(load(ptr, 2) == 0x90); + assert(load(ptr, 3) == 0xb7); + assert(load(ptr, 4) == 0x68); + assert(load(ptr, 5) == 0x69); + assert(load(ptr, 6) == 0xf0); + assert(load(ptr, 7) == 0xa4); + assert(load(ptr, 8) == 0xad); + assert(load(ptr, 9) == 0xa2); +} +testUTF8Encode(); + +function testUTF8EncodeDelimited(): void { + var buf = UTF8.encode(str, true); + var ptr = changetype(buf); + assert(buf.byteLength == 11); + assert(load(ptr, 0) == 0xf0); + assert(load(ptr, 1) == 0x90); + assert(load(ptr, 2) == 0x90); + assert(load(ptr, 3) == 0xb7); + assert(load(ptr, 4) == 0x68); + assert(load(ptr, 5) == 0x69); + assert(load(ptr, 6) == 0xf0); + assert(load(ptr, 7) == 0xa4); + assert(load(ptr, 8) == 0xad); + assert(load(ptr, 9) == 0xa2); + assert(load(ptr, 10) == 0x00); +} +testUTF8EncodeDelimited(); + +function testUTF8Decode(): void { + var buf = UTF8.encode(str); + assert(UTF8.decode(buf) == str); +} +testUTF8Decode(); + +function testUTF8DecodeDelimited(): void { + var buf = UTF8.encode(str, true); + assert(UTF8.decode(buf, true) == str); +} +testUTF8DecodeDelimited(); + +function testUTF8Raw(): void { + var buf = changetype(UTF8.encode(str)); + + assert(UTF8.decodeRaw(buf, 0) == ""); + assert(UTF8.decodeRaw(buf, UTF8.length(str)) == str); + assert(UTF8.decodeRaw(buf, 4) == "š·"); + assert(UTF8.decodeRaw(buf + 4, 2) == "hi"); + assert(UTF8.decodeRaw(buf + 6, 4) == "š¤­¢"); + assert(UTF8.decodeRaw(buf + 10, 0) == ""); + + store(buf, 0, 10); // don't try this at home + assert(UTF8.decodeRawDelimited(buf + 4) == "hiš¤­¢"); + assert(UTF8.decodeRawDelimited(buf + 6) == "š¤­¢"); + assert(UTF8.decodeRawDelimited(buf + 10) == ""); +} +testUTF8Raw(); diff --git a/tests/compiler/std/string-utf8.untouched.wat b/tests/compiler/std/encoding.untouched.wat similarity index 65% rename from tests/compiler/std/string-utf8.untouched.wat rename to tests/compiler/std/encoding.untouched.wat index 7872dcdee5..3180ad1a08 100644 --- a/tests/compiler/std/string-utf8.untouched.wat +++ b/tests/compiler/std/encoding.untouched.wat @@ -1,33 +1,32 @@ (module + (type $FUNCSIG$v (func)) + (type $FUNCSIG$iii (func (param i32 i32) (result i32))) (type $FUNCSIG$ii (func (param i32) (result i32))) (type $FUNCSIG$viiii (func (param i32 i32 i32 i32))) - (type $FUNCSIG$iii (func (param i32 i32) (result i32))) (type $FUNCSIG$viii (func (param i32 i32 i32))) (type $FUNCSIG$vi (func (param i32))) (type $FUNCSIG$iiiiii (func (param i32 i32 i32 i32 i32) (result i32))) - (type $FUNCSIG$v (func)) (import "env" "abort" (func $~lib/env/abort (param i32 i32 i32 i32))) (memory $0 1) (data (i32.const 8) "\01\00\00\00\0c\00\00\00\01\d87\dch\00i\00R\d8b\df") - (data (i32.const 32) "\01\00\00\00$\00\00\00s\00t\00d\00/\00s\00t\00r\00i\00n\00g\00-\00u\00t\00f\008\00.\00t\00s\00") - (data (i32.const 80) "\01\00\00\00\00\00\00\00") - (data (i32.const 88) "\01\00\00\00\1c\00\00\00~\00l\00i\00b\00/\00s\00t\00r\00i\00n\00g\00.\00t\00s\00") - (data (i32.const 128) "\01\00\00\00\1e\00\00\00~\00l\00i\00b\00/\00r\00u\00n\00t\00i\00m\00e\00.\00t\00s\00") - (data (i32.const 168) "\01\00\00\00\04\00\00\00\01\d87\dc") - (data (i32.const 184) "\01\00\00\00\04\00\00\00h\00i\00") - (data (i32.const 200) "\01\00\00\00\04\00\00\00R\d8b\df") - (data (i32.const 216) "\01\00\00\00\02\00\00\00\00\00") + (data (i32.const 32) "\01\00\00\00\1e\00\00\00s\00t\00d\00/\00e\00n\00c\00o\00d\00i\00n\00g\00.\00t\00s\00") + (data (i32.const 72) "\01\00\00\00 \00\00\00~\00l\00i\00b\00/\00e\00n\00c\00o\00d\00i\00n\00g\00.\00t\00s\00") + (data (i32.const 112) "\01\00\00\00\1e\00\00\00~\00l\00i\00b\00/\00r\00u\00n\00t\00i\00m\00e\00.\00t\00s\00") + (data (i32.const 152) "\01\00\00\00\00\00\00\00") + (data (i32.const 160) "\01\00\00\00\04\00\00\00\01\d87\dc") + (data (i32.const 176) "\01\00\00\00\04\00\00\00h\00i\00") + (data (i32.const 192) "\01\00\00\00\04\00\00\00R\d8b\df") + (data (i32.const 208) "\01\00\00\00\08\00\00\00h\00i\00R\d8b\df") (table $0 1 funcref) (elem (i32.const 0) $null) - (global $std/string-utf8/str (mut i32) (i32.const 16)) + (global $std/encoding/str (mut i32) (i32.const 16)) (global $~lib/runtime/HEADER_SIZE i32 (i32.const 8)) (global $~lib/runtime/HEADER_MAGIC i32 (i32.const -1520547049)) - (global $std/string-utf8/len (mut i32) (i32.const 0)) (global $~lib/allocator/arena/startOffset (mut i32) (i32.const 0)) (global $~lib/allocator/arena/offset (mut i32) (i32.const 0)) - (global $std/string-utf8/ptr (mut i32) (i32.const 0)) (global $~lib/ASC_NO_ASSERT i32 (i32.const 0)) - (global $~lib/memory/HEAP_BASE i32 (i32.const 228)) + (global $~lib/runtime/MAX_BYTELENGTH i32 (i32.const 1073741816)) + (global $~lib/memory/HEAP_BASE i32 (i32.const 224)) (export "memory" (memory $0)) (export "table" (table $0)) (start $start) @@ -39,19 +38,30 @@ i32.const 1 i32.shr_u ) - (func $~lib/string/String#get:lengthUTF8 (; 2 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - (local $1 i32) + (func $~lib/encoding/UTF8.length (; 2 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) (local $5 i32) - i32.const 1 - local.set $1 - i32.const 0 + (local $6 i32) + local.get $0 local.set $2 local.get $0 + local.get $0 call $~lib/string/String#get:length + i32.const 1 + i32.shl + i32.add local.set $3 + local.get $1 + i32.const 0 + i32.ne + if (result i32) + i32.const 1 + else + i32.const 0 + end + local.set $4 block $break|0 loop $continue|0 local.get $2 @@ -59,90 +69,77 @@ i32.lt_u if block - local.get $0 local.get $2 - i32.const 1 - i32.shl - i32.add i32.load16_u - local.set $4 - local.get $4 + local.set $5 + local.get $5 i32.const 128 i32.lt_u if - local.get $1 + local.get $4 i32.const 1 i32.add - local.set $1 + local.set $4 local.get $2 - i32.const 1 + i32.const 2 i32.add local.set $2 else - local.get $4 + local.get $5 i32.const 2048 i32.lt_u if - local.get $1 + local.get $4 i32.const 2 i32.add - local.set $1 + local.set $4 local.get $2 - i32.const 1 + i32.const 2 i32.add local.set $2 else - local.get $4 + local.get $5 i32.const 64512 i32.and i32.const 55296 i32.eq - local.tee $5 + local.tee $6 if (result i32) local.get $2 - i32.const 1 + i32.const 2 i32.add local.get $3 i32.lt_u else - local.get $5 + local.get $6 end - local.tee $5 - if (result i32) - local.get $0 + if local.get $2 - i32.const 1 - i32.add - i32.const 1 - i32.shl - i32.add - i32.load16_u + i32.load16_u offset=2 i32.const 64512 i32.and i32.const 56320 i32.eq - else - local.get $5 - end - if - local.get $1 - i32.const 4 - i32.add - local.set $1 - local.get $2 - i32.const 2 - i32.add - local.set $2 - else - local.get $1 - i32.const 3 - i32.add - local.set $1 - local.get $2 - i32.const 1 - i32.add - local.set $2 + if + local.get $2 + i32.const 4 + i32.add + local.set $2 + local.get $4 + i32.const 4 + i32.add + local.set $4 + br $continue|0 + end end + local.get $2 + i32.const 2 + i32.add + local.set $2 + local.get $4 + i32.const 3 + i32.add + local.set $4 end end end @@ -150,9 +147,51 @@ end end end - local.get $1 + local.get $4 + ) + (func $std/encoding/testUTF8Length (; 3 ;) (type $FUNCSIG$v) + global.get $std/encoding/str + i32.const 0 + call $~lib/encoding/UTF8.length + i32.const 10 + i32.eq + i32.eqz + if + i32.const 0 + i32.const 40 + i32.const 6 + i32.const 2 + call $~lib/env/abort + unreachable + end + global.get $std/encoding/str + i32.const 1 + call $~lib/encoding/UTF8.length + i32.const 11 + i32.eq + i32.eqz + if + i32.const 0 + i32.const 40 + i32.const 7 + i32.const 2 + call $~lib/env/abort + unreachable + end + ) + (func $~lib/runtime/ADJUSTOBLOCK (; 4 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + i32.const 1 + i32.const 32 + local.get $0 + global.get $~lib/runtime/HEADER_SIZE + i32.add + i32.const 1 + i32.sub + i32.clz + i32.sub + i32.shl ) - (func $~lib/allocator/arena/__mem_allocate (; 3 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/allocator/arena/__mem_allocate (; 5 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) (local $3 i32) @@ -231,13 +270,64 @@ global.set $~lib/allocator/arena/offset local.get $1 ) - (func $~lib/memory/memory.allocate (; 4 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/memory/memory.allocate (; 6 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) local.get $0 call $~lib/allocator/arena/__mem_allocate return ) - (func $~lib/string/String#toUTF8 (; 5 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/runtime/allocate (; 7 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) (local $1 i32) + local.get $0 + call $~lib/runtime/ADJUSTOBLOCK + call $~lib/memory/memory.allocate + local.set $1 + local.get $1 + global.get $~lib/runtime/HEADER_MAGIC + i32.store + local.get $1 + local.get $0 + i32.store offset=4 + local.get $1 + global.get $~lib/runtime/HEADER_SIZE + i32.add + ) + (func $~lib/runtime/register (; 8 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (local $2 i32) + local.get $0 + global.get $~lib/memory/HEAP_BASE + i32.gt_u + i32.eqz + if + i32.const 0 + i32.const 120 + i32.const 149 + i32.const 4 + call $~lib/env/abort + unreachable + end + local.get $0 + global.get $~lib/runtime/HEADER_SIZE + i32.sub + local.set $2 + local.get $2 + i32.load + global.get $~lib/runtime/HEADER_MAGIC + i32.eq + i32.eqz + if + i32.const 0 + i32.const 120 + i32.const 151 + i32.const 4 + call $~lib/env/abort + unreachable + end + local.get $2 + local.get $1 + i32.store + local.get $0 + ) + (func $~lib/encoding/UTF8.encode (; 9 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -245,16 +335,25 @@ (local $6 i32) (local $7 i32) local.get $0 - call $~lib/string/String#get:lengthUTF8 - call $~lib/memory/memory.allocate - local.set $1 - i32.const 0 local.set $2 local.get $0 + local.get $0 call $~lib/string/String#get:length + i32.const 1 + i32.shl + i32.add local.set $3 - i32.const 0 - local.set $4 + block $~lib/runtime/ALLOCATE|inlined.0 (result i32) + local.get $0 + local.get $1 + call $~lib/encoding/UTF8.length + local.set $4 + local.get $4 + call $~lib/runtime/allocate + end + local.set $5 + local.get $5 + local.set $6 block $break|0 loop $continue|0 local.get $2 @@ -262,67 +361,53 @@ i32.lt_u if block - local.get $0 local.get $2 - i32.const 1 - i32.shl - i32.add i32.load16_u - local.set $5 - local.get $5 + local.set $4 + local.get $4 i32.const 128 i32.lt_u if - local.get $1 + local.get $6 local.get $4 - i32.add - local.get $5 i32.store8 - local.get $4 + local.get $6 i32.const 1 i32.add - local.set $4 + local.set $6 local.get $2 - i32.const 1 + i32.const 2 i32.add local.set $2 else - local.get $5 + local.get $4 i32.const 2048 i32.lt_u if - local.get $1 - local.get $4 - i32.add - local.set $6 local.get $6 - local.get $5 + local.get $4 i32.const 6 i32.shr_u i32.const 192 i32.or i32.store8 local.get $6 - local.get $5 + local.get $4 i32.const 63 i32.and i32.const 128 i32.or i32.store8 offset=1 - local.get $4 + local.get $6 i32.const 2 i32.add - local.set $4 + local.set $6 local.get $2 - i32.const 1 + i32.const 2 i32.add local.set $2 else - local.get $1 local.get $4 - i32.add - local.set $6 - local.get $5 i32.const 64512 i32.and i32.const 55296 @@ -330,7 +415,7 @@ local.tee $7 if (result i32) local.get $2 - i32.const 1 + i32.const 2 i32.add local.get $3 i32.lt_u @@ -338,14 +423,8 @@ local.get $7 end if - local.get $0 local.get $2 - i32.const 1 - i32.add - i32.const 1 - i32.shl - i32.add - i32.load16_u + i32.load16_u offset=2 local.set $7 local.get $7 i32.const 64512 @@ -354,7 +433,7 @@ i32.eq if i32.const 65536 - local.get $5 + local.get $4 i32.const 1023 i32.and i32.const 10 @@ -364,16 +443,16 @@ i32.const 1023 i32.and i32.add - local.set $5 + local.set $4 local.get $6 - local.get $5 + local.get $4 i32.const 18 i32.shr_u i32.const 240 i32.or i32.store8 local.get $6 - local.get $5 + local.get $4 i32.const 12 i32.shr_u i32.const 63 @@ -382,7 +461,7 @@ i32.or i32.store8 offset=1 local.get $6 - local.get $5 + local.get $4 i32.const 6 i32.shr_u i32.const 63 @@ -391,32 +470,32 @@ i32.or i32.store8 offset=2 local.get $6 - local.get $5 + local.get $4 i32.const 63 i32.and i32.const 128 i32.or i32.store8 offset=3 - local.get $4 - i32.const 4 - i32.add - local.set $4 local.get $2 - i32.const 2 + i32.const 4 i32.add local.set $2 + local.get $6 + i32.const 4 + i32.add + local.set $6 br $continue|0 end end local.get $6 - local.get $5 + local.get $4 i32.const 12 i32.shr_u i32.const 224 i32.or i32.store8 local.get $6 - local.get $5 + local.get $4 i32.const 6 i32.shr_u i32.const 63 @@ -425,20 +504,20 @@ i32.or i32.store8 offset=1 local.get $6 - local.get $5 + local.get $4 i32.const 63 i32.and i32.const 128 i32.or i32.store8 offset=2 - local.get $4 - i32.const 3 - i32.add - local.set $4 local.get $2 - i32.const 1 + i32.const 2 i32.add local.set $2 + local.get $6 + i32.const 3 + i32.add + local.set $6 end end end @@ -446,203 +525,521 @@ end end end + local.get $2 + local.get $3 + i32.eq + i32.eqz + if + i32.const 0 + i32.const 80 + i32.const 97 + i32.const 4 + call $~lib/env/abort + unreachable + end local.get $1 - local.get $4 - i32.add i32.const 0 - i32.store8 - local.get $1 + i32.ne + if + local.get $6 + i32.const 0 + i32.store8 + end + block $~lib/runtime/REGISTER<~lib/arraybuffer/ArrayBuffer>|inlined.0 (result i32) + local.get $5 + local.set $4 + local.get $4 + i32.const 2 + call $~lib/runtime/register + end ) - (func $~lib/runtime/ADJUSTOBLOCK (; 6 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - i32.const 1 - i32.const 32 + (func $~lib/arraybuffer/ArrayBuffer#get:byteLength (; 10 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) local.get $0 global.get $~lib/runtime/HEADER_SIZE - i32.add - i32.const 1 - i32.sub - i32.clz i32.sub - i32.shl + i32.load offset=4 ) - (func $~lib/runtime/allocate (; 7 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $std/encoding/testUTF8Encode (; 11 ;) (type $FUNCSIG$v) + (local $0 i32) (local $1 i32) + global.get $std/encoding/str + i32.const 0 + call $~lib/encoding/UTF8.encode + local.set $0 local.get $0 - call $~lib/runtime/ADJUSTOBLOCK - call $~lib/memory/memory.allocate local.set $1 - local.get $1 - global.get $~lib/runtime/HEADER_MAGIC - i32.store - local.get $1 local.get $0 - i32.store offset=4 + call $~lib/arraybuffer/ArrayBuffer#get:byteLength + i32.const 10 + i32.eq + i32.eqz + if + i32.const 0 + i32.const 40 + i32.const 14 + i32.const 2 + call $~lib/env/abort + unreachable + end local.get $1 - global.get $~lib/runtime/HEADER_SIZE - i32.add - ) - (func $~lib/util/memory/memcpy (; 8 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) - (local $3 i32) - (local $4 i32) - (local $5 i32) - block $break|0 - loop $continue|0 - local.get $2 - if (result i32) - local.get $1 - i32.const 3 - i32.and - else - local.get $2 - end - if - block - block (result i32) - local.get $0 - local.tee $5 - i32.const 1 - i32.add - local.set $0 - local.get $5 - end - block (result i32) - local.get $1 - local.tee $5 - i32.const 1 - i32.add - local.set $1 - local.get $5 - end - i32.load8_u - i32.store8 - local.get $2 - i32.const 1 - i32.sub - local.set $2 - end - br $continue|0 - end - end + i32.load8_u + i32.const 240 + i32.eq + i32.eqz + if + i32.const 0 + i32.const 40 + i32.const 15 + i32.const 2 + call $~lib/env/abort + unreachable end - local.get $0 - i32.const 3 - i32.and - i32.const 0 + local.get $1 + i32.load8_u offset=1 + i32.const 144 i32.eq + i32.eqz if - block $break|1 - loop $continue|1 - local.get $2 - i32.const 16 - i32.ge_u - if - block - local.get $0 - local.get $1 - i32.load - i32.store - local.get $0 - i32.const 4 - i32.add - local.get $1 - i32.const 4 - i32.add - i32.load - i32.store - local.get $0 - i32.const 8 - i32.add - local.get $1 - i32.const 8 - i32.add - i32.load - i32.store - local.get $0 - i32.const 12 - i32.add - local.get $1 - i32.const 12 - i32.add - i32.load - i32.store - local.get $1 - i32.const 16 - i32.add - local.set $1 - local.get $0 - i32.const 16 - i32.add - local.set $0 - local.get $2 - i32.const 16 - i32.sub - local.set $2 - end - br $continue|1 - end - end - end - local.get $2 - i32.const 8 - i32.and - if - local.get $0 - local.get $1 - i32.load - i32.store - local.get $0 - i32.const 4 - i32.add - local.get $1 - i32.const 4 - i32.add - i32.load - i32.store - local.get $0 - i32.const 8 - i32.add - local.set $0 - local.get $1 - i32.const 8 - i32.add - local.set $1 - end - local.get $2 - i32.const 4 - i32.and - if - local.get $0 - local.get $1 - i32.load - i32.store - local.get $0 - i32.const 4 - i32.add - local.set $0 - local.get $1 - i32.const 4 - i32.add - local.set $1 - end - local.get $2 + i32.const 0 + i32.const 40 + i32.const 16 i32.const 2 - i32.and - if - local.get $0 - local.get $1 - i32.load16_u - i32.store16 - local.get $0 - i32.const 2 - i32.add - local.set $0 - local.get $1 - i32.const 2 - i32.add - local.set $1 - end - local.get $2 - i32.const 1 + call $~lib/env/abort + unreachable + end + local.get $1 + i32.load8_u offset=2 + i32.const 144 + i32.eq + i32.eqz + if + i32.const 0 + i32.const 40 + i32.const 17 + i32.const 2 + call $~lib/env/abort + unreachable + end + local.get $1 + i32.load8_u offset=3 + i32.const 183 + i32.eq + i32.eqz + if + i32.const 0 + i32.const 40 + i32.const 18 + i32.const 2 + call $~lib/env/abort + unreachable + end + local.get $1 + i32.load8_u offset=4 + i32.const 104 + i32.eq + i32.eqz + if + i32.const 0 + i32.const 40 + i32.const 19 + i32.const 2 + call $~lib/env/abort + unreachable + end + local.get $1 + i32.load8_u offset=5 + i32.const 105 + i32.eq + i32.eqz + if + i32.const 0 + i32.const 40 + i32.const 20 + i32.const 2 + call $~lib/env/abort + unreachable + end + local.get $1 + i32.load8_u offset=6 + i32.const 240 + i32.eq + i32.eqz + if + i32.const 0 + i32.const 40 + i32.const 21 + i32.const 2 + call $~lib/env/abort + unreachable + end + local.get $1 + i32.load8_u offset=7 + i32.const 164 + i32.eq + i32.eqz + if + i32.const 0 + i32.const 40 + i32.const 22 + i32.const 2 + call $~lib/env/abort + unreachable + end + local.get $1 + i32.load8_u offset=8 + i32.const 173 + i32.eq + i32.eqz + if + i32.const 0 + i32.const 40 + i32.const 23 + i32.const 2 + call $~lib/env/abort + unreachable + end + local.get $1 + i32.load8_u offset=9 + i32.const 162 + i32.eq + i32.eqz + if + i32.const 0 + i32.const 40 + i32.const 24 + i32.const 2 + call $~lib/env/abort + unreachable + end + ) + (func $std/encoding/testUTF8EncodeDelimited (; 12 ;) (type $FUNCSIG$v) + (local $0 i32) + (local $1 i32) + global.get $std/encoding/str + i32.const 1 + call $~lib/encoding/UTF8.encode + local.set $0 + local.get $0 + local.set $1 + local.get $0 + call $~lib/arraybuffer/ArrayBuffer#get:byteLength + i32.const 11 + i32.eq + i32.eqz + if + i32.const 0 + i32.const 40 + i32.const 31 + i32.const 2 + call $~lib/env/abort + unreachable + end + local.get $1 + i32.load8_u + i32.const 240 + i32.eq + i32.eqz + if + i32.const 0 + i32.const 40 + i32.const 32 + i32.const 2 + call $~lib/env/abort + unreachable + end + local.get $1 + i32.load8_u offset=1 + i32.const 144 + i32.eq + i32.eqz + if + i32.const 0 + i32.const 40 + i32.const 33 + i32.const 2 + call $~lib/env/abort + unreachable + end + local.get $1 + i32.load8_u offset=2 + i32.const 144 + i32.eq + i32.eqz + if + i32.const 0 + i32.const 40 + i32.const 34 + i32.const 2 + call $~lib/env/abort + unreachable + end + local.get $1 + i32.load8_u offset=3 + i32.const 183 + i32.eq + i32.eqz + if + i32.const 0 + i32.const 40 + i32.const 35 + i32.const 2 + call $~lib/env/abort + unreachable + end + local.get $1 + i32.load8_u offset=4 + i32.const 104 + i32.eq + i32.eqz + if + i32.const 0 + i32.const 40 + i32.const 36 + i32.const 2 + call $~lib/env/abort + unreachable + end + local.get $1 + i32.load8_u offset=5 + i32.const 105 + i32.eq + i32.eqz + if + i32.const 0 + i32.const 40 + i32.const 37 + i32.const 2 + call $~lib/env/abort + unreachable + end + local.get $1 + i32.load8_u offset=6 + i32.const 240 + i32.eq + i32.eqz + if + i32.const 0 + i32.const 40 + i32.const 38 + i32.const 2 + call $~lib/env/abort + unreachable + end + local.get $1 + i32.load8_u offset=7 + i32.const 164 + i32.eq + i32.eqz + if + i32.const 0 + i32.const 40 + i32.const 39 + i32.const 2 + call $~lib/env/abort + unreachable + end + local.get $1 + i32.load8_u offset=8 + i32.const 173 + i32.eq + i32.eqz + if + i32.const 0 + i32.const 40 + i32.const 40 + i32.const 2 + call $~lib/env/abort + unreachable + end + local.get $1 + i32.load8_u offset=9 + i32.const 162 + i32.eq + i32.eqz + if + i32.const 0 + i32.const 40 + i32.const 41 + i32.const 2 + call $~lib/env/abort + unreachable + end + local.get $1 + i32.load8_u offset=10 + i32.const 0 + i32.eq + i32.eqz + if + i32.const 0 + i32.const 40 + i32.const 42 + i32.const 2 + call $~lib/env/abort + unreachable + end + ) + (func $~lib/util/memory/memcpy (; 13 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) + (local $3 i32) + (local $4 i32) + (local $5 i32) + block $break|0 + loop $continue|0 + local.get $2 + if (result i32) + local.get $1 + i32.const 3 + i32.and + else + local.get $2 + end + if + block + block (result i32) + local.get $0 + local.tee $5 + i32.const 1 + i32.add + local.set $0 + local.get $5 + end + block (result i32) + local.get $1 + local.tee $5 + i32.const 1 + i32.add + local.set $1 + local.get $5 + end + i32.load8_u + i32.store8 + local.get $2 + i32.const 1 + i32.sub + local.set $2 + end + br $continue|0 + end + end + end + local.get $0 + i32.const 3 + i32.and + i32.const 0 + i32.eq + if + block $break|1 + loop $continue|1 + local.get $2 + i32.const 16 + i32.ge_u + if + block + local.get $0 + local.get $1 + i32.load + i32.store + local.get $0 + i32.const 4 + i32.add + local.get $1 + i32.const 4 + i32.add + i32.load + i32.store + local.get $0 + i32.const 8 + i32.add + local.get $1 + i32.const 8 + i32.add + i32.load + i32.store + local.get $0 + i32.const 12 + i32.add + local.get $1 + i32.const 12 + i32.add + i32.load + i32.store + local.get $1 + i32.const 16 + i32.add + local.set $1 + local.get $0 + i32.const 16 + i32.add + local.set $0 + local.get $2 + i32.const 16 + i32.sub + local.set $2 + end + br $continue|1 + end + end + end + local.get $2 + i32.const 8 + i32.and + if + local.get $0 + local.get $1 + i32.load + i32.store + local.get $0 + i32.const 4 + i32.add + local.get $1 + i32.const 4 + i32.add + i32.load + i32.store + local.get $0 + i32.const 8 + i32.add + local.set $0 + local.get $1 + i32.const 8 + i32.add + local.set $1 + end + local.get $2 + i32.const 4 + i32.and + if + local.get $0 + local.get $1 + i32.load + i32.store + local.get $0 + i32.const 4 + i32.add + local.set $0 + local.get $1 + i32.const 4 + i32.add + local.set $1 + end + local.get $2 + i32.const 2 + i32.and + if + local.get $0 + local.get $1 + i32.load16_u + i32.store16 + local.get $0 + i32.const 2 + i32.add + local.set $0 + local.get $1 + i32.const 2 + i32.add + local.set $1 + end + local.get $2 + i32.const 1 i32.and if block (result i32) @@ -1390,11 +1787,196 @@ end i32.load8_u i32.store8 - end - local.get $2 - i32.const 8 - i32.and - if + end + local.get $2 + i32.const 8 + i32.and + if + block (result i32) + local.get $0 + local.tee $5 + i32.const 1 + i32.add + local.set $0 + local.get $5 + end + block (result i32) + local.get $1 + local.tee $5 + i32.const 1 + i32.add + local.set $1 + local.get $5 + end + i32.load8_u + i32.store8 + block (result i32) + local.get $0 + local.tee $5 + i32.const 1 + i32.add + local.set $0 + local.get $5 + end + block (result i32) + local.get $1 + local.tee $5 + i32.const 1 + i32.add + local.set $1 + local.get $5 + end + i32.load8_u + i32.store8 + block (result i32) + local.get $0 + local.tee $5 + i32.const 1 + i32.add + local.set $0 + local.get $5 + end + block (result i32) + local.get $1 + local.tee $5 + i32.const 1 + i32.add + local.set $1 + local.get $5 + end + i32.load8_u + i32.store8 + block (result i32) + local.get $0 + local.tee $5 + i32.const 1 + i32.add + local.set $0 + local.get $5 + end + block (result i32) + local.get $1 + local.tee $5 + i32.const 1 + i32.add + local.set $1 + local.get $5 + end + i32.load8_u + i32.store8 + block (result i32) + local.get $0 + local.tee $5 + i32.const 1 + i32.add + local.set $0 + local.get $5 + end + block (result i32) + local.get $1 + local.tee $5 + i32.const 1 + i32.add + local.set $1 + local.get $5 + end + i32.load8_u + i32.store8 + block (result i32) + local.get $0 + local.tee $5 + i32.const 1 + i32.add + local.set $0 + local.get $5 + end + block (result i32) + local.get $1 + local.tee $5 + i32.const 1 + i32.add + local.set $1 + local.get $5 + end + i32.load8_u + i32.store8 + block (result i32) + local.get $0 + local.tee $5 + i32.const 1 + i32.add + local.set $0 + local.get $5 + end + block (result i32) + local.get $1 + local.tee $5 + i32.const 1 + i32.add + local.set $1 + local.get $5 + end + i32.load8_u + i32.store8 + block (result i32) + local.get $0 + local.tee $5 + i32.const 1 + i32.add + local.set $0 + local.get $5 + end + block (result i32) + local.get $1 + local.tee $5 + i32.const 1 + i32.add + local.set $1 + local.get $5 + end + i32.load8_u + i32.store8 + end + local.get $2 + i32.const 4 + i32.and + if + block (result i32) + local.get $0 + local.tee $5 + i32.const 1 + i32.add + local.set $0 + local.get $5 + end + block (result i32) + local.get $1 + local.tee $5 + i32.const 1 + i32.add + local.set $1 + local.get $5 + end + i32.load8_u + i32.store8 + block (result i32) + local.get $0 + local.tee $5 + i32.const 1 + i32.add + local.set $0 + local.get $5 + end + block (result i32) + local.get $1 + local.tee $5 + i32.const 1 + i32.add + local.set $1 + local.get $5 + end + i32.load8_u + i32.store8 block (result i32) local.get $0 local.tee $5 @@ -1431,6 +2013,11 @@ end i32.load8_u i32.store8 + end + local.get $2 + i32.const 2 + i32.and + if block (result i32) local.get $0 local.tee $5 @@ -1467,6 +2054,11 @@ end i32.load8_u i32.store8 + end + local.get $2 + i32.const 1 + i32.and + if block (result i32) local.get $0 local.tee $5 @@ -1475,761 +2067,1087 @@ local.set $0 local.get $5 end - block (result i32) - local.get $1 - local.tee $5 - i32.const 1 - i32.add - local.set $1 - local.get $5 + block (result i32) + local.get $1 + local.tee $5 + i32.const 1 + i32.add + local.set $1 + local.get $5 + end + i32.load8_u + i32.store8 + end + ) + (func $~lib/memory/memory.copy (; 14 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) + (local $3 i32) + (local $4 i32) + (local $5 i32) + block $~lib/util/memory/memmove|inlined.0 + local.get $0 + local.get $1 + i32.eq + if + br $~lib/util/memory/memmove|inlined.0 + end + local.get $1 + local.get $2 + i32.add + local.get $0 + i32.le_u + local.tee $5 + if (result i32) + local.get $5 + else + local.get $0 + local.get $2 + i32.add + local.get $1 + i32.le_u + end + if + local.get $0 + local.get $1 + local.get $2 + call $~lib/util/memory/memcpy + br $~lib/util/memory/memmove|inlined.0 + end + local.get $0 + local.get $1 + i32.lt_u + if + local.get $1 + i32.const 7 + i32.and + local.get $0 + i32.const 7 + i32.and + i32.eq + if + block $break|0 + loop $continue|0 + local.get $0 + i32.const 7 + i32.and + if + block + local.get $2 + i32.eqz + if + br $~lib/util/memory/memmove|inlined.0 + end + local.get $2 + i32.const 1 + i32.sub + local.set $2 + block (result i32) + local.get $0 + local.tee $5 + i32.const 1 + i32.add + local.set $0 + local.get $5 + end + block (result i32) + local.get $1 + local.tee $5 + i32.const 1 + i32.add + local.set $1 + local.get $5 + end + i32.load8_u + i32.store8 + end + br $continue|0 + end + end + end + block $break|1 + loop $continue|1 + local.get $2 + i32.const 8 + i32.ge_u + if + block + local.get $0 + local.get $1 + i64.load + i64.store + local.get $2 + i32.const 8 + i32.sub + local.set $2 + local.get $0 + i32.const 8 + i32.add + local.set $0 + local.get $1 + i32.const 8 + i32.add + local.set $1 + end + br $continue|1 + end + end + end + end + block $break|2 + loop $continue|2 + local.get $2 + if + block + block (result i32) + local.get $0 + local.tee $5 + i32.const 1 + i32.add + local.set $0 + local.get $5 + end + block (result i32) + local.get $1 + local.tee $5 + i32.const 1 + i32.add + local.set $1 + local.get $5 + end + i32.load8_u + i32.store8 + local.get $2 + i32.const 1 + i32.sub + local.set $2 + end + br $continue|2 + end + end + end + else + local.get $1 + i32.const 7 + i32.and + local.get $0 + i32.const 7 + i32.and + i32.eq + if + block $break|3 + loop $continue|3 + local.get $0 + local.get $2 + i32.add + i32.const 7 + i32.and + if + block + local.get $2 + i32.eqz + if + br $~lib/util/memory/memmove|inlined.0 + end + local.get $0 + local.get $2 + i32.const 1 + i32.sub + local.tee $2 + i32.add + local.get $1 + local.get $2 + i32.add + i32.load8_u + i32.store8 + end + br $continue|3 + end + end + end + block $break|4 + loop $continue|4 + local.get $2 + i32.const 8 + i32.ge_u + if + block + local.get $2 + i32.const 8 + i32.sub + local.set $2 + local.get $0 + local.get $2 + i32.add + local.get $1 + local.get $2 + i32.add + i64.load + i64.store + end + br $continue|4 + end + end + end + end + block $break|5 + loop $continue|5 + local.get $2 + if + local.get $0 + local.get $2 + i32.const 1 + i32.sub + local.tee $2 + i32.add + local.get $1 + local.get $2 + i32.add + i32.load8_u + i32.store8 + br $continue|5 + end + end + end + end + end + ) + (func $~lib/memory/memory.fill (; 15 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) + (local $3 i32) + (local $4 i32) + (local $5 i32) + (local $6 i64) + block $~lib/util/memory/memset|inlined.0 + local.get $2 + i32.eqz + if + br $~lib/util/memory/memset|inlined.0 end - i32.load8_u + local.get $0 + local.get $1 i32.store8 - block (result i32) - local.get $0 - local.tee $5 - i32.const 1 - i32.add - local.set $0 - local.get $5 + local.get $0 + local.get $2 + i32.add + i32.const 1 + i32.sub + local.get $1 + i32.store8 + local.get $2 + i32.const 2 + i32.le_u + if + br $~lib/util/memory/memset|inlined.0 end - block (result i32) - local.get $1 - local.tee $5 - i32.const 1 - i32.add - local.set $1 - local.get $5 + local.get $0 + i32.const 1 + i32.add + local.get $1 + i32.store8 + local.get $0 + i32.const 2 + i32.add + local.get $1 + i32.store8 + local.get $0 + local.get $2 + i32.add + i32.const 2 + i32.sub + local.get $1 + i32.store8 + local.get $0 + local.get $2 + i32.add + i32.const 3 + i32.sub + local.get $1 + i32.store8 + local.get $2 + i32.const 6 + i32.le_u + if + br $~lib/util/memory/memset|inlined.0 end - i32.load8_u + local.get $0 + i32.const 3 + i32.add + local.get $1 i32.store8 - block (result i32) - local.get $0 - local.tee $5 - i32.const 1 - i32.add - local.set $0 - local.get $5 + local.get $0 + local.get $2 + i32.add + i32.const 4 + i32.sub + local.get $1 + i32.store8 + local.get $2 + i32.const 8 + i32.le_u + if + br $~lib/util/memory/memset|inlined.0 end - block (result i32) - local.get $1 - local.tee $5 - i32.const 1 - i32.add - local.set $1 - local.get $5 + i32.const 0 + local.get $0 + i32.sub + i32.const 3 + i32.and + local.set $5 + local.get $0 + local.get $5 + i32.add + local.set $0 + local.get $2 + local.get $5 + i32.sub + local.set $2 + local.get $2 + i32.const -4 + i32.and + local.set $2 + i32.const -1 + i32.const 255 + i32.div_u + local.get $1 + i32.const 255 + i32.and + i32.mul + local.set $4 + local.get $0 + local.get $4 + i32.store + local.get $0 + local.get $2 + i32.add + i32.const 4 + i32.sub + local.get $4 + i32.store + local.get $2 + i32.const 8 + i32.le_u + if + br $~lib/util/memory/memset|inlined.0 end - i32.load8_u - i32.store8 - block (result i32) - local.get $0 - local.tee $5 - i32.const 1 - i32.add - local.set $0 - local.get $5 + local.get $0 + i32.const 4 + i32.add + local.get $4 + i32.store + local.get $0 + i32.const 8 + i32.add + local.get $4 + i32.store + local.get $0 + local.get $2 + i32.add + i32.const 12 + i32.sub + local.get $4 + i32.store + local.get $0 + local.get $2 + i32.add + i32.const 8 + i32.sub + local.get $4 + i32.store + local.get $2 + i32.const 24 + i32.le_u + if + br $~lib/util/memory/memset|inlined.0 end - block (result i32) - local.get $1 - local.tee $5 - i32.const 1 - i32.add - local.set $1 - local.get $5 + local.get $0 + i32.const 12 + i32.add + local.get $4 + i32.store + local.get $0 + i32.const 16 + i32.add + local.get $4 + i32.store + local.get $0 + i32.const 20 + i32.add + local.get $4 + i32.store + local.get $0 + i32.const 24 + i32.add + local.get $4 + i32.store + local.get $0 + local.get $2 + i32.add + i32.const 28 + i32.sub + local.get $4 + i32.store + local.get $0 + local.get $2 + i32.add + i32.const 24 + i32.sub + local.get $4 + i32.store + local.get $0 + local.get $2 + i32.add + i32.const 20 + i32.sub + local.get $4 + i32.store + local.get $0 + local.get $2 + i32.add + i32.const 16 + i32.sub + local.get $4 + i32.store + i32.const 24 + local.get $0 + i32.const 4 + i32.and + i32.add + local.set $5 + local.get $0 + local.get $5 + i32.add + local.set $0 + local.get $2 + local.get $5 + i32.sub + local.set $2 + local.get $4 + i64.extend_i32_u + local.get $4 + i64.extend_i32_u + i64.const 32 + i64.shl + i64.or + local.set $6 + block $break|0 + loop $continue|0 + local.get $2 + i32.const 32 + i32.ge_u + if + block + local.get $0 + local.get $6 + i64.store + local.get $0 + i32.const 8 + i32.add + local.get $6 + i64.store + local.get $0 + i32.const 16 + i32.add + local.get $6 + i64.store + local.get $0 + i32.const 24 + i32.add + local.get $6 + i64.store + local.get $2 + i32.const 32 + i32.sub + local.set $2 + local.get $0 + i32.const 32 + i32.add + local.set $0 + end + br $continue|0 + end + end end - i32.load8_u - i32.store8 end + ) + (func $~lib/allocator/arena/__mem_free (; 16 ;) (type $FUNCSIG$vi) (param $0 i32) + nop + ) + (func $~lib/memory/memory.free (; 17 ;) (type $FUNCSIG$vi) (param $0 i32) + local.get $0 + call $~lib/allocator/arena/__mem_free + ) + (func $~lib/runtime/reallocate (; 18 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (local $2 i32) + (local $3 i32) + (local $4 i32) + (local $5 i32) + (local $6 i32) + local.get $0 + global.get $~lib/runtime/HEADER_SIZE + i32.sub + local.set $2 local.get $2 - i32.const 4 - i32.and + i32.load offset=4 + local.set $3 + local.get $3 + local.get $1 + i32.lt_u if - block (result i32) - local.get $0 - local.tee $5 - i32.const 1 - i32.add - local.set $0 - local.get $5 - end - block (result i32) - local.get $1 - local.tee $5 - i32.const 1 - i32.add - local.set $1 - local.get $5 - end - i32.load8_u - i32.store8 - block (result i32) - local.get $0 - local.tee $5 - i32.const 1 - i32.add - local.set $0 - local.get $5 - end - block (result i32) - local.get $1 - local.tee $5 - i32.const 1 - i32.add - local.set $1 + local.get $1 + call $~lib/runtime/ADJUSTOBLOCK + local.set $4 + local.get $3 + call $~lib/runtime/ADJUSTOBLOCK + i32.const 0 + local.get $0 + global.get $~lib/memory/HEAP_BASE + i32.gt_u + select + local.get $4 + i32.lt_u + if + local.get $4 + call $~lib/memory/memory.allocate + local.set $5 local.get $5 - end - i32.load8_u - i32.store8 - block (result i32) - local.get $0 - local.tee $5 - i32.const 1 - i32.add - local.set $0 + local.get $2 + i32.load + i32.store local.get $5 - end - block (result i32) - local.get $1 - local.tee $5 - i32.const 1 + global.get $~lib/runtime/HEADER_SIZE i32.add - local.set $1 - local.get $5 - end - i32.load8_u - i32.store8 - block (result i32) + local.set $6 + local.get $6 local.get $0 - local.tee $5 - i32.const 1 + local.get $3 + call $~lib/memory/memory.copy + local.get $6 + local.get $3 i32.add - local.set $0 - local.get $5 - end - block (result i32) + i32.const 0 local.get $1 - local.tee $5 - i32.const 1 - i32.add - local.set $1 + local.get $3 + i32.sub + call $~lib/memory/memory.fill + local.get $2 + i32.load + global.get $~lib/runtime/HEADER_MAGIC + i32.eq + if + local.get $0 + global.get $~lib/memory/HEAP_BASE + i32.gt_u + i32.eqz + if + i32.const 0 + i32.const 120 + i32.const 113 + i32.const 8 + call $~lib/env/abort + unreachable + end + local.get $2 + call $~lib/memory/memory.free + else + nop + end local.get $5 - end - i32.load8_u - i32.store8 - end - local.get $2 - i32.const 2 - i32.and - if - block (result i32) - local.get $0 - local.tee $5 - i32.const 1 - i32.add + local.set $2 + local.get $6 local.set $0 - local.get $5 - end - block (result i32) - local.get $1 - local.tee $5 - i32.const 1 - i32.add - local.set $1 - local.get $5 - end - i32.load8_u - i32.store8 - block (result i32) + else local.get $0 - local.tee $5 - i32.const 1 + local.get $3 i32.add - local.set $0 - local.get $5 - end - block (result i32) + i32.const 0 local.get $1 - local.tee $5 - i32.const 1 - i32.add - local.set $1 - local.get $5 + local.get $3 + i32.sub + call $~lib/memory/memory.fill end - i32.load8_u - i32.store8 + else + nop end local.get $2 - i32.const 1 - i32.and - if - block (result i32) - local.get $0 - local.tee $5 - i32.const 1 - i32.add - local.set $0 - local.get $5 - end - block (result i32) - local.get $1 - local.tee $5 - i32.const 1 - i32.add - local.set $1 - local.get $5 - end - i32.load8_u - i32.store8 - end + local.get $1 + i32.store offset=4 + local.get $0 ) - (func $~lib/memory/memory.copy (; 9 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/encoding/UTF8.decodeRawDelimited (; 19 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (local $2 i32) (local $3 i32) (local $4 i32) (local $5 i32) - block $~lib/util/memory/memmove|inlined.0 - local.get $0 - local.get $1 - i32.eq - if - br $~lib/util/memory/memmove|inlined.0 - end - local.get $1 - local.get $2 - i32.add - local.get $0 - i32.le_u - local.tee $5 - if (result i32) - local.get $5 - else - local.get $0 - local.get $2 - i32.add - local.get $1 - i32.le_u - end - if - local.get $0 - local.get $1 + (local $6 i32) + (local $7 i32) + (local $8 i32) + local.get $0 + local.set $2 + local.get $0 + local.get $1 + i32.add + local.set $3 + local.get $3 + local.get $2 + i32.gt_u + i32.eqz + if + i32.const 0 + i32.const 80 + i32.const 152 + i32.const 4 + call $~lib/env/abort + unreachable + end + block $~lib/runtime/ALLOCATE|inlined.1 (result i32) + i32.const 16 + local.set $4 + local.get $4 + call $~lib/runtime/allocate + end + local.set $5 + i32.const 0 + local.set $6 + block $break|0 + loop $continue|0 local.get $2 - call $~lib/util/memory/memcpy - br $~lib/util/memory/memmove|inlined.0 - end - local.get $0 - local.get $1 - i32.lt_u - if - local.get $1 - i32.const 7 - i32.and - local.get $0 - i32.const 7 - i32.and - i32.eq - if - block $break|0 - loop $continue|0 - local.get $0 - i32.const 7 - i32.and + local.get $3 + i32.lt_u + if + block + block (result i32) + local.get $2 + local.tee $4 + i32.const 1 + i32.add + local.set $2 + local.get $4 + end + i32.load8_u + local.set $4 + local.get $4 + i32.const 128 + i32.lt_u + if + local.get $4 + i32.eqz if - block + br $break|0 + end + block $~lib/runtime/REALLOCATE|inlined.0 (result i32) + local.get $5 + local.set $8 + local.get $6 + i32.const 2 + i32.add + local.set $7 + local.get $8 + local.get $7 + call $~lib/runtime/reallocate + end + local.set $5 + local.get $5 + local.get $6 + i32.add + local.get $4 + i32.store16 + local.get $6 + i32.const 2 + i32.add + local.set $6 + else + local.get $4 + i32.const 191 + i32.gt_u + local.tee $7 + if (result i32) + local.get $4 + i32.const 224 + i32.lt_u + else + local.get $7 + end + if + local.get $2 + local.get $3 + i32.ge_u + if + br $break|0 + end + block $~lib/runtime/REALLOCATE|inlined.1 (result i32) + local.get $5 + local.set $8 + local.get $6 + i32.const 2 + i32.add + local.set $7 + local.get $8 + local.get $7 + call $~lib/runtime/reallocate + end + local.set $5 + local.get $5 + local.get $6 + i32.add + local.get $4 + i32.const 31 + i32.and + i32.const 6 + i32.shl + block (result i32) local.get $2 - i32.eqz + local.tee $7 + i32.const 1 + i32.add + local.set $2 + local.get $7 + end + i32.load8_u + i32.const 63 + i32.and + i32.or + i32.store16 + local.get $6 + i32.const 2 + i32.add + local.set $6 + else + local.get $4 + i32.const 239 + i32.gt_u + local.tee $7 + if (result i32) + local.get $4 + i32.const 365 + i32.lt_u + else + local.get $7 + end + if + local.get $2 + i32.const 3 + i32.add + local.get $3 + i32.gt_u if - br $~lib/util/memory/memmove|inlined.0 + br $break|0 end + local.get $4 + i32.const 7 + i32.and + i32.const 18 + i32.shl local.get $2 - i32.const 1 + i32.load8_u + i32.const 63 + i32.and + i32.const 12 + i32.shl + i32.or + local.get $2 + i32.load8_u offset=1 + i32.const 63 + i32.and + i32.const 6 + i32.shl + i32.or + local.get $2 + i32.load8_u offset=2 + i32.const 63 + i32.and + i32.or + i32.const 65536 i32.sub + local.set $4 + local.get $2 + i32.const 3 + i32.add local.set $2 - block (result i32) - local.get $0 - local.tee $5 - i32.const 1 - i32.add - local.set $0 + block $~lib/runtime/REALLOCATE|inlined.2 (result i32) local.get $5 - end - block (result i32) - local.get $1 - local.tee $5 - i32.const 1 + local.set $8 + local.get $6 + i32.const 4 i32.add - local.set $1 - local.get $5 + local.set $7 + local.get $8 + local.get $7 + call $~lib/runtime/reallocate end - i32.load8_u - i32.store8 - end - br $continue|0 - end - end - end - block $break|1 - loop $continue|1 - local.get $2 - i32.const 8 - i32.ge_u - if - block - local.get $0 - local.get $1 - i64.load - i64.store - local.get $2 - i32.const 8 - i32.sub - local.set $2 - local.get $0 - i32.const 8 + local.set $5 + local.get $5 + local.get $6 i32.add - local.set $0 - local.get $1 - i32.const 8 + local.set $7 + local.get $7 + i32.const 55296 + local.get $4 + i32.const 10 + i32.shr_u i32.add - local.set $1 - end - br $continue|1 - end - end - end - end - block $break|2 - loop $continue|2 - local.get $2 - if - block - block (result i32) - local.get $0 - local.tee $5 - i32.const 1 + i32.store16 + local.get $7 + i32.const 56320 + local.get $4 + i32.const 1023 + i32.and i32.add - local.set $0 - local.get $5 - end - block (result i32) - local.get $1 - local.tee $5 - i32.const 1 + i32.store16 offset=2 + local.get $6 + i32.const 4 i32.add - local.set $1 - local.get $5 - end - i32.load8_u - i32.store8 - local.get $2 - i32.const 1 - i32.sub - local.set $2 - end - br $continue|2 - end - end - end - else - local.get $1 - i32.const 7 - i32.and - local.get $0 - i32.const 7 - i32.and - i32.eq - if - block $break|3 - loop $continue|3 - local.get $0 - local.get $2 - i32.add - i32.const 7 - i32.and - if - block + local.set $6 + else local.get $2 - i32.eqz + i32.const 2 + i32.add + local.get $3 + i32.gt_u if - br $~lib/util/memory/memmove|inlined.0 + br $break|0 end - local.get $0 - local.get $2 - i32.const 1 - i32.sub - local.tee $2 + block $~lib/runtime/REALLOCATE|inlined.3 (result i32) + local.get $5 + local.set $8 + local.get $6 + i32.const 2 + i32.add + local.set $7 + local.get $8 + local.get $7 + call $~lib/runtime/reallocate + end + local.set $5 + local.get $5 + local.get $6 i32.add - local.get $1 + local.get $4 + i32.const 15 + i32.and + i32.const 12 + i32.shl local.get $2 - i32.add i32.load8_u - i32.store8 - end - br $continue|3 - end - end - end - block $break|4 - loop $continue|4 - local.get $2 - i32.const 8 - i32.ge_u - if - block + i32.const 63 + i32.and + i32.const 6 + i32.shl + i32.or local.get $2 - i32.const 8 - i32.sub - local.set $2 - local.get $0 + i32.load8_u offset=1 + i32.const 63 + i32.and + i32.or + i32.store16 local.get $2 + i32.const 2 i32.add - local.get $1 - local.get $2 + local.set $2 + local.get $6 + i32.const 2 i32.add - i64.load - i64.store + local.set $6 end - br $continue|4 end end end - end - block $break|5 - loop $continue|5 - local.get $2 - if - local.get $0 - local.get $2 - i32.const 1 - i32.sub - local.tee $2 - i32.add - local.get $1 - local.get $2 - i32.add - i32.load8_u - i32.store8 - br $continue|5 - end - end + br $continue|0 end end end - ) - (func $~lib/allocator/arena/__mem_free (; 10 ;) (type $FUNCSIG$vi) (param $0 i32) - nop - ) - (func $~lib/memory/memory.free (; 11 ;) (type $FUNCSIG$vi) (param $0 i32) - local.get $0 - call $~lib/allocator/arena/__mem_free - ) - (func $~lib/runtime/register (; 12 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) - (local $2 i32) - local.get $0 - global.get $~lib/memory/HEAP_BASE - i32.gt_u - i32.eqz - if - i32.const 0 - i32.const 136 - i32.const 149 - i32.const 4 - call $~lib/env/abort - unreachable - end - local.get $0 - global.get $~lib/runtime/HEADER_SIZE - i32.sub - local.set $2 - local.get $2 - i32.load - global.get $~lib/runtime/HEADER_MAGIC - i32.eq - i32.eqz - if - i32.const 0 - i32.const 136 - i32.const 151 - i32.const 4 - call $~lib/env/abort - unreachable + block $~lib/runtime/REGISTER<~lib/string/String>|inlined.0 (result i32) + block $~lib/runtime/REALLOCATE|inlined.4 (result i32) + local.get $5 + local.set $8 + local.get $6 + local.set $7 + local.get $8 + local.get $7 + call $~lib/runtime/reallocate + end + local.set $4 + local.get $4 + i32.const 1 + call $~lib/runtime/register end - local.get $2 - local.get $1 - i32.store - local.get $0 ) - (func $~lib/string/String.fromUTF8 (; 13 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/encoding/UTF8.decodeRaw (; 20 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) (local $5 i32) (local $6 i32) (local $7 i32) - local.get $1 - i32.const 1 - i32.lt_u - if - i32.const 88 - return - end - i32.const 0 + (local $8 i32) + local.get $0 local.set $2 + local.get $0 local.get $1 - i32.const 1 - i32.shl - call $~lib/memory/memory.allocate + i32.add local.set $3 - i32.const 0 - local.set $4 + block $~lib/runtime/ALLOCATE|inlined.2 (result i32) + local.get $1 + i32.const 1 + i32.shl + local.set $4 + local.get $4 + call $~lib/runtime/allocate + end + local.set $5 + local.get $5 + local.set $6 block $break|0 loop $continue|0 local.get $2 - local.get $1 + local.get $3 i32.lt_u if block - local.get $0 block (result i32) local.get $2 - local.tee $5 + local.tee $4 i32.const 1 i32.add local.set $2 - local.get $5 + local.get $4 end - i32.add i32.load8_u - local.set $5 - local.get $5 + local.set $4 + local.get $4 i32.const 128 i32.lt_u if - local.get $3 + local.get $6 local.get $4 - i32.add - local.get $5 i32.store16 - local.get $4 + local.get $6 i32.const 2 i32.add - local.set $4 + local.set $6 else - local.get $5 + local.get $4 i32.const 191 i32.gt_u - local.tee $6 + local.tee $7 if (result i32) - local.get $5 + local.get $4 i32.const 224 i32.lt_u else - local.get $6 + local.get $7 end if - local.get $2 - i32.const 1 - i32.add - local.get $1 - i32.le_u - i32.eqz - if - i32.const 0 - i32.const 96 - i32.const 447 - i32.const 8 - call $~lib/env/abort - unreachable - end - local.get $3 + local.get $6 local.get $4 - i32.add - local.get $5 i32.const 31 i32.and i32.const 6 i32.shl - local.get $0 block (result i32) local.get $2 - local.tee $6 + local.tee $7 i32.const 1 i32.add local.set $2 - local.get $6 + local.get $7 end - i32.add i32.load8_u i32.const 63 i32.and i32.or i32.store16 - local.get $4 + local.get $6 i32.const 2 i32.add - local.set $4 + local.set $6 else - local.get $5 + local.get $4 i32.const 239 i32.gt_u - local.tee $6 + local.tee $7 if (result i32) - local.get $5 + local.get $4 i32.const 365 i32.lt_u else - local.get $6 + local.get $7 end if - local.get $2 - i32.const 3 - i32.add - local.get $1 - i32.le_u - i32.eqz - if - i32.const 0 - i32.const 96 - i32.const 451 - i32.const 8 - call $~lib/env/abort - unreachable - end - local.get $5 + local.get $4 i32.const 7 i32.and i32.const 18 i32.shl - local.get $0 - block (result i32) - local.get $2 - local.tee $6 - i32.const 1 - i32.add - local.set $2 - local.get $6 - end - i32.add + local.get $2 i32.load8_u i32.const 63 i32.and i32.const 12 i32.shl i32.or - local.get $0 - block (result i32) - local.get $2 - local.tee $6 - i32.const 1 - i32.add - local.set $2 - local.get $6 - end - i32.add - i32.load8_u + local.get $2 + i32.load8_u offset=1 i32.const 63 i32.and i32.const 6 i32.shl i32.or - local.get $0 - block (result i32) - local.get $2 - local.tee $6 - i32.const 1 - i32.add - local.set $2 - local.get $6 - end - i32.add - i32.load8_u + local.get $2 + i32.load8_u offset=2 i32.const 63 i32.and i32.or i32.const 65536 i32.sub - local.set $5 - local.get $3 - local.get $4 + local.set $4 + local.get $2 + i32.const 3 i32.add + local.set $2 + local.get $6 i32.const 55296 - local.get $5 + local.get $4 i32.const 10 i32.shr_u i32.add i32.store16 - local.get $4 - i32.const 2 - i32.add - local.set $4 - local.get $3 - local.get $4 - i32.add + local.get $6 i32.const 56320 - local.get $5 + local.get $4 i32.const 1023 i32.and i32.add - i32.store16 - local.get $4 - i32.const 2 + i32.store16 offset=2 + local.get $6 + i32.const 4 i32.add - local.set $4 + local.set $6 else - local.get $2 - i32.const 2 - i32.add - local.get $1 - i32.le_u - i32.eqz - if - i32.const 0 - i32.const 96 - i32.const 463 - i32.const 8 - call $~lib/env/abort - unreachable - end - local.get $3 - local.get $4 - i32.add - local.get $5 + local.get $6 + local.get $4 i32.const 15 i32.and i32.const 12 i32.shl - local.get $0 - block (result i32) - local.get $2 - local.tee $6 - i32.const 1 - i32.add - local.set $2 - local.get $6 - end - i32.add + local.get $2 i32.load8_u i32.const 63 i32.and i32.const 6 i32.shl i32.or - local.get $0 - block (result i32) - local.get $2 - local.tee $6 - i32.const 1 - i32.add - local.set $2 - local.get $6 - end - i32.add - i32.load8_u + local.get $2 + i32.load8_u offset=1 i32.const 63 i32.and i32.or i32.store16 - local.get $4 + local.get $2 i32.const 2 i32.add - local.set $4 + local.set $2 + local.get $6 + i32.const 2 + i32.add + local.set $6 end end end @@ -2238,40 +3156,41 @@ end end end - local.get $2 - local.get $1 - i32.eq - i32.eqz - if - i32.const 0 - i32.const 96 - i32.const 472 - i32.const 4 - call $~lib/env/abort - unreachable - end - block $~lib/runtime/ALLOCATE|inlined.0 (result i32) + block $~lib/runtime/REGISTER<~lib/string/String>|inlined.1 (result i32) + block $~lib/runtime/REALLOCATE|inlined.5 (result i32) + local.get $5 + local.set $8 + local.get $6 + local.get $5 + i32.sub + local.set $7 + local.get $8 + local.get $7 + call $~lib/runtime/reallocate + end + local.set $4 local.get $4 - local.set $5 - local.get $5 - call $~lib/runtime/allocate - end - local.set $7 - local.get $7 - local.get $3 - local.get $4 - call $~lib/memory/memory.copy - local.get $3 - call $~lib/memory/memory.free - block $~lib/runtime/REGISTER<~lib/string/String>|inlined.0 (result i32) - local.get $7 - local.set $5 - local.get $5 i32.const 1 call $~lib/runtime/register end ) - (func $~lib/util/string/compareImpl (; 14 ;) (type $FUNCSIG$iiiiii) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (param $4 i32) (result i32) + (func $~lib/encoding/UTF8.decode (; 21 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + local.get $1 + i32.const 0 + i32.ne + if (result i32) + local.get $0 + local.get $0 + call $~lib/arraybuffer/ArrayBuffer#get:byteLength + call $~lib/encoding/UTF8.decodeRawDelimited + else + local.get $0 + local.get $0 + call $~lib/arraybuffer/ArrayBuffer#get:byteLength + call $~lib/encoding/UTF8.decodeRaw + end + ) + (func $~lib/util/string/compareImpl (; 22 ;) (type $FUNCSIG$iiiiii) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (param $4 i32) (result i32) (local $5 i32) (local $6 i32) (local $7 i32) @@ -2324,7 +3243,7 @@ end local.get $5 ) - (func $~lib/string/String.__eq (; 15 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/string/String.__eq (; 23 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) local.get $0 @@ -2368,276 +3287,219 @@ call $~lib/util/string/compareImpl i32.eqz ) - (func $start:std/string-utf8 (; 16 ;) (type $FUNCSIG$v) - global.get $std/string-utf8/str - call $~lib/string/String#get:lengthUTF8 - global.set $std/string-utf8/len - global.get $std/string-utf8/len - i32.const 11 - i32.eq - i32.eqz - if - i32.const 0 - i32.const 40 - i32.const 7 - i32.const 0 - call $~lib/env/abort - unreachable - end - global.get $~lib/memory/HEAP_BASE - i32.const 7 - i32.add - i32.const 7 - i32.const -1 - i32.xor - i32.and - global.set $~lib/allocator/arena/startOffset - global.get $~lib/allocator/arena/startOffset - global.set $~lib/allocator/arena/offset - global.get $std/string-utf8/str - call $~lib/string/String#toUTF8 - global.set $std/string-utf8/ptr - global.get $std/string-utf8/ptr - i32.load8_u - i32.const 240 - i32.eq - i32.eqz - if - i32.const 0 - i32.const 40 - i32.const 11 - i32.const 0 - call $~lib/env/abort - unreachable - end - global.get $std/string-utf8/ptr - i32.load8_u offset=1 - i32.const 144 - i32.eq - i32.eqz - if - i32.const 0 - i32.const 40 - i32.const 12 - i32.const 0 - call $~lib/env/abort - unreachable - end - global.get $std/string-utf8/ptr - i32.load8_u offset=2 - i32.const 144 - i32.eq - i32.eqz - if - i32.const 0 - i32.const 40 - i32.const 13 - i32.const 0 - call $~lib/env/abort - unreachable - end - global.get $std/string-utf8/ptr - i32.load8_u offset=3 - i32.const 183 - i32.eq - i32.eqz - if - i32.const 0 - i32.const 40 - i32.const 14 - i32.const 0 - call $~lib/env/abort - unreachable - end - global.get $std/string-utf8/ptr - i32.load8_u offset=4 - i32.const 104 - i32.eq - i32.eqz - if - i32.const 0 - i32.const 40 - i32.const 15 - i32.const 0 - call $~lib/env/abort - unreachable - end - global.get $std/string-utf8/ptr - i32.load8_u offset=5 - i32.const 105 - i32.eq - i32.eqz - if - i32.const 0 - i32.const 40 - i32.const 16 - i32.const 0 - call $~lib/env/abort - unreachable - end - global.get $std/string-utf8/ptr - i32.load8_u offset=6 - i32.const 240 - i32.eq + (func $std/encoding/testUTF8Decode (; 24 ;) (type $FUNCSIG$v) + (local $0 i32) + global.get $std/encoding/str + i32.const 0 + call $~lib/encoding/UTF8.encode + local.set $0 + local.get $0 + i32.const 0 + call $~lib/encoding/UTF8.decode + global.get $std/encoding/str + call $~lib/string/String.__eq i32.eqz if i32.const 0 i32.const 40 - i32.const 17 - i32.const 0 + i32.const 48 + i32.const 2 call $~lib/env/abort unreachable end - global.get $std/string-utf8/ptr - i32.load8_u offset=7 - i32.const 164 - i32.eq + ) + (func $std/encoding/testUTF8DecodeDelimited (; 25 ;) (type $FUNCSIG$v) + (local $0 i32) + global.get $std/encoding/str + i32.const 1 + call $~lib/encoding/UTF8.encode + local.set $0 + local.get $0 + i32.const 1 + call $~lib/encoding/UTF8.decode + global.get $std/encoding/str + call $~lib/string/String.__eq i32.eqz if i32.const 0 i32.const 40 - i32.const 18 - i32.const 0 + i32.const 54 + i32.const 2 call $~lib/env/abort unreachable end - global.get $std/string-utf8/ptr - i32.load8_u offset=8 - i32.const 173 - i32.eq + ) + (func $std/encoding/testUTF8Raw (; 26 ;) (type $FUNCSIG$v) + (local $0 i32) + global.get $std/encoding/str + i32.const 0 + call $~lib/encoding/UTF8.encode + local.set $0 + local.get $0 + i32.const 0 + call $~lib/encoding/UTF8.decodeRaw + i32.const 160 + call $~lib/string/String.__eq i32.eqz if i32.const 0 i32.const 40 - i32.const 19 - i32.const 0 + i32.const 61 + i32.const 2 call $~lib/env/abort unreachable end - global.get $std/string-utf8/ptr - i32.load8_u offset=9 - i32.const 162 - i32.eq + local.get $0 + global.get $std/encoding/str + i32.const 0 + call $~lib/encoding/UTF8.length + call $~lib/encoding/UTF8.decodeRaw + global.get $std/encoding/str + call $~lib/string/String.__eq i32.eqz if i32.const 0 i32.const 40 - i32.const 20 - i32.const 0 + i32.const 62 + i32.const 2 call $~lib/env/abort unreachable end - global.get $std/string-utf8/ptr - i32.load8_u offset=10 - i32.const 0 - i32.eq + local.get $0 + i32.const 4 + call $~lib/encoding/UTF8.decodeRaw + i32.const 168 + call $~lib/string/String.__eq i32.eqz if i32.const 0 i32.const 40 - i32.const 21 - i32.const 0 + i32.const 63 + i32.const 2 call $~lib/env/abort unreachable end - global.get $std/string-utf8/ptr - i32.const 0 - call $~lib/string/String.fromUTF8 - i32.const 88 + local.get $0 + i32.const 4 + i32.add + i32.const 2 + call $~lib/encoding/UTF8.decodeRaw + i32.const 184 call $~lib/string/String.__eq i32.eqz if i32.const 0 i32.const 40 - i32.const 23 - i32.const 0 + i32.const 64 + i32.const 2 call $~lib/env/abort unreachable end - global.get $std/string-utf8/ptr - global.get $std/string-utf8/len - i32.const 1 - i32.sub - call $~lib/string/String.fromUTF8 - global.get $std/string-utf8/str + local.get $0 + i32.const 6 + i32.add + i32.const 4 + call $~lib/encoding/UTF8.decodeRaw + i32.const 200 call $~lib/string/String.__eq i32.eqz if i32.const 0 i32.const 40 - i32.const 24 - i32.const 0 + i32.const 65 + i32.const 2 call $~lib/env/abort unreachable end - global.get $std/string-utf8/ptr - i32.const 4 - call $~lib/string/String.fromUTF8 - i32.const 176 + local.get $0 + i32.const 10 + i32.add + i32.const 0 + call $~lib/encoding/UTF8.decodeRaw + i32.const 160 call $~lib/string/String.__eq i32.eqz if i32.const 0 i32.const 40 - i32.const 25 - i32.const 0 + i32.const 66 + i32.const 2 call $~lib/env/abort unreachable end - global.get $std/string-utf8/ptr + local.get $0 + i32.const 0 + i32.store8 offset=10 + local.get $0 i32.const 4 i32.add - i32.const 2 - call $~lib/string/String.fromUTF8 - i32.const 192 + global.get $~lib/runtime/MAX_BYTELENGTH + call $~lib/encoding/UTF8.decodeRawDelimited + i32.const 216 call $~lib/string/String.__eq i32.eqz if i32.const 0 i32.const 40 - i32.const 26 - i32.const 0 + i32.const 69 + i32.const 2 call $~lib/env/abort unreachable end - global.get $std/string-utf8/ptr + local.get $0 i32.const 6 i32.add - i32.const 4 - call $~lib/string/String.fromUTF8 - i32.const 208 + global.get $~lib/runtime/MAX_BYTELENGTH + call $~lib/encoding/UTF8.decodeRawDelimited + i32.const 200 call $~lib/string/String.__eq i32.eqz if i32.const 0 i32.const 40 - i32.const 27 - i32.const 0 + i32.const 70 + i32.const 2 call $~lib/env/abort unreachable end - global.get $std/string-utf8/ptr + local.get $0 i32.const 10 i32.add - i32.const 1 - call $~lib/string/String.fromUTF8 - i32.const 224 + global.get $~lib/runtime/MAX_BYTELENGTH + call $~lib/encoding/UTF8.decodeRawDelimited + i32.const 160 call $~lib/string/String.__eq i32.eqz if i32.const 0 i32.const 40 - i32.const 28 - i32.const 0 + i32.const 71 + i32.const 2 call $~lib/env/abort unreachable end - global.get $std/string-utf8/ptr - call $~lib/memory/memory.free ) - (func $start (; 17 ;) (type $FUNCSIG$v) - call $start:std/string-utf8 + (func $start:std/encoding (; 27 ;) (type $FUNCSIG$v) + call $std/encoding/testUTF8Length + global.get $~lib/memory/HEAP_BASE + i32.const 7 + i32.add + i32.const 7 + i32.const -1 + i32.xor + i32.and + global.set $~lib/allocator/arena/startOffset + global.get $~lib/allocator/arena/startOffset + global.set $~lib/allocator/arena/offset + call $std/encoding/testUTF8Encode + call $std/encoding/testUTF8EncodeDelimited + call $std/encoding/testUTF8Decode + call $std/encoding/testUTF8DecodeDelimited + call $std/encoding/testUTF8Raw + ) + (func $start (; 28 ;) (type $FUNCSIG$v) + call $start:std/encoding ) - (func $null (; 18 ;) (type $FUNCSIG$v) + (func $null (; 29 ;) (type $FUNCSIG$v) ) ) diff --git a/tests/compiler/std/string-utf8.ts b/tests/compiler/std/string-utf8.ts deleted file mode 100644 index f3c6adbd96..0000000000 --- a/tests/compiler/std/string-utf8.ts +++ /dev/null @@ -1,30 +0,0 @@ -import "allocator/arena"; - -var str = "š·hiš¤­¢"; // -> f0 90 90 b7 68 69 f0 a4 ad a2 00 - -var len = str.lengthUTF8; - -assert(len == 11); - -var ptr = str.toUTF8(); // toUTF8 is zero-terminated - -assert(load(ptr, 0) == 0xf0); -assert(load(ptr, 1) == 0x90); -assert(load(ptr, 2) == 0x90); -assert(load(ptr, 3) == 0xb7); -assert(load(ptr, 4) == 0x68); -assert(load(ptr, 5) == 0x69); -assert(load(ptr, 6) == 0xf0); -assert(load(ptr, 7) == 0xa4); -assert(load(ptr, 8) == 0xad); -assert(load(ptr, 9) == 0xa2); -assert(load(ptr, 10) == 0); - -assert(String.fromUTF8(ptr, 0) == ""); // fromUTF8 is not zero-terminated -assert(String.fromUTF8(ptr, len - 1) == str); -assert(String.fromUTF8(ptr, 4) == "š·"); -assert(String.fromUTF8(ptr + 4, 2) == "hi"); -assert(String.fromUTF8(ptr + 6, 4) == "š¤­¢"); -assert(String.fromUTF8(ptr + 10, 1) == "\0"); - -memory.free(ptr); diff --git a/tests/compiler/std/string.optimized.wat b/tests/compiler/std/string.optimized.wat index c7226e25ab..a3b17e9bc0 100644 --- a/tests/compiler/std/string.optimized.wat +++ b/tests/compiler/std/string.optimized.wat @@ -575,7 +575,7 @@ if i32.const 0 i32.const 216 - i32.const 24 + i32.const 25 i32.const 4 call $~lib/env/abort unreachable @@ -630,7 +630,7 @@ if i32.const 0 i32.const 216 - i32.const 164 + i32.const 165 i32.const 4 call $~lib/env/abort unreachable @@ -678,7 +678,7 @@ if i32.const 0 i32.const 216 - i32.const 77 + i32.const 78 i32.const 4 call $~lib/env/abort unreachable @@ -726,7 +726,7 @@ if i32.const 0 i32.const 216 - i32.const 133 + i32.const 134 i32.const 4 call $~lib/env/abort unreachable @@ -1877,7 +1877,7 @@ if i32.const 0 i32.const 216 - i32.const 281 + i32.const 282 i32.const 4 call $~lib/env/abort unreachable @@ -1972,7 +1972,7 @@ if i32.const 0 i32.const 216 - i32.const 302 + i32.const 303 i32.const 4 call $~lib/env/abort unreachable @@ -2068,7 +2068,7 @@ if i32.const 0 i32.const 216 - i32.const 149 + i32.const 150 i32.const 4 call $~lib/env/abort unreachable @@ -2490,7 +2490,7 @@ if i32.const 0 i32.const 216 - i32.const 569 + i32.const 464 i32.const 10 call $~lib/env/abort unreachable @@ -2762,7 +2762,7 @@ if i32.const 0 i32.const 216 - i32.const 323 + i32.const 324 i32.const 4 call $~lib/env/abort unreachable @@ -2792,7 +2792,7 @@ if i32.const 0 i32.const 216 - i32.const 328 + i32.const 329 i32.const 6 call $~lib/env/abort unreachable @@ -3354,7 +3354,7 @@ if i32.const 0 i32.const 216 - i32.const 350 + i32.const 351 i32.const 4 call $~lib/env/abort unreachable @@ -5072,7 +5072,7 @@ if i32.const 0 i32.const 216 - i32.const 189 + i32.const 190 i32.const 4 call $~lib/env/abort unreachable diff --git a/tests/compiler/std/string.untouched.wat b/tests/compiler/std/string.untouched.wat index e8e9c3aa52..91eebc927b 100644 --- a/tests/compiler/std/string.untouched.wat +++ b/tests/compiler/std/string.untouched.wat @@ -524,7 +524,7 @@ if i32.const 0 i32.const 216 - i32.const 24 + i32.const 25 i32.const 4 call $~lib/env/abort unreachable @@ -597,7 +597,7 @@ if i32.const 0 i32.const 216 - i32.const 164 + i32.const 165 i32.const 4 call $~lib/env/abort unreachable @@ -663,7 +663,7 @@ if i32.const 0 i32.const 216 - i32.const 77 + i32.const 78 i32.const 4 call $~lib/env/abort unreachable @@ -727,7 +727,7 @@ if i32.const 0 i32.const 216 - i32.const 133 + i32.const 134 i32.const 4 call $~lib/env/abort unreachable @@ -2288,7 +2288,7 @@ if i32.const 0 i32.const 216 - i32.const 281 + i32.const 282 i32.const 4 call $~lib/env/abort unreachable @@ -2397,7 +2397,7 @@ if i32.const 0 i32.const 216 - i32.const 302 + i32.const 303 i32.const 4 call $~lib/env/abort unreachable @@ -2507,7 +2507,7 @@ if i32.const 0 i32.const 216 - i32.const 149 + i32.const 150 i32.const 4 call $~lib/env/abort unreachable @@ -3021,7 +3021,7 @@ if i32.const 0 i32.const 216 - i32.const 569 + i32.const 464 i32.const 10 call $~lib/env/abort unreachable @@ -3311,7 +3311,7 @@ if i32.const 0 i32.const 216 - i32.const 323 + i32.const 324 i32.const 4 call $~lib/env/abort unreachable @@ -3339,7 +3339,7 @@ if i32.const 0 i32.const 216 - i32.const 328 + i32.const 329 i32.const 6 call $~lib/env/abort unreachable @@ -4110,7 +4110,7 @@ if i32.const 0 i32.const 216 - i32.const 350 + i32.const 351 i32.const 4 call $~lib/env/abort unreachable @@ -6587,7 +6587,7 @@ if i32.const 0 i32.const 216 - i32.const 189 + i32.const 190 i32.const 4 call $~lib/env/abort unreachable From a742537dd9b2a02ca85e8b1acdf9618116932d03 Mon Sep 17 00:00:00 2001 From: dcode Date: Thu, 28 Mar 2019 22:49:22 +0100 Subject: [PATCH 2/2] split into encoders and decoders --- std/assembly/encoding.ts | 119 ++++++--- std/assembly/index.d.ts | 37 ++- std/assembly/string.ts | 1 - tests/compiler/number.optimized.wat | 2 +- tests/compiler/number.untouched.wat | 2 +- tests/compiler/std/array-access.optimized.wat | 2 +- tests/compiler/std/array-access.untouched.wat | 2 +- tests/compiler/std/array.optimized.wat | 2 +- tests/compiler/std/array.untouched.wat | 4 +- tests/compiler/std/encoding.optimized.wat | 111 ++++++--- tests/compiler/std/encoding.ts | 48 ++-- tests/compiler/std/encoding.untouched.wat | 231 +++++++++++------- tests/compiler/std/string.optimized.wat | 24 +- tests/compiler/std/string.untouched.wat | 24 +- 14 files changed, 378 insertions(+), 231 deletions(-) diff --git a/std/assembly/encoding.ts b/std/assembly/encoding.ts index 8915f11a2d..42bde1be65 100644 --- a/std/assembly/encoding.ts +++ b/std/assembly/encoding.ts @@ -1,46 +1,71 @@ import { ALLOCATE, REGISTER, REALLOCATE, MAX_BYTELENGTH } from "./runtime"; -import { E_INVALIDLENGTH } from "./util/error"; +import { E_INVALIDLENGTH, E_NOTIMPLEMENTED } from "./util/error"; -/** UTF16 encoding. */ -export namespace UTF16 { +export class UTF16Encoder { - /** Calculates the length of a string when encoded as an UTF16 buffer. */ - export function length(str: string): i32 { + /** Calculates the length of a string when encoded as UTF16 bytes. */ + static byteLength(str: string): i32 { return str.length << 1; } - /** Encodes a string as an UTF16 buffer. */ - export function encode(str: string): ArrayBuffer { + /** Encodes a string to UTF16 bytes. */ + static encode(str: string): ArrayBuffer { var size = str.length << 1; var buf = ALLOCATE(size); memory.copy(buf, changetype(str), size); return REGISTER(buf); } - /** Decodes an UTF16 buffer to a string.*/ - export function decode(buf: ArrayBuffer): string { - return decodeRaw(changetype(buf), buf.byteLength); + constructor() { + throw new Error(E_NOTIMPLEMENTED); } - // @ts-ignore: decorator + write(str: string): void { + throw new Error(E_NOTIMPLEMENTED); + } + + end(): ArrayBuffer { + throw new Error(E_NOTIMPLEMENTED); + } +} + +export class UTF16Decoder { + + /** Decodes UTF16 bytes to a string.*/ + static decode(buf: ArrayBuffer): string { + return UTF16Decoder.decodeUnsafe(changetype(buf), buf.byteLength); + } + + /** Decodes UTF16 bytes to a string. */ @unsafe - export function decodeRaw(buf: usize, len: i32): string { + static decodeUnsafe(buf: usize, len: i32): string { if (len > MAX_BYTELENGTH) throw new RangeError(E_INVALIDLENGTH); var size = len; var str = ALLOCATE(size); memory.copy(str, changetype(buf), size); return REGISTER(str); } + + constructor() { + throw new Error(E_NOTIMPLEMENTED); + } + + write(buf: ArrayBuffer): void { + throw new Error(E_NOTIMPLEMENTED); + } + + end(): string { + throw new Error(E_NOTIMPLEMENTED); + } } -/** UTF8 encoding. */ -export namespace UTF8 { +export class UTF8Encoder { - /** Calculates the length of a string when encoded as an UTF8 buffer. */ - export function length(str: string, delimited: bool = false): i32 { + /** Calculates the length of a string when encoded as UTF8 bytes. */ + static byteLength(str: string, nullTerminated: bool = false): i32 { var strOff = changetype(str); var strEnd = changetype(str) + (str.length << 1); - var bufLen = delimited ? 1 : 0; + var bufLen = nullTerminated ? 1 : 0; while (strOff < strEnd) { let c = load(strOff); if (c < 128) { @@ -60,11 +85,11 @@ export namespace UTF8 { return bufLen; } - /** Encodes a string as an UTF8 buffer. */ - export function encode(str: string, delimited: bool = false): ArrayBuffer { + /** Encodes a string as UTF8 bytes. */ + static encode(str: string, nullTerminated: bool = false): ArrayBuffer { var strOff = changetype(str); var strEnd = changetype(str) + (str.length << 1); - var buf = ALLOCATE(length(str, delimited)); + var buf = ALLOCATE(UTF8Encoder.byteLength(str, nullTerminated)); var bufOff = changetype(buf); while (strOff < strEnd) { let c1 = load(strOff); @@ -95,22 +120,39 @@ export namespace UTF8 { } } assert(strOff == strEnd); - if (delimited) store(bufOff, 0); + if (nullTerminated) store(bufOff, 0); return REGISTER(buf); } - /** Decodes an UTF8 buffer to a string.*/ - export function decode(buf: ArrayBuffer, delimited: bool = false): string { - return delimited - ? decodeRawDelimited(changetype(buf), buf.byteLength) - : decodeRaw(changetype(buf), buf.byteLength); + constructor() { + throw new Error(E_NOTIMPLEMENTED); } - // @ts-ignore: decorator + write(str: string): void { + throw new Error(E_NOTIMPLEMENTED); + } + + end(): ArrayBuffer { + throw new Error(E_NOTIMPLEMENTED); + } +} + +export class UTF8Decoder { + + /** Decodes UTF8 bytes to a string.*/ + static decode(buf: ArrayBuffer, nullTerminated: bool = false): string { + return nullTerminated + ? UTF8Decoder.decodeNullTerminatedUnsafe(changetype(buf), buf.byteLength) + : UTF8Decoder.decodeUnsafe(changetype(buf), buf.byteLength); + } + + /** Decodes UTF8 bytes to a string.*/ @unsafe - export function decodeRaw(buf: usize, len: i32): string { + static decodeUnsafe(buf: usize, len: i32): string { + if (len > MAX_BYTELENGTH) throw new RangeError(E_INVALIDLENGTH); var bufOff = buf; var bufEnd = buf + len; + assert(bufEnd >= bufOff); // guard wraparound var str = ALLOCATE(len << 1); // max is one u16 char per u8 byte var strOff = str; while (bufOff < bufEnd) { @@ -144,13 +186,14 @@ export namespace UTF8 { return REGISTER(REALLOCATE(str, strOff - str)); } - // @ts-ignore: decorator + /** Decodes UTF8 bytes to a string. Zero terminated. */ @unsafe - export function decodeRawDelimited(buf: usize, maxLen: i32 = MAX_BYTELENGTH): string { + static decodeNullTerminatedUnsafe(buf: usize, maxLen: i32 = MAX_BYTELENGTH): string { + if (maxLen > MAX_BYTELENGTH) throw new RangeError(E_INVALIDLENGTH); var bufOff = buf; var bufLim = buf + maxLen; - assert(bufLim > bufOff); // guard wraparound - var str = ALLOCATE(16); // optimize for small strings + assert(bufLim >= bufOff); // guard wraparound + var str = ALLOCATE(min(maxLen, 16)); // optimize for small strings var strLen = 0; while (bufOff < bufLim) { let cp = load(bufOff++); @@ -191,4 +234,16 @@ export namespace UTF8 { } return REGISTER(REALLOCATE(str, strLen)); } + + constructor() { + throw new Error(E_NOTIMPLEMENTED); + } + + write(buf: ArrayBuffer): void { + throw new Error(E_NOTIMPLEMENTED); + } + + end(): string { + throw new Error(E_NOTIMPLEMENTED); + } } diff --git a/std/assembly/index.d.ts b/std/assembly/index.d.ts index ffd00a96a7..af8bb084db 100644 --- a/std/assembly/index.d.ts +++ b/std/assembly/index.d.ts @@ -1254,19 +1254,34 @@ declare class String { toString(): string; } -declare namespace UTF16 { - export function length(str: string): i32; - export function encode(str: string): ArrayBuffer; - export function decode(buf: ArrayBuffer, delimited?: bool): string; - export function decodeRaw(buf: usize, len: i32): string; // unsafe +declare class UTF16Encoder { + /** Calculates the length of a string when encoded as UTF16 bytes. */ + static byteLength(str: string): i32; + /** Encodes a string to UTF16 bytes. */ + static encode(str: string): ArrayBuffer; } -declare namespace UTF8 { - export function length(str: string, delimited?: bool): i32; - export function encode(str: string, delimited?: bool): ArrayBuffer; - export function decode(buf: ArrayBuffer, delimited?: bool): string; - export function decodeRaw(buf: usize, len: i32): string; // unsafe - export function decodeRawDelimited(buf: usize, maxLen?: i32): string; // unsafe +declare class UTF16Decoder { + /** Decodes UTF16 bytes to a string.*/ + static decode(buf: ArrayBuffer): string; + /** Decodes UTF16 bytes to a string. */ + static decodeUnsafe(buf: usize, len: i32): string; +} + +declare class UTF8Encoder { + /** Calculates the length of a string when encoded as UTF8 bytes. */ + static byteLength(str: string, nullTerminated?: bool): i32; + /** Encodes a string as UTF8 bytes. */ + static encode(str: string, nullTerminated?: bool): ArrayBuffer; +} + +declare class UTF8Decoder { + /** Decodes UTF8 bytes to a string.*/ + static decode(buf: ArrayBuffer, nullTerminated?: bool): string; + /** Decodes UTF8 bytes to a string.*/ + static decodeUnsafe(buf: usize, len: i32): string; + /** Decodes UTF8 bytes to a string. */ + static decodeNullTerminatedUnsafe(buf: usize, maxLen?: i32): string; } /** Class for representing a runtime error. Base class of all errors. */ diff --git a/std/assembly/string.ts b/std/assembly/string.ts index 34c18a1374..0acbfe33f7 100644 --- a/std/assembly/string.ts +++ b/std/assembly/string.ts @@ -4,7 +4,6 @@ import { ALLOCATE, REGISTER, HEADER, HEADER_SIZE, MAKEARRAY, ArrayBufferView } f import { MAX_SIZE_32 } from "./util/allocator"; import { compareImpl, parse, CharCode, isWhiteSpaceOrLineTerminator } from "./util/string"; import { E_INVALIDLENGTH } from "./util/error"; -import { UTF8 } from "./encoding"; @sealed export abstract class String { diff --git a/tests/compiler/number.optimized.wat b/tests/compiler/number.optimized.wat index c1b84a5de3..89aa758653 100644 --- a/tests/compiler/number.optimized.wat +++ b/tests/compiler/number.optimized.wat @@ -2358,7 +2358,7 @@ if i32.const 0 i32.const 1648 - i32.const 190 + i32.const 189 i32.const 4 call $~lib/env/abort unreachable diff --git a/tests/compiler/number.untouched.wat b/tests/compiler/number.untouched.wat index 27d211e87a..3032067b46 100644 --- a/tests/compiler/number.untouched.wat +++ b/tests/compiler/number.untouched.wat @@ -3424,7 +3424,7 @@ if i32.const 0 i32.const 1648 - i32.const 190 + i32.const 189 i32.const 4 call $~lib/env/abort unreachable diff --git a/tests/compiler/std/array-access.optimized.wat b/tests/compiler/std/array-access.optimized.wat index 7e9cbe252f..c1ffc30d5a 100644 --- a/tests/compiler/std/array-access.optimized.wat +++ b/tests/compiler/std/array-access.optimized.wat @@ -142,7 +142,7 @@ if i32.const 0 i32.const 64 - i32.const 165 + i32.const 164 i32.const 4 call $~lib/env/abort unreachable diff --git a/tests/compiler/std/array-access.untouched.wat b/tests/compiler/std/array-access.untouched.wat index e65829fd21..2d16c9f85b 100644 --- a/tests/compiler/std/array-access.untouched.wat +++ b/tests/compiler/std/array-access.untouched.wat @@ -219,7 +219,7 @@ if i32.const 0 i32.const 64 - i32.const 165 + i32.const 164 i32.const 4 call $~lib/env/abort unreachable diff --git a/tests/compiler/std/array.optimized.wat b/tests/compiler/std/array.optimized.wat index 9bc32116a2..5ce6486507 100644 --- a/tests/compiler/std/array.optimized.wat +++ b/tests/compiler/std/array.optimized.wat @@ -6229,7 +6229,7 @@ if i32.const 0 i32.const 4376 - i32.const 190 + i32.const 189 i32.const 4 call $~lib/env/abort unreachable diff --git a/tests/compiler/std/array.untouched.wat b/tests/compiler/std/array.untouched.wat index 4cfd5bf98d..6c0bc57382 100644 --- a/tests/compiler/std/array.untouched.wat +++ b/tests/compiler/std/array.untouched.wat @@ -8951,7 +8951,7 @@ if i32.const 0 i32.const 4376 - i32.const 40 + i32.const 39 i32.const 4 call $~lib/env/abort unreachable @@ -9590,7 +9590,7 @@ if i32.const 0 i32.const 4376 - i32.const 190 + i32.const 189 i32.const 4 call $~lib/env/abort unreachable diff --git a/tests/compiler/std/encoding.optimized.wat b/tests/compiler/std/encoding.optimized.wat index a16df4a6fb..07ce2de591 100644 --- a/tests/compiler/std/encoding.optimized.wat +++ b/tests/compiler/std/encoding.optimized.wat @@ -25,7 +25,7 @@ (export "memory" (memory $0)) (export "table" (table $0)) (start $start) - (func $~lib/encoding/UTF8.length (; 1 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/encoding/UTF8Encoder.byteLength (; 1 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) local.get $0 @@ -119,7 +119,7 @@ (func $std/encoding/testUTF8Length (; 2 ;) (type $FUNCSIG$v) global.get $std/encoding/str i32.const 0 - call $~lib/encoding/UTF8.length + call $~lib/encoding/UTF8Encoder.byteLength i32.const 10 i32.ne if @@ -132,7 +132,7 @@ end global.get $std/encoding/str i32.const 1 - call $~lib/encoding/UTF8.length + call $~lib/encoding/UTF8Encoder.byteLength i32.const 11 i32.ne if @@ -260,7 +260,7 @@ i32.store local.get $0 ) - (func $~lib/encoding/UTF8.encode (; 6 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/encoding/UTF8Encoder.encode (; 6 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -279,7 +279,7 @@ local.set $4 local.get $0 local.get $1 - call $~lib/encoding/UTF8.length + call $~lib/encoding/UTF8Encoder.byteLength call $~lib/runtime/allocate local.tee $6 local.set $2 @@ -443,7 +443,7 @@ if i32.const 0 i32.const 80 - i32.const 97 + i32.const 122 i32.const 4 call $~lib/env/abort unreachable @@ -462,7 +462,7 @@ (local $0 i32) global.get $std/encoding/str i32.const 0 - call $~lib/encoding/UTF8.encode + call $~lib/encoding/UTF8Encoder.encode local.tee $0 i32.const 8 i32.sub @@ -598,11 +598,11 @@ unreachable end ) - (func $std/encoding/testUTF8EncodeDelimited (; 8 ;) (type $FUNCSIG$v) + (func $std/encoding/testUTF8EncodeNullTerminated (; 8 ;) (type $FUNCSIG$v) (local $0 i32) global.get $std/encoding/str i32.const 1 - call $~lib/encoding/UTF8.encode + call $~lib/encoding/UTF8Encoder.encode local.tee $0 i32.const 8 i32.sub @@ -2096,26 +2096,42 @@ i32.store offset=4 local.get $0 ) - (func $~lib/encoding/UTF8.decodeRawDelimited (; 13 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/encoding/UTF8Decoder.decodeNullTerminatedUnsafe (; 13 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) (local $5 i32) + local.get $1 + i32.const 1073741816 + i32.gt_u + if + i32.const 0 + i32.const 80 + i32.const 192 + i32.const 47 + call $~lib/env/abort + unreachable + end local.get $0 local.get $1 i32.add local.tee $5 local.get $0 - i32.le_u + i32.lt_u if i32.const 0 i32.const 80 - i32.const 152 + i32.const 195 i32.const 4 call $~lib/env/abort unreachable end + local.get $1 i32.const 16 + local.get $1 + i32.const 16 + i32.lt_s + select call $~lib/runtime/allocate local.set $4 loop $continue|0 @@ -2326,15 +2342,36 @@ i32.const 1 call $~lib/runtime/register ) - (func $~lib/encoding/UTF8.decodeRaw (; 14 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/encoding/UTF8Decoder.decodeUnsafe (; 14 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) (local $5 i32) + local.get $1 + i32.const 1073741816 + i32.gt_u + if + i32.const 0 + i32.const 80 + i32.const 152 + i32.const 44 + call $~lib/env/abort + unreachable + end local.get $0 local.get $1 i32.add - local.set $5 + local.tee $5 + local.get $0 + i32.lt_u + if + i32.const 0 + i32.const 80 + i32.const 155 + i32.const 4 + call $~lib/env/abort + unreachable + end local.get $1 i32.const 1 i32.shl @@ -2500,7 +2537,7 @@ i32.const 1 call $~lib/runtime/register ) - (func $~lib/encoding/UTF8.decode (; 15 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/encoding/UTF8Decoder.decode (; 15 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) local.get $1 if (result i32) local.get $0 @@ -2508,14 +2545,14 @@ i32.const 8 i32.sub i32.load offset=4 - call $~lib/encoding/UTF8.decodeRawDelimited + call $~lib/encoding/UTF8Decoder.decodeNullTerminatedUnsafe else local.get $0 local.get $0 i32.const 8 i32.sub i32.load offset=4 - call $~lib/encoding/UTF8.decodeRaw + call $~lib/encoding/UTF8Decoder.decodeUnsafe end ) (func $~lib/util/string/compareImpl (; 16 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) @@ -2600,9 +2637,9 @@ (func $std/encoding/testUTF8Decode (; 18 ;) (type $FUNCSIG$v) global.get $std/encoding/str i32.const 0 - call $~lib/encoding/UTF8.encode + call $~lib/encoding/UTF8Encoder.encode i32.const 0 - call $~lib/encoding/UTF8.decode + call $~lib/encoding/UTF8Decoder.decode global.get $std/encoding/str call $~lib/string/String.__eq i32.eqz @@ -2615,12 +2652,12 @@ unreachable end ) - (func $std/encoding/testUTF8DecodeDelimited (; 19 ;) (type $FUNCSIG$v) + (func $std/encoding/testUTF8DecodeNullTerminated (; 19 ;) (type $FUNCSIG$v) global.get $std/encoding/str i32.const 1 - call $~lib/encoding/UTF8.encode + call $~lib/encoding/UTF8Encoder.encode i32.const 1 - call $~lib/encoding/UTF8.decode + call $~lib/encoding/UTF8Decoder.decode global.get $std/encoding/str call $~lib/string/String.__eq i32.eqz @@ -2633,14 +2670,14 @@ unreachable end ) - (func $std/encoding/testUTF8Raw (; 20 ;) (type $FUNCSIG$v) + (func $std/encoding/testUTF8DecodeUnsafe (; 20 ;) (type $FUNCSIG$v) (local $0 i32) global.get $std/encoding/str i32.const 0 - call $~lib/encoding/UTF8.encode + call $~lib/encoding/UTF8Encoder.encode local.tee $0 i32.const 0 - call $~lib/encoding/UTF8.decodeRaw + call $~lib/encoding/UTF8Decoder.decodeUnsafe i32.const 160 call $~lib/string/String.__eq i32.eqz @@ -2655,8 +2692,8 @@ local.get $0 global.get $std/encoding/str i32.const 0 - call $~lib/encoding/UTF8.length - call $~lib/encoding/UTF8.decodeRaw + call $~lib/encoding/UTF8Encoder.byteLength + call $~lib/encoding/UTF8Decoder.decodeUnsafe global.get $std/encoding/str call $~lib/string/String.__eq i32.eqz @@ -2670,7 +2707,7 @@ end local.get $0 i32.const 4 - call $~lib/encoding/UTF8.decodeRaw + call $~lib/encoding/UTF8Decoder.decodeUnsafe i32.const 168 call $~lib/string/String.__eq i32.eqz @@ -2686,7 +2723,7 @@ i32.const 4 i32.add i32.const 2 - call $~lib/encoding/UTF8.decodeRaw + call $~lib/encoding/UTF8Decoder.decodeUnsafe i32.const 184 call $~lib/string/String.__eq i32.eqz @@ -2702,7 +2739,7 @@ i32.const 6 i32.add i32.const 4 - call $~lib/encoding/UTF8.decodeRaw + call $~lib/encoding/UTF8Decoder.decodeUnsafe i32.const 200 call $~lib/string/String.__eq i32.eqz @@ -2718,7 +2755,7 @@ i32.const 10 i32.add i32.const 0 - call $~lib/encoding/UTF8.decodeRaw + call $~lib/encoding/UTF8Decoder.decodeUnsafe i32.const 160 call $~lib/string/String.__eq i32.eqz @@ -2737,7 +2774,7 @@ i32.const 4 i32.add i32.const 1073741816 - call $~lib/encoding/UTF8.decodeRawDelimited + call $~lib/encoding/UTF8Decoder.decodeNullTerminatedUnsafe i32.const 216 call $~lib/string/String.__eq i32.eqz @@ -2753,7 +2790,7 @@ i32.const 6 i32.add i32.const 1073741816 - call $~lib/encoding/UTF8.decodeRawDelimited + call $~lib/encoding/UTF8Decoder.decodeNullTerminatedUnsafe i32.const 200 call $~lib/string/String.__eq i32.eqz @@ -2769,7 +2806,7 @@ i32.const 10 i32.add i32.const 1073741816 - call $~lib/encoding/UTF8.decodeRawDelimited + call $~lib/encoding/UTF8Decoder.decodeNullTerminatedUnsafe i32.const 160 call $~lib/string/String.__eq i32.eqz @@ -2789,10 +2826,10 @@ global.get $~lib/allocator/arena/startOffset global.set $~lib/allocator/arena/offset call $std/encoding/testUTF8Encode - call $std/encoding/testUTF8EncodeDelimited + call $std/encoding/testUTF8EncodeNullTerminated call $std/encoding/testUTF8Decode - call $std/encoding/testUTF8DecodeDelimited - call $std/encoding/testUTF8Raw + call $std/encoding/testUTF8DecodeNullTerminated + call $std/encoding/testUTF8DecodeUnsafe ) (func $null (; 22 ;) (type $FUNCSIG$v) nop diff --git a/tests/compiler/std/encoding.ts b/tests/compiler/std/encoding.ts index a2cc80b2c5..6ea0d2a319 100644 --- a/tests/compiler/std/encoding.ts +++ b/tests/compiler/std/encoding.ts @@ -3,13 +3,13 @@ import "allocator/arena"; var str = "š·hiš¤­¢"; // -> f0 90 90 b7 68 69 f0 a4 ad a2 [00] function testUTF8Length(): void { - assert(UTF8.length(str) == 10); - assert(UTF8.length(str, true) == 11); + assert(UTF8Encoder.byteLength(str) == 10); + assert(UTF8Encoder.byteLength(str, true) == 11); } testUTF8Length(); function testUTF8Encode(): void { - var buf = UTF8.encode(str); + var buf = UTF8Encoder.encode(str); var ptr = changetype(buf); assert(buf.byteLength == 10); assert(load(ptr, 0) == 0xf0); @@ -25,8 +25,8 @@ function testUTF8Encode(): void { } testUTF8Encode(); -function testUTF8EncodeDelimited(): void { - var buf = UTF8.encode(str, true); +function testUTF8EncodeNullTerminated(): void { + var buf = UTF8Encoder.encode(str, true); var ptr = changetype(buf); assert(buf.byteLength == 11); assert(load(ptr, 0) == 0xf0); @@ -41,33 +41,33 @@ function testUTF8EncodeDelimited(): void { assert(load(ptr, 9) == 0xa2); assert(load(ptr, 10) == 0x00); } -testUTF8EncodeDelimited(); +testUTF8EncodeNullTerminated(); function testUTF8Decode(): void { - var buf = UTF8.encode(str); - assert(UTF8.decode(buf) == str); + var buf = UTF8Encoder.encode(str); + assert(UTF8Decoder.decode(buf) == str); } testUTF8Decode(); -function testUTF8DecodeDelimited(): void { - var buf = UTF8.encode(str, true); - assert(UTF8.decode(buf, true) == str); +function testUTF8DecodeNullTerminated(): void { + var buf = UTF8Encoder.encode(str, true); + assert(UTF8Decoder.decode(buf, true) == str); } -testUTF8DecodeDelimited(); +testUTF8DecodeNullTerminated(); -function testUTF8Raw(): void { - var buf = changetype(UTF8.encode(str)); +function testUTF8DecodeUnsafe(): void { + var buf = changetype(UTF8Encoder.encode(str)); - assert(UTF8.decodeRaw(buf, 0) == ""); - assert(UTF8.decodeRaw(buf, UTF8.length(str)) == str); - assert(UTF8.decodeRaw(buf, 4) == "š·"); - assert(UTF8.decodeRaw(buf + 4, 2) == "hi"); - assert(UTF8.decodeRaw(buf + 6, 4) == "š¤­¢"); - assert(UTF8.decodeRaw(buf + 10, 0) == ""); + assert(UTF8Decoder.decodeUnsafe(buf, 0) == ""); + assert(UTF8Decoder.decodeUnsafe(buf, UTF8Encoder.byteLength(str)) == str); + assert(UTF8Decoder.decodeUnsafe(buf, 4) == "š·"); + assert(UTF8Decoder.decodeUnsafe(buf + 4, 2) == "hi"); + assert(UTF8Decoder.decodeUnsafe(buf + 6, 4) == "š¤­¢"); + assert(UTF8Decoder.decodeUnsafe(buf + 10, 0) == ""); store(buf, 0, 10); // don't try this at home - assert(UTF8.decodeRawDelimited(buf + 4) == "hiš¤­¢"); - assert(UTF8.decodeRawDelimited(buf + 6) == "š¤­¢"); - assert(UTF8.decodeRawDelimited(buf + 10) == ""); + assert(UTF8Decoder.decodeNullTerminatedUnsafe(buf + 4) == "hiš¤­¢"); + assert(UTF8Decoder.decodeNullTerminatedUnsafe(buf + 6) == "š¤­¢"); + assert(UTF8Decoder.decodeNullTerminatedUnsafe(buf + 10) == ""); } -testUTF8Raw(); +testUTF8DecodeUnsafe(); diff --git a/tests/compiler/std/encoding.untouched.wat b/tests/compiler/std/encoding.untouched.wat index 3180ad1a08..031d7f7178 100644 --- a/tests/compiler/std/encoding.untouched.wat +++ b/tests/compiler/std/encoding.untouched.wat @@ -38,7 +38,7 @@ i32.const 1 i32.shr_u ) - (func $~lib/encoding/UTF8.length (; 2 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/encoding/UTF8Encoder.byteLength (; 2 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -152,7 +152,7 @@ (func $std/encoding/testUTF8Length (; 3 ;) (type $FUNCSIG$v) global.get $std/encoding/str i32.const 0 - call $~lib/encoding/UTF8.length + call $~lib/encoding/UTF8Encoder.byteLength i32.const 10 i32.eq i32.eqz @@ -166,7 +166,7 @@ end global.get $std/encoding/str i32.const 1 - call $~lib/encoding/UTF8.length + call $~lib/encoding/UTF8Encoder.byteLength i32.const 11 i32.eq i32.eqz @@ -327,7 +327,7 @@ i32.store local.get $0 ) - (func $~lib/encoding/UTF8.encode (; 9 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/encoding/UTF8Encoder.encode (; 9 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -346,7 +346,7 @@ block $~lib/runtime/ALLOCATE|inlined.0 (result i32) local.get $0 local.get $1 - call $~lib/encoding/UTF8.length + call $~lib/encoding/UTF8Encoder.byteLength local.set $4 local.get $4 call $~lib/runtime/allocate @@ -532,7 +532,7 @@ if i32.const 0 i32.const 80 - i32.const 97 + i32.const 122 i32.const 4 call $~lib/env/abort unreachable @@ -564,7 +564,7 @@ (local $1 i32) global.get $std/encoding/str i32.const 0 - call $~lib/encoding/UTF8.encode + call $~lib/encoding/UTF8Encoder.encode local.set $0 local.get $0 local.set $1 @@ -712,12 +712,12 @@ unreachable end ) - (func $std/encoding/testUTF8EncodeDelimited (; 12 ;) (type $FUNCSIG$v) + (func $std/encoding/testUTF8EncodeNullTerminated (; 12 ;) (type $FUNCSIG$v) (local $0 i32) (local $1 i32) global.get $std/encoding/str i32.const 1 - call $~lib/encoding/UTF8.encode + call $~lib/encoding/UTF8Encoder.encode local.set $0 local.get $0 local.set $1 @@ -2671,7 +2671,7 @@ i32.store offset=4 local.get $0 ) - (func $~lib/encoding/UTF8.decodeRawDelimited (; 19 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/encoding/UTF8Decoder.decodeNullTerminatedUnsafe (; 19 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -2679,6 +2679,17 @@ (local $6 i32) (local $7 i32) (local $8 i32) + local.get $1 + global.get $~lib/runtime/MAX_BYTELENGTH + i32.gt_u + if + i32.const 0 + i32.const 80 + i32.const 192 + i32.const 47 + call $~lib/env/abort + unreachable + end local.get $0 local.set $2 local.get $0 @@ -2687,25 +2698,32 @@ local.set $3 local.get $3 local.get $2 - i32.gt_u + i32.ge_u i32.eqz if i32.const 0 i32.const 80 - i32.const 152 + i32.const 195 i32.const 4 call $~lib/env/abort unreachable end block $~lib/runtime/ALLOCATE|inlined.1 (result i32) + local.get $1 + local.tee $5 i32.const 16 + local.tee $6 + local.get $5 + local.get $6 + i32.lt_s + select local.set $4 local.get $4 call $~lib/runtime/allocate end - local.set $5 + local.set $7 i32.const 0 - local.set $6 + local.set $8 block $break|0 loop $continue|0 local.get $2 @@ -2733,37 +2751,37 @@ br $break|0 end block $~lib/runtime/REALLOCATE|inlined.0 (result i32) - local.get $5 - local.set $8 - local.get $6 + local.get $7 + local.set $6 + local.get $8 i32.const 2 i32.add - local.set $7 - local.get $8 - local.get $7 + local.set $5 + local.get $6 + local.get $5 call $~lib/runtime/reallocate end - local.set $5 - local.get $5 - local.get $6 + local.set $7 + local.get $7 + local.get $8 i32.add local.get $4 i32.store16 - local.get $6 + local.get $8 i32.const 2 i32.add - local.set $6 + local.set $8 else local.get $4 i32.const 191 i32.gt_u - local.tee $7 + local.tee $5 if (result i32) local.get $4 i32.const 224 i32.lt_u else - local.get $7 + local.get $5 end if local.get $2 @@ -2773,19 +2791,19 @@ br $break|0 end block $~lib/runtime/REALLOCATE|inlined.1 (result i32) - local.get $5 - local.set $8 - local.get $6 + local.get $7 + local.set $6 + local.get $8 i32.const 2 i32.add - local.set $7 - local.get $8 - local.get $7 + local.set $5 + local.get $6 + local.get $5 call $~lib/runtime/reallocate end - local.set $5 - local.get $5 - local.get $6 + local.set $7 + local.get $7 + local.get $8 i32.add local.get $4 i32.const 31 @@ -2794,32 +2812,32 @@ i32.shl block (result i32) local.get $2 - local.tee $7 + local.tee $5 i32.const 1 i32.add local.set $2 - local.get $7 + local.get $5 end i32.load8_u i32.const 63 i32.and i32.or i32.store16 - local.get $6 + local.get $8 i32.const 2 i32.add - local.set $6 + local.set $8 else local.get $4 i32.const 239 i32.gt_u - local.tee $7 + local.tee $5 if (result i32) local.get $4 i32.const 365 i32.lt_u else - local.get $7 + local.get $5 end if local.get $2 @@ -2862,39 +2880,39 @@ i32.add local.set $2 block $~lib/runtime/REALLOCATE|inlined.2 (result i32) - local.get $5 - local.set $8 - local.get $6 + local.get $7 + local.set $6 + local.get $8 i32.const 4 i32.add - local.set $7 - local.get $8 - local.get $7 + local.set $5 + local.get $6 + local.get $5 call $~lib/runtime/reallocate end - local.set $5 - local.get $5 - local.get $6 - i32.add local.set $7 local.get $7 + local.get $8 + i32.add + local.set $5 + local.get $5 i32.const 55296 local.get $4 i32.const 10 i32.shr_u i32.add i32.store16 - local.get $7 + local.get $5 i32.const 56320 local.get $4 i32.const 1023 i32.and i32.add i32.store16 offset=2 - local.get $6 + local.get $8 i32.const 4 i32.add - local.set $6 + local.set $8 else local.get $2 i32.const 2 @@ -2905,19 +2923,19 @@ br $break|0 end block $~lib/runtime/REALLOCATE|inlined.3 (result i32) - local.get $5 - local.set $8 - local.get $6 + local.get $7 + local.set $6 + local.get $8 i32.const 2 i32.add - local.set $7 - local.get $8 - local.get $7 + local.set $5 + local.get $6 + local.get $5 call $~lib/runtime/reallocate end - local.set $5 - local.get $5 - local.get $6 + local.set $7 + local.get $7 + local.get $8 i32.add local.get $4 i32.const 15 @@ -2941,10 +2959,10 @@ i32.const 2 i32.add local.set $2 - local.get $6 + local.get $8 i32.const 2 i32.add - local.set $6 + local.set $8 end end end @@ -2955,12 +2973,12 @@ end block $~lib/runtime/REGISTER<~lib/string/String>|inlined.0 (result i32) block $~lib/runtime/REALLOCATE|inlined.4 (result i32) - local.get $5 - local.set $8 - local.get $6 - local.set $7 - local.get $8 local.get $7 + local.set $6 + local.get $8 + local.set $5 + local.get $6 + local.get $5 call $~lib/runtime/reallocate end local.set $4 @@ -2969,7 +2987,7 @@ call $~lib/runtime/register end ) - (func $~lib/encoding/UTF8.decodeRaw (; 20 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/encoding/UTF8Decoder.decodeUnsafe (; 20 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -2977,12 +2995,35 @@ (local $6 i32) (local $7 i32) (local $8 i32) + local.get $1 + global.get $~lib/runtime/MAX_BYTELENGTH + i32.gt_u + if + i32.const 0 + i32.const 80 + i32.const 152 + i32.const 44 + call $~lib/env/abort + unreachable + end local.get $0 local.set $2 local.get $0 local.get $1 i32.add local.set $3 + local.get $3 + local.get $2 + i32.ge_u + i32.eqz + if + i32.const 0 + i32.const 80 + i32.const 155 + i32.const 4 + call $~lib/env/abort + unreachable + end block $~lib/runtime/ALLOCATE|inlined.2 (result i32) local.get $1 i32.const 1 @@ -3174,7 +3215,7 @@ call $~lib/runtime/register end ) - (func $~lib/encoding/UTF8.decode (; 21 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/encoding/UTF8Decoder.decode (; 21 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) local.get $1 i32.const 0 i32.ne @@ -3182,12 +3223,12 @@ local.get $0 local.get $0 call $~lib/arraybuffer/ArrayBuffer#get:byteLength - call $~lib/encoding/UTF8.decodeRawDelimited + call $~lib/encoding/UTF8Decoder.decodeNullTerminatedUnsafe else local.get $0 local.get $0 call $~lib/arraybuffer/ArrayBuffer#get:byteLength - call $~lib/encoding/UTF8.decodeRaw + call $~lib/encoding/UTF8Decoder.decodeUnsafe end ) (func $~lib/util/string/compareImpl (; 22 ;) (type $FUNCSIG$iiiiii) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (param $4 i32) (result i32) @@ -3291,11 +3332,11 @@ (local $0 i32) global.get $std/encoding/str i32.const 0 - call $~lib/encoding/UTF8.encode + call $~lib/encoding/UTF8Encoder.encode local.set $0 local.get $0 i32.const 0 - call $~lib/encoding/UTF8.decode + call $~lib/encoding/UTF8Decoder.decode global.get $std/encoding/str call $~lib/string/String.__eq i32.eqz @@ -3308,15 +3349,15 @@ unreachable end ) - (func $std/encoding/testUTF8DecodeDelimited (; 25 ;) (type $FUNCSIG$v) + (func $std/encoding/testUTF8DecodeNullTerminated (; 25 ;) (type $FUNCSIG$v) (local $0 i32) global.get $std/encoding/str i32.const 1 - call $~lib/encoding/UTF8.encode + call $~lib/encoding/UTF8Encoder.encode local.set $0 local.get $0 i32.const 1 - call $~lib/encoding/UTF8.decode + call $~lib/encoding/UTF8Decoder.decode global.get $std/encoding/str call $~lib/string/String.__eq i32.eqz @@ -3329,15 +3370,15 @@ unreachable end ) - (func $std/encoding/testUTF8Raw (; 26 ;) (type $FUNCSIG$v) + (func $std/encoding/testUTF8DecodeUnsafe (; 26 ;) (type $FUNCSIG$v) (local $0 i32) global.get $std/encoding/str i32.const 0 - call $~lib/encoding/UTF8.encode + call $~lib/encoding/UTF8Encoder.encode local.set $0 local.get $0 i32.const 0 - call $~lib/encoding/UTF8.decodeRaw + call $~lib/encoding/UTF8Decoder.decodeUnsafe i32.const 160 call $~lib/string/String.__eq i32.eqz @@ -3352,8 +3393,8 @@ local.get $0 global.get $std/encoding/str i32.const 0 - call $~lib/encoding/UTF8.length - call $~lib/encoding/UTF8.decodeRaw + call $~lib/encoding/UTF8Encoder.byteLength + call $~lib/encoding/UTF8Decoder.decodeUnsafe global.get $std/encoding/str call $~lib/string/String.__eq i32.eqz @@ -3367,7 +3408,7 @@ end local.get $0 i32.const 4 - call $~lib/encoding/UTF8.decodeRaw + call $~lib/encoding/UTF8Decoder.decodeUnsafe i32.const 168 call $~lib/string/String.__eq i32.eqz @@ -3383,7 +3424,7 @@ i32.const 4 i32.add i32.const 2 - call $~lib/encoding/UTF8.decodeRaw + call $~lib/encoding/UTF8Decoder.decodeUnsafe i32.const 184 call $~lib/string/String.__eq i32.eqz @@ -3399,7 +3440,7 @@ i32.const 6 i32.add i32.const 4 - call $~lib/encoding/UTF8.decodeRaw + call $~lib/encoding/UTF8Decoder.decodeUnsafe i32.const 200 call $~lib/string/String.__eq i32.eqz @@ -3415,7 +3456,7 @@ i32.const 10 i32.add i32.const 0 - call $~lib/encoding/UTF8.decodeRaw + call $~lib/encoding/UTF8Decoder.decodeUnsafe i32.const 160 call $~lib/string/String.__eq i32.eqz @@ -3434,7 +3475,7 @@ i32.const 4 i32.add global.get $~lib/runtime/MAX_BYTELENGTH - call $~lib/encoding/UTF8.decodeRawDelimited + call $~lib/encoding/UTF8Decoder.decodeNullTerminatedUnsafe i32.const 216 call $~lib/string/String.__eq i32.eqz @@ -3450,7 +3491,7 @@ i32.const 6 i32.add global.get $~lib/runtime/MAX_BYTELENGTH - call $~lib/encoding/UTF8.decodeRawDelimited + call $~lib/encoding/UTF8Decoder.decodeNullTerminatedUnsafe i32.const 200 call $~lib/string/String.__eq i32.eqz @@ -3466,7 +3507,7 @@ i32.const 10 i32.add global.get $~lib/runtime/MAX_BYTELENGTH - call $~lib/encoding/UTF8.decodeRawDelimited + call $~lib/encoding/UTF8Decoder.decodeNullTerminatedUnsafe i32.const 160 call $~lib/string/String.__eq i32.eqz @@ -3492,10 +3533,10 @@ global.get $~lib/allocator/arena/startOffset global.set $~lib/allocator/arena/offset call $std/encoding/testUTF8Encode - call $std/encoding/testUTF8EncodeDelimited + call $std/encoding/testUTF8EncodeNullTerminated call $std/encoding/testUTF8Decode - call $std/encoding/testUTF8DecodeDelimited - call $std/encoding/testUTF8Raw + call $std/encoding/testUTF8DecodeNullTerminated + call $std/encoding/testUTF8DecodeUnsafe ) (func $start (; 28 ;) (type $FUNCSIG$v) call $start:std/encoding diff --git a/tests/compiler/std/string.optimized.wat b/tests/compiler/std/string.optimized.wat index a3b17e9bc0..c847927717 100644 --- a/tests/compiler/std/string.optimized.wat +++ b/tests/compiler/std/string.optimized.wat @@ -575,7 +575,7 @@ if i32.const 0 i32.const 216 - i32.const 25 + i32.const 24 i32.const 4 call $~lib/env/abort unreachable @@ -630,7 +630,7 @@ if i32.const 0 i32.const 216 - i32.const 165 + i32.const 164 i32.const 4 call $~lib/env/abort unreachable @@ -678,7 +678,7 @@ if i32.const 0 i32.const 216 - i32.const 78 + i32.const 77 i32.const 4 call $~lib/env/abort unreachable @@ -726,7 +726,7 @@ if i32.const 0 i32.const 216 - i32.const 134 + i32.const 133 i32.const 4 call $~lib/env/abort unreachable @@ -1877,7 +1877,7 @@ if i32.const 0 i32.const 216 - i32.const 282 + i32.const 281 i32.const 4 call $~lib/env/abort unreachable @@ -1972,7 +1972,7 @@ if i32.const 0 i32.const 216 - i32.const 303 + i32.const 302 i32.const 4 call $~lib/env/abort unreachable @@ -2068,7 +2068,7 @@ if i32.const 0 i32.const 216 - i32.const 150 + i32.const 149 i32.const 4 call $~lib/env/abort unreachable @@ -2490,7 +2490,7 @@ if i32.const 0 i32.const 216 - i32.const 464 + i32.const 463 i32.const 10 call $~lib/env/abort unreachable @@ -2762,7 +2762,7 @@ if i32.const 0 i32.const 216 - i32.const 324 + i32.const 323 i32.const 4 call $~lib/env/abort unreachable @@ -2792,7 +2792,7 @@ if i32.const 0 i32.const 216 - i32.const 329 + i32.const 328 i32.const 6 call $~lib/env/abort unreachable @@ -3354,7 +3354,7 @@ if i32.const 0 i32.const 216 - i32.const 351 + i32.const 350 i32.const 4 call $~lib/env/abort unreachable @@ -5072,7 +5072,7 @@ if i32.const 0 i32.const 216 - i32.const 190 + i32.const 189 i32.const 4 call $~lib/env/abort unreachable diff --git a/tests/compiler/std/string.untouched.wat b/tests/compiler/std/string.untouched.wat index 91eebc927b..8fa9e205ab 100644 --- a/tests/compiler/std/string.untouched.wat +++ b/tests/compiler/std/string.untouched.wat @@ -524,7 +524,7 @@ if i32.const 0 i32.const 216 - i32.const 25 + i32.const 24 i32.const 4 call $~lib/env/abort unreachable @@ -597,7 +597,7 @@ if i32.const 0 i32.const 216 - i32.const 165 + i32.const 164 i32.const 4 call $~lib/env/abort unreachable @@ -663,7 +663,7 @@ if i32.const 0 i32.const 216 - i32.const 78 + i32.const 77 i32.const 4 call $~lib/env/abort unreachable @@ -727,7 +727,7 @@ if i32.const 0 i32.const 216 - i32.const 134 + i32.const 133 i32.const 4 call $~lib/env/abort unreachable @@ -2288,7 +2288,7 @@ if i32.const 0 i32.const 216 - i32.const 282 + i32.const 281 i32.const 4 call $~lib/env/abort unreachable @@ -2397,7 +2397,7 @@ if i32.const 0 i32.const 216 - i32.const 303 + i32.const 302 i32.const 4 call $~lib/env/abort unreachable @@ -2507,7 +2507,7 @@ if i32.const 0 i32.const 216 - i32.const 150 + i32.const 149 i32.const 4 call $~lib/env/abort unreachable @@ -3021,7 +3021,7 @@ if i32.const 0 i32.const 216 - i32.const 464 + i32.const 463 i32.const 10 call $~lib/env/abort unreachable @@ -3311,7 +3311,7 @@ if i32.const 0 i32.const 216 - i32.const 324 + i32.const 323 i32.const 4 call $~lib/env/abort unreachable @@ -3339,7 +3339,7 @@ if i32.const 0 i32.const 216 - i32.const 329 + i32.const 328 i32.const 6 call $~lib/env/abort unreachable @@ -4110,7 +4110,7 @@ if i32.const 0 i32.const 216 - i32.const 351 + i32.const 350 i32.const 4 call $~lib/env/abort unreachable @@ -6587,7 +6587,7 @@ if i32.const 0 i32.const 216 - i32.const 190 + i32.const 189 i32.const 4 call $~lib/env/abort unreachable