remove old traversal code

This commit is contained in:
dcode
2019-04-02 16:46:28 +02:00
parent e1bd0050e2
commit d85a43892f

View File

@ -8344,134 +8344,6 @@ export class Compiler extends DiagnosticEmitter {
flow.popBreakLabel();
return module.createBlock(label, conditions, NativeType.I32);
}
/** Reserves the function index / class id for the following `makeTraverse` operation. */
makeTraverseReserve(classInstance: Class): u32 {
var functionTable = this.functionTable;
var functionIndex = functionTable.length;
functionTable.push(classInstance.internalName + "~traverse");
return functionIndex;
}
/** Makes the managed traversal function of the specified class. */
makeTraverse(classInstance: Class, functionIndex: i32): void {
var program = this.program;
assert(classInstance.type.isManaged(program));
// check if the class implements a custom iteration function (only valid for library elements)
var members = classInstance.members;
if (classInstance.isDeclaredInLibrary) {
if (members !== null && members.has("__traverse")) {
let iterPrototype = members.get("__traverse")!;
assert(iterPrototype.kind == ElementKind.FUNCTION_PROTOTYPE);
let iterInstance = assert(program.resolver.resolveFunction(<FunctionPrototype>iterPrototype, null));
assert(iterInstance.is(CommonFlags.PRIVATE | CommonFlags.INSTANCE));
assert(iterInstance.hasDecorator(DecoratorFlags.UNSAFE));
assert(!iterInstance.isAny(CommonFlags.AMBIENT | CommonFlags.VIRTUAL));
let signature = iterInstance.signature;
let parameterTypes = signature.parameterTypes;
assert(parameterTypes.length == 0);
assert(signature.returnType == Type.void);
iterInstance.internalName = classInstance.internalName + "~traverse";
assert(this.compileFunction(iterInstance));
this.ensureFunctionTableEntry(iterInstance);
return;
}
}
var module = this.module;
var options = this.options;
var usizeType = options.usizeType;
var nativeSizeType = options.nativeSizeType;
var nativeSizeSize = options.usizeType.byteSize;
var body = new Array<ExpressionRef>();
// nothing to mark if 'this' is null (should not happen)
// body.push(
// module.createIf(
// module.createUnary(
// options.isWasm64
// ? UnaryOp.EqzI64
// : UnaryOp.EqzI32,
// module.createGetLocal(0, nativeSizeType)
// ),
// module.createReturn()
// )
// );
// remember the function index so we don't recurse infinitely
var functionTable = this.functionTable;
var functionName = classInstance.internalName + "~traverse";
assert(functionIndex < functionTable.length);
assert(functionTable[functionIndex] == functionName);
// if the class extends a base class, call its hook first
var baseInstance = classInstance.base;
if (baseInstance) {
let baseType = baseInstance.type;
let baseClassId = baseInstance.ensureId();
assert(baseType.isManaged(program));
body.push(
// BASECLASS~traverse.call(this)
module.createCall(functionTable[baseClassId], [
module.createGetLocal(0, nativeSizeType)
], NativeType.None)
);
}
var markRef = assert(program.markRef);
var hasRefFields = false;
// traverse references assigned to own fields
if (members) {
for (let member of members.values()) {
if (member.kind == ElementKind.FIELD) {
if ((<Field>member).parent === classInstance) {
let fieldType = (<Field>member).type;
if (fieldType.isManaged(program)) {
let fieldClass = fieldType.classReference!;
let fieldClassId = fieldClass.ensureId();
let fieldOffset = (<Field>member).memoryOffset;
assert(fieldOffset >= 0);
hasRefFields = true;
body.push(
// if ($1 = value) FIELDCLASS~traverse($1)
module.createIf(
module.createTeeLocal(1,
module.createLoad(
nativeSizeSize,
false,
module.createGetLocal(0, nativeSizeType),
nativeSizeType,
fieldOffset
)
),
module.createBlock(null, [
module.createCall(markRef.internalName, [
module.createGetLocal(1, nativeSizeType)
], NativeType.None),
module.createCall(functionTable[fieldClassId], [
module.createGetLocal(1, nativeSizeType)
], NativeType.None)
])
)
);
}
}
}
}
}
if (hasRefFields) this.compileFunction(markRef);
// add the function to the module and return its table index
module.addFunction(
functionName,
this.ensureFunctionType(null, Type.void, options.usizeType),
members ? [ nativeSizeType ] : null,
module.createBlock(null, body)
);
}
}
// helpers