Skip to content

Commit

Permalink
Allow declaring vector type with arbitrary symbol for size so long as…
Browse files Browse the repository at this point in the history
… it ends up as an IntLiteral.
  • Loading branch information
FeepingCreature committed Jan 3, 2024
1 parent 494ab2d commit 71e5e42
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
9 changes: 3 additions & 6 deletions src/neat/stuff.nt
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
7 changes: 6 additions & 1 deletion src/neat/vectors.nt
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 71e5e42

Please sign in to comment.