1
0
mirror of https://github.com/fluencelabs/assemblyscript synced 2025-07-29 13:12:08 +00:00

Rename memory instructions; Rework constant handling

This commit is contained in:
dcodeIO
2018-07-18 23:49:32 +02:00
parent 34e8facfdc
commit a1b75b69b7
170 changed files with 26392 additions and 5185 deletions
examples
lib/loader/tests/assembly
package-lock.jsonpackage.json
snap
src
std
tests
allocators
binaryen
compiler
abi.optimized.watabi.untouched.watasc-constants.untouched.watbuiltins.optimized.watbuiltins.tsbuiltins.untouched.watcall-optional.optimized.watcall-optional.untouched.watclass-extends.optimized.watclass-extends.untouched.watclass-overloading.optimized.watclass-overloading.untouched.watclass-with-boolean-field.optimized.watclass-with-boolean-field.untouched.watclass.optimized.watclass.untouched.watenum.optimized.watenum.tsenum.untouched.watexport.optimized.watexport.untouched.watexports.optimized.watexports.tsexports.untouched.watexternal.optimized.watexternal.untouched.watfunction-types.optimized.watfunction-types.untouched.wati64-polyfill.optimized.wati64-polyfill.untouched.watif.optimized.watif.untouched.watimport.untouched.watinfer-type.untouched.watinlining-recursive.optimized.watinlining-recursive.untouched.watinlining.optimized.watinlining.untouched.watlimits.untouched.watmain.optimized.watmain.untouched.watmandelbrot.optimized.watmandelbrot.untouched.watmany-locals.optimized.watmany-locals.untouched.watmemcpy.optimized.watmemcpy.untouched.watmemmove.untouched.watmemset.optimized.watnamed-export-default.optimized.watnamed-export-default.untouched.watnamed-import-default.optimized.watnamed-import-default.untouched.watnamespace.tsnamespace.untouched.watnew-without-allocator.optimized.watnew-without-allocator.tsnew-without-allocator.untouched.watobject-literal.optimized.watobject-literal.untouched.watrecursive.optimized.watrecursive.untouched.watreexport.optimized.watreexport.untouched.watretain-i32.untouched.wat
std
typealias.optimized.wattypealias.untouched.wat

@@ -2,5 +2,10 @@
/// <reference path="../binaryen.d.ts" />
declare function allocate_memory(size: usize): usize;
declare function free_memory(ptr: usize): void;
declare namespace binaryen {
class Module {
constructor(ref: number);
emitText(): string;
emitAsmjs(): string;
}
}

@@ -1,42 +1,16 @@
// Copy Binaryen exports to global scope
const binaryen = global.Binaryen || require("binaryen");
global.binaryen = binaryen;
for (var key in binaryen)
if (key.startsWith("_Binaryen") || key.startsWith("_Relooper"))
global[key] = binaryen[key];
for (var key in binaryen) {
if (key.startsWith("_Binaryen") || key.startsWith("_Relooper")) global[key] = binaryen[key];
}
// Utilize Binaryen's heap
global.allocate_memory = function(size) {
if (!size) return 0; // should be safe in our case
return binaryen._malloc(size);
};
global.free_memory = function(ptr) {
if (ptr) binaryen._free(ptr);
};
global.move_memory = function(dest, src, n) {
return binaryen._memmove(dest, src, n);
};
global.store = function(ptr, val) {
binaryen.HEAPU8[ptr] = val;
};
global.load = function(ptr) {
return binaryen.HEAPU8[ptr];
};
// Implement module stubs
const Module = require("../../module").Module;
Module.prototype.toText = function() {
return new binaryen.Module(this.ref).emitText();
};
Module.prototype.toAsmjs = function() {
return new binaryen.Module(this.ref).emitAsmjs();
};
global.__memory_allocate = binaryen._malloc;
global.__memory_free = binaryen._free;
global.__memory_copy = binaryen._memmove;
global.__store = function(ptr, val) { binaryen.HEAPU8[ptr] = val; };
global.__load = function(ptr) { return binaryen.HEAPU8[ptr]; };

@@ -6,7 +6,17 @@
/// <reference path="./node.d.ts" />
import "./binaryen"; // must be first so portable can pick up the memory implementation
import "../../../std/portable/index";
import "./binaryen";
import "./float";
import "./i64";
import { Module } from "../../module";
Module.prototype.toText = function(this: Module) {
return new binaryen.Module(this.ref).emitText();
};
Module.prototype.toAsmjs = function(this: Module) {
return new binaryen.Module(this.ref).emitAsmjs();
};