Giter VIP home page Giter VIP logo

Comments (4)

Blub avatar Blub commented on August 19, 2024

Might be good do note that when they are AST macros and you don't actually use a {{{body}}} in there, then the following will NOT work:

macro for_stuff(n) { for (float i = 0; i < n; ++i) }
// used as
for_stuff(5) {
    print("Foo\n");
}

because parsing the macro definition itself will give you a parse error about a missing body for the for loop in it.

The nice part about ast macros is that a lot of checking (specifically syntax within the macro definition) will happen while parsing the macro definition, so if there's a syntax error it'll be shown in there. While with the preprocessor macros you'll end up getting an error at each use of the macro, and with huge macros it's hard to find the actual point of failure. Plus, there'll be syntax checking at the macro's use for the actual parameters directly.

It may be good to have the possibility to request a specific type in a macro parameter though. So that for instance the macro can create a counter variable accessible in the body by taking a variable-name as parameter. Note that in the above macro, the i will not be accessible if we have hygienic macros!

from gmqcc.

Blub avatar Blub commented on August 19, 2024

Implementation wise we'd need to add copy-ctors to ast nodes. Which are also required for inlining.
So I'm referencing #35 here.

from gmqcc.

divVerent avatar divVerent commented on August 19, 2024

I would also like AST macros to return values (e.g. by also adding a syntax like gcc's ({ ... }) construct.

Furthermore, I would really also like a replacement for #ifdef

from gmqcc.

divVerent avatar divVerent commented on August 19, 2024

Will this work? If yes, why is x in the right scope? If no, why not?

macro do { {{{body}}} }
do { float x; }
do { float foo() { return x; } }

Or would it be better to have a second simple CPP mode that only supports argumentless #define/#undef and #ifdef/#else/#endif?

from gmqcc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.