Greetings!
I've recently developed a simple JVM in C++ as a university
assignment; by simple I really do mean simple! There is no support for
strings, longs or doubles, multi-dimensional arrays, any Java classes
besides output (which is emulated), inheritance or other fancy OO
features.
More importantly what it is capable of doing is working with floats,
integers, doing proper flow control, converting between floats and
integers, working with static and non-static fields and methods, be it
through instantiation or otherwise. Single-dimensional arrays are
supported. In other words: all the fun Java stuff is left out, but it
is nonetheless a workable programming language.
But the thing is, it's really hard to find Java programs with these
constraints! (Not so in C, for example.) I've written a few simple
examples which get their job done while testing individual features,
but does anyone have any suggestions on a more complex program to test
it more thoroughly? The idea is to use it to showcase the VM's
(little) functionality. Either source code or ideas would be
appreciated.
Thanks in advance!
Pedro.
bugbear - 03 Jul 2007 09:44 GMT
> Greetings!
>
[quoted text clipped - 18 lines]
> (little) functionality. Either source code or ideas would be
> appreciated.
http://weblogs.java.net/blog/kgh/archive/2004/12/j2se_compatibil.html
BugBear
Pedro Brandao - 03 Jul 2007 13:22 GMT
> > Greetings!
>
[quoted text clipped - 22 lines]
>
> BugBear
Hey, thanks BugBear!
Unfunately the JCK comes with a strictly read-only license,
disallowing other uses (including compiling and running!). Also the
download link seems to be down...
Shame, it looked like a good source at first. =(
Roedy Green - 03 Jul 2007 14:08 GMT
On Tue, 03 Jul 2007 03:50:41 -0000, Pedro Brandao
<pgbrandao@gmail.com> wrote, quoted or indirectly quoted someone who
said :
>Greetings!
>
[quoted text clipped - 22 lines]
>
>Pedro.
You restrictions are extremely onerous . No IO either. So all you can
do is write your own test code or look for some computationally
intensive code and modify it to remove all strings.
See http://mindprod.com/products.html#PRIMES
for example.
--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
Oliver Wong - 03 Jul 2007 22:14 GMT
> Greetings!
>
[quoted text clipped - 18 lines]
> (little) functionality. Either source code or ideas would be
> appreciated.
Without support for strings, it's hard to make interesting output (and
thus interesting programs). If you can emulate strings (perhaps with
arrays of chars), then the following programs might become feasible:
* Hello World
* 99 Bottles of Beer
* Tower of Hanoi
* Factorials
- Oliver
Roedy Green - 04 Jul 2007 01:48 GMT
On Tue, 3 Jul 2007 17:14:39 -0400, "Oliver Wong"
<owong@castortech.com> wrote, quoted or indirectly quoted someone who
said :
> Without support for strings, it's hard to make interesting output (and
>thus interesting programs).
You might kludge in a string implementation with just the basic string
methods and perhaps some temporary Mickey Mouse implementation -- e.g.
all backed by fixed length static char arrays.
--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
Patricia Shanahan - 04 Jul 2007 02:00 GMT
> On Tue, 3 Jul 2007 17:14:39 -0400, "Oliver Wong"
> <owong@castortech.com> wrote, quoted or indirectly quoted someone who
[quoted text clipped - 10 lines]
> The Java Glossary
> http://mindprod.com
The OP didn't mention char data type, but one could use an int array
instead.
Patricia
Patricia Shanahan - 03 Jul 2007 22:35 GMT
> Greetings!
>
[quoted text clipped - 18 lines]
> (little) functionality. Either source code or ideas would be
> appreciated.
Even in C, programs that use float but not double are rare. If I were
only going to implement one of float and double I would pick double.
Maybe you should write a Turing machine emulator. That would prove that
your mini-JVM is Turing-complete.
I'm a bit confused about how you can have instantiation without having
any Java classes.
Patricia
Pedro Brandao - 03 Jul 2007 23:59 GMT
> > Greetings!
>
[quoted text clipped - 29 lines]
>
> Patricia
My bad, I meant I didn't implement the Java library. Classses written
within the constraints imposed are properly instantiated.
I didn't implement doubles and longs yet simply because I want to
ensure the rest is working thoroughly before going further; the
implementation itself is really very simple.
As for the Turing machine, that's a great idea! Fits in with the idea
perfectly. How about a Brainfuck interpreter? I'll think about it....