Add a simple UTF8 converter, i.e. for calling C++ APIs; Fix disabling 'abort' entirely

This commit is contained in:
dcodeIO 2018-05-21 23:14:47 +02:00
parent 73417a9a06
commit ea0eb7f1a5
13 changed files with 1733 additions and 10 deletions

View File

@ -357,7 +357,7 @@ exports.main = function main(argv, options, callback) {
// Initialize default aliases
assemblyscript.setGlobalAlias(compilerOptions, "Math", "NativeMath");
assemblyscript.setGlobalAlias(compilerOptions, "Mathf", "NativeMathf");
assemblyscript.setGlobalAlias(compilerOptions, "abort", "~lib/env/abort");
assemblyscript.setGlobalAlias(compilerOptions, "abort", "~lib/env/abort"); // to disable: --use abort=
// Add or override aliases if specified
var aliases = args.use;
@ -369,7 +369,7 @@ exports.main = function main(argv, options, callback) {
if (p < 0) return callback(Error("Global alias '" + part + "' is invalid."));
let name = part.substring(0, p).trim();
let alias = part.substring(p + 1).trim();
if (!name.length || !alias.length) return callback(Error("Global alias '" + part + "' is invalid."));
if (!name.length) return callback(Error("Global alias '" + part + "' is invalid."));
assemblyscript.setGlobalAlias(compilerOptions, name, alias);
}
}

2
dist/asc.js vendored

File diff suppressed because one or more lines are too long

2
dist/asc.js.map vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -416,7 +416,7 @@ export class Program extends DiagnosticEmitter {
var globalAliases = options.globalAliases;
if (globalAliases) {
for (let [alias, name] of globalAliases) {
if (!alias.length) continue; // explicitly disabled
if (!name.length) continue; // explicitly disabled
let element = this.elementsLookup.get(name);
if (element) this.elementsLookup.set(alias, element);
else throw new Error("element not found: " + name);

4
std/assembly.d.ts vendored
View File

@ -403,7 +403,8 @@ declare class String {
static fromCodePoint(cp: i32): string;
static fromCodePoints(arr: i32[]): string;
readonly length: u32;
readonly length: i32;
readonly lengthUTF8: i32;
charAt(index: u32): string;
charCodeAt(index: u32): u16;
@ -419,6 +420,7 @@ declare class String {
trimRight(): string;
repeat(count?: i32): string;
toString(): string;
toUTF8(): usize;
}
/** Class for representing a runtime error. Base class of all errors. */

View File

@ -412,6 +412,66 @@ export class String {
toString(): String {
return this;
}
get lengthUTF8(): i32 {
var clen = this.length;
var blen = 1; // null terminated
for (let i = 0; i < clen;) {
let c = <u32>load<u16>(changetype<usize>(this) + (<usize>i << 1), HEADER_SIZE);
if (c < 128) {
blen += 1; ++i;
} else if (c < 2048) {
blen += 2; ++i;
} else if (
(c & 0xFC00) === 0xD800 &&
(<u32>load<u16>(changetype<usize>(this) + ((<usize>i + 1) << 1), HEADER_SIZE) & 0xFC00) === 0xDC00
) {
blen += 4; i += 2;
} else {
blen += 3; ++i;
}
}
return blen;
}
toUTF8(): usize {
var len = this.lengthUTF8;
var buf = allocate_memory(len);
var off: usize = 0;
for (let i = 0, k = this.length; i < k;) {
let c1 = <u32>load<u16>(changetype<usize>(this) + (<usize>i << 1), HEADER_SIZE);
if (c1 < 128) {
store<u8>(buf + off, c1);
++off; ++i;
} else if (c1 < 2048) {
let pos = buf + off;
store<u8>(pos, c1 >> 6 | 192, 0);
store<u8>(pos, c1 & 63 | 128, 1);
off += 2; ++i;
} else {
let pos = buf + off;
if ((c1 & 0xFC00) == 0xD800) {
let c2 = <u32>load<u16>(changetype<usize>(this) + ((<usize>i + 1) << 1), HEADER_SIZE);
if ((c2 & 0xFC00) == 0xDC00) {
c1 = 0x10000 + ((c1 & 0x03FF) << 10) + (c2 & 0x03FF);
store<u8>(pos, c1 >> 18 | 240, 0);
store<u8>(pos, c1 >> 12 & 63 | 128, 1);
store<u8>(pos, c1 >> 6 & 63 | 128, 2);
store<u8>(pos, c1 & 63 | 128, 3);
off += 4; i += 2;
continue;
}
}
store<u8>(pos, c1 >> 12 | 224, 0);
store<u8>(pos, c1 >> 6 & 63 | 128, 1);
store<u8>(pos, c1 & 63 | 128, 2);
off += 3; ++i;
}
}
assert(off == len - 1);
store<u8>(buf + off, 0);
return buf;
}
}
export function parseInt(str: String, radix: i32 = 0): f64 {

View File

@ -0,0 +1,768 @@
(module
(type $ii (func (param i32) (result i32)))
(type $iiiiv (func (param i32 i32 i32 i32)))
(type $iv (func (param i32)))
(type $v (func))
(import "env" "abort" (func $~lib/env/abort (param i32 i32 i32 i32)))
(global $~lib/allocator/arena/startOffset (mut i32) (i32.const 0))
(global $~lib/allocator/arena/offset (mut i32) (i32.const 0))
(global $std/string-utf8/str (mut i32) (i32.const 8))
(global $std/string-utf8/len (mut i32) (i32.const 0))
(global $std/string-utf8/ptr (mut i32) (i32.const 0))
(global $HEAP_BASE i32 (i32.const 96))
(memory $0 1)
(data (i32.const 8) "\06\00\00\00\01\d87\dch\00i\00R\d8b\df")
(data (i32.const 24) "\12\00\00\00s\00t\00d\00/\00s\00t\00r\00i\00n\00g\00-\00u\00t\00f\008\00.\00t\00s")
(data (i32.const 64) "\0e\00\00\00~\00l\00i\00b\00/\00s\00t\00r\00i\00n\00g\00.\00t\00s")
(export "memory" (memory $0))
(start $start)
(func $~lib/string/String#get:lengthUTF8 (; 1 ;) (type $ii) (param $0 i32) (result i32)
(local $1 i32)
(local $2 i32)
(local $3 i32)
(local $4 i32)
(set_local $4
(i32.load
(get_local $0)
)
)
(set_local $1
(i32.const 1)
)
(loop $continue|0
(if
(i32.lt_s
(get_local $2)
(get_local $4)
)
(block
(set_local $2
(if (result i32)
(i32.lt_u
(tee_local $3
(i32.load16_u offset=4
(i32.add
(get_local $0)
(i32.shl
(get_local $2)
(i32.const 1)
)
)
)
)
(i32.const 128)
)
(block (result i32)
(set_local $1
(i32.add
(get_local $1)
(i32.const 1)
)
)
(i32.add
(get_local $2)
(i32.const 1)
)
)
(if (result i32)
(i32.lt_u
(get_local $3)
(i32.const 2048)
)
(block (result i32)
(set_local $1
(i32.add
(get_local $1)
(i32.const 2)
)
)
(i32.add
(get_local $2)
(i32.const 1)
)
)
(if (result i32)
(if (result i32)
(tee_local $3
(i32.eq
(i32.and
(get_local $3)
(i32.const 64512)
)
(i32.const 55296)
)
)
(i32.eq
(i32.and
(i32.load16_u offset=4
(i32.add
(get_local $0)
(i32.shl
(i32.add
(get_local $2)
(i32.const 1)
)
(i32.const 1)
)
)
)
(i32.const 64512)
)
(i32.const 56320)
)
(get_local $3)
)
(block (result i32)
(set_local $1
(i32.add
(get_local $1)
(i32.const 4)
)
)
(i32.add
(get_local $2)
(i32.const 2)
)
)
(block (result i32)
(set_local $1
(i32.add
(get_local $1)
(i32.const 3)
)
)
(i32.add
(get_local $2)
(i32.const 1)
)
)
)
)
)
)
(br $continue|0)
)
)
)
(get_local $1)
)
(func $~lib/allocator/arena/allocate_memory (; 2 ;) (type $ii) (param $0 i32) (result i32)
(local $1 i32)
(local $2 i32)
(local $3 i32)
(local $4 i32)
(if
(get_local $0)
(block
(if
(i32.gt_u
(get_local $0)
(i32.const 1073741824)
)
(unreachable)
)
(if
(i32.gt_u
(tee_local $0
(i32.and
(i32.add
(i32.add
(tee_local $1
(get_global $~lib/allocator/arena/offset)
)
(get_local $0)
)
(i32.const 7)
)
(i32.const -8)
)
)
(i32.shl
(tee_local $2
(current_memory)
)
(i32.const 16)
)
)
(if
(i32.lt_s
(grow_memory
(select
(get_local $2)
(tee_local $4
(tee_local $3
(i32.shr_u
(i32.and
(i32.add
(i32.sub
(get_local $0)
(get_local $1)
)
(i32.const 65535)
)
(i32.const -65536)
)
(i32.const 16)
)
)
)
(i32.gt_s
(get_local $2)
(get_local $4)
)
)
)
(i32.const 0)
)
(if
(i32.lt_s
(grow_memory
(get_local $3)
)
(i32.const 0)
)
(unreachable)
)
)
)
(set_global $~lib/allocator/arena/offset
(get_local $0)
)
(return
(get_local $1)
)
)
)
(i32.const 0)
)
(func $~lib/string/String#toUTF8 (; 3 ;) (type $ii) (param $0 i32) (result i32)
(local $1 i32)
(local $2 i32)
(local $3 i32)
(local $4 i32)
(local $5 i32)
(local $6 i32)
(local $7 i32)
(local $8 i32)
(set_local $5
(call $~lib/allocator/arena/allocate_memory
(tee_local $6
(call $~lib/string/String#get:lengthUTF8
(get_local $0)
)
)
)
)
(set_local $7
(i32.load
(get_local $0)
)
)
(loop $continue|0
(if
(i32.lt_s
(get_local $3)
(get_local $7)
)
(block
(set_local $2
(if (result i32)
(i32.lt_u
(tee_local $1
(i32.load16_u offset=4
(i32.add
(get_local $0)
(i32.shl
(get_local $3)
(i32.const 1)
)
)
)
)
(i32.const 128)
)
(block (result i32)
(i32.store8
(i32.add
(get_local $5)
(get_local $2)
)
(get_local $1)
)
(set_local $3
(i32.add
(get_local $3)
(i32.const 1)
)
)
(i32.add
(get_local $2)
(i32.const 1)
)
)
(if (result i32)
(i32.lt_u
(get_local $1)
(i32.const 2048)
)
(block (result i32)
(i32.store8
(tee_local $4
(i32.add
(get_local $5)
(get_local $2)
)
)
(i32.or
(i32.shr_u
(get_local $1)
(i32.const 6)
)
(i32.const 192)
)
)
(i32.store8 offset=1
(get_local $4)
(i32.or
(i32.and
(get_local $1)
(i32.const 63)
)
(i32.const 128)
)
)
(set_local $3
(i32.add
(get_local $3)
(i32.const 1)
)
)
(i32.add
(get_local $2)
(i32.const 2)
)
)
(block (result i32)
(set_local $4
(i32.add
(get_local $5)
(get_local $2)
)
)
(if
(i32.eq
(i32.and
(get_local $1)
(i32.const 64512)
)
(i32.const 55296)
)
(if
(i32.eq
(i32.and
(tee_local $8
(i32.load16_u offset=4
(i32.add
(get_local $0)
(i32.shl
(i32.add
(get_local $3)
(i32.const 1)
)
(i32.const 1)
)
)
)
)
(i32.const 64512)
)
(i32.const 56320)
)
(block
(i32.store8
(get_local $4)
(i32.or
(i32.shr_u
(tee_local $1
(i32.add
(i32.add
(i32.shl
(i32.and
(get_local $1)
(i32.const 1023)
)
(i32.const 10)
)
(i32.const 65536)
)
(i32.and
(get_local $8)
(i32.const 1023)
)
)
)
(i32.const 18)
)
(i32.const 240)
)
)
(i32.store8 offset=1
(get_local $4)
(i32.or
(i32.and
(i32.shr_u
(get_local $1)
(i32.const 12)
)
(i32.const 63)
)
(i32.const 128)
)
)
(i32.store8 offset=2
(get_local $4)
(i32.or
(i32.and
(i32.shr_u
(get_local $1)
(i32.const 6)
)
(i32.const 63)
)
(i32.const 128)
)
)
(i32.store8 offset=3
(get_local $4)
(i32.or
(i32.and
(get_local $1)
(i32.const 63)
)
(i32.const 128)
)
)
(set_local $2
(i32.add
(get_local $2)
(i32.const 4)
)
)
(set_local $3
(i32.add
(get_local $3)
(i32.const 2)
)
)
(br $continue|0)
)
)
)
(i32.store8
(get_local $4)
(i32.or
(i32.shr_u
(get_local $1)
(i32.const 12)
)
(i32.const 224)
)
)
(i32.store8 offset=1
(get_local $4)
(i32.or
(i32.and
(i32.shr_u
(get_local $1)
(i32.const 6)
)
(i32.const 63)
)
(i32.const 128)
)
)
(i32.store8 offset=2
(get_local $4)
(i32.or
(i32.and
(get_local $1)
(i32.const 63)
)
(i32.const 128)
)
)
(set_local $3
(i32.add
(get_local $3)
(i32.const 1)
)
)
(i32.add
(get_local $2)
(i32.const 3)
)
)
)
)
)
(br $continue|0)
)
)
)
(if
(i32.ne
(get_local $2)
(i32.sub
(get_local $6)
(i32.const 1)
)
)
(block
(call $~lib/env/abort
(i32.const 0)
(i32.const 64)
(i32.const 471)
(i32.const 4)
)
(unreachable)
)
)
(i32.store8
(i32.add
(get_local $5)
(get_local $2)
)
(i32.const 0)
)
(get_local $5)
)
(func $~lib/allocator/arena/free_memory (; 4 ;) (type $iv) (param $0 i32)
(nop)
)
(func $start (; 5 ;) (type $v)
(set_global $~lib/allocator/arena/startOffset
(i32.and
(i32.add
(get_global $HEAP_BASE)
(i32.const 7)
)
(i32.const -8)
)
)
(set_global $~lib/allocator/arena/offset
(get_global $~lib/allocator/arena/startOffset)
)
(set_global $std/string-utf8/len
(call $~lib/string/String#get:lengthUTF8
(get_global $std/string-utf8/str)
)
)
(if
(i32.ne
(get_global $std/string-utf8/len)
(i32.const 11)
)
(block
(call $~lib/env/abort
(i32.const 0)
(i32.const 24)
(i32.const 7)
(i32.const 0)
)
(unreachable)
)
)
(set_global $std/string-utf8/ptr
(call $~lib/string/String#toUTF8
(get_global $std/string-utf8/str)
)
)
(if
(i32.ne
(i32.load8_u
(get_global $std/string-utf8/ptr)
)
(i32.const 240)
)
(block
(call $~lib/env/abort
(i32.const 0)
(i32.const 24)
(i32.const 11)
(i32.const 0)
)
(unreachable)
)
)
(if
(i32.ne
(i32.load8_u offset=1
(get_global $std/string-utf8/ptr)
)
(i32.const 144)
)
(block
(call $~lib/env/abort
(i32.const 0)
(i32.const 24)
(i32.const 12)
(i32.const 0)
)
(unreachable)
)
)
(if
(i32.ne
(i32.load8_u offset=2
(get_global $std/string-utf8/ptr)
)
(i32.const 144)
)
(block
(call $~lib/env/abort
(i32.const 0)
(i32.const 24)
(i32.const 13)
(i32.const 0)
)
(unreachable)
)
)
(if
(i32.ne
(i32.load8_u offset=3
(get_global $std/string-utf8/ptr)
)
(i32.const 183)
)
(block
(call $~lib/env/abort
(i32.const 0)
(i32.const 24)
(i32.const 14)
(i32.const 0)
)
(unreachable)
)
)
(if
(i32.ne
(i32.load8_u offset=4
(get_global $std/string-utf8/ptr)
)
(i32.const 104)
)
(block
(call $~lib/env/abort
(i32.const 0)
(i32.const 24)
(i32.const 15)
(i32.const 0)
)
(unreachable)
)
)
(if
(i32.ne
(i32.load8_u offset=5
(get_global $std/string-utf8/ptr)
)
(i32.const 105)
)
(block
(call $~lib/env/abort
(i32.const 0)
(i32.const 24)
(i32.const 16)
(i32.const 0)
)
(unreachable)
)
)
(if
(i32.ne
(i32.load8_u offset=6
(get_global $std/string-utf8/ptr)
)
(i32.const 240)
)
(block
(call $~lib/env/abort
(i32.const 0)
(i32.const 24)
(i32.const 17)
(i32.const 0)
)
(unreachable)
)
)
(if
(i32.ne
(i32.load8_u offset=7
(get_global $std/string-utf8/ptr)
)
(i32.const 164)
)
(block
(call $~lib/env/abort
(i32.const 0)
(i32.const 24)
(i32.const 18)
(i32.const 0)
)
(unreachable)
)
)
(if
(i32.ne
(i32.load8_u offset=8
(get_global $std/string-utf8/ptr)
)
(i32.const 173)
)
(block
(call $~lib/env/abort
(i32.const 0)
(i32.const 24)
(i32.const 19)
(i32.const 0)
)
(unreachable)
)
)
(if
(i32.ne
(i32.load8_u offset=9
(get_global $std/string-utf8/ptr)
)
(i32.const 162)
)
(block
(call $~lib/env/abort
(i32.const 0)
(i32.const 24)
(i32.const 20)
(i32.const 0)
)
(unreachable)
)
)
(if
(i32.load8_u offset=10
(get_global $std/string-utf8/ptr)
)
(block
(call $~lib/env/abort
(i32.const 0)
(i32.const 24)
(i32.const 21)
(i32.const 0)
)
(unreachable)
)
)
(call $~lib/allocator/arena/free_memory
(get_global $std/string-utf8/ptr)
)
)
)

View File

@ -0,0 +1,23 @@
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();
assert(load<u8>(ptr, 0) == 0xf0);
assert(load<u8>(ptr, 1) == 0x90);
assert(load<u8>(ptr, 2) == 0x90);
assert(load<u8>(ptr, 3) == 0xb7);
assert(load<u8>(ptr, 4) == 0x68);
assert(load<u8>(ptr, 5) == 0x69);
assert(load<u8>(ptr, 6) == 0xf0);
assert(load<u8>(ptr, 7) == 0xa4);
assert(load<u8>(ptr, 8) == 0xad);
assert(load<u8>(ptr, 9) == 0xa2);
assert(load<u8>(ptr, 10) == 0);
free_memory(ptr);

View File

@ -0,0 +1,870 @@
(module
(type $ii (func (param i32) (result i32)))
(type $iiiiv (func (param i32 i32 i32 i32)))
(type $iv (func (param i32)))
(type $v (func))
(import "env" "abort" (func $~lib/env/abort (param i32 i32 i32 i32)))
(global $~lib/internal/allocator/AL_BITS i32 (i32.const 3))
(global $~lib/internal/allocator/AL_SIZE i32 (i32.const 8))
(global $~lib/internal/allocator/AL_MASK i32 (i32.const 7))
(global $~lib/internal/allocator/MAX_SIZE_32 i32 (i32.const 1073741824))
(global $~lib/allocator/arena/startOffset (mut i32) (i32.const 0))
(global $~lib/allocator/arena/offset (mut i32) (i32.const 0))
(global $std/string-utf8/str (mut i32) (i32.const 8))
(global $~lib/internal/string/HEADER_SIZE i32 (i32.const 4))
(global $std/string-utf8/len (mut i32) (i32.const 0))
(global $std/string-utf8/ptr (mut i32) (i32.const 0))
(global $HEAP_BASE i32 (i32.const 96))
(memory $0 1)
(data (i32.const 8) "\06\00\00\00\01\d87\dch\00i\00R\d8b\df")
(data (i32.const 24) "\12\00\00\00s\00t\00d\00/\00s\00t\00r\00i\00n\00g\00-\00u\00t\00f\008\00.\00t\00s\00")
(data (i32.const 64) "\0e\00\00\00~\00l\00i\00b\00/\00s\00t\00r\00i\00n\00g\00.\00t\00s\00")
(export "memory" (memory $0))
(start $start)
(func $~lib/string/String#get:lengthUTF8 (; 1 ;) (type $ii) (param $0 i32) (result i32)
(local $1 i32)
(local $2 i32)
(local $3 i32)
(local $4 i32)
(local $5 i32)
(set_local $1
(i32.load
(get_local $0)
)
)
(set_local $2
(i32.const 1)
)
(block $break|0
(set_local $3
(i32.const 0)
)
(loop $continue|0
(if
(i32.lt_s
(get_local $3)
(get_local $1)
)
(block
(block
(set_local $4
(i32.load16_u offset=4
(i32.add
(get_local $0)
(i32.shl
(get_local $3)
(i32.const 1)
)
)
)
)
(if
(i32.lt_u
(get_local $4)
(i32.const 128)
)
(block
(set_local $2
(i32.add
(get_local $2)
(i32.const 1)
)
)
(set_local $3
(i32.add
(get_local $3)
(i32.const 1)
)
)
)
(if
(i32.lt_u
(get_local $4)
(i32.const 2048)
)
(block
(set_local $2
(i32.add
(get_local $2)
(i32.const 2)
)
)
(set_local $3
(i32.add
(get_local $3)
(i32.const 1)
)
)
)
(if
(if (result i32)
(tee_local $5
(i32.eq
(i32.and
(get_local $4)
(i32.const 64512)
)
(i32.const 55296)
)
)
(i32.eq
(i32.and
(i32.load16_u offset=4
(i32.add
(get_local $0)
(i32.shl
(i32.add
(get_local $3)
(i32.const 1)
)
(i32.const 1)
)
)
)
(i32.const 64512)
)
(i32.const 56320)
)
(get_local $5)
)
(block
(set_local $2
(i32.add
(get_local $2)
(i32.const 4)
)
)
(set_local $3
(i32.add
(get_local $3)
(i32.const 2)
)
)
)
(block
(set_local $2
(i32.add
(get_local $2)
(i32.const 3)
)
)
(set_local $3
(i32.add
(get_local $3)
(i32.const 1)
)
)
)
)
)
)
)
(nop)
(br $continue|0)
)
)
)
)
(return
(get_local $2)
)
)
(func $~lib/allocator/arena/allocate_memory (; 2 ;) (type $ii) (param $0 i32) (result i32)
(local $1 i32)
(local $2 i32)
(local $3 i32)
(local $4 i32)
(local $5 i32)
(local $6 i32)
(if
(get_local $0)
(block
(if
(i32.gt_u
(get_local $0)
(i32.const 1073741824)
)
(unreachable)
)
(set_local $1
(get_global $~lib/allocator/arena/offset)
)
(set_local $2
(i32.and
(i32.add
(i32.add
(get_local $1)
(get_local $0)
)
(i32.const 7)
)
(i32.xor
(i32.const 7)
(i32.const -1)
)
)
)
(set_local $3
(current_memory)
)
(if
(i32.gt_u
(get_local $2)
(i32.shl
(get_local $3)
(i32.const 16)
)
)
(block
(set_local $4
(i32.shr_u
(i32.and
(i32.add
(i32.sub
(get_local $2)
(get_local $1)
)
(i32.const 65535)
)
(i32.xor
(i32.const 65535)
(i32.const -1)
)
)
(i32.const 16)
)
)
(set_local $5
(select
(tee_local $5
(get_local $3)
)
(tee_local $6
(get_local $4)
)
(i32.gt_s
(get_local $5)
(get_local $6)
)
)
)
(if
(i32.lt_s
(grow_memory
(get_local $5)
)
(i32.const 0)
)
(if
(i32.lt_s
(grow_memory
(get_local $4)
)
(i32.const 0)
)
(unreachable)
)
)
)
)
(set_global $~lib/allocator/arena/offset
(get_local $2)
)
(return
(get_local $1)
)
)
)
(return
(i32.const 0)
)
)
(func $~lib/string/String#toUTF8 (; 3 ;) (type $ii) (param $0 i32) (result i32)
(local $1 i32)
(local $2 i32)
(local $3 i32)
(local $4 i32)
(local $5 i32)
(local $6 i32)
(local $7 i32)
(local $8 i32)
(set_local $1
(call $~lib/string/String#get:lengthUTF8
(get_local $0)
)
)
(set_local $2
(call $~lib/allocator/arena/allocate_memory
(get_local $1)
)
)
(set_local $3
(i32.const 0)
)
(block $break|0
(block
(set_local $4
(i32.const 0)
)
(set_local $5
(i32.load
(get_local $0)
)
)
)
(loop $continue|0
(if
(i32.lt_s
(get_local $4)
(get_local $5)
)
(block
(block
(set_local $6
(i32.load16_u offset=4
(i32.add
(get_local $0)
(i32.shl
(get_local $4)
(i32.const 1)
)
)
)
)
(if
(i32.lt_u
(get_local $6)
(i32.const 128)
)
(block
(i32.store8
(i32.add
(get_local $2)
(get_local $3)
)
(get_local $6)
)
(set_local $3
(i32.add
(get_local $3)
(i32.const 1)
)
)
(set_local $4
(i32.add
(get_local $4)
(i32.const 1)
)
)
)
(if
(i32.lt_u
(get_local $6)
(i32.const 2048)
)
(block
(set_local $7
(i32.add
(get_local $2)
(get_local $3)
)
)
(i32.store8
(get_local $7)
(i32.or
(i32.shr_u
(get_local $6)
(i32.const 6)
)
(i32.const 192)
)
)
(i32.store8 offset=1
(get_local $7)
(i32.or
(i32.and
(get_local $6)
(i32.const 63)
)
(i32.const 128)
)
)
(set_local $3
(i32.add
(get_local $3)
(i32.const 2)
)
)
(set_local $4
(i32.add
(get_local $4)
(i32.const 1)
)
)
)
(block
(set_local $7
(i32.add
(get_local $2)
(get_local $3)
)
)
(if
(i32.eq
(i32.and
(get_local $6)
(i32.const 64512)
)
(i32.const 55296)
)
(block
(set_local $8
(i32.load16_u offset=4
(i32.add
(get_local $0)
(i32.shl
(i32.add
(get_local $4)
(i32.const 1)
)
(i32.const 1)
)
)
)
)
(if
(i32.eq
(i32.and
(get_local $8)
(i32.const 64512)
)
(i32.const 56320)
)
(block
(set_local $6
(i32.add
(i32.add
(i32.const 65536)
(i32.shl
(i32.and
(get_local $6)
(i32.const 1023)
)
(i32.const 10)
)
)
(i32.and
(get_local $8)
(i32.const 1023)
)
)
)
(i32.store8
(get_local $7)
(i32.or
(i32.shr_u
(get_local $6)
(i32.const 18)
)
(i32.const 240)
)
)
(i32.store8 offset=1
(get_local $7)
(i32.or
(i32.and
(i32.shr_u
(get_local $6)
(i32.const 12)
)
(i32.const 63)
)
(i32.const 128)
)
)
(i32.store8 offset=2
(get_local $7)
(i32.or
(i32.and
(i32.shr_u
(get_local $6)
(i32.const 6)
)
(i32.const 63)
)
(i32.const 128)
)
)
(i32.store8 offset=3
(get_local $7)
(i32.or
(i32.and
(get_local $6)
(i32.const 63)
)
(i32.const 128)
)
)
(set_local $3
(i32.add
(get_local $3)
(i32.const 4)
)
)
(set_local $4
(i32.add
(get_local $4)
(i32.const 2)
)
)
(br $continue|0)
)
)
)
)
(i32.store8
(get_local $7)
(i32.or
(i32.shr_u
(get_local $6)
(i32.const 12)
)
(i32.const 224)
)
)
(i32.store8 offset=1
(get_local $7)
(i32.or
(i32.and
(i32.shr_u
(get_local $6)
(i32.const 6)
)
(i32.const 63)
)
(i32.const 128)
)
)
(i32.store8 offset=2
(get_local $7)
(i32.or
(i32.and
(get_local $6)
(i32.const 63)
)
(i32.const 128)
)
)
(set_local $3
(i32.add
(get_local $3)
(i32.const 3)
)
)
(set_local $4
(i32.add
(get_local $4)
(i32.const 1)
)
)
)
)
)
)
(nop)
(br $continue|0)
)
)
)
)
(if
(i32.eqz
(i32.eq
(get_local $3)
(i32.sub
(get_local $1)
(i32.const 1)
)
)
)
(block
(call $~lib/env/abort
(i32.const 0)
(i32.const 64)
(i32.const 471)
(i32.const 4)
)
(unreachable)
)
)
(i32.store8
(i32.add
(get_local $2)
(get_local $3)
)
(i32.const 0)
)
(return
(get_local $2)
)
)
(func $~lib/allocator/arena/free_memory (; 4 ;) (type $iv) (param $0 i32)
(nop)
)
(func $start (; 5 ;) (type $v)
(set_global $~lib/allocator/arena/startOffset
(i32.and
(i32.add
(get_global $HEAP_BASE)
(i32.const 7)
)
(i32.xor
(i32.const 7)
(i32.const -1)
)
)
)
(set_global $~lib/allocator/arena/offset
(get_global $~lib/allocator/arena/startOffset)
)
(set_global $std/string-utf8/len
(call $~lib/string/String#get:lengthUTF8
(get_global $std/string-utf8/str)
)
)
(if
(i32.eqz
(i32.eq
(get_global $std/string-utf8/len)
(i32.const 11)
)
)
(block
(call $~lib/env/abort
(i32.const 0)
(i32.const 24)
(i32.const 7)
(i32.const 0)
)
(unreachable)
)
)
(set_global $std/string-utf8/ptr
(call $~lib/string/String#toUTF8
(get_global $std/string-utf8/str)
)
)
(if
(i32.eqz
(i32.eq
(i32.load8_u
(get_global $std/string-utf8/ptr)
)
(i32.const 240)
)
)
(block
(call $~lib/env/abort
(i32.const 0)
(i32.const 24)
(i32.const 11)
(i32.const 0)
)
(unreachable)
)
)
(if
(i32.eqz
(i32.eq
(i32.load8_u offset=1
(get_global $std/string-utf8/ptr)
)
(i32.const 144)
)
)
(block
(call $~lib/env/abort
(i32.const 0)
(i32.const 24)
(i32.const 12)
(i32.const 0)
)
(unreachable)
)
)
(if
(i32.eqz
(i32.eq
(i32.load8_u offset=2
(get_global $std/string-utf8/ptr)
)
(i32.const 144)
)
)
(block
(call $~lib/env/abort
(i32.const 0)
(i32.const 24)
(i32.const 13)
(i32.const 0)
)
(unreachable)
)
)
(if
(i32.eqz
(i32.eq
(i32.load8_u offset=3
(get_global $std/string-utf8/ptr)
)
(i32.const 183)
)
)
(block
(call $~lib/env/abort
(i32.const 0)
(i32.const 24)
(i32.const 14)
(i32.const 0)
)
(unreachable)
)
)
(if
(i32.eqz
(i32.eq
(i32.load8_u offset=4
(get_global $std/string-utf8/ptr)
)
(i32.const 104)
)
)
(block
(call $~lib/env/abort
(i32.const 0)
(i32.const 24)
(i32.const 15)
(i32.const 0)
)
(unreachable)
)
)
(if
(i32.eqz
(i32.eq
(i32.load8_u offset=5
(get_global $std/string-utf8/ptr)
)
(i32.const 105)
)
)
(block
(call $~lib/env/abort
(i32.const 0)
(i32.const 24)
(i32.const 16)
(i32.const 0)
)
(unreachable)
)
)
(if
(i32.eqz
(i32.eq
(i32.load8_u offset=6
(get_global $std/string-utf8/ptr)
)
(i32.const 240)
)
)
(block
(call $~lib/env/abort
(i32.const 0)
(i32.const 24)
(i32.const 17)
(i32.const 0)
)
(unreachable)
)
)
(if
(i32.eqz
(i32.eq
(i32.load8_u offset=7
(get_global $std/string-utf8/ptr)
)
(i32.const 164)
)
)
(block
(call $~lib/env/abort
(i32.const 0)
(i32.const 24)
(i32.const 18)
(i32.const 0)
)
(unreachable)
)
)
(if
(i32.eqz
(i32.eq
(i32.load8_u offset=8
(get_global $std/string-utf8/ptr)
)
(i32.const 173)
)
)
(block
(call $~lib/env/abort
(i32.const 0)
(i32.const 24)
(i32.const 19)
(i32.const 0)
)
(unreachable)
)
)
(if
(i32.eqz
(i32.eq
(i32.load8_u offset=9
(get_global $std/string-utf8/ptr)
)
(i32.const 162)
)
)
(block
(call $~lib/env/abort
(i32.const 0)
(i32.const 24)
(i32.const 20)
(i32.const 0)
)
(unreachable)
)
)
(if
(i32.eqz
(i32.eq
(i32.load8_u offset=10
(get_global $std/string-utf8/ptr)
)
(i32.const 0)
)
)
(block
(call $~lib/env/abort
(i32.const 0)
(i32.const 24)
(i32.const 21)
(i32.const 0)
)
(unreachable)
)
)
(call $~lib/allocator/arena/free_memory
(get_global $std/string-utf8/ptr)
)
)
)

View File

@ -980,7 +980,7 @@
(call $~lib/env/abort
(i32.const 0)
(i32.const 76)
(i32.const 466)
(i32.const 526)
(i32.const 10)
)
(unreachable)

View File

@ -1157,7 +1157,7 @@
(call $~lib/env/abort
(i32.const 0)
(i32.const 76)
(i32.const 466)
(i32.const 526)
(i32.const 10)
)
(unreachable)