Skip to content

Commit bb4a24b

Browse files
author
Matthias Grimmer
committed
Merge pull request #16 in G/truffle from ~MATTHIAS.G.GRIMMER_ORACLE.COM/truffle:master to master
* commit 'feec4a84e5157b24c01329c341c69b389ecdd065': Factor language check into guard helper method in CachedObjectAccessNode Rename LanguageCheck annotation to CanResolve Use deep copy of can-resolve node of interop DSL Add tests for @Languagecheck annotation Extend Interop DSL and provide an @Languagecheck annotation, which allows expressing the language check as a node
2 parents d0afa11 + feec4a8 commit bb4a24b

File tree

20 files changed

+697
-80
lines changed

20 files changed

+697
-80
lines changed

truffle/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/interop/Snippets.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
package com.oracle.truffle.api.dsl.test.interop;
2424

2525
import com.oracle.truffle.api.interop.ForeignAccess;
26+
import com.oracle.truffle.api.interop.CanResolve;
2627
import com.oracle.truffle.api.interop.MessageResolution;
2728
import com.oracle.truffle.api.interop.Resolve;
2829
import com.oracle.truffle.api.interop.TruffleObject;
@@ -89,6 +90,14 @@ protected static int access(ExampleTruffleObject receiver,
8990
}
9091
}
9192

93+
@CanResolve
94+
public abstract static class Check extends Node {
95+
96+
protected static boolean test(TruffleObject receiver) {
97+
return receiver instanceof ExampleTruffleObject;
98+
}
99+
}
100+
92101
}
93102
// END: com.oracle.truffle.api.dsl.test.interop.Snippets.ExampleTruffleObjectMR
94103
//@formatter:on

truffle/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/interop/ValidTruffleObject1.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,6 @@ public static boolean isInstance(TruffleObject obj) {
3232

3333
@Override
3434
public ForeignAccess getForeignAccess() {
35-
return ValidTruffleObject1MRForeign.ACCESS;
35+
return null;
3636
}
3737
}
Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,9 @@
2525
import com.oracle.truffle.api.interop.ForeignAccess;
2626
import com.oracle.truffle.api.interop.TruffleObject;
2727

28-
public class ValidTruffleObject10 implements TruffleObject {
28+
public class ValidTruffleObject11 implements TruffleObject {
2929

3030
public ForeignAccess getForeignAccess() {
31-
return ValidTruffleObject10Foreign.ACCESS;
31+
return ValidTruffleObject11MRForeign.ACCESS;
3232
}
33-
34-
public static boolean isInstance(TruffleObject obj) {
35-
return obj instanceof ValidTruffleObject10;
36-
}
37-
3833
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
package com.oracle.truffle.api.dsl.test.interop;
24+
25+
import com.oracle.truffle.api.frame.VirtualFrame;
26+
import com.oracle.truffle.api.interop.CanResolve;
27+
import com.oracle.truffle.api.interop.MessageResolution;
28+
import com.oracle.truffle.api.interop.Resolve;
29+
import com.oracle.truffle.api.interop.TruffleObject;
30+
import com.oracle.truffle.api.nodes.Node;
31+
32+
@SuppressWarnings("unused")
33+
@MessageResolution(receiverType = ValidTruffleObject11.class, language = TestTruffleLanguage.class)
34+
public class ValidTruffleObject11MR {
35+
36+
@Resolve(message = "READ")
37+
public abstract static class ReadNode11 extends Node {
38+
39+
protected Object access(VirtualFrame frame, ValidTruffleObject1 receiver, Object name) {
40+
return 0;
41+
}
42+
}
43+
44+
@CanResolve
45+
public abstract static class LanguageCheck1 extends Node {
46+
47+
protected boolean test(VirtualFrame frame, TruffleObject receiver) {
48+
return receiver instanceof ValidTruffleObject11;
49+
}
50+
}
51+
52+
}
Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,12 @@
2222
*/
2323
package com.oracle.truffle.api.dsl.test.interop;
2424

25-
import com.oracle.truffle.api.frame.VirtualFrame;
25+
import com.oracle.truffle.api.interop.ForeignAccess;
26+
import com.oracle.truffle.api.interop.TruffleObject;
2627

27-
@SuppressWarnings("deprecation")
28-
@com.oracle.truffle.api.interop.AcceptMessage(value = "WRITE", receiverType = ValidTruffleObject10.class, language = TestTruffleLanguage.class)
29-
public final class AcceptMessageTest extends AcceptMessageTestBase {
28+
public class ValidTruffleObject12 implements TruffleObject {
3029

31-
@Override
32-
protected int access(VirtualFrame frame, Object receiver, Object name, Object value) {
33-
return 0;
30+
public ForeignAccess getForeignAccess() {
31+
return null;
3432
}
3533
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
package com.oracle.truffle.api.dsl.test.interop;
24+
25+
import com.oracle.truffle.api.dsl.test.ExpectError;
26+
import com.oracle.truffle.api.frame.VirtualFrame;
27+
import com.oracle.truffle.api.interop.CanResolve;
28+
import com.oracle.truffle.api.interop.MessageResolution;
29+
import com.oracle.truffle.api.interop.Resolve;
30+
import com.oracle.truffle.api.interop.TruffleObject;
31+
import com.oracle.truffle.api.nodes.Node;
32+
33+
@SuppressWarnings("unused")
34+
@MessageResolution(receiverType = ValidTruffleObject12.class, language = TestTruffleLanguage.class)
35+
@ExpectError("Only one @LanguageCheck element allowed")
36+
public class ValidTruffleObject12MR {
37+
38+
@Resolve(message = "READ")
39+
public abstract static class ReadNode12 extends Node {
40+
41+
protected Object access(VirtualFrame frame, ValidTruffleObject1 receiver, Object name) {
42+
return 0;
43+
}
44+
}
45+
46+
@CanResolve
47+
public abstract static class LanguageCheck1 extends Node {
48+
49+
protected boolean test(VirtualFrame frame, TruffleObject receiver) {
50+
return receiver instanceof ValidTruffleObject11;
51+
}
52+
}
53+
54+
@CanResolve
55+
public abstract static class LanguageCheck2 extends Node {
56+
57+
protected boolean test(VirtualFrame frame, TruffleObject receiver) {
58+
return receiver instanceof ValidTruffleObject11;
59+
}
60+
}
61+
62+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
package com.oracle.truffle.api.dsl.test.interop;
24+
25+
import com.oracle.truffle.api.dsl.test.ExpectError;
26+
import com.oracle.truffle.api.frame.VirtualFrame;
27+
import com.oracle.truffle.api.interop.CanResolve;
28+
import com.oracle.truffle.api.interop.MessageResolution;
29+
import com.oracle.truffle.api.interop.Resolve;
30+
import com.oracle.truffle.api.interop.TruffleObject;
31+
import com.oracle.truffle.api.nodes.Node;
32+
33+
@SuppressWarnings("unused")
34+
@MessageResolution(receiverType = ValidTruffleObject12.class, language = TestTruffleLanguage.class)
35+
public class ValidTruffleObject13MR {
36+
37+
@Resolve(message = "READ")
38+
public abstract static class ReadNode13 extends Node {
39+
40+
protected Object access(VirtualFrame frame, ValidTruffleObject1 receiver, Object name) {
41+
return 0;
42+
}
43+
}
44+
45+
@CanResolve
46+
public abstract static class LanguageCheck1 extends Node {
47+
48+
@ExpectError("Method must return a boolean value")
49+
protected Object test(VirtualFrame frame, TruffleObject receiver) {
50+
return receiver instanceof ValidTruffleObject11;
51+
}
52+
}
53+
54+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
package com.oracle.truffle.api.dsl.test.interop;
24+
25+
import com.oracle.truffle.api.dsl.test.ExpectError;
26+
import com.oracle.truffle.api.frame.VirtualFrame;
27+
import com.oracle.truffle.api.interop.CanResolve;
28+
import com.oracle.truffle.api.interop.MessageResolution;
29+
import com.oracle.truffle.api.interop.Resolve;
30+
import com.oracle.truffle.api.interop.TruffleObject;
31+
import com.oracle.truffle.api.nodes.Node;
32+
33+
@SuppressWarnings("unused")
34+
@MessageResolution(receiverType = ValidTruffleObject12.class, language = TestTruffleLanguage.class)
35+
public class ValidTruffleObject14MR {
36+
37+
@Resolve(message = "READ")
38+
public abstract static class ReadNode14 extends Node {
39+
40+
protected Object access(VirtualFrame frame, ValidTruffleObject1 receiver, Object name) {
41+
return 0;
42+
}
43+
}
44+
45+
@CanResolve
46+
public abstract static class LanguageCheck1 extends Node {
47+
48+
@ExpectError("The receiver type must be TruffleObject")
49+
protected boolean test(VirtualFrame frame, ValidTruffleObject12 receiver) {
50+
return false;
51+
}
52+
}
53+
54+
}

truffle/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/interop/ValidTruffleObject6.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
public class ValidTruffleObject6 implements TruffleObject {
2929

3030
public ForeignAccess getForeignAccess() {
31-
return ValidTruffleObject6MRForeign.ACCESS;
31+
return null;
3232
}
3333

3434
public static boolean isInstance(TruffleObject obj) {

truffle/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/interop/ValidTruffleObject7.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
public class ValidTruffleObject7 implements TruffleObject {
2929

3030
public ForeignAccess getForeignAccess() {
31-
return ValidTruffleObject8MRForeign.ACCESS;
31+
return null;
3232
}
3333

3434
public static boolean isInstance(TruffleObject obj) {

0 commit comments

Comments
 (0)