mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-06-20 02:11:31 +00:00
more general gc hooks?
This commit is contained in:
@ -4287,13 +4287,12 @@ export function compileBuiltinArraySetWithValue(
|
||||
}
|
||||
}
|
||||
|
||||
// handle Array<Ref>: value = LINK<T, TArray>(value, this)
|
||||
// handle Array<Ref>: value = RETAIN<T, TArray>(value, this)
|
||||
if (isManaged) {
|
||||
let program = compiler.program;
|
||||
let linkPrototype = assert(program.linkPrototype);
|
||||
let linkInstance = compiler.resolver.resolveFunction(linkPrototype, [ type, target.type ]);
|
||||
if (!linkInstance) return module.createUnreachable();
|
||||
valueExpr = compiler.makeCallInlinePrechecked(linkInstance, [
|
||||
let retainInstance = compiler.resolver.resolveFunction(assert(program.retainPrototype), [ type, target.type ]);
|
||||
if (!retainInstance) return module.createUnreachable();
|
||||
valueExpr = compiler.makeCallInlinePrechecked(retainInstance, [
|
||||
valueExpr,
|
||||
module.createGetLocal(assert(tempThis).index, nativeSizeType)
|
||||
], 0, true);
|
||||
|
@ -187,7 +187,8 @@ export namespace LibrarySymbols {
|
||||
export const REALLOCATE = "REALLOCATE";
|
||||
export const DISCARD = "DISCARD";
|
||||
export const REGISTER = "REGISTER";
|
||||
export const LINK = "LINK";
|
||||
export const RETAIN = "RETAIN";
|
||||
export const RELEASE = "RELEASE";
|
||||
export const WRAPARRAY = "WRAPARRAY";
|
||||
// other
|
||||
export const length = "length";
|
||||
|
@ -4870,16 +4870,16 @@ export class Compiler extends DiagnosticEmitter {
|
||||
let program = this.program;
|
||||
let tempThis: Local | null = null;
|
||||
if (type.isManaged(program) && thisType.isManaged(program)) {
|
||||
let linkInstance = this.resolver.resolveFunction(assert(program.linkPrototype), [ type, thisType ]);
|
||||
if (!linkInstance) {
|
||||
let retainInstance = this.resolver.resolveFunction(assert(program.retainPrototype), [ type, thisType ]);
|
||||
if (!retainInstance) {
|
||||
this.currentType = tee ? type : Type.void;
|
||||
return module.createUnreachable();
|
||||
}
|
||||
tempThis = this.currentFlow.getTempLocal(thisType, false);
|
||||
// this = (tempThis = this)
|
||||
thisExpr = module.createTeeLocal(tempThis.index, thisExpr);
|
||||
// value = LINK(value, tempThis)
|
||||
valueWithCorrectType = this.makeCallInlinePrechecked(linkInstance, [
|
||||
// value = RETAIN(value, tempThis)
|
||||
valueWithCorrectType = this.makeCallInlinePrechecked(retainInstance, [
|
||||
valueWithCorrectType,
|
||||
module.createGetLocal(tempThis.index, this.options.nativeSizeType)
|
||||
], 0, true);
|
||||
@ -6795,8 +6795,8 @@ export class Compiler extends DiagnosticEmitter {
|
||||
)
|
||||
);
|
||||
var isManaged = elementType.isManaged(program) && arrayType.isManaged(program);
|
||||
var linkInstance = isManaged
|
||||
? this.resolver.resolveFunction(assert(program.linkPrototype), [ elementType, arrayType ])
|
||||
var retainInstance = isManaged
|
||||
? this.resolver.resolveFunction(assert(program.retainPrototype), [ elementType, arrayType ])
|
||||
: null;
|
||||
for (let i = 0, alignLog2 = elementType.alignLog2; i < length; ++i) {
|
||||
let valueExpression = expressions[i];
|
||||
@ -6804,11 +6804,11 @@ export class Compiler extends DiagnosticEmitter {
|
||||
? this.compileExpression(valueExpression, elementType, ConversionKind.IMPLICIT, WrapMode.NONE)
|
||||
: elementType.toNativeZero(module);
|
||||
if (isManaged) {
|
||||
if (!linkInstance) {
|
||||
if (!retainInstance) {
|
||||
valueExpr = module.createUnreachable();
|
||||
} else {
|
||||
// value = LINK(value, tempThis)
|
||||
valueExpr = this.makeCallInlinePrechecked(linkInstance, [
|
||||
// value = RETAIN(value, tempThis)
|
||||
valueExpr = this.makeCallInlinePrechecked(retainInstance, [
|
||||
valueExpr,
|
||||
module.createGetLocal(tempThis.index, nativeArrayType)
|
||||
], 0, true);
|
||||
|
@ -364,8 +364,10 @@ export class Program extends DiagnosticEmitter {
|
||||
discardInstance: Function | null = null;
|
||||
/** Runtime register function. */
|
||||
registerPrototype: FunctionPrototype | null = null;
|
||||
/** Runtime link function. */
|
||||
linkPrototype: FunctionPrototype | null = null;
|
||||
/** Runtime retain function. */
|
||||
retainPrototype: FunctionPrototype | null = null;
|
||||
/** Runtime release function. */
|
||||
releasePrototype: FunctionPrototype | null = null;
|
||||
/** Runtime wrap array function. */
|
||||
wrapArrayPrototype: FunctionPrototype | null = null;
|
||||
|
||||
@ -828,9 +830,13 @@ export class Program extends DiagnosticEmitter {
|
||||
assert(element.kind == ElementKind.FUNCTION_PROTOTYPE);
|
||||
this.registerPrototype = <FunctionPrototype>element;
|
||||
}
|
||||
if (element = this.lookupGlobal(LibrarySymbols.LINK)) {
|
||||
if (element = this.lookupGlobal(LibrarySymbols.RETAIN)) {
|
||||
assert(element.kind == ElementKind.FUNCTION_PROTOTYPE);
|
||||
this.linkPrototype = <FunctionPrototype>element;
|
||||
this.retainPrototype = <FunctionPrototype>element;
|
||||
}
|
||||
if (element = this.lookupGlobal(LibrarySymbols.RELEASE)) {
|
||||
assert(element.kind == ElementKind.FUNCTION_PROTOTYPE);
|
||||
this.releasePrototype = <FunctionPrototype>element;
|
||||
}
|
||||
if (element = this.lookupGlobal(LibrarySymbols.WRAPARRAY)) {
|
||||
assert(element.kind == ElementKind.FUNCTION_PROTOTYPE);
|
||||
|
Reference in New Issue
Block a user