diff --git a/generic.w b/generic.w new file mode 100644 index 0000000..eb25bd1 --- /dev/null +++ b/generic.w @@ -0,0 +1,13 @@ +struct Foo { + static Func(t: T): T { + return t; + } +} + +struct Program { + static main(): int { + x: int = 4; + y: int = Foo.Func(x); + return x; + } +} \ No newline at end of file diff --git a/src/ast.c b/src/ast.c index dde4693..a6809a6 100644 --- a/src/ast.c +++ b/src/ast.c @@ -39,6 +39,10 @@ const char *SyntaxKindString(SyntaxKind syntaxKind) return "FunctionSignature"; case FunctionSignatureArguments: return "FunctionSignatureArguments"; + case GenericArgument: + return "GenericArgument"; + case GenericArguments: + return "GenericArguments"; case Identifier: return "Identifier"; case IfStatement: @@ -599,6 +603,7 @@ void PrintNode(Node *node, uint32_t tabCount) case FunctionSignature: printf("\n"); PrintNode(node->functionSignature.identifier, tabCount + 1); + PrintNode(node->functionSignature.genericArguments, tabCount + 1); PrintNode(node->functionSignature.arguments, tabCount + 1); PrintNode(node->functionSignature.type, tabCount + 1); PrintNode(node->functionSignature.modifiers, tabCount + 1); @@ -614,6 +619,20 @@ void PrintNode(Node *node, uint32_t tabCount) } return; + case GenericArgument: + printf("\n"); + PrintNode(node->genericArgument.identifier, tabCount + 1); + /* Constraint nodes are not implemented. */ + /* PrintNode(node->genericArgument.constraint, tabCount + 1); */ + return; + + case GenericArguments: + printf("\n"); + for (i = 0; i < node->genericArguments.count; i += 1) { + PrintNode(node->genericArguments.arguments[i], tabCount + 1); + } + return; + case Identifier: if (node->typeTag == NULL) {