|
| 1 | +package org.perl6.nqp.truffle.nodes.sixmodel; |
| 2 | +import com.oracle.truffle.api.frame.VirtualFrame; |
| 3 | +import com.oracle.truffle.api.nodes.NodeInfo; |
| 4 | +import org.perl6.nqp.truffle.nodes.NQPNode; |
| 5 | +import org.perl6.nqp.truffle.nodes.NQPObjNode; |
| 6 | +import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; |
| 7 | +import com.oracle.truffle.api.object.DynamicObject; |
| 8 | +import org.perl6.nqp.dsl.Deserializer; |
| 9 | + |
| 10 | +@NodeInfo(shortName = "bindattr") |
| 11 | +public final class NQPBindattrNode extends NQPObjNode { |
| 12 | + @Child private NQPNode objNode; |
| 13 | + @Child private NQPNode classHandleNode; |
| 14 | + @Child private NQPNode nameNode; |
| 15 | + @Child private NQPNode valueNode; |
| 16 | + |
| 17 | + @Deserializer |
| 18 | + public NQPBindattrNode(NQPNode objNode, NQPNode classHandleNode, NQPNode nameNode, NQPNode valueNode) { |
| 19 | + this.objNode = objNode; |
| 20 | + this.classHandleNode = classHandleNode; |
| 21 | + this.nameNode = nameNode; |
| 22 | + this.valueNode = valueNode; |
| 23 | + } |
| 24 | + |
| 25 | + @TruffleBoundary |
| 26 | + public void setAttribute(DynamicObject obj, String name, Object value) { |
| 27 | + // TODO - take classHandle into account |
| 28 | + if (!(obj.set(name, value))) { |
| 29 | + throw new RuntimeException("Can't set attribute"); |
| 30 | + } |
| 31 | + } |
| 32 | + |
| 33 | + @Override |
| 34 | + public Object execute(VirtualFrame frame) { |
| 35 | + Object obj = objNode.execute(frame); |
| 36 | + Object classHandle = classHandleNode.execute(frame); |
| 37 | + String name = nameNode.executeStr(frame); |
| 38 | + Object value = valueNode.execute(frame); |
| 39 | + |
| 40 | + setAttribute((DynamicObject) obj, name, value); |
| 41 | + |
| 42 | + return value; |
| 43 | + } |
| 44 | +} |
0 commit comments