links icon indicating copy to clipboard operation
links copied to clipboard

Explore JIT compilation as a computational effect

Open dhil opened this issue 4 years ago • 0 comments

Project idea: Use effect handlers to JIT compile (optimise and deoptimise) code.

It is fairly straightforward to JIT compile in Links on the client side using the alien interface

alien javascript "./evalK.js" evalK : (String) ~> a;
# evalK.js
# The gist of it in JavaScript
# function evalK(code, k) {
#     return k(eval(code));
# }

var fac = "function fac(n, k) { if (n === 0) return k(1); 
                                else return fac(n-1, function(acc) { return k(acc*n) }); }";

var fac5 = { 
  evalK(fac);
  evalK("fac(5, function(x) { return x; })") : Int # returns 120 : Int
};

(it would be good to have alien abstract types, so evalK could return some opaque type, say, JSObj.)

dhil avatar Jul 28 '21 08:07 dhil