Skip to content

Conversation

@ivanaivanovska
Copy link
Contributor

@ivanaivanovska ivanaivanovska commented Nov 21, 2025

Adding support for macros with boolean literals.

Demo:

// main.carbon

library "Main";

import Core library "io";

import Cpp inline '''
  #define M_TRUE true
''';

fn Run() -> i32 {
  let a: bool = Cpp.M_TRUE;
  if (a) {
    Core.Print(1);
  } else {
    Core.Print(0);
  }
  return 0;
}
$ bazel-bin/toolchain/carbon compile main.carbon
$ bazel-bin/toolchain/carbon link main.o \--output=demo_carbon
$ ./demo_carbon
1

Part of #6303

@ivanaivanovska ivanaivanovska marked this pull request as ready for review November 21, 2025 14:59
@ivanaivanovska ivanaivanovska requested a review from a team as a code owner November 21, 2025 14:59
@ivanaivanovska ivanaivanovska requested review from danakj and removed request for a team November 21, 2025 14:59
Copy link
Contributor

@danakj danakj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Comment on lines +2272 to +2274
context, MakeImportedLocIdAndInst(
context, imported_loc_id,
SemIR::BoolLiteral{.type_id = type_id,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: We usually write the instruction type in the instruction-creating functions as an explicit template parameter. Why? Idk, I always have to move it to the {} when I have an error and need to see what it actually is. But I think clang-format does a nicer job with things that way, and by being consistent you can grep for <SemIR::SomeInstName to find where it's created.

Suggested change
context, MakeImportedLocIdAndInst(
context, imported_loc_id,
SemIR::BoolLiteral{.type_id = type_id,
context, MakeImportedLocIdAndInst<SemIR::BoolLiteral>(
context, imported_loc_id,
{.type_id = type_id,

Will probably need to reformat after

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants