diff --git a/std/assembly/encoding.ts b/std/assembly/encoding.ts new file mode 100644 index 0000000000..42bde1be65 --- /dev/null +++ b/std/assembly/encoding.ts @@ -0,0 +1,249 @@ +import { ALLOCATE, REGISTER, REALLOCATE, MAX_BYTELENGTH } from "./runtime"; +import { E_INVALIDLENGTH, E_NOTIMPLEMENTED } from "./util/error"; + +export class UTF16Encoder { + + /** Calculates the length of a string when encoded as UTF16 bytes. */ + static byteLength(str: string): i32 { + return str.length << 1; + } + + /** 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); + } + + constructor() { + throw new Error(E_NOTIMPLEMENTED); + } + + 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 + 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); + } +} + +export class UTF8Encoder { + + /** 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 = nullTerminated ? 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 UTF8 bytes. */ + static encode(str: string, nullTerminated: bool = false): ArrayBuffer { + var strOff = changetype(str); + var strEnd = changetype(str) + (str.length << 1); + var buf = ALLOCATE(UTF8Encoder.byteLength(str, nullTerminated)); + 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 (nullTerminated) store(bufOff, 0); + return REGISTER(buf); + } + + constructor() { + throw new Error(E_NOTIMPLEMENTED); + } + + 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 + 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) { + 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)); + } + + /** Decodes UTF8 bytes to a string. Zero terminated. */ + @unsafe + 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(min(maxLen, 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)); + } + + 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 67f655cb44..af8bb084db 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,36 @@ 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 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 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 cdf4e4c9d2..0acbfe33f7 100644 --- a/std/assembly/string.ts +++ b/std/assembly/string.ts @@ -408,112 +408,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/std/string-utf8.optimized.wat b/tests/compiler/std/encoding.optimized.wat similarity index 61% rename from tests/compiler/std/string-utf8.optimized.wat rename to tests/compiler/std/encoding.optimized.wat index abc325672d..07ce2de591 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/UTF8Encoder.byteLength (; 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/UTF8Encoder.byteLength + 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/UTF8Encoder.byteLength + 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/UTF8Encoder.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/UTF8Encoder.byteLength + 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 122 + 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/UTF8Encoder.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/testUTF8EncodeNullTerminated (; 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/UTF8Encoder.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) @@ -987,9 +1320,203 @@ i32.add local.tee $0 local.get $1 - i32.const 1 - i32.add - local.tee $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 $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 $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 + local.get $1 i32.load8_u i32.store8 local.get $0 @@ -1015,738 +1542,1020 @@ local.get $0 i32.const 1 i32.add - local.tee $0 - local.get $1 + local.tee $3 i32.const 1 i32.add - local.tee $1 - i32.load8_u - i32.store8 - local.get $0 + local.set $0 + local.get $1 i32.const 1 i32.add - local.tee $0 - local.get $1 + local.tee $4 i32.const 1 i32.add - local.tee $1 + 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 - 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.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 - i32.add - local.tee $0 local.get $1 - i32.const 1 - i32.add - local.tee $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 - i32.const 1 - i32.add - local.tee $0 local.get $1 - i32.const 1 + i32.eq + br_if $~lib/util/memory/memmove|inlined.0 + local.get $1 + local.get $2 i32.add - local.tee $1 - i32.load8_u + 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.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/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.lt_u + if + i32.const 0 + i32.const 80 + 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 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 $2 - i32.eqz - br_if $~lib/util/memory/memmove|inlined.0 - local.get $2 - i32.const 1 - i32.sub - local.tee $2 + local.get $3 + i32.const 224 + i32.lt_u + local.set $1 + end + local.get $1 + if + 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 + local.get $4 + local.get $2 + call $~lib/runtime/reallocate + i32.const 1 + call $~lib/runtime/register ) - (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 + (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 136 - i32.const 149 - i32.const 4 + i32.const 80 + i32.const 152 + i32.const 44 call $~lib/env/abort unreachable end local.get $0 - i32.const 8 - i32.sub - local.tee $1 - i32.load - i32.const -1520547049 - i32.ne + local.get $1 + i32.add + local.tee $5 + local.get $0 + i32.lt_u if i32.const 0 - i32.const 136 - i32.const 151 + i32.const 80 + i32.const 155 i32.const 4 call $~lib/env/abort unreachable end local.get $1 i32.const 1 - i32.store - local.get $0 - ) - (func $~lib/string/String.fromUTF8 (; 8 ;) (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 $1 - i32.const 1 - i32.lt_u - if - i32.const 88 - return - end - 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/UTF8Decoder.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/UTF8Decoder.decodeNullTerminatedUnsafe + else + local.get $0 + local.get $0 + i32.const 8 + i32.sub + i32.load offset=4 + 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) (local $3 i32) loop $continue|0 local.get $2 @@ -1779,7 +2588,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 +2634,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/UTF8Encoder.encode + i32.const 0 + call $~lib/encoding/UTF8Decoder.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/testUTF8DecodeNullTerminated (; 19 ;) (type $FUNCSIG$v) + global.get $std/encoding/str + i32.const 1 + call $~lib/encoding/UTF8Encoder.encode + i32.const 1 + call $~lib/encoding/UTF8Decoder.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/testUTF8DecodeUnsafe (; 20 ;) (type $FUNCSIG$v) + (local $0 i32) + global.get $std/encoding/str + i32.const 0 + call $~lib/encoding/UTF8Encoder.encode + local.tee $0 + i32.const 0 + call $~lib/encoding/UTF8Decoder.decodeUnsafe + 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/UTF8Encoder.byteLength + call $~lib/encoding/UTF8Decoder.decodeUnsafe + 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/UTF8Decoder.decodeUnsafe + 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/UTF8Decoder.decodeUnsafe + 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/UTF8Decoder.decodeUnsafe + 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/UTF8Decoder.decodeUnsafe + 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/UTF8Decoder.decodeNullTerminatedUnsafe + 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/UTF8Decoder.decodeNullTerminatedUnsafe + 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/UTF8Decoder.decodeNullTerminatedUnsafe + 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/testUTF8EncodeNullTerminated + call $std/encoding/testUTF8Decode + call $std/encoding/testUTF8DecodeNullTerminated + call $std/encoding/testUTF8DecodeUnsafe ) - (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..6ea0d2a319 --- /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(UTF8Encoder.byteLength(str) == 10); + assert(UTF8Encoder.byteLength(str, true) == 11); +} +testUTF8Length(); + +function testUTF8Encode(): void { + var buf = UTF8Encoder.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 testUTF8EncodeNullTerminated(): void { + var buf = UTF8Encoder.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); +} +testUTF8EncodeNullTerminated(); + +function testUTF8Decode(): void { + var buf = UTF8Encoder.encode(str); + assert(UTF8Decoder.decode(buf) == str); +} +testUTF8Decode(); + +function testUTF8DecodeNullTerminated(): void { + var buf = UTF8Encoder.encode(str, true); + assert(UTF8Decoder.decode(buf, true) == str); +} +testUTF8DecodeNullTerminated(); + +function testUTF8DecodeUnsafe(): void { + var buf = changetype(UTF8Encoder.encode(str)); + + 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(UTF8Decoder.decodeNullTerminatedUnsafe(buf + 4) == "hi𤭢"); + assert(UTF8Decoder.decodeNullTerminatedUnsafe(buf + 6) == "𤭢"); + assert(UTF8Decoder.decodeNullTerminatedUnsafe(buf + 10) == ""); +} +testUTF8DecodeUnsafe(); 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..031d7f7178 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/UTF8Encoder.byteLength (; 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/UTF8Encoder.byteLength + 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/UTF8Encoder.byteLength + 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/UTF8Encoder.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/UTF8Encoder.byteLength + 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,202 +525,520 @@ end end end + local.get $2 + local.get $3 + i32.eq + i32.eqz + if + i32.const 0 + i32.const 80 + i32.const 122 + 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/UTF8Encoder.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 + 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/testUTF8EncodeNullTerminated (; 12 ;) (type $FUNCSIG$v) + (local $0 i32) + (local $1 i32) + global.get $std/encoding/str + i32.const 1 + call $~lib/encoding/UTF8Encoder.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 @@ -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,1128 @@ 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/UTF8Decoder.decodeNullTerminatedUnsafe (; 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 $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 + 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 195 + i32.const 4 + call $~lib/env/abort + unreachable + end + block $~lib/runtime/ALLOCATE|inlined.1 (result i32) 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 + 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 $7 + i32.const 0 + local.set $8 + 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 + local.get $3 + i32.lt_u if - block $break|0 - loop $continue|0 - local.get $0 - i32.const 7 - i32.and + 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 - 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 + br $break|0 + end + block $~lib/runtime/REALLOCATE|inlined.0 (result i32) + local.get $7 + local.set $6 + local.get $8 + i32.const 2 + i32.add + local.set $5 + local.get $6 + local.get $5 + call $~lib/runtime/reallocate + end + local.set $7 + local.get $7 + local.get $8 + i32.add + local.get $4 + i32.store16 + local.get $8 + i32.const 2 + i32.add + local.set $8 + else + local.get $4 + i32.const 191 + i32.gt_u + local.tee $5 + if (result i32) + local.get $4 + i32.const 224 + i32.lt_u + else + local.get $5 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 + local.get $2 + local.get $3 + i32.ge_u + if + br $break|0 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 + block $~lib/runtime/REALLOCATE|inlined.1 (result i32) + local.get $7 + local.set $6 + local.get $8 + i32.const 2 i32.add - local.set $0 + local.set $5 + local.get $6 local.get $5 + call $~lib/runtime/reallocate end + local.set $7 + local.get $7 + local.get $8 + i32.add + local.get $4 + i32.const 31 + i32.and + i32.const 6 + i32.shl block (result i32) - local.get $1 + local.get $2 local.tee $5 i32.const 1 i32.add - local.set $1 + local.set $2 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 + i32.const 63 + i32.and + i32.or + i32.store16 + local.get $8 + i32.const 2 + i32.add + local.set $8 + else + local.get $4 + i32.const 239 + i32.gt_u + local.tee $5 + if (result i32) + local.get $4 + i32.const 365 + i32.lt_u + else + local.get $5 + end + if local.get $2 - i32.eqz + 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 $0 + 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.tee $2 + local.set $4 + local.get $2 + i32.const 3 + i32.add + local.set $2 + block $~lib/runtime/REALLOCATE|inlined.2 (result i32) + local.get $7 + local.set $6 + local.get $8 + i32.const 4 + i32.add + local.set $5 + local.get $6 + local.get $5 + call $~lib/runtime/reallocate + end + 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 $5 + i32.const 56320 + local.get $4 + i32.const 1023 + i32.and + i32.add + i32.store16 offset=2 + local.get $8 + i32.const 4 + i32.add + local.set $8 + else + local.get $2 + i32.const 2 + i32.add + local.get $3 + i32.gt_u + if + br $break|0 + end + block $~lib/runtime/REALLOCATE|inlined.3 (result i32) + local.get $7 + local.set $6 + local.get $8 + i32.const 2 + i32.add + local.set $5 + local.get $6 + local.get $5 + call $~lib/runtime/reallocate + end + local.set $7 + local.get $7 + local.get $8 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 $8 + i32.const 2 i32.add - i64.load - i64.store + local.set $8 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 + block $~lib/runtime/REGISTER<~lib/string/String>|inlined.0 (result i32) + block $~lib/runtime/REALLOCATE|inlined.4 (result i32) + 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 + local.get $4 + i32.const 1 + call $~lib/runtime/register + 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) + (func $~lib/encoding/UTF8Decoder.decodeUnsafe (; 20 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) - local.get $0 - global.get $~lib/memory/HEAP_BASE + (local $3 i32) + (local $4 i32) + (local $5 i32) + (local $6 i32) + (local $7 i32) + (local $8 i32) + local.get $1 + global.get $~lib/runtime/MAX_BYTELENGTH i32.gt_u - i32.eqz if i32.const 0 - i32.const 136 - i32.const 149 - i32.const 4 + i32.const 80 + i32.const 152 + i32.const 44 call $~lib/env/abort unreachable end local.get $0 - global.get $~lib/runtime/HEADER_SIZE - i32.sub local.set $2 + local.get $0 + local.get $1 + i32.add + local.set $3 + local.get $3 local.get $2 - i32.load - global.get $~lib/runtime/HEADER_MAGIC - i32.eq + i32.ge_u i32.eqz if i32.const 0 - i32.const 136 - i32.const 151 + i32.const 80 + i32.const 155 i32.const 4 call $~lib/env/abort unreachable 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) - (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 + 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 - i32.const 0 - local.set $2 - local.get $1 - i32.const 1 - i32.shl - call $~lib/memory/memory.allocate - local.set $3 - i32.const 0 - local.set $4 + 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 +3197,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/UTF8Decoder.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/UTF8Decoder.decodeNullTerminatedUnsafe + else + local.get $0 + local.get $0 + call $~lib/arraybuffer/ArrayBuffer#get:byteLength + 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) (local $5 i32) (local $6 i32) (local $7 i32) @@ -2324,7 +3284,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 +3328,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/UTF8Encoder.encode + local.set $0 + local.get $0 + i32.const 0 + call $~lib/encoding/UTF8Decoder.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/testUTF8DecodeNullTerminated (; 25 ;) (type $FUNCSIG$v) + (local $0 i32) + global.get $std/encoding/str + i32.const 1 + call $~lib/encoding/UTF8Encoder.encode + local.set $0 + local.get $0 + i32.const 1 + call $~lib/encoding/UTF8Decoder.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/testUTF8DecodeUnsafe (; 26 ;) (type $FUNCSIG$v) + (local $0 i32) + global.get $std/encoding/str + i32.const 0 + call $~lib/encoding/UTF8Encoder.encode + local.set $0 + local.get $0 + i32.const 0 + call $~lib/encoding/UTF8Decoder.decodeUnsafe + 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/UTF8Encoder.byteLength + call $~lib/encoding/UTF8Decoder.decodeUnsafe + 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/UTF8Decoder.decodeUnsafe + 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/UTF8Decoder.decodeUnsafe + 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/UTF8Decoder.decodeUnsafe + 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/UTF8Decoder.decodeUnsafe + 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/UTF8Decoder.decodeNullTerminatedUnsafe + 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/UTF8Decoder.decodeNullTerminatedUnsafe + 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/UTF8Decoder.decodeNullTerminatedUnsafe + 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/testUTF8EncodeNullTerminated + call $std/encoding/testUTF8Decode + call $std/encoding/testUTF8DecodeNullTerminated + call $std/encoding/testUTF8DecodeUnsafe + ) + (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..c847927717 100644 --- a/tests/compiler/std/string.optimized.wat +++ b/tests/compiler/std/string.optimized.wat @@ -2490,7 +2490,7 @@ if i32.const 0 i32.const 216 - i32.const 569 + i32.const 463 i32.const 10 call $~lib/env/abort unreachable diff --git a/tests/compiler/std/string.untouched.wat b/tests/compiler/std/string.untouched.wat index e8e9c3aa52..8fa9e205ab 100644 --- a/tests/compiler/std/string.untouched.wat +++ b/tests/compiler/std/string.untouched.wat @@ -3021,7 +3021,7 @@ if i32.const 0 i32.const 216 - i32.const 569 + i32.const 463 i32.const 10 call $~lib/env/abort unreachable