From 71e5e4268316374f81d9cb21f859dd9f45786315 Mon Sep 17 00:00:00 2001 From: FeepingCreature Date: Wed, 3 Jan 2024 06:49:28 +0100 Subject: [PATCH] Allow declaring vector type with arbitrary symbol for size so long as it ends up as an IntLiteral. --- src/neat/stuff.nt | 9 +++------ src/neat/vectors.nt | 7 ++++++- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/neat/stuff.nt b/src/neat/stuff.nt index 3cad789..c66bfc6 100644 --- a/src/neat/stuff.nt +++ b/src/neat/stuff.nt @@ -309,14 +309,11 @@ with (parser.transaction) auto element = lexicalContext.compiler.parseType(parser, lexicalContext)?? else return parser.fail("element type expected"); parser.expectToken(TokenType.comma)?; - auto count = lexicalContext.compiler.parseExpression(parser, lexicalContext)?; - parser.assert_(count && count.instanceOf(ASTNumberLiteral), "number expected")?; + auto count = lexicalContext.compiler.parseExpression(parser, lexicalContext)? + .(that? else return parser.fail("number expected")); parser.expectToken(TokenType.rparen)?; commit; - return new ASTVectorType( - element, - cast(int) count.instanceOf(ASTNumberLiteral).value, - parser.to(from)); + return new ASTVectorType(element, count, parser.to(from)); } if (parser.acceptIdentifier("typeof")) diff --git a/src/neat/vectors.nt b/src/neat/vectors.nt index 78e37c9..deeee8b 100644 --- a/src/neat/vectors.nt +++ b/src/neat/vectors.nt @@ -15,12 +15,17 @@ class ASTVectorType : ASTSymbol { ASTSymbol elementType; - int count; + ASTSymbol count; this(this.elementType, this.count, this.locRange=__CALLER__) { } override (Type | Error) compile(Context context) { + auto count = this.count.compile(context)? + .beExpression(this.locRange)? + .instanceOf(IntLiteral) + .(that? else return locRange.fail("number expected")) + .value; return new VectorType( this.elementType.compile(context)?.beType(this.locRange)?, count); }