mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-06-22 19:21:47 +00:00
Fix compilation of immediate called function expressions
This commit is contained in:
@ -31,6 +31,7 @@ import {
|
||||
Field,
|
||||
FunctionPrototype,
|
||||
Function,
|
||||
FunctionTarget,
|
||||
Global,
|
||||
Local,
|
||||
Namespace,
|
||||
@ -3876,8 +3877,9 @@ export class Compiler extends DiagnosticEmitter {
|
||||
}
|
||||
}
|
||||
case ElementKind.FIELD: {
|
||||
if (signature = (<Field>element).type.functionType) {
|
||||
let targetExpr = this.compileExpression(assert(resolved.targetExpression), Type.u32);
|
||||
let type = (<Field>element).type;
|
||||
if (signature = type.functionType) {
|
||||
let targetExpr = this.compileExpression(assert(resolved.targetExpression), type);
|
||||
indexArg = this.module.createLoad(
|
||||
4,
|
||||
false,
|
||||
@ -3894,9 +3896,12 @@ export class Compiler extends DiagnosticEmitter {
|
||||
return this.module.createUnreachable();
|
||||
}
|
||||
}
|
||||
case ElementKind.PROPERTY: {
|
||||
// TODO
|
||||
case ElementKind.FUNCTION_TARGET: {
|
||||
signature = (<FunctionTarget>element).signature;
|
||||
indexArg = this.compileExpression(expression.expression, (<FunctionTarget>element).type);
|
||||
break;
|
||||
}
|
||||
case ElementKind.PROPERTY: // TODO
|
||||
|
||||
// not supported
|
||||
default: {
|
||||
|
@ -1774,10 +1774,15 @@ export class Program extends DiagnosticEmitter {
|
||||
if (!resolvedElement) resolvedElement = new ResolvedElement();
|
||||
return resolvedElement.set(classType);
|
||||
} else {
|
||||
let functionType = returnType.functionType;
|
||||
if (functionType) {
|
||||
// TODO: Signatures aren't elements but probably should be
|
||||
throw new Error("not implemented");
|
||||
let signature = returnType.functionType;
|
||||
if (signature) {
|
||||
let functionTarget = signature.cachedFunctionTarget;
|
||||
if (!functionTarget) {
|
||||
functionTarget = new FunctionTarget(this, signature);
|
||||
signature.cachedFunctionTarget = functionTarget;
|
||||
}
|
||||
if (!resolvedElement) resolvedElement = new ResolvedElement();
|
||||
return resolvedElement.set(functionTarget);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1846,6 +1851,8 @@ export enum ElementKind {
|
||||
FUNCTION_PROTOTYPE,
|
||||
/** A {@link Function}. */
|
||||
FUNCTION,
|
||||
/** A {@link FunctionTarget}. */
|
||||
FUNCTION_TARGET,
|
||||
/** A {@link ClassPrototype}. */
|
||||
CLASS_PROTOTYPE,
|
||||
/** A {@link Class}. */
|
||||
@ -2671,6 +2678,27 @@ export class Function extends Element {
|
||||
toString(): string { return this.prototype.simpleName; }
|
||||
}
|
||||
|
||||
/** A resolved function table entry, that is an function called by an index and signature. */
|
||||
export class FunctionTarget extends Element {
|
||||
|
||||
kind = ElementKind.FUNCTION_TARGET;
|
||||
|
||||
/** Underlying signature. */
|
||||
signature: Signature;
|
||||
/** Function type. */
|
||||
type: Type;
|
||||
|
||||
/** Constructs a new function target. */
|
||||
constructor(program: Program, signature: Signature) {
|
||||
super(program, "", "");
|
||||
var simpleName = signature.toSignatureString();
|
||||
this.simpleName = simpleName;
|
||||
this.internalName = simpleName;
|
||||
this.signature = signature;
|
||||
this.type = Type.u32.asFunction(signature);
|
||||
}
|
||||
}
|
||||
|
||||
/** A yet unresolved instance field prototype. */
|
||||
export class FieldPrototype extends Element {
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
import {
|
||||
Class
|
||||
Class,
|
||||
FunctionTarget
|
||||
} from "./program";
|
||||
|
||||
import {
|
||||
@ -452,6 +453,8 @@ export class Signature {
|
||||
thisType: Type | null;
|
||||
/** Whether the last parameter is a rest parameter. */
|
||||
hasRest: bool;
|
||||
/** Cached {@link FunctionTarget}. */
|
||||
cachedFunctionTarget: FunctionTarget | null = null;
|
||||
|
||||
constructor(
|
||||
parameterTypes: Type[] | null = null,
|
||||
|
Reference in New Issue
Block a user