ArachnidAbby / BCL

BCL Compiled Language (BCL)
https://discord.gg/sShr7fMNFn
GNU General Public License v3.0
21 stars 0 forks source link

[FEATURE REQUEST] Optimize out constant expressions and branches with constant expressions #24

Open ArachnidAbby opened 6 months ago

ArachnidAbby commented 6 months ago

Description of the feature Basically we need to do constant folding and we need to remove branches that rely exclusively on constants to determine the conditional jump. Essentially optimize if 1 {println("hi");} to println("hi");

This would also allow for bounds checking at compile time of constant expressions. Examples of usage

my_array[T::SIZEOF * 2] // no longer generates a runtime check!

Possible issues that may make this feature difficult to implement we need to create an is_constant_expression(self) -> bool property on all ast nodes. Defaults to false. The math may also be slow in python. So certain constant folding would only be done in builds with --release (once added).