more type validation
parent
f59be30791
commit
1a21618bee
17
generic.w
17
generic.w
|
@ -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);
|
||||
|
|
|
@ -1395,7 +1395,7 @@ static LLVMValueRef CompileFunctionCallExpression(
|
|||
&isStatic
|
||||
);
|
||||
|
||||
//free(typeTag);
|
||||
free(typeTag);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue