some improvements

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

some improvements

Uli Kastlunger
This post was updated on .
Hello,

There's a little improvement for the if-code, which is also used by the supplied compiler, I think:

if (cond)
  A
else
  B

can be written as

cond
if-goto X
B
goto Y
X:
A
Y:

This saves one line, because we don't have to calculate ~cond. Remark that it is now necessary to write A into a buffer, because we must not write A immediately when we encounter it while parsing. If the if's are nested, we have to use a stacked buffer.

There's also an improvement in handling let-assignments involving arrays.

If you have something like

let a[exp1] = exp2

The supplied compiler saves the value of exp2 in a temp. variable, then assigns pointer 1 and finally that 0;

however you can again save this temp-stuff by writing the exp1 code to a buffer.

startBuffer()
push a
push exp1
add
pop pointer 1
pop that 0
endBuffer()

push exp2
writeBuffer() // writes the stuff inside startBuffer() ... endBuffer()

best regards,
uli