Mercurial > urweb
comparison src/cjr_print.sml @ 1524:a71223513c77
Compile self-tail-calls as gotos
author | Adam Chlipala <adam@chlipala.net> |
---|---|
date | Tue, 02 Aug 2011 17:04:14 -0400 |
parents | c4f39b49aa2d |
children | e627bab3eda7 |
comparison
equal
deleted
inserted
replaced
1523:52fbd8534ef3 | 1524:a71223513c77 |
---|---|
1317 | EDml {dml = e, ...} => potentiallyFancy e | 1317 | EDml {dml = e, ...} => potentiallyFancy e |
1318 | ENextval {seq = e, ...} => potentiallyFancy e | 1318 | ENextval {seq = e, ...} => potentiallyFancy e |
1319 | ESetval {seq = e1, count = e2} => potentiallyFancy e1 orelse potentiallyFancy e2 | 1319 | ESetval {seq = e1, count = e2} => potentiallyFancy e1 orelse potentiallyFancy e2 |
1320 | EUnurlify _ => true | 1320 | EUnurlify _ => true |
1321 | 1321 |
1322 fun p_exp' par env (e, loc) = | 1322 val self = ref (NONE : int option) |
1323 | |
1324 fun p_exp' par tail env (e, loc) = | |
1323 case e of | 1325 case e of |
1324 EPrim p => Prim.p_t_GCC p | 1326 EPrim p => Prim.p_t_GCC p |
1325 | ERel n => p_rel env n | 1327 | ERel n => p_rel env n |
1326 | ENamed n => p_enamed env n | 1328 | ENamed n => p_enamed env n |
1327 | ECon (Enum, pc, _) => p_patCon env pc | 1329 | ECon (Enum, pc, _) => p_patCon env pc |
1335 val t = case to of | 1337 val t = case to of |
1336 NONE => raise Fail "CjrPrint: ECon argument status mismatch" | 1338 NONE => raise Fail "CjrPrint: ECon argument status mismatch" |
1337 | SOME t => t | 1339 | SOME t => t |
1338 in | 1340 in |
1339 if isUnboxable t then | 1341 if isUnboxable t then |
1340 p_exp' par env e | 1342 p_exp' par tail env e |
1341 else | 1343 else |
1342 box [string "({", | 1344 box [string "({", |
1343 newline, | 1345 newline, |
1344 p_typ env t, | 1346 p_typ env t, |
1345 space, | 1347 space, |
1353 newline, | 1355 newline, |
1354 string "*tmp", | 1356 string "*tmp", |
1355 space, | 1357 space, |
1356 string "=", | 1358 string "=", |
1357 space, | 1359 space, |
1358 p_exp' par env e, | 1360 p_exp' par false env e, |
1359 string ";", | 1361 string ";", |
1360 newline, | 1362 newline, |
1361 string "tmp;", | 1363 string "tmp;", |
1362 newline, | 1364 newline, |
1363 string "})"] | 1365 string "})"] |
1392 | SOME e => box [string "tmp->data.", | 1394 | SOME e => box [string "tmp->data.", |
1393 string xn, | 1395 string xn, |
1394 space, | 1396 space, |
1395 string "=", | 1397 string "=", |
1396 space, | 1398 space, |
1397 p_exp env e, | 1399 p_exp' false false env e, |
1398 string ";", | 1400 string ";", |
1399 newline], | 1401 newline], |
1400 string "tmp;", | 1402 string "tmp;", |
1401 newline, | 1403 newline, |
1402 string "})"] | 1404 string "})"] |
1403 end | 1405 end |
1404 | ENone _ => string "NULL" | 1406 | ENone _ => string "NULL" |
1405 | ESome (t, e) => | 1407 | ESome (t, e) => |
1406 if isUnboxable t then | 1408 if isUnboxable t then |
1407 p_exp' par env e | 1409 p_exp' par tail env e |
1408 else | 1410 else |
1409 box [string "({", | 1411 box [string "({", |
1410 newline, | 1412 newline, |
1411 p_typ env t, | 1413 p_typ env t, |
1412 space, | 1414 space, |
1420 newline, | 1422 newline, |
1421 string "*tmp", | 1423 string "*tmp", |
1422 space, | 1424 space, |
1423 string "=", | 1425 string "=", |
1424 space, | 1426 space, |
1425 p_exp' par env e, | 1427 p_exp' par false env e, |
1426 string ";", | 1428 string ";", |
1427 newline, | 1429 newline, |
1428 string "tmp;", | 1430 string "tmp;", |
1429 newline, | 1431 newline, |
1430 string "})"] | 1432 string "})"] |
1438 string "tmp;", | 1440 string "tmp;", |
1439 newline, | 1441 newline, |
1440 string "uw_error(ctx, FATAL, \"", | 1442 string "uw_error(ctx, FATAL, \"", |
1441 string (ErrorMsg.spanToString loc), | 1443 string (ErrorMsg.spanToString loc), |
1442 string ": %s\", ", | 1444 string ": %s\", ", |
1443 p_exp env e, | 1445 p_exp' false false env e, |
1444 string ");", | 1446 string ");", |
1445 newline, | 1447 newline, |
1446 string "tmp;", | 1448 string "tmp;", |
1447 newline, | 1449 newline, |
1448 string "})"] | 1450 string "})"] |
1452 p_typ env t, | 1454 p_typ env t, |
1453 space, | 1455 space, |
1454 string "tmp;", | 1456 string "tmp;", |
1455 newline, | 1457 newline, |
1456 string "uw_return_blob(ctx, ", | 1458 string "uw_return_blob(ctx, ", |
1457 p_exp env blob, | 1459 p_exp' false false env blob, |
1458 string ", ", | 1460 string ", ", |
1459 p_exp env mimeType, | 1461 p_exp' false false env mimeType, |
1460 string ");", | 1462 string ");", |
1461 newline, | 1463 newline, |
1462 string "tmp;", | 1464 string "tmp;", |
1463 newline, | 1465 newline, |
1464 string "})"] | 1466 string "})"] |
1468 p_typ env t, | 1470 p_typ env t, |
1469 space, | 1471 space, |
1470 string "tmp;", | 1472 string "tmp;", |
1471 newline, | 1473 newline, |
1472 string "uw_redirect(ctx, ", | 1474 string "uw_redirect(ctx, ", |
1473 p_exp env e, | 1475 p_exp' false false env e, |
1474 string ");", | 1476 string ");", |
1475 newline, | 1477 newline, |
1476 string "tmp;", | 1478 string "tmp;", |
1477 newline, | 1479 newline, |
1478 string "})"] | 1480 string "})"] |
1479 | EApp ((EError (e, (TFun (_, ran), _)), loc), _) => | 1481 | EApp ((EError (e, (TFun (_, ran), _)), loc), _) => |
1480 p_exp env (EError (e, ran), loc) | 1482 p_exp' false false env (EError (e, ran), loc) |
1481 | EApp ((EReturnBlob {blob, mimeType, t = (TFun (_, ran), _)}, loc), _) => | 1483 | EApp ((EReturnBlob {blob, mimeType, t = (TFun (_, ran), _)}, loc), _) => |
1482 p_exp env (EReturnBlob {blob = blob, mimeType = mimeType, t = ran}, loc) | 1484 p_exp' false false env (EReturnBlob {blob = blob, mimeType = mimeType, t = ran}, loc) |
1483 | 1485 |
1484 | EFfiApp ("Basis", "strcat", [e1, e2]) => | 1486 | EFfiApp ("Basis", "strcat", [e1, e2]) => |
1485 let | 1487 let |
1486 fun flatten e = | 1488 fun flatten e = |
1487 case #1 e of | 1489 case #1 e of |
1488 EFfiApp ("Basis", "strcat", [e1, e2]) => flatten e1 @ flatten e2 | 1490 EFfiApp ("Basis", "strcat", [e1, e2]) => flatten e1 @ flatten e2 |
1489 | _ => [e] | 1491 | _ => [e] |
1490 in | 1492 in |
1491 case flatten e1 @ flatten e2 of | 1493 case flatten e1 @ flatten e2 of |
1492 [e1, e2] => box [string "uw_Basis_strcat(ctx, ", | 1494 [e1, e2] => box [string "uw_Basis_strcat(ctx, ", |
1493 p_exp env e1, | 1495 p_exp' false false env e1, |
1494 string ",", | 1496 string ",", |
1495 p_exp env e2, | 1497 p_exp' false false env e2, |
1496 string ")"] | 1498 string ")"] |
1497 | es => box [string "uw_Basis_mstrcat(ctx, ", | 1499 | es => box [string "uw_Basis_mstrcat(ctx, ", |
1498 p_list (p_exp env) es, | 1500 p_list (p_exp' false false env) es, |
1499 string ", NULL)"] | 1501 string ", NULL)"] |
1500 end | 1502 end |
1501 | 1503 |
1502 | EFfiApp (m, x, []) => box [string "uw_", | 1504 | EFfiApp (m, x, []) => box [string "uw_", |
1503 p_ident m, | 1505 p_ident m, |
1508 | EFfiApp (m, x, es) => box [string "uw_", | 1510 | EFfiApp (m, x, es) => box [string "uw_", |
1509 p_ident m, | 1511 p_ident m, |
1510 string "_", | 1512 string "_", |
1511 p_ident x, | 1513 p_ident x, |
1512 string "(ctx, ", | 1514 string "(ctx, ", |
1513 p_list (p_exp env) es, | 1515 p_list (p_exp' false false env) es, |
1514 string ")"] | 1516 string ")"] |
1515 | EApp (f, args) => | 1517 | EApp (f, args) => |
1516 parenIf par (box [p_exp' true env f, | 1518 let |
1517 string "(ctx,", | 1519 fun default () = parenIf par (box [p_exp' true false env f, |
1518 space, | 1520 string "(ctx,", |
1519 p_list_sep (box [string ",", space]) (p_exp env) args, | 1521 space, |
1520 string ")"]) | 1522 p_list_sep (box [string ",", space]) (p_exp' false false env) args, |
1523 string ")"]) | |
1524 | |
1525 fun isSelf n = | |
1526 let | |
1527 val (_, t) = E.lookupENamed env n | |
1528 | |
1529 fun getSig (t, args) = | |
1530 case #1 t of | |
1531 TFun (dom, t) => getSig (t, dom :: args) | |
1532 | _ => (args, t) | |
1533 | |
1534 val (argts, ret) = getSig (t, []) | |
1535 in | |
1536 parenIf par (box [string "({", | |
1537 newline, | |
1538 p_list_sepi newline | |
1539 (fn i => fn (e, t) => | |
1540 box [p_typ env t, | |
1541 space, | |
1542 string ("rearg" ^ Int.toString i), | |
1543 space, | |
1544 string "=", | |
1545 space, | |
1546 p_exp' false false env e, | |
1547 string ";"]) | |
1548 (ListPair.zip (args, argts)), | |
1549 newline, | |
1550 p_typ env ret, | |
1551 space, | |
1552 string "tmp;", | |
1553 newline, | |
1554 p_list_sepi newline | |
1555 (fn i => fn _ => | |
1556 box [p_rel env (E.countERels env - 1 - i), | |
1557 space, | |
1558 string "=", | |
1559 space, | |
1560 string ("rearg" ^ Int.toString i ^ ";")]) args, | |
1561 newline, | |
1562 string "goto restart;", | |
1563 newline, | |
1564 string "tmp;", | |
1565 newline, | |
1566 string "})"]) | |
1567 end | |
1568 in | |
1569 case #1 f of | |
1570 ENamed n => if SOME n = !self andalso tail then | |
1571 isSelf n | |
1572 else | |
1573 default () | |
1574 | _ => default () | |
1575 end | |
1521 | 1576 |
1522 | EUnop (s, e1) => | 1577 | EUnop (s, e1) => |
1523 parenIf par (box [string s, | 1578 parenIf par (box [string s, |
1524 space, | 1579 space, |
1525 p_exp' true env e1]) | 1580 p_exp' true false env e1]) |
1526 | 1581 |
1527 | EBinop (s, e1, e2) => | 1582 | EBinop (s, e1, e2) => |
1528 if Char.isAlpha (String.sub (s, size s - 1)) then | 1583 if Char.isAlpha (String.sub (s, size s - 1)) then |
1529 box [string s, | 1584 box [string s, |
1530 string "(", | 1585 string "(", |
1531 p_exp env e1, | 1586 p_exp' false false env e1, |
1532 string ",", | 1587 string ",", |
1533 space, | 1588 space, |
1534 p_exp env e2, | 1589 p_exp' false false env e2, |
1535 string ")"] | 1590 string ")"] |
1536 else | 1591 else |
1537 parenIf par (box [p_exp' true env e1, | 1592 parenIf par (box [p_exp' true false env e1, |
1538 space, | 1593 space, |
1539 string s, | 1594 string s, |
1540 space, | 1595 space, |
1541 p_exp' true env e2]) | 1596 p_exp' true false env e2]) |
1542 | 1597 |
1543 | ERecord (0, _) => string "0" | 1598 | ERecord (0, _) => string "0" |
1544 | 1599 |
1545 | ERecord (i, xes) => box [string "({", | 1600 | ERecord (i, xes) => box [string "({", |
1546 space, | 1601 space, |
1552 space, | 1607 space, |
1553 string "=", | 1608 string "=", |
1554 space, | 1609 space, |
1555 string "{", | 1610 string "{", |
1556 p_list (fn (_, e) => | 1611 p_list (fn (_, e) => |
1557 p_exp env e) xes, | 1612 p_exp' false false env e) xes, |
1558 string "};", | 1613 string "};", |
1559 space, | 1614 space, |
1560 string "tmp;", | 1615 string "tmp;", |
1561 space, | 1616 space, |
1562 string "})" ] | 1617 string "})" ] |
1563 | EField (e, x) => | 1618 | EField (e, x) => |
1564 box [p_exp' true env e, | 1619 box [p_exp' true false env e, |
1565 string ".__uwf_", | 1620 string ".__uwf_", |
1566 p_ident x] | 1621 p_ident x] |
1567 | 1622 |
1568 | ECase (e, pes, {disc, result}) => | 1623 | ECase (e, pes, {disc, result}) => |
1569 box [string "({", | 1624 box [string "({", |
1572 space, | 1627 space, |
1573 string "disc", | 1628 string "disc", |
1574 space, | 1629 space, |
1575 string "=", | 1630 string "=", |
1576 space, | 1631 space, |
1577 p_exp env e, | 1632 p_exp' false false env e, |
1578 string ";", | 1633 string ";", |
1579 newline, | 1634 newline, |
1580 newline, | 1635 newline, |
1581 foldr (fn ((p, e), body) => | 1636 foldr (fn ((p, e), body) => |
1582 let | 1637 let |
1586 box [pm, | 1641 box [pm, |
1587 space, | 1642 space, |
1588 string "?", | 1643 string "?", |
1589 space, | 1644 space, |
1590 if E.countERels env' = E.countERels env then | 1645 if E.countERels env' = E.countERels env then |
1591 p_exp env e | 1646 p_exp' false tail env e |
1592 else | 1647 else |
1593 box [string "({", | 1648 box [string "({", |
1594 pb, | 1649 pb, |
1595 p_exp env' e, | 1650 p_exp' false tail env' e, |
1596 string ";", | 1651 string ";", |
1597 newline, | 1652 newline, |
1598 string "})"], | 1653 string "})"], |
1599 newline, | 1654 newline, |
1600 space, | 1655 space, |
1617 string ";", | 1672 string ";", |
1618 newline, | 1673 newline, |
1619 string "})"] | 1674 string "})"] |
1620 | 1675 |
1621 | EWrite e => box [string "(uw_write(ctx, ", | 1676 | EWrite e => box [string "(uw_write(ctx, ", |
1622 p_exp env e, | 1677 p_exp' false false env e, |
1623 string "), 0)"] | 1678 string "), 0)"] |
1624 | 1679 |
1625 | ESeq (e1, e2) => | 1680 | ESeq (e1, e2) => |
1626 let | 1681 let |
1627 val useRegion = potentiallyFancy e1 | 1682 val useRegion = potentiallyFancy e1 |
1630 if useRegion then | 1685 if useRegion then |
1631 box [string "uw_begin_region(ctx),", | 1686 box [string "uw_begin_region(ctx),", |
1632 space] | 1687 space] |
1633 else | 1688 else |
1634 box [], | 1689 box [], |
1635 p_exp env e1, | 1690 p_exp' false false env e1, |
1636 string ",", | 1691 string ",", |
1637 space, | 1692 space, |
1638 if useRegion then | 1693 if useRegion then |
1639 box [string "uw_end_region(ctx),", | 1694 box [string "uw_end_region(ctx),", |
1640 space] | 1695 space] |
1641 else | 1696 else |
1642 box [], | 1697 box [], |
1643 p_exp env e2, | 1698 p_exp' false tail env e2, |
1644 string ")"] | 1699 string ")"] |
1645 end | 1700 end |
1646 | ELet (x, t, e1, e2) => | 1701 | ELet (x, t, e1, e2) => |
1647 let | 1702 let |
1648 val useRegion = notLeaky env false t andalso potentiallyFancy e1 | 1703 val useRegion = notLeaky env false t andalso potentiallyFancy e1 |
1661 if useRegion then | 1716 if useRegion then |
1662 box [string "(uw_begin_region(ctx),", | 1717 box [string "(uw_begin_region(ctx),", |
1663 space] | 1718 space] |
1664 else | 1719 else |
1665 box [], | 1720 box [], |
1666 p_exp env e1, | 1721 p_exp' false false env e1, |
1667 if useRegion then | 1722 if useRegion then |
1668 string ")" | 1723 string ")" |
1669 else | 1724 else |
1670 box [], | 1725 box [], |
1671 string ";", | 1726 string ";", |
1673 if useRegion then | 1728 if useRegion then |
1674 box [string "uw_end_region(ctx);", | 1729 box [string "uw_end_region(ctx);", |
1675 newline] | 1730 newline] |
1676 else | 1731 else |
1677 box [], | 1732 box [], |
1678 p_exp (E.pushERel env x t) e2, | 1733 p_exp' false tail (E.pushERel env x t) e2, |
1679 string ";", | 1734 string ";", |
1680 newline, | 1735 newline, |
1681 string "})"] | 1736 string "})"] |
1682 end | 1737 end |
1683 | 1738 |
1743 | 1798 |
1744 string "acc", | 1799 string "acc", |
1745 space, | 1800 space, |
1746 string "=", | 1801 string "=", |
1747 space, | 1802 space, |
1748 p_exp (E.pushERel | 1803 p_exp' false false (E.pushERel |
1749 (E.pushERel env "r" (TRecord rnum, loc)) | 1804 (E.pushERel env "r" (TRecord rnum, loc)) |
1750 "acc" state) | 1805 "acc" state) |
1751 body, | 1806 body, |
1752 string ";", | 1807 string ";", |
1753 newline] | 1808 newline] |
1754 in | 1809 in |
1755 box [if wontLeakAnything then | 1810 box [if wontLeakAnything then |
1756 string "(uw_begin_region(ctx), " | 1811 string "(uw_begin_region(ctx), " |
1762 space, | 1817 space, |
1763 string "acc", | 1818 string "acc", |
1764 space, | 1819 space, |
1765 string "=", | 1820 string "=", |
1766 space, | 1821 space, |
1767 p_exp env initial, | 1822 p_exp' false false env initial, |
1768 string ";", | 1823 string ";", |
1769 newline, | 1824 newline, |
1770 string "int dummy = (uw_begin_region(ctx), 0);", | 1825 string "int dummy = (uw_begin_region(ctx), 0);", |
1771 newline, | 1826 newline, |
1772 | 1827 |
1773 case prepared of | 1828 case prepared of |
1774 NONE => | 1829 NONE => |
1775 box [string "char *query = ", | 1830 box [string "char *query = ", |
1776 p_exp env query, | 1831 p_exp' false false env query, |
1777 string ";", | 1832 string ";", |
1778 newline, | 1833 newline, |
1779 newline, | 1834 newline, |
1780 | 1835 |
1781 #query (Settings.currentDbms ()) | 1836 #query (Settings.currentDbms ()) |
1790 string "arg", | 1845 string "arg", |
1791 string (Int.toString (i + 1)), | 1846 string (Int.toString (i + 1)), |
1792 space, | 1847 space, |
1793 string "=", | 1848 string "=", |
1794 space, | 1849 space, |
1795 p_exp env e, | 1850 p_exp' false false env e, |
1796 string ";"]) | 1851 string ";"]) |
1797 inputs, | 1852 inputs, |
1798 newline, | 1853 newline, |
1799 newline, | 1854 newline, |
1800 | 1855 |
1825 | EDml {dml, prepared, mode} => | 1880 | EDml {dml, prepared, mode} => |
1826 box [string "(uw_begin_region(ctx), ({", | 1881 box [string "(uw_begin_region(ctx), ({", |
1827 newline, | 1882 newline, |
1828 case prepared of | 1883 case prepared of |
1829 NONE => box [string "char *dml = ", | 1884 NONE => box [string "char *dml = ", |
1830 p_exp env dml, | 1885 p_exp' false false env dml, |
1831 string ";", | 1886 string ";", |
1832 newline, | 1887 newline, |
1833 newline, | 1888 newline, |
1834 #dml (Settings.currentDbms ()) (loc, mode)] | 1889 #dml (Settings.currentDbms ()) (loc, mode)] |
1835 | SOME {id, dml = dml'} => | 1890 | SOME {id, dml = dml'} => |
1843 string "arg", | 1898 string "arg", |
1844 string (Int.toString (i + 1)), | 1899 string (Int.toString (i + 1)), |
1845 space, | 1900 space, |
1846 string "=", | 1901 string "=", |
1847 space, | 1902 space, |
1848 p_exp env e, | 1903 p_exp' false false env e, |
1849 string ";"]) | 1904 string ";"]) |
1850 inputs, | 1905 inputs, |
1851 newline, | 1906 newline, |
1852 newline, | 1907 newline, |
1853 | 1908 |
1875 string "uw_Basis_int n;", | 1930 string "uw_Basis_int n;", |
1876 newline, | 1931 newline, |
1877 | 1932 |
1878 case prepared of | 1933 case prepared of |
1879 NONE => #nextval (Settings.currentDbms ()) {loc = loc, | 1934 NONE => #nextval (Settings.currentDbms ()) {loc = loc, |
1880 seqE = p_exp env seq, | 1935 seqE = p_exp' false false env seq, |
1881 seqName = case #1 seq of | 1936 seqName = case #1 seq of |
1882 EPrim (Prim.String s) => SOME s | 1937 EPrim (Prim.String s) => SOME s |
1883 | _ => NONE} | 1938 | _ => NONE} |
1884 | SOME {id, query} => #nextvalPrepared (Settings.currentDbms ()) {loc = loc, | 1939 | SOME {id, query} => #nextvalPrepared (Settings.currentDbms ()) {loc = loc, |
1885 id = id, | 1940 id = id, |
1894 | ESetval {seq, count} => | 1949 | ESetval {seq, count} => |
1895 box [string "({", | 1950 box [string "({", |
1896 newline, | 1951 newline, |
1897 | 1952 |
1898 #setval (Settings.currentDbms ()) {loc = loc, | 1953 #setval (Settings.currentDbms ()) {loc = loc, |
1899 seqE = p_exp env seq, | 1954 seqE = p_exp' false false env seq, |
1900 count = p_exp env count}, | 1955 count = p_exp' false false env count}, |
1901 newline, | 1956 newline, |
1902 newline, | 1957 newline, |
1903 | 1958 |
1904 string "0;", | 1959 string "0;", |
1905 newline, | 1960 newline, |
1927 string "})"] | 1982 string "})"] |
1928 in | 1983 in |
1929 box [string "({", | 1984 box [string "({", |
1930 newline, | 1985 newline, |
1931 string "uw_Basis_string request = uw_maybe_strdup(ctx, ", | 1986 string "uw_Basis_string request = uw_maybe_strdup(ctx, ", |
1932 p_exp env e, | 1987 p_exp' false false env e, |
1933 string ");", | 1988 string ");", |
1934 newline, | 1989 newline, |
1935 newline, | 1990 newline, |
1936 string "(request ? ", | 1991 string "(request ? ", |
1937 getIt (), | 1992 getIt (), |
1962 string "})"] | 2017 string "})"] |
1963 in | 2018 in |
1964 box [string "({", | 2019 box [string "({", |
1965 newline, | 2020 newline, |
1966 string "uw_Basis_string request = uw_maybe_strdup(ctx, ", | 2021 string "uw_Basis_string request = uw_maybe_strdup(ctx, ", |
1967 p_exp env e, | 2022 p_exp' false false env e, |
1968 string ");", | 2023 string ");", |
1969 newline, | 2024 newline, |
1970 newline, | 2025 newline, |
1971 unurlify false env t, | 2026 unurlify false env t, |
1972 string ";", | 2027 string ";", |
1973 newline, | 2028 newline, |
1974 string "})"] | 2029 string "})"] |
1975 end | 2030 end |
1976 | 2031 |
1977 and p_exp env = p_exp' false env | 2032 and p_exp env = p_exp' false true env |
1978 | 2033 |
1979 fun p_fun isRec env (fx, n, args, ran, e) = | 2034 fun p_fun isRec env (fx, n, args, ran, e) = |
1980 let | 2035 let |
1981 val nargs = length args | 2036 val nargs = length args |
1982 val env' = foldl (fn ((x, dom), env) => E.pushERel env x dom) env args | 2037 val env' = foldl (fn ((x, dom), env) => E.pushERel env x dom) env args |
1993 space, | 2048 space, |
1994 p_rel env' (nargs - i - 1)]) args), | 2049 p_rel env' (nargs - i - 1)]) args), |
1995 string ")", | 2050 string ")", |
1996 space, | 2051 space, |
1997 string "{", | 2052 string "{", |
2053 if isRec then | |
2054 box [string "restart:", | |
2055 newline] | |
2056 else | |
2057 box [], | |
1998 newline, | 2058 newline, |
1999 if isRec andalso Settings.getDeadlines () then | 2059 if isRec andalso Settings.getDeadlines () then |
2000 box [string "uw_check_deadline(ctx);", | 2060 box [string "uw_check_deadline(ctx);", |
2001 newline] | 2061 newline] |
2002 else | 2062 else |
2125 space, | 2185 space, |
2126 p_list_sep (box [string ",", space]) | 2186 p_list_sep (box [string ",", space]) |
2127 (fn (_, dom) => p_typ env dom) args, | 2187 (fn (_, dom) => p_typ env dom) args, |
2128 string ");"]) vis, | 2188 string ");"]) vis, |
2129 newline, | 2189 newline, |
2130 p_list_sep newline (p_fun true env) vis, | 2190 p_list_sep newline (fn vi as (_, n, _, _, _) => |
2191 (self := SOME n; | |
2192 p_fun true env vi | |
2193 before self := NONE)) vis, | |
2131 newline] | 2194 newline] |
2132 end | 2195 end |
2133 | DTable (x, _, pk, csts) => box [string "/* SQL table ", | 2196 | DTable (x, _, pk, csts) => box [string "/* SQL table ", |
2134 string x, | 2197 string x, |
2135 space, | 2198 space, |
2247 fun p_file env (ds, ps) = | 2310 fun p_file env (ds, ps) = |
2248 let | 2311 let |
2249 val () = (clearUrlHandlers (); | 2312 val () = (clearUrlHandlers (); |
2250 unurlifies := IS.empty; | 2313 unurlifies := IS.empty; |
2251 urlifies := IS.empty; | 2314 urlifies := IS.empty; |
2252 urlifiesL := IS.empty) | 2315 urlifiesL := IS.empty; |
2316 self := NONE) | |
2253 | 2317 |
2254 val (pds, env) = ListUtil.foldlMap (fn (d, env) => | 2318 val (pds, env) = ListUtil.foldlMap (fn (d, env) => |
2255 let | 2319 let |
2256 val d' = p_decl env d | 2320 val d' = p_decl env d |
2257 in | 2321 in |