Skip to content

Commit bce21f2

Browse files
committed
Merge pull request #12 from graalvm/interop/annotation-processor-to-generate-classes-for-message-resolution
AcceptMessage annotation. Its annotation processor. InteropException and its subclasses. Specialized sendXYZ methods in ForeignAccess class.
2 parents add047d + 69b2258 commit bce21f2

File tree

101 files changed

+4554
-867
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+4554
-867
lines changed

mx.truffle/suite.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,10 @@
9999
"com.oracle.truffle.dsl.processor" : {
100100
"subDir" : "truffle",
101101
"sourceDirs" : ["src"],
102-
"dependencies" : ["com.oracle.truffle.api.dsl"],
102+
"dependencies" : [
103+
"com.oracle.truffle.api.dsl",
104+
"com.oracle.truffle.api.interop"
105+
],
103106
"checkstyle" : "com.oracle.truffle.dsl.processor",
104107
"javaCompliance" : "1.7",
105108
"workingSets" : "Truffle,Codegen",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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.AcceptMessage;
27+
import com.oracle.truffle.api.interop.UnknownIdentifierException;
28+
29+
//@formatter:off
30+
// BEGIN: AcceptMessageExample
31+
@AcceptMessage(value = "READ",
32+
receiverType = ExampleTruffleObject.class,
33+
language = TestTruffleLanguage.class)
34+
public final class ExampleReadNode extends ExampleReadBaseNode {
35+
36+
@Override
37+
protected Object access(VirtualFrame vf,
38+
ExampleTruffleObject receiver,
39+
String name) {
40+
if (ExampleTruffleObject.MEMBER_NAME.equals(name)) {
41+
return receiver.getValue();
42+
}
43+
throw UnknownIdentifierException.raise(name);
44+
}
45+
}
46+
// END: AcceptMessageExample
47+
//@formatter:on
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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.interop.ForeignAccess;
26+
import com.oracle.truffle.api.interop.TruffleObject;
27+
28+
public class ExampleTruffleObject implements TruffleObject {
29+
static final String MEMBER_NAME = "value";
30+
31+
private int value = 0;
32+
33+
void setValue(int value) {
34+
this.value = value;
35+
}
36+
37+
int getValue() {
38+
return value;
39+
}
40+
41+
// BEGIN: getForeignAccessMethod
42+
public ForeignAccess getForeignAccess() {
43+
return ExampleTruffleObjectForeign.ACCESS;
44+
}
45+
46+
// END: getForeignAccessMethod
47+
48+
// BEGIN: isInstanceCheck
49+
public static boolean isInstance(TruffleObject obj) {
50+
return obj instanceof ExampleTruffleObject;
51+
}
52+
// END: isInstanceCheck
53+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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.AcceptMessage;
27+
import com.oracle.truffle.api.interop.UnknownIdentifierException;
28+
29+
@AcceptMessage(value = "WRITE", receiverType = ExampleTruffleObject.class, language = TestTruffleLanguage.class)
30+
public final class ExampleWriteNode extends ExampleWriteBaseNode {
31+
32+
@Override
33+
protected int access(VirtualFrame vf, ExampleTruffleObject receiver, String name, int value) {
34+
if (ExampleTruffleObject.MEMBER_NAME.equals(name)) {
35+
receiver.setValue(value);
36+
return value;
37+
}
38+
throw UnknownIdentifierException.raise(name);
39+
}
40+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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.AcceptMessage;
28+
29+
@AcceptMessage(value = "EXECUTE", receiverType = ValidTruffleObject.class, language = TestTruffleLanguage.class)
30+
public final class Execute extends BaseExecute {
31+
@SuppressWarnings({"static-method", "unused"})
32+
@ExpectError({"access method has to have 3 arguments"})
33+
public Object access(VirtualFrame frame, ValidTruffleObject object) {
34+
return true;
35+
}
36+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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.interop.AcceptMessage;
27+
28+
@AcceptMessage(value = "EXECUTE", receiverType = ValidTruffleObject.class, language = TestTruffleLanguage.class)
29+
public final class Execute2 extends BaseExecute2 {
30+
@SuppressWarnings({"static-method", "unused"})
31+
@ExpectError({"The first argument must be a com.oracle.truffle.api.frame.VirtualFrame- but is java.lang.String"})
32+
public Object access(String frame, ValidTruffleObject object, Object[] args) {
33+
return true;
34+
}
35+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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.AcceptMessage;
28+
29+
@AcceptMessage(value = "EXECUTE", receiverType = ValidTruffleObject.class, language = TestTruffleLanguage.class)
30+
public final class Execute3 extends BaseExecute3 {
31+
@SuppressWarnings({"static-method", "unused"})
32+
@ExpectError({"The last argument must be the arguments array. Required type: java.lang.Object[]- but is java.lang.String"})
33+
public Object access(VirtualFrame frame, ValidTruffleObject object, String args) {
34+
return true;
35+
}
36+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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.AcceptMessage;
27+
28+
@AcceptMessage(value = "EXECUTE", receiverType = ValidTruffleObject.class, language = TestTruffleLanguage.class)
29+
public final class Execute4 extends BaseExecute4 {
30+
@Override
31+
public Object access(VirtualFrame frame, ValidTruffleObject object, Object[] args) {
32+
return true;
33+
}
34+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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.AcceptMessage;
27+
28+
@AcceptMessage(value = "EXECUTE", receiverType = ValidTruffleObject.class, language = TestTruffleLanguage.class)
29+
public final class Execute5 extends BaseExecute5 {
30+
@Override
31+
public Object access(VirtualFrame frame, ValidTruffleObjectB object, Object[] args) {
32+
return true;
33+
}
34+
35+
@Override
36+
public Object access(VirtualFrame frame, ValidTruffleObject object, Object[] args) {
37+
return true;
38+
}
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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.interop.ForeignAccess;
26+
import com.oracle.truffle.api.interop.TruffleObject;
27+
28+
public class InvalidTruffleObject implements TruffleObject {
29+
30+
public ForeignAccess getForeignAccess() {
31+
return null;
32+
}
33+
}

0 commit comments

Comments
 (0)