comparison src/monoize.sml @ 1778:818d4097e2ed

Lighter-weight encoding of window function use
author Adam Chlipala <adam@chlipala.net>
date Sun, 03 Jun 2012 11:29:31 -0400
parents 59b07fdae1ff
children 5bc4fbf9c0fe
comparison
equal deleted inserted replaced
1777:59b07fdae1ff 1778:818d4097e2ed
247 (L'.TFfi ("Basis", "string"), loc) 247 (L'.TFfi ("Basis", "string"), loc)
248 | L.CApp ((L.CApp ((L.CApp ((L.CApp ((L.CApp ((L.CFfi ("Basis", "sql_query1"), _), _), _), _), _), _), _), _), _), _) => 248 | L.CApp ((L.CApp ((L.CApp ((L.CApp ((L.CApp ((L.CFfi ("Basis", "sql_query1"), _), _), _), _), _), _), _), _), _), _) =>
249 (L'.TFfi ("Basis", "string"), loc) 249 (L'.TFfi ("Basis", "string"), loc)
250 | L.CApp ((L.CApp ((L.CFfi ("Basis", "sql_from_items"), _), _), _), _) => 250 | L.CApp ((L.CApp ((L.CFfi ("Basis", "sql_from_items"), _), _), _), _) =>
251 (L'.TFfi ("Basis", "string"), loc) 251 (L'.TFfi ("Basis", "string"), loc)
252 | L.CApp ((L.CApp ((L.CApp ((L.CApp ((L.CApp ((L.CFfi ("Basis", "sql_exp"), _), _), _), _), _), _), _), _), _), _) => 252 | L.CApp ((L.CApp ((L.CApp ((L.CApp ((L.CFfi ("Basis", "sql_exp"), _), _), _), _), _), _), _), _) =>
253 (L'.TFfi ("Basis", "string"), loc)
254 | L.CApp ((L.CApp ((L.CApp ((L.CApp ((L.CFfi ("Basis", "sql_expw"), _), _), _), _), _), _), _), _) =>
255 (L'.TFfi ("Basis", "string"), loc)
256 | L.CApp ((L.CFfi ("Basis", "sql_window"), _), _) =>
257 (L'.TRecord [], loc)
258 | L.CApp ((L.CApp ((L.CApp ((L.CApp ((L.CFfi ("Basis", "sql_window_function"), _), _), _), _), _), _), _), _) =>
253 (L'.TFfi ("Basis", "string"), loc) 259 (L'.TFfi ("Basis", "string"), loc)
254 | L.CApp ((L.CApp ((L.CFfi ("Basis", "primary_key"), _), _), _), _) => 260 | L.CApp ((L.CApp ((L.CFfi ("Basis", "primary_key"), _), _), _), _) =>
255 (L'.TFfi ("Basis", "string"), loc) 261 (L'.TFfi ("Basis", "string"), loc)
256 | L.CApp ((L.CApp ((L.CFfi ("Basis", "sql_constraints"), _), _), _), _) => 262 | L.CApp ((L.CApp ((L.CFfi ("Basis", "sql_constraints"), _), _), _), _) =>
257 (L'.TFfi ("Basis", "sql_constraints"), loc) 263 (L'.TFfi ("Basis", "sql_constraints"), loc)
297 (L'.TFfi ("Basis", "string"), loc) 303 (L'.TFfi ("Basis", "string"), loc)
298 | L.CApp ((L.CFfi ("Basis", "sql_summable"), _), _) => 304 | L.CApp ((L.CFfi ("Basis", "sql_summable"), _), _) =>
299 (L'.TRecord [], loc) 305 (L'.TRecord [], loc)
300 | L.CApp ((L.CFfi ("Basis", "sql_maxable"), _), _) => 306 | L.CApp ((L.CFfi ("Basis", "sql_maxable"), _), _) =>
301 (L'.TRecord [], loc) 307 (L'.TRecord [], loc)
302 | L.CApp ((L.CApp ((L.CApp ((L.CFfi ("Basis", "sql_partition"), _), _), _), _), _), _) =>
303 (L'.TFfi ("Basis", "string"), loc)
304 | L.CApp ((L.CApp ((L.CApp ((L.CApp ((L.CFfi ("Basis", "sql_window"), _), _), _), _), _), _), _), _) =>
305 (L'.TFfi ("Basis", "string"), loc)
306 | L.CApp ((L.CFfi ("Basis", "sql_arith"), _), _) => 308 | L.CApp ((L.CFfi ("Basis", "sql_arith"), _), _) =>
307 (L'.TRecord [], loc) 309 (L'.TRecord [], loc)
308 | L.CApp ((L.CFfi ("Basis", "sql_nfunc"), _), _) => 310 | L.CApp ((L.CFfi ("Basis", "sql_nfunc"), _), _) =>
309 (L'.TFfi ("Basis", "string"), loc) 311 (L'.TFfi ("Basis", "string"), loc)
310 | L.CApp ((L.CApp ((L.CFfi ("Basis", "sql_ufunc"), _), _), _), _) => 312 | L.CApp ((L.CApp ((L.CFfi ("Basis", "sql_ufunc"), _), _), _), _) =>
313 (L'.TFfi ("Basis", "string"), loc)
314 | L.CApp ((L.CApp ((L.CApp ((L.CFfi ("Basis", "sql_partition"), _), _), _), _), _), _) =>
315 (L'.TFfi ("Basis", "string"), loc)
316 | L.CApp ((L.CApp ((L.CApp ((L.CApp ((L.CFfi ("Basis", "sql_window"), _), _), _), _), _), _), _), _) =>
311 (L'.TFfi ("Basis", "string"), loc) 317 (L'.TFfi ("Basis", "string"), loc)
312 318
313 | L.CApp ((L.CFfi ("Basis", "channel"), _), _) => 319 | L.CApp ((L.CFfi ("Basis", "channel"), _), _) =>
314 (L'.TFfi ("Basis", "channel"), loc) 320 (L'.TFfi ("Basis", "channel"), loc)
315 321
2109 2115
2110 | L.ECApp ( 2116 | L.ECApp (
2111 (L.ECApp ( 2117 (L.ECApp (
2112 (L.ECApp ( 2118 (L.ECApp (
2113 (L.ECApp ( 2119 (L.ECApp (
2114 (L.ECApp ( 2120 (L.EFfi ("Basis", "sql_inject"), _),
2115 (L.EFfi ("Basis", "sql_inject"), _),
2116 _), _),
2117 _), _), 2121 _), _),
2118 _), _), 2122 _), _),
2119 _), _), 2123 _), _),
2120 t) => 2124 t) =>
2121 let 2125 let
2424 | L.ECApp ((L.ECApp ((L.EFfi ("Basis", "sql_order_by_random"), _), _), _), _) => 2428 | L.ECApp ((L.ECApp ((L.EFfi ("Basis", "sql_order_by_random"), _), _), _), _) =>
2425 ((L'.EPrim (Prim.String (#randomFunction (Settings.currentDbms ()) ^ "()")), loc), fm) 2429 ((L'.EPrim (Prim.String (#randomFunction (Settings.currentDbms ()) ^ "()")), loc), fm)
2426 | L.ECApp ( 2430 | L.ECApp (
2427 (L.ECApp ( 2431 (L.ECApp (
2428 (L.ECApp ( 2432 (L.ECApp (
2429 (L.EFfi ("Basis", "sql_order_by_Cons"), _), 2433 (L.ECApp (
2434 (L.EFfi ("Basis", "sql_order_by_Cons"), _),
2435 _), _),
2430 _), _), 2436 _), _),
2431 _), _), 2437 _), _),
2432 _) => 2438 _) =>
2433 let 2439 let
2434 val s = (L'.TFfi ("Basis", "string"), loc) 2440 val s = (L'.TFfi ("Basis", "string"), loc)
2435 fun sc s = (L'.EPrim (Prim.String s), loc) 2441 fun sc s = (L'.EPrim (Prim.String s), loc)
2436 in 2442 in
2437 ((L'.EAbs ("e1", s, (L'.TFun (s, (L'.TFun (s, s), loc)), loc), 2443 ((L'.EAbs ("_", (L'.TRecord [], loc), (L'.TFun (s, (L'.TFun (s, (L'.TFun (s, s), loc)), loc)), loc),
2438 (L'.EAbs ("d", s, (L'.TFun (s, s), loc), 2444 (L'.EAbs ("e1", s, (L'.TFun (s, (L'.TFun (s, s), loc)), loc),
2439 (L'.EAbs ("e2", s, s, 2445 (L'.EAbs ("d", s, (L'.TFun (s, s), loc),
2440 (L'.ECase ((L'.ERel 0, loc), 2446 (L'.EAbs ("e2", s, s,
2441 [((L'.PPrim (Prim.String ""), loc), 2447 (L'.ECase ((L'.ERel 0, loc),
2442 strcat [(L'.ERel 2, loc), 2448 [((L'.PPrim (Prim.String ""), loc),
2443 (L'.ERel 1, loc)]), 2449 strcat [(L'.ERel 2, loc),
2444 ((L'.PWild, loc), 2450 (L'.ERel 1, loc)]),
2445 strcat [(L'.ERel 2, loc), 2451 ((L'.PWild, loc),
2446 (L'.ERel 1, loc), 2452 strcat [(L'.ERel 2, loc),
2447 sc ", ", 2453 (L'.ERel 1, loc),
2448 (L'.ERel 0, loc)])], 2454 sc ", ",
2449 {disc = s, result = s}), loc)), loc)), loc)), loc), 2455 (L'.ERel 0, loc)])],
2456 {disc = s, result = s}), loc)), loc)), loc)), loc)), loc),
2450 fm) 2457 fm)
2451 end 2458 end
2452 2459
2453 | L.EFfi ("Basis", "sql_no_limit") => 2460 | L.EFfi ("Basis", "sql_no_limit") =>
2454 ((L'.EPrim (Prim.String ""), loc), fm) 2461 ((L'.EPrim (Prim.String ""), loc), fm)
2510 | L.ECApp ( 2517 | L.ECApp (
2511 (L.ECApp ( 2518 (L.ECApp (
2512 (L.ECApp ( 2519 (L.ECApp (
2513 (L.ECApp ( 2520 (L.ECApp (
2514 (L.ECApp ( 2521 (L.ECApp (
2515 (L.ECApp (
2516 (L.EFfi ("Basis", "sql_unary"), _), 2522 (L.EFfi ("Basis", "sql_unary"), _),
2517 _), _), 2523 _), _),
2518 _), _),
2519 _), _), 2524 _), _),
2520 _), _), 2525 _), _),
2521 _), _), 2526 _), _),
2522 _) => 2527 _) =>
2523 let 2528 let
2542 (L.ECApp ( 2547 (L.ECApp (
2543 (L.ECApp ( 2548 (L.ECApp (
2544 (L.ECApp ( 2549 (L.ECApp (
2545 (L.ECApp ( 2550 (L.ECApp (
2546 (L.ECApp ( 2551 (L.ECApp (
2547 (L.ECApp ( 2552 (L.EFfi ("Basis", "sql_binary"), _),
2548 (L.EFfi ("Basis", "sql_binary"), _),
2549 _), _),
2550 _), _), 2553 _), _),
2551 _), _), 2554 _), _),
2552 _), _), 2555 _), _),
2553 _), _), 2556 _), _),
2554 _), _), 2557 _), _),
2577 (L.ECApp ( 2580 (L.ECApp (
2578 (L.ECApp ( 2581 (L.ECApp (
2579 (L.ECApp ( 2582 (L.ECApp (
2580 (L.ECApp ( 2583 (L.ECApp (
2581 (L.ECApp ( 2584 (L.ECApp (
2582 (L.ECApp ( 2585 (L.EFfi ("Basis", "sql_field"), _),
2583 (L.EFfi ("Basis", "sql_field"), _),
2584 _), _),
2585 _), _), 2586 _), _),
2586 _), _), 2587 _), _),
2587 _), _), 2588 _), _),
2588 _), _), 2589 _), _),
2589 _), _), 2590 _), _),
2593 | L.ECApp ( 2594 | L.ECApp (
2594 (L.ECApp ( 2595 (L.ECApp (
2595 (L.ECApp ( 2596 (L.ECApp (
2596 (L.ECApp ( 2597 (L.ECApp (
2597 (L.ECApp ( 2598 (L.ECApp (
2598 (L.ECApp ( 2599 (L.EFfi ("Basis", "sql_exp"), _),
2599 (L.EFfi ("Basis", "sql_exp"), _),
2600 _), _),
2601 _), _), 2600 _), _),
2602 _), _), 2601 _), _),
2603 _), _), 2602 _), _),
2604 _), _), 2603 _), _),
2605 (L.CName nm, _)) => ((L'.EPrim (Prim.String ("uw_" ^ lowercaseFirst nm)), loc), fm) 2604 (L.CName nm, _)) => ((L'.EPrim (Prim.String ("uw_" ^ lowercaseFirst nm)), loc), fm)
2699 ((L'.EPrim (Prim.String "EXCEPT"), loc), fm)) 2698 ((L'.EPrim (Prim.String "EXCEPT"), loc), fm))
2700 2699
2701 | L.ECApp ( 2700 | L.ECApp (
2702 (L.ECApp ( 2701 (L.ECApp (
2703 (L.ECApp ( 2702 (L.ECApp (
2704 (L.ECApp ( 2703 (L.EFfi ("Basis", "sql_count"), _),
2705 (L.EFfi ("Basis", "sql_count"), _),
2706 _), _),
2707 _), _), 2704 _), _),
2708 _), _), 2705 _), _),
2709 _) => ((L'.EPrim (Prim.String "COUNT(*)"), loc), 2706 _) => ((L'.EPrim (Prim.String "COUNT(*)"), loc),
2710 fm) 2707 fm)
2711 2708
2712 | L.ECApp ( 2709 | L.ECApp (
2713 (L.ECApp ( 2710 (L.ECApp (
2714 (L.ECApp ( 2711 (L.ECApp (
2715 (L.ECApp ( 2712 (L.ECApp (
2716 (L.ECApp ( 2713 (L.ECApp (
2717 (L.ECApp ( 2714 (L.EFfi ("Basis", "sql_aggregate"), _),
2718 (L.EFfi ("Basis", "sql_aggregate"), _),
2719 _), _),
2720 _), _), 2715 _), _),
2721 _), _), 2716 _), _),
2722 _), _), 2717 _), _),
2723 _), _), 2718 _), _),
2724 t) => 2719 t) =>
2730 sc "(", 2725 sc "(",
2731 (L'.ERel 0, loc), 2726 (L'.ERel 0, loc),
2732 sc ")"] 2727 sc ")"]
2733 in 2728 in
2734 ((L'.EAbs ("c", s, (L'.TFun (s, (L'.TFun (s, s), loc)), loc), 2729 ((L'.EAbs ("c", s, (L'.TFun (s, (L'.TFun (s, s), loc)), loc),
2735 (L'.EAbs ("e1", s, s, main), loc)), loc), 2730 (L'.EAbs ("e1", s, (L'.TFun (s, s), loc), main), loc)), loc),
2736 fm) 2731 fm)
2737 end 2732 end
2738 2733
2739 | L.ECApp ((L.EFfi ("Basis", "sql_count_col"), _), _) => 2734 | L.ECApp ((L.EFfi ("Basis", "sql_count_col"), _), _) =>
2740 ((L'.EPrim (Prim.String "COUNT"), loc), 2735 ((L'.EPrim (Prim.String "COUNT"), loc),
2779 ((L'.EAbs ("_", (L'.TRecord [], loc), (L'.TFun ((L'.TRecord [], loc), (L'.TFfi ("Basis", "string"), loc)), loc), 2774 ((L'.EAbs ("_", (L'.TRecord [], loc), (L'.TFun ((L'.TRecord [], loc), (L'.TFfi ("Basis", "string"), loc)), loc),
2780 (L'.EAbs ("_", (L'.TRecord [], loc), (L'.TFfi ("Basis", "string"), loc), 2775 (L'.EAbs ("_", (L'.TRecord [], loc), (L'.TFfi ("Basis", "string"), loc),
2781 (L'.EPrim (Prim.String "MIN"), loc)), loc)), loc), 2776 (L'.EPrim (Prim.String "MIN"), loc)), loc)), loc),
2782 fm) 2777 fm)
2783 2778
2779 | L.EFfi ("Basis", "sql_asc") => ((L'.EPrim (Prim.String ""), loc), fm)
2780 | L.EFfi ("Basis", "sql_desc") => ((L'.EPrim (Prim.String " DESC"), loc), fm)
2781 | L.ECApp (
2782 (L.ECApp (
2783 (L.ECApp (
2784 (L.ECApp (
2785 (L.EFfi ("Basis", "sql_nfunc"), _),
2786 _), _),
2787 _), _),
2788 _), _),
2789 _) =>
2790 let
2791 val s = (L'.TFfi ("Basis", "string"), loc)
2792 fun sc s = (L'.EPrim (Prim.String s), loc)
2793 in
2794 ((L'.EAbs ("s", s, s, (L'.ERel 0, loc)), loc),
2795 fm)
2796 end
2797
2798 | L.EFfi ("Basis", "sql_window_normal") => ((L'.ERecord [], loc), fm)
2799 | L.EFfi ("Basis", "sql_window_fancy") => ((L'.ERecord [], loc), fm)
2800 | L.ECApp (
2801 (L.ECApp (
2802 (L.ECApp (
2803 (L.ECApp (
2804 (L.ECApp (
2805 (L.EFfi ("Basis", "sql_window"), _),
2806 _), _),
2807 _), _),
2808 _), _),
2809 _), _),
2810 _) =>
2811 let
2812 val s = (L'.TFfi ("Basis", "string"), loc)
2813 in
2814 ((L'.EAbs ("_", (L'.TRecord [], loc), (L'.TFun (s, s), loc),
2815 (L'.EAbs ("e", s, s,
2816 (L'.ERel 0, loc)), loc)), loc),
2817 fm)
2818 end
2819
2820 | L.EFfi ("Basis", "sql_current_timestamp") => ((L'.EPrim (Prim.String "CURRENT_TIMESTAMP"), loc), fm)
2821
2822 | L.ECApp (
2823 (L.ECApp (
2824 (L.ECApp (
2825 (L.ECApp (
2826 (L.ECApp (
2827 (L.EFfi ("Basis", "sql_ufunc"), _),
2828 _), _),
2829 _), _),
2830 _), _),
2831 _), _),
2832 _) =>
2833 let
2834 val s = (L'.TFfi ("Basis", "string"), loc)
2835 fun sc s = (L'.EPrim (Prim.String s), loc)
2836 in
2837 ((L'.EAbs ("f", s, (L'.TFun (s, s), loc),
2838 (L'.EAbs ("x", s, s,
2839 strcat [(L'.ERel 1, loc),
2840 sc "(",
2841 (L'.ERel 0, loc),
2842 sc ")"]), loc)), loc),
2843 fm)
2844 end
2845 | L.EFfi ("Basis", "sql_octet_length") =>
2846 ((L'.EPrim (Prim.String (if #supportsOctetLength (Settings.currentDbms ()) then
2847 "octet_length"
2848 else
2849 "length")), loc), fm)
2850 | L.EFfi ("Basis", "sql_lower") =>
2851 ((L'.EPrim (Prim.String "lower"), loc), fm)
2852 | L.EFfi ("Basis", "sql_upper") =>
2853 ((L'.EPrim (Prim.String "upper"), loc), fm)
2854 | L.ECApp ((L.EFfi ("Basis", "sql_known"), _), _) =>
2855 ((L'.EFfi ("Basis", "sql_known"), loc), fm)
2856
2857 | (L.ECApp (
2858 (L.ECApp (
2859 (L.ECApp (
2860 (L.ECApp (
2861 (L.EFfi ("Basis", "sql_is_null"), _), _),
2862 _), _),
2863 _), _),
2864 _), _)) =>
2865 let
2866 val s = (L'.TFfi ("Basis", "string"), loc)
2867 fun sc s = (L'.EPrim (Prim.String s), loc)
2868 in
2869 ((L'.EAbs ("s", s, s,
2870 strcat [sc "(",
2871 (L'.ERel 0, loc),
2872 sc " IS NULL)"]), loc),
2873 fm)
2874 end
2875
2876 | (L.ECApp (
2877 (L.ECApp (
2878 (L.ECApp (
2879 (L.ECApp (
2880 (L.EFfi ("Basis", "sql_coalesce"), _), _),
2881 _), _),
2882 _), _),
2883 _), _)) =>
2884 let
2885 val s = (L'.TFfi ("Basis", "string"), loc)
2886 fun sc s = (L'.EPrim (Prim.String s), loc)
2887 in
2888 ((L'.EAbs ("x1", s, (L'.TFun (s, s), loc),
2889 (L'.EAbs ("x1", s, s,
2890 strcat [sc "COALESCE(",
2891 (L'.ERel 1, loc),
2892 sc ",",
2893 (L'.ERel 0, loc),
2894 sc ")"]), loc)), loc),
2895 fm)
2896 end
2897
2898 | (L.ECApp (
2899 (L.ECApp (
2900 (L.ECApp (
2901 (L.ECApp (
2902 (L.EFfi ("Basis", "sql_if_then_else"), _), _),
2903 _), _),
2904 _), _),
2905 _), _)) =>
2906 let
2907 val s = (L'.TFfi ("Basis", "string"), loc)
2908 fun sc s = (L'.EPrim (Prim.String s), loc)
2909 in
2910 ((L'.EAbs ("if", s, (L'.TFun (s, (L'.TFun (s, s), loc)), loc),
2911 (L'.EAbs ("then", s, (L'.TFun (s, s), loc),
2912 (L'.EAbs ("else", s, s,
2913 strcat [sc "(CASE WHEN (",
2914 (L'.ERel 2, loc),
2915 sc ") THEN (",
2916 (L'.ERel 1, loc),
2917 sc ") ELSE (",
2918 (L'.ERel 0, loc),
2919 sc ") END)"]), loc)), loc)), loc),
2920 fm)
2921 end
2922
2923 | L.ECApp (
2924 (L.ECApp (
2925 (L.ECApp (
2926 (L.ECApp (
2927 (L.EFfi ("Basis", "sql_nullable"), _),
2928 _), _),
2929 _), _),
2930 _), _),
2931 _) =>
2932 let
2933 val s = (L'.TFfi ("Basis", "string"), loc)
2934 fun sc s = (L'.EPrim (Prim.String s), loc)
2935 in
2936 ((L'.EAbs ("u", (L'.TRecord [], loc), (L'.TFun (s, s), loc),
2937 (L'.EAbs ("x", s, s,
2938 (L'.ERel 0, loc)), loc)), loc),
2939 fm)
2940 end
2941
2942 | L.ECApp (
2943 (L.ECApp (
2944 (L.ECApp (
2945 (L.ECApp (
2946 (L.ECApp (
2947 (L.ECApp (
2948 (L.EFfi ("Basis", "sql_subquery"), _),
2949 _), _),
2950 _), _),
2951 _), _),
2952 _), _),
2953 _), _),
2954 _) =>
2955 let
2956 val s = (L'.TFfi ("Basis", "string"), loc)
2957 fun sc s = (L'.EPrim (Prim.String s), loc)
2958 in
2959 ((L'.EAbs ("_", (L'.TRecord [], loc), (L'.TFun (s, s), loc),
2960 (L'.EAbs ("x", s, s,
2961 strcat [sc "(",
2962 (L'.ERel 0, loc),
2963 sc ")"]), loc)), loc),
2964 fm)
2965 end
2966
2784 | L.ECApp ( 2967 | L.ECApp (
2785 (L.ECApp ( 2968 (L.ECApp (
2786 (L.ECApp ( 2969 (L.ECApp (
2787 (L.EFfi ("Basis", "sql_no_partition"), _), 2970 (L.EFfi ("Basis", "sql_no_partition"), _),
2788 _), _), 2971 _), _),
2806 2989
2807 | L.ECApp ( 2990 | L.ECApp (
2808 (L.ECApp ( 2991 (L.ECApp (
2809 (L.ECApp ( 2992 (L.ECApp (
2810 (L.ECApp ( 2993 (L.ECApp (
2811 (L.EFfi ("Basis", "sql_window"), _), 2994 (L.EFfi ("Basis", "sql_window_function"), _),
2812 _), _), 2995 _), _),
2813 _), _), 2996 _), _),
2814 _), _), 2997 _), _),
2815 _) => 2998 _) =>
2816 let 2999 let
2867 fm) 3050 fm)
2868 end 3051 end
2869 3052
2870 | L.ECApp ((L.ECApp ((L.ECApp ((L.EFfi ("Basis", "sql_window_count"), _), _), _), _), _), _) => 3053 | L.ECApp ((L.ECApp ((L.ECApp ((L.EFfi ("Basis", "sql_window_count"), _), _), _), _), _), _) =>
2871 ((L'.EPrim (Prim.String "COUNT(*)"), loc), fm) 3054 ((L'.EPrim (Prim.String "COUNT(*)"), loc), fm)
2872 | L.ECApp ((L.ECApp ((L.ECApp ((L.EFfi ("Basis", "sql_window_rank"), _), _), _), _), _), _) => 3055 | L.ECApp ((L.ECApp ((L.ECApp ((L.EFfi ("Basis", "sql_rank"), _), _), _), _), _), _) =>
2873 ((L'.EPrim (Prim.String "RANK()"), loc), fm) 3056 ((L'.EPrim (Prim.String "RANK()"), loc), fm)
2874
2875 | L.EFfi ("Basis", "sql_asc") => ((L'.EPrim (Prim.String ""), loc), fm)
2876 | L.EFfi ("Basis", "sql_desc") => ((L'.EPrim (Prim.String " DESC"), loc), fm)
2877 | L.ECApp (
2878 (L.ECApp (
2879 (L.ECApp (
2880 (L.ECApp (
2881 (L.ECApp (
2882 (L.EFfi ("Basis", "sql_nfunc"), _),
2883 _), _),
2884 _), _),
2885 _), _),
2886 _), _),
2887 _) =>
2888 let
2889 val s = (L'.TFfi ("Basis", "string"), loc)
2890 fun sc s = (L'.EPrim (Prim.String s), loc)
2891 in
2892 ((L'.EAbs ("s", s, s, (L'.ERel 0, loc)), loc),
2893 fm)
2894 end
2895 | L.EFfi ("Basis", "sql_current_timestamp") => ((L'.EPrim (Prim.String "CURRENT_TIMESTAMP"), loc), fm)
2896
2897 | L.ECApp (
2898 (L.ECApp (
2899 (L.ECApp (
2900 (L.ECApp (
2901 (L.ECApp (
2902 (L.ECApp (
2903 (L.EFfi ("Basis", "sql_ufunc"), _),
2904 _), _),
2905 _), _),
2906 _), _),
2907 _), _),
2908 _), _),
2909 _) =>
2910 let
2911 val s = (L'.TFfi ("Basis", "string"), loc)
2912 fun sc s = (L'.EPrim (Prim.String s), loc)
2913 in
2914 ((L'.EAbs ("f", s, (L'.TFun (s, s), loc),
2915 (L'.EAbs ("x", s, s,
2916 strcat [(L'.ERel 1, loc),
2917 sc "(",
2918 (L'.ERel 0, loc),
2919 sc ")"]), loc)), loc),
2920 fm)
2921 end
2922 | L.EFfi ("Basis", "sql_octet_length") =>
2923 ((L'.EPrim (Prim.String (if #supportsOctetLength (Settings.currentDbms ()) then
2924 "octet_length"
2925 else
2926 "length")), loc), fm)
2927 | L.EFfi ("Basis", "sql_lower") =>
2928 ((L'.EPrim (Prim.String "lower"), loc), fm)
2929 | L.EFfi ("Basis", "sql_upper") =>
2930 ((L'.EPrim (Prim.String "upper"), loc), fm)
2931 | L.ECApp ((L.EFfi ("Basis", "sql_known"), _), _) =>
2932 ((L'.EFfi ("Basis", "sql_known"), loc), fm)
2933
2934 | (L.ECApp (
2935 (L.ECApp (
2936 (L.ECApp (
2937 (L.ECApp (
2938 (L.ECApp (
2939 (L.EFfi ("Basis", "sql_is_null"), _), _),
2940 _), _),
2941 _), _),
2942 _), _),
2943 _), _)) =>
2944 let
2945 val s = (L'.TFfi ("Basis", "string"), loc)
2946 fun sc s = (L'.EPrim (Prim.String s), loc)
2947 in
2948 ((L'.EAbs ("s", s, s,
2949 strcat [sc "(",
2950 (L'.ERel 0, loc),
2951 sc " IS NULL)"]), loc),
2952 fm)
2953 end
2954
2955 | (L.ECApp (
2956 (L.ECApp (
2957 (L.ECApp (
2958 (L.ECApp (
2959 (L.EFfi ("Basis", "sql_coalesce"), _), _),
2960 _), _),
2961 _), _),
2962 _), _)) =>
2963 let
2964 val s = (L'.TFfi ("Basis", "string"), loc)
2965 fun sc s = (L'.EPrim (Prim.String s), loc)
2966 in
2967 ((L'.EAbs ("x1", s, (L'.TFun (s, s), loc),
2968 (L'.EAbs ("x1", s, s,
2969 strcat [sc "COALESCE(",
2970 (L'.ERel 1, loc),
2971 sc ",",
2972 (L'.ERel 0, loc),
2973 sc ")"]), loc)), loc),
2974 fm)
2975 end
2976
2977 | (L.ECApp (
2978 (L.ECApp (
2979 (L.ECApp (
2980 (L.ECApp (
2981 (L.ECApp (
2982 (L.ECApp (
2983 (L.EFfi ("Basis", "sql_if_then_else"), _), _),
2984 _), _),
2985 _), _),
2986 _), _),
2987 _), _),
2988 _), _)) =>
2989 let
2990 val s = (L'.TFfi ("Basis", "string"), loc)
2991 fun sc s = (L'.EPrim (Prim.String s), loc)
2992 in
2993 ((L'.EAbs ("if", s, (L'.TFun (s, (L'.TFun (s, s), loc)), loc),
2994 (L'.EAbs ("then", s, (L'.TFun (s, s), loc),
2995 (L'.EAbs ("else", s, s,
2996 strcat [sc "(CASE WHEN (",
2997 (L'.ERel 2, loc),
2998 sc ") THEN (",
2999 (L'.ERel 1, loc),
3000 sc ") ELSE (",
3001 (L'.ERel 0, loc),
3002 sc ") END)"]), loc)), loc)), loc),
3003 fm)
3004 end
3005
3006 | L.ECApp (
3007 (L.ECApp (
3008 (L.ECApp (
3009 (L.ECApp (
3010 (L.ECApp (
3011 (L.EFfi ("Basis", "sql_nullable"), _),
3012 _), _),
3013 _), _),
3014 _), _),
3015 _), _),
3016 _) =>
3017 let
3018 val s = (L'.TFfi ("Basis", "string"), loc)
3019 fun sc s = (L'.EPrim (Prim.String s), loc)
3020 in
3021 ((L'.EAbs ("u", (L'.TRecord [], loc), (L'.TFun (s, s), loc),
3022 (L'.EAbs ("x", s, s,
3023 (L'.ERel 0, loc)), loc)), loc),
3024 fm)
3025 end
3026
3027 | L.ECApp (
3028 (L.ECApp (
3029 (L.ECApp (
3030 (L.ECApp (
3031 (L.ECApp (
3032 (L.ECApp (
3033 (L.ECApp (
3034 (L.EFfi ("Basis", "sql_subquery"), _),
3035 _), _),
3036 _), _),
3037 _), _),
3038 _), _),
3039 _), _),
3040 _), _),
3041 _) =>
3042 let
3043 val s = (L'.TFfi ("Basis", "string"), loc)
3044 fun sc s = (L'.EPrim (Prim.String s), loc)
3045 in
3046 ((L'.EAbs ("_", (L'.TRecord [], loc), (L'.TFun (s, s), loc),
3047 (L'.EAbs ("x", s, s,
3048 strcat [sc "(",
3049 (L'.ERel 0, loc),
3050 sc ")"]), loc)), loc),
3051 fm)
3052 end
3053 3057
3054 | L.EFfiApp ("Basis", "nextval", [(e, _)]) => 3058 | L.EFfiApp ("Basis", "nextval", [(e, _)]) =>
3055 let 3059 let
3056 val (e, fm) = monoExp (env, st, fm) e 3060 val (e, fm) = monoExp (env, st, fm) e
3057 in 3061 in