mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-06-23 03:31:44 +00:00
Better testing infrastructure; Initial exports/imports/re-exports
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
/// <reference path="../src/binaryen.d.ts" />
|
||||
/// <reference path="../src/glue/binaryen.d.ts" />
|
||||
|
||||
import "../src/glue/js";
|
||||
import { Type, Module, MemorySegment, BinaryOp } from "../src/binaryen";
|
||||
import { NativeType, Module, MemorySegment, BinaryOp } from "../src/module";
|
||||
import { Target } from "../src/compiler";
|
||||
import { U64 } from "../src/util";
|
||||
|
||||
@ -11,33 +12,33 @@ mod.setMemory(1, Module.MAX_MEMORY_WASM32, [
|
||||
MemorySegment.create(new Uint8Array(4), U64.fromI32(12))
|
||||
], Target.WASM32, "memory");
|
||||
|
||||
const add = mod.addFunctionType("iii", Type.I32, [ Type.I32, Type.I32 ]);
|
||||
const add = mod.addFunctionType("iii", NativeType.I32, [ NativeType.I32, NativeType.I32 ]);
|
||||
mod.addFunction("add", add, [], mod.createReturn(
|
||||
mod.createBinary(BinaryOp.AddI32,
|
||||
mod.createGetLocal(0, Type.I32),
|
||||
mod.createGetLocal(1, Type.I32)
|
||||
mod.createGetLocal(0, NativeType.I32),
|
||||
mod.createGetLocal(1, NativeType.I32)
|
||||
)
|
||||
));
|
||||
mod.addExport("add", "add");
|
||||
|
||||
const lit = mod.addFunctionType("I", Type.I64, []);
|
||||
const lit = mod.addFunctionType("I", NativeType.I64, []);
|
||||
mod.addFunction("lit", lit, [], mod.createReturn(
|
||||
mod.createI64(0, 0x80000000) // I64_MIN
|
||||
));
|
||||
mod.addExport("lit", "lit");
|
||||
|
||||
mod.addGlobal("42", Type.I32, false, mod.createI32(42));
|
||||
mod.addGlobal("42", NativeType.I32, false, mod.createI32(42));
|
||||
|
||||
const aSwitch = mod.addFunctionType("ii", Type.I32, [ Type.I32 ]);
|
||||
const aSwitch = mod.addFunctionType("ii", NativeType.I32, [ NativeType.I32 ]);
|
||||
const rl = mod.createRelooper();
|
||||
const b0 = rl.addBlockWithSwitch(mod.createNop(), mod.createGetLocal(0, Type.I32));
|
||||
const b0 = rl.addBlockWithSwitch(mod.createNop(), mod.createGetLocal(0, NativeType.I32));
|
||||
let b1, b2, b3;
|
||||
rl.addBranchForSwitch(b0, b2 = rl.addBlock(mod.createReturn(mod.createI32(1))), [1]); // indexed branch
|
||||
rl.addBranchForSwitch(b0, b3 = rl.addBlock(mod.createReturn(mod.createI32(2))), [2]); // indexed branch
|
||||
rl.addBranch(b0, b1 = rl.addBlock(mod.createDrop(mod.createI32(0)))); // default branch
|
||||
rl.addBranch(b1, b2);
|
||||
|
||||
mod.addFunction("aSwitch", aSwitch, [ Type.I32 ], mod.createBlock(null, [
|
||||
mod.addFunction("aSwitch", aSwitch, [ NativeType.I32 ], mod.createBlock(null, [
|
||||
rl.renderAndDispose(b0, 1),
|
||||
mod.createUnreachable()
|
||||
]));
|
||||
|
Reference in New Issue
Block a user