forked from cosmonaut/wraith-lang
skeleton of generic function lookup
parent
24bcef6d87
commit
0d94e89045
|
@ -411,9 +411,22 @@ static LLVMTypeRef ResolveType(Node *typeNode)
|
|||
}
|
||||
}
|
||||
|
||||
static LLVMValueRef LookupGenericFunction(
|
||||
StructTypeGenericFunction *genericFunction,
|
||||
TypeTag **genericArgumentTypes,
|
||||
uint32_t genericArgumentTypeCount,
|
||||
LLVMTypeRef *pReturnType,
|
||||
uint8_t *pStatic)
|
||||
{
|
||||
/* TODO: hash the argument types */
|
||||
/* TODO: compile the monomorphism if doesnt exist */
|
||||
}
|
||||
|
||||
static LLVMValueRef LookupFunctionByType(
|
||||
LLVMTypeRef structType,
|
||||
char *name,
|
||||
TypeTag **genericArgumentTypes,
|
||||
uint32_t genericArgumentTypeCount,
|
||||
LLVMTypeRef *pReturnType,
|
||||
uint8_t *pStatic)
|
||||
{
|
||||
|
@ -434,6 +447,22 @@ static LLVMValueRef LookupFunctionByType(
|
|||
return structTypeDeclarations[i].functions[j].function;
|
||||
}
|
||||
}
|
||||
|
||||
for (j = 0; j < structTypeDeclarations[i].genericFunctionCount;
|
||||
j += 1)
|
||||
{
|
||||
if (strcmp(
|
||||
structTypeDeclarations[i].genericFunctions[j].name,
|
||||
name) == 0)
|
||||
{
|
||||
return LookupGenericFunction(
|
||||
&structTypeDeclarations[i].genericFunctions[j],
|
||||
genericArgumentTypes,
|
||||
genericArgumentTypeCount,
|
||||
pReturnType,
|
||||
pStatic);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -444,6 +473,8 @@ static LLVMValueRef LookupFunctionByType(
|
|||
static LLVMValueRef LookupFunctionByPointerType(
|
||||
LLVMTypeRef structPointerType,
|
||||
char *name,
|
||||
TypeTag **genericArgumentTypes,
|
||||
uint32_t genericArgumentTypeCount,
|
||||
LLVMTypeRef *pReturnType,
|
||||
uint8_t *pStatic)
|
||||
{
|
||||
|
@ -464,6 +495,22 @@ static LLVMValueRef LookupFunctionByPointerType(
|
|||
return structTypeDeclarations[i].functions[j].function;
|
||||
}
|
||||
}
|
||||
|
||||
for (j = 0; j < structTypeDeclarations[i].genericFunctionCount;
|
||||
j += 1)
|
||||
{
|
||||
if (strcmp(
|
||||
structTypeDeclarations[i].genericFunctions[j].name,
|
||||
name) == 0)
|
||||
{
|
||||
return LookupGenericFunction(
|
||||
&structTypeDeclarations[i].genericFunctions[j],
|
||||
genericArgumentTypes,
|
||||
genericArgumentTypeCount,
|
||||
pReturnType,
|
||||
pStatic);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -474,12 +521,16 @@ static LLVMValueRef LookupFunctionByPointerType(
|
|||
static LLVMValueRef LookupFunctionByInstance(
|
||||
LLVMValueRef structPointer,
|
||||
char *name,
|
||||
TypeTag **genericArgumentTypes,
|
||||
uint32_t genericArgumentTypeCount,
|
||||
LLVMTypeRef *pReturnType,
|
||||
uint8_t *pStatic)
|
||||
{
|
||||
return LookupFunctionByPointerType(
|
||||
LLVMTypeOf(structPointer),
|
||||
name,
|
||||
genericArgumentTypes,
|
||||
genericArgumentTypeCount,
|
||||
pReturnType,
|
||||
pStatic);
|
||||
}
|
||||
|
@ -591,16 +642,37 @@ static LLVMValueRef CompileFunctionCallExpression(
|
|||
{
|
||||
uint32_t i;
|
||||
uint32_t argumentCount = 0;
|
||||
uint32_t genericArgumentCount = 0;
|
||||
LLVMValueRef args
|
||||
[functionCallExpression->functionCallExpression.argumentSequence
|
||||
->functionArgumentSequence.count +
|
||||
1];
|
||||
TypeTag *genericArgumentTypes[functionCallExpression->functionCallExpression
|
||||
.argumentSequence
|
||||
->functionArgumentSequence.count];
|
||||
LLVMValueRef function;
|
||||
uint8_t isStatic;
|
||||
LLVMValueRef structInstance;
|
||||
LLVMTypeRef functionReturnType;
|
||||
char *returnName = "";
|
||||
|
||||
for (i = 0; i < functionCallExpression->functionCallExpression
|
||||
.argumentSequence->functionArgumentSequence.count;
|
||||
i += 1)
|
||||
{
|
||||
if (functionCallExpression->functionCallExpression.argumentSequence
|
||||
->functionArgumentSequence.sequence[i]
|
||||
->syntaxKind == GenericArgument)
|
||||
{
|
||||
genericArgumentTypes[genericArgumentCount] =
|
||||
functionCallExpression->functionCallExpression.argumentSequence
|
||||
->functionArgumentSequence.sequence[i]
|
||||
->typeTag;
|
||||
|
||||
genericArgumentCount += 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* FIXME: this needs to be recursive on access chains */
|
||||
/* FIXME: this needs to be able to call same-struct functions implicitly */
|
||||
if (functionCallExpression->functionCallExpression.identifier->syntaxKind ==
|
||||
|
@ -616,6 +688,8 @@ static LLVMValueRef CompileFunctionCallExpression(
|
|||
typeReference,
|
||||
functionCallExpression->functionCallExpression.identifier
|
||||
->accessExpression.accessor->identifier.name,
|
||||
genericArgumentTypes,
|
||||
genericArgumentCount,
|
||||
&functionReturnType,
|
||||
&isStatic);
|
||||
}
|
||||
|
@ -628,6 +702,8 @@ static LLVMValueRef CompileFunctionCallExpression(
|
|||
structInstance,
|
||||
functionCallExpression->functionCallExpression.identifier
|
||||
->accessExpression.accessor->identifier.name,
|
||||
genericArgumentTypes,
|
||||
genericArgumentCount,
|
||||
&functionReturnType,
|
||||
&isStatic);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue