summaryrefslogtreecommitdiff
path: root/test/binaryen.js/push-pop.js
blob: 2b50b2dca66bd304c5731bff2c130d5dd1ae1b4c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
function assert(x) {
  if (!x) throw 'error!';
}

function cleanInfo(info) {
  var ret = {};
  for (var x in info) {
    if (x !== 'value') {
      ret[x] = info[x];
    }
  }
  return ret;
}

function stringify(expr) {
  return JSON.stringify(cleanInfo(Binaryen.getExpressionInfo(expr)));
}

function test() {
  var module = new Binaryen.Module();

  var func = module.addFunction("func", Binaryen.none, Binaryen.none, [],
    module.block(null, [
      module.push(module.i32.pop()),
      module.push(module.i64.pop()),
      module.push(module.f32.pop()),
      module.push(module.f64.pop()),
      module.push(module.v128.pop()),
      module.push(module.funcref.pop()),
      module.push(module.anyref.pop()),
      module.push(module.nullref.pop()),
      module.push(module.exnref.pop())
    ]
  )
  )

  assert(module.validate());
  console.log(module.emitText());

  console.log("getExpressionInfo(i32.pop) = " + stringify(module.i32.pop()));
  console.log("getExpressionInfo(i64.pop) = " + stringify(module.i64.pop()));
  console.log("getExpressionInfo(f32.pop) = " + stringify(module.f32.pop()));
  console.log("getExpressionInfo(f64.pop) = " + stringify(module.f64.pop()));
  console.log("getExpressionInfo(v128.pop) = " + stringify(module.v128.pop()));
  console.log("getExpressionInfo(funcref.pop) = " + stringify(module.funcref.pop()));
  console.log("getExpressionInfo(anyref.pop) = " + stringify(module.anyref.pop()));
  console.log("getExpressionInfo(nullref.pop) = " + stringify(module.nullref.pop()));
  console.log("getExpressionInfo(exnref.pop) = " + stringify(module.exnref.pop()));
  console.log("getExpressionInfo(push) = " + stringify(module.push(module.i32.const(0))));
}

Binaryen.ready.then(test);