mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-04-25 15:12:12 +00:00
Properly resolve top level enums to i32s, see #116
This commit is contained in:
parent
ea0eb7f1a5
commit
33b10e347b
2
dist/asc.js
vendored
2
dist/asc.js
vendored
File diff suppressed because one or more lines are too long
2
dist/asc.js.map
vendored
2
dist/asc.js.map
vendored
File diff suppressed because one or more lines are too long
2
dist/assemblyscript.js
vendored
2
dist/assemblyscript.js
vendored
File diff suppressed because one or more lines are too long
2
dist/assemblyscript.js.map
vendored
2
dist/assemblyscript.js.map
vendored
File diff suppressed because one or more lines are too long
@ -1738,10 +1738,12 @@ export class Program extends DiagnosticEmitter {
|
||||
var localName = typeNode.range.source.internalPath + PATH_DELIMITER + simpleName;
|
||||
|
||||
var element: Element | null;
|
||||
|
||||
// check file-global / program-global element
|
||||
if ((element = this.elementsLookup.get(localName)) || (element = this.elementsLookup.get(globalName))) {
|
||||
if (
|
||||
(element = this.elementsLookup.get(localName)) || // file-global
|
||||
(element = this.elementsLookup.get(globalName)) // program-global
|
||||
) {
|
||||
switch (element.kind) {
|
||||
case ElementKind.ENUM: return Type.i32;
|
||||
case ElementKind.CLASS_PROTOTYPE: {
|
||||
let instance = (<ClassPrototype>element).resolveUsingTypeArguments(
|
||||
typeNode.typeArguments,
|
||||
|
@ -414,17 +414,16 @@ export class String {
|
||||
}
|
||||
|
||||
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);
|
||||
for (let i: usize = 0, k = <usize>this.length; i < k;) {
|
||||
let c = <u32>load<u16>(changetype<usize>(this) + (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
|
||||
(<u32>load<u16>(changetype<usize>(this) + ((i + 1) << 1), HEADER_SIZE) & 0xFC00) === 0xDC00
|
||||
) {
|
||||
blen += 4; i += 2;
|
||||
} else {
|
||||
@ -438,23 +437,23 @@ export class String {
|
||||
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);
|
||||
for (let i: usize = 0, k = <usize>this.length; i < k;) {
|
||||
let c1 = <u32>load<u16>(changetype<usize>(this) + (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);
|
||||
store<u8>(pos, c1 >> 6 | 192);
|
||||
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);
|
||||
let c2 = <u32>load<u16>(changetype<usize>(this) + ((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 >> 18 | 240);
|
||||
store<u8>(pos, c1 >> 12 & 63 | 128, 1);
|
||||
store<u8>(pos, c1 >> 6 & 63 | 128, 2);
|
||||
store<u8>(pos, c1 & 63 | 128, 3);
|
||||
@ -462,13 +461,12 @@ export class String {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
store<u8>(pos, c1 >> 12 | 224, 0);
|
||||
store<u8>(pos, c1 >> 12 | 224);
|
||||
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;
|
||||
}
|
||||
|
@ -32,3 +32,5 @@ export enum SelfReference {
|
||||
ZERO,
|
||||
ONE = ZERO + 1
|
||||
}
|
||||
|
||||
var enumType: SelfReference;
|
||||
|
@ -17,6 +17,7 @@
|
||||
(global $enum/NonConstant.ONE (mut i32) (i32.const 0))
|
||||
(global $enum/SelfReference.ZERO i32 (i32.const 0))
|
||||
(global $enum/SelfReference.ONE i32 (i32.const 1))
|
||||
(global $enum/enumType (mut i32) (i32.const 0))
|
||||
(global $HEAP_BASE i32 (i32.const 8))
|
||||
(memory $0 1)
|
||||
(export "Implicit.ZERO" (global $enum/Implicit.ZERO))
|
||||
|
@ -9,11 +9,10 @@
|
||||
(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))
|
||||
(global $HEAP_BASE i32 (i32.const 64))
|
||||
(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)
|
||||
@ -21,17 +20,17 @@
|
||||
(local $2 i32)
|
||||
(local $3 i32)
|
||||
(local $4 i32)
|
||||
(set_local $1
|
||||
(i32.const 1)
|
||||
)
|
||||
(set_local $4
|
||||
(i32.load
|
||||
(get_local $0)
|
||||
)
|
||||
)
|
||||
(set_local $1
|
||||
(i32.const 1)
|
||||
)
|
||||
(loop $continue|0
|
||||
(if
|
||||
(i32.lt_s
|
||||
(i32.lt_u
|
||||
(get_local $2)
|
||||
(get_local $4)
|
||||
)
|
||||
@ -243,29 +242,26 @@
|
||||
(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)
|
||||
)
|
||||
(call $~lib/string/String#get:lengthUTF8
|
||||
(get_local $0)
|
||||
)
|
||||
)
|
||||
)
|
||||
(set_local $7
|
||||
(set_local $6
|
||||
(i32.load
|
||||
(get_local $0)
|
||||
)
|
||||
)
|
||||
(loop $continue|0
|
||||
(if
|
||||
(i32.lt_s
|
||||
(get_local $3)
|
||||
(get_local $7)
|
||||
(i32.lt_u
|
||||
(get_local $2)
|
||||
(get_local $6)
|
||||
)
|
||||
(block
|
||||
(set_local $2
|
||||
(set_local $3
|
||||
(if (result i32)
|
||||
(i32.lt_u
|
||||
(tee_local $1
|
||||
@ -273,7 +269,7 @@
|
||||
(i32.add
|
||||
(get_local $0)
|
||||
(i32.shl
|
||||
(get_local $3)
|
||||
(get_local $2)
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
@ -285,18 +281,18 @@
|
||||
(i32.store8
|
||||
(i32.add
|
||||
(get_local $5)
|
||||
(get_local $2)
|
||||
(get_local $3)
|
||||
)
|
||||
(get_local $1)
|
||||
)
|
||||
(set_local $3
|
||||
(set_local $2
|
||||
(i32.add
|
||||
(get_local $3)
|
||||
(get_local $2)
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
(i32.add
|
||||
(get_local $2)
|
||||
(get_local $3)
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
@ -310,7 +306,7 @@
|
||||
(tee_local $4
|
||||
(i32.add
|
||||
(get_local $5)
|
||||
(get_local $2)
|
||||
(get_local $3)
|
||||
)
|
||||
)
|
||||
(i32.or
|
||||
@ -331,14 +327,14 @@
|
||||
(i32.const 128)
|
||||
)
|
||||
)
|
||||
(set_local $3
|
||||
(set_local $2
|
||||
(i32.add
|
||||
(get_local $3)
|
||||
(get_local $2)
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
(i32.add
|
||||
(get_local $2)
|
||||
(get_local $3)
|
||||
(i32.const 2)
|
||||
)
|
||||
)
|
||||
@ -346,7 +342,7 @@
|
||||
(set_local $4
|
||||
(i32.add
|
||||
(get_local $5)
|
||||
(get_local $2)
|
||||
(get_local $3)
|
||||
)
|
||||
)
|
||||
(if
|
||||
@ -360,13 +356,13 @@
|
||||
(if
|
||||
(i32.eq
|
||||
(i32.and
|
||||
(tee_local $8
|
||||
(tee_local $7
|
||||
(i32.load16_u offset=4
|
||||
(i32.add
|
||||
(get_local $0)
|
||||
(i32.shl
|
||||
(i32.add
|
||||
(get_local $3)
|
||||
(get_local $2)
|
||||
(i32.const 1)
|
||||
)
|
||||
(i32.const 1)
|
||||
@ -396,7 +392,7 @@
|
||||
(i32.const 65536)
|
||||
)
|
||||
(i32.and
|
||||
(get_local $8)
|
||||
(get_local $7)
|
||||
(i32.const 1023)
|
||||
)
|
||||
)
|
||||
@ -442,15 +438,15 @@
|
||||
(i32.const 128)
|
||||
)
|
||||
)
|
||||
(set_local $2
|
||||
(i32.add
|
||||
(get_local $2)
|
||||
(i32.const 4)
|
||||
)
|
||||
)
|
||||
(set_local $3
|
||||
(i32.add
|
||||
(get_local $3)
|
||||
(i32.const 4)
|
||||
)
|
||||
)
|
||||
(set_local $2
|
||||
(i32.add
|
||||
(get_local $2)
|
||||
(i32.const 2)
|
||||
)
|
||||
)
|
||||
@ -491,14 +487,14 @@
|
||||
(i32.const 128)
|
||||
)
|
||||
)
|
||||
(set_local $3
|
||||
(set_local $2
|
||||
(i32.add
|
||||
(get_local $3)
|
||||
(get_local $2)
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
(i32.add
|
||||
(get_local $2)
|
||||
(get_local $3)
|
||||
(i32.const 3)
|
||||
)
|
||||
)
|
||||
@ -509,28 +505,10 @@
|
||||
)
|
||||
)
|
||||
)
|
||||
(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)
|
||||
(get_local $3)
|
||||
)
|
||||
(i32.const 0)
|
||||
)
|
||||
|
@ -14,11 +14,10 @@
|
||||
(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))
|
||||
(global $HEAP_BASE i32 (i32.const 64))
|
||||
(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)
|
||||
@ -28,22 +27,24 @@
|
||||
(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)
|
||||
(block
|
||||
(set_local $2
|
||||
(i32.const 0)
|
||||
)
|
||||
(set_local $3
|
||||
(i32.load
|
||||
(get_local $0)
|
||||
)
|
||||
)
|
||||
)
|
||||
(loop $continue|0
|
||||
(if
|
||||
(i32.lt_s
|
||||
(i32.lt_u
|
||||
(get_local $2)
|
||||
(get_local $3)
|
||||
(get_local $1)
|
||||
)
|
||||
(block
|
||||
(block
|
||||
@ -52,7 +53,7 @@
|
||||
(i32.add
|
||||
(get_local $0)
|
||||
(i32.shl
|
||||
(get_local $3)
|
||||
(get_local $2)
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
@ -64,15 +65,15 @@
|
||||
(i32.const 128)
|
||||
)
|
||||
(block
|
||||
(set_local $2
|
||||
(set_local $1
|
||||
(i32.add
|
||||
(get_local $2)
|
||||
(get_local $1)
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
(set_local $3
|
||||
(set_local $2
|
||||
(i32.add
|
||||
(get_local $3)
|
||||
(get_local $2)
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
@ -83,15 +84,15 @@
|
||||
(i32.const 2048)
|
||||
)
|
||||
(block
|
||||
(set_local $2
|
||||
(set_local $1
|
||||
(i32.add
|
||||
(get_local $2)
|
||||
(get_local $1)
|
||||
(i32.const 2)
|
||||
)
|
||||
)
|
||||
(set_local $3
|
||||
(set_local $2
|
||||
(i32.add
|
||||
(get_local $3)
|
||||
(get_local $2)
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
@ -114,7 +115,7 @@
|
||||
(get_local $0)
|
||||
(i32.shl
|
||||
(i32.add
|
||||
(get_local $3)
|
||||
(get_local $2)
|
||||
(i32.const 1)
|
||||
)
|
||||
(i32.const 1)
|
||||
@ -128,29 +129,29 @@
|
||||
(get_local $5)
|
||||
)
|
||||
(block
|
||||
(set_local $2
|
||||
(set_local $1
|
||||
(i32.add
|
||||
(get_local $2)
|
||||
(get_local $1)
|
||||
(i32.const 4)
|
||||
)
|
||||
)
|
||||
(set_local $3
|
||||
(set_local $2
|
||||
(i32.add
|
||||
(get_local $3)
|
||||
(get_local $2)
|
||||
(i32.const 2)
|
||||
)
|
||||
)
|
||||
)
|
||||
(block
|
||||
(set_local $2
|
||||
(set_local $1
|
||||
(i32.add
|
||||
(get_local $2)
|
||||
(get_local $1)
|
||||
(i32.const 3)
|
||||
)
|
||||
)
|
||||
(set_local $3
|
||||
(set_local $2
|
||||
(i32.add
|
||||
(get_local $3)
|
||||
(get_local $2)
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
@ -166,7 +167,7 @@
|
||||
)
|
||||
)
|
||||
(return
|
||||
(get_local $2)
|
||||
(get_local $1)
|
||||
)
|
||||
)
|
||||
(func $~lib/allocator/arena/allocate_memory (; 2 ;) (type $ii) (param $0 i32) (result i32)
|
||||
@ -314,7 +315,7 @@
|
||||
)
|
||||
(loop $continue|0
|
||||
(if
|
||||
(i32.lt_s
|
||||
(i32.lt_u
|
||||
(get_local $4)
|
||||
(get_local $5)
|
||||
)
|
||||
@ -577,26 +578,6 @@
|
||||
)
|
||||
)
|
||||
)
|
||||
(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)
|
||||
|
@ -980,7 +980,7 @@
|
||||
(call $~lib/env/abort
|
||||
(i32.const 0)
|
||||
(i32.const 76)
|
||||
(i32.const 526)
|
||||
(i32.const 524)
|
||||
(i32.const 10)
|
||||
)
|
||||
(unreachable)
|
||||
|
@ -1157,7 +1157,7 @@
|
||||
(call $~lib/env/abort
|
||||
(i32.const 0)
|
||||
(i32.const 76)
|
||||
(i32.const 526)
|
||||
(i32.const 524)
|
||||
(i32.const 10)
|
||||
)
|
||||
(unreachable)
|
||||
|
Loading…
x
Reference in New Issue
Block a user