|
47 | 47 | import com.oracle.graal.python.nodes.expression.ExpressionNode;
|
48 | 48 | import com.oracle.graal.python.nodes.frame.ReadLocalNode;
|
49 | 49 | import com.oracle.graal.python.nodes.frame.ReadNode;
|
| 50 | +import com.oracle.graal.python.nodes.frame.WriteNode; |
50 | 51 | import com.oracle.graal.python.nodes.statement.StatementNode;
|
51 | 52 | import com.oracle.graal.python.nodes.subscript.GetItemNode;
|
52 | 53 | import com.oracle.graal.python.runtime.exception.PException;
|
@@ -94,14 +95,12 @@ public StatementNode makeDeleteNode() {
|
94 | 95 |
|
95 | 96 | @Override
|
96 | 97 | public StatementNode makeWriteNode(ExpressionNode rhs) {
|
97 |
| - ExpressionNode right = rhs; |
98 | 98 | // freevars pass through the special Class scope
|
99 | 99 | if (readCellLocal != null && !isFreeVar) {
|
100 |
| - // TODO (tfel): Is this what's intended? |
101 |
| - return ((ReadNode) readCellLocal).makeWriteNode(rhs); |
| 100 | + return new WriteClassAttributeCellNode((ReadNode) readCellLocal, (ReadNode) getNsItem, rhs); |
102 | 101 | } else {
|
103 | 102 | // assignments always got to the innermost scope
|
104 |
| - return ((ReadNode) getNsItem).makeWriteNode(right); |
| 103 | + return ((ReadNode) getNsItem).makeWriteNode(rhs); |
105 | 104 | }
|
106 | 105 | }
|
107 | 106 |
|
@@ -132,4 +131,31 @@ Object read(VirtualFrame frame,
|
132 | 131 | return readGlobal.execute(frame);
|
133 | 132 | }
|
134 | 133 | }
|
| 134 | + |
| 135 | + private static class WriteClassAttributeCellNode extends StatementNode implements WriteNode { |
| 136 | + @Child private WriteNode writeCellLocal; |
| 137 | + @Child private WriteNode writeNsItem; |
| 138 | + @Child private ExpressionNode right; |
| 139 | + |
| 140 | + WriteClassAttributeCellNode(ReadNode readCellLocal, ReadNode getNsItem, ExpressionNode rhs) { |
| 141 | + writeCellLocal = (WriteNode) readCellLocal.makeWriteNode(null); |
| 142 | + writeNsItem = (WriteNode) getNsItem.makeWriteNode(null); |
| 143 | + right = rhs; |
| 144 | + } |
| 145 | + |
| 146 | + public ExpressionNode getRhs() { |
| 147 | + return right; |
| 148 | + } |
| 149 | + |
| 150 | + public void doWrite(VirtualFrame frame, Object value) { |
| 151 | + writeCellLocal.doWrite(frame, value); |
| 152 | + writeNsItem.doWrite(frame, value); |
| 153 | + } |
| 154 | + |
| 155 | + @Override |
| 156 | + public void executeVoid(VirtualFrame frame) { |
| 157 | + Object value = right.execute(frame); |
| 158 | + doWrite(frame, value); |
| 159 | + } |
| 160 | + } |
135 | 161 | }
|
0 commit comments