cardinal-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Cardinal-dev] RubyInRuby parser/compiler


From: Erik Bågfors
Subject: [Cardinal-dev] RubyInRuby parser/compiler
Date: 01 Jan 2003 16:54:29 +0100

Hi All!

during the holidays I played around with the ruby-parser that can be
found in the ruby cvs under lib/metaruby/ruby-parser.

My experiences so far has been great!  I really think we can use this
baby to write the parrot compiler.  If we only had objects working in
parrot I think we could get very far in a short time.

One think I noticed when started to think about what it means that
EVERYTHING is an object is that everything has to be objects :)

For example, the following ruby code
a=1+2

Will have to be quite long.  What we have to do here is
* Create a object of type "Fixnum"
* Set that object to the value 1
* Create another object of type "Fixnum"
* Set that object to the value 2
* lookup the subrutine "+" in the first object (or maybe it's enough to
look that up in the class "Fixnum")
* put the objects on the stack
* call the sub
* pop the answer into "a"

Am I correct so far?

So far my "play-compiler" outputs the following imc-like code for this

$P1 = new RubyFixnum
$P1 = 1
# TODO: lookup + in $P1
.local $P2
$P2 = new RubyFixnum
$P2 = 1
.arg $P1    # assuming that self is first
.arg $P2
call __+    # TODO, should use whatever was looked up above
.local a
pop a


Anyway, I really feel that we can't do very much more than play with
compilers/pmcs/whatever until parrot has real object support.  Ruby is a
very oo language :)


Operator overriding also needs a standard naming convention for all
languages. In ruby it's simply done like this

def +(val);return something; end

if python I think it looks like this (if I remember correctly)

def __add__(val)
   return something


in c++ I think it's like this (again, if I remember correctly)

klass operator+(klass value) {
    return something;
}

I for one wants to be able to use the operators in a python-object from
a ruby-object.  Of course. this is way into the future right now.

/Erik

-- 
Erik Bågfors               | address@hidden
Supporter of free software | GSM +46 733 279 273
fingerprint: 6666 A85B 95D3 D26B 296B 6C60 4F32 2C0B 693D 6E32



reply via email to

[Prev in Thread] Current Thread [Next in Thread]