Discussion
Loading...

Discussion

  • About
  • Code of conduct
  • Privacy
  • Users
  • Instances
  • About Bonfire
alcinnz
@alcinnz@floss.social  ·  activity timestamp 2 weeks ago
#include would read the named file & concatenate into the output string preceded by a #line directive. #embed would work similarly, but reformats the read bytes into hexadecimal literals.

#define would extract the identifier & parse the following optional argument list & body removing (escaped) newlines to load into a "macro" table.

Non-preprocessor lines would be scanned for these macros' identifiers to perform a find & replace, recursing to handle substitute in parameters.

2/3?

  • Copy link
  • Flag this post
  • Block
alcinnz
@alcinnz@floss.social replied  ·  activity timestamp 2 weeks ago

I'd track a stack of control-flow preprocessor lines tracking whether to keep or discard the lines between them, inserting #line where needed. This is how I'd handle #if, #elif, #else, #endif, #ifdef, #ifndef, #elifdef, #elifndef.

Some of these take identifiers whose presence it should check in the macros table, others would interpret infix expressions via a couple stacks & The Shunting Yard Algorithm. Or they simply end a control-flow block.

#undef removes an entry from the macros table.

3/4

  • Copy link
  • Flag this comment
  • Block
alcinnz
@alcinnz@floss.social replied  ·  activity timestamp 2 weeks ago
#warning or #error would append lines to secondary outputs. I don't know if I have anything for #pragma to do.

Specific to GLSL #version checks if our parser supports the given version. Whilst #extension checks whether our parser supports a given extension possibly enabling or disabling it, or complaining about its support or lack thereof. Depending on what's requested.

Funny thing about discussing the C, GLSL, etc preprocessor on the fediverse. Directives get confused for hashtags!

4/4 Fin!

  • Copy link
  • Flag this comment
  • Block
Log in

bonfire.cafe

A space for Bonfire maintainers and contributors to communicate

bonfire.cafe: About · Code of conduct · Privacy · Users · Instances
Bonfire social · 1.0.0-rc.2.21 no JS en
Automatic federation enabled
  • Explore
  • About
  • Members
  • Code of Conduct
Home
Login