xtc.lang.jeannie

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Parser » Rats Parser Generators » xtc.lang.jeannie 
xtc.lang.jeannie
A compiler contributed to xtc that integrates Java with C. Both language and compiler are described in an OOPSLA '07 paper by Martin Hirzel and Robert Grimm.

Prerequisites

You need Java 1.5, gcc, and the usual GNU tooling (in particular, gcc and make). We have tested Jeannie under Mac OS X with HotSpot, and under Linux and Cygwin with IBM Java.

Environment variables

JAVA_DEV_ROOT set this such that $JAVA_DEV_ROOT/xtc is the top-level xtc directory
PATH_SEP ':' for MacOS or Linux, or ';' for Cygwin
CLASSPATH $JAVA_DEV_ROOT/classes$PATH_SEP$JAVA_DEV_ROOT/bin/junit.jar$PATH_SEP$JAVA_DEV_ROOT/bin/antlr.jar
JAVA_HOME set this such that $JAVA_HOME/bin/java is the Java virtual machine
CPATH should include the directory that contains jni.h, which is most likely $JAVA_HOME/include
PATH should include $JAVA_HOME/bin
OSTYPE should be either cygwin, or have linux or darwin as a substring

Testing using the Makefile

Try the following:
make -C $JAVA_DEV_ROOT/fonda/jeannie_testsuite test_000
If all goes well, that should produce the output:
==== integration test_000 ====
Processing tmp/000sugared/Main.jni ...
diff tmp/000mangled/output.txt tmp/000sugared/output.txt
What happened is that the Makefile compiled and ran the same test written in Jeannie (fonda/jeannie_testsuite/input/000sugared_Main.jni) and in JNI (fonda/jeannie_testsuite/input/000mangled_Main.{c,java}), and compared the output.

You can also run all included integration tests in batch mode:

make -C $JAVA_DEV_ROOT/fonda/jeannie_testsuite test
To find out the individual compilation steps, uncomment the following line in the Makefile:
# export VERBOSE_MAKE=true

Compiling your own programs

The easiest way is to follow the existing examples and use the existing Makefiles. But if you prefer to compile by hand, the following example compiles and runs foo/Bar.jni
  • Run Jeannie preprocessor to inject "#include <jni.h>" at the start of the file.
    java -ea xtc.lang.jeannie.PreJeannieParser foo/Main.jni > foo/Main.jni.pp
    
  • Run C prepreocessor to resolve #includes, #ifdefs, and macros.
    # Mac OS:
    cc -DSPECIALIZE_RELPROD -DSPECIALIZE_AND -DSPECIALIZE_OR -DSMALL_NODES -fomit-frame-pointer -fno-common -I/System/Library/Frameworks/JavaVM.framework/Headers -E -x c foo/Bar.jni.pp > foo/Bar.jni.i
    # Linux:
    gcc -E -x c foo/Bar.jni.pp > foo/Bar.jni.i
    # Cygwin:
    gcc -mno-cygwin -I$JAVA_HOME/include -E -x c foo/Bar.jni.pp > foo/Bar.jni.i
    
  • Run Jeannie compiler.
    # Mac OS or Linux:
    java -ea -DJNICALL='' xtc.lang.jeannie.Jeannie -analyze -translate -in foo foo/Bar.jni.i
    # Cygwin:
    java -ea -DJNICALL='__attribute__((__stdcall__))' xtc.lang.jeannie.Jeannie -analyze -translate -in foo foo/Bar.jni.i
    
  • Compile resulting C code into a shared object file (dynamically linked libary):
    # Mac OS:
    cc -DSPECIALIZE_RELPROD -DSPECIALIZE_AND -DSPECIALIZE_OR -DSMALL_NODES -fomit-frame-pointer -fno-common -I/System/Library/Frameworks/JavaVM.framework/Headers -dynamiclib -framework JavaVM -o foo/libBar.jnilib foo/Bar.i
    # Linux:
    gcc -shared -o foo/libBar.so foo/Bar.i
    # Cygwin:
    gcc -mno-cygwin -I$JAVA_HOME/include -Wl,--add-stdcall-alias -shared -o foo/Bar.dll foo/Bar.i
    
  • Compile resulting Java code into class files (bytecode):
    javac -sourcepath foo -d foo foo/Bar.java
    
  • Tell the dynamic linker where to find the shared object file.
    export PATH=foo:"$PATH"
    export LD_LIBRARY_PATH=foo:"$LD_LIBRARY_PATH"
    
  • Run the code with a Java virtual machine.
    java -cp foo -Djava.library.path=foo Bar
    
Java Source File NameTypeComment
Analyzer.javaClass A visitor that constructs a symbol table for a Jeannie file.
AstSimplifier.javaClass A visitor that simplifies Jeannie ASTs.
CodeGenerator.javaClass A visitor that constructs separate C and Java ASTs from a JNI AST.
Debugger.javaClass The Blink terminal debugger.
DebuggerAstAnalyzer.javaClass
DebuggerAstPrinter.javaClass
DebuggerCommand.javaClass The Blink macro command implementation.
DebuggerExpression.javaClass A Jeannie expression handler for the Blink debugger.
DebuggerInterpreter.javaClass
DebuggerParser.javaClass Packrat parser for grammar xtc.lang.jeannie.Debugger.
DebuggerSymbolMapper.javaInterface
Jeannie.javaClass A compiler from Jeannie to separate Java and C files that use JNI.
JeannieCFactory.javaClass Node factory xtc.lang.jeannie.JeannieCFactory.
JeannieJavaFactory.javaClass Node factory xtc.lang.jeannie.JeannieJavaFactory.
JeannieParser.javaClass Packrat parser for grammar xtc.lang.jeannie.Jeannie.
JeanniePrinter.javaClass A pretty printer for Jeannie (pretty JNI). This is an example of combining two visitors (CPrinter and JavaPrinter).
PreJeannieParser.javaClass Packrat parser for grammar xtc.lang.jeannie.PreJeannie.
Preprocessor.javaClass
UnitTests.javaClass JUnit tests for classes in package xtc.lang.jeannie. This class is a good place to quickly try a method on some simple inputs.
Utilities.javaClass Static helper routines related to JNI and Jeannie. This is a good place to put code that is useful for more than one visitor.
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.