Mercurial > repos > rhope
comparison cbackend_c.rhope @ 140:c14698c512f1
Untested addition of Pause/Resume
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Sat, 20 Nov 2010 20:03:25 +0000 |
parents | a68e6828d896 |
children | f2cb85c53ced |
comparison
equal
deleted
inserted
replaced
139:a68e6828d896 | 140:c14698c512f1 |
---|---|
1507 | 1507 |
1508 Dispatch@C Program[program,all methods:out] | 1508 Dispatch@C Program[program,all methods:out] |
1509 { | 1509 { |
1510 out <- [[[[["typedef enum {\n" | 1510 out <- [[[[["typedef enum {\n" |
1511 ]Append[Fold[_Dispatch Enum[?], | 1511 ]Append[Fold[_Dispatch Enum[?], |
1512 [Fold[_Dispatch Enum Methods[[program]Escape Pattern >>,?], "", all methods]]Append["\tFUNC_Build,\n\tFUNC_BlueprintSP_Of,\n\tFUNC_ID,\n\tFUNC_BlueprintSP_FromSP_ID,\n"], | 1512 [Fold[_Dispatch Enum Methods[[program]Escape Pattern >>,?], "", all methods]]Append["\tFUNC_Build,\n\tFUNC_BlueprintSP_Of,\n\tFUNC_ID,\n\tFUNC_BlueprintSP_FromSP_ID,\n\tFUNC_Pause,\n\tRES_1_Pause,\n\tFUNC_Resume,\n\tFUNC_CallSP_Async,\n"], |
1513 [program]Functions >>]] | 1513 [program]Functions >>]] |
1514 ]Append["\tEND\n} funcids;\n\n"] | 1514 ]Append["\tEND,\n\tEND_THREAD\n} funcids;\n\n"] |
1515 ]Append["#define DispatchEntries \\\n"] | 1515 ]Append["#define DispatchEntries \\\n"] |
1516 ]Append[Fold[_Dispatch Switch[?], | 1516 ]Append[Fold[_Dispatch Switch[?], |
1517 [Fold[_Dispatch Switch Methods[[program]Escape Pattern >>,?], "", all methods]]Append["\tDispatchEntry(Build)\\\n\tDispatchEntry(BlueprintSP_Of)\\\n\tDispatchEntry(ID)\\\n\tDispatchEntry(BlueprintSP_FromSP_ID)\\\n"], | 1517 [Fold[_Dispatch Switch Methods[[program]Escape Pattern >>,?], "", all methods]]Append["\tDispatchEntry(Build)\\\n\tDispatchEntry(BlueprintSP_Of)\\\n\tDispatchEntry(ID)\\\n\tDispatchEntry(BlueprintSP_FromSP_ID)\\\n\tDispatchEntry(Pause)\\\n\tResumeEntry(1,Pause)\\\n\tDispatchEntry(Resume)\\\n\tDispatchEntry(CallSP_Async)\\\n"], |
1518 [program]Functions >>]] | 1518 [program]Functions >>]] |
1519 ]Append["\tEndEntry\n\n"] | 1519 ]Append["\tEndEntry\n\tEndThreadEntry\n\n"] |
1520 } | 1520 } |
1521 | 1521 |
1522 Not Native[func:out] | 1522 Not Native[func:out] |
1523 { | 1523 { |
1524 If[[[func]Convention >>] = ["rhope"]] | 1524 If[[[func]Convention >>] = ["rhope"]] |
1631 { | 1631 { |
1632 #ifdef ENABLE_PROFILING | 1632 #ifdef ENABLE_PROFILING |
1633 struct timeval time; | 1633 struct timeval time; |
1634 #endif | 1634 #endif |
1635 uint16_t resume,idx, vcparam_offset, last_vcparam; | 1635 uint16_t resume,idx, vcparam_offset, last_vcparam; |
1636 context * ct; | 1636 context *ct,*temp_ct; |
1637 void *tmp; | 1637 void *tmp; |
1638 calldata * cdata, *temp_cdata, *my_cdata; | 1638 calldata * cdata, *temp_cdata, *my_cdata; |
1639 DispatchVar | 1639 DispatchVar |
1640 FuncDef(Build) | 1640 FuncDef(Build) |
1641 FuncDef(BlueprintSP_Of) | 1641 FuncDef(BlueprintSP_Of) |
1642 FuncDef(ID) | 1642 FuncDef(ID) |
1643 FuncDef(BlueprintSP_FromSP_ID)\n"] | 1643 FuncDef(BlueprintSP_FromSP_ID) |
1644 FuncDef(Pause) | |
1645 FuncDef(Resume) | |
1646 FuncDef(CallSP_Async)\n"] | |
1644 ]Append[Fold[Local Pointers[?], "", [program]Functions >>]] | 1647 ]Append[Fold[Local Pointers[?], "", [program]Functions >>]] |
1645 ]Append[" | 1648 ]Append[" |
1646 ct = new_context(); | 1649 ct = new_context(); |
1647 cdata = alloc_cdata(ct, NULL, callspace); | 1650 cdata = alloc_cdata(ct, NULL, callspace); |
1648 cdata->num_params = numparams; | 1651 cdata->num_params = numparams; |
1700 ((t_Blueprint *)cdata->params[0])->bp = registered_types[lv_BlueprintSP_FromSP_ID->type]; | 1703 ((t_Blueprint *)cdata->params[0])->bp = registered_types[lv_BlueprintSP_FromSP_ID->type]; |
1701 Ret(1, NULL) | 1704 Ret(1, NULL) |
1702 } | 1705 } |
1703 | 1706 |
1704 EndFunc(BlueprintSP_FromSP_ID) | 1707 EndFunc(BlueprintSP_FromSP_ID) |
1708 DISPATCH | |
1709 | |
1710 FuncNoLocals(Pause, NumParams 1) | |
1711 Param(0, TYPE_WORKER) | |
1712 | |
1713 ct->resume_cdata = my_cdata; | |
1714 ct->resumeable = 1; | |
1715 temp_ct = ct; | |
1716 ct = new_context(); | |
1717 VCPrepCall(my_cdata->params[0], 1) | |
1718 VCSetParam(my_cdata->params[0], 0, make_Context(temp_ct)) | |
1719 ValCall(my_cdata->params[0], 1, 1, Pause) | |
1720 release_ref(my_cdata->params[0]); | |
1721 DISPATCH | |
1722 ValCallPostlude(1, Pause) | |
1723 for(idx = 0; idx < cdata->num_params; ++idx) | |
1724 { | |
1725 release_ref(cdata->params[idx]); | |
1726 } | |
1727 free_context(ct); | |
1728 ct = get_cqueue(); | |
1729 if (!ct) goto NOTHING_TO_DO; | |
1730 cdata = ct->resume_cdata; | |
1731 ct->resume_data = NULL; | |
1732 if(ct->start_func >= 0) | |
1733 { | |
1734 func = ct->start_func; | |
1735 ct->start_func = -1; | |
1736 DISPATCH | |
1737 } | |
1738 EndFuncNoLocals(Pause) | |
1739 DISPATCH | |
1740 | |
1741 FuncNoLocals(Resume, NumParams 2) | |
1742 Param(0, TYPE_CONTEXT) | |
1743 | |
1744 temp_ct = ((t_Context *)my_cdata->params[0])->ct; | |
1745 release_ref(my_cdata->params[0]); | |
1746 if(temp_ct->resumeable && temp_ct->resume_cdata) | |
1747 { | |
1748 temp_ct->resumeable = 0; | |
1749 temp_ct->resume_cdata->params[0] = add_ref(my_cdata-params[1]); | |
1750 my_cdata->params[0] = my_cdata->params[1]; | |
1751 my_cdata->params[1] = NULL; | |
1752 if(!put_cqueue(temp_ct)) | |
1753 { | |
1754 ct->resume_cdata = my_cdata; | |
1755 temp_ct->runafter = ct; | |
1756 ct = temp_ct; | |
1757 cdata = ct->resume_cdata; | |
1758 ct->resume_cdata = NULL; | |
1759 } | |
1760 } else { | |
1761 my_cdata->params[0] = NULL; | |
1762 } | |
1763 EndFuncNoLocals(Resume) | |
1764 DISPATCH | |
1765 | |
1766 FuncNoLocals(CallSP_Async, NumParams 1) | |
1767 Param(0, TYPE_WORKER) | |
1768 | |
1769 temp_ct = new_context(); | |
1770 cdata = alloc_cdata(temp_ct, NULL, ((t_Worker *)my_cdata->params[0])->payload.Size); | |
1771 cdata->func = END_THREAD; | |
1772 for(idx = 0; idx < ((t_Worker *)my_cdata->params[0])->payload.Size; ++idx) | |
1773 { | |
1774 cdata->params[idx] = add_ref(((object **)(((t_Worker *)my_cdata->params[0])+1))[idx]); | |
1775 } | |
1776 temp_ct->start_func = ((t_Worker *)my_cdata->params[0])->payload.Index; | |
1777 temp_ct->resume_cdata = cdata; | |
1778 if(put_cqueue(temp_ct)) | |
1779 { | |
1780 cdata = my_cdata; | |
1781 } else { | |
1782 ct->resume_cdata = my_cdata; | |
1783 temp_ct->runafter = ct; | |
1784 ct = temp_ct; | |
1785 ct->resume_cdata = NULL; | |
1786 func = ct->start_func; | |
1787 ct->start_func = -1; | |
1788 DISPATCH | |
1789 } | |
1790 EndFuncNoLocals(CallSP_Async) | |
1705 DISPATCH\n"] | 1791 DISPATCH\n"] |
1706 ]Append[Fold[_Text C Program[?, ?, [program]Type Registry >>], "", Filter[[program]Functions >>, Native[?]]]] | 1792 ]Append[Fold[_Text C Program[?, ?, [program]Type Registry >>], "", Filter[[program]Functions >>, Native[?]]]] |
1707 ]Append[" | 1793 ]Append[" |
1708 DO_END: | 1794 DO_END: |
1709 for(idx = 0; idx < cdata->num_params; ++idx) | 1795 for(idx = 0; idx < cdata->num_params; ++idx) |
1710 params[idx] = cdata->params[idx]; | 1796 params[idx] = cdata->params[idx]; |
1711 free_context(ct); | 1797 free_context(ct); |
1712 return cdata->num_params; | 1798 return cdata->num_params; |
1713 | 1799 |
1800 DO_END_THREAD: | |
1801 for(idx = 0; idx < cdata->num_params; ++idx) | |
1802 { release_ref(cdata->params[idx]); } | |
1803 if(ct->runafter) | |
1804 { | |
1805 temp_ct = ct; | |
1806 ct = ct->runafter; | |
1807 free_context(temp_ct); | |
1808 cdata = ct->resume_cdata; | |
1809 func = cdata->func; | |
1810 DISPATCH | |
1811 } | |
1812 free_context(ct); | |
1813 if(ct = get_cqueue()) | |
1814 { | |
1815 cdata = ct->resume_cdata; | |
1816 if(ct->start_func >= 0) | |
1817 func = ct->start_func; | |
1818 else | |
1819 func = cdata->func; | |
1820 DISPATCH | |
1821 } | |
1822 NOTHING_TO_DO: | |
1823 return 0; | |
1824 | |
1714 _exception: | 1825 _exception: |
1715 puts(\"Exception! Trace follows:\"); | 1826 puts(\"Exception! Trace follows:\"); |
1716 while(cdata && cdata->func != END) | 1827 while(cdata && cdata->func < END) |
1717 { | 1828 { |
1718 printf(\"%d\\n\", cdata->func); | 1829 printf(\"%d\\n\", cdata->func); |
1719 cdata = cdata->lastframe; | 1830 cdata = cdata->lastframe; |
1720 } | 1831 } |
1721 return -1; | 1832 return -1; |