Implicitly alias stdlib exports as program globals, see #8

This commit is contained in:
dcodeIO
2018-01-12 15:36:17 +01:00
parent 3980e53bb7
commit 2df318a7ec
27 changed files with 417 additions and 179 deletions

View File

@ -72,11 +72,11 @@
(if
(i32.and
(if (result i32)
(i32.eqz
(i32.ne
(tee_local $8
(i32.and
(if (result i32)
(i32.eqz
(i32.ne
(tee_local $8
(i64.eq
(i64.shl
@ -86,24 +86,26 @@
(i64.const 0)
)
)
(i32.const 0)
)
(get_local $8)
(f64.ne
(tee_local $7
(get_local $1)
)
(get_local $7)
)
(get_local $8)
)
(i32.const 1)
)
)
(i32.const 0)
)
(get_local $8)
(i32.eq
(get_local $4)
(i32.const 2047)
)
(get_local $8)
)
(i32.const 1)
)
@ -542,11 +544,11 @@
(if
(i32.and
(if (result i32)
(i32.eqz
(i32.ne
(tee_local $8
(i32.and
(if (result i32)
(i32.eqz
(i32.ne
(tee_local $8
(i32.eq
(i32.shl
@ -556,24 +558,26 @@
(i32.const 0)
)
)
(i32.const 0)
)
(get_local $8)
(f32.ne
(tee_local $7
(get_local $1)
)
(get_local $7)
)
(get_local $8)
)
(i32.const 1)
)
)
(i32.const 0)
)
(get_local $8)
(i32.eq
(get_local $4)
(i32.const 255)
)
(get_local $8)
)
(i32.const 1)
)

View File

@ -211,7 +211,11 @@
(if
(i32.and
(if (result i32)
(i32.ge_u
(i32.lt_u
(get_local $2)
(i32.const 2)
)
(i32.lt_u
(get_local $2)
(i32.const 2)
)
@ -219,10 +223,6 @@
(get_local $2)
(i32.const 3)
)
(i32.lt_u
(get_local $2)
(i32.const 2)
)
)
(i32.const 1)
)

View File

@ -237,20 +237,21 @@
(if
(i32.and
(if (result i32)
(i32.eqz
(i32.ne
(i32.lt_u
(get_local $8)
(i32.const 2)
)
)
(i32.gt_u
(get_local $8)
(i32.const 3)
(i32.const 0)
)
(i32.lt_u
(get_local $8)
(i32.const 2)
)
(i32.gt_u
(get_local $8)
(i32.const 3)
)
)
(i32.const 1)
)

View File

@ -1,10 +1,12 @@
(module
(type $ii (func (param i32) (result i32)))
(type $v (func))
(memory $0 1)
(export "ifThenElse" (func $if/ifThenElse))
(export "ifThen" (func $if/ifThen))
(export "ifThenElseBlock" (func $if/ifThenElse))
(export "memory" (memory $0))
(start $start)
(func $if/ifThenElse (; 0 ;) (type $ii) (param $0 i32) (result i32)
(if (result i32)
(get_local $0)
@ -21,4 +23,51 @@
)
(i32.const 0)
)
(func $start (; 2 ;) (type $v)
(if
(call $if/ifThenElse
(i32.const 0)
)
(unreachable)
)
(if
(i32.ne
(call $if/ifThenElse
(i32.const 1)
)
(i32.const 1)
)
(unreachable)
)
(if
(call $if/ifThen
(i32.const 0)
)
(unreachable)
)
(if
(i32.ne
(call $if/ifThen
(i32.const 1)
)
(i32.const 1)
)
(unreachable)
)
(if
(call $if/ifThenElse
(i32.const 0)
)
(unreachable)
)
(if
(i32.ne
(call $if/ifThenElse
(i32.const 1)
)
(i32.const 1)
)
(unreachable)
)
)
)

View File

@ -5,12 +5,18 @@ export function ifThenElse(n: i32): bool {
return false;
}
assert(ifThenElse(0) == false);
assert(ifThenElse(1) == true);
export function ifThen(n: i32): bool {
if (n)
return true;
return false;
}
assert(ifThen(0) == false);
assert(ifThen(1) == true);
export function ifThenElseBlock(n: i32): bool {
if (n) {
; // nop
@ -20,3 +26,6 @@ export function ifThenElseBlock(n: i32): bool {
return false;
}
}
assert(ifThenElseBlock(0) == false);
assert(ifThenElseBlock(1) == true);

View File

@ -1,11 +1,13 @@
(module
(type $ii (func (param i32) (result i32)))
(type $v (func))
(global $HEAP_BASE i32 (i32.const 4))
(memory $0 1)
(export "ifThenElse" (func $if/ifThenElse))
(export "ifThen" (func $if/ifThen))
(export "ifThenElseBlock" (func $if/ifThenElseBlock))
(export "memory" (memory $0))
(start $start)
(func $if/ifThenElse (; 0 ;) (type $ii) (param $0 i32) (result i32)
(if
(get_local $0)
@ -45,6 +47,74 @@
)
)
)
(func $start (; 3 ;) (type $v)
(if
(i32.eqz
(i32.eq
(call $if/ifThenElse
(i32.const 0)
)
(i32.const 0)
)
)
(unreachable)
)
(if
(i32.eqz
(i32.eq
(call $if/ifThenElse
(i32.const 1)
)
(i32.const 1)
)
)
(unreachable)
)
(if
(i32.eqz
(i32.eq
(call $if/ifThen
(i32.const 0)
)
(i32.const 0)
)
)
(unreachable)
)
(if
(i32.eqz
(i32.eq
(call $if/ifThen
(i32.const 1)
)
(i32.const 1)
)
)
(unreachable)
)
(if
(i32.eqz
(i32.eq
(call $if/ifThenElseBlock
(i32.const 0)
)
(i32.const 0)
)
)
(unreachable)
)
(if
(i32.eqz
(i32.eq
(call $if/ifThenElseBlock
(i32.const 1)
)
(i32.const 1)
)
)
(unreachable)
)
)
)
(;
[program.elements]

View File

@ -13,85 +13,90 @@
(local $1 f64)
(drop
(if (result i32)
(i32.eqz
(i32.ne
(i32.const 0)
(i32.const 0)
)
(i32.const 0)
(unreachable)
(i32.const 0)
)
)
(drop
(if (result f64)
(f64.eq
(f64.ne
(f64.const 0)
(f64.const 0)
)
(f64.const 0)
(unreachable)
(f64.const 0)
)
)
(drop
(if (result i32)
(i32.eqz
(i32.ne
(i32.const 1)
(i32.const 0)
)
(unreachable)
(i32.const 1)
(unreachable)
)
)
(drop
(if (result f64)
(f64.eq
(f64.ne
(f64.const 1)
(f64.const 0)
)
(unreachable)
(f64.const 1)
(unreachable)
)
)
(drop
(if (result i32)
(i32.eqz
(i32.ne
(tee_local $0
(if (result i32)
(i32.eqz
(i32.ne
(i32.const 1)
(i32.const 0)
)
(i32.const 1)
(i32.const 2)
(i32.const 1)
)
)
(i32.const 0)
)
(unreachable)
(get_local $0)
(unreachable)
)
)
(drop
(if (result f64)
(f64.eq
(f64.ne
(tee_local $1
(if (result f64)
(f64.eq
(f64.ne
(f64.const 1)
(f64.const 0)
)
(f64.const 1)
(f64.const 2)
(f64.const 1)
)
)
(f64.const 0)
)
(unreachable)
(get_local $1)
(unreachable)
)
)
(set_global $logical/i
(if (result i32)
(i32.eqz
(i32.ne
(i32.const 1)
(i32.const 0)
)
(i32.const 1)
(i32.const 2)
(i32.const 1)
)
)
(if
@ -105,11 +110,12 @@
)
(set_global $logical/i
(if (result i32)
(i32.eqz
(i32.ne
(i32.const 0)
(i32.const 0)
)
(i32.const 1)
(i32.const 0)
(i32.const 1)
)
)
(if
@ -123,11 +129,12 @@
)
(set_global $logical/I
(if (result i64)
(i64.eqz
(i64.ne
(i64.const 1)
(i64.const 0)
)
(i64.const 1)
(i64.const 2)
(i64.const 1)
)
)
(if
@ -141,11 +148,12 @@
)
(set_global $logical/I
(if (result i64)
(i64.eqz
(i64.ne
(i64.const 0)
(i64.const 0)
)
(i64.const 1)
(i64.const 0)
(i64.const 1)
)
)
(if
@ -159,12 +167,12 @@
)
(set_global $logical/f
(if (result f32)
(f32.eq
(f32.ne
(f32.const 1)
(f32.const 0)
)
(f32.const 1)
(f32.const 2)
(f32.const 1)
)
)
(if
@ -178,12 +186,12 @@
)
(set_global $logical/f
(if (result f32)
(f32.eq
(f32.ne
(f32.const 0)
(f32.const 0)
)
(f32.const 1)
(f32.const 0)
(f32.const 1)
)
)
(if
@ -197,12 +205,12 @@
)
(set_global $logical/F
(if (result f64)
(f64.eq
(f64.ne
(f64.const 1)
(f64.const 0)
)
(f64.const 1)
(f64.const 2)
(f64.const 1)
)
)
(if
@ -216,12 +224,12 @@
)
(set_global $logical/F
(if (result f64)
(f64.eq
(f64.ne
(f64.const 0)
(f64.const 0)
)
(f64.const 1)
(f64.const 0)
(f64.const 1)
)
)
(if

View File

@ -27,14 +27,15 @@
(loop $continue|0
(if
(if (result i32)
(i32.eqz
(i32.ne
(get_local $2)
(i32.const 0)
)
(get_local $2)
(i32.rem_u
(get_local $4)
(i32.const 4)
)
(get_local $2)
)
(block
(block

View File

@ -135,14 +135,15 @@
(loop $continue|0
(if
(if (result i32)
(i32.eqz
(i32.ne
(get_local $2)
(i32.const 0)
)
(get_local $2)
(i32.rem_u
(get_local $4)
(i32.const 4)
)
(get_local $2)
)
(block
(block
@ -1992,11 +1993,11 @@
(if
(i32.and
(if (result i32)
(i32.eqz
(i32.ne
(tee_local $8
(i32.and
(if (result i32)
(i32.eqz
(i32.ne
(tee_local $8
(i64.eq
(i64.shl
@ -2006,24 +2007,26 @@
(i64.const 0)
)
)
(i32.const 0)
)
(get_local $8)
(f64.ne
(tee_local $7
(get_local $1)
)
(get_local $7)
)
(get_local $8)
)
(i32.const 1)
)
)
(i32.const 0)
)
(get_local $8)
(i32.eq
(get_local $4)
(i32.const 2047)
)
(get_local $8)
)
(i32.const 1)
)
@ -2462,11 +2465,11 @@
(if
(i32.and
(if (result i32)
(i32.eqz
(i32.ne
(tee_local $8
(i32.and
(if (result i32)
(i32.eqz
(i32.ne
(tee_local $8
(i32.eq
(i32.shl
@ -2476,24 +2479,26 @@
(i32.const 0)
)
)
(i32.const 0)
)
(get_local $8)
(f32.ne
(tee_local $7
(get_local $1)
)
(get_local $7)
)
(get_local $8)
)
(i32.const 1)
)
)
(i32.const 0)
)
(get_local $8)
(i32.eq
(get_local $4)
(i32.const 255)
)
(get_local $8)
)
(i32.const 1)
)
@ -4231,85 +4236,90 @@
)
(drop
(if (result i32)
(i32.eqz
(i32.ne
(i32.const 0)
(i32.const 0)
)
(i32.const 0)
(unreachable)
(i32.const 0)
)
)
(drop
(if (result f64)
(f64.eq
(f64.ne
(f64.const 0)
(f64.const 0)
)
(f64.const 0)
(unreachable)
(f64.const 0)
)
)
(drop
(if (result i32)
(i32.eqz
(i32.ne
(i32.const 1)
(i32.const 0)
)
(unreachable)
(i32.const 1)
(unreachable)
)
)
(drop
(if (result f64)
(f64.eq
(f64.ne
(f64.const 1)
(f64.const 0)
)
(unreachable)
(f64.const 1)
(unreachable)
)
)
(drop
(if (result i32)
(i32.eqz
(i32.ne
(tee_local $0
(if (result i32)
(i32.eqz
(i32.ne
(i32.const 1)
(i32.const 0)
)
(i32.const 1)
(i32.const 2)
(i32.const 1)
)
)
(i32.const 0)
)
(unreachable)
(get_local $0)
(unreachable)
)
)
(drop
(if (result f64)
(f64.eq
(f64.ne
(tee_local $3
(if (result f64)
(f64.eq
(f64.ne
(f64.const 1)
(f64.const 0)
)
(f64.const 1)
(f64.const 2)
(f64.const 1)
)
)
(f64.const 0)
)
(unreachable)
(get_local $3)
(unreachable)
)
)
(set_global $logical/i
(if (result i32)
(i32.eqz
(i32.ne
(i32.const 1)
(i32.const 0)
)
(i32.const 1)
(i32.const 2)
(i32.const 1)
)
)
(if
@ -4323,11 +4333,12 @@
)
(set_global $logical/i
(if (result i32)
(i32.eqz
(i32.ne
(i32.const 0)
(i32.const 0)
)
(i32.const 1)
(i32.const 0)
(i32.const 1)
)
)
(if
@ -4341,11 +4352,12 @@
)
(set_global $logical/I
(if (result i64)
(i64.eqz
(i64.ne
(i64.const 1)
(i64.const 0)
)
(i64.const 1)
(i64.const 2)
(i64.const 1)
)
)
(if
@ -4359,11 +4371,12 @@
)
(set_global $logical/I
(if (result i64)
(i64.eqz
(i64.ne
(i64.const 0)
(i64.const 0)
)
(i64.const 1)
(i64.const 0)
(i64.const 1)
)
)
(if
@ -4377,12 +4390,12 @@
)
(set_global $logical/f
(if (result f32)
(f32.eq
(f32.ne
(f32.const 1)
(f32.const 0)
)
(f32.const 1)
(f32.const 2)
(f32.const 1)
)
)
(if
@ -4396,12 +4409,12 @@
)
(set_global $logical/f
(if (result f32)
(f32.eq
(f32.ne
(f32.const 0)
(f32.const 0)
)
(f32.const 1)
(f32.const 0)
(f32.const 1)
)
)
(if
@ -4415,12 +4428,12 @@
)
(set_global $logical/F
(if (result f64)
(f64.eq
(f64.ne
(f64.const 1)
(f64.const 0)
)
(f64.const 1)
(f64.const 2)
(f64.const 1)
)
)
(if
@ -4434,12 +4447,12 @@
)
(set_global $logical/F
(if (result f64)
(f64.eq
(f64.ne
(f64.const 0)
(f64.const 0)
)
(f64.const 1)
(f64.const 0)
(f64.const 1)
)
)
(if

View File

@ -80,7 +80,9 @@
CLASS_PROTOTYPE: String
FUNCTION_PROTOTYPE: std:string/isWhiteSpaceOrLineTerminator
FUNCTION_PROTOTYPE: std:string/parseInt
FUNCTION_PROTOTYPE: parseInt
FUNCTION_PROTOTYPE: std:string/parseFloat
FUNCTION_PROTOTYPE: parseFloat
[program.exports]
CLASS_PROTOTYPE: std:array/Array
CLASS_PROTOTYPE: std:array/CArray
@ -88,6 +90,7 @@
CLASS_PROTOTYPE: std:error/RangeError
CLASS_PROTOTYPE: std:heap/Heap
CLASS_PROTOTYPE: std:map/Map
CLASS_PROTOTYPE: std:regexp/RegExp
CLASS_PROTOTYPE: std:set/Set
CLASS_PROTOTYPE: std:string/String
FUNCTION_PROTOTYPE: std:string/parseInt

View File

@ -528,14 +528,15 @@
(loop $continue|0
(if
(if (result i32)
(i32.eqz
(i32.ne
(get_local $2)
(i32.const 0)
)
(get_local $2)
(i32.rem_u
(get_local $1)
(i32.const 4)
)
(get_local $2)
)
(block
(block
@ -2337,10 +2338,10 @@
(loop $continue|0
(if
(if (result i32)
(i32.eqz
(i32.ne
(get_local $2)
(i32.const 0)
)
(get_local $2)
(i32.eq
(i32.load8_u
(get_local $0)
@ -2349,6 +2350,7 @@
(get_local $1)
)
)
(get_local $2)
)
(block
(block
@ -2600,7 +2602,9 @@
CLASS_PROTOTYPE: String
FUNCTION_PROTOTYPE: std:string/isWhiteSpaceOrLineTerminator
FUNCTION_PROTOTYPE: std:string/parseInt
FUNCTION_PROTOTYPE: parseInt
FUNCTION_PROTOTYPE: std:string/parseFloat
FUNCTION_PROTOTYPE: parseFloat
GLOBAL: std/heap/size
GLOBAL: std/heap/ptr1
GLOBAL: std/heap/ptr2
@ -2612,6 +2616,7 @@
CLASS_PROTOTYPE: std:error/RangeError
CLASS_PROTOTYPE: std:heap/Heap
CLASS_PROTOTYPE: std:map/Map
CLASS_PROTOTYPE: std:regexp/RegExp
CLASS_PROTOTYPE: std:set/Set
CLASS_PROTOTYPE: std:string/String
FUNCTION_PROTOTYPE: std:string/parseInt

View File

@ -160,7 +160,7 @@
(loop $continue|3
(if
(if (result i32)
(i32.eqz
(i32.ne
(tee_local $0
(block (result i32)
(set_local $0
@ -175,8 +175,8 @@
(get_local $0)
)
)
(i32.const 0)
)
(get_local $0)
(block (result i32)
(set_global $while/m
(i32.add
@ -186,6 +186,7 @@
)
(get_global $while/m)
)
(get_local $0)
)
(block
(nop)