Monday, April 6, 2009

Name Directory - Beta Implementation

So after about 4-5 hours of slogging it out to implement the Name Directory I mentioned in my previous post, I got its working implementation, in a not so beautiful piece of code, but it works!
Take this LIR snippet for instance -
start
two = int 2
twoPlusTwo = add two, two
three = int 3
threePlusThree = add three, three
five = int 5
fpf = add five, five
threePlusFive = add three, five
ret threePlusFive
It uses three named immediates, two, three, and five, alongwith other values calculated upon using these immediates. From the parser now, you can reference any value(which should have been the case in the first place), from anywhere in the snippet, and use it. For example, here, we use immediates three and five in threePlusFive, and return that value. The earlier problem of the most immediate result staying in the result variable has also been removed. The parser scans the named variable in the directory, and if found, returns it.

I will illustrate this with another example.Take this LIR for instance -
start
two = int 2
twoPlusTwo = add two, two
three = int 3
threePlusThree = add three, three
five = int 5
fpf = add five, five
threePlusFive = add three, five
temp = add threePlusFive, three
ret temp
As it should, the temp variable returns 11.

The code snippet can be found here.
Would surely love to hear on this.

No comments:

Post a Comment