* can gccjit support ternary condition operator?
@ 2023-12-27 2:36 zhao xin
0 siblings, 0 replies; only message in thread
From: zhao xin @ 2023-12-27 2:36 UTC (permalink / raw)
To: jit
[-- Attachment #1: Type: text/plain, Size: 1153 bytes --]
Hi,
I am writing a simple Lua JIT toy by using the GGC JIT. and Lua has the grammar "a and b", the usage just like below
--------
local a = nil
print(a and a.b)
a = { b = 1 }
print(a and a.b)
--------
it will print
--------
nil
1
--------
it is different with the C “&&” grammar, but more like the C ternary condition operator "a ? a : b".
and I didn't find the relevant API in GCC JIT, so it may only be used to use alternatives "({int _temp; if (cond) _temp=then; else _temp=otherwise; _temp;})"
but, it can not use in the global variable, here is the C++ code
--------
#define GET_SIZE(cond, then, otherwise) ({int _temp; if (cond) _temp=then; else _temp=otherwise; _temp;})
std::string *s = 0;
//auto size = GET_SIZE(s, s->size(), 0); // compile fail : statement-expressions are not allowed outside functions nor in template-argument lists
auto size = auto size = s ? s->size() : 0; // compile ok
int main() {
std::cout << GET_SIZE(s, s->size(), 0) << std::endl; // compile ok
return 0;
}
--------
so is there any other way to implement "a and b"? or maybe add ternary condition operator support in GCC JIT?
thanks
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-12-27 2:36 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-27 2:36 can gccjit support ternary condition operator? zhao xin
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).