mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 18:51:11 +01:00
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:
@@ -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>};
|
||||
|
||||
Reference in New Issue
Block a user