oppc/code: support multiple assignments
authorDmitry Selyutin <ghostmansd@gmail.com>
Sun, 14 Jan 2024 18:41:16 +0000 (21:41 +0300)
committerDmitry Selyutin <ghostmansd@gmail.com>
Tue, 16 Jan 2024 19:10:07 +0000 (22:10 +0300)
src/openpower/oppc/pc_code.py

index 4a2b4f759d84b2b88acf2c3e4469f3b24a7d01b3..6ac371cb1c5dff381f023ab0209f9b2523a6d9db 100644 (file)
@@ -164,6 +164,21 @@ class CodeVisitor(pc_util.Visitor):
         if isinstance(node.rvalue, pc_ast.Attribute):
             self.fixup_attr(node=node.rvalue)
 
+        if isinstance(node.lvalue, pc_ast.Sequence):
+            if not isinstance(node.rvalue, pc_ast.Sequence):
+                raise ValueError(node.rvalue)
+            if len(node.lvalue) != len(node.rvalue):
+                raise ValueError(node)
+            for (lvalue, rvalue) in zip(node.lvalue, node.rvalue):
+                assign = node.__class__(
+                    lvalue=lvalue.clone(),
+                    rvalue=rvalue.clone(),
+                )
+                self.traverse(root=assign)
+                for (level, stmt) in self[assign]:
+                    self[node].emit(stmt=stmt, level=level)
+            return
+
         if isinstance(node.lvalue, pc_ast.SubscriptExpr):
             call = self.call(name="oppc_subscript_assign", node=node, stmt=True, code=[
                 self[node.lvalue.subject],
@@ -553,6 +568,10 @@ class CodeVisitor(pc_util.Visitor):
     def AttributeName(self, node):
         yield node
 
+    @pc_util.Hook(pc_ast.Sequence)
+    def Sequence(self, node):
+        yield node
+
     @pc_util.Hook(pc_ast.Attribute)
     def Attribute(self, node):
         yield node