PSON decoder example using namespaced imports

This commit is contained in:
dcodeIO
2017-12-30 05:11:58 +01:00
parent c67f87a988
commit 2888ba14ad
41 changed files with 1283 additions and 336 deletions

View File

@ -1 +1,3 @@
assert(true);
assert(1 == 1);
assert(0.5 > 0.4);

View File

@ -11,6 +11,24 @@
)
(unreachable)
)
(if
(i32.eqz
(i32.eq
(i32.const 1)
(i32.const 1)
)
)
(unreachable)
)
(if
(i32.eqz
(f64.gt
(f64.const 0.5)
(f64.const 0.4)
)
)
(unreachable)
)
)
)
(;

View File

@ -1,6 +1,6 @@
let b: bool = false;
var b = false;
let i: i32 = 0;
var i: i32 = 0;
i < 1;
i > 1;
@ -49,7 +49,7 @@ i &= 1;
i |= 1;
i ^= 1;
let I: i64 = 0;
var I: i64 = 0;
I < 1;
I > 1;
@ -98,7 +98,7 @@ I &= 1;
I |= 1;
I ^= 1;
let f: f32 = 0;
var f: f32 = 0;
f < 1;
f > 1;
@ -129,7 +129,7 @@ f -= 1;
f *= 1;
// f %= 1;
let F: f64 = 0;
var F: f64 = 0;
F < 1;
F > 1;

View File

@ -7,9 +7,13 @@
(global $builtins/F (mut f64) (f64.const 0))
(global $builtins/s (mut i32) (i32.const 0))
(memory $0 1)
(export "test" (func $builtins/test))
(export "memory" (memory $0))
(start $start)
(func $start (; 0 ;) (type $v)
(func $builtins/test (; 0 ;) (type $v)
(nop)
)
(func $start (; 1 ;) (type $v)
(local $0 f32)
(local $1 f64)
(local $2 i32)

View File

@ -1,8 +1,8 @@
let b: bool;
var b: bool;
// integers
let i: i32;
var i: i32;
clz<i32>(1);
ctz<i32>(1);
@ -22,7 +22,7 @@ i = abs<i32>(-42); assert(i == 42);
i = max<i32>(1, 2); assert(i == 2);
i = min<i32>(1, 2); assert(i == 1);
let I: i64;
var I: i64;
clz<i64>(1);
ctz<i64>(1);
@ -42,7 +42,7 @@ I = min<i64>(1, 2); assert(i == 1);
// floats
let f: f32;
var f: f32;
<f32>NaN;
<f32>Infinity;
@ -72,7 +72,7 @@ f = trunc<f32>(1.25);
b = isNaN<f32>(1.25);
b = isFinite<f32>(1.25);
let F: f64;
var F: f64;
<f64>NaN;
<f64>Infinity;
@ -129,7 +129,7 @@ F = reinterpret<i64,f64>(25);
// host
let s: usize;
var s: usize;
current_memory();
grow_memory(1);
@ -179,8 +179,9 @@ assert(isFinite<f64>(0));
// imported
// TODO: Can't be interpreted due to 'Fatal: callImport: unknown import: env.parseInt'
// parseInt(0);
// parseInt(0, 10);
// parseFloat(0);
export function test(): void {
// cannot be interpreted
// parseInt("01");
// parseInt("1", 10);
// parseFloat("1.0");
}

View File

@ -8,9 +8,12 @@
(global $builtins/s (mut i32) (i32.const 0))
(global $HEAP_BASE i32 (i32.const 4))
(memory $0 1)
(export "test" (func $builtins/test))
(export "memory" (memory $0))
(start $start)
(func $start (; 0 ;) (type $v)
(func $builtins/test (; 0 ;) (type $v)
)
(func $start (; 1 ;) (type $v)
(local $0 i32)
(local $1 i32)
(local $2 i64)
@ -1085,6 +1088,7 @@
GLOBAL: builtins/f
GLOBAL: builtins/F
GLOBAL: builtins/s
FUNCTION_PROTOTYPE: builtins/test
[program.exports]
FUNCTION_PROTOTYPE: builtins/test
;)

View File

@ -1,42 +1,132 @@
(module
(type $iv (func (param i32)))
(type $v (func))
(global $do/n (mut i32) (i32.const 10))
(global $do/m (mut i32) (i32.const 0))
(global $do/o (mut i32) (i32.const 0))
(memory $0 1)
(export "loopDo" (func $do/loopDo))
(export "loopDoInDo" (func $do/loopDoInDo))
(export "memory" (memory $0))
(func $do/loopDo (; 0 ;) (type $iv) (param $0 i32)
(start $start)
(func $start (; 0 ;) (type $v)
(local $0 i32)
(loop $continue|0
(br_if $continue|0
(tee_local $0
(i32.sub
(get_local $0)
(i32.const 1)
)
)
)
)
)
(func $do/loopDoInDo (; 1 ;) (type $iv) (param $0 i32)
(loop $continue|0
(set_local $0
(set_global $do/n
(i32.sub
(get_local $0)
(get_global $do/n)
(i32.const 1)
)
)
(loop $continue|1
(br_if $continue|1
(tee_local $0
(i32.sub
(get_local $0)
(i32.const 1)
)
)
(set_global $do/m
(i32.add
(get_global $do/m)
(i32.const 1)
)
)
(br_if $continue|0
(get_global $do/n)
)
)
(if
(get_global $do/n)
(unreachable)
)
(if
(i32.ne
(get_global $do/m)
(i32.const 10)
)
(unreachable)
)
(set_global $do/n
(i32.const 10)
)
(loop $continue|1
(set_global $do/n
(i32.sub
(tee_local $0
(get_global $do/n)
)
(i32.const 1)
)
)
(br_if $continue|1
(get_local $0)
)
)
(if
(i32.ne
(get_global $do/n)
(i32.const -1)
)
(unreachable)
)
(set_global $do/n
(i32.const 10)
)
(set_global $do/m
(i32.const 0)
)
(loop $continue|2
(set_global $do/n
(i32.sub
(get_global $do/n)
(i32.const 1)
)
)
(set_global $do/m
(i32.add
(get_global $do/m)
(i32.const 1)
)
)
(loop $continue|3
(set_global $do/n
(i32.sub
(get_global $do/n)
(i32.const 1)
)
)
(set_global $do/o
(i32.add
(get_global $do/o)
(i32.const 1)
)
)
(br_if $continue|3
(get_global $do/n)
)
)
(if
(get_global $do/n)
(unreachable)
)
(if
(i32.ne
(get_global $do/o)
(i32.const 9)
)
(unreachable)
)
(br_if $continue|2
(get_global $do/n)
)
)
(if
(get_global $do/n)
(unreachable)
)
(if
(i32.ne
(get_global $do/m)
(i32.const 1)
)
(unreachable)
)
(if
(i32.ne
(get_global $do/o)
(i32.const 9)
)
(unreachable)
)
)
)

View File

@ -1,14 +1,29 @@
export function loopDo(n: i32): void {
do {
n = n - 1;
} while (n);
}
var n = 10;
var m = 0;
do {
n--;
m++;
} while (n);
assert(n == 0);
assert(m == 10);
export function loopDoInDo(n: i32): void {
n = 10;
do; while(n--);
assert(n == -1);
n = 10;
m = 0;
var o = 0;
do {
n--;
m++;
do {
n = n - 1;
do {
n = n - 1;
} while (n);
n--;
o++;
} while (n);
}
assert(n == 0);
assert(o == 9);
} while (n);
assert(n == 0);
assert(m == 1);
assert(o == 9);

View File

@ -1,54 +1,228 @@
(module
(type $iv (func (param i32)))
(type $v (func))
(global $do/n (mut i32) (i32.const 10))
(global $do/m (mut i32) (i32.const 0))
(global $do/o (mut i32) (i32.const 0))
(global $HEAP_BASE i32 (i32.const 4))
(memory $0 1)
(export "loopDo" (func $do/loopDo))
(export "loopDoInDo" (func $do/loopDoInDo))
(export "memory" (memory $0))
(func $do/loopDo (; 0 ;) (type $iv) (param $0 i32)
(block $break|0
(loop $continue|0
(set_local $0
(i32.sub
(get_local $0)
(i32.const 1)
)
)
(br_if $continue|0
(get_local $0)
)
)
)
)
(func $do/loopDoInDo (; 1 ;) (type $iv) (param $0 i32)
(start $start)
(func $start (; 0 ;) (type $v)
(local $0 i32)
(block $break|0
(loop $continue|0
(block
(set_local $0
(i32.sub
(get_local $0)
(i32.const 1)
)
)
(block $break|1
(loop $continue|1
(drop
(block (result i32)
(set_local $0
(get_global $do/n)
)
(set_global $do/n
(i32.sub
(get_local $0)
(i32.const 1)
)
)
(br_if $continue|1
(get_local $0)
(get_local $0)
)
)
(drop
(block (result i32)
(set_local $0
(get_global $do/m)
)
(set_global $do/m
(i32.add
(get_local $0)
(i32.const 1)
)
)
(get_local $0)
)
)
)
(br_if $continue|0
(get_local $0)
(get_global $do/n)
)
)
)
(if
(i32.eqz
(i32.eq
(get_global $do/n)
(i32.const 0)
)
)
(unreachable)
)
(if
(i32.eqz
(i32.eq
(get_global $do/m)
(i32.const 10)
)
)
(unreachable)
)
(set_global $do/n
(i32.const 10)
)
(block $break|1
(loop $continue|1
(nop)
(br_if $continue|1
(block (result i32)
(set_local $0
(get_global $do/n)
)
(set_global $do/n
(i32.sub
(get_local $0)
(i32.const 1)
)
)
(get_local $0)
)
)
)
)
(if
(i32.eqz
(i32.eq
(get_global $do/n)
(i32.sub
(i32.const 0)
(i32.const 1)
)
)
)
(unreachable)
)
(set_global $do/n
(i32.const 10)
)
(set_global $do/m
(i32.const 0)
)
(block $break|2
(loop $continue|2
(block
(drop
(block (result i32)
(set_local $0
(get_global $do/n)
)
(set_global $do/n
(i32.sub
(get_local $0)
(i32.const 1)
)
)
(get_local $0)
)
)
(drop
(block (result i32)
(set_local $0
(get_global $do/m)
)
(set_global $do/m
(i32.add
(get_local $0)
(i32.const 1)
)
)
(get_local $0)
)
)
(block $break|3
(loop $continue|3
(block
(drop
(block (result i32)
(set_local $0
(get_global $do/n)
)
(set_global $do/n
(i32.sub
(get_local $0)
(i32.const 1)
)
)
(get_local $0)
)
)
(drop
(block (result i32)
(set_local $0
(get_global $do/o)
)
(set_global $do/o
(i32.add
(get_local $0)
(i32.const 1)
)
)
(get_local $0)
)
)
)
(br_if $continue|3
(get_global $do/n)
)
)
)
(if
(i32.eqz
(i32.eq
(get_global $do/n)
(i32.const 0)
)
)
(unreachable)
)
(if
(i32.eqz
(i32.eq
(get_global $do/o)
(i32.const 9)
)
)
(unreachable)
)
)
(br_if $continue|2
(get_global $do/n)
)
)
)
(if
(i32.eqz
(i32.eq
(get_global $do/n)
(i32.const 0)
)
)
(unreachable)
)
(if
(i32.eqz
(i32.eq
(get_global $do/m)
(i32.const 1)
)
)
(unreachable)
)
(if
(i32.eqz
(i32.eq
(get_global $do/o)
(i32.const 9)
)
)
(unreachable)
)
)
)
(;
@ -97,9 +271,9 @@
FUNCTION_PROTOTYPE: isize
FUNCTION_PROTOTYPE: usize
GLOBAL: HEAP_BASE
FUNCTION_PROTOTYPE: do/loopDo
FUNCTION_PROTOTYPE: do/loopDoInDo
GLOBAL: do/n
GLOBAL: do/m
GLOBAL: do/o
[program.exports]
FUNCTION_PROTOTYPE: do/loopDo
FUNCTION_PROTOTYPE: do/loopDoInDo
;)

View File

@ -10,6 +10,7 @@
(export "renamed_b" (global $export/b))
(export "two" (func $export/ns.two))
(export "memory" (memory $0))
(start $export/ns.two)
(func $export/add (; 0 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
(i32.add
(get_local $0)

View File

@ -11,6 +11,7 @@ export { sub as renamed_sub };
export const a: i32 = 1;
const b: i32 = 2;
b;
export { b as renamed_b };

View File

@ -11,6 +11,7 @@
(export "renamed_b" (global $export/b))
(export "two" (func $export/ns.two))
(export "memory" (memory $0))
(start $start)
(func $export/add (; 0 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
(return
(i32.add
@ -29,6 +30,11 @@
)
(func $export/ns.two (; 2 ;) (type $v)
)
(func $start (; 3 ;) (type $v)
(drop
(i32.const 2)
)
)
)
(;
[program.elements]

View File

@ -1,10 +1,10 @@
let i: i32;
var i: i32;
for (i = 0; i < 10; ++i) {
;
}
assert(i == 10);
for (let j: i32 = 0; j < 10; ++j) {
for (var j: i32 = 0; j < 10; ++j) {
;
}

View File

@ -33,206 +33,204 @@
(local $6 i32)
(local $7 i32)
(local $8 i32)
(local $9 i32)
(local $10 i32)
(nop)
(nop)
(block
(set_local $6
(set_local $0
(i32.sub
(get_global $../../examples/game-of-life/assembly/game-of-life/h)
(i32.const 1)
)
)
(set_local $7
(set_local $1
(i32.sub
(get_global $../../examples/game-of-life/assembly/game-of-life/w)
(i32.const 1)
)
)
)
(block
(set_local $10
(i32.const 0)
)
)
(block $break|0
(set_local $0
(i32.const 0)
(block
(set_local $2
(i32.const 0)
)
)
(loop $continue|0
(if
(i32.lt_u
(get_local $0)
(get_local $2)
(get_global $../../examples/game-of-life/assembly/game-of-life/h)
)
(block
(block
(set_local $1
(select
(get_local $6)
(i32.sub
(block
(set_local $3
(select
(get_local $0)
(i32.const 1)
)
(i32.eq
(get_local $0)
(i32.const 0)
(i32.sub
(get_local $2)
(i32.const 1)
)
(i32.eq
(get_local $2)
(i32.const 0)
)
)
)
)
(set_local $2
(select
(i32.const 0)
(i32.add
(get_local $0)
(i32.const 1)
)
(i32.eq
(get_local $0)
(get_local $6)
(set_local $4
(select
(i32.const 0)
(i32.add
(get_local $2)
(i32.const 1)
)
(i32.eq
(get_local $2)
(get_local $0)
)
)
)
)
(block $break|1
(set_local $3
(i32.const 0)
(block
(set_local $5
(i32.const 0)
)
)
(loop $continue|1
(if
(i32.lt_u
(get_local $3)
(get_local $5)
(get_global $../../examples/game-of-life/assembly/game-of-life/w)
)
(block
(block
(set_local $4
(select
(get_local $7)
(i32.sub
(get_local $3)
(i32.const 1)
(block
(set_local $6
(select
(get_local $1)
(i32.sub
(get_local $5)
(i32.const 1)
)
(i32.eq
(get_local $5)
(i32.const 0)
)
)
(i32.eq
(get_local $3)
)
(set_local $7
(select
(i32.const 0)
(i32.add
(get_local $5)
(i32.const 1)
)
(i32.eq
(get_local $5)
(get_local $1)
)
)
)
)
(set_local $5
(select
(i32.const 0)
(i32.add
(get_local $3)
(i32.const 1)
)
(i32.eq
(get_local $3)
(get_local $7)
)
)
)
(set_local $8
(i32.add
(block
(set_local $8
(i32.add
(i32.add
(i32.add
(i32.add
(i32.add
(i32.add
(i32.load8_u
(i32.add
(i32.mul
(get_local $1)
(get_global $../../examples/game-of-life/assembly/game-of-life/w)
(i32.add
(i32.load8_u
(i32.add
(i32.mul
(get_local $3)
(get_global $../../examples/game-of-life/assembly/game-of-life/w)
)
(get_local $6)
)
)
(i32.load8_u
(i32.add
(i32.mul
(get_local $3)
(get_global $../../examples/game-of-life/assembly/game-of-life/w)
)
(get_local $5)
)
(get_local $4)
)
)
(i32.load8_u
(i32.add
(i32.mul
(get_local $1)
(get_local $3)
(get_global $../../examples/game-of-life/assembly/game-of-life/w)
)
(get_local $3)
(get_local $7)
)
)
)
(i32.load8_u
(i32.add
(i32.mul
(get_local $1)
(get_local $2)
(get_global $../../examples/game-of-life/assembly/game-of-life/w)
)
(get_local $5)
(get_local $6)
)
)
)
(i32.load8_u
(i32.add
(i32.mul
(get_local $0)
(get_local $2)
(get_global $../../examples/game-of-life/assembly/game-of-life/w)
)
(get_local $4)
(get_local $7)
)
)
)
(i32.load8_u
(i32.add
(i32.mul
(get_local $0)
(get_local $4)
(get_global $../../examples/game-of-life/assembly/game-of-life/w)
)
(get_local $5)
(get_local $6)
)
)
)
(i32.load8_u
(i32.add
(i32.mul
(get_local $2)
(get_local $4)
(get_global $../../examples/game-of-life/assembly/game-of-life/w)
)
(get_local $4)
(get_local $5)
)
)
)
(i32.load8_u
(i32.add
(i32.mul
(get_local $2)
(get_local $4)
(get_global $../../examples/game-of-life/assembly/game-of-life/w)
)
(get_local $3)
(get_local $7)
)
)
)
(i32.load8_u
(i32.add
(i32.mul
(get_local $2)
(get_global $../../examples/game-of-life/assembly/game-of-life/w)
)
(get_local $5)
)
)
)
)
(set_local $9
(i32.load8_u
(i32.add
(i32.mul
(get_local $0)
(get_global $../../examples/game-of-life/assembly/game-of-life/w)
)
(get_local $3)
)
)
)
(if
(get_local $9)
(i32.load8_u
(i32.add
(i32.mul
(get_local $2)
(get_global $../../examples/game-of-life/assembly/game-of-life/w)
)
(get_local $5)
)
)
(if
(if (result i32)
(i32.lt_u
@ -253,11 +251,11 @@
(i32.add
(get_global $../../examples/game-of-life/assembly/game-of-life/s)
(i32.mul
(get_local $0)
(get_local $2)
(get_global $../../examples/game-of-life/assembly/game-of-life/w)
)
)
(get_local $3)
(get_local $5)
)
(i32.const 0)
)
@ -272,20 +270,20 @@
(i32.add
(get_global $../../examples/game-of-life/assembly/game-of-life/s)
(i32.mul
(get_local $0)
(get_local $2)
(get_global $../../examples/game-of-life/assembly/game-of-life/w)
)
)
(get_local $3)
(get_local $5)
)
(i32.const 1)
)
)
)
)
(set_local $3
(set_local $5
(i32.add
(get_local $3)
(get_local $5)
(i32.const 1)
)
)
@ -295,9 +293,9 @@
)
)
)
(set_local $0
(set_local $2
(i32.add
(get_local $0)
(get_local $2)
(i32.const 1)
)
)

View File

@ -1,8 +1,8 @@
(module
(type $iii (func (param i32 i32) (result i32)))
(type $v (func))
(global $export/a i32 (i32.const 1))
(global $export/b i32 (i32.const 2))
(global $export/a i32 (i32.const 1))
(global $HEAP_BASE i32 (i32.const 4))
(memory $0 1)
(export "memory" (memory $0))
@ -26,6 +26,9 @@
(func $export/ns.two (; 2 ;) (type $v)
)
(func $start (; 3 ;) (type $v)
(drop
(i32.const 2)
)
(drop
(i32.add
(call $export/add

View File

@ -8,39 +8,39 @@ const F = 1.5;
F;
function locals(): void {
let li = 10;
let lI = 0x100000000;
let lF = 1.5;
let ai = i;
let aI = I;
let aF = F;
var li = 10;
var lI = 0x100000000;
var lF = 1.5;
var ai = i;
var aI = I;
var aF = F;
}
locals();
function reti(): i32 {
return 0;
}
let ri = reti();
var ri = reti();
ri;
function retI(): i64 {
return 0;
}
let rI = retI();
var rI = retI();
rI;
function retf(): f32 {
return 0;
}
let rf = retf();
var rf = retf();
rf;
function refF(): f64 {
return 0;
}
let rF = refF();
var rF = refF();
rF;
for (let a = 0, b = 10; a < b; ++a) {
for (var a = 0, b = 10; a < b; ++a) {
;
}

View File

@ -6,7 +6,7 @@
1 && 2 || unreachable();
1.0 && 2.0 || unreachable();
let i: i32;
var i: i32;
i = 1 && 2;
assert(i == 2);
@ -14,7 +14,7 @@ assert(i == 2);
i = 0 || 1;
assert(i == 1);
let I: i64;
var I: i64;
I = 1 && 2;
assert(I == 2);
@ -22,7 +22,7 @@ assert(I == 2);
I = 0 || 1;
assert(I == 1);
let f: f32;
var f: f32;
f = 1.0 && 2.0;
assert(f == 2.0);
@ -30,7 +30,7 @@ assert(f == 2.0);
f = 0.0 || 1.0;
assert(f == 1.0);
let F: f64;
var F: f64;
F = 1.0 && 2.0;
assert(F == 2.0);

View File

@ -1,7 +1,7 @@
export function memcpy(dest: usize, src: usize, n: usize): usize {
// the following is based on musl's implementation of memcpy
let d: usize = dest, s: usize = src;
let w: u32, x: u32;
var d: usize = dest, s: usize = src;
var w: u32, x: u32;
// copy 1 byte each until src is aligned to 4 bytes
while (n && s % 4) {
@ -147,7 +147,7 @@ store<u64>(base + 8 , 0x2222222222222222);
store<u64>(base + 16, 0x3333333333333333);
store<u64>(base + 24, 0x4444444444444444);
let dest: usize;
var dest: usize;
dest = memcpy(base + 1, base + 16, 4);
assert(dest == base + 1);
assert(load<u64>(base) == 0x1111113333333311);

View File

@ -1,6 +1,6 @@
namespace Outer {
export namespace Inner {
export let aVar: i32 = 0;
export var aVar: i32 = 0;
export function aFunc(): i32 { return aVar; }
export enum anEnum { ONE = 1, TWO = 2 }
}

View File

@ -1,7 +1,7 @@
let i: i32 = 0;
let I: i64 = 0;
let f: f32 = 0;
let F: f64 = 0;
var i: i32 = 0;
var I: i64 = 0;
var f: f32 = 0;
var F: f64 = 0;
i8(i);
i8(I);

View File

@ -1,8 +1,8 @@
(module
(type $iii (func (param i32 i32) (result i32)))
(type $v (func))
(global $export/a i32 (i32.const 1))
(global $export/b i32 (i32.const 2))
(global $export/a i32 (i32.const 1))
(memory $0 1)
(export "add" (func $export/add))
(export "renamed_sub" (func $export/sub))

View File

@ -1,8 +1,8 @@
(module
(type $iii (func (param i32 i32) (result i32)))
(type $v (func))
(global $export/a i32 (i32.const 1))
(global $export/b i32 (i32.const 2))
(global $export/a i32 (i32.const 1))
(global $HEAP_BASE i32 (i32.const 4))
(memory $0 1)
(export "add" (func $export/add))
@ -32,6 +32,9 @@
(func $export/ns.two (; 2 ;) (type $v)
)
(func $start (; 3 ;) (type $v)
(drop
(i32.const 2)
)
(drop
(i32.add
(call $export/add

View File

@ -2,7 +2,7 @@
1 ? 1 : unreachable();
(0 ? unreachable() : 1) ? 1 : unreachable();
let a: i32;
var a: i32;
a = 0 ? unreachable() : 1;
a = 1 ? 1 : unreachable();

View File

@ -180,9 +180,9 @@ export function control$construct(ptr: usize): void {
block$set_next_free(ptr, ptr);
block$set_prev_free(ptr, ptr);
control$set_fl_bitmap(ptr, 0);
for (let flIndex: usize = 0; flIndex < FL_INDEX_COUNT; ++flIndex) {
for (var flIndex: usize = 0; flIndex < FL_INDEX_COUNT; ++flIndex) {
control$set_sl_bitmap(ptr, flIndex, 0);
for (let slIndex: usize = 0; slIndex < SL_INDEX_COUNT; ++slIndex)
for (var slIndex: usize = 0; slIndex < SL_INDEX_COUNT; ++slIndex)
control$set_block(ptr, flIndex, slIndex, ptr);
}
}

View File

@ -6,7 +6,7 @@
-1.25;
!1.25;
let i: i32 = 0;
var i: i32 = 0;
+i;
-i;
@ -30,7 +30,7 @@ i = --i;
i = i++;
i = i--;
let I: i64 = 0;
var I: i64 = 0;
+I;
-I;
@ -54,7 +54,7 @@ I = --I;
I = I++;
I = I--;
let f: f32 = 0;
var f: f32 = 0;
+f;
-f;
@ -75,7 +75,7 @@ f = --f;
f = f++;
f = f--;
let F: f64 = 0;
var F: f64 = 0;
+F;
-F;

View File

@ -1,17 +1,26 @@
(module
(type $iv (func (param i32)))
(type $v (func))
(global $while/n (mut i32) (i32.const 10))
(global $while/m (mut i32) (i32.const 0))
(global $while/o (mut i32) (i32.const 0))
(memory $0 1)
(export "loopWhile" (func $while/loopWhile))
(export "loopWhileInWhile" (func $while/loopWhileInWhile))
(export "memory" (memory $0))
(func $while/loopWhile (; 0 ;) (type $iv) (param $0 i32)
(start $start)
(func $start (; 0 ;) (type $v)
(local $0 i32)
(loop $continue|0
(if
(get_local $0)
(get_global $while/n)
(block
(set_local $0
(set_global $while/n
(i32.sub
(get_local $0)
(get_global $while/n)
(i32.const 1)
)
)
(set_global $while/m
(i32.add
(get_global $while/m)
(i32.const 1)
)
)
@ -19,35 +28,140 @@
)
)
)
)
(func $while/loopWhileInWhile (; 1 ;) (type $iv) (param $0 i32)
(loop $continue|0
(if
(get_global $while/n)
(unreachable)
)
(if
(i32.ne
(get_global $while/m)
(i32.const 10)
)
(unreachable)
)
(set_global $while/n
(i32.const 10)
)
(set_global $while/m
(i32.const 0)
)
(loop $continue|1
(if
(get_local $0)
(get_global $while/n)
(block
(set_local $0
(set_global $while/n
(i32.sub
(get_local $0)
(get_global $while/n)
(i32.const 1)
)
)
(loop $continue|1
(set_global $while/m
(i32.add
(get_global $while/m)
(i32.const 1)
)
)
(loop $continue|2
(if
(get_local $0)
(get_global $while/n)
(block
(set_local $0
(set_global $while/n
(i32.sub
(get_local $0)
(get_global $while/n)
(i32.const 1)
)
)
(br $continue|1)
(set_global $while/o
(i32.add
(get_global $while/o)
(i32.const 1)
)
)
(br $continue|2)
)
)
)
(br $continue|0)
(if
(get_global $while/n)
(unreachable)
)
(if
(i32.ne
(get_global $while/o)
(i32.const 9)
)
(unreachable)
)
(br $continue|1)
)
)
)
(if
(get_global $while/n)
(unreachable)
)
(if
(i32.ne
(get_global $while/m)
(i32.const 1)
)
(unreachable)
)
(if
(i32.ne
(get_global $while/o)
(i32.const 9)
)
(unreachable)
)
(set_global $while/n
(i32.const 1)
)
(set_global $while/m
(i32.const 0)
)
(loop $continue|3
(br_if $continue|3
(if (result i32)
(block (result i32)
(set_global $while/n
(i32.sub
(tee_local $0
(get_global $while/n)
)
(i32.const 1)
)
)
(tee_local $0
(get_local $0)
)
)
(block (result i32)
(set_global $while/m
(i32.add
(get_global $while/m)
(i32.const 1)
)
)
(get_global $while/m)
)
(get_local $0)
)
)
)
(if
(i32.ne
(get_global $while/n)
(i32.const -1)
)
(unreachable)
)
(if
(i32.ne
(get_global $while/m)
(i32.const 1)
)
(unreachable)
)
)
)

View File

@ -1,14 +1,32 @@
export function loopWhile(n: i32): void {
while (n) {
n = n - 1;
}
}
var n = 10;
var m = 0;
export function loopWhileInWhile(n: i32): void {
while (n) {
n = n - 1;
while (n) {
n = n - 1;
}
}
while (n) {
n--;
m++;
}
assert(n == 0);
assert(m == 10);
n = 10;
m = 0;
var o = 0;
while (n) {
n--;
m++;
while (n) {
n--;
o++;
}
assert(n == 0);
assert(o == 9);
}
assert(n == 0);
assert(m == 1);
assert(o == 9);
n = 1;
m = 0;
while (n-- && ++m);
assert(n == -1);
assert(m == 1);

View File

@ -1,20 +1,47 @@
(module
(type $iv (func (param i32)))
(type $v (func))
(global $while/n (mut i32) (i32.const 10))
(global $while/m (mut i32) (i32.const 0))
(global $while/o (mut i32) (i32.const 0))
(global $HEAP_BASE i32 (i32.const 4))
(memory $0 1)
(export "loopWhile" (func $while/loopWhile))
(export "loopWhileInWhile" (func $while/loopWhileInWhile))
(export "memory" (memory $0))
(func $while/loopWhile (; 0 ;) (type $iv) (param $0 i32)
(start $start)
(func $start (; 0 ;) (type $v)
(local $0 i32)
(block $break|0
(loop $continue|0
(if
(get_local $0)
(get_global $while/n)
(block
(set_local $0
(i32.sub
(get_local $0)
(i32.const 1)
(block
(drop
(block (result i32)
(set_local $0
(get_global $while/n)
)
(set_global $while/n
(i32.sub
(get_local $0)
(i32.const 1)
)
)
(get_local $0)
)
)
(drop
(block (result i32)
(set_local $0
(get_global $while/m)
)
(set_global $while/m
(i32.add
(get_local $0)
(i32.const 1)
)
)
(get_local $0)
)
)
)
(br $continue|0)
@ -22,42 +49,218 @@
)
)
)
)
(func $while/loopWhileInWhile (; 1 ;) (type $iv) (param $0 i32)
(block $break|0
(loop $continue|0
(if
(i32.eqz
(i32.eq
(get_global $while/n)
(i32.const 0)
)
)
(unreachable)
)
(if
(i32.eqz
(i32.eq
(get_global $while/m)
(i32.const 10)
)
)
(unreachable)
)
(set_global $while/n
(i32.const 10)
)
(set_global $while/m
(i32.const 0)
)
(block $break|1
(loop $continue|1
(if
(get_local $0)
(get_global $while/n)
(block
(block
(set_local $0
(i32.sub
(drop
(block (result i32)
(set_local $0
(get_global $while/n)
)
(set_global $while/n
(i32.sub
(get_local $0)
(i32.const 1)
)
)
(get_local $0)
(i32.const 1)
)
)
(block $break|1
(loop $continue|1
(drop
(block (result i32)
(set_local $0
(get_global $while/m)
)
(set_global $while/m
(i32.add
(get_local $0)
(i32.const 1)
)
)
(get_local $0)
)
)
(block $break|2
(loop $continue|2
(if
(get_local $0)
(get_global $while/n)
(block
(set_local $0
(i32.sub
(get_local $0)
(i32.const 1)
(block
(drop
(block (result i32)
(set_local $0
(get_global $while/n)
)
(set_global $while/n
(i32.sub
(get_local $0)
(i32.const 1)
)
)
(get_local $0)
)
)
(drop
(block (result i32)
(set_local $0
(get_global $while/o)
)
(set_global $while/o
(i32.add
(get_local $0)
(i32.const 1)
)
)
(get_local $0)
)
)
)
(br $continue|1)
(br $continue|2)
)
)
)
)
(if
(i32.eqz
(i32.eq
(get_global $while/n)
(i32.const 0)
)
)
(unreachable)
)
(if
(i32.eqz
(i32.eq
(get_global $while/o)
(i32.const 9)
)
)
(unreachable)
)
)
(br $continue|0)
(br $continue|1)
)
)
)
)
(if
(i32.eqz
(i32.eq
(get_global $while/n)
(i32.const 0)
)
)
(unreachable)
)
(if
(i32.eqz
(i32.eq
(get_global $while/m)
(i32.const 1)
)
)
(unreachable)
)
(if
(i32.eqz
(i32.eq
(get_global $while/o)
(i32.const 9)
)
)
(unreachable)
)
(set_global $while/n
(i32.const 1)
)
(set_global $while/m
(i32.const 0)
)
(block $break|3
(loop $continue|3
(if
(if (result i32)
(tee_local $0
(block (result i32)
(set_local $0
(get_global $while/n)
)
(set_global $while/n
(i32.sub
(get_local $0)
(i32.const 1)
)
)
(get_local $0)
)
)
(block (result i32)
(set_global $while/m
(i32.add
(get_global $while/m)
(i32.const 1)
)
)
(get_global $while/m)
)
(get_local $0)
)
(block
(nop)
(br $continue|3)
)
)
)
)
(if
(i32.eqz
(i32.eq
(get_global $while/n)
(i32.sub
(i32.const 0)
(i32.const 1)
)
)
)
(unreachable)
)
(if
(i32.eqz
(i32.eq
(get_global $while/m)
(i32.const 1)
)
)
(unreachable)
)
)
)
(;
@ -106,9 +309,9 @@
FUNCTION_PROTOTYPE: isize
FUNCTION_PROTOTYPE: usize
GLOBAL: HEAP_BASE
FUNCTION_PROTOTYPE: while/loopWhile
FUNCTION_PROTOTYPE: while/loopWhileInWhile
GLOBAL: while/n
GLOBAL: while/m
GLOBAL: while/o
[program.exports]
FUNCTION_PROTOTYPE: while/loopWhile
FUNCTION_PROTOTYPE: while/loopWhileInWhile
;)