mattbierner / khepri

ECMAScript derived programming language
http://khepri-lang.com/
MIT License
67 stars 3 forks source link

Generation of Unreachable Bindings #95

Closed mattbierner closed 10 years ago

mattbierner commented 10 years ago

More specific problem than #91, inlining and constant propagation currently generates unreachable bindings. This should be easier to solve than #91.

let x = 8 + 2, y = x * 2 in x + y;

outputs

"use strict";
var x = 10,
    y = 20;
30;

The output should be:

"use strict";
30;

However if the binding is to a function, we cannot delete it so easily because the function may reference itself in its body or not be inlined because the depth is too great (Currently limited to 4):

with mod10 := \x -> ? x < 10 : x : mod10 (x -10) in {
    mod10 101;
}

Outputs:

"use strict";
var mod10 = (function(x) {
    return ((x < 10) ? x : mod10((x - 10)));
}),
    x = 101,
    x0 = 91,
    x1 = 81,
    x2 = 71;
mod10(61);

Where x, x0, x1, and x2 are not reachable by mod10 is. #91 would probably be required to solve that fully.

mattbierner commented 10 years ago

Fixed for constants in Khepri compile V0.3.9