comparison src/monoize.sml @ 1191:61c3139eab12

Subquery expressions
author Adam Chlipala <adamc@hcoop.net>
date Thu, 25 Mar 2010 15:44:24 -0400
parents ad9829c3c12c
children 9c82548c97e9
comparison
equal deleted inserted replaced
1190:899875315bde 1191:61c3139eab12
1 (* Copyright (c) 2008-2009, Adam Chlipala 1 (* Copyright (c) 2008-2010, Adam Chlipala
2 * All rights reserved. 2 * All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met: 5 * modification, are permitted provided that the following conditions are met:
6 * 6 *
184 (L'.TFfi ("Basis", "string"), loc) 184 (L'.TFfi ("Basis", "string"), loc)
185 | L.CApp ((L.CFfi ("Basis", "sql_view"), _), _) => 185 | L.CApp ((L.CFfi ("Basis", "sql_view"), _), _) =>
186 (L'.TFfi ("Basis", "string"), loc) 186 (L'.TFfi ("Basis", "string"), loc)
187 | L.CFfi ("Basis", "sql_sequence") => 187 | L.CFfi ("Basis", "sql_sequence") =>
188 (L'.TFfi ("Basis", "string"), loc) 188 (L'.TFfi ("Basis", "string"), loc)
189 | L.CApp ((L.CApp ((L.CFfi ("Basis", "sql_query"), _), _), _), _) => 189 | L.CApp ((L.CApp ((L.CApp ((L.CFfi ("Basis", "sql_query"), _), _), _), _), _), _) =>
190 (L'.TFfi ("Basis", "string"), loc) 190 (L'.TFfi ("Basis", "string"), loc)
191 | L.CApp ((L.CApp ((L.CApp ((L.CFfi ("Basis", "sql_query1"), _), _), _), _), _), _) => 191 | L.CApp ((L.CApp ((L.CApp ((L.CApp ((L.CFfi ("Basis", "sql_query1"), _), _), _), _), _), _), _), _) =>
192 (L'.TFfi ("Basis", "string"), loc) 192 (L'.TFfi ("Basis", "string"), loc)
193 | L.CApp ((L.CFfi ("Basis", "sql_from_items"), _), _) => 193 | L.CApp ((L.CApp ((L.CFfi ("Basis", "sql_from_items"), _), _), _), _) =>
194 (L'.TFfi ("Basis", "string"), loc) 194 (L'.TFfi ("Basis", "string"), loc)
195 | L.CApp ((L.CApp ((L.CApp ((L.CApp ((L.CFfi ("Basis", "sql_exp"), _), _), _), _), _), _), _), _) => 195 | L.CApp ((L.CApp ((L.CApp ((L.CApp ((L.CFfi ("Basis", "sql_exp"), _), _), _), _), _), _), _), _) =>
196 (L'.TFfi ("Basis", "string"), loc) 196 (L'.TFfi ("Basis", "string"), loc)
197 | L.CApp ((L.CApp ((L.CFfi ("Basis", "primary_key"), _), _), _), _) => 197 | L.CApp ((L.CApp ((L.CFfi ("Basis", "primary_key"), _), _), _), _) =>
198 (L'.TFfi ("Basis", "string"), loc) 198 (L'.TFfi ("Basis", "string"), loc)
1779 body), loc)), loc)), loc)), loc), fm) 1779 body), loc)), loc)), loc)), loc), fm)
1780 end 1780 end
1781 end 1781 end
1782 | _ => poly ()) 1782 | _ => poly ())
1783 1783
1784 | L.ECApp ((L.ECApp ((L.ECApp ((L.EFfi ("Basis", "sql_query"), _), _), _), _), _), _) => 1784 | L.ECApp ((L.ECApp ((L.ECApp ((L.ECApp ((L.EFfi ("Basis", "sql_query"), _), _), _), _), _), _), _), _) =>
1785 let 1785 let
1786 fun sc s = (L'.EPrim (Prim.String s), loc) 1786 fun sc s = (L'.EPrim (Prim.String s), loc)
1787 val s = (L'.TFfi ("Basis", "string"), loc) 1787 val s = (L'.TFfi ("Basis", "string"), loc)
1788 fun gf s = (L'.EField ((L'.ERel 0, loc), s), loc) 1788 fun gf s = (L'.EField ((L'.ERel 0, loc), s), loc)
1789 in 1789 in
1804 | L.ECApp ( 1804 | L.ECApp (
1805 (L.ECApp ( 1805 (L.ECApp (
1806 (L.ECApp ( 1806 (L.ECApp (
1807 (L.ECApp ( 1807 (L.ECApp (
1808 (L.ECApp ( 1808 (L.ECApp (
1809 (L.EFfi ("Basis", "sql_query1"), _), 1809 (L.ECApp (
1810 (L.EFfi ("Basis", "sql_query1"), _),
1811 _), _),
1810 (L.CRecord (_, tables), _)), _), 1812 (L.CRecord (_, tables), _)), _),
1811 (L.CRecord (_, grouped), _)), _), 1813 (L.CRecord (_, grouped), _)), _),
1812 (L.CRecord (_, stables), _)), _), 1814 (L.CRecord (_, stables), _)), _),
1813 sexps), _), 1815 sexps), _),
1814 _) => 1816 _) =>
2044 | L.ECApp ((L.ECApp ((L.EFfi ("Basis", "fieldsOf_table"), _), _), _), _) => 2046 | L.ECApp ((L.ECApp ((L.EFfi ("Basis", "fieldsOf_table"), _), _), _), _) =>
2045 ((L'.ERecord [], loc), fm) 2047 ((L'.ERecord [], loc), fm)
2046 | L.ECApp ((L.EFfi ("Basis", "fieldsOf_view"), _), _) => 2048 | L.ECApp ((L.EFfi ("Basis", "fieldsOf_view"), _), _) =>
2047 ((L'.ERecord [], loc), fm) 2049 ((L'.ERecord [], loc), fm)
2048 2050
2049 | L.ECApp ((L.EApp ((L.ECApp ((L.ECApp ((L.EFfi ("Basis", "sql_from_table"), _), _), _), _), _), _), _), 2051 | L.ECApp ((L.EApp ((L.ECApp ((L.ECApp ((L.ECApp ((L.EFfi ("Basis", "sql_from_table"), _), _),
2052 _), _), _), _), _), _), _),
2050 (L.CName name, _)) => 2053 (L.CName name, _)) =>
2051 let 2054 let
2052 val s = (L'.TFfi ("Basis", "string"), loc) 2055 val s = (L'.TFfi ("Basis", "string"), loc)
2053 in 2056 in
2054 ((L'.EAbs ("tab", s, s, 2057 ((L'.EAbs ("tab", s, s,
2055 strcat [(L'.ERel 0, loc), 2058 strcat [(L'.ERel 0, loc),
2056 (L'.EPrim (Prim.String (" AS T_" ^ name)), loc)]), loc), 2059 (L'.EPrim (Prim.String (" AS T_" ^ name)), loc)]), loc),
2057 fm) 2060 fm)
2058 end 2061 end
2059 | L.ECApp ((L.ECApp ((L.EFfi ("Basis", "sql_from_comma"), _), _), _), _) => 2062 | L.ECApp ((L.ECApp ((L.ECApp ((L.EFfi ("Basis", "sql_from_comma"), _), _), _), _), _), _) =>
2060 let 2063 let
2061 val s = (L'.TFfi ("Basis", "string"), loc) 2064 val s = (L'.TFfi ("Basis", "string"), loc)
2062 in 2065 in
2063 ((L'.EAbs ("tab1", s, (L'.TFun (s, s), loc), 2066 ((L'.EAbs ("tab1", s, (L'.TFun (s, s), loc),
2064 (L'.EAbs ("tab2", s, s, 2067 (L'.EAbs ("tab2", s, s,
2065 strcat [(L'.ERel 1, loc), 2068 strcat [(L'.ERel 1, loc),
2066 (L'.EPrim (Prim.String ", "), loc), 2069 (L'.EPrim (Prim.String ", "), loc),
2067 (L'.ERel 0, loc)]), loc)), loc), 2070 (L'.ERel 0, loc)]), loc)), loc),
2068 fm) 2071 fm)
2069 end 2072 end
2070 | L.ECApp ((L.ECApp ((L.EFfi ("Basis", "sql_inner_join"), _), _), _), _) => 2073 | L.ECApp ((L.ECApp ((L.ECApp ((L.EFfi ("Basis", "sql_inner_join"), _), _), _), _), _), _) =>
2071 let 2074 let
2072 val s = (L'.TFfi ("Basis", "string"), loc) 2075 val s = (L'.TFfi ("Basis", "string"), loc)
2073 in 2076 in
2074 ((L'.EAbs ("tab1", s, (L'.TFun (s, (L'.TFun (s, s), loc)), loc), 2077 ((L'.EAbs ("tab1", s, (L'.TFun (s, (L'.TFun (s, s), loc)), loc),
2075 (L'.EAbs ("tab2", s, (L'.TFun (s, s), loc), 2078 (L'.EAbs ("tab2", s, (L'.TFun (s, s), loc),
2081 (L'.EPrim (Prim.String " ON "), loc), 2084 (L'.EPrim (Prim.String " ON "), loc),
2082 (L'.ERel 0, loc), 2085 (L'.ERel 0, loc),
2083 (L'.EPrim (Prim.String ")"), loc)]), loc)), loc)), loc), 2086 (L'.EPrim (Prim.String ")"), loc)]), loc)), loc)), loc),
2084 fm) 2087 fm)
2085 end 2088 end
2086 | L.ECApp ((L.ECApp ((L.EFfi ("Basis", "sql_left_join"), _), _), _), (L.CRecord (_, right), _)) => 2089 | L.ECApp ((L.ECApp ((L.ECApp ((L.EFfi ("Basis", "sql_left_join"), _), _), _), _), _),
2090 (L.CRecord (_, right), _)) =>
2087 let 2091 let
2088 val s = (L'.TFfi ("Basis", "string"), loc) 2092 val s = (L'.TFfi ("Basis", "string"), loc)
2089 in 2093 in
2090 ((L'.EAbs ("_", outerRec right, 2094 ((L'.EAbs ("_", outerRec right,
2091 (L'.TFun (s, (L'.TFun (s, (L'.TFun (s, s), loc)), loc)), loc), 2095 (L'.TFun (s, (L'.TFun (s, (L'.TFun (s, s), loc)), loc)), loc),
2100 (L'.ERel 0, loc), 2104 (L'.ERel 0, loc),
2101 (L'.EPrim (Prim.String ")"), loc)]), 2105 (L'.EPrim (Prim.String ")"), loc)]),
2102 loc)), loc)), loc)), loc), 2106 loc)), loc)), loc)), loc),
2103 fm) 2107 fm)
2104 end 2108 end
2105 | L.ECApp ((L.ECApp ((L.EFfi ("Basis", "sql_right_join"), _), (L.CRecord (_, left), _)), _), _) => 2109 | L.ECApp ((L.ECApp ((L.ECApp ((L.EFfi ("Basis", "sql_right_join"), _), (L.CRecord (_, left), _)),
2110 _), _), _), _) =>
2106 let 2111 let
2107 val s = (L'.TFfi ("Basis", "string"), loc) 2112 val s = (L'.TFfi ("Basis", "string"), loc)
2108 in 2113 in
2109 ((L'.EAbs ("_", outerRec left, 2114 ((L'.EAbs ("_", outerRec left,
2110 (L'.TFun (s, (L'.TFun (s, (L'.TFun (s, s), loc)), loc)), loc), 2115 (L'.TFun (s, (L'.TFun (s, (L'.TFun (s, s), loc)), loc)), loc),
2119 (L'.ERel 0, loc), 2124 (L'.ERel 0, loc),
2120 (L'.EPrim (Prim.String ")"), loc)]), 2125 (L'.EPrim (Prim.String ")"), loc)]),
2121 loc)), loc)), loc)), loc), 2126 loc)), loc)), loc)), loc),
2122 fm) 2127 fm)
2123 end 2128 end
2124 | L.ECApp ((L.ECApp ((L.EFfi ("Basis", "sql_full_join"), _), (L.CRecord (_, left), _)), _), 2129 | L.ECApp ((L.ECApp ((L.ECApp ((L.EFfi ("Basis", "sql_full_join"), _), (L.CRecord (_, left), _)), _),
2125 (L.CRecord (_, right), _)) => 2130 (L.CRecord (_, right), _)), _), _) =>
2126 let 2131 let
2127 val s = (L'.TFfi ("Basis", "string"), loc) 2132 val s = (L'.TFfi ("Basis", "string"), loc)
2128 in 2133 in
2129 ((L'.EAbs ("_", outerRec (left @ right), 2134 ((L'.EAbs ("_", outerRec (left @ right),
2130 (L'.TFun (s, (L'.TFun (s, (L'.TFun (s, s), loc)), loc)), loc), 2135 (L'.TFun (s, (L'.TFun (s, (L'.TFun (s, s), loc)), loc)), loc),
2316 2321
2317 | L.ECApp ( 2322 | L.ECApp (
2318 (L.ECApp ( 2323 (L.ECApp (
2319 (L.ECApp ( 2324 (L.ECApp (
2320 (L.ECApp ( 2325 (L.ECApp (
2321 (L.EFfi ("Basis", "sql_relop"), _), 2326 (L.ECApp (
2327 (L.EFfi ("Basis", "sql_relop"), _),
2328 _), _),
2322 _), _), 2329 _), _),
2323 _), _), 2330 _), _),
2324 _), _), 2331 _), _),
2325 _) => 2332 _) =>
2326 let 2333 let
2340 fm) 2347 fm)
2341 end 2348 end
2342 | L.ECApp ( 2349 | L.ECApp (
2343 (L.ECApp ( 2350 (L.ECApp (
2344 (L.ECApp ( 2351 (L.ECApp (
2345 (L.EFfi ("Basis", "sql_forget_tables"), _), 2352 (L.ECApp (
2353 (L.EFfi ("Basis", "sql_forget_tables"), _),
2354 _), _),
2346 _), _), 2355 _), _),
2347 _), _), 2356 _), _),
2348 _) => 2357 _) =>
2349 let 2358 let
2350 val s = (L'.TFfi ("Basis", "string"), loc) 2359 val s = (L'.TFfi ("Basis", "string"), loc)
2516 fun sc s = (L'.EPrim (Prim.String s), loc) 2525 fun sc s = (L'.EPrim (Prim.String s), loc)
2517 in 2526 in
2518 ((L'.EAbs ("u", (L'.TRecord [], loc), (L'.TFun (s, s), loc), 2527 ((L'.EAbs ("u", (L'.TRecord [], loc), (L'.TFun (s, s), loc),
2519 (L'.EAbs ("x", s, s, 2528 (L'.EAbs ("x", s, s,
2520 (L'.ERel 0, loc)), loc)), loc), 2529 (L'.ERel 0, loc)), loc)), loc),
2530 fm)
2531 end
2532
2533 | L.ECApp (
2534 (L.ECApp (
2535 (L.ECApp (
2536 (L.ECApp (
2537 (L.ECApp (
2538 (L.EFfi ("Basis", "sql_subquery"), _),
2539 _), _),
2540 _), _),
2541 _), _),
2542 _), _),
2543 _) =>
2544 let
2545 val s = (L'.TFfi ("Basis", "string"), loc)
2546 fun sc s = (L'.EPrim (Prim.String s), loc)
2547 in
2548 ((L'.EAbs ("x", s, s,
2549 strcat [sc "(",
2550 (L'.ERel 0, loc),
2551 sc ")"]), loc),
2521 fm) 2552 fm)
2522 end 2553 end
2523 2554
2524 | L.EFfiApp ("Basis", "nextval", [e]) => 2555 | L.EFfiApp ("Basis", "nextval", [e]) =>
2525 let 2556 let