I'd like to do that, problem is with default: if we encounter a default, we need to remember that there is a default in the generic, but we need to continue parsing generic expression to check if there is a type that match, and with you technique we can't go back and re-evaluate default if at the end, no match was found.
example: int a = _Generic(a, default: 3, char : '_', int : 1); On Fri, Jun 30, 2017 at 5:25 PM, Michael Matz <[email protected]> wrote: > Hi, > > On Fri, 30 Jun 2017, uso ewin wrote: > >> I've clean my commit and merge everything on my my mob which should be >> easily mergeable with official mob: >> https://github.com/cosmo-ray/tcc/commit/d2659993274e076894e039cc654fc9e1617ed056 > > Yeah, already nicer. More suggestions below: > >> > I've very briefly looked at your implementation: Don't use your >> > current way of parsing the controlling expression/type, you should be >> > able to reuse expr_type/parse_expr_type/parse_type (or parts of it). >> >> Thanks for your advice, and done on mob branch on my github, expr_type >> work great. >> >> As buying the official C11 standard from ISO is a little expensive for >> my, I use this draft for the implementation: >> http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1548.pdf > > n1570 is the most recent draft before finalization of the standard. But > I guess for _Generic it doesn't matter. Now for the suggestion: > > Instead of saving the tokens for the matching expression and evaluating it > after completely parsed, use the nocode_wanted facility to enable or > disable code generation for the matching and non-matching expressions. > Ala: > > while (1) { > parse type > if (type matches) > expr_eq(); > else { > nocode_wanted++; > expr_eq(); > vpop(); > nocode_wanted--; > } > } > > (Obviously with all the added checking you already have in there for > double defaults or twice-matching types). > > That should further simplify the code and make it nicer. > > > Ciao, > Michael. > > _______________________________________________ > Tinycc-devel mailing list > [email protected] > https://lists.nongnu.org/mailman/listinfo/tinycc-devel _______________________________________________ Tinycc-devel mailing list [email protected] https://lists.nongnu.org/mailman/listinfo/tinycc-devel
