# HG changeset patch # User Adam Chlipala # Date 1422811754 18000 # Node ID 9e9c915f554cd6c11245ab5daca801caa65ff668 # Parent f42fea631c1dbef3b047b50ae3a9aa90c9f0ffb8 A new MonoReduce optimization for lifting 'let' out of field projection; JavaScript compilation for exponentiation diff -r f42fea631c1d -r 9e9c915f554c lib/js/urweb.js --- 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 diff -r f42fea631c1d -r 9e9c915f554c src/jscomp.sml --- 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) diff -r f42fea631c1d -r 9e9c915f554c src/mono_reduce.sml --- 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