chharvey / counterpoint

A robust programming language.
GNU Affero General Public License v3.0
2 stars 0 forks source link

Compiler Technique: Constant Folding #34

Closed chharvey closed 4 years ago

chharvey commented 4 years ago

Constant Folding is a technique in which the compiler computes expressions with constant terms before run time, thus speeding up execution.

For example, given an expression (10 + 11) * 2, the compiler would essentially transform that into the expression 42. For partial computations, e.g. (10 + 11) * x, the compiler will do as much as it can: 21 * x.

Since this is going in version v0.1.0, where there are no variables or statements and an entire Solid program consists of a single numerical expression, the compiler will compute the entire expression and simply print a single number as the compiled output.