runtime api

This commit is contained in:
dcode
2019-04-03 21:47:38 +02:00
parent cc1e4cd004
commit 85f3fc54a7
69 changed files with 1016 additions and 982 deletions

View File

@ -483,7 +483,7 @@ export namespace BuiltinSymbols {
export const runtime_reallocate = "~lib/runtime/runtime.reallocate";
export const runtime_register = "~lib/runtime/runtime.register";
export const runtime_discard = "~lib/runtime/runtime.discard";
export const runtime_makeArray = "~lib/runtime/runtime.makeArray";
export const runtime_newArray = "~lib/runtime/runtime.newArray";
// std/gc.ts
export const gc_mark_roots = "~lib/gc/__gc_mark_roots";

View File

@ -184,5 +184,7 @@ export namespace CommonSymbols {
export const reallocate = "reallocate";
export const register = "register";
export const discard = "discard";
export const makeArray = "makeArray";
export const newString = "newString";
export const newArrayBuffer = "newArrayBuffer";
export const newArray = "newArray";
}

View File

@ -6944,13 +6944,13 @@ export class Compiler extends DiagnosticEmitter {
// otherwise allocate a new array header and make it wrap a copy of the static buffer
} else {
// makeArray(length, classId, alignLog2, staticBuffer)
let expr = this.makeCallDirect(assert(program.makeArrayInstance), [
// newArray(length, alignLog2, classId, staticBuffer)
let expr = this.makeCallDirect(assert(program.newArrayInstance), [
module.createI32(length),
module.createI32(arrayInstance.ensureId()),
program.options.isWasm64
? module.createI64(elementType.alignLog2)
: module.createI32(elementType.alignLog2),
module.createI32(arrayInstance.ensureId()),
program.options.isWasm64
? module.createI64(i64_low(bufferAddress), i64_high(bufferAddress))
: module.createI32(i64_low(bufferAddress))
@ -6974,17 +6974,17 @@ export class Compiler extends DiagnosticEmitter {
var flow = this.currentFlow;
var tempThis = flow.getTempLocal(arrayType, false);
var tempDataStart = flow.getTempLocal(arrayBufferInstance.type);
var makeArrayInstance = assert(program.makeArrayInstance);
var newArrayInstance = assert(program.newArrayInstance);
var stmts = new Array<ExpressionRef>();
// tempThis = makeArray(length, classId, alignLog2, source = 0)
// tempThis = newArray(length, alignLog2, classId, source = 0)
stmts.push(
module.createSetLocal(tempThis.index,
this.makeCallDirect(makeArrayInstance, [
this.makeCallDirect(newArrayInstance, [
module.createI32(length),
module.createI32(arrayInstance.ensureId()),
program.options.isWasm64
? module.createI64(elementType.alignLog2)
: module.createI32(elementType.alignLog2),
module.createI32(arrayInstance.ensureId()),
program.options.isWasm64
? module.createI64(0)
: module.createI32(0)

View File

@ -374,8 +374,8 @@ export class Program extends DiagnosticEmitter {
discardInstance: Function | null = null;
/** Runtime register function. `register(ref: usize, cid: u32): usize` */
registerInstance: Function | null = null;
/** Runtime make array function. `makeArray(capacity: i32, source: usize = 0, cid: u32): usize` */
makeArrayInstance: Function | null = null;
/** Runtime make array function. `newArray(length: i32, alignLog2: usize, id: u32, source: usize = 0): usize` */
newArrayInstance: Function | null = null;
/** The kind of garbage collector being present. */
collectorKind: CollectorKind = CollectorKind.NONE;
@ -844,9 +844,9 @@ export class Program extends DiagnosticEmitter {
assert(element.kind == ElementKind.FUNCTION_PROTOTYPE);
this.registerInstance = this.resolver.resolveFunction(<FunctionPrototype>element, null);
}
if (element = this.lookupGlobal(BuiltinSymbols.runtime_makeArray)) {
if (element = this.lookupGlobal(BuiltinSymbols.runtime_newArray)) {
assert(element.kind == ElementKind.FUNCTION_PROTOTYPE);
this.makeArrayInstance = this.resolver.resolveFunction(<FunctionPrototype>element, null);
this.newArrayInstance = this.resolver.resolveFunction(<FunctionPrototype>element, null);
}
// memory allocator interface
if (element = this.lookupGlobal("__mem_allocate")) {