-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 9cd3801
Showing
83 changed files
with
21,745 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,215 @@ | ||
/// Copyright (C) eValuator, Lda | ||
|
||
/// THIS SOFTWARE IS PROVIDED BY THE AUTHOR 'AS IS' AND ANY EXPRESSED | ||
/// OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
/// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
/// ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY | ||
/// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
/// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE | ||
/// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
/// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | ||
/// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
/// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
/// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
|
||
import java.lang.reflect.*; | ||
import java.io.*; | ||
|
||
public class JavaToLMI { | ||
public static void main(String[] args) throws IOException { | ||
if (args.length == 0) { //Server mode | ||
String request; | ||
BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); | ||
while ((request = in.readLine()) != null) { | ||
processRequest(request, false); | ||
} | ||
} else if (args.length == 1) { //One-shot mode | ||
processRequest(args[0], true); | ||
} else { | ||
System.err.println("Usage: JavaToLMI classname"); | ||
System.exit(1); | ||
} | ||
} | ||
|
||
public static void processRequest(String name, boolean oneShotP) { | ||
try { | ||
dumpClassInfo(Class.forName(name, false, JavaToLMI.class.getClassLoader())); | ||
//Class.forName(name)); | ||
} catch (ClassNotFoundException cnfe) { | ||
if (oneShotP) { | ||
System.err.println("Class '" + name + "' not found"); | ||
System.exit(1); | ||
} else { | ||
println("()"); | ||
} | ||
} | ||
} | ||
|
||
public static void dumpClassInfo(Class classToDump) { | ||
printsp(classToDump.isInterface() ? "(defmixin-0" : "(defclass-0"); | ||
printsp(toTypeName(classToDump)); | ||
|
||
if (! classToDump.isInterface()) { | ||
Class superclass = classToDump.getSuperclass(); | ||
if (superclass == null) { | ||
printsp("()"); | ||
} else { | ||
printsp(toTypeName(superclass)); | ||
} | ||
} | ||
|
||
print("("); | ||
Class[] interfaces = classToDump.getInterfaces(); | ||
for(int i = 0; i < interfaces.length; i++) { | ||
printsp(toTypeName(interfaces[i])); | ||
} | ||
println(")"); | ||
|
||
println("()"); //options | ||
|
||
Field[] fields = classToDump.getDeclaredFields(); | ||
for(int i = 0; i < fields.length; i++) { | ||
dumpFieldInfo(fields[i]); | ||
} | ||
|
||
Constructor[] constructors = classToDump.getDeclaredConstructors(); | ||
for(int i = 0; i < constructors.length; i++) { | ||
dumpConstructorInfo(constructors[i]); | ||
} | ||
|
||
Method[] methods = classToDump.getDeclaredMethods(); | ||
for(int i = 0; i < methods.length; i++) { | ||
if (! methods[i].isBridge()) { | ||
dumpMethodInfo(methods[i]); | ||
} | ||
} | ||
|
||
// Class[] classes = classToDump.getDeclaredClasses(); | ||
// for(int i = 0; i < classes.length; i++) { | ||
// dumpClassInfo(classes[i]); | ||
// } | ||
|
||
println(")"); | ||
} | ||
|
||
public static void dumpFieldInfo(Field field) { | ||
if (isPublicOrProtected(field)) { | ||
printsp(" (defslot-0"); | ||
|
||
print("("); | ||
printsp(field.getName()); | ||
printsp("(the"); | ||
print(toTypeName(field.getType())); | ||
printsp("))"); | ||
// print(field.getName()); | ||
// print("/"); | ||
// printsp(toTypeName(field.getType())); | ||
|
||
dumpMemberOptions(field); | ||
println(")"); | ||
} | ||
} | ||
|
||
public static void dumpConstructorInfo(Constructor constructor) { | ||
if (isPublicOrProtected(constructor)) { | ||
printsp(" (defnew"); | ||
dumpArglist(constructor.getParameterTypes(), false); | ||
dumpMemberOptions(constructor); | ||
printsp(""); | ||
dumpThrows(constructor.getExceptionTypes()); | ||
println(")"); | ||
} | ||
} | ||
|
||
public static void dumpMethodInfo(Method method) { | ||
if (isPublicOrProtected(method)) { | ||
printsp(" (defmethod"); | ||
// printsp(toTypeName(method.getReturnType())); | ||
printsp(method.getName()); | ||
dumpArglist(method.getParameterTypes(), | ||
! Modifier.isStatic(method.getModifiers())); | ||
dumpMemberOptions(method); | ||
printsp(""); | ||
if (Modifier.isAbstract(method.getModifiers())) { | ||
printsp(":category :abstract"); | ||
} | ||
|
||
printsp(" :returns"); | ||
printsp(toTypeName(method.getReturnType())); | ||
|
||
dumpThrows(method.getExceptionTypes()); | ||
println(")"); | ||
} | ||
} | ||
|
||
public static void dumpMemberOptions(Member member) { | ||
int mods = member.getModifiers(); | ||
if (Modifier.isStatic(mods)) { | ||
printsp(":allocation :class"); | ||
} | ||
|
||
if (Modifier.isFinal(mods)) { | ||
printsp(":constant t"); | ||
} | ||
|
||
printsp(":visibility"); | ||
if (Modifier.isPublic(mods)) { | ||
print(":public"); | ||
} else { | ||
print(":protected"); | ||
} | ||
} | ||
|
||
public static void dumpArglist(Class[] argTypes, boolean withThis) { | ||
print("("); | ||
if (withThis) { | ||
printsp("this"); | ||
} | ||
for(int i = 0; i < argTypes.length; i++) { | ||
print("(arg" + i + " (the "); | ||
print(toTypeName(argTypes[i])); | ||
printsp("))"); | ||
} | ||
printsp(")"); | ||
} | ||
|
||
public static void dumpThrows(Class[] excepTypes) { | ||
if (excepTypes.length > 0) { | ||
print(":throws ("); | ||
for(int i = 0; i < excepTypes.length; i++) { | ||
printsp(toTypeName(excepTypes[i])); | ||
} | ||
printsp(")"); | ||
} | ||
} | ||
|
||
public static boolean isPublicOrProtected(Member member) { | ||
int mods = member.getModifiers(); | ||
return (Modifier.isPublic(mods) || Modifier.isProtected(mods)); | ||
} | ||
|
||
public static String toTypeName(Class classObj) { | ||
return toPrintableName(classObj); | ||
} | ||
|
||
protected static String toPrintableName(Class classObj) { | ||
if (classObj.isArray()) { | ||
return toPrintableName(classObj.getComponentType()) + "[]"; | ||
} else { | ||
return classObj.getName().replace('$', '/'); | ||
} | ||
} | ||
|
||
protected static void println(String text) { | ||
System.out.println(text); | ||
} | ||
|
||
protected static void printsp(String text) { | ||
System.out.print(text); | ||
System.out.print(" "); | ||
} | ||
|
||
protected static void print(String text) { | ||
System.out.print(text); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
README for Linj_1.x | ||
|
||
Apr, 9, 2004 | ||
|
||
|
||
|
||
Overview | ||
-------- | ||
|
||
Linj is a Common Lisp-like language that tries to be as similar to | ||
Common Lisp as possible but allowing Linj programs to be compiled into | ||
human-readable Java code. | ||
|
||
|
||
|
||
License | ||
------- | ||
|
||
This Linj distribution is free of charge for non-commercial use. If | ||
you use Linj for profit, you should contact us and buy a license. | ||
|
||
Copyright and ownership of this software belong to eValuator, Lda. | ||
|
||
|
||
|
||
Requirements | ||
------------ | ||
|
||
The Linj compiler is written in Common Lisp and currently runs on | ||
|
||
- CMU Common Lisp 19a for Linux | ||
- SBCL 0.8.15 for Linux and MacOSX | ||
- Allegro CL 6.2 for Linux and Windows | ||
|
||
You should download the version that matches your working environment. | ||
|
||
Linj requires a JDK that conforms to the Java 1.1 Core API. | ||
|
||
If you need Linj for other architectures and/or Common Lisp | ||
environments, please, contact us. | ||
|
||
|
||
|
||
Installation | ||
----------- | ||
|
||
Assuming that you extracted the files in the Linj distribution to the | ||
path <path>, start your Common Lisp environment and evaluate the | ||
expression: | ||
|
||
(load "<path>/load") | ||
|
||
|
||
|
||
Use | ||
---------- | ||
|
||
Put your Linj program into a file named according to the Linj | ||
conventions for classes (lowercase with hyphens), e.g., test.linj and | ||
invoke the Linj compiler using the (quoted) name of the file (without | ||
extension) and (optionally) the pathname to the directory containing | ||
that file. As an example, assuming that test.linj is in /tmp, use: | ||
|
||
(linj2java 'test "/tmp/") | ||
|
||
If the file test.linj is in the current directory, you can omit the | ||
second argument. | ||
|
||
If you have several linj files in a directory you can compile all of | ||
them using | ||
|
||
(linj2java-directory <path to the directory>) | ||
|
||
The <path to the directory> defaults to the current directory. | ||
|
||
|
||
|
||
Support Files | ||
------------- | ||
|
||
This Linj distribution also includes several pre-defined supporting | ||
classes (defined in Linj itself). You will find them on the | ||
<path>/linj/ subdirectory. For these classes to be useful, you must | ||
define your CLASSPATH to include the directory containing the file you | ||
are just reading. As an example, if your Linj distribution is on the | ||
path "/home/user/linj_1.0/" then you should set your CLASSPATH as | ||
follows: | ||
|
||
export CLASSPATH=/home/user/linj1.0/:$CLASSPATH | ||
|
||
|
||
|
||
Documentation | ||
------------- | ||
|
||
You can find a Linj tutorial at | ||
http://www.evaluator.pt/downloads/tutorial.html | ||
|
||
One (unfinished) manual can be found at | ||
http://www.evaluator.pt/downloads/linj-manual.pdf | ||
|
||
|
||
|
||
Bugs | ||
---- | ||
|
||
If you find bugs in Linj, please, send an e-mail to linj-bugs@evaluator.pt | ||
describing the bug and, if possible, including the necessary | ||
information to reproduce the bug. | ||
|
||
|
||
|
||
Inquiry & Support | ||
----------------- | ||
|
||
If you need more information regarding Linj, please send email to | ||
info@evaluator.pt. | ||
|
||
For technical support, send email to support@evaluator.pt. | ||
|
||
|
||
|
||
Feedback | ||
-------- | ||
|
||
Comments are very welcome! Please send them to info@evaluator.pt. | ||
|
||
|
||
Thanks for using Linj. | ||
|
||
----------------------------------------------------------------------- | ||
"Java" is a registered trademark of Sun Microsystems. |
Oops, something went wrong.