New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[OPTIMISATION] Better conditions transcriptions from AST inside if/while/!/bool() #2274
Comments
Also, there are a lot of temporary variables that aren't used. E.g. a = 2
b = a Is translated as : var v1380 = 2
locals_exec.a = v1380
var v1381 = locals_exec.a
locals_exec.b = v1381 Could be rewritten : let v1380 = locals_exec.a = 2;
locals_exec.b = v1380; // avoid doing locals_exec.a which can be a little costly or locals_exec.a = 2;
locals_exec.b = locals_exec.a; |
Removing class A:
def __eq__(self, other):
return []
if A() == 'xy':
print('ok') would not give the same result as CPython. |
I implemented the second suggestion in commit b1383ca |
Hum, I think we can still do it by removing the 2.i step. Pretty sure : if 1 and 2: Instead of : if( $B.$bool( (! $B.$bool(locals.$test = 1) ? locals.$test : 2) ) ){ .... } can be rewritten as : if( ( $B.$bool(1) && $B.$bool(2) ) ){ .... } Because the |
function and(a,b) {
if( $B.bool(a) )
a;
return b;
}
EDIT: I'm an idiot, I forgot that the second operand must not be evaluated if "a" is evaluated to False. |
Implemented in the commit above. Do you think we can close this issue ? |
Hi, Sorry for the late answer. I am currently in the middle of an house moving so I currently doesn't have a lot of time. |
Pas de problème Denis, bon courage pour le déménagement ! |
Hi,
The logical operators are, rightfully, converted as follow, as they need to return the value (and not just
True
/False
) :However, in direct children of nodes :
!
if
while
bool()
We don't care about the value.
For example
if 1 and 2:
is converted as :When it could be converted to :
Resulting on smaller, cleaner, and faster code.
Hence I suggest the following behavior :
N
the current node. IfN
isn'tif
orwhile
or!
orbool()
, stops here.n
the direct child ofN
.ifn
is a comparison operator (e.g.>
ornot in
orin
), write :($B.rich_comp('__gt__', 1, 3))
instead of$B.$bool($B.rich_comp('__gt__', 1, 3))
(indeed it already returns a boolean.)n
is!
orand
oror
orbool()
, write e.g. :( [LEFT_VALUE] && [RIGHT_VALUE] )
instead of$B.$bool((! $B.$bool(locals.$test = [LEFT_VALUE]) ? locals.$test : [RIGHT_VALUE]))
[LEFT_VALUE]
(or[RIGHT_VALUE]
) isn't a!
orand
oror
orbool()
, write it as :$B.bool([THE_VALUE])
(we need to convert it).[LEFT_VALUE]
and go step 2. to determine how to write[LEFT_VALUE]
.Note : I think adding
=== true
inif
andwhile
can very slightly increase execution speed as JS/the browser would knows it doesn't have to try casting the types :Cordially,
The text was updated successfully, but these errors were encountered: