comparison src/monoize.sml @ 1776:8f28c3295148

Compiled a window function use
author Adam Chlipala <adam@chlipala.net>
date Sat, 02 Jun 2012 16:00:50 -0400
parents 6bc2a8cb3a67
children 59b07fdae1ff
comparison
equal deleted inserted replaced
1775:6bc2a8cb3a67 1776:8f28c3295148
297 (L'.TFfi ("Basis", "string"), loc) 297 (L'.TFfi ("Basis", "string"), loc)
298 | L.CApp ((L.CFfi ("Basis", "sql_summable"), _), _) => 298 | L.CApp ((L.CFfi ("Basis", "sql_summable"), _), _) =>
299 (L'.TRecord [], loc) 299 (L'.TRecord [], loc)
300 | L.CApp ((L.CFfi ("Basis", "sql_maxable"), _), _) => 300 | L.CApp ((L.CFfi ("Basis", "sql_maxable"), _), _) =>
301 (L'.TRecord [], loc) 301 (L'.TRecord [], loc)
302 | L.CApp ((L.CApp ((L.CApp ((L.CApp ((L.CFfi ("Basis", "sql_window"), _), _), _), _), _), _), _), _) =>
303 (L'.TFfi ("Basis", "string"), loc)
302 | L.CApp ((L.CFfi ("Basis", "sql_arith"), _), _) => 304 | L.CApp ((L.CFfi ("Basis", "sql_arith"), _), _) =>
303 (L'.TRecord [], loc) 305 (L'.TRecord [], loc)
304 | L.CApp ((L.CFfi ("Basis", "sql_nfunc"), _), _) => 306 | L.CApp ((L.CFfi ("Basis", "sql_nfunc"), _), _) =>
305 (L'.TFfi ("Basis", "string"), loc) 307 (L'.TFfi ("Basis", "string"), loc)
306 | L.CApp ((L.CApp ((L.CFfi ("Basis", "sql_ufunc"), _), _), _), _) => 308 | L.CApp ((L.CApp ((L.CFfi ("Basis", "sql_ufunc"), _), _), _), _) =>
2726 sc "(", 2728 sc "(",
2727 (L'.ERel 0, loc), 2729 (L'.ERel 0, loc),
2728 sc ")"] 2730 sc ")"]
2729 in 2731 in
2730 ((L'.EAbs ("c", s, (L'.TFun (s, (L'.TFun (s, s), loc)), loc), 2732 ((L'.EAbs ("c", s, (L'.TFun (s, (L'.TFun (s, s), loc)), loc),
2731 (L'.EAbs ("e1", s, (L'.TFun (s, s), loc), main), loc)), loc), 2733 (L'.EAbs ("e1", s, s, main), loc)), loc),
2732 fm) 2734 fm)
2733 end 2735 end
2734 2736
2735 | L.ECApp ((L.EFfi ("Basis", "sql_count_col"), _), _) => 2737 | L.ECApp ((L.EFfi ("Basis", "sql_count_col"), _), _) =>
2736 ((L'.EPrim (Prim.String "COUNT"), loc), 2738 ((L'.EPrim (Prim.String "COUNT"), loc),
2775 | L.ECApp ((L.ECApp ((L.EFfi ("Basis", "sql_min"), _), _), _), _) => 2777 | L.ECApp ((L.ECApp ((L.EFfi ("Basis", "sql_min"), _), _), _), _) =>
2776 ((L'.EAbs ("_", (L'.TRecord [], loc), (L'.TFun ((L'.TRecord [], loc), (L'.TFfi ("Basis", "string"), loc)), loc), 2778 ((L'.EAbs ("_", (L'.TRecord [], loc), (L'.TFun ((L'.TRecord [], loc), (L'.TFfi ("Basis", "string"), loc)), loc),
2777 (L'.EAbs ("_", (L'.TRecord [], loc), (L'.TFfi ("Basis", "string"), loc), 2779 (L'.EAbs ("_", (L'.TRecord [], loc), (L'.TFfi ("Basis", "string"), loc),
2778 (L'.EPrim (Prim.String "MIN"), loc)), loc)), loc), 2780 (L'.EPrim (Prim.String "MIN"), loc)), loc)), loc),
2779 fm) 2781 fm)
2782
2783 | L.ECApp (
2784 (L.ECApp (
2785 (L.ECApp (
2786 (L.ECApp (
2787 (L.EFfi ("Basis", "sql_window"), _),
2788 _), _),
2789 _), _),
2790 _), _),
2791 _) =>
2792 let
2793 val s = (L'.TFfi ("Basis", "string"), loc)
2794 fun sc s = (L'.EPrim (Prim.String s), loc)
2795
2796 val main = strcat [(L'.ERel 0, loc),
2797 sc " OVER ()"]
2798 in
2799 ((L'.EAbs ("w", s, s, main), loc),
2800 fm)
2801 end
2802
2803 | L.ECApp (
2804 (L.ECApp (
2805 (L.ECApp (
2806 (L.ECApp (
2807 (L.ECApp (
2808 (L.EFfi ("Basis", "sql_window_aggregate"), _),
2809 _), _),
2810 _), _),
2811 _), _),
2812 _), _),
2813 _) =>
2814 let
2815 val s = (L'.TFfi ("Basis", "string"), loc)
2816 fun sc s = (L'.EPrim (Prim.String s), loc)
2817
2818 val main = strcat [(L'.ERel 1, loc),
2819 sc "(",
2820 (L'.ERel 0, loc),
2821 sc ")"]
2822 in
2823 ((L'.EAbs ("c", s, (L'.TFun (s, (L'.TFun (s, s), loc)), loc),
2824 (L'.EAbs ("e1", s, s, main), loc)), loc),
2825 fm)
2826 end
2827
2828 | L.ECApp ((L.ECApp ((L.ECApp ((L.EFfi ("Basis", "sql_window_count"), _), _), _), _), _), _) =>
2829 ((L'.EPrim (Prim.String "COUNT(*)"), loc), fm)
2830 | L.ECApp ((L.ECApp ((L.ECApp ((L.EFfi ("Basis", "sql_window_rank"), _), _), _), _), _), _) =>
2831 ((L'.EPrim (Prim.String "RANK()"), loc), fm)
2780 2832
2781 | L.EFfi ("Basis", "sql_asc") => ((L'.EPrim (Prim.String ""), loc), fm) 2833 | L.EFfi ("Basis", "sql_asc") => ((L'.EPrim (Prim.String ""), loc), fm)
2782 | L.EFfi ("Basis", "sql_desc") => ((L'.EPrim (Prim.String " DESC"), loc), fm) 2834 | L.EFfi ("Basis", "sql_desc") => ((L'.EPrim (Prim.String " DESC"), loc), fm)
2783 | L.ECApp ( 2835 | L.ECApp (
2784 (L.ECApp ( 2836 (L.ECApp (