Initial ArrayBuffer implementation; Conditional allocation within constructors; Explicit constructor return values

This commit is contained in:
dcodeIO
2018-03-23 01:47:01 +01:00
parent 8cfc479cc0
commit 9cc0fcd611
18 changed files with 6285 additions and 176 deletions

View File

@ -2462,44 +2462,46 @@ const allocateInternalName = "allocate_memory";
/** Compiles a memory allocation for an instance of the specified class. */
export function compileAllocate(
compiler: Compiler,
cls: Class,
classInstance: Class,
reportNode: Node
): ExpressionRef {
var program = compiler.program;
assert(cls.program == program);
assert(classInstance.program == program);
var module = compiler.module;
var options = compiler.options;
var prototype = program.elementsLookup.get(allocateInternalName);
if (!prototype) {
var allocatePrototype = program.elementsLookup.get(allocateInternalName);
if (!allocatePrototype) {
program.error(
DiagnosticCode.Cannot_find_name_0,
reportNode.range, allocateInternalName
);
return module.createUnreachable();
}
if (prototype.kind != ElementKind.FUNCTION_PROTOTYPE) {
if (allocatePrototype.kind != ElementKind.FUNCTION_PROTOTYPE) {
program.error(
DiagnosticCode.Cannot_invoke_an_expression_whose_type_lacks_a_call_signature_Type_0_has_no_compatible_call_signatures,
reportNode.range, prototype.internalName
reportNode.range, allocatePrototype.internalName
);
return module.createUnreachable();
}
var instance = (<FunctionPrototype>prototype).resolve(); // reports
if (!(instance && compiler.compileFunction(instance))) return module.createUnreachable();
var allocateInstance = (<FunctionPrototype>allocatePrototype).resolve(); // reports
if (!(allocateInstance && compiler.compileFunction(allocateInstance))) return module.createUnreachable();
compiler.currentType = cls.type;
compiler.currentType = classInstance.type;
return module.createCall(
instance.internalName, [
allocateInstance.internalName, [
options.isWasm64
? module.createI64(cls.currentMemoryOffset)
: module.createI32(cls.currentMemoryOffset)
? module.createI64(classInstance.currentMemoryOffset)
: module.createI32(classInstance.currentMemoryOffset)
],
options.nativeSizeType
);
}
const abortInternalName = "abort";
/** Compiles an abort wired to the conditionally imported 'abort' function. */
export function compileAbort(
compiler: Compiler,
@ -2512,7 +2514,7 @@ export function compileAbort(
var stringType = program.typesLookup.get("string"); // might be intended
if (!stringType) return module.createUnreachable();
var abortPrototype = program.elementsLookup.get("abort"); // might be intended
var abortPrototype = program.elementsLookup.get(abortInternalName); // might be intended
if (!abortPrototype || abortPrototype.kind != ElementKind.FUNCTION_PROTOTYPE) return module.createUnreachable();
var abortInstance = (<FunctionPrototype>abortPrototype).resolve(); // reports