Support chained assignment statements, e.g. a = b = c.

We know when we have begun a chained assignment when we process a DUP_TOP with non-null on the stack. Push a NODE_CHAINSTORE onto the stack when this happens, and keep it 'floating' on top of the stack for all STORE_X operations until the stack is empty.
To support versions of Python <= 2.5 which use DUP_TOP in more places, I modified ROT_TWO, ROT_THREE and ROT_FOUR to get rid of NODE_CHAINSTORE on the stack if it is present.
This commit is contained in:
Aralox
2020-10-23 21:19:01 +11:00
parent 1db8d28729
commit 7a89b72260
7 changed files with 200 additions and 14 deletions

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,39 @@
a = [y, z] = x = (k1, k2, k3) = [] = c = myfunc(x) + 3
x = y = g = {keyA: X}
global store_global
Gx = Gy = Gz = Gq1
Gx = [Gy, Gz] = Gq2
a = b = store_global = c
def func_with_global():
global Gx, Gy, Gz, Gq
Gx = Gy = Gz = Gq
y = store_subscr[0] = x
a[0] = b[x] = c[3] = D[4]
a[0] = (b[x], c[3]) = D[4]
a[0] = Q = [b[x], c[3]] = F = D[4]
q = v = arr[a:b:c] = x
class store_attr1:
def __init__(self, a,b,c):
self.a = self.b = self.c = x
self.d = y
class store_attr2:
def __init__(self, a,b,c): self.a = (self.b, self.c) = x
a.b = c.d = e.f + g.h
def store_deref():
a = I
a = b = c = R1
a = (b, c) = R2
def store_fast():
x = a
y = b
z = c
p = q = r = s
p = [q, r] = s

View File

@@ -0,0 +1,43 @@
a = ( y , z ) = x = ( k1 , k2 , k3 ) = ( ) = c = myfunc ( x ) + 3 <EOL>
x = y = g = { keyA : X } <EOL>
Gx = Gy = Gz = Gq1 <EOL>
Gx = ( Gy , Gz ) = Gq2 <EOL>
a = b = store_global = c <EOL>
def func_with_global ( ) : <EOL>
<INDENT>
global Gx , Gy , Gz <EOL>
Gx = Gy = Gz = Gq <EOL>
<OUTDENT>
y = store_subscr [ 0 ] = x <EOL>
a [ 0 ] = b [ x ] = c [ 3 ] = D [ 4 ] <EOL>
a [ 0 ] = ( b [ x ] , c [ 3 ] ) = D [ 4 ] <EOL>
a [ 0 ] = Q = ( b [ x ] , c [ 3 ] ) = F = D [ 4 ] <EOL>
q = v = arr [ a : b : c ] = x <EOL>
class store_attr1 : <EOL>
<INDENT>
def __init__ ( self , a , b , c ) : <EOL>
<INDENT>
self . a = self . b = self . c = x <EOL>
self . d = y <EOL>
<OUTDENT>
<OUTDENT>
class store_attr2 : <EOL>
<INDENT>
def __init__ ( self , a , b , c ) : <EOL>
<INDENT>
self . a = ( self . b , self . c ) = x <EOL>
<OUTDENT>
<OUTDENT>
a . b = c . d = e . f + g . h <EOL>
def store_deref ( ) : <EOL>
<INDENT>
a = I <EOL>
a = b = c = R1 <EOL>
a = ( b , c ) = R2 <EOL>
def store_fast ( ) : <EOL>
<INDENT>
x = a <EOL>
y = b <EOL>
z = c <EOL>
p = q = r = s <EOL>
p = ( q , r ) = s <EOL>

View File

@@ -1,8 +1,6 @@
var1 = 'x' <EOL>
var2 = 'y' <EOL>
x = 1.23456 <EOL>
s1 = 1.23456 <EOL>
var3 = 1.23456 <EOL>
x = s1 = var3 = 1.23456 <EOL>
a = 15 <EOL>
some_dict = { } <EOL>
some_dict [ 2 ] = 3 <EOL>