mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-06-17 17:01:37 +00:00
llvm-like naming of __heap_base, definition fixes, update examples
This commit is contained in:
@ -85,7 +85,7 @@ function postInstantiate(baseModule, instance) {
|
||||
const table = rawExports.table;
|
||||
const alloc = rawExports["__alloc"];
|
||||
const retain = rawExports["__retain"];
|
||||
const rtti = rawExports["__rtti"] || ~0; // oob if not present
|
||||
const rttiBase = rawExports["__rtti_base"] || ~0; // oob if not present
|
||||
|
||||
// Provide views for all sorts of basic values
|
||||
var buffer, I8, U8, I16, U16, I32, U32, F32, F64, I64, U64;
|
||||
@ -113,16 +113,16 @@ function postInstantiate(baseModule, instance) {
|
||||
|
||||
/** Gets the runtime type info for the given id. */
|
||||
function getInfo(id) {
|
||||
const count = U32[rtti >>> 2];
|
||||
const count = U32[rttiBase >>> 2];
|
||||
if ((id >>>= 0) >= count) throw Error("invalid id: " + id);
|
||||
return U32[(rtti + 4 >>> 2) + id * 2];
|
||||
return U32[(rttiBase + 4 >>> 2) + id * 2];
|
||||
}
|
||||
|
||||
/** Gets the runtime base id for the given id. */
|
||||
function getBase(id) {
|
||||
const count = U32[rtti >>> 2];
|
||||
const count = U32[rttiBase >>> 2];
|
||||
if ((id >>>= 0) >= count) throw Error("invalid id: " + id);
|
||||
return U32[(rtti + 4 >>> 2) + id * 2 + 1];
|
||||
return U32[(rttiBase + 4 >>> 2) + id * 2 + 1];
|
||||
}
|
||||
|
||||
/** Gets the runtime alignment of a collection's values or keys. */
|
||||
@ -217,7 +217,7 @@ function postInstantiate(baseModule, instance) {
|
||||
/** Tests whether an object is an instance of the class represented by the specified base id. */
|
||||
function __instanceof(ref, baseId) {
|
||||
var id = U32[(ref + ID_OFFSET) >>> 2];
|
||||
if (id <= U32[rtti >>> 2]) {
|
||||
if (id <= U32[rttiBase >>> 2]) {
|
||||
do if (id == baseId) return true;
|
||||
while (id = getBase(id));
|
||||
}
|
||||
@ -308,7 +308,11 @@ function demangle(exports, baseModule) {
|
||||
let ctor = function(...args) {
|
||||
return ctor.wrap(ctor.prototype.constructor(0, ...args));
|
||||
};
|
||||
ctor.prototype = {};
|
||||
ctor.prototype = {
|
||||
valueOf: function valueOf() {
|
||||
return this[THIS];
|
||||
}
|
||||
};
|
||||
ctor.wrap = function(thisValue) {
|
||||
return Object.create(ctor.prototype, { [THIS]: { value: thisValue, writable: false } });
|
||||
};
|
||||
|
Binary file not shown.
@ -111,6 +111,7 @@ car.openDoors();
|
||||
assert.strictEqual(car.isDoorsOpen, 1);
|
||||
car.closeDoors();
|
||||
assert.strictEqual(car.isDoorsOpen, 0);
|
||||
module.__release(car); // uses Car.prototype.valueOf to obtain `thisPtr`
|
||||
|
||||
// should be able to use trace
|
||||
module.dotrace(42);
|
||||
|
Reference in New Issue
Block a user