mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-04-25 15:12:12 +00:00
Infer u32 from 32-bit integer literals if MSB is set
This commit is contained in:
parent
c74eed2bd8
commit
525795b354
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
@ -5979,9 +5979,12 @@ export class Compiler extends DiagnosticEmitter {
|
||||
if (i64_is_u16(intValue)) return module.createI32(i64_low(intValue));
|
||||
break;
|
||||
}
|
||||
case TypeKind.I32:
|
||||
case TypeKind.I32: {
|
||||
if (i64_is_i32(intValue)) return module.createI32(i64_low(intValue));
|
||||
break;
|
||||
}
|
||||
case TypeKind.U32: {
|
||||
if (i64_is_i32(intValue) || i64_is_u32(intValue)) return module.createI32(i64_low(intValue));
|
||||
if (i64_is_u32(intValue)) return module.createI32(i64_low(intValue));
|
||||
break;
|
||||
}
|
||||
case TypeKind.BOOL: {
|
||||
@ -5990,14 +5993,14 @@ export class Compiler extends DiagnosticEmitter {
|
||||
}
|
||||
case TypeKind.ISIZE: {
|
||||
if (!this.options.isWasm64) {
|
||||
if (i64_is_i32(intValue) || i64_is_u32(intValue)) return module.createI32(i64_low(intValue));
|
||||
if (i64_is_i32(intValue)) return module.createI32(i64_low(intValue));
|
||||
break;
|
||||
}
|
||||
return module.createI64(i64_low(intValue), i64_high(intValue));
|
||||
}
|
||||
case TypeKind.USIZE: {
|
||||
if (!this.options.isWasm64) {
|
||||
if (i64_is_i32(intValue) || i64_is_u32(intValue)) return module.createI32(i64_low(intValue));
|
||||
if (i64_is_u32(intValue)) return module.createI32(i64_low(intValue));
|
||||
break;
|
||||
}
|
||||
return module.createI64(i64_low(intValue), i64_high(intValue));
|
||||
@ -6028,6 +6031,9 @@ export class Compiler extends DiagnosticEmitter {
|
||||
if (i64_is_i32(intValue)) {
|
||||
this.currentType = Type.i32;
|
||||
return module.createI32(i64_low(intValue));
|
||||
} else if (i64_is_u32(intValue)) {
|
||||
this.currentType = Type.u32;
|
||||
return module.createI32(i64_low(intValue));
|
||||
} else {
|
||||
this.currentType = Type.i64;
|
||||
return module.createI64(i64_low(intValue), i64_high(intValue));
|
||||
|
@ -10,6 +10,7 @@ export class Symbol {
|
||||
if (!stringToId) { stringToId = new Map(); idToString = new Map(); }
|
||||
else if (stringToId.has(key)) return changetype<Symbol>(stringToId.get(key));
|
||||
var id = nextId++;
|
||||
if (!id) unreachable(); // out of ids
|
||||
stringToId.set(key, id);
|
||||
idToString.set(id, key);
|
||||
return changetype<Symbol>(id);
|
||||
@ -22,6 +23,8 @@ export class Symbol {
|
||||
}
|
||||
|
||||
constructor(description: string | null = null) {
|
||||
return changetype<Symbol>(nextId++);
|
||||
var id = nextId++;
|
||||
if (!id) unreachable(); // out of ids
|
||||
return changetype<Symbol>(id);
|
||||
}
|
||||
}
|
||||
|
@ -9,6 +9,7 @@
|
||||
(global $infer-type/rf (mut f32) (f32.const 0))
|
||||
(global $infer-type/rF (mut f64) (f64.const 0))
|
||||
(memory $0 1)
|
||||
(data (i32.const 8) "\0d\00\00\00i\00n\00f\00e\00r\00-\00t\00y\00p\00e\00.\00t\00s")
|
||||
(export "memory" (memory $0))
|
||||
(start $start)
|
||||
(func $infer-type/locals (; 0 ;) (type $v)
|
||||
|
@ -1,4 +1,4 @@
|
||||
const i = 10; // infers i32 because
|
||||
const i = 10; // infers i32 because it fits into i32 as the default
|
||||
i;
|
||||
|
||||
const I = 0x100000000; // infers i64 because the value doesn't fit into 32 bits
|
||||
@ -44,3 +44,9 @@ rF;
|
||||
for (var a = 0, b = 10; a < b; ++a) {
|
||||
;
|
||||
}
|
||||
|
||||
var inferi = 0x80000000; // infers u32
|
||||
assert(!isSigned(inferi));
|
||||
|
||||
var inferu = 0x7fffffff; // infers i32
|
||||
assert(isSigned(inferu));
|
||||
|
@ -4,6 +4,8 @@
|
||||
(type $I (func (result i64)))
|
||||
(type $f (func (result f32)))
|
||||
(type $F (func (result f64)))
|
||||
(type $iiiiv (func (param i32 i32 i32 i32)))
|
||||
(import "env" "abort" (func $~lib/env/abort (param i32 i32 i32 i32)))
|
||||
(global $infer-type/i i32 (i32.const 10))
|
||||
(global $infer-type/I i64 (i64.const 4294967296))
|
||||
(global $infer-type/F f64 (f64.const 1.5))
|
||||
@ -11,11 +13,14 @@
|
||||
(global $infer-type/rI (mut i64) (i64.const 0))
|
||||
(global $infer-type/rf (mut f32) (f32.const 0))
|
||||
(global $infer-type/rF (mut f64) (f64.const 0))
|
||||
(global $HEAP_BASE i32 (i32.const 8))
|
||||
(global $infer-type/inferi (mut i32) (i32.const -2147483648))
|
||||
(global $infer-type/inferu (mut i32) (i32.const 2147483647))
|
||||
(global $HEAP_BASE i32 (i32.const 40))
|
||||
(memory $0 1)
|
||||
(data (i32.const 8) "\0d\00\00\00i\00n\00f\00e\00r\00-\00t\00y\00p\00e\00.\00t\00s\00")
|
||||
(export "memory" (memory $0))
|
||||
(start $start)
|
||||
(func $infer-type/locals (; 0 ;) (type $v)
|
||||
(func $infer-type/locals (; 1 ;) (type $v)
|
||||
(local $0 i32)
|
||||
(local $1 i64)
|
||||
(local $2 f64)
|
||||
@ -41,27 +46,27 @@
|
||||
(f64.const 1.5)
|
||||
)
|
||||
)
|
||||
(func $infer-type/reti (; 1 ;) (type $i) (result i32)
|
||||
(func $infer-type/reti (; 2 ;) (type $i) (result i32)
|
||||
(return
|
||||
(i32.const 0)
|
||||
)
|
||||
)
|
||||
(func $infer-type/retI (; 2 ;) (type $I) (result i64)
|
||||
(func $infer-type/retI (; 3 ;) (type $I) (result i64)
|
||||
(return
|
||||
(i64.const 0)
|
||||
)
|
||||
)
|
||||
(func $infer-type/retf (; 3 ;) (type $f) (result f32)
|
||||
(func $infer-type/retf (; 4 ;) (type $f) (result f32)
|
||||
(return
|
||||
(f32.const 0)
|
||||
)
|
||||
)
|
||||
(func $infer-type/refF (; 4 ;) (type $F) (result f64)
|
||||
(func $infer-type/refF (; 5 ;) (type $F) (result f64)
|
||||
(return
|
||||
(f64.const 0)
|
||||
)
|
||||
)
|
||||
(func $start (; 5 ;) (type $v)
|
||||
(func $start (; 6 ;) (type $v)
|
||||
(local $0 i32)
|
||||
(local $1 i32)
|
||||
(drop
|
||||
@ -126,5 +131,35 @@
|
||||
(br $repeat|0)
|
||||
)
|
||||
)
|
||||
(if
|
||||
(i32.eqz
|
||||
(i32.eqz
|
||||
(i32.const 0)
|
||||
)
|
||||
)
|
||||
(block
|
||||
(call $~lib/env/abort
|
||||
(i32.const 0)
|
||||
(i32.const 8)
|
||||
(i32.const 49)
|
||||
(i32.const 0)
|
||||
)
|
||||
(unreachable)
|
||||
)
|
||||
)
|
||||
(if
|
||||
(i32.eqz
|
||||
(i32.const 1)
|
||||
)
|
||||
(block
|
||||
(call $~lib/env/abort
|
||||
(i32.const 0)
|
||||
(i32.const 8)
|
||||
(i32.const 52)
|
||||
(i32.const 0)
|
||||
)
|
||||
(unreachable)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
@ -84,9 +84,7 @@
|
||||
)
|
||||
(i32.and
|
||||
(get_local $0)
|
||||
(i32.wrap/i64
|
||||
(i64.const 4294901760)
|
||||
)
|
||||
(i32.const -65536)
|
||||
)
|
||||
)
|
||||
)
|
||||
@ -224,9 +222,7 @@
|
||||
)
|
||||
(i32.and
|
||||
(get_local $0)
|
||||
(i32.wrap/i64
|
||||
(i64.const 4294901760)
|
||||
)
|
||||
(i32.const -65536)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
@ -30,16 +30,21 @@
|
||||
(export "memory" (memory $0))
|
||||
(start $start)
|
||||
(func $~lib/symbol/Symbol#constructor (; 1 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
|
||||
(local $2 i32)
|
||||
(set_global $~lib/symbol/nextId
|
||||
(i32.add
|
||||
(tee_local $2
|
||||
(tee_local $0
|
||||
(get_global $~lib/symbol/nextId)
|
||||
)
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
(get_local $2)
|
||||
(if
|
||||
(i32.eqz
|
||||
(get_local $0)
|
||||
)
|
||||
(unreachable)
|
||||
)
|
||||
(get_local $0)
|
||||
)
|
||||
(func $~lib/allocator/arena/allocate_memory (; 2 ;) (type $ii) (param $0 i32) (result i32)
|
||||
(local $1 i32)
|
||||
@ -1639,6 +1644,12 @@
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
(if
|
||||
(i32.eqz
|
||||
(get_local $1)
|
||||
)
|
||||
(unreachable)
|
||||
)
|
||||
(call $~lib/map/Map<String,usize>#set
|
||||
(get_global $~lib/symbol/stringToId)
|
||||
(get_local $0)
|
||||
|
@ -45,7 +45,8 @@
|
||||
(start $start)
|
||||
(func $~lib/symbol/Symbol#constructor (; 1 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
|
||||
(local $2 i32)
|
||||
(return
|
||||
(local $3 i32)
|
||||
(set_local $3
|
||||
(block (result i32)
|
||||
(set_local $2
|
||||
(get_global $~lib/symbol/nextId)
|
||||
@ -59,6 +60,15 @@
|
||||
(get_local $2)
|
||||
)
|
||||
)
|
||||
(if
|
||||
(i32.eqz
|
||||
(get_local $3)
|
||||
)
|
||||
(unreachable)
|
||||
)
|
||||
(return
|
||||
(get_local $3)
|
||||
)
|
||||
)
|
||||
(func $~lib/allocator/arena/allocate_memory (; 2 ;) (type $ii) (param $0 i32) (result i32)
|
||||
(local $1 i32)
|
||||
@ -1979,6 +1989,12 @@
|
||||
(get_local $1)
|
||||
)
|
||||
)
|
||||
(if
|
||||
(i32.eqz
|
||||
(get_local $2)
|
||||
)
|
||||
(unreachable)
|
||||
)
|
||||
(call $~lib/map/Map<String,usize>#set
|
||||
(get_global $~lib/symbol/stringToId)
|
||||
(get_local $0)
|
||||
|
Loading…
x
Reference in New Issue
Block a user