statement expressions (e.g. for ternary condition operator) in GCCJIT
Basile Starynkevitch
basile@starynkevitch.net
Fri Jan 1 00:00:00 GMT 2016
Hello All,
AFAIU, GCCJIT is strongly separating statements and expressions.
However, GCC itself (in its C language) is accepting statement expressions
https://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html
It would be really nice if GCCJIT had something equivalent. BTW, if it
did, expressing the ternary conditional operator ?: of C would be
trivial, since
cond?then:otherwise
where all of cond, then and otherwise are int expressions
is the same as
({int _temp; if (cond) _temp=then; else _temp=otherwise; _temp;})
Notice also that many languages (notably Scheme, including Guile, and
Ocaml, and Common Lisp, ...) do not separate statements from
expressions. So providing a way to mix statements (actually blocks) with
rvalues is sensible.
I have not thought a lot about how to extend GCCJIT API to get these
statement expressions. Perhaps a simple
gcc_jit_rvalue*gcc_jit_statement_expr(gcc_jit_context*ctxt,
gcc_jit_location*loc,
gcc_jit_block*block,
gcc_jit_lvalue*res)
would be enough (it would construct a statement expr similar to
({<block>; <res>}) in context ctxt with
"source" location loc.
Of course, I guess that implementing such a function in GCCJIT might not
be trivial.
regards.
--
Basile STARYNKEVITCH http://starynkevitch.net/Basile/
email: basile<at>starynkevitch<dot>net mobile: +33 6 8501 2359
8, rue de la Faiencerie, 92340 Bourg La Reine, France
*** opinions {are only mine, sont seulement les miennes} ***
More information about the Jit
mailing list