comparison src/monoize.sml @ 559:5d494183ca89

Add SQL arithmetic operators
author Adam Chlipala <adamc@hcoop.net>
date Tue, 09 Dec 2008 14:41:19 -0500
parents 4154b4dc62c6
children 803b2f3bb86b
comparison
equal deleted inserted replaced
558:390cba747188 559:5d494183ca89
163 (L'.TFun (mt env dtmap t, (L'.TFfi ("Basis", "string"), loc)), loc) 163 (L'.TFun (mt env dtmap t, (L'.TFfi ("Basis", "string"), loc)), loc)
164 | L.CApp ((L.CApp ((L.CFfi ("Basis", "sql_unary"), _), _), _), _) => 164 | L.CApp ((L.CApp ((L.CFfi ("Basis", "sql_unary"), _), _), _), _) =>
165 (L'.TFfi ("Basis", "string"), loc) 165 (L'.TFfi ("Basis", "string"), loc)
166 | L.CApp ((L.CApp ((L.CApp ((L.CFfi ("Basis", "sql_binary"), _), _), _), _), _), _) => 166 | L.CApp ((L.CApp ((L.CApp ((L.CFfi ("Basis", "sql_binary"), _), _), _), _), _), _) =>
167 (L'.TFfi ("Basis", "string"), loc) 167 (L'.TFfi ("Basis", "string"), loc)
168 | L.CFfi ("Basis", "sql_comparison") =>
169 (L'.TFfi ("Basis", "string"), loc)
170 | L.CApp ((L.CFfi ("Basis", "sql_aggregate"), _), t) => 168 | L.CApp ((L.CFfi ("Basis", "sql_aggregate"), _), t) =>
171 (L'.TFfi ("Basis", "string"), loc) 169 (L'.TFfi ("Basis", "string"), loc)
172 | L.CApp ((L.CFfi ("Basis", "sql_summable"), _), _) => 170 | L.CApp ((L.CFfi ("Basis", "sql_summable"), _), _) =>
173 (L'.TRecord [], loc) 171 (L'.TRecord [], loc)
174 | L.CApp ((L.CFfi ("Basis", "sql_maxable"), _), _) => 172 | L.CApp ((L.CFfi ("Basis", "sql_maxable"), _), _) =>
173 (L'.TRecord [], loc)
174 | L.CApp ((L.CFfi ("Basis", "sql_arith"), _), _) =>
175 (L'.TRecord [], loc) 175 (L'.TRecord [], loc)
176 | L.CApp ((L.CFfi ("Basis", "sql_nfunc"), _), _) => 176 | L.CApp ((L.CFfi ("Basis", "sql_nfunc"), _), _) =>
177 (L'.TFfi ("Basis", "string"), loc) 177 (L'.TFfi ("Basis", "string"), loc)
178 178
179 | L.CRel _ => poly () 179 | L.CRel _ => poly ()
1367 (L'.EFfiApp ("Basis", "sqlifyInt", [e]), loc) 1367 (L'.EFfiApp ("Basis", "sqlifyInt", [e]), loc)
1368 ], 1368 ],
1369 fm) 1369 fm)
1370 end 1370 end
1371 1371
1372 | L.EFfi ("Basis", "sql_eq") => 1372 | L.ECApp ((L.EFfi ("Basis", "sql_eq"), _), _) =>
1373 ((L'.EPrim (Prim.String "="), loc), fm) 1373 ((L'.EPrim (Prim.String "="), loc), fm)
1374 | L.EFfi ("Basis", "sql_ne") => 1374 | L.ECApp ((L.EFfi ("Basis", "sql_ne"), _), _) =>
1375 ((L'.EPrim (Prim.String "<>"), loc), fm) 1375 ((L'.EPrim (Prim.String "<>"), loc), fm)
1376 | L.EFfi ("Basis", "sql_lt") => 1376 | L.ECApp ((L.EFfi ("Basis", "sql_lt"), _), _) =>
1377 ((L'.EPrim (Prim.String "<"), loc), fm) 1377 ((L'.EPrim (Prim.String "<"), loc), fm)
1378 | L.EFfi ("Basis", "sql_le") => 1378 | L.ECApp ((L.EFfi ("Basis", "sql_le"), _), _) =>
1379 ((L'.EPrim (Prim.String "<="), loc), fm) 1379 ((L'.EPrim (Prim.String "<="), loc), fm)
1380 | L.EFfi ("Basis", "sql_gt") => 1380 | L.ECApp ((L.EFfi ("Basis", "sql_gt"), _), _) =>
1381 ((L'.EPrim (Prim.String ">"), loc), fm) 1381 ((L'.EPrim (Prim.String ">"), loc), fm)
1382 | L.EFfi ("Basis", "sql_ge") => 1382 | L.ECApp ((L.EFfi ("Basis", "sql_ge"), _), _) =>
1383 ((L'.EPrim (Prim.String ">="), loc), fm) 1383 ((L'.EPrim (Prim.String ">="), loc), fm)
1384
1385 | L.ECApp ((L.EFfi ("Basis", "sql_plus"), _), _) =>
1386 ((L'.EAbs ("_", (L'.TRecord [], loc), (L'.TFfi ("Basis", "string"), loc),
1387 (L'.EPrim (Prim.String "+"), loc)), loc), fm)
1388 | L.ECApp ((L.EFfi ("Basis", "sql_minus"), _), _) =>
1389 ((L'.EAbs ("_", (L'.TRecord [], loc), (L'.TFfi ("Basis", "string"), loc),
1390 (L'.EPrim (Prim.String "-"), loc)), loc), fm)
1391 | L.ECApp ((L.EFfi ("Basis", "sql_times"), _), _) =>
1392 ((L'.EAbs ("_", (L'.TRecord [], loc), (L'.TFfi ("Basis", "string"), loc),
1393 (L'.EPrim (Prim.String "*"), loc)), loc), fm)
1394 | L.ECApp ((L.EFfi ("Basis", "sql_div"), _), _) =>
1395 ((L'.EAbs ("_", (L'.TRecord [], loc), (L'.TFfi ("Basis", "string"), loc),
1396 (L'.EPrim (Prim.String "/"), loc)), loc), fm)
1397 | L.EFfi ("Basis", "sql_mod") =>
1398 ((L'.EPrim (Prim.String "%"), loc), fm)
1384 1399
1385 | L.ECApp ( 1400 | L.ECApp (
1386 (L.ECApp ( 1401 (L.ECApp (
1387 (L.ECApp ( 1402 (L.ECApp (
1388 (L.ECApp ( 1403 (L.ECApp (
1405 (L'.ERel 0, loc), 1420 (L'.ERel 0, loc),
1406 sc ")"]), loc)), loc), 1421 sc ")"]), loc)), loc),
1407 fm) 1422 fm)
1408 end 1423 end
1409 | L.EFfi ("Basis", "sql_not") => ((L'.EPrim (Prim.String "NOT"), loc), fm) 1424 | L.EFfi ("Basis", "sql_not") => ((L'.EPrim (Prim.String "NOT"), loc), fm)
1425 | L.ECApp ((L.EFfi ("Basis", "sql_neg"), _), _) =>
1426 ((L'.EAbs ("_", (L'.TRecord [], loc), (L'.TFfi ("Basis", "string"), loc),
1427 (L'.EPrim (Prim.String "-"), loc)), loc), fm)
1410 1428
1411 | L.ECApp ( 1429 | L.ECApp (
1412 (L.ECApp ( 1430 (L.ECApp (
1413 (L.ECApp ( 1431 (L.ECApp (
1414 (L.ECApp ( 1432 (L.ECApp (
1437 sc ")"]), loc)), loc)), loc), 1455 sc ")"]), loc)), loc)), loc),
1438 fm) 1456 fm)
1439 end 1457 end
1440 | L.EFfi ("Basis", "sql_and") => ((L'.EPrim (Prim.String "AND"), loc), fm) 1458 | L.EFfi ("Basis", "sql_and") => ((L'.EPrim (Prim.String "AND"), loc), fm)
1441 | L.EFfi ("Basis", "sql_or") => ((L'.EPrim (Prim.String "OR"), loc), fm) 1459 | L.EFfi ("Basis", "sql_or") => ((L'.EPrim (Prim.String "OR"), loc), fm)
1442
1443 | L.ECApp (
1444 (L.ECApp (
1445 (L.ECApp (
1446 (L.ECApp (
1447 (L.EFfi ("Basis", "sql_comparison"), _),
1448 _), _),
1449 _), _),
1450 _), _),
1451 _) =>
1452 let
1453 val s = (L'.TFfi ("Basis", "string"), loc)
1454 fun sc s = (L'.EPrim (Prim.String s), loc)
1455 in
1456 ((L'.EAbs ("c", s, (L'.TFun (s, (L'.TFun (s, s), loc)), loc),
1457 (L'.EAbs ("e1", s, (L'.TFun (s, s), loc),
1458 (L'.EAbs ("e2", s, s,
1459 strcat loc [sc "(",
1460 (L'.ERel 1, loc),
1461 sc " ",
1462 (L'.ERel 2, loc),
1463 sc " ",
1464 (L'.ERel 0, loc),
1465 sc ")"]), loc)), loc)), loc),
1466 fm)
1467 end
1468 1460
1469 | L.ECApp ( 1461 | L.ECApp (
1470 (L.ECApp ( 1462 (L.ECApp (
1471 (L.ECApp ( 1463 (L.ECApp (
1472 (L.ECApp ( 1464 (L.ECApp (
1563 fm) 1555 fm)
1564 | L.ECApp ((L.EFfi ("Basis", "sql_sum"), _), _) => 1556 | L.ECApp ((L.EFfi ("Basis", "sql_sum"), _), _) =>
1565 ((L'.EAbs ("_", (L'.TRecord [], loc), (L'.TFfi ("Basis", "string"), loc), 1557 ((L'.EAbs ("_", (L'.TRecord [], loc), (L'.TFfi ("Basis", "string"), loc),
1566 (L'.EPrim (Prim.String "SUM"), loc)), loc), 1558 (L'.EPrim (Prim.String "SUM"), loc)), loc),
1567 fm) 1559 fm)
1560
1561 | L.EFfi ("Basis", "sql_arith_int") => ((L'.ERecord [], loc), fm)
1562 | L.EFfi ("Basis", "sql_arith_float") => ((L'.ERecord [], loc), fm)
1568 1563
1569 | L.EFfi ("Basis", "sql_maxable_int") => ((L'.ERecord [], loc), fm) 1564 | L.EFfi ("Basis", "sql_maxable_int") => ((L'.ERecord [], loc), fm)
1570 | L.EFfi ("Basis", "sql_maxable_float") => ((L'.ERecord [], loc), fm) 1565 | L.EFfi ("Basis", "sql_maxable_float") => ((L'.ERecord [], loc), fm)
1571 | L.EFfi ("Basis", "sql_maxable_string") => ((L'.ERecord [], loc), fm) 1566 | L.EFfi ("Basis", "sql_maxable_string") => ((L'.ERecord [], loc), fm)
1572 | L.ECApp ((L.EFfi ("Basis", "sql_max"), _), _) => 1567 | L.ECApp ((L.EFfi ("Basis", "sql_max"), _), _) =>