Mercurial > hg > graal-compiler
annotate graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/NodeFactory.java @ 10617:88fa00e79d4a
Add GC counter for starting tracing of barriers
author | Christos Kotselidis <christos.kotselidis@oracle.com> |
---|---|
date | Sun, 07 Jul 2013 17:02:15 +0200 |
parents | cd1a1d92b3e3 |
children | 5151a7588384 |
rev | line source |
---|---|
7292
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
1 /* |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
2 * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved. |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
4 * |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
8 * |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
13 * accompanied this code). |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
14 * |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
18 * |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
21 * questions. |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
22 */ |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
23 package com.oracle.truffle.sl; |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
24 |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
25 import java.io.*; |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
26 import java.math.*; |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
27 import java.util.*; |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
28 |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
29 import com.oracle.truffle.api.frame.*; |
8254
ac2204c05a02
UseSpecializations is now turned off for the generic specialization in WriteLocalNode.
Christian Humer <christian.humer@gmail.com>
parents:
7848
diff
changeset
|
30 import com.oracle.truffle.sl.nodes.ArithmeticNodeFactory.AddNodeFactory; |
ac2204c05a02
UseSpecializations is now turned off for the generic specialization in WriteLocalNode.
Christian Humer <christian.humer@gmail.com>
parents:
7848
diff
changeset
|
31 import com.oracle.truffle.sl.nodes.ArithmeticNodeFactory.DivNodeFactory; |
ac2204c05a02
UseSpecializations is now turned off for the generic specialization in WriteLocalNode.
Christian Humer <christian.humer@gmail.com>
parents:
7848
diff
changeset
|
32 import com.oracle.truffle.sl.nodes.ArithmeticNodeFactory.MulNodeFactory; |
ac2204c05a02
UseSpecializations is now turned off for the generic specialization in WriteLocalNode.
Christian Humer <christian.humer@gmail.com>
parents:
7848
diff
changeset
|
33 import com.oracle.truffle.sl.nodes.ArithmeticNodeFactory.SubNodeFactory; |
7292
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
34 import com.oracle.truffle.sl.nodes.*; |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
35 |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
36 public class NodeFactory { |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
37 |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
38 private final HashMap<String, FunctionDefinitionNode> functions; |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
39 private final PrintStream printOutput; |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
40 |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
41 private FrameDescriptor frameDescriptor; |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
42 private TypedNode returnValue; |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
43 |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
44 public NodeFactory(PrintStream printOutput) { |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
45 this.functions = new HashMap<>(); |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
46 this.printOutput = printOutput; |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
47 } |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
48 |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
49 public FunctionDefinitionNode findFunction(String name) { |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
50 return functions.get(name); |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
51 } |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
52 |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
53 public void startFunction() { |
9258
07f8d136a05e
Truffle API changes for the Frame API. Introduction of Assumptions class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9222
diff
changeset
|
54 frameDescriptor = new FrameDescriptor(); |
7292
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
55 } |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
56 |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
57 public void createFunction(StatementNode body, String name) { |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
58 functions.put(name, new FunctionDefinitionNode(body, frameDescriptor, name, returnValue)); |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
59 } |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
60 |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
61 public TypedNode createLocal(String name) { |
9321
cd1a1d92b3e3
Frame API: Introduce FrameSlotKind.
Andreas Woess <andreas.woess@jku.at>
parents:
9278
diff
changeset
|
62 return ReadLocalNodeFactory.create(frameDescriptor.findOrAddFrameSlot(name, FrameSlotKind.Int)); |
7292
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
63 } |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
64 |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
65 public TypedNode createStringLiteral(String value) { |
7503
31da1716950f
Updated truffle-sl for the changed operation code generation.
Christian Humer <christian.humer@gmail.com>
parents:
7292
diff
changeset
|
66 return StringLiteralNodeFactory.create(value); |
7292
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
67 } |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
68 |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
69 public StatementNode createAssignment(String name, TypedNode right) { |
9321
cd1a1d92b3e3
Frame API: Introduce FrameSlotKind.
Andreas Woess <andreas.woess@jku.at>
parents:
9278
diff
changeset
|
70 return WriteLocalNodeFactory.create(frameDescriptor.findOrAddFrameSlot(name, FrameSlotKind.Int), right); |
7292
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
71 } |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
72 |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
73 public StatementNode createPrint(List<TypedNode> expressions) { |
7503
31da1716950f
Updated truffle-sl for the changed operation code generation.
Christian Humer <christian.humer@gmail.com>
parents:
7292
diff
changeset
|
74 if (expressions.size() >= 1) { |
31da1716950f
Updated truffle-sl for the changed operation code generation.
Christian Humer <christian.humer@gmail.com>
parents:
7292
diff
changeset
|
75 StatementNode[] nodes = new StatementNode[expressions.size() + 1]; |
31da1716950f
Updated truffle-sl for the changed operation code generation.
Christian Humer <christian.humer@gmail.com>
parents:
7292
diff
changeset
|
76 for (int i = 0; i < expressions.size(); i++) { |
9222
aa9ffb3a715e
Updated Truffle-SL to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents:
8254
diff
changeset
|
77 nodes[i] = PrintNodeFactory.create(printOutput, expressions.get(i)); |
7503
31da1716950f
Updated truffle-sl for the changed operation code generation.
Christian Humer <christian.humer@gmail.com>
parents:
7292
diff
changeset
|
78 } |
31da1716950f
Updated truffle-sl for the changed operation code generation.
Christian Humer <christian.humer@gmail.com>
parents:
7292
diff
changeset
|
79 nodes[expressions.size()] = new PrintLineNode(printOutput); |
31da1716950f
Updated truffle-sl for the changed operation code generation.
Christian Humer <christian.humer@gmail.com>
parents:
7292
diff
changeset
|
80 return new BlockNode(nodes); |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7503
diff
changeset
|
81 } else { |
7503
31da1716950f
Updated truffle-sl for the changed operation code generation.
Christian Humer <christian.humer@gmail.com>
parents:
7292
diff
changeset
|
82 return new BlockNode(new StatementNode[]{new PrintLineNode(printOutput)}); |
31da1716950f
Updated truffle-sl for the changed operation code generation.
Christian Humer <christian.humer@gmail.com>
parents:
7292
diff
changeset
|
83 } |
7292
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
84 } |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
85 |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
86 public StatementNode createWhile(ConditionNode condition, StatementNode body) { |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
87 return new WhileNode(condition, body); |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
88 } |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
89 |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
90 public StatementNode createBlock(List<StatementNode> statements) { |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
91 return new BlockNode(statements.toArray(new StatementNode[statements.size()])); |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
92 } |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
93 |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
94 public TypedNode createBinary(String operation, TypedNode left, TypedNode right) { |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
95 switch (operation) { |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
96 case "+": |
7503
31da1716950f
Updated truffle-sl for the changed operation code generation.
Christian Humer <christian.humer@gmail.com>
parents:
7292
diff
changeset
|
97 return AddNodeFactory.create(left, right); |
7292
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
98 case "*": |
7503
31da1716950f
Updated truffle-sl for the changed operation code generation.
Christian Humer <christian.humer@gmail.com>
parents:
7292
diff
changeset
|
99 return MulNodeFactory.create(left, right); |
31da1716950f
Updated truffle-sl for the changed operation code generation.
Christian Humer <christian.humer@gmail.com>
parents:
7292
diff
changeset
|
100 case "/": |
31da1716950f
Updated truffle-sl for the changed operation code generation.
Christian Humer <christian.humer@gmail.com>
parents:
7292
diff
changeset
|
101 return DivNodeFactory.create(left, right); |
31da1716950f
Updated truffle-sl for the changed operation code generation.
Christian Humer <christian.humer@gmail.com>
parents:
7292
diff
changeset
|
102 case "-": |
31da1716950f
Updated truffle-sl for the changed operation code generation.
Christian Humer <christian.humer@gmail.com>
parents:
7292
diff
changeset
|
103 return SubNodeFactory.create(left, right); |
7292
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
104 case "<": |
7503
31da1716950f
Updated truffle-sl for the changed operation code generation.
Christian Humer <christian.humer@gmail.com>
parents:
7292
diff
changeset
|
105 return LessThanNodeFactory.create(left, right); |
7292
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
106 case "&&": |
7503
31da1716950f
Updated truffle-sl for the changed operation code generation.
Christian Humer <christian.humer@gmail.com>
parents:
7292
diff
changeset
|
107 return LogicalAndNodeFactory.create(left, right); |
7292
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
108 default: |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
109 throw new RuntimeException("unexpected operation: " + operation); |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
110 } |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
111 } |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
112 |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
113 public TypedNode createNumericLiteral(String value) { |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
114 try { |
7503
31da1716950f
Updated truffle-sl for the changed operation code generation.
Christian Humer <christian.humer@gmail.com>
parents:
7292
diff
changeset
|
115 return IntegerLiteralNodeFactory.create(Integer.parseInt(value)); |
7292
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
116 } catch (NumberFormatException ex) { |
7503
31da1716950f
Updated truffle-sl for the changed operation code generation.
Christian Humer <christian.humer@gmail.com>
parents:
7292
diff
changeset
|
117 return BigIntegerLiteralNodeFactory.create(new BigInteger(value)); |
7292
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
118 } |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
119 } |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
120 |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
121 public TypedNode createTime() { |
7503
31da1716950f
Updated truffle-sl for the changed operation code generation.
Christian Humer <christian.humer@gmail.com>
parents:
7292
diff
changeset
|
122 return TimeNodeFactory.create(); |
7292
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
123 } |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
124 |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
125 public StatementNode createReturn(TypedNode value) { |
9321
cd1a1d92b3e3
Frame API: Introduce FrameSlotKind.
Andreas Woess <andreas.woess@jku.at>
parents:
9278
diff
changeset
|
126 FrameSlot slot = frameDescriptor.findOrAddFrameSlot("<retval>", FrameSlotKind.Int); |
7292
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
127 if (returnValue == null) { |
7503
31da1716950f
Updated truffle-sl for the changed operation code generation.
Christian Humer <christian.humer@gmail.com>
parents:
7292
diff
changeset
|
128 returnValue = ReadLocalNodeFactory.create(slot); |
7292
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
129 } |
7503
31da1716950f
Updated truffle-sl for the changed operation code generation.
Christian Humer <christian.humer@gmail.com>
parents:
7292
diff
changeset
|
130 StatementNode write = WriteLocalNodeFactory.create(slot, value); |
7292
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
131 return new ReturnNode(write); |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
132 } |
7848
698cd036a1ca
Added a ternary operator to simple language to test short circuit specialization.
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
133 |
698cd036a1ca
Added a ternary operator to simple language to test short circuit specialization.
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
134 public TypedNode createTernary(TypedNode condition, TypedNode thenPart, TypedNode elsePart) { |
698cd036a1ca
Added a ternary operator to simple language to test short circuit specialization.
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
135 return TernaryNodeFactory.create(condition, thenPart, elsePart); |
698cd036a1ca
Added a ternary operator to simple language to test short circuit specialization.
Christian Humer <christian.humer@gmail.com>
parents:
7530
diff
changeset
|
136 } |
7292
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
137 } |