在X10里加入C++或者Java代码
2010-06-09 10:44
741 查看
The primary mechanism X10 programmers should use is annotations. The annotations override the usual code generation strategy used by the X10 compiler, allowing the programmer to insert verbatim C++ or Java code into their X10 program. In the following example, the string on the static method being called is used verbatim at the call site. Because calls are expressions, the native annotation ought to be an expression too.
Test.x10
Test.x10
import x10.compiler.Native; public class Test { // Use native code in all backends: @Native("c++","printf(\"Hello World!\\n\")") @Native("java","System.out.println(\"Hello World!\")") private static native def test1 () : Void; // Only use native code in C++ backend: @Native("c++","printf(\"Hello World!\\n\")") private static def test2 () { // X10 code provides behaviour for Java backend. } // Use function parameters in native code // #0 is the name of the class (Test in this case) // #1, #2, #3, etc name the parameters @Native("c++","printf(\"This is the number %d\\n\", (#1))") @Native("java","System.out.println(\"This is the number \"+(#1))") private static native def test3 (x:Int) : Void; public static def main (args:Rail[String]!) { test1(); test2(); test3(42); } }
相关文章推荐
- 重新发布本人所有博客文章中涉及的代码与工具(大部分是C++和Java)
- Java使用wkhtmltox实现HTML代码生成PDF文档或者图片
- 安卓系统级 Java/C++代码除错
- C++ 代码创建虚拟机调用java方法
- Cocos2d-x中通过JNI进行C++调用Java代码
- java与c/c++进行socket通信的一些问题(1)-JSP教程,Java技巧及代码
- 遇到奇怪的C#/C/C++或者Java的bug可以去问问Coverity
- 冒泡排序及C++/java代码实现(BubbleSort)
- C++ 调用 Java Cocos2d-x利用jni调用java层代码
- JAVA和C++中获取当前函数名,文件名和代码行
- JAVA代码在图片上加入文字信息的代码实例
- VC6.0和VS2005查看查看C或者C++文件汇编代码的方法
- 使用JNI进行混合编程:在C/C++中调用Java代码
- 我刚翻译的一些用Swig将c/c++程序转为java代码的英文文档
- java通过JNI调用c++代码
- 最简单的Java调用C/C++代码的步骤
- Android-NDK开发之基础--Android JNI实例代码(一)-- 在JNI中执行Java方法--C/C++调用Java
- 在Android源码中查找Java代码中native函数对应的C++实现
- JNI技术实践(1) Java调用C/C++代码
- Java利用JNI调用c++代码简易例子演示