Add float to int builtin

This commit is contained in:
nub31
2025-09-28 22:48:32 +02:00
parent a2bdf47f5d
commit c489f23c41
6 changed files with 111 additions and 15 deletions

View File

@@ -461,7 +461,7 @@ public sealed class Parser
Symbol.OpenBracket => ParseArrayInitializer(startIndex),
Symbol.OpenBrace => new StructInitializerSyntax(GetTokens(startIndex), null, ParseStructInitializerBody()),
Symbol.Struct => ParseStructInitializer(startIndex),
Symbol.At => ParseCompilerMacro(startIndex),
Symbol.At => ParseBuiltinFunction(startIndex),
_ => throw new ParseException(Diagnostic
.Error($"Unexpected symbol '{symbolToken.Symbol}' in expression")
.WithHelp("Expected '(', '-', '!', '[' or '{'")
@@ -478,7 +478,7 @@ public sealed class Parser
return ParsePostfixOperators(expr);
}
private ExpressionSyntax ParseCompilerMacro(int startIndex)
private ExpressionSyntax ParseBuiltinFunction(int startIndex)
{
var name = ExpectIdentifier();
ExpectSymbol(Symbol.OpenParen);
@@ -489,7 +489,7 @@ public sealed class Parser
{
var type = ParseType();
ExpectSymbol(Symbol.CloseParen);
return new SizeCompilerMacroSyntax(GetTokens(startIndex), type);
return new SizeBuiltinSyntax(GetTokens(startIndex), type);
}
case "interpret":
{
@@ -497,11 +497,19 @@ public sealed class Parser
ExpectSymbol(Symbol.Comma);
var expression = ParseExpression();
ExpectSymbol(Symbol.CloseParen);
return new InterpretCompilerMacroSyntax(GetTokens(startIndex), type, expression);
return new InterpretBuiltinSyntax(GetTokens(startIndex), type, expression);
}
case "floatToInt":
{
var type = ParseType();
ExpectSymbol(Symbol.Comma);
var expression = ParseExpression();
ExpectSymbol(Symbol.CloseParen);
return new FloatToIntBuiltinSyntax(GetTokens(startIndex), type, expression);
}
default:
{
throw new ParseException(Diagnostic.Error("Unknown compiler macro").At(name).Build());
throw new ParseException(Diagnostic.Error($"Unknown builtin {name.Value}").At(name).Build());
}
}
}