mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Add a basic Core.Print function for ints. (#4078)
We'd been discussing that explorer remains necessary for print, and I was wondering if this kind of approach would be okay (we _probably_ want this to work, based on #2110, albeit with more overloads -- but I don't think there's a good way to support overloads at the moment). ``` ╚╡../bazel-bin/examples/sieve 2 3 5 7 11 13 17 19 23 29 31 37 41 43 ... ```
This commit is contained in:
@@ -60,6 +60,18 @@ struct BuiltinType {
|
||||
}
|
||||
};
|
||||
|
||||
// Constraint that the function has no return.
|
||||
struct NoReturn {
|
||||
static auto Check(const File& sem_ir, ValidateState& /*state*/,
|
||||
TypeId type_id) -> bool {
|
||||
auto tuple = sem_ir.types().TryGetAs<SemIR::TupleType>(type_id);
|
||||
if (!tuple) {
|
||||
return false;
|
||||
}
|
||||
return sem_ir.type_blocks().Get(tuple->elements_id).empty();
|
||||
}
|
||||
};
|
||||
|
||||
// Constraint that a type is `bool`.
|
||||
using Bool = BuiltinType<InstId::BuiltinBoolType>;
|
||||
|
||||
@@ -157,6 +169,10 @@ using FloatT = TypeParam<0, AnyFloat>;
|
||||
// Not a builtin function.
|
||||
constexpr BuiltinInfo None = {"", nullptr};
|
||||
|
||||
// Prints an argument.
|
||||
constexpr BuiltinInfo PrintInt = {"print.int",
|
||||
ValidateSignature<auto(AnyInt)->NoReturn>};
|
||||
|
||||
// Returns the `i32` type. Doesn't take a bit size because we need an integer
|
||||
// type as a basis for that.
|
||||
constexpr BuiltinInfo IntMakeType32 = {"int.make_type_32",
|
||||
|
||||
Reference in New Issue
Block a user