Refactored builtins

This commit is contained in:
dcodeIO
2017-12-05 01:45:15 +01:00
parent b7030d4dea
commit 40b814ac73
7 changed files with 488 additions and 417 deletions

3
src/glue/js.d.ts vendored
View File

@ -14,3 +14,6 @@ declare type bool = boolean;
// Raw memory access (here: Binaryen memory)
declare function store<T = u8>(ptr: usize, val: T): void;
declare function load<T = u8>(ptr: usize): T;
// Other things that might or might not be useful
declare function select<T>(ifTrue: T, ifFalse: T, condition: bool): T;

View File

@ -8,6 +8,10 @@ globalScope["load"] = function load_u8(ptr: number) {
return binaryen.HEAPU8[ptr];
};
globalScope["select"] = function select<T>(ifTrue: T, ifFalse: T, condition: bool): T {
return condition ? ifTrue : ifFalse;
};
const binaryen = require("binaryen");
for (const key in binaryen)
if (/^_(?:Binaryen|Relooper|malloc$|free$)/.test(key))