Re: Euphoria to Java

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

On Sat, 2 Dec 2000, David Cuny wrote:

> Jeffrey Fielding wrote:
>
> > But in Java, you have to use a whole
> > class such as Integer. And what's
> > worse is that you can't re-assign
> > Integers in Java, so every time you
> > modify it you have to create a new
> > object. This makes it really, really
> > slow compared to using a primitive int.
>
> But if you created a pool of Integers (for example, in the range -1 to 255),
> you could share those values. For example, here's the coding for adding two
> objects:
>
>    // o3 = o1 + o2
>
>    // store old value
>    _0 = 0o3;
>
>    // are both values numeric?
>    if !(_0o1 instanceof Vector || _0o2 instanceof Vector) {
>       // perform addition
>       _tmpLong = _0o1.data.longValue + _0o2.data.longValue;
>       // is the result in the integer pool?
>       if (_tmpLong.isInt() && _tmpLong >= -1 && _tmpLong <= 255) {
>          // fetch pre-defined constant from the pool
>          _1.data = _intPool[(int)_tmpLong + 1];
>       } else {
>          // create a new Integer
>          _1.data = new Integer( _tmpLong );
>    } else {
>       // there's a sequence, use class method
>       _1 = _binary_op( PLUS, _0o1, _0o2 );
>    }
>
>    // assign
>    _0o3 - _1;
>
>    // release temp
>    _1 = _null;
>
>    // dereference
>    _0.DeRef();
>

You might do that, but I think it would be faster (though I haven't tested
it) to do one of the following:
1. create a replacement for Integer etc. that lets you modify the value
2. create an interface, EuObject, and then make specific classes like
EuInteger, EuAtom, and EuSequence which implement that interface, but each
stores the value in the most efficient way
3. create a (slightly bloated) EuObject class with a way to store each
type:
class EuObject
{
        int iVal;
        double fVal;
        Vector sVal;
}

> More importantly, he wrote:
>
> > So maybe I'll start working on an Euphoria
> > to C/Java translator over winter vacation...
>
> Are you serious about this? Do you want some help?
>
> -- David Cuny
Well, I've started such a project several times, but I have yet to finish
it. I've been trying to come up with a neat way to parse an Euphoria
program and to represent it as a tree. For simply translating it, it's
not necessary to do this, but I want to optimize it too. Since it would
probably be easiest to represent such a tree with classes and pointers, I
tried doing this in Java. Unfortunately, I'm too impatient to design every
intricate detail of the program before writing it, so it got really ugly
fast.
Mostly, I'm interested in writing such a translator as an intellectual
challenge, but also I think it would be useful because then I might be
able to add stuff like object orientation to Euphoria, which would make
some tasks much easier. Pointers, though they can get really ugly, would
also make many tasks easier in Euphoria. I'd like to experiment with
features like those.
As part of a project I started a long while ago, I wrote an Euphoria
lexer, which seems to work quite nicely and it is pretty easily
extendible. I haven't been very successful (yet, anyway) at writing a
parser for those tokens. As I mentioned, I have a set of C++ classes for
Euphoria objects and sequences, with some basic routines implemented. They
seem to be reasonably fast, and they should automatically clean up unused
variables when they go out of scope.
So, if you'd like to help, that would be great. I have exams coming up
next week, but then a long break grin, so I'll probably not be able to do
all that much work on it until then.

Jeff

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

Search



Quick Links

User menu

Not signed in.

Misc Menu