Skip to content

Commit 2131c51

Browse files
authored
Rework constructor handling (#446)
1 parent 75328f3 commit 2131c51

30 files changed

+3276
-2777
lines changed

src/builtins.ts

-52
Original file line numberDiff line numberDiff line change
@@ -2933,58 +2933,6 @@ function evaluateConstantOffset(compiler: Compiler, expression: Expression): i32
29332933
return value;
29342934
}
29352935

2936-
/** Compiles a memory allocation for an instance of the specified class. */
2937-
export function compileAllocate(
2938-
compiler: Compiler,
2939-
classInstance: Class,
2940-
reportNode: Node
2941-
): ExpressionRef {
2942-
var program = compiler.program;
2943-
assert(classInstance.program == program);
2944-
var module = compiler.module;
2945-
var options = compiler.options;
2946-
2947-
// __gc_allocate(size, markFn)
2948-
if (program.hasGC && classInstance.type.isManaged(program)) {
2949-
let allocateInstance = assert(program.gcAllocateInstance);
2950-
if (!compiler.compileFunction(allocateInstance)) return module.createUnreachable();
2951-
compiler.currentType = classInstance.type;
2952-
return module.createCall(
2953-
allocateInstance.internalName, [
2954-
options.isWasm64
2955-
? module.createI64(classInstance.currentMemoryOffset)
2956-
: module.createI32(classInstance.currentMemoryOffset),
2957-
module.createI32(
2958-
ensureGCHook(compiler, classInstance)
2959-
)
2960-
],
2961-
options.nativeSizeType
2962-
);
2963-
2964-
// memory.allocate(size)
2965-
} else {
2966-
let allocateInstance = program.memoryAllocateInstance;
2967-
if (!allocateInstance) {
2968-
program.error(
2969-
DiagnosticCode.Cannot_find_name_0,
2970-
reportNode.range, "memory.allocate"
2971-
);
2972-
return module.createUnreachable();
2973-
}
2974-
if (!compiler.compileFunction(allocateInstance)) return module.createUnreachable();
2975-
2976-
compiler.currentType = classInstance.type;
2977-
return module.createCall(
2978-
allocateInstance.internalName, [
2979-
options.isWasm64
2980-
? module.createI64(classInstance.currentMemoryOffset)
2981-
: module.createI32(classInstance.currentMemoryOffset)
2982-
],
2983-
options.nativeSizeType
2984-
);
2985-
}
2986-
}
2987-
29882936
/** Compiles an abort wired to the conditionally imported 'abort' function. */
29892937
export function compileAbort(
29902938
compiler: Compiler,

0 commit comments

Comments
 (0)