Mercurial > urweb
changeset 2110:9e9c915f554c
A new MonoReduce optimization for lifting 'let' out of field projection; JavaScript compilation for exponentiation
author | Adam Chlipala <adam@chlipala.net> |
---|---|
date | Sun, 01 Feb 2015 12:29:14 -0500 |
parents | f42fea631c1d |
children | 809bceab15a3 |
files | lib/js/urweb.js src/jscomp.sml src/mono_reduce.sml |
diffstat | 3 files changed, 19 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/lib/js/urweb.js Wed Jan 28 08:47:04 2015 -0500 +++ b/lib/js/urweb.js Sun Feb 01 12:29:14 2015 -0500 @@ -112,6 +112,10 @@ return Math.round(n); } +function pow(n, m) { + return Math.pow(n, m); +} + // Time, represented as counts of microseconds since the epoch
--- a/src/jscomp.sml Wed Jan 28 08:47:04 2015 -0500 +++ b/src/jscomp.sml Sun Feb 01 12:29:14 2015 -0500 @@ -724,6 +724,8 @@ | "<" => "lt" | "<=" => "le" | "strcmp" => "strcmp" + | "powl" => "pow" + | "powf" => "pow" | _ => raise Fail ("Jscomp: Unknown binary operator " ^ s) val (e1, st) = jsE inner (e1, st)
--- a/src/mono_reduce.sml Wed Jan 28 08:47:04 2015 -0500 +++ b/src/mono_reduce.sml Sun Feb 01 12:29:14 2015 -0500 @@ -818,10 +818,19 @@ search pes end - | EField ((ERecord xes, _), x) => - (case List.find (fn (x', _, _) => x' = x) xes of - SOME (_, e, _) => #1 e - | NONE => e) + | EField (e1, x) => + let + fun yankLets (e : exp) = + case #1 e of + ELet (x, t, e1, e2) => (ELet (x, t, e1, yankLets e2), #2 e) + | ERecord xes => + (case List.find (fn (x', _, _) => x' = x) xes of + SOME (_, e, _) => e + | NONE => (EField (e, x), #2 e)) + | _ => (EField (e, x), #2 e) + in + #1 (yankLets e1) + end | ELet (x1, t1, (ELet (x2, t2, e1, b1), loc), b2) => let