dschmenk / PLASMA

Proto Language AsSeMbler for All (formerly Apple)
MIT License
191 stars 26 forks source link

Merge latest upstream code #24

Closed ZornsLemma closed 7 years ago

ZornsLemma commented 7 years ago

Sorry about this, I find the github pull request interface confusing - I wanted to pull your code into my repo, not the other way round...

dschmenk commented 7 years ago

Heh, me too. Were there any changes you wanted my to commit or are we up-to-date? (I know I still have a lot of vegetables to eat...)

ZornsLemma commented 7 years ago

Sorry, I don't have anything exciting yet, though I've identified some more possible optimiser enhancements which I haven't yet tried to implement. The main one is that constant folding doesn't seem to happen at the 'end' of an expression. Compiling

def foo(x)                                                                       
    return x + 2 + 3                                                             
end

generates:

        !BYTE   $58,$02,$01             ; ENTER 2,1
        !BYTE   $66,$00                 ; LLW   [0]
        !BYTE   $2A,$02                 ; CB    2
        !BYTE   $02                     ; ADD
        !BYTE   $2A,$03                 ; CB    3
        !BYTE   $02                     ; ADD
        !BYTE   $5A                     ; LEAVE

using 'CB 2; ADD; CB 3; ADD' rather than just doing 'CB 5; ADD'. I don't know if this would be best fixed in the peephole optimiser or the compiler's own constant folding could be tweaked.