Mercurial > hg > truffle
annotate truffle/com.oracle.truffle.tck/src/com/oracle/truffle/tck/TruffleTCK.java @ 22200:7abcbeb12d08
Creating a TruffleObject that knows its PolyglotEngine and wrapping all values returned from the engine by it, so it is always clear into which engine context an object belongs.
author | Jaroslav Tulach <jaroslav.tulach@oracle.com> |
---|---|
date | Fri, 25 Sep 2015 16:53:27 +0200 |
parents | dcb70d90c11d |
children | 85a6db6624ab |
rev | line source |
---|---|
21938
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
1 /* |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
2 * Copyright (c) 2015, 2015, Oracle and/or its affiliates. All rights reserved. |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
4 * |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. Oracle designates this |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
8 * particular file as subject to the "Classpath" exception as provided |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
9 * by Oracle in the LICENSE file that accompanied this code. |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
10 * |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
11 * This code is distributed in the hope that it will be useful, but WITHOUT |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
14 * version 2 for more details (a copy is included in the LICENSE file that |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
15 * accompanied this code). |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
16 * |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
17 * You should have received a copy of the GNU General Public License version |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
18 * 2 along with this work; if not, write to the Free Software Foundation, |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
20 * |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
22 * or visit www.oracle.com if you need additional information or have any |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
23 * questions. |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
24 */ |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
25 package com.oracle.truffle.tck; |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
26 |
22135
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
27 import com.oracle.truffle.api.interop.TruffleObject; |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
28 import com.oracle.truffle.api.interop.java.JavaInterop; |
22104
cf19259edf87
TruffleVM.eval and Source.withMimeType
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22076
diff
changeset
|
29 import com.oracle.truffle.api.source.Source; |
22170
796f0fef110e
Renaming to PolyglotEngine
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22168
diff
changeset
|
30 import com.oracle.truffle.api.vm.PolyglotEngine; |
21938
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
31 import java.io.IOException; |
22200
7abcbeb12d08
Creating a TruffleObject that knows its PolyglotEngine and wrapping all values returned from the engine by it, so it is always clear into which engine context an object belongs.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22173
diff
changeset
|
32 import java.lang.reflect.Field; |
21938
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
33 import java.util.Random; |
22157
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22156
diff
changeset
|
34 import static org.junit.Assert.assertEquals; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22156
diff
changeset
|
35 import static org.junit.Assert.assertNotNull; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22156
diff
changeset
|
36 import static org.junit.Assert.assertNotSame; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22156
diff
changeset
|
37 import static org.junit.Assert.assertNull; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22156
diff
changeset
|
38 import static org.junit.Assert.assertSame; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22156
diff
changeset
|
39 import static org.junit.Assert.fail; |
21938
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
40 import org.junit.Test; |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
41 |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
42 /** |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
43 * A collection of tests that can certify language implementation to be compliant with most recent |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
44 * requirements of the Truffle infrastructure and tooling. Subclass, implement abstract methods and |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
45 * include in your test suite. |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
46 */ |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
47 public abstract class TruffleTCK { |
22135
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
48 private static final Random RANDOM = new Random(); |
22170
796f0fef110e
Renaming to PolyglotEngine
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22168
diff
changeset
|
49 private PolyglotEngine tckVM; |
21938
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
50 |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
51 protected TruffleTCK() { |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
52 } |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
53 |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
54 /** |
22172
b31dcacfc8ff
Replacing more TruffleVM references in comments with the new PolyglotEngine name
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22170
diff
changeset
|
55 * This methods is called before first test is executed. It's purpose is to set a |
b31dcacfc8ff
Replacing more TruffleVM references in comments with the new PolyglotEngine name
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22170
diff
changeset
|
56 * {@link PolyglotEngine} with your language up, so it is ready for testing. |
b31dcacfc8ff
Replacing more TruffleVM references in comments with the new PolyglotEngine name
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22170
diff
changeset
|
57 * {@link PolyglotEngine#eval(com.oracle.truffle.api.source.Source) Execute} any scripts you |
b31dcacfc8ff
Replacing more TruffleVM references in comments with the new PolyglotEngine name
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22170
diff
changeset
|
58 * need, and prepare global symbols with proper names. The symbols will then be looked up by the |
21938
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
59 * infrastructure (using the names provided by you from methods like {@link #plusInt()}) and |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
60 * used for internal testing. |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
61 * |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
62 * @return initialized Truffle virtual machine |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
63 * @throws java.lang.Exception thrown when the VM preparation fails |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
64 */ |
22170
796f0fef110e
Renaming to PolyglotEngine
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22168
diff
changeset
|
65 protected abstract PolyglotEngine prepareVM() throws Exception; |
21938
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
66 |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
67 /** |
22135
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
68 * MIME type associated with your language. The MIME type will be passed to |
22172
b31dcacfc8ff
Replacing more TruffleVM references in comments with the new PolyglotEngine name
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22170
diff
changeset
|
69 * {@link PolyglotEngine#eval(com.oracle.truffle.api.source.Source)} method of the |
b31dcacfc8ff
Replacing more TruffleVM references in comments with the new PolyglotEngine name
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22170
diff
changeset
|
70 * {@link #prepareVM() created engine}. |
21938
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
71 * |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
72 * @return mime type of the tested language |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
73 */ |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
74 protected abstract String mimeType(); |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
75 |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
76 /** |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
77 * Name of function which will return value 42 as a number. The return value of the method |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
78 * should be instance of {@link Number} and its {@link Number#intValue()} should return |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
79 * <code>42</code>. |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
80 * |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
81 * @return name of globally exported symbol |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
82 */ |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
83 protected abstract String fourtyTwo(); |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
84 |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
85 /** |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
86 * Name of a function that returns <code>null</code>. Truffle languages are encouraged to have |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
87 * their own type representing <code>null</code>, but when such value is returned from |
22172
b31dcacfc8ff
Replacing more TruffleVM references in comments with the new PolyglotEngine name
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22170
diff
changeset
|
88 * {@link PolyglotEngine#eval}, it needs to be converted to real Java <code>null</code> by |
b31dcacfc8ff
Replacing more TruffleVM references in comments with the new PolyglotEngine name
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22170
diff
changeset
|
89 * sending a foreign access <em>isNull</em> message. There is a test to verify it is really |
b31dcacfc8ff
Replacing more TruffleVM references in comments with the new PolyglotEngine name
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22170
diff
changeset
|
90 * true. |
21938
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
91 * |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
92 * @return name of globally exported symbol |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
93 */ |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
94 protected abstract String returnsNull(); |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
95 |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
96 /** |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
97 * Name of function to add two integer values together. The symbol will be invoked with two |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
98 * parameters of type {@link Integer} and expects result of type {@link Number} which's |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
99 * {@link Number#intValue()} is equivalent of <code>param1 + param2</code>. |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
100 * |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
101 * @return name of globally exported symbol |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
102 */ |
22138
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
103 protected String plusInt() { |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
104 throw new UnsupportedOperationException("Override plus(Class,Class) method!"); |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
105 } |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
106 |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
107 /** |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
108 * Name of function to add two numbers together. The symbol will be invoked with two parameters |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
109 * of <code>type1</code> and <code>type2</code> and expects result of type {@link Number} |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
110 * which's {@link Number#intValue()} is equivalent of <code>param1 + param2</code>. As some |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
111 * languages may have different operations for different types of numbers, the actual types are |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
112 * passed to the method and the implementation can decide to return different symbol based on |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
113 * the parameters. |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
114 * |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
115 * @param type1 one of byte, short, int, long, float, double class |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
116 * @param type2 one of byte, short, int, long, float, double class |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
117 * @return name of globally exported symbol |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
118 */ |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
119 protected String plus(Class<?> type1, Class<?> type2) { |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
120 return plusInt(); |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
121 } |
21938
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
122 |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
123 /** |
21960
a88981c5ce8b
Initial test for Java Interop: Perform callback to Math.min and Math.max via TruffleObject and Message.createExecute(2).
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
124 * Name of a function in your language to perform a callback to foreign function. Your function |
a88981c5ce8b
Initial test for Java Interop: Perform callback to Math.min and Math.max via TruffleObject and Message.createExecute(2).
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
125 * should prepare two numbers (18 and 32) and apply them to the function passed in as an |
a88981c5ce8b
Initial test for Java Interop: Perform callback to Math.min and Math.max via TruffleObject and Message.createExecute(2).
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
126 * argument of your function. It should then add 10 to the returned value and return the result |
a88981c5ce8b
Initial test for Java Interop: Perform callback to Math.min and Math.max via TruffleObject and Message.createExecute(2).
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
127 * back to its caller. |
a88981c5ce8b
Initial test for Java Interop: Perform callback to Math.min and Math.max via TruffleObject and Message.createExecute(2).
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
128 * |
a88981c5ce8b
Initial test for Java Interop: Perform callback to Math.min and Math.max via TruffleObject and Message.createExecute(2).
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
129 * @return name of globally exported symbol |
a88981c5ce8b
Initial test for Java Interop: Perform callback to Math.min and Math.max via TruffleObject and Message.createExecute(2).
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
130 */ |
a88981c5ce8b
Initial test for Java Interop: Perform callback to Math.min and Math.max via TruffleObject and Message.createExecute(2).
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
131 protected abstract String applyNumbers(); |
a88981c5ce8b
Initial test for Java Interop: Perform callback to Math.min and Math.max via TruffleObject and Message.createExecute(2).
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
132 |
a88981c5ce8b
Initial test for Java Interop: Perform callback to Math.min and Math.max via TruffleObject and Message.createExecute(2).
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
133 /** |
22140
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
134 * Name of identity function. The identity function accepts one argument and returns it. The |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
135 * argument should go through without any modification, e.g. the input should result in |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
136 * identical output. |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
137 * |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
138 * @return name of globally exported symbol |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
139 */ |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
140 protected String identity() { |
22156
50056a161d7f
Replacing time out associated warnings by UnsupportedOperationException. Meaning of exception is probably more straightforward than a soft hint attempted before. Shouldn't influence the way things are build, if tests are skipped.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22142
diff
changeset
|
141 throw new UnsupportedOperationException("identity() method not implemented"); |
22140
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
142 } |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
143 |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
144 /** |
22172
b31dcacfc8ff
Replacing more TruffleVM references in comments with the new PolyglotEngine name
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22170
diff
changeset
|
145 * Name of a function that counts number of its invocations in current {@link PolyglotEngine} |
22046
e7c2d36daf72
TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21960
diff
changeset
|
146 * context. Your function should somehow keep a counter to remember number of its invocations |
e7c2d36daf72
TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21960
diff
changeset
|
147 * and always increment it. The first invocation should return <code>1</code>, the second |
e7c2d36daf72
TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21960
diff
changeset
|
148 * <code>2</code> and so on. The returned values are expected to be instances of {@link Number}. |
e7c2d36daf72
TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21960
diff
changeset
|
149 * <p> |
e7c2d36daf72
TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21960
diff
changeset
|
150 * The function will be used to test that two instances of your language can co-exist next to |
e7c2d36daf72
TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21960
diff
changeset
|
151 * each other. Without being mutually influenced. |
e7c2d36daf72
TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21960
diff
changeset
|
152 * |
e7c2d36daf72
TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21960
diff
changeset
|
153 * @return name of globally expected symbol |
e7c2d36daf72
TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21960
diff
changeset
|
154 */ |
e7c2d36daf72
TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21960
diff
changeset
|
155 protected abstract String countInvocations(); |
e7c2d36daf72
TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21960
diff
changeset
|
156 |
e7c2d36daf72
TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21960
diff
changeset
|
157 /** |
21938
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
158 * Return a code snippet that is invalid in your language. Its |
22172
b31dcacfc8ff
Replacing more TruffleVM references in comments with the new PolyglotEngine name
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22170
diff
changeset
|
159 * {@link PolyglotEngine#eval(com.oracle.truffle.api.source.Source) evaluation} should fail and |
b31dcacfc8ff
Replacing more TruffleVM references in comments with the new PolyglotEngine name
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22170
diff
changeset
|
160 * yield an exception. |
21938
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
161 * |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
162 * @return code snippet invalid in the tested language |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
163 */ |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
164 protected abstract String invalidCode(); |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
165 |
22135
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
166 /** |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
167 * Name of a function that returns a compound object with members representing certain |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
168 * operations. In the JavaScript the object should look like: |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
169 * |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
170 * <pre> |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
171 * <b>var</b> obj = { |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
172 * 'fourtyTwo': function {@link #fourtyTwo()}, |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
173 * 'plus': function {@link #plusInt()}, |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
174 * 'returnsNull': function {@link #returnsNull()}, |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
175 * 'returnsThis': function() { return obj; } |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
176 * }; |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
177 * <b>return</b> obj; |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
178 * </pre> |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
179 * |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
180 * The returned object shall have three functions that will be obtained and used exactly as |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
181 * described in their Javadoc - e.g. {@link #fourtyTwo()}, {@link #plusInt()} and |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
182 * {@link #returnsNull()}. In addition to that there should be one more function |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
183 * <b>returnsThis</b> that will return the object itself again. |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
184 * |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
185 * @return name of a function that returns such compound object |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
186 */ |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
187 protected String compoundObject() { |
22156
50056a161d7f
Replacing time out associated warnings by UnsupportedOperationException. Meaning of exception is probably more straightforward than a soft hint attempted before. Shouldn't influence the way things are build, if tests are skipped.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22142
diff
changeset
|
188 throw new UnsupportedOperationException("compoundObject() method not implemented"); |
22135
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
189 } |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
190 |
22170
796f0fef110e
Renaming to PolyglotEngine
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22168
diff
changeset
|
191 private PolyglotEngine vm() throws Exception { |
21938
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
192 if (tckVM == null) { |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
193 tckVM = prepareVM(); |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
194 } |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
195 return tckVM; |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
196 } |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
197 |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
198 // |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
199 // The tests |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
200 // |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
201 |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
202 @Test |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
203 public void testFortyTwo() throws Exception { |
22170
796f0fef110e
Renaming to PolyglotEngine
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22168
diff
changeset
|
204 PolyglotEngine.Value fourtyTwo = findGlobalSymbol(fourtyTwo()); |
21938
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
205 |
22121
d045a505c2b3
Asynchronous TruffleVM can be created by providing own Executor when configuring the TruffleVM.Builder
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22104
diff
changeset
|
206 Object res = fourtyTwo.invoke(null).get(); |
21938
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
207 |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
208 assert res instanceof Number : "should yield a number, but was: " + res; |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
209 |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
210 Number n = (Number) res; |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
211 |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
212 assert 42 == n.intValue() : "The value is 42 = " + n.intValue(); |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
213 } |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
214 |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
215 @Test |
22135
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
216 public void testFortyTwoWithCompoundObject() throws Exception { |
22156
50056a161d7f
Replacing time out associated warnings by UnsupportedOperationException. Meaning of exception is probably more straightforward than a soft hint attempted before. Shouldn't influence the way things are build, if tests are skipped.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22142
diff
changeset
|
217 CompoundObject obj = findCompoundSymbol(); |
22135
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
218 if (obj == null) { |
21938
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
219 return; |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
220 } |
22135
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
221 Number res = obj.fourtyTwo(); |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
222 assertEquals("Should be 42", 42, res.intValue()); |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
223 } |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
224 |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
225 @Test |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
226 public void testNull() throws Exception { |
22170
796f0fef110e
Renaming to PolyglotEngine
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22168
diff
changeset
|
227 PolyglotEngine.Value retNull = findGlobalSymbol(returnsNull()); |
21938
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
228 |
22121
d045a505c2b3
Asynchronous TruffleVM can be created by providing own Executor when configuring the TruffleVM.Builder
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22104
diff
changeset
|
229 Object res = retNull.invoke(null).get(); |
21938
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
230 |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
231 assertNull("Should yield real Java null", res); |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
232 } |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
233 |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
234 @Test |
22135
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
235 public void testNullInCompoundObject() throws Exception { |
22156
50056a161d7f
Replacing time out associated warnings by UnsupportedOperationException. Meaning of exception is probably more straightforward than a soft hint attempted before. Shouldn't influence the way things are build, if tests are skipped.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22142
diff
changeset
|
236 CompoundObject obj = findCompoundSymbol(); |
22135
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
237 if (obj == null) { |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
238 return; |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
239 } |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
240 Object res = obj.returnsNull(); |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
241 assertNull("Should yield real Java null", res); |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
242 } |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
243 |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
244 @Test |
21938
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
245 public void testPlusWithInts() throws Exception { |
22135
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
246 int a = RANDOM.nextInt(100); |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
247 int b = RANDOM.nextInt(100); |
21938
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
248 |
22170
796f0fef110e
Renaming to PolyglotEngine
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22168
diff
changeset
|
249 PolyglotEngine.Value plus = findGlobalSymbol(plus(int.class, int.class)); |
21938
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
250 |
22135
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
251 Number n = plus.invoke(null, a, b).as(Number.class); |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
252 assert a + b == n.intValue() : "The value is correct: (" + a + " + " + b + ") = " + n.intValue(); |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
253 } |
21938
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
254 |
22135
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
255 @Test |
22138
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
256 public void testPlusWithBytes() throws Exception { |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
257 int a = RANDOM.nextInt(100); |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
258 int b = RANDOM.nextInt(100); |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
259 |
22170
796f0fef110e
Renaming to PolyglotEngine
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22168
diff
changeset
|
260 PolyglotEngine.Value plus = findGlobalSymbol(plus(byte.class, byte.class)); |
22138
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
261 |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
262 Number n = plus.invoke(null, (byte) a, (byte) b).as(Number.class); |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
263 assert a + b == n.intValue() : "The value is correct: (" + a + " + " + b + ") = " + n.intValue(); |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
264 } |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
265 |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
266 @Test |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
267 public void testPlusWithShort() throws Exception { |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
268 int a = RANDOM.nextInt(100); |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
269 int b = RANDOM.nextInt(100); |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
270 |
22170
796f0fef110e
Renaming to PolyglotEngine
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22168
diff
changeset
|
271 PolyglotEngine.Value plus = findGlobalSymbol(plus(short.class, short.class)); |
22138
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
272 |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
273 Number n = plus.invoke(null, (short) a, (short) b).as(Number.class); |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
274 assert a + b == n.intValue() : "The value is correct: (" + a + " + " + b + ") = " + n.intValue(); |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
275 } |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
276 |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
277 @Test |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
278 public void testPlusWithLong() throws Exception { |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
279 long a = RANDOM.nextInt(100); |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
280 long b = RANDOM.nextInt(100); |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
281 |
22170
796f0fef110e
Renaming to PolyglotEngine
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22168
diff
changeset
|
282 PolyglotEngine.Value plus = findGlobalSymbol(plus(long.class, long.class)); |
22138
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
283 |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
284 Number n = plus.invoke(null, a, b).as(Number.class); |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
285 assert a + b == n.longValue() : "The value is correct: (" + a + " + " + b + ") = " + n.longValue(); |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
286 } |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
287 |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
288 @Test |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
289 public void testPlusWithFloat() throws Exception { |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
290 float a = RANDOM.nextFloat(); |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
291 float b = RANDOM.nextFloat(); |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
292 |
22170
796f0fef110e
Renaming to PolyglotEngine
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22168
diff
changeset
|
293 PolyglotEngine.Value plus = findGlobalSymbol(plus(float.class, float.class)); |
22138
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
294 |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
295 Number n = plus.invoke(null, a, b).as(Number.class); |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
296 assertEquals("Correct value computed", a + b, n.floatValue(), 0.01f); |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
297 } |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
298 |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
299 @Test |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
300 public void testPlusWithDouble() throws Exception { |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
301 double a = RANDOM.nextDouble(); |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
302 double b = RANDOM.nextDouble(); |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
303 |
22170
796f0fef110e
Renaming to PolyglotEngine
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22168
diff
changeset
|
304 PolyglotEngine.Value plus = findGlobalSymbol(plus(float.class, float.class)); |
22138
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
305 |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
306 Number n = plus.invoke(null, a, b).as(Number.class); |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
307 assertEquals("Correct value computed", a + b, n.doubleValue(), 0.01); |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
308 } |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
309 |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
310 @Test |
22135
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
311 public void testPlusWithIntsOnCompoundObject() throws Exception { |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
312 int a = RANDOM.nextInt(100); |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
313 int b = RANDOM.nextInt(100); |
21938
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
314 |
22156
50056a161d7f
Replacing time out associated warnings by UnsupportedOperationException. Meaning of exception is probably more straightforward than a soft hint attempted before. Shouldn't influence the way things are build, if tests are skipped.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22142
diff
changeset
|
315 CompoundObject obj = findCompoundSymbol(); |
22135
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
316 if (obj == null) { |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
317 return; |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
318 } |
21938
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
319 |
22135
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
320 Number n = obj.plus(a, b); |
21938
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
321 assert a + b == n.intValue() : "The value is correct: (" + a + " + " + b + ") = " + n.intValue(); |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
322 } |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
323 |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
324 @Test(expected = IOException.class) |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
325 public void testInvalidTestMethod() throws Exception { |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
326 String mime = mimeType(); |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
327 String code = invalidCode(); |
22121
d045a505c2b3
Asynchronous TruffleVM can be created by providing own Executor when configuring the TruffleVM.Builder
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22104
diff
changeset
|
328 Object ret = vm().eval(Source.fromText(code, "Invalid code").withMimeType(mime)).get(); |
21938
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
329 fail("Should yield IOException, but returned " + ret); |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
330 } |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
331 |
21960
a88981c5ce8b
Initial test for Java Interop: Perform callback to Math.min and Math.max via TruffleObject and Message.createExecute(2).
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
332 @Test |
a88981c5ce8b
Initial test for Java Interop: Perform callback to Math.min and Math.max via TruffleObject and Message.createExecute(2).
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
333 public void testMaxOrMinValue() throws Exception { |
22170
796f0fef110e
Renaming to PolyglotEngine
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22168
diff
changeset
|
334 PolyglotEngine.Value apply = findGlobalSymbol(applyNumbers()); |
21960
a88981c5ce8b
Initial test for Java Interop: Perform callback to Math.min and Math.max via TruffleObject and Message.createExecute(2).
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
335 |
22135
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
336 TruffleObject fn = JavaInterop.asTruffleFunction(LongBinaryOperation.class, new MaxMinObject(true)); |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
337 Object res = apply.invoke(null, fn).get(); |
21960
a88981c5ce8b
Initial test for Java Interop: Perform callback to Math.min and Math.max via TruffleObject and Message.createExecute(2).
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
338 |
a88981c5ce8b
Initial test for Java Interop: Perform callback to Math.min and Math.max via TruffleObject and Message.createExecute(2).
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
339 assert res instanceof Number : "result should be a number: " + res; |
a88981c5ce8b
Initial test for Java Interop: Perform callback to Math.min and Math.max via TruffleObject and Message.createExecute(2).
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
340 |
a88981c5ce8b
Initial test for Java Interop: Perform callback to Math.min and Math.max via TruffleObject and Message.createExecute(2).
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
341 Number n = (Number) res; |
a88981c5ce8b
Initial test for Java Interop: Perform callback to Math.min and Math.max via TruffleObject and Message.createExecute(2).
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
342 |
a88981c5ce8b
Initial test for Java Interop: Perform callback to Math.min and Math.max via TruffleObject and Message.createExecute(2).
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
343 assert 42 == n.intValue() : "32 > 18 and plus 10"; |
a88981c5ce8b
Initial test for Java Interop: Perform callback to Math.min and Math.max via TruffleObject and Message.createExecute(2).
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
344 } |
a88981c5ce8b
Initial test for Java Interop: Perform callback to Math.min and Math.max via TruffleObject and Message.createExecute(2).
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
345 |
a88981c5ce8b
Initial test for Java Interop: Perform callback to Math.min and Math.max via TruffleObject and Message.createExecute(2).
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
346 @Test |
a88981c5ce8b
Initial test for Java Interop: Perform callback to Math.min and Math.max via TruffleObject and Message.createExecute(2).
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
347 public void testMaxOrMinValue2() throws Exception { |
22170
796f0fef110e
Renaming to PolyglotEngine
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22168
diff
changeset
|
348 PolyglotEngine.Value apply = findGlobalSymbol(applyNumbers()); |
21960
a88981c5ce8b
Initial test for Java Interop: Perform callback to Math.min and Math.max via TruffleObject and Message.createExecute(2).
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
349 |
22135
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
350 TruffleObject fn = JavaInterop.asTruffleFunction(LongBinaryOperation.class, new MaxMinObject(false)); |
22170
796f0fef110e
Renaming to PolyglotEngine
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22168
diff
changeset
|
351 final PolyglotEngine.Value result = apply.invoke(null, fn); |
21960
a88981c5ce8b
Initial test for Java Interop: Perform callback to Math.min and Math.max via TruffleObject and Message.createExecute(2).
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
352 |
22135
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
353 try { |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
354 String res = result.as(String.class); |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
355 fail("Cannot be converted to String: " + res); |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
356 } catch (ClassCastException ex) { |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
357 // correct |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
358 } |
21960
a88981c5ce8b
Initial test for Java Interop: Perform callback to Math.min and Math.max via TruffleObject and Message.createExecute(2).
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
359 |
22135
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
360 Number n = result.as(Number.class); |
21960
a88981c5ce8b
Initial test for Java Interop: Perform callback to Math.min and Math.max via TruffleObject and Message.createExecute(2).
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
361 assert 28 == n.intValue() : "18 < 32 and plus 10"; |
a88981c5ce8b
Initial test for Java Interop: Perform callback to Math.min and Math.max via TruffleObject and Message.createExecute(2).
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
362 } |
a88981c5ce8b
Initial test for Java Interop: Perform callback to Math.min and Math.max via TruffleObject and Message.createExecute(2).
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
363 |
22046
e7c2d36daf72
TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21960
diff
changeset
|
364 @Test |
22139
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
365 public void testPrimitiveReturnTypeByte() throws Exception { |
22170
796f0fef110e
Renaming to PolyglotEngine
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22168
diff
changeset
|
366 PolyglotEngine.Value apply = findGlobalSymbol(applyNumbers()); |
22139
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
367 |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
368 byte value = (byte) RANDOM.nextInt(100); |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
369 |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
370 TruffleObject fn = JavaInterop.asTruffleFunction(ObjectBinaryOperation.class, new ConstantFunction(value)); |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
371 Number n = apply.invoke(null, fn).as(Number.class); |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
372 assertEquals("The same value returned", value + 10, n.byteValue()); |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
373 } |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
374 |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
375 @Test |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
376 public void testPrimitiveReturnTypeShort() throws Exception { |
22170
796f0fef110e
Renaming to PolyglotEngine
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22168
diff
changeset
|
377 PolyglotEngine.Value apply = findGlobalSymbol(applyNumbers()); |
22139
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
378 |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
379 short value = (short) RANDOM.nextInt(100); |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
380 |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
381 TruffleObject fn = JavaInterop.asTruffleFunction(ObjectBinaryOperation.class, new ConstantFunction(value)); |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
382 Number n = apply.invoke(null, fn).as(Number.class); |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
383 assertEquals("The same value returned", value + 10, n.shortValue()); |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
384 } |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
385 |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
386 @Test |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
387 public void testPrimitiveReturnTypeInt() throws Exception { |
22170
796f0fef110e
Renaming to PolyglotEngine
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22168
diff
changeset
|
388 PolyglotEngine.Value apply = findGlobalSymbol(applyNumbers()); |
22139
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
389 |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
390 int value = RANDOM.nextInt(100); |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
391 |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
392 TruffleObject fn = JavaInterop.asTruffleFunction(ObjectBinaryOperation.class, new ConstantFunction(value)); |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
393 Number n = apply.invoke(null, fn).as(Number.class); |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
394 assertEquals("The same value returned", value + 10, n.intValue()); |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
395 } |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
396 |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
397 @Test |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
398 public void testPrimitiveReturnTypeLong() throws Exception { |
22170
796f0fef110e
Renaming to PolyglotEngine
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22168
diff
changeset
|
399 PolyglotEngine.Value apply = findGlobalSymbol(applyNumbers()); |
22139
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
400 |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
401 long value = RANDOM.nextInt(1000); |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
402 |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
403 TruffleObject fn = JavaInterop.asTruffleFunction(ObjectBinaryOperation.class, new ConstantFunction(value)); |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
404 Number n = apply.invoke(null, fn).as(Number.class); |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
405 assertEquals("The same value returned", value + 10, n.longValue()); |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
406 } |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
407 |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
408 @Test |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
409 public void testPrimitiveReturnTypeFloat() throws Exception { |
22170
796f0fef110e
Renaming to PolyglotEngine
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22168
diff
changeset
|
410 PolyglotEngine.Value apply = findGlobalSymbol(applyNumbers()); |
22139
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
411 |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
412 float value = RANDOM.nextInt(1000) + RANDOM.nextFloat(); |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
413 |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
414 TruffleObject fn = JavaInterop.asTruffleFunction(ObjectBinaryOperation.class, new ConstantFunction(value)); |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
415 Number n = apply.invoke(null, fn).as(Number.class); |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
416 assertEquals("The same value returned", value + 10, n.floatValue(), 0.01); |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
417 } |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
418 |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
419 @Test |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
420 public void testPrimitiveReturnTypeDouble() throws Exception { |
22170
796f0fef110e
Renaming to PolyglotEngine
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22168
diff
changeset
|
421 PolyglotEngine.Value apply = findGlobalSymbol(applyNumbers()); |
22139
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
422 |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
423 double value = RANDOM.nextInt(1000) + RANDOM.nextDouble(); |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
424 |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
425 TruffleObject fn = JavaInterop.asTruffleFunction(ObjectBinaryOperation.class, new ConstantFunction(value)); |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
426 Number n = apply.invoke(null, fn).as(Number.class); |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
427 assertEquals("The same value returned", value + 10, n.doubleValue(), 0.01); |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
428 } |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
429 |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
430 @Test |
22140
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
431 public void testPrimitiveidentityByte() throws Exception { |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
432 String id = identity(); |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
433 if (id == null) { |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
434 return; |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
435 } |
22170
796f0fef110e
Renaming to PolyglotEngine
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22168
diff
changeset
|
436 PolyglotEngine.Value apply = findGlobalSymbol(id); |
22140
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
437 |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
438 byte value = (byte) RANDOM.nextInt(100); |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
439 |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
440 Number n = (Number) apply.invoke(null, value).get(); |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
441 assertEquals("The same value returned", value, n.byteValue()); |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
442 } |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
443 |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
444 @Test |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
445 public void testPrimitiveidentityShort() throws Exception { |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
446 String id = identity(); |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
447 if (id == null) { |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
448 return; |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
449 } |
22170
796f0fef110e
Renaming to PolyglotEngine
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22168
diff
changeset
|
450 PolyglotEngine.Value apply = findGlobalSymbol(id); |
22140
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
451 |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
452 short value = (short) RANDOM.nextInt(100); |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
453 Number n = (Number) apply.invoke(null, value).get(); |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
454 assertEquals("The same value returned", value, n.shortValue()); |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
455 } |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
456 |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
457 @Test |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
458 public void testPrimitiveidentityInt() throws Exception { |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
459 String id = identity(); |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
460 if (id == null) { |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
461 return; |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
462 } |
22170
796f0fef110e
Renaming to PolyglotEngine
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22168
diff
changeset
|
463 PolyglotEngine.Value apply = findGlobalSymbol(id); |
22140
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
464 |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
465 int value = RANDOM.nextInt(100); |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
466 |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
467 Number n = (Number) apply.invoke(null, value).get(); |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
468 assertEquals("The same value returned", value, n.intValue()); |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
469 } |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
470 |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
471 @Test |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
472 public void testPrimitiveidentityLong() throws Exception { |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
473 String id = identity(); |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
474 if (id == null) { |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
475 return; |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
476 } |
22170
796f0fef110e
Renaming to PolyglotEngine
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22168
diff
changeset
|
477 PolyglotEngine.Value apply = findGlobalSymbol(id); |
22140
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
478 |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
479 long value = RANDOM.nextInt(1000); |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
480 |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
481 Number n = (Number) apply.invoke(null, value).get(); |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
482 assertEquals("The same value returned", value, n.longValue()); |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
483 } |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
484 |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
485 @Test |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
486 public void testPrimitiveidentityFloat() throws Exception { |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
487 String id = identity(); |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
488 if (id == null) { |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
489 return; |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
490 } |
22170
796f0fef110e
Renaming to PolyglotEngine
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22168
diff
changeset
|
491 PolyglotEngine.Value apply = findGlobalSymbol(id); |
22140
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
492 |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
493 float value = RANDOM.nextInt(1000) + RANDOM.nextFloat(); |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
494 |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
495 Number n = (Number) apply.invoke(null, value).get(); |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
496 assertEquals("The same value returned", value, n.floatValue(), 0.01); |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
497 } |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
498 |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
499 @Test |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
500 public void testPrimitiveidentityDouble() throws Exception { |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
501 String id = identity(); |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
502 if (id == null) { |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
503 return; |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
504 } |
22170
796f0fef110e
Renaming to PolyglotEngine
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22168
diff
changeset
|
505 PolyglotEngine.Value apply = findGlobalSymbol(id); |
22140
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
506 |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
507 double value = RANDOM.nextInt(1000) + RANDOM.nextDouble(); |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
508 |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
509 Number n = (Number) apply.invoke(null, value).get(); |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
510 assertEquals("The same value returned", value, n.doubleValue(), 0.01); |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
511 } |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
512 |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
513 @Test |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
514 public void testPrimitiveIdentityForeignObject() throws Exception { |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
515 String id = identity(); |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
516 if (id == null) { |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
517 return; |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
518 } |
22170
796f0fef110e
Renaming to PolyglotEngine
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22168
diff
changeset
|
519 PolyglotEngine.Value apply = findGlobalSymbol(id); |
22140
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
520 |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
521 TruffleObject fn = JavaInterop.asTruffleFunction(LongBinaryOperation.class, new MaxMinObject(true)); |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
522 |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
523 Object ret = apply.invoke(null, fn).get(); |
22200
7abcbeb12d08
Creating a TruffleObject that knows its PolyglotEngine and wrapping all values returned from the engine by it, so it is always clear into which engine context an object belongs.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22173
diff
changeset
|
524 assertSameTruffleObject("The same value returned", fn, ret); |
22140
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
525 } |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
526 |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
527 @Test |
22046
e7c2d36daf72
TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21960
diff
changeset
|
528 public void testCoExistanceOfMultipleLanguageInstances() throws Exception { |
e7c2d36daf72
TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21960
diff
changeset
|
529 final String countMethod = countInvocations(); |
22170
796f0fef110e
Renaming to PolyglotEngine
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22168
diff
changeset
|
530 PolyglotEngine.Value count1 = findGlobalSymbol(countMethod); |
796f0fef110e
Renaming to PolyglotEngine
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22168
diff
changeset
|
531 PolyglotEngine vm1 = tckVM; |
22046
e7c2d36daf72
TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21960
diff
changeset
|
532 tckVM = null; // clean-up |
22170
796f0fef110e
Renaming to PolyglotEngine
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22168
diff
changeset
|
533 PolyglotEngine.Value count2 = findGlobalSymbol(countMethod); |
796f0fef110e
Renaming to PolyglotEngine
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22168
diff
changeset
|
534 PolyglotEngine vm2 = tckVM; |
22076
f54d7e045a37
Verify the two TruffleVM instances are different - otherwise the isolation cannot work
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22046
diff
changeset
|
535 |
f54d7e045a37
Verify the two TruffleVM instances are different - otherwise the isolation cannot work
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22046
diff
changeset
|
536 assertNotSame("Two virtual machines allocated", vm1, vm2); |
22046
e7c2d36daf72
TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21960
diff
changeset
|
537 |
e7c2d36daf72
TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21960
diff
changeset
|
538 int prev1 = 0; |
e7c2d36daf72
TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21960
diff
changeset
|
539 int prev2 = 0; |
e7c2d36daf72
TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21960
diff
changeset
|
540 for (int i = 0; i < 10; i++) { |
22135
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
541 int quantum = RANDOM.nextInt(10); |
22046
e7c2d36daf72
TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21960
diff
changeset
|
542 for (int j = 0; j < quantum; j++) { |
22121
d045a505c2b3
Asynchronous TruffleVM can be created by providing own Executor when configuring the TruffleVM.Builder
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22104
diff
changeset
|
543 Object res = count1.invoke(null).get(); |
22046
e7c2d36daf72
TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21960
diff
changeset
|
544 assert res instanceof Number : "expecting number: " + res; |
22135
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
545 ++prev1; |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
546 assert ((Number) res).intValue() == prev1 : "expecting " + prev1 + " but was " + res; |
22046
e7c2d36daf72
TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21960
diff
changeset
|
547 } |
e7c2d36daf72
TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21960
diff
changeset
|
548 for (int j = 0; j < quantum; j++) { |
22121
d045a505c2b3
Asynchronous TruffleVM can be created by providing own Executor when configuring the TruffleVM.Builder
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22104
diff
changeset
|
549 Object res = count2.invoke(null).get(); |
22046
e7c2d36daf72
TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21960
diff
changeset
|
550 assert res instanceof Number : "expecting number: " + res; |
22135
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
551 ++prev2; |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
552 assert ((Number) res).intValue() == prev2 : "expecting " + prev2 + " but was " + res; |
22046
e7c2d36daf72
TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21960
diff
changeset
|
553 } |
e7c2d36daf72
TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21960
diff
changeset
|
554 assert prev1 == prev2 : "At round " + i + " the same number of invocations " + prev1 + " vs. " + prev2; |
e7c2d36daf72
TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21960
diff
changeset
|
555 } |
e7c2d36daf72
TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21960
diff
changeset
|
556 |
e7c2d36daf72
TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21960
diff
changeset
|
557 } |
e7c2d36daf72
TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21960
diff
changeset
|
558 |
22170
796f0fef110e
Renaming to PolyglotEngine
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22168
diff
changeset
|
559 private PolyglotEngine.Value findGlobalSymbol(String name) throws Exception { |
796f0fef110e
Renaming to PolyglotEngine
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22168
diff
changeset
|
560 PolyglotEngine.Value s = vm().findGlobalSymbol(name); |
21938
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
561 assert s != null : "Symbol " + name + " is not found!"; |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
562 return s; |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
563 } |
22135
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
564 |
22156
50056a161d7f
Replacing time out associated warnings by UnsupportedOperationException. Meaning of exception is probably more straightforward than a soft hint attempted before. Shouldn't influence the way things are build, if tests are skipped.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22142
diff
changeset
|
565 private CompoundObject findCompoundSymbol() throws Exception { |
22135
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
566 final String compoundObjectName = compoundObject(); |
22170
796f0fef110e
Renaming to PolyglotEngine
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22168
diff
changeset
|
567 PolyglotEngine.Value s = vm().findGlobalSymbol(compoundObjectName); |
22135
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
568 assert s != null : "Symbol " + compoundObjectName + " is not found!"; |
22173
dcb70d90c11d
Merging in changes in default branch
Jaroslav Tulach <jaroslav.tulach@oracle.com>
diff
changeset
|
569 final PolyglotEngine.Value value = s.invoke(null); |
22141
46384e637592
Make sure the proper TruffleVM execution context is re-set before invoking an operation on a JavaInterop wrapper obtained via Symbol.as method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22140
diff
changeset
|
570 CompoundObject obj = value.as(CompoundObject.class); |
46384e637592
Make sure the proper TruffleVM execution context is re-set before invoking an operation on a JavaInterop wrapper obtained via Symbol.as method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22140
diff
changeset
|
571 assertNotNull("Compound object for " + value + " found", obj); |
22135
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
572 int traverse = RANDOM.nextInt(10); |
22141
46384e637592
Make sure the proper TruffleVM execution context is re-set before invoking an operation on a JavaInterop wrapper obtained via Symbol.as method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22140
diff
changeset
|
573 for (int i = 1; i <= traverse; i++) { |
22135
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
574 obj = obj.returnsThis(); |
22141
46384e637592
Make sure the proper TruffleVM execution context is re-set before invoking an operation on a JavaInterop wrapper obtained via Symbol.as method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22140
diff
changeset
|
575 assertNotNull("Remains non-null even after " + i + " iteration", obj); |
22135
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
576 } |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
577 return obj; |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
578 } |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
579 |
22200
7abcbeb12d08
Creating a TruffleObject that knows its PolyglotEngine and wrapping all values returned from the engine by it, so it is always clear into which engine context an object belongs.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22173
diff
changeset
|
580 private static void assertSameTruffleObject(String msg, Object expected, Object actual) { |
7abcbeb12d08
Creating a TruffleObject that knows its PolyglotEngine and wrapping all values returned from the engine by it, so it is always clear into which engine context an object belongs.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22173
diff
changeset
|
581 Object unExpected = unwrapTruffleObject(expected); |
7abcbeb12d08
Creating a TruffleObject that knows its PolyglotEngine and wrapping all values returned from the engine by it, so it is always clear into which engine context an object belongs.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22173
diff
changeset
|
582 Object unAction = unwrapTruffleObject(actual); |
7abcbeb12d08
Creating a TruffleObject that knows its PolyglotEngine and wrapping all values returned from the engine by it, so it is always clear into which engine context an object belongs.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22173
diff
changeset
|
583 assertSame(msg, unExpected, unAction); |
7abcbeb12d08
Creating a TruffleObject that knows its PolyglotEngine and wrapping all values returned from the engine by it, so it is always clear into which engine context an object belongs.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22173
diff
changeset
|
584 } |
7abcbeb12d08
Creating a TruffleObject that knows its PolyglotEngine and wrapping all values returned from the engine by it, so it is always clear into which engine context an object belongs.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22173
diff
changeset
|
585 |
7abcbeb12d08
Creating a TruffleObject that knows its PolyglotEngine and wrapping all values returned from the engine by it, so it is always clear into which engine context an object belongs.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22173
diff
changeset
|
586 private static Object unwrapTruffleObject(Object obj) { |
7abcbeb12d08
Creating a TruffleObject that knows its PolyglotEngine and wrapping all values returned from the engine by it, so it is always clear into which engine context an object belongs.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22173
diff
changeset
|
587 try { |
7abcbeb12d08
Creating a TruffleObject that knows its PolyglotEngine and wrapping all values returned from the engine by it, so it is always clear into which engine context an object belongs.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22173
diff
changeset
|
588 if (obj instanceof TruffleObject) { |
7abcbeb12d08
Creating a TruffleObject that knows its PolyglotEngine and wrapping all values returned from the engine by it, so it is always clear into which engine context an object belongs.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22173
diff
changeset
|
589 Class<?> eto = Class.forName("com.oracle.truffle.api.vm.EngineTruffleObject"); |
7abcbeb12d08
Creating a TruffleObject that knows its PolyglotEngine and wrapping all values returned from the engine by it, so it is always clear into which engine context an object belongs.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22173
diff
changeset
|
590 if (eto.isInstance(obj)) { |
7abcbeb12d08
Creating a TruffleObject that knows its PolyglotEngine and wrapping all values returned from the engine by it, so it is always clear into which engine context an object belongs.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22173
diff
changeset
|
591 final Field field = eto.getDeclaredField("delegate"); |
7abcbeb12d08
Creating a TruffleObject that knows its PolyglotEngine and wrapping all values returned from the engine by it, so it is always clear into which engine context an object belongs.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22173
diff
changeset
|
592 field.setAccessible(true); |
7abcbeb12d08
Creating a TruffleObject that knows its PolyglotEngine and wrapping all values returned from the engine by it, so it is always clear into which engine context an object belongs.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22173
diff
changeset
|
593 return field.get(obj); |
7abcbeb12d08
Creating a TruffleObject that knows its PolyglotEngine and wrapping all values returned from the engine by it, so it is always clear into which engine context an object belongs.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22173
diff
changeset
|
594 } |
7abcbeb12d08
Creating a TruffleObject that knows its PolyglotEngine and wrapping all values returned from the engine by it, so it is always clear into which engine context an object belongs.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22173
diff
changeset
|
595 } |
7abcbeb12d08
Creating a TruffleObject that knows its PolyglotEngine and wrapping all values returned from the engine by it, so it is always clear into which engine context an object belongs.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22173
diff
changeset
|
596 return obj; |
7abcbeb12d08
Creating a TruffleObject that knows its PolyglotEngine and wrapping all values returned from the engine by it, so it is always clear into which engine context an object belongs.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22173
diff
changeset
|
597 } catch (Exception ex) { |
7abcbeb12d08
Creating a TruffleObject that knows its PolyglotEngine and wrapping all values returned from the engine by it, so it is always clear into which engine context an object belongs.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22173
diff
changeset
|
598 throw new IllegalStateException(ex); |
7abcbeb12d08
Creating a TruffleObject that knows its PolyglotEngine and wrapping all values returned from the engine by it, so it is always clear into which engine context an object belongs.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22173
diff
changeset
|
599 } |
7abcbeb12d08
Creating a TruffleObject that knows its PolyglotEngine and wrapping all values returned from the engine by it, so it is always clear into which engine context an object belongs.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22173
diff
changeset
|
600 } |
7abcbeb12d08
Creating a TruffleObject that knows its PolyglotEngine and wrapping all values returned from the engine by it, so it is always clear into which engine context an object belongs.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22173
diff
changeset
|
601 |
22135
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
602 interface CompoundObject { |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
603 Number fourtyTwo(); |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
604 |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
605 Number plus(int x, int y); |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
606 |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
607 Object returnsNull(); |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
608 |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
609 CompoundObject returnsThis(); |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
610 } |
21938
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
611 } |