more type validation

interfaces
cosmonaut 2021-09-07 12:46:47 -07:00
parent f59be30791
commit 1a21618bee
3 changed files with 46 additions and 8 deletions

View File

@ -14,6 +14,15 @@ struct MemoryBlock<T>
start: MemoryAddress;
capacity: uint;
static Init(capacity: uint): MemoryBlock<T>
{
return MemoryBlock<T>
{
capacity: capacity,
start: @malloc(capacity * @sizeof<T>())
};
}
AddressOf(index: uint): MemoryAddress
{
return start + (index * @sizeof<T>());
@ -43,7 +52,7 @@ struct Array<T>
{
return Array<T>
{
memoryBlock: MemoryBlock<T> { capacity: capacity, start: @malloc(capacity * @sizeof<T>()) }
memoryBlock: MemoryBlock<T>.Init(capacity)
};
}
@ -58,12 +67,6 @@ struct Array<T>
}
}
interface Iterable<T>
{
HasNext(): bool;
Next(): T;
}
struct Program {
static Main(): int {
array: Array<int> = Array<int>.Init(4);

View File

@ -1395,7 +1395,7 @@ static LLVMValueRef CompileFunctionCallExpression(
&isStatic
);
//free(typeTag);
free(typeTag);
}
else
{

View File

@ -432,6 +432,41 @@ void ConvertCustomsToGenerics(Node *node)
switch (node->syntaxKind)
{
case Type:
{
Node *type = node->type.typeNode;
if (type->syntaxKind == CustomTypeNode)
{
char *target = type->customType.name;
Node *typeLookup = LookupType(node, target);
if (typeLookup != NULL &&
typeLookup->syntaxKind == GenericDeclaration)
{
node->typeTag->type = Generic;
free(node->declaration.type);
node->declaration.type =
MakeGenericTypeNode(node->typeTag->value.genericType);
}
}
else if (type->syntaxKind == ConcreteGenericTypeNode)
{
for (int32_t i = 0; i < node->typeTag->value.concreteGenericType.genericArgumentCount; i += 1)
{
if (node->typeTag->value.concreteGenericType.genericArguments[i]->type == Custom)
{
char *target = node->typeTag->value.concreteGenericType.genericArguments[i]->value.customType;
Node *typeLookup = LookupType(node, target);
if (typeLookup != NULL &&
typeLookup->syntaxKind == GenericDeclaration)
{
node->typeTag->value.concreteGenericType.genericArguments[i]->type = Generic;
}
}
}
}
break;
}
case Declaration:
{
Node *id = node->declaration.identifier;