Mercurial > hg > graal-compiler
annotate graal/com.oracle.truffle.api.codegen.test/src/com/oracle/truffle/api/codegen/test/BuiltinTest.java @ 8596:6ef9fc7375c7
Updated codegen tests for guards and builtins.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Mon, 01 Apr 2013 21:43:39 +0200 |
parents | graal/com.oracle.truffle.api.codegen.test/src/com/oracle/truffle/api/codegen/test/RuntimeStringTest.java@a80bf36c6a1e |
children | 5f7f0d3e3638 |
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.*; |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
26 import static junit.framework.Assert.*; |
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; |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
35 import com.oracle.truffle.api.codegen.test.TypeSystemTest.ChildrenNode; |
8249
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.TestRootNode; |
aad7e9f4f71c
A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
8246
diff
changeset
|
37 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
|
38 |
8596
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
39 public class BuiltinTest { |
8249
aad7e9f4f71c
A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
8246
diff
changeset
|
40 |
aad7e9f4f71c
A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
8246
diff
changeset
|
41 @Test |
8596
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
42 public void testConcat() { |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
43 TestRootNode<BuiltinNode> node = create(StrConcatFactory.getInstance(), new Context()); |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
44 Str str1 = new Str("42"); |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
45 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
|
46 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
|
47 } |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
48 |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
49 @Test(expected = UnsupportedOperationException.class) |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
50 public void testConcatUnsupported() { |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
51 TestRootNode<BuiltinNode> node = create(StrConcatFactory.getInstance(), new Context()); |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
52 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
|
53 } |
aad7e9f4f71c
A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
8246
diff
changeset
|
54 |
aad7e9f4f71c
A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
8246
diff
changeset
|
55 @Test |
8596
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
56 public void testSubstrSpecialized() { |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
57 TestRootNode<BuiltinNode> node = create(StrSubstrFactory.getInstance(), new Context()); |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
58 Str str = new Str("test 42"); |
8249
aad7e9f4f71c
A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
8246
diff
changeset
|
59 |
8596
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
60 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
|
61 } |
aad7e9f4f71c
A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
8246
diff
changeset
|
62 |
aad7e9f4f71c
A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
8246
diff
changeset
|
63 @Test |
8596
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
64 public void testSubstrGeneric() { |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
65 TestRootNode<BuiltinNode> node = create(StrSubstrFactory.getInstance(), new Context()); |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
66 Str str = new Str("test 42"); |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
67 |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
68 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
|
69 } |
8246
3862508afe2f
Updated @NodeClass tests.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
70 |
8596
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
71 @Test(expected = UnsupportedOperationException.class) |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
72 public void testSubstrUnsupported() { |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
73 TestRootNode<BuiltinNode> node = create(StrSubstrFactory.getInstance(), new Context()); |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
74 executeWith(node, new Object(), "5", "7"); |
8249
aad7e9f4f71c
A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
8246
diff
changeset
|
75 } |
aad7e9f4f71c
A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
8246
diff
changeset
|
76 |
8596
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
77 @Test |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
78 public void testLength() { |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
79 TestRootNode<BuiltinNode> node = create(StrLengthFactory.getInstance(), new Context()); |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
80 Str testStr = new Str("test 42"); |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
81 assertEquals(testStr.length(), executeWith(node, testStr)); |
8249
aad7e9f4f71c
A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
8246
diff
changeset
|
82 } |
8246
3862508afe2f
Updated @NodeClass tests.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
83 |
8596
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
84 @Test(expected = UnsupportedOperationException.class) |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
85 public void testLengthUnsupported() { |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
86 TestRootNode<BuiltinNode> node = create(StrLengthFactory.getInstance(), new Context()); |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
87 executeWith(node, new Object()); |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
88 } |
8246
3862508afe2f
Updated @NodeClass tests.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
89 |
8596
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
90 @Test |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
91 public void testAccessContext() { |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
92 Context context = new Context(); |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
93 TestRootNode<BuiltinNode> node = create(StrAccessContextFactory.getInstance(), context); |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
94 // accessible by node |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
95 assertSame(context, node.getNode().getContext()); |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
96 // accessible by execution |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
97 assertSame(context, executeWith(node)); |
8246
3862508afe2f
Updated @NodeClass tests.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
98 } |
3862508afe2f
Updated @NodeClass tests.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
99 |
8249
aad7e9f4f71c
A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
8246
diff
changeset
|
100 @NodeClass(BuiltinNode.class) |
8596
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
101 static class Str { |
8249
aad7e9f4f71c
A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
8246
diff
changeset
|
102 |
aad7e9f4f71c
A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
8246
diff
changeset
|
103 private final String internal; |
aad7e9f4f71c
A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
8246
diff
changeset
|
104 |
8596
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
105 public Str(String internal) { |
8249
aad7e9f4f71c
A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
8246
diff
changeset
|
106 this.internal = internal; |
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 |
aad7e9f4f71c
A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
8246
diff
changeset
|
109 @Specialization |
8596
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
110 Str concat(Str s1) { |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
111 return new Str(internal + s1.internal); |
8249
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 |
aad7e9f4f71c
A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
8246
diff
changeset
|
114 @Specialization |
8596
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
115 Str substr(int beginIndex, int endIndex) { |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
116 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
|
117 } |
aad7e9f4f71c
A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
8246
diff
changeset
|
118 |
aad7e9f4f71c
A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
8246
diff
changeset
|
119 @Generic |
8596
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
120 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
|
121 if (!(thisValue instanceof Str)) { |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
122 throw new UnsupportedOperationException(); |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
123 } |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
124 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
|
125 } |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
126 |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
127 @Specialization |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
128 int length() { |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
129 return internal.length(); |
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 |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
132 @Specialization |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
133 static Object accessContext(Context context) { |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
134 return context; |
8249
aad7e9f4f71c
A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
8246
diff
changeset
|
135 } |
8246
3862508afe2f
Updated @NodeClass tests.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
136 |
8249
aad7e9f4f71c
A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
8246
diff
changeset
|
137 static int convertInt(Object value) { |
aad7e9f4f71c
A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
8246
diff
changeset
|
138 if (value instanceof Number) { |
aad7e9f4f71c
A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
8246
diff
changeset
|
139 return ((Number) value).intValue(); |
aad7e9f4f71c
A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
8246
diff
changeset
|
140 } else if (value instanceof String) { |
aad7e9f4f71c
A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
8246
diff
changeset
|
141 return Integer.parseInt((String) value); |
aad7e9f4f71c
A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
8246
diff
changeset
|
142 } |
aad7e9f4f71c
A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
8246
diff
changeset
|
143 throw new RuntimeException("Invalid datatype"); |
aad7e9f4f71c
A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
8246
diff
changeset
|
144 } |
8246
3862508afe2f
Updated @NodeClass tests.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
145 |
8249
aad7e9f4f71c
A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
8246
diff
changeset
|
146 @Override |
aad7e9f4f71c
A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
8246
diff
changeset
|
147 public boolean equals(Object obj) { |
8596
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
148 if (obj instanceof Str) { |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
149 return internal.equals(((Str) obj).internal); |
8249
aad7e9f4f71c
A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
8246
diff
changeset
|
150 } |
aad7e9f4f71c
A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
8246
diff
changeset
|
151 return super.equals(obj); |
8246
3862508afe2f
Updated @NodeClass tests.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
152 } |
8249
aad7e9f4f71c
A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
8246
diff
changeset
|
153 |
aad7e9f4f71c
A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
8246
diff
changeset
|
154 @Override |
aad7e9f4f71c
A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
8246
diff
changeset
|
155 public String toString() { |
aad7e9f4f71c
A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
8246
diff
changeset
|
156 return internal; |
aad7e9f4f71c
A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
8246
diff
changeset
|
157 } |
aad7e9f4f71c
A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
8246
diff
changeset
|
158 |
8596
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
159 @Override |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
160 public int hashCode() { |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
161 return internal.hashCode(); |
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 } |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
164 |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
165 abstract static class BuiltinNode extends ChildrenNode { |
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) { |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
170 this(node.context, node.children); |
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 |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
173 public BuiltinNode(Context context, ValueNode... children) { |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
174 super(children); |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
175 this.context = context; |
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 |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
178 public Context getContext() { |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
179 return context; |
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 } |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
183 |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
184 static class Context { |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
185 |
8246
3862508afe2f
Updated @NodeClass tests.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
186 } |
3862508afe2f
Updated @NodeClass tests.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
187 |
3862508afe2f
Updated @NodeClass tests.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
188 } |