Question

I'm writing a Java to Java Bytecode compiler by compiling to Jasmin code, and assembling that. I'm creating it with the intention that source code files will be able to reference and use Java Library classes (you pretty much have to for Strings, printing etc.). My problem is how exactly to go about doing this.

So far I have just been using a reference to a list of all library classes which is held in a text file in the Java installation folder (it simply lists their packages and names). I have used it in coding the parser/type checker, although this was less than ideal since the type checker could not do any type checking when library classes were used.

It is really a problem now that I'm working on the code generation, because if you want to call a method of a library class, you must give it's full method signature - something which I do not have access to.

I was wandering what people's advice would be on how to progress. One way would be to go through all the classes creating a database/list of all their parameters and return types. This would be extremely time consuming obviously, and probably too unrealistic. Are there other, more elegant, approaches possible?

Thanks, Will

P.S. I'm using Python to code this. I suppose if the solution must use Java code, I could run it as a subprocess.

Was it helpful?

Solution 2

By looking into this further, it seems like it might be possible by using Java Reflection. I'll reply to this post letting you know how successful I was.

OTHER TIPS

There already is a Java to bytecode compiler, you know. And a JVM Python. What is your actual goal?

What makes you think it'd be "extremely time consuming" to create a collection of methods/return types? How time consuming is "extremely"? It's kind of how it works in real life, and it's not particularly time consuming to pull that information out of class files, even using javap. Other than that, there's ASM, BCEL, and a few other libraries to pull the info directly out of .class files, but javap provides simple text output and is likely adequate for your needs.

In order to use symbols, you need a symbol table. The only way to get what's available is to store what's available. It's faster, and smaller, than you think, especially if you use the shorthand notation.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top