annotate graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/access/SLWritePropertyNode.java @ 20955:f7bc60c3a8f6

SL: use DSL for property writes.
author Christian Humer <christian.humer@gmail.com>
date Tue, 14 Apr 2015 15:16:14 +0200
parents 997bc9764a9a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
18411
dc2e000bed40 SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
1 /*
20955
f7bc60c3a8f6 SL: use DSL for property writes.
Christian Humer <christian.humer@gmail.com>
parents: 18412
diff changeset
2 * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
18411
dc2e000bed40 SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
dc2e000bed40 SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
4 *
dc2e000bed40 SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
dc2e000bed40 SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
dc2e000bed40 SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
7 * published by the Free Software Foundation.
dc2e000bed40 SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
8 *
dc2e000bed40 SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
dc2e000bed40 SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
dc2e000bed40 SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
dc2e000bed40 SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
dc2e000bed40 SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
13 * accompanied this code).
dc2e000bed40 SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
14 *
dc2e000bed40 SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
dc2e000bed40 SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
dc2e000bed40 SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
dc2e000bed40 SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
18 *
dc2e000bed40 SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
dc2e000bed40 SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
dc2e000bed40 SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
21 * questions.
dc2e000bed40 SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
22 */
dc2e000bed40 SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
23 package com.oracle.truffle.sl.nodes.access;
dc2e000bed40 SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
24
dc2e000bed40 SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
25 import com.oracle.truffle.api.frame.*;
dc2e000bed40 SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
26 import com.oracle.truffle.api.nodes.*;
dc2e000bed40 SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
27 import com.oracle.truffle.api.source.*;
18412
997bc9764a9a SL: use the truffle object storage model to represent SL objects
Andreas Woess <andreas.woess@jku.at>
parents: 18411
diff changeset
28 import com.oracle.truffle.api.utilities.*;
18411
dc2e000bed40 SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
29 import com.oracle.truffle.sl.*;
dc2e000bed40 SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
30 import com.oracle.truffle.sl.nodes.*;
18412
997bc9764a9a SL: use the truffle object storage model to represent SL objects
Andreas Woess <andreas.woess@jku.at>
parents: 18411
diff changeset
31 import com.oracle.truffle.sl.runtime.*;
18411
dc2e000bed40 SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
32
dc2e000bed40 SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
33 /**
dc2e000bed40 SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
34 * The node for setting a property of an object. When executed, this node first evaluates the value
dc2e000bed40 SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
35 * expression on the right hand side of the equals operator, followed by the object expression on
dc2e000bed40 SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
36 * the left side of the dot operator, and then sets the named property of this object to the new
dc2e000bed40 SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
37 * value if the property already exists or adds a new property. Finally, it returns the new value.
dc2e000bed40 SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
38 */
dc2e000bed40 SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
39 @NodeInfo(shortName = ".=")
dc2e000bed40 SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
40 public final class SLWritePropertyNode extends SLExpressionNode {
dc2e000bed40 SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
41
dc2e000bed40 SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
42 public static SLWritePropertyNode create(SourceSection src, SLExpressionNode receiverNode, String propertyName, SLExpressionNode valueNode) {
dc2e000bed40 SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
43 return new SLWritePropertyNode(src, receiverNode, propertyName, valueNode);
dc2e000bed40 SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
44 }
dc2e000bed40 SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
45
dc2e000bed40 SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
46 @Child protected SLExpressionNode receiverNode;
dc2e000bed40 SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
47 protected final String propertyName;
dc2e000bed40 SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
48 @Child protected SLExpressionNode valueNode;
18412
997bc9764a9a SL: use the truffle object storage model to represent SL objects
Andreas Woess <andreas.woess@jku.at>
parents: 18411
diff changeset
49 @Child protected SLWritePropertyCacheNode cacheNode;
997bc9764a9a SL: use the truffle object storage model to represent SL objects
Andreas Woess <andreas.woess@jku.at>
parents: 18411
diff changeset
50 private final ConditionProfile receiverTypeCondition = ConditionProfile.createBinaryProfile();
18411
dc2e000bed40 SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
51
dc2e000bed40 SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
52 private SLWritePropertyNode(SourceSection src, SLExpressionNode receiverNode, String propertyName, SLExpressionNode valueNode) {
dc2e000bed40 SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
53 super(src);
dc2e000bed40 SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
54 this.receiverNode = receiverNode;
dc2e000bed40 SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
55 this.propertyName = propertyName;
dc2e000bed40 SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
56 this.valueNode = valueNode;
20955
f7bc60c3a8f6 SL: use DSL for property writes.
Christian Humer <christian.humer@gmail.com>
parents: 18412
diff changeset
57 this.cacheNode = SLWritePropertyCacheNodeGen.create(propertyName);
18411
dc2e000bed40 SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
58 }
dc2e000bed40 SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
59
dc2e000bed40 SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
60 @Override
dc2e000bed40 SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
61 public Object executeGeneric(VirtualFrame frame) {
dc2e000bed40 SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
62 Object value = valueNode.executeGeneric(frame);
dc2e000bed40 SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
63 Object object = receiverNode.executeGeneric(frame);
18412
997bc9764a9a SL: use the truffle object storage model to represent SL objects
Andreas Woess <andreas.woess@jku.at>
parents: 18411
diff changeset
64 if (receiverTypeCondition.profile(SLContext.isSLObject(object))) {
997bc9764a9a SL: use the truffle object storage model to represent SL objects
Andreas Woess <andreas.woess@jku.at>
parents: 18411
diff changeset
65 cacheNode.executeObject(SLContext.castSLObject(object), value);
18411
dc2e000bed40 SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
66 } else {
dc2e000bed40 SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
67 throw new SLException("unexpected receiver type");
dc2e000bed40 SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
68 }
dc2e000bed40 SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
69 return value;
dc2e000bed40 SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
70 }
dc2e000bed40 SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
71 }