235 posts
Location
/dev/earth1aus5
Posted 01 January 2013 - 03:52 PM
JavaL (instead of LuaJ, you know?)
Basically, sort of like that n00b programming language ComputerCraftFan11 is writing, except instead of parsing Java source code (which would be a pain in the a**), it parses either Java bytecode (directly), or disassembled (through `javap -c`) code.
That way, instead of relying on people to program according to a strict standard supported by the interpreter (durr, you must put one statement on each line and you have to have braces on the same line and no extra whitespace), the interpreter only needs to rely on the (inherently strict) bytecode produced by the Java compiler (or, if you're really desperate, yourself).
That's what I'm working on right now, using
Wikipedia and the
Java VM Specs as reference.
Feedback?
Screenies!
Spoiler
–Current Version–
v0.1b2: Disassembled/interpreted Java bytecode. Halfway there!
v0.1b2: Reading all the constants, interfaces, fields, etc.
–Older Versions–
v0.1b1: Reading the constants from the .class file
Edited on 02 January 2013 - 11:32 PM
1619 posts
Posted 01 January 2013 - 03:54 PM
Maybe I misunderstood, but since when can you run java code directly through computercraft?
235 posts
Location
/dev/earth1aus5
Posted 01 January 2013 - 05:58 PM
Maybe I misunderstood, but since when can you run java code directly through computercraft?
Maybe I wasn't clear. I was actually talking about writing a Java VM in Lua (which, of course, CC can run).
On an unrelated note, here's a screenshot of it!
1619 posts
Posted 01 January 2013 - 06:16 PM
Maybe I misunderstood, but since when can you run java code directly through computercraft?
Maybe I wasn't clear. I was actually talking about writing a Java VM in Lua (which, of course, CC can run).
On an unrelated note, here's a screenshot of it!
o_O it's done already?
1054 posts
Posted 02 January 2013 - 12:24 AM
* snip *
o_O it's done already?
He's just listing up all constants in the binary, which is only one step towards an actual JVM.
235 posts
Location
/dev/earth1aus5
Posted 02 January 2013 - 02:05 AM
* snip *
o_O it's done already?
He's just listing up all constants in the binary, which is only one step towards an actual JVM.
Yes, I've got quite a fair bit to go. (Actually, not that much towards a Hello World compatible JVM) Although, flicking through the JVM specifications, it doesn't look like too big a job. Mainly just keeping everything readable (without having access to OOP) and implementing all those 200 opcodes………
1054 posts
Posted 02 January 2013 - 02:10 AM
* snip *
o_O it's done already?
He's just listing up all constants in the binary, which is only one step towards an actual JVM.
Yes, I've got quite a fair bit to go. (Actually, not that much towards a Hello World compatible JVM) Although, flicking through the JVM specifications, it doesn't look like too big a job. Mainly just keeping everything readable (without having access to OOP) and implementing all those 200 opcodes………
I happen to be in the middle of creating an emulator myself (for the 6502 cpu), and the biggest issue for you will be efficiency, not readability. :P/> At least if you want it to run at a bearable speed…
1243 posts
Location
Indiana, United States
Posted 02 January 2013 - 06:18 AM
I happen to be in the middle of creating an emulator myself (for the 6502 cpu), and the biggest issue for you will be efficiency, not readability. :P/> At least if you want it to run at a bearable speed…
For Redpower 2?! Java emulator! :o/>
1054 posts
Posted 02 January 2013 - 07:01 AM
I happen to be in the middle of creating an emulator myself (for the 6502 cpu), and the biggest issue for you will be efficiency, not readability. :P/> At least if you want it to run at a bearable speed…
For Redpower 2?! Java emulator! :o/>
Not a Java emulator :P/> A 65EL02 bytecode emulator written in Lua. There will also be a compiler and a way to flash the 65EL02 from CC using bundled cables. :)/> I could try and port an existing open source Java emulator to the 65EL02.. would be challenging with those specs though.
235 posts
Location
/dev/earth1aus5
Posted 02 January 2013 - 03:28 PM
I happen to be in the middle of creating an emulator myself (for the 6502 cpu), and the biggest issue for you will be efficiency, not readability. :P/> At least if you want it to run at a bearable speed…
I'm not that worried about efficiency :D/>. It it runs at 1 FLOPS,
deal with it. But if I can't find my way around the growing labyrinth of code…
1054 posts
Posted 02 January 2013 - 03:42 PM
I happen to be in the middle of creating an emulator myself (for the 6502 cpu), and the biggest issue for you will be efficiency, not readability. :P/> At least if you want it to run at a bearable speed…
I'm not that worried about efficiency :D/>. It it runs at 1 FLOPS,
deal with it. But if I can't find my way around the growing labyrinth of code…
Fair point. :)/>
235 posts
Location
/dev/earth1aus5
Posted 03 January 2013 - 12:35 AM
He's just listing up all constants in the binary, which is only one step towards an actual JVM.
Here's another step! JavaL can now print the disassembled bytecode of a Java program! Almost there!!!
Spoiler
1054 posts
Posted 03 January 2013 - 12:42 AM
This is exciting..! :D/> I think that you'll have more work than you expect though. :P/> I know that I have for my own.
235 posts
Location
/dev/earth1aus5
Posted 03 January 2013 - 01:35 AM
This is exciting..! :D/>/> I think that you'll have more work than you expect though. :P/>/> I know that I have for my own.
http://en.wikipedia.org/wiki/Java_bytecode_instruction_listingsPush to stack… Pop from stack… Look-up from constant pool… Numerical local variables…
Doesn't look too difficult from here on in.
The lack of OOP in Lua might become a problem later down the track though…
1054 posts
Posted 03 January 2013 - 01:44 AM
The problems lie more in stuff like unsigned bytes and big endian and other stuff that's non-trivial in Lua… But you'll be ok. Java is designed to be emulated anyway, so that's an advantage. :)/>
235 posts
Location
/dev/earth1aus5
Posted 03 January 2013 - 01:55 AM
The problems lie more in stuff like unsigned bytes and big endian and other stuff that's non-trivial in Lua… But you'll be ok. Java is designed to be emulated anyway, so that's an advantage. :)/>/>
Unsigned bytes? Just… read a number……. Lua doesn't care.
Big endian? The majority of numbers in class files are 2-bytes long. I couldn't have gotten this far without implementing that!
function readu2() --Read unsigned 2-byte integer
bit.blshift(byte1, 8) + byte2
end
1054 posts
Posted 03 January 2013 - 02:02 AM
I know, those were just examples. About signedness, Lua doesn't care, but the simulated machine does, I'm not sure about the JVM, but I had to implement both explicitly. Well, you can keep on proving how simple it is, I believe you anyway. :)/> My experience just says that you will hit at least one wall somewhere, but we'll see. :P/>
I must say, I can see your doing a good job at this. :)/> And I notice that you have a good understanding of computer systems and architecture. :)/> I'm rather curious!
235 posts
Location
/dev/earth1aus5
Posted 03 January 2013 - 02:08 AM
I notice that you have a good understanding of computer systems and architecture. :)/>
Really? I honestly don't. I still don't get the difference between 32-bit and 64-bit computers :)/> I'm just a unix-head who uses C when he has to.
1054 posts
Posted 03 January 2013 - 02:14 AM
I notice that you have a good understanding of computer systems and architecture. :)/>
Really? I honestly don't. I still don't get the difference between 32-bit and 64-bit computers :)/> I'm just a unix-head who uses C when he has to.
In that case, I'm even more curious. :P/> Addressing width might even be something you need to take in consideration (not sure, I'm not that knowledgeable about the JVM).
Btw, I just checked and the JVM is quite chill about signedness. :)/> Basically it uses unsigned bytes or signed shorts.
Edit: Also, most emulators are written using the procedural paradigm instead of object oriented. It would be quite hard to implement OOP into the design (I have the cpu and ram as the only types, the rest are all helper functions that take the cpu as argument). I'm sure you could do better, though often OOP is traded for efficiency.
496 posts
Location
New Zealand
Posted 03 January 2013 - 12:17 PM
If you plan on being able to just run an arbitrary Java program, you then need the entire Java part of the jvm library, which then relies on native libraries that I'm unsure how easily you'll be able to achieve if at all loading of jni native libs.
235 posts
Location
/dev/earth1aus5
Posted 03 January 2013 - 02:54 PM
If you plan on being able to just run an arbitrary Java program, you then need the entire Java part of the jvm library, which then relies on native libraries that I'm unsure how easily you'll be able to achieve if at all loading of jni native libs.
I was planning on re-implementing some of the core classes of the Java libraries. For example, javal.lang.System might be defined as abstract and it's functionality is provided directly by the JVM.
Addressing width might even be something you need to take in consideration
See, I had to Google that one! Hmm… It looks like something to do with locations in memory - Java doesn't really care about memory. It just cares about the stack.