public inbox for jit@gcc.gnu.org
 help / color / mirror / Atom feed
* statement expressions (e.g. for ternary condition operator) in GCCJIT
@ 2016-01-01  0:00 Basile Starynkevitch
  2016-01-01  0:00 ` Basile Starynkevitch
  0 siblings, 1 reply; 2+ messages in thread
From: Basile Starynkevitch @ 2016-01-01  0:00 UTC (permalink / raw)
  To: jit

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} ***

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: statement expressions (e.g. for ternary condition operator) in GCCJIT
  2016-01-01  0:00 statement expressions (e.g. for ternary condition operator) in GCCJIT Basile Starynkevitch
@ 2016-01-01  0:00 ` Basile Starynkevitch
  0 siblings, 0 replies; 2+ messages in thread
From: Basile Starynkevitch @ 2016-01-01  0:00 UTC (permalink / raw)
  To: jit

On 02/10/2016 05:34 PM, Basile Starynkevitch wrote:
>
> 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.


After thinking a few minutes, naming that gcc_jit_block_expr would be 
more consistent.

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} ***

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-02-10 16:38 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-01  0:00 statement expressions (e.g. for ternary condition operator) in GCCJIT Basile Starynkevitch
2016-01-01  0:00 ` Basile Starynkevitch

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).