Mercurial > hg > truffle
annotate truffle/com.oracle.truffle.tck/src/com/oracle/truffle/tck/TruffleTCK.java @ 22139:597953a8e6f0
Testing behavior of primitive types returned from an interop method.
author | Jaroslav Tulach <jaroslav.tulach@oracle.com> |
---|---|
date | Wed, 09 Sep 2015 19:18:44 +0200 |
parents | a583d7ffd285 |
children | 92906003d607 |
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; |
21938
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
30 import com.oracle.truffle.api.vm.TruffleVM; |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
31 import java.io.IOException; |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
32 import java.util.Random; |
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
|
33 import java.util.logging.Level; |
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
|
34 import java.util.logging.Logger; |
21938
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
35 import static org.junit.Assert.*; |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
36 import org.junit.Test; |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
37 |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
38 /** |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
39 * 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
|
40 * 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
|
41 * include in your test suite. |
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 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
|
44 private static final Logger LOG = Logger.getLogger(TruffleTCK.class.getName()); |
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
|
45 private static final Random RANDOM = new Random(); |
21938
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
46 private TruffleVM tckVM; |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
47 |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
48 protected TruffleTCK() { |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
49 } |
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 /** |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
52 * This methods is called before first test is executed. It's purpose is to set a TruffleVM with |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
53 * your language up, so it is ready for testing. |
22104
cf19259edf87
TruffleVM.eval and Source.withMimeType
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22076
diff
changeset
|
54 * {@link TruffleVM#eval(com.oracle.truffle.api.source.Source) Execute} any scripts you need, |
cf19259edf87
TruffleVM.eval and Source.withMimeType
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22076
diff
changeset
|
55 * 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
|
56 * 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
|
57 * used for internal testing. |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
58 * |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
59 * @return initialized Truffle virtual machine |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
60 * @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
|
61 */ |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
62 protected abstract TruffleVM prepareVM() throws Exception; |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
63 |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
64 /** |
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
|
65 * MIME type associated with your language. The MIME type will be passed to |
22104
cf19259edf87
TruffleVM.eval and Source.withMimeType
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22076
diff
changeset
|
66 * {@link TruffleVM#eval(com.oracle.truffle.api.source.Source)} method of the |
cf19259edf87
TruffleVM.eval and Source.withMimeType
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22076
diff
changeset
|
67 * {@link #prepareVM() created TruffleVM}. |
21938
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
68 * |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
69 * @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
|
70 */ |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
71 protected abstract String mimeType(); |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
72 |
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 * 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
|
75 * 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
|
76 * <code>42</code>. |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
77 * |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
78 * @return name of globally exported symbol |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
79 */ |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
80 protected abstract String fourtyTwo(); |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
81 |
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 * 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
|
84 * their own type representing <code>null</code>, but when such value is returned from |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
85 * {@link TruffleVM#eval}, it needs to be converted to real Java <code>null</code> by sending a |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
86 * foreign access <em>isNull</em> message. There is a test to verify it is really true. |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
87 * |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
88 * @return name of globally exported symbol |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
89 */ |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
90 protected abstract String returnsNull(); |
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 /** |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
93 * 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
|
94 * 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
|
95 * {@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
|
96 * |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
97 * @return name of globally exported symbol |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
98 */ |
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
|
99 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
|
100 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
|
101 } |
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
|
102 |
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 /** |
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 * 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
|
105 * 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
|
106 * 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
|
107 * 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
|
108 * 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
|
109 * 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
|
110 * |
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 * @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
|
112 * @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
|
113 * @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
|
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 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
|
116 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
|
117 } |
21938
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
118 |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
119 /** |
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
|
120 * 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
|
121 * 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
|
122 * 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
|
123 * 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
|
124 * |
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 * @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
|
126 */ |
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 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
|
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 /** |
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
|
130 * Name of a function that counts number of its invocations in current {@link TruffleVM} |
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
|
131 * 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
|
132 * 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
|
133 * <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
|
134 * <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
|
135 * 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
|
136 * 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
|
137 * |
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
|
138 * @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
|
139 */ |
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
|
140 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
|
141 |
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
|
142 /** |
21938
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
143 * Return a code snippet that is invalid in your language. Its |
22104
cf19259edf87
TruffleVM.eval and Source.withMimeType
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22076
diff
changeset
|
144 * {@link TruffleVM#eval(com.oracle.truffle.api.source.Source) evaluation} should fail and yield |
21938
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
145 * an exception. |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
146 * |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
147 * @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
|
148 */ |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
149 protected abstract String invalidCode(); |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
150 |
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
|
151 /** |
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
|
152 * 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
|
153 * 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
|
154 * |
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
|
155 * <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
|
156 * <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
|
157 * '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
|
158 * '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
|
159 * '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
|
160 * '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
|
161 * }; |
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
|
162 * <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
|
163 * </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
|
164 * |
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
|
165 * 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
|
166 * 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
|
167 * {@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
|
168 * <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
|
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 * @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
|
171 */ |
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 protected String 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
|
173 return 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
|
174 } |
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 |
21938
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
176 private TruffleVM vm() throws Exception { |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
177 if (tckVM == null) { |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
178 tckVM = prepareVM(); |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
179 } |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
180 return tckVM; |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
181 } |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
182 |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
183 // |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
184 // The tests |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
185 // |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
186 |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
187 @Test |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
188 public void testFortyTwo() throws Exception { |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
189 TruffleVM.Symbol fourtyTwo = findGlobalSymbol(fourtyTwo()); |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
190 |
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
|
191 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
|
192 |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
193 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
|
194 |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
195 Number n = (Number) res; |
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 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
|
198 } |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
199 |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
200 @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
|
201 public void testFortyTwoWithCompoundObject() 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
|
202 CompoundObject obj = findCompoundSymbol("testFortyTwoWithCompoundObject"); |
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
|
203 if (obj == null) { |
21938
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
204 return; |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
205 } |
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
|
206 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
|
207 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
|
208 } |
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
|
209 |
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
|
210 @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
|
211 public void testNull() throws Exception { |
21938
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
212 TruffleVM.Symbol retNull = findGlobalSymbol(returnsNull()); |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
213 |
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
|
214 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
|
215 |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
216 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
|
217 } |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
218 |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
219 @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
|
220 public void testNullInCompoundObject() 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
|
221 CompoundObject obj = findCompoundSymbol("testNullInCompoundObject"); |
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 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
|
223 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
|
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 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
|
226 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
|
227 } |
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
|
228 |
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
|
229 @Test |
21938
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
230 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
|
231 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
|
232 int b = RANDOM.nextInt(100); |
21938
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
233 |
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
|
234 TruffleVM.Symbol 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
|
235 |
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
|
236 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
|
237 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
|
238 } |
21938
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
239 |
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
|
240 @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
|
241 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
|
242 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
|
243 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
|
244 |
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
|
245 TruffleVM.Symbol plus = findGlobalSymbol(plus(byte.class, byte.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
|
246 |
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
|
247 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
|
248 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
|
249 } |
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
|
250 |
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
|
251 @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
|
252 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
|
253 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
|
254 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
|
255 |
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 TruffleVM.Symbol plus = findGlobalSymbol(plus(short.class, short.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
|
257 |
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 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
|
259 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
|
260 } |
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 @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
|
263 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
|
264 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
|
265 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
|
266 |
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 TruffleVM.Symbol plus = findGlobalSymbol(plus(long.class, long.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
|
268 |
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 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
|
270 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
|
271 } |
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 @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
|
274 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
|
275 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
|
276 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
|
277 |
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 TruffleVM.Symbol plus = findGlobalSymbol(plus(float.class, float.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
|
279 |
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 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
|
281 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
|
282 } |
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 @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
|
285 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
|
286 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
|
287 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
|
288 |
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 TruffleVM.Symbol plus = findGlobalSymbol(plus(float.class, float.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
|
290 |
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 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
|
292 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
|
293 } |
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 @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
|
296 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
|
297 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
|
298 int b = RANDOM.nextInt(100); |
21938
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
299 |
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
|
300 CompoundObject obj = findCompoundSymbol("testPlusWithIntsOnCompoundObject"); |
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
|
301 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
|
302 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
|
303 } |
21938
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
304 |
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
|
305 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
|
306 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
|
307 } |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
308 |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
309 @Test(expected = IOException.class) |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
310 public void testInvalidTestMethod() throws Exception { |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
311 String mime = mimeType(); |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
312 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
|
313 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
|
314 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
|
315 } |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
316 |
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
|
317 @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
|
318 public void testMaxOrMinValue() throws Exception { |
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
|
319 TruffleVM.Symbol apply = findGlobalSymbol(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
|
320 |
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
|
321 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
|
322 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
|
323 |
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
|
324 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
|
325 |
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
|
326 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
|
327 |
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
|
328 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
|
329 } |
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
|
330 |
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
|
331 @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
|
332 public void testMaxOrMinValue2() throws Exception { |
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 TruffleVM.Symbol apply = findGlobalSymbol(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
|
334 |
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
|
335 TruffleObject fn = JavaInterop.asTruffleFunction(LongBinaryOperation.class, new MaxMinObject(false)); |
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 final TruffleVM.Symbol 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
|
337 |
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
|
338 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
|
339 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
|
340 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
|
341 } 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
|
342 // 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
|
343 } |
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
|
344 |
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
|
345 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
|
346 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
|
347 } |
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
|
348 |
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
|
349 @Test |
22139
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
350 public void testPrimitiveReturnTypeByte() throws Exception { |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
351 TruffleVM.Symbol apply = findGlobalSymbol(applyNumbers()); |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
352 |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
353 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
|
354 |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
355 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
|
356 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
|
357 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
|
358 } |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
359 |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
360 @Test |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
361 public void testPrimitiveReturnTypeShort() throws Exception { |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
362 TruffleVM.Symbol apply = findGlobalSymbol(applyNumbers()); |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
363 |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
364 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
|
365 |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
366 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
|
367 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
|
368 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
|
369 } |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
370 |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
371 @Test |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
372 public void testPrimitiveReturnTypeInt() throws Exception { |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
373 TruffleVM.Symbol apply = findGlobalSymbol(applyNumbers()); |
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 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
|
376 |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
377 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
|
378 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
|
379 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
|
380 } |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
381 |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
382 @Test |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
383 public void testPrimitiveReturnTypeLong() throws Exception { |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
384 TruffleVM.Symbol apply = findGlobalSymbol(applyNumbers()); |
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 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
|
387 |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
388 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
|
389 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
|
390 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
|
391 } |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
392 |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
393 @Test |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
394 public void testPrimitiveReturnTypeFloat() throws Exception { |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
395 TruffleVM.Symbol apply = findGlobalSymbol(applyNumbers()); |
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 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
|
398 |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
399 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
|
400 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
|
401 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
|
402 } |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
403 |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
404 @Test |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
405 public void testPrimitiveReturnTypeDouble() throws Exception { |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
406 TruffleVM.Symbol apply = findGlobalSymbol(applyNumbers()); |
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 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
|
409 |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
410 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
|
411 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
|
412 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
|
413 } |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
414 |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
415 @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
|
416 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
|
417 final String countMethod = 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
|
418 TruffleVM.Symbol count1 = findGlobalSymbol(countMethod); |
22076
f54d7e045a37
Verify the two TruffleVM instances are different - otherwise the isolation cannot work
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22046
diff
changeset
|
419 TruffleVM 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
|
420 tckVM = null; // clean-up |
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
|
421 TruffleVM.Symbol count2 = findGlobalSymbol(countMethod); |
22076
f54d7e045a37
Verify the two TruffleVM instances are different - otherwise the isolation cannot work
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22046
diff
changeset
|
422 TruffleVM vm2 = tckVM; |
f54d7e045a37
Verify the two TruffleVM instances are different - otherwise the isolation cannot work
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22046
diff
changeset
|
423 |
f54d7e045a37
Verify the two TruffleVM instances are different - otherwise the isolation cannot work
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22046
diff
changeset
|
424 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
|
425 |
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
|
426 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
|
427 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
|
428 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
|
429 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
|
430 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
|
431 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
|
432 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
|
433 ++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
|
434 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
|
435 } |
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
|
436 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
|
437 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
|
438 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
|
439 ++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
|
440 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
|
441 } |
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
|
442 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
|
443 } |
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
|
444 |
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
|
445 } |
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
|
446 |
21938
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
447 private TruffleVM.Symbol findGlobalSymbol(String name) throws Exception { |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
448 TruffleVM.Symbol s = vm().findGlobalSymbol(name); |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
449 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
|
450 return s; |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
451 } |
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
|
452 |
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
|
453 private CompoundObject findCompoundSymbol(String name) 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
|
454 final String compoundObjectName = 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
|
455 if (compoundObjectName == 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
|
456 final long introduced = 1441616302340L; |
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
|
457 long wait = (System.currentTimeMillis() - introduced) / 3600; |
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
|
458 if (wait < 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
|
459 wait = 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
|
460 } |
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
|
461 LOG.log(Level.SEVERE, "compoundObject() method not overriden! Skipping {1} test for now. But sleeping for {0} ms.", new Object[]{wait, name}); |
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
|
462 Thread.sleep(wait); |
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
|
463 return 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
|
464 } |
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
|
465 TruffleVM.Symbol s = vm().findGlobalSymbol(compoundObjectName); |
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
|
466 assert s != null : "Symbol " + compoundObjectName + " is not found!"; |
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
|
467 CompoundObject obj = s.invoke(null).as(CompoundObject.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
|
468 int traverse = RANDOM.nextInt(10); |
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
|
469 while (traverse-- >= 0) { |
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
|
470 obj = obj.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
|
471 } |
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
|
472 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
|
473 } |
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
|
474 |
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
|
475 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
|
476 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
|
477 |
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
|
478 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
|
479 |
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
|
480 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
|
481 |
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
|
482 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
|
483 } |
21938
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
484 } |