Re: Euphoria to Java

new topic     » goto parent     » topic index » view thread      » older message » newer message

Hi David,

How much less effort would it be to write a Euphoria -> Java translator
then it would be to write your own Euphoria -> C translator.

All the benefits you mention about Java exist in C,
as well C has speed and resource benefits.

Obvisously the current translator only supports the compilers
that Rob creates a library for.

If you had your own Translator you could compile it for any
development envirnonment you wanted to.

In actual fact you'd only need to write your own lib that emulates
what Rob has done and use the current Translator ... although I
don't know how legal or ethically correct that would be.

What ideas do you have in incorporating Swig into this Java Translator?

Also whatever ideas you have ... would the same or similiar concepts
work with the current Translator with GTK+ or wxWindows?

Ray Smith


> For various and sundry reasons, I've been pondering a Euphoria to Java
> translator. I've heard the arguments against Java - it's a slow, bloated
> resource-hogging b&d style language. I used to believe some of them, but
> with each new generation of PC, the requirements of Java seem more and
more
> modest. Additionally, the speed increases due to JIT compiler technology
has
> been nothing short of staggering.
>
> Some time back, I had written a preliminary Euphoria to Java translator.
You
> can find it at:
>
>    http://www.lanset.com/dcuny/java.htm
>
> It's only capable of translating simple Euphoria programs. The project
> stalled because I had trouble figuring out how to link it to Swing. As you
> might guess, I've gotten back to the code more recently, and have been
doing
> some more experiments.
>
> I've been spurred on mostly by Robert's Euphoria to C translator. There's
> obviously a good enough mapping between C and Euphoria for his translator
to
> work. But it seems to me that an equally viable mapping exists between
> Euphoria and Java. For example, here's a mapping of the basic data types:
>
>    integer -> int, Integer
>    atom -> long, Long
>    sequence -> Vector
>
> Robert's coding of sequences is:
>
>    struct s1 {
>       object_ptr first;
>       long length;
>       long ref;
>       long postfill;
>    }
>
> Java already provides a mechanism for determining the length of a Vector,
> and automatically maintains space for expansion. So the Java equivalent
> could simply be:
>
>    class EuObject {
>       Object data;
>       int refcount = 0;
>    }
>
> There's a close correlation in code generation as well. Here's an example:
>
>    object o1, o2
>    o1 = {1,2,3}
>    o2 = o1[2]
>
> Robert's translator generates:
>
>     // o1 = {1,2,3}
>     _0 = _0o1;
>     _1 = NewS1(3);
>     _2 = (int)((s1_ptr)_1)->first;
>     *((int *)(_2+0)) = 1;
>     *((int *)(_2+4)) = 2;
>     *((int *)(_2+8)) = 3;
>     _0o1 = MAKE_SEQ(_1);
>     DeRef(_0);
>
>     // o2 = o1[2]
>     _0 = _0o2;
>     _2 = (int)SEQ_PTR(_0o1);
>     _0o2 = (int)*(1 + ((s1_ptr)_2)->first);
>     Ref(_0o2);
>     DeRef(_0);
>
> Here's a guess at what the equivalent Java code might be:
>
>    // o1 = {1,2,3}
>    _0 = _0o1;
>    _1 = new EuObject();
>    _1.data = new Vector();
>    _1.data.addElement( new Integer( 1 ) );
>    _1.data.addElement( new Integer( 2 ) );
>    _1.data.addElement( new Integer( 3 ) );
>    _0o1 = _1;
>    _1.DeRef();
>
>    // o2 = o1[2]
>    _0 = _0o2;
>    _0o2 = _0o1.elementAt( 1 );
>    _0o2.Ref();
>    _0.DeRef();
>
> Of course, it's sort of cheating not to show how Ref and DeRef might be
> implemented:
>
>    public void Ref() {
>       // is the object is a sequence?
>       if (this.data instanceof Vector) {
>          // increment the reference count
>          this.refcount += 1;
>       }
>    }
>
>    public void DeRef() {
>       // is the object a sequence?
>       if (this.data instanceof Vector) {
>          // decrement the reference count
>          this.refcount -= 1;
>       }
>
>       // release the object. if there are no more
>       // references to it, Java will garbage collect it.
>       this = _null;
>    }
>
> The Java code isn't that different from the C code, and I *suspect* that
the
> resulting Java code would be acceptably fast.
>
> If such a translator were written, Euphoria programs would be able to run
on
> a much wider base of machines - Macs, non-x86 based machines - anything
that
> Java has been ported to.
>
> In addition, we'd also have access to the AWT and Swing. Anyone subscribed
> to this list for any period of time knows that I'd love for Euphoria to
have
> a portable GUI.
>
> So, assuming that the project is feasible, here comes the interesting
> question:
>
>    - Who wants to write it?
>
> Robert is obviously in the best position to write this. Whether he is
> interested in doing this, or even if such a project is commercially
viable,
> I couldn't guess.
>
> Pete Eberlein is my number two pick, but he seems to have disappeared off
> into the Land of Reality, that unhappy place of the 9 to 5 grind.
>
> I suspect that I could do it, but there are other things that I'd rather
do.
>
> I've also got a sneaking feeling that *someone* is currently working on
this
> project, but it's nothing more than a hunch.
>
> Comments?
>
> -- David Cuny

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu