Mercurial > hg > graal-compiler
annotate graal/com.oracle.truffle.api.codegen.test/src/com/oracle/truffle/api/codegen/test/BuiltinTest.java @ 9605:1a87230c775d
removed embedding of compiler creating objects into installed code (HotSpot cannot support this)
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Tue, 07 May 2013 22:42:46 +0200 |
parents | 8e3a1635cc9e |
children |
rev | line source |
---|---|
8246
3862508afe2f
Updated @NodeClass tests.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1 /* |
3862508afe2f
Updated @NodeClass tests.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2 * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved. |
3862508afe2f
Updated @NodeClass tests.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3862508afe2f
Updated @NodeClass tests.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
4 * |
3862508afe2f
Updated @NodeClass tests.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
3862508afe2f
Updated @NodeClass tests.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
3862508afe2f
Updated @NodeClass tests.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
3862508afe2f
Updated @NodeClass tests.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
8 * |
3862508afe2f
Updated @NodeClass tests.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
3862508afe2f
Updated @NodeClass tests.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
3862508afe2f
Updated @NodeClass tests.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
3862508afe2f
Updated @NodeClass tests.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
3862508afe2f
Updated @NodeClass tests.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
13 * accompanied this code). |
3862508afe2f
Updated @NodeClass tests.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
14 * |
3862508afe2f
Updated @NodeClass tests.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
3862508afe2f
Updated @NodeClass tests.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
3862508afe2f
Updated @NodeClass tests.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
3862508afe2f
Updated @NodeClass tests.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
18 * |
3862508afe2f
Updated @NodeClass tests.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
3862508afe2f
Updated @NodeClass tests.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
3862508afe2f
Updated @NodeClass tests.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
21 * questions. |
3862508afe2f
Updated @NodeClass tests.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
22 */ |
3862508afe2f
Updated @NodeClass tests.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
23 package com.oracle.truffle.api.codegen.test; |
3862508afe2f
Updated @NodeClass tests.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
24 |
8596
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
25 import static com.oracle.truffle.api.codegen.test.TestHelper.*; |
9226
e27f125147d6
Fixed deprecated static imports to junit.
Christian Humer <christian.humer@gmail.com>
parents:
9223
diff
changeset
|
26 import static org.junit.Assert.*; |
8596
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
27 |
8249
aad7e9f4f71c
A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
8246
diff
changeset
|
28 import org.junit.*; |
aad7e9f4f71c
A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
8246
diff
changeset
|
29 |
8246
3862508afe2f
Updated @NodeClass tests.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
30 import com.oracle.truffle.api.codegen.*; |
8596
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
31 import com.oracle.truffle.api.codegen.test.BuiltinTestFactory.StrFactory.StrAccessContextFactory; |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
32 import com.oracle.truffle.api.codegen.test.BuiltinTestFactory.StrFactory.StrConcatFactory; |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
33 import com.oracle.truffle.api.codegen.test.BuiltinTestFactory.StrFactory.StrLengthFactory; |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
34 import com.oracle.truffle.api.codegen.test.BuiltinTestFactory.StrFactory.StrSubstrFactory; |
8249
aad7e9f4f71c
A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
8246
diff
changeset
|
35 import com.oracle.truffle.api.codegen.test.TypeSystemTest.TestRootNode; |
aad7e9f4f71c
A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
8246
diff
changeset
|
36 import com.oracle.truffle.api.codegen.test.TypeSystemTest.ValueNode; |
aad7e9f4f71c
A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
8246
diff
changeset
|
37 |
8596
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
38 public class BuiltinTest { |
8249
aad7e9f4f71c
A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
8246
diff
changeset
|
39 |
aad7e9f4f71c
A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
8246
diff
changeset
|
40 @Test |
8596
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
41 public void testConcat() { |
9287
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9226
diff
changeset
|
42 TestRootNode<BuiltinNode> node = createRoot(StrConcatFactory.getInstance(), new Context()); |
8596
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
43 Str str1 = new Str("42"); |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
44 Str str2 = new Str(" is the number."); |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
45 assertEquals(str1.concat(str2), executeWith(node, str1, str2)); |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
46 } |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
47 |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
48 @Test(expected = UnsupportedOperationException.class) |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
49 public void testConcatUnsupported() { |
9287
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9226
diff
changeset
|
50 TestRootNode<BuiltinNode> node = createRoot(StrConcatFactory.getInstance(), new Context()); |
8596
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
51 executeWith(node, 42, new Str(" is the number.")); |
8249
aad7e9f4f71c
A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
8246
diff
changeset
|
52 } |
aad7e9f4f71c
A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
8246
diff
changeset
|
53 |
aad7e9f4f71c
A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
8246
diff
changeset
|
54 @Test |
8596
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
55 public void testSubstrSpecialized() { |
9287
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9226
diff
changeset
|
56 TestRootNode<BuiltinNode> node = createRoot(StrSubstrFactory.getInstance(), new Context()); |
8596
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
57 Str str = new Str("test 42"); |
8249
aad7e9f4f71c
A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
8246
diff
changeset
|
58 |
8596
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
59 assertEquals(str.substr(5, 7), executeWith(node, str, 5, 7)); |
8249
aad7e9f4f71c
A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
8246
diff
changeset
|
60 } |
aad7e9f4f71c
A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
8246
diff
changeset
|
61 |
aad7e9f4f71c
A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
8246
diff
changeset
|
62 @Test |
8596
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
63 public void testSubstrGeneric() { |
9287
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9226
diff
changeset
|
64 TestRootNode<BuiltinNode> node = createRoot(StrSubstrFactory.getInstance(), new Context()); |
8596
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
65 Str str = new Str("test 42"); |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
66 |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
67 assertEquals(Str.substr(str, "5", "7"), executeWith(node, str, "5", "7")); |
8249
aad7e9f4f71c
A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
8246
diff
changeset
|
68 } |
8246
3862508afe2f
Updated @NodeClass tests.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
69 |
8596
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
70 @Test(expected = UnsupportedOperationException.class) |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
71 public void testSubstrUnsupported() { |
9287
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9226
diff
changeset
|
72 TestRootNode<BuiltinNode> node = createRoot(StrSubstrFactory.getInstance(), new Context()); |
8596
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
73 executeWith(node, new Object(), "5", "7"); |
8249
aad7e9f4f71c
A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
8246
diff
changeset
|
74 } |
aad7e9f4f71c
A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
8246
diff
changeset
|
75 |
8596
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
76 @Test |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
77 public void testLength() { |
9287
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9226
diff
changeset
|
78 TestRootNode<BuiltinNode> node = createRoot(StrLengthFactory.getInstance(), new Context()); |
8596
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
79 Str testStr = new Str("test 42"); |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
80 assertEquals(testStr.length(), executeWith(node, testStr)); |
8249
aad7e9f4f71c
A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
8246
diff
changeset
|
81 } |
8246
3862508afe2f
Updated @NodeClass tests.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
82 |
8596
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
83 @Test(expected = UnsupportedOperationException.class) |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
84 public void testLengthUnsupported() { |
9287
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9226
diff
changeset
|
85 TestRootNode<BuiltinNode> node = createRoot(StrLengthFactory.getInstance(), new Context()); |
8596
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
86 executeWith(node, new Object()); |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
87 } |
8246
3862508afe2f
Updated @NodeClass tests.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
88 |
8596
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
89 @Test |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
90 public void testAccessContext() { |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
91 Context context = new Context(); |
9287
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9226
diff
changeset
|
92 TestRootNode<BuiltinNode> node = createRoot(StrAccessContextFactory.getInstance(), context); |
8596
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
93 // accessible by node |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
94 assertSame(context, node.getNode().getContext()); |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
95 // accessible by execution |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
96 assertSame(context, executeWith(node)); |
8246
3862508afe2f
Updated @NodeClass tests.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
97 } |
3862508afe2f
Updated @NodeClass tests.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
98 |
9223
5f7f0d3e3638
Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents:
8596
diff
changeset
|
99 @NodeClass(value = BuiltinNode.class, splitByMethodName = true) |
8596
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
100 static class Str { |
8249
aad7e9f4f71c
A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
8246
diff
changeset
|
101 |
aad7e9f4f71c
A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
8246
diff
changeset
|
102 private final String internal; |
aad7e9f4f71c
A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
8246
diff
changeset
|
103 |
8596
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
104 public Str(String internal) { |
8249
aad7e9f4f71c
A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
8246
diff
changeset
|
105 this.internal = internal; |
aad7e9f4f71c
A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
8246
diff
changeset
|
106 } |
aad7e9f4f71c
A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
8246
diff
changeset
|
107 |
aad7e9f4f71c
A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
8246
diff
changeset
|
108 @Specialization |
8596
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
109 Str concat(Str s1) { |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
110 return new Str(internal + s1.internal); |
8249
aad7e9f4f71c
A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
8246
diff
changeset
|
111 } |
aad7e9f4f71c
A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
8246
diff
changeset
|
112 |
aad7e9f4f71c
A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
8246
diff
changeset
|
113 @Specialization |
8596
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
114 Str substr(int beginIndex, int endIndex) { |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
115 return new Str(internal.substring(beginIndex, endIndex)); |
8249
aad7e9f4f71c
A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
8246
diff
changeset
|
116 } |
aad7e9f4f71c
A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
8246
diff
changeset
|
117 |
aad7e9f4f71c
A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
8246
diff
changeset
|
118 @Generic |
8596
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
119 static Str substr(Object thisValue, Object beginIndex, Object endIndex) { |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
120 if (!(thisValue instanceof Str)) { |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
121 throw new UnsupportedOperationException(); |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
122 } |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
123 return ((Str) thisValue).substr(convertInt(beginIndex), convertInt(endIndex)); |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
124 } |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
125 |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
126 @Specialization |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
127 int length() { |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
128 return internal.length(); |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
129 } |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
130 |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
131 @Specialization |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
132 static Object accessContext(Context context) { |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
133 return context; |
8249
aad7e9f4f71c
A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
8246
diff
changeset
|
134 } |
8246
3862508afe2f
Updated @NodeClass tests.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
135 |
8249
aad7e9f4f71c
A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
8246
diff
changeset
|
136 static int convertInt(Object value) { |
aad7e9f4f71c
A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
8246
diff
changeset
|
137 if (value instanceof Number) { |
aad7e9f4f71c
A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
8246
diff
changeset
|
138 return ((Number) value).intValue(); |
aad7e9f4f71c
A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
8246
diff
changeset
|
139 } else if (value instanceof String) { |
aad7e9f4f71c
A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
8246
diff
changeset
|
140 return Integer.parseInt((String) value); |
aad7e9f4f71c
A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
8246
diff
changeset
|
141 } |
aad7e9f4f71c
A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
8246
diff
changeset
|
142 throw new RuntimeException("Invalid datatype"); |
aad7e9f4f71c
A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
8246
diff
changeset
|
143 } |
8246
3862508afe2f
Updated @NodeClass tests.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
144 |
8249
aad7e9f4f71c
A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
8246
diff
changeset
|
145 @Override |
aad7e9f4f71c
A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
8246
diff
changeset
|
146 public boolean equals(Object obj) { |
8596
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
147 if (obj instanceof Str) { |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
148 return internal.equals(((Str) obj).internal); |
8249
aad7e9f4f71c
A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
8246
diff
changeset
|
149 } |
aad7e9f4f71c
A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
8246
diff
changeset
|
150 return super.equals(obj); |
8246
3862508afe2f
Updated @NodeClass tests.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
151 } |
8249
aad7e9f4f71c
A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
8246
diff
changeset
|
152 |
aad7e9f4f71c
A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
8246
diff
changeset
|
153 @Override |
aad7e9f4f71c
A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
8246
diff
changeset
|
154 public String toString() { |
aad7e9f4f71c
A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
8246
diff
changeset
|
155 return internal; |
aad7e9f4f71c
A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
8246
diff
changeset
|
156 } |
aad7e9f4f71c
A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
8246
diff
changeset
|
157 |
8596
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
158 @Override |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
159 public int hashCode() { |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
160 return internal.hashCode(); |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
161 } |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
162 } |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
163 |
9223
5f7f0d3e3638
Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents:
8596
diff
changeset
|
164 @NodeChild(value = "children", type = ValueNode[].class) |
5f7f0d3e3638
Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents:
8596
diff
changeset
|
165 abstract static class BuiltinNode extends ValueNode { |
8596
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
166 |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
167 protected final Context context; |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
168 |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
169 public BuiltinNode(BuiltinNode node) { |
9223
5f7f0d3e3638
Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents:
8596
diff
changeset
|
170 this(node.context); |
8596
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
171 } |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
172 |
9223
5f7f0d3e3638
Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents:
8596
diff
changeset
|
173 public BuiltinNode(Context context) { |
8596
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
174 this.context = context; |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
175 } |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
176 |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
177 public Context getContext() { |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
178 return context; |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
179 } |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
180 } |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
181 |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
182 static class Context { |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
183 |
8246
3862508afe2f
Updated @NodeClass tests.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
184 } |
3862508afe2f
Updated @NodeClass tests.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
185 |
3862508afe2f
Updated @NodeClass tests.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
186 } |