|
Re: I don't get your point
|
Posted: Sep 21, 2006 7:28 AM
|
|
I've implemented a compiler of my language Kogut which translates it to C. I feel that it's easier than targetting JVM, even though the language is nothing like C. JVM has too many Java-specific limitations.
It uses garbage collection, dynamic typing, tail call optimization, exceptions, big integers, Unicode strings, lightweight threads, etc.
Tail calls are implemented by postprocessing the assembler output generated by a C compiler (or portably with a driver loop). The union of small integers and pointers to other objects is implemented by tagging small integers in the lowest bit. The system stack is almost unused; there is a custom stack, useful because of GC, tail calls, threads, stack traces on an unhandled exception, and detection of stack overflow.
These hacks, even though some of them are theoretically unportable and violate the letter of C rules, work quite well. JVM neither provides appropriate mechanisms itself nor allows to cheat in order to implement them.
JVM would require extremely stupid workarounds to implement tail calls. JVM has no way to put small integers along with pointers in a single pointer-sized field. Type safety on this level would do more harm than good. JVM has heavy exceptions, heavy threads, UTF-16 strings (I want UCS-4, and the implementation uses an alternative ISO-8859-1 representation of some strings for space optimization), and makes each object one field larger in order to support a per-object mutex and address hash that I wouldn't use. JVM has a wrong semantics of finalizers.
JVM is poorly suited for implementing languages which don't want to compromise in order to be JVM-compatible.
|
|