Mercurial > hg > truffle
comparison truffle/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/vm/HashLanguage.java @ 22385:0e86a9f324bf
Capturing the current state of Source->CallTarget caching in a test
author | Jaroslav Tulach <jaroslav.tulach@oracle.com> |
---|---|
date | Thu, 19 Nov 2015 09:29:24 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
22384:2acc64b45848 | 22385:0e86a9f324bf |
---|---|
1 /* | |
2 * Copyright (c) 2015, 2015, Oracle and/or its affiliates. All rights reserved. | |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
20 * or visit www.oracle.com if you need additional information or have any | |
21 * questions. | |
22 */ | |
23 package com.oracle.truffle.api.test.vm; | |
24 | |
25 import com.oracle.truffle.api.CallTarget; | |
26 import com.oracle.truffle.api.Truffle; | |
27 import com.oracle.truffle.api.TruffleLanguage; | |
28 import com.oracle.truffle.api.TruffleLanguage.Env; | |
29 import com.oracle.truffle.api.frame.MaterializedFrame; | |
30 import com.oracle.truffle.api.frame.VirtualFrame; | |
31 import com.oracle.truffle.api.instrument.Visualizer; | |
32 import com.oracle.truffle.api.instrument.WrapperNode; | |
33 import com.oracle.truffle.api.nodes.Node; | |
34 import com.oracle.truffle.api.nodes.RootNode; | |
35 import com.oracle.truffle.api.source.Source; | |
36 import java.io.IOException; | |
37 | |
38 @TruffleLanguage.Registration(name = "Hash", mimeType = "application/x-test-hash", version = "1.0") | |
39 public class HashLanguage extends TruffleLanguage<Env> { | |
40 public static final HashLanguage INSTANCE = new HashLanguage(); | |
41 | |
42 @Override | |
43 protected Env createContext(Env env) { | |
44 return env; | |
45 } | |
46 | |
47 @Override | |
48 protected CallTarget parse(Source code, Node context, String... argumentNames) throws IOException { | |
49 return Truffle.getRuntime().createCallTarget(new HashNode(this, code)); | |
50 } | |
51 | |
52 @Override | |
53 protected Object findExportedSymbol(Env context, String globalName, boolean onlyExplicit) { | |
54 return null; | |
55 } | |
56 | |
57 @Override | |
58 protected Object getLanguageGlobal(Env context) { | |
59 return null; | |
60 } | |
61 | |
62 @Override | |
63 protected boolean isObjectOfLanguage(Object object) { | |
64 return false; | |
65 } | |
66 | |
67 @Override | |
68 protected Visualizer getVisualizer() { | |
69 return null; | |
70 } | |
71 | |
72 @Override | |
73 protected boolean isInstrumentable(Node node) { | |
74 return false; | |
75 } | |
76 | |
77 @Override | |
78 protected WrapperNode createWrapperNode(Node node) { | |
79 throw new UnsupportedOperationException(); | |
80 } | |
81 | |
82 @Override | |
83 protected Object evalInContext(Source source, Node node, MaterializedFrame mFrame) throws IOException { | |
84 throw new UnsupportedOperationException("Not supported yet."); // To change body of | |
85 // generated methods, choose | |
86 // Tools | Templates. | |
87 } | |
88 | |
89 private static class HashNode extends RootNode { | |
90 private static int counter; | |
91 private final Source code; | |
92 private final int id; | |
93 | |
94 public HashNode(HashLanguage hash, Source code) { | |
95 super(hash.getClass(), null, null); | |
96 this.code = code; | |
97 id = ++counter; | |
98 } | |
99 | |
100 @Override | |
101 public Object execute(VirtualFrame frame) { | |
102 return System.identityHashCode(this) + "@" + code.getCode() + " @ " + id; | |
103 } | |
104 } | |
105 | |
106 @TruffleLanguage.Registration(name = "AltHash", mimeType = "application/x-test-hash-alt", version = "1.0") | |
107 public static final class SubLang extends HashLanguage { | |
108 public static final SubLang INSTANCE = new SubLang(); | |
109 } | |
110 } |