An extern operator: is this possible?

21 views
Skip to first unread message

Yannick Duchêne

unread,
May 9, 2015, 10:08:43 PM5/9/15
to ats-lan...@googlegroups.com
Hi,

Is there a way to get an externally defined operator, the same way there are externally defined function with “mac#”?

This may be possible indirectly with the C target, with “mac#<some-name>” referring to a C macro itself assigned to an expression using an operator, ex. “#define ADD(a,b) (a + b)” the using “mac#” for an “extern” function which will later overload an operator (at least, I guess it may be possible). There are no macro with most other targets, including JavaScript, thus the question.

The reason for this question, is another different question, with a case like this:

val test = not (0 = 0);

which gets compiled by atscc2js into this:

statmp3 = ats2jspre_eq_int1_int1(0, 0);
statmp2
= ats2jspre_neg_bool1(statmp3);

which I would like to avoid, if feasible.


gmhwxi

unread,
May 9, 2015, 10:50:12 PM5/9/15
to ats-lan...@googlegroups.com
Is your main concern here about performance?

I don't really know much about the JIT compiler for JS.
But I would assume that a reasonable JIT compiler for JS
should optimize away the two function calls in this case:


statmp3 = ats2jspre_eq_int1_int1(0, 0);
statmp2
= ats2jspre_neg_bool1(statmp3);

Message has been deleted

gmhwxi

unread,
May 9, 2015, 11:06:28 PM5/9/15
to ats-lan...@googlegroups.com
You could try:

macdef not(x) = $extfcall(bool, "not", ,(x))


On Saturday, May 9, 2015 at 10:08:43 PM UTC-4, Yannick Duchêne wrote:

Yannick Duchêne

unread,
May 10, 2015, 12:18:09 AM5/10/15
to ats-lan...@googlegroups.com


Le dimanche 10 mai 2015 05:06:28 UTC+2, gmhwxi a écrit :
You could try:

macdef not(x) = $extfcall(bool, "not", ,(x))

 I will try it. For now, I came to tell there is Closure, a JavaScript to JavaScript compiler. It's like a minifier, which is also able of inlining, and the latter is important here. It's at https://developers.google.com/closure/compiler/ . It can be used as standalone from the command line.
Reply all
Reply to author
Forward
0 new messages