Mercurial > hg > graal-compiler
annotate graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/call/SLCallNode.java @ 13761:7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
author | Christian Wimmer <christian.wimmer@oracle.com> |
---|---|
date | Fri, 24 Jan 2014 18:16:24 -0800 |
parents | graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/CallNode.java@c2ed2ce2cfe0 |
children | b16ec83edc73 |
rev | line source |
---|---|
12752
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1 /* |
13761
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13709
diff
changeset
|
2 * Copyright (c) 2013, 2013, Oracle and/or its affiliates. All rights reserved. |
12752
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
4 * |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
8 * |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
13 * accompanied this code). |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
14 * |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
18 * |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
21 * questions. |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
22 */ |
13761
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13709
diff
changeset
|
23 package com.oracle.truffle.sl.nodes.call; |
12752
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
24 |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
25 import com.oracle.truffle.api.frame.*; |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
26 import com.oracle.truffle.api.nodes.*; |
13761
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13709
diff
changeset
|
27 import com.oracle.truffle.sl.nodes.*; |
12752
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
28 import com.oracle.truffle.sl.runtime.*; |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
29 |
13761
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13709
diff
changeset
|
30 public final class SLCallNode extends SLExpressionNode { |
12752
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
31 |
13761
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13709
diff
changeset
|
32 public static SLCallNode create(SLExpressionNode function, SLExpressionNode[] arguments) { |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13709
diff
changeset
|
33 return new SLCallNode(function, arguments, new SLUninitializedCallNode()); |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13709
diff
changeset
|
34 } |
12752
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
35 |
13761
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13709
diff
changeset
|
36 @Child protected SLExpressionNode functionNode; |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13709
diff
changeset
|
37 @Children protected final SLExpressionNode[] argumentNodes; |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13709
diff
changeset
|
38 @Child protected SLAbstractDispatchNode dispatchNode; |
12752
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
39 |
13761
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13709
diff
changeset
|
40 private SLCallNode(SLExpressionNode functionNode, SLExpressionNode[] argumentNodes, SLAbstractDispatchNode dispatchNode) { |
13338
652f24858aad
SL: simplified call nodes. aligned builtin inlining with user function inlining.
Christian Humer <christian.humer@gmail.com>
parents:
13276
diff
changeset
|
41 this.functionNode = adoptChild(functionNode); |
13761
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13709
diff
changeset
|
42 this.argumentNodes = adoptChildren(argumentNodes); |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13709
diff
changeset
|
43 this.dispatchNode = adoptChild(dispatchNode); |
12752
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
44 } |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
45 |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
46 @Override |
13761
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13709
diff
changeset
|
47 @ExplodeLoop |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13709
diff
changeset
|
48 public Object executeGeneric(VirtualFrame frame) { |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13709
diff
changeset
|
49 SLFunction function; |
13338
652f24858aad
SL: simplified call nodes. aligned builtin inlining with user function inlining.
Christian Humer <christian.humer@gmail.com>
parents:
13276
diff
changeset
|
50 try { |
13761
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13709
diff
changeset
|
51 function = functionNode.executeFunction(frame); |
13338
652f24858aad
SL: simplified call nodes. aligned builtin inlining with user function inlining.
Christian Humer <christian.humer@gmail.com>
parents:
13276
diff
changeset
|
52 } catch (UnexpectedResultException e) { |
652f24858aad
SL: simplified call nodes. aligned builtin inlining with user function inlining.
Christian Humer <christian.humer@gmail.com>
parents:
13276
diff
changeset
|
53 throw new UnsupportedOperationException("Call to " + e.getMessage() + " not supported."); |
652f24858aad
SL: simplified call nodes. aligned builtin inlining with user function inlining.
Christian Humer <christian.humer@gmail.com>
parents:
13276
diff
changeset
|
54 } |
652f24858aad
SL: simplified call nodes. aligned builtin inlining with user function inlining.
Christian Humer <christian.humer@gmail.com>
parents:
13276
diff
changeset
|
55 |
13761
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13709
diff
changeset
|
56 Object[] argumentValues = new Object[argumentNodes.length]; |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13709
diff
changeset
|
57 for (int i = 0; i < argumentNodes.length; i++) { |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13709
diff
changeset
|
58 argumentValues[i] = argumentNodes[i].executeGeneric(frame); |
13338
652f24858aad
SL: simplified call nodes. aligned builtin inlining with user function inlining.
Christian Humer <christian.humer@gmail.com>
parents:
13276
diff
changeset
|
59 } |
13761
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13709
diff
changeset
|
60 SLArguments arguments = new SLArguments(argumentValues); |
12752
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
61 |
13761
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13709
diff
changeset
|
62 return dispatchNode.executeCall(frame, function, arguments); |
12752
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
63 } |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
64 } |