Coder Social home page Coder Social logo

Comments (8)

P-p-H-d avatar P-p-H-d commented on May 15, 2024

I can reproduce the issue.
I have a precise idea why it fails and it is a nasty bug (recursive call of M_REDUCE2 that fails to expand properly on its second invocation). I'll think about which is the best solution to fix this properly.

Thanks for the report!

from mlib.

P-p-H-d avatar P-p-H-d commented on May 15, 2024

The issue should be solved in master.
If it works fine, I'll back-port the fix to the variant.

from mlib.

mario-tux avatar mario-tux commented on May 15, 2024

Ok, I can confirm that it fixes the toy example and my bigger code.

A question: if I understood I can omit the oplist specifications also in macros like TUPLE_OPLIST (like in the toy example above). Right?

If this is true I think that another bug is raising: it looks related to the automatic definition of the out_str method (with container elements supporting it). I'll try to create another related toy example.

from mlib.

mario-tux avatar mario-tux commented on May 15, 2024

Here the example for the second bug:

TUPLE_DEF2(my_tuple, (name, string_t), (value, int))
#define M_OPL_my_tuple_t() TUPLE_OPLIST(my_tuple)

ARRAY_DEF(my_list_of_tuple, my_tuple_t)
#define M_OPL_my_list_of_tuple_t() ARRAY_OPLIST(my_list_of_tuple)

TUPLE_DEF2(my_tuple_of_tuple, (name, string_t), (inner_tuple, my_tuple_t))
#define M_OPL_my_tuple_of_tuple_t() TUPLE_OPLIST(my_tuple_of_tuple)

int main() {
    M_LET(t, my_tuple_t)
    M_LET(lt, my_list_of_tuple_t)
    M_LET(tt, my_tuple_of_tuple_t) {
        my_tuple_out_str(stdout, t);
        my_list_of_tuple_out_str(stdout, lt);
        my_tuple_of_tuple_out_str(stdout, tt);
    }
}

Here the methods my_list_of_tuple_out_str/my_tuple_of_tuple_out_str are not defined. If I use the specific OPLISTs for the former tuple (#define M_OPL_my_tuple_t() TUPLE_OPLIST(my_tuple, STRING_OPLIST, M_DEFAULT_OPLIST) then the methods are defined.

from mlib.

P-p-H-d avatar P-p-H-d commented on May 15, 2024

You cannot omit the oplist specifications in macros like TUPLE_OPLIST. Otherwise this macro will be conservative and will only provide the interfaces that are always defined by the tuples. This is true for all _OPLIST macro. Unfortunately, I don't know any way to avoid this constraint.

I plan to add support for types in _OPLIST alongside oplist (so that it will try to get a global defined one), but it is not supported yet.

from mlib.

mario-tux avatar mario-tux commented on May 15, 2024

Ok, but I don't understand why the following example looks to work even if the last two OPLISTs are defined without further specifications:

TUPLE_DEF2(my_tuple, (name, string_t), (value, int))
#define M_OPL_my_tuple_t() TUPLE_OPLIST(my_tuple, STRING_OPLIST, M_DEFAULT_OPLIST

ARRAY_DEF(my_list_of_tuple, my_tuple_t)
#define M_OPL_my_list_of_tuple_t() ARRAY_OPLIST(my_list_of_tuple)

TUPLE_DEF2(my_tuple_of_tuple, (name, string_t), (inner_tuple, my_tuple_t))
#define M_OPL_my_tuple_of_tuple_t() TUPLE_OPLIST(my_tuple_of_tuple)

int main() {
    M_LET(t, my_tuple_t)
    M_LET(lt, my_list_of_tuple_t)
    M_LET(tt, my_tuple_of_tuple_t) {
        my_tuple_out_str(stdout, t);
        my_list_of_tuple_out_str(stdout, lt);
        my_tuple_of_tuple_out_str(stdout, tt);
    }
}

In this case the _out_str methods looks defined...

from mlib.

P-p-H-d avatar P-p-H-d commented on May 15, 2024

The only interface that will read the oplists defined by M_OPL_my_list_of_tuple_t() and M_OPL_my_tuple_of_tuple_t() is the macro M_LET. M_LET only needs an interface that provides the INIT & CLEAR & TYPE operators. And all oplist provide the methods of theses operators. Therefore, you can omit it in this case and it will still work.
An OPLIST only provides to other the interface of the defined type itself. The type and its functions are defined by the macro _DEF, and this macro only needs the oplists of its sub types to decide which function to define, and doesn't need at all the upper OPLIST.

In summary:

/* This will define my_tuple_of_tuple_out_str as string_t exports an OUT_STR method and my_tuple_t exports one too */
TUPLE_DEF2(my_tuple_of_tuple, (name, string_t), (inner_tuple, my_tuple_t))
/* This will not export the defined OUT_STR method to other interfaces */
#define M_OPL_my_tuple_of_tuple_t() TUPLE_OPLIST(my_tuple_of_tuple)

However, I think it is safer to always define the OPLIST with the proper sub-oplists.

from mlib.

mario-tux avatar mario-tux commented on May 15, 2024

Ok, thanks for the details. Closing this.

from mlib.

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.