dbaumgarten / yodk

Development Kit for Starbase's ingame programming language YOLOL
MIT License
57 stars 16 forks source link

Logical Expression Repalcement with Arithmatic Expression, Optimisation #46

Open Woccz opened 3 years ago

Woccz commented 3 years ago

Sometimes logical expressions can be replaced by arithmatic expressions, due to YOLOL using number type variables for booleans.

Example: image

I'm not sure of all the places these expressions can be substituted, for example, x+= a or b can result in a different output from x+= a+b. Perhaps it is best to just replace statements used for logical evaluation, i.e. if x then ...

Thank you.

dbaumgarten commented 3 years ago

A problem here is the lack of type-information. Replacing and/or with */+ is only safe, when you are sure that the user is only interested in the truthvalue of the computation.

You are right, if the expression is used DIRECTLY as condition for an if, that would be safe to assume. But even in cases like

if (a or b)==(c or d) then ....

this would fail in unexpected ways.

I guess if I ever find a way to implement a proper type-system, optimizations like this could become relatively simple.

dbaumgarten commented 3 years ago

Waiting for #48