Add solutions for advent of code 2024 day 1 to examples/. (#4673)

In order to support these examples, this adds two new builtins to the
toolchain: `print.char` and `read.char`, which map to the libc functions
`putchar` and `getchar`.
This commit is contained in:
Richard Smith
2024-12-17 00:47:51 +00:00
committed by GitHub
parent b25117b508
commit 3645143e27
20 changed files with 620 additions and 80 deletions
+11 -2
View File
@@ -63,7 +63,8 @@ struct BuiltinType {
}
};
// Constraint that the function has no return.
// Constraint that a type is `()`, used as the return type of builtin functions
// with no return value.
struct NoReturn {
static auto Check(const File& sem_ir, ValidateState& /*state*/,
TypeId type_id) -> bool {
@@ -194,10 +195,18 @@ using FloatT = TypeParam<0, AnyFloat>;
// Not a builtin function.
constexpr BuiltinInfo None = {"", nullptr};
// Prints an argument.
// Prints a single character.
constexpr BuiltinInfo PrintChar = {"print.char",
ValidateSignature<auto(AnyInt)->AnyInt>};
// Prints an integer.
constexpr BuiltinInfo PrintInt = {"print.int",
ValidateSignature<auto(AnyInt)->NoReturn>};
// Reads a single character from stdin.
constexpr BuiltinInfo ReadChar = {"read.char",
ValidateSignature<auto()->AnyInt>};
// Returns the `Core.IntLiteral` type.
constexpr BuiltinInfo IntLiteralMakeType = {"int_literal.make_type",
ValidateSignature<auto()->Type>};