Nickforall / taal

:zap:Experimental systems programming language
6 stars 0 forks source link

Optimize binary expressions #5

Open Nickforall opened 6 years ago

Nickforall commented 6 years ago

So, we have this AST, representing 100 + 200 + 300.

{
    "type": "binary",
    "operator": "+",
    "left": {
        "type": "binary",
        "operator": "+",
        "left": {
            "type": "numberLiteral",
            "value": 100
        },
        "right": {
            "type": "numberLiteral",
            "value": 200
        }
    },
    "right": {
        "type": "numberLiteral",
        "value": 300
    }
}

In the end they are all number literals, so we can just optimize this to the expression below, because at compiletime we know these numbers will never change, they are constant.

{
    "type": "numberLiteral",
    "value": 600
}
Nickforall commented 6 years ago

oh, we could also optimize this, but that looks really hard

fn some_function {
    test = 40
    yo = 1000
    hello = 10

    print yo * test + hello
}

I'll probably make a different issue sometime