Type hierarchy

Renze Torensma renzetorensma at gmail.com
Thu Apr 2 13:01:00 UTC 2015


Hi Chris,

Thanks for your answer! I asked this because I have an existing code base for a language and I want to use Truffle to speed it up. Comparable to JRuby I think, but it’s just a research project so not used in production. And if I want to use Java primitives I have to change a lot of code, because the Value superclass is used all over the code base.

I’m going to think about it a bit more and hopefully come up with a good solution :)

Renze

> On 1 apr. 2015, at 15:59, Chris Seaton <chris.seaton at oracle.com> wrote:
> 
> Hello Renze,
> 
> In the past when people have developed JVM languages like Jython and JRuby they have recreated the guest language’s class hierarchy in Java. So in JRuby, there is a RubyBasicObject, a RubyObject and a RubyFixnum. These Java classes have methods that correspond to the Ruby methods in the same classes.
> 
> I would not recommend doing this for a Truffle language. I think instead you want to increase the level of abstraction slightly and think more about writing a Java program that represents the guest language object model, rather than recreating it in Java.
> 
> In the Truffle implementation of Ruby, we use int and long for Fixnum, even though they logically extend Object and BasicObject, and there is no RubyFixnum class at all. We then add special cases for all operations that examine the class of an object to return that Fixnum is the class for an int or long - we abstract the inheritance and express it in Java code, rather than expressing it using the Java object model.
> 
> To take it one stage further you can use a Truffle DyanmicObject to represent your guest language objects.
> 
> Combining all of this - not using the Java class hierarchy, not writing methods in your guest language classes, and then using DyanmicObject instead, in the end you’ll find you don’t have any need for classes like RubyObject at all (we still have them in JRuby+Truffle but they’re going away soon).
> 
> Is that helpful? Or do you have more specific reasons why you want the inheritance which make this not practical?
> 
> Regards,
> 
> Chris
> 
>> On 1 Apr 2015, at 14:32, Renze Torensma <renzetorensma at gmail.com> wrote:
>> 
>> Hi,
>> 
>> Do you have any tips about dealing with a type hierarchy that has one superclass for all types? For example a Value superclass with Boolean, String, Int, List and Date subclasses. That way I can’t use the java primitives for boolean and int so I lose out on those performance gains I think..
>> 
>> Renze
> 



More information about the graal-dev mailing list