Changeset 144 for trunk/orca/ovalue.c
- Timestamp:
- 05/11/06 14:23:03 (3 years ago)
- Files:
-
- 1 modified
-
trunk/orca/ovalue.c (modified) (50 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/orca/ovalue.c
r142 r144 133 133 134 134 135 static void orNop()135 OR_NATIVE( orNop ) 136 136 { 137 137 //cprint( "KR nop %p %d\n", orEnv->dataStack.buf, orEnv->dataStack.used ); … … 319 319 void orInitEnv( OEnv* env, int dataStackSize, int callStackSize ) 320 320 { 321 OValue* res; 322 321 323 #ifdef DEBUG 322 324 _validateEnv(); … … 399 401 OBlock* blk; 400 402 OBlock* typeBlk; 401 OValue* res;402 403 OValue* wval; 403 404 OContext ctx; … … 411 412 orAppendBlock( typeBlk, 0 ); 412 413 413 res = or RESULT;414 res = orEnv->dataStack.values; 414 415 orSetTF( res, OT_BLOCK ); 415 416 orSetSeries( res, orBlockN(blk), 0 ); … … 431 432 { 432 433 cprint( "** Boot Error: " ); 433 orPrintNative( orRESULT);434 orPrintNative( res ); 434 435 } 435 436 … … 450 451 { 451 452 cprint( "** Boot Error: " ); 452 orPrintNative( orRESULT);453 orPrintNative( res ); 453 454 } 454 455 … … 685 686 #endif 686 687 case OT_LOGIC: 687 orResult( OT_LOGIC, orInt(from) ? 1 : 0 ); 688 orSetTF( res, OT_LOGIC ); 689 orInt(res) = orInt(from) ? 1 : 0; 688 690 return 1; 689 691 … … 740 742 (it[1].type == OT_INTEGER) ) 741 743 { 742 OValue* res = orRESULT;743 744 orSetTF( res, OT_PAIR ); 744 745 res->pair[0] = it[0].integer; … … 901 902 // Return curried function to pick up body argument. 902 903 // Too bad we have no way of executing this native. 903 OValue* res = orRESULT; 904 res->type = OT_NATIVE; 905 res->flags = 0; 906 res->argc = 1; 907 res->refc = 0; 908 res->native.addr = orFuncNative; 909 res->native.specBlk = 0; 904 a1->type = OT_NATIVE; 905 a1->flags = 0; 906 a1->argc = 1; 907 a1->refc = 0; 908 a1->native.addr = orFuncNative; 909 a1->native.specBlk = 0; 910 910 } 911 911 return; … … 915 915 case OT_VEC2: 916 916 case OT_VEC3: 917 { 918 OValue* res = orRESULT; 919 orSetTF( res, orInt(a1) ); 920 res->vec3.x = 0.0f; 921 res->vec3.y = 0.0f; 922 res->vec3.z = 0.0f; 917 orSetTF( a1, orInt(a1) ); 918 a1->vec3.x = 0.0f; 919 a1->vec3.y = 0.0f; 920 a1->vec3.z = 0.0f; 923 921 if( a2->type == OT_BLOCK ) 924 orLoadVectorBlock( &res->vec3.x, 3, a2 ); 925 } 922 orLoadVectorBlock( &a1->vec3.x, 3, a2 ); 926 923 return; 927 924 … … 1239 1236 1240 1237 1241 /* Public because ofOrca-GL */1238 /* Public for Orca-GL */ 1242 1239 OR_NATIVE_PUB( orLoadNative ) 1243 1240 { … … 1261 1258 1262 1259 orTermCStr( str ); 1263 1264 1260 file = orStrChars( str, a1 ); 1265 1261 … … 1295 1291 { 1296 1292 orResultBLOCK( blk - orBLOCKS ); 1297 orRESULT->flags |= OR_FLAG_HEADER;1293 a1->flags |= OR_FLAG_HEADER; 1298 1294 } 1299 1295 } … … 1377 1373 #define REF_DO_ARG a1+2 1378 1374 1375 /* 1376 do: native [value /args arg] 1377 */ 1379 1378 OR_NATIVE_PUB( orDoNative ) 1380 1379 { … … 1382 1381 { 1383 1382 orEvalBlock( orBLOCK( a1 ), a1->series.it ); 1383 orCopyV(a1, a1[3]); 1384 1384 } 1385 1385 else if( orIs(a1, OT_FILE) ) … … 1411 1411 orRefPop( 1 ); 1412 1412 orEvalBlock( orBlockPtr( blkN ), 2 ); 1413 orCopyV(a1, a1[3]); 1413 1414 _popScript(); 1414 1415 } … … 1424 1425 return; 1425 1426 orEvalBlock( orBLOCK( a1 ), 0 ); 1427 orCopyV(a1, a1[3]); 1426 1428 } 1427 1429 else if( orIs(a1, OT_WORD) ) … … 1525 1527 { 1526 1528 int logic; 1527 if( (a1->type == OT_NONE) || 1528 ((a1->type == OT_LOGIC) && (orInt(a1) == OR_FALSE)) ) 1529 if( orIfFalse(a1) ) 1529 1530 logic = OR_TRUE; 1530 1531 else … … 1535 1536 1536 1537 1538 /* 1539 if: native [cond body] 1540 */ 1537 1541 OR_NATIVE( orIfNative ) 1538 1542 { … … 1541 1545 OValue* a2 = a1 + 1; 1542 1546 orEvalBlock( orBLOCK( a2 ), a2->series.it ); 1547 orCopyV( a1, a1[2] ); 1543 1548 return; 1544 1549 } … … 1553 1558 OValue* a2 = a1 + 1; 1554 1559 orEvalBlock( orBLOCK( a2 ), a2->series.it ); 1560 orCopyV( a1, a1[2] ); 1555 1561 return; 1556 1562 } … … 1562 1568 { 1563 1569 OValue* blkArg = a1 + 2; 1564 if( a1->type != OT_NONE ) 1565 { 1566 if( (a1->type != OT_LOGIC) || (orInt(a1) != 0) ) 1567 --blkArg; 1568 } 1570 if( orIfTrue(a1) ) 1571 --blkArg; 1569 1572 orEvalBlock( orBLOCK( blkArg ), blkArg->series.it ); 1570 } 1571 1572 1573 orCopyV( a1, a1[3] ); 1574 } 1575 1576 1577 /* 1578 loop: native [count block] 1579 */ 1573 1580 OR_NATIVE( orLoopNative ) 1574 1581 { … … 1577 1584 int n = orInt(a1); 1578 1585 1579 ++a1; 1580 body = a1->index; 1581 bi = a1->series.it; 1586 body = (a1 + 1)->index; 1587 bi = (a1 + 1)->series.it; 1588 1589 orStackDrop(2); 1582 1590 1583 1591 while( n > 0 ) … … 1588 1596 break; 1589 1597 } 1598 1599 orStackGrow(2); 1590 1600 } 1591 1601 … … 1659 1669 1660 1670 1671 /* 1672 until: native [cond] 1673 */ 1661 1674 OR_NATIVE( orUntilNative ) 1662 1675 { 1663 OValue* res ;1676 OValue* res = a1 + 1; 1664 1677 OIndex cond = a1->index; 1665 1678 OIndex ci = a1->series.it; … … 1674 1687 break; 1675 1688 } 1676 res = orRESULT; 1677 if( res->type != OT_NONE ) 1678 { 1679 if( (res->type != OT_LOGIC) || (orInt(res) != 0) ) 1680 break; 1681 } 1682 } 1683 } 1684 1685 1689 if( orIfTrue(res) ) 1690 { 1691 orCopyV(a1, *res); 1692 break; 1693 } 1694 } 1695 } 1696 1697 1698 /* 1699 while: native [cond body] 1700 */ 1686 1701 OR_NATIVE( orWhileNative ) 1687 1702 { … … 1693 1708 OIndex bi = (a1 + 1)->series.it; 1694 1709 1695 orRefAvailErr( 2 ) 1696 orRefPush( OT_BLOCK, cond ); 1697 orRefPush( OT_BLOCK, body ); 1710 res = orTOS; 1698 1711 1699 1712 loop: … … 1703 1716 goto exit; 1704 1717 1705 res = orRESULT; 1706 if( res->type != OT_NONE ) 1707 { 1708 if( (res->type != OT_LOGIC) || (orInt(res) != 0) ) 1709 { 1710 if( onstack ) 1711 { 1712 onstack = 0; 1713 --orEnv->dataStack.used; 1714 } 1715 1716 orEvalBlock( orBLOCKS + body, bi ); 1717 if( orErrorThrown ) 1718 { 1719 if( orErrorIsType(OR_ERROR_BREAK) ) 1720 { 1721 orErrorClear; 1722 res = orRESULT; 1723 orSetTF( res, OT_UNSET ); 1724 } 1725 goto pop; 1726 } 1727 1728 ++orEnv->dataStack.used; 1729 onstack = 1; 1730 goto loop; 1731 } 1718 res = orTOS; 1719 if( orIfTrue(res) ) 1720 { 1721 if( onstack ) 1722 { 1723 onstack = 0; 1724 --orEnv->dataStack.used; 1725 } 1726 1727 orEvalBlock( orBLOCKS + body, bi ); 1728 if( orErrorThrown ) 1729 { 1730 if( orErrorIsType(OR_ERROR_BREAK) ) 1731 { 1732 orErrorClear; 1733 orSetTF( a1, OT_UNSET ); 1734 } 1735 orCopyV( a1, a1[2] ); 1736 return; 1737 } 1738 1739 ++orEnv->dataStack.used; 1740 onstack = 1; 1741 goto loop; 1732 1742 } 1733 1743 … … 1735 1745 1736 1746 if( onstack ) 1747 { 1737 1748 --orEnv->dataStack.used; 1738 1739 pop: 1740 1741 orRefPop( 2 ); 1749 orCopyV( a1, a1[2] ); 1750 } 1742 1751 } 1743 1752 … … 1774 1783 1775 1784 1776 void orQuitNative() 1777 { 1778 OValue* res = orRESULT; 1779 1780 orSetError( res, OR_ERROR_QUIT ); 1781 1782 res->error.msg = 0; 1783 res->error.block = 0; 1784 res->error.nearVal = 0; 1785 } 1786 1787 1788 void orHaltNative() 1789 { 1790 OValue* res = orRESULT; 1791 1792 orSetError( res, OR_ERROR_HALT ); 1793 1794 res->error.msg = 0; 1795 res->error.block = 0; 1796 res->error.nearVal = 0; 1785 OR_NATIVE( orQuitNative ) 1786 { 1787 orSetError( a1, OR_ERROR_QUIT ); 1788 1789 a1->error.msg = 0; 1790 a1->error.block = 0; 1791 a1->error.nearVal = 0; 1792 } 1793 1794 1795 OR_NATIVE( orHaltNative ) 1796 { 1797 orSetError( a1, OR_ERROR_HALT ); 1798 1799 a1->error.msg = 0; 1800 a1->error.block = 0; 1801 a1->error.nearVal = 0; 1797 1802 } 1798 1803 … … 1825 1830 // (must set result index before type). 1826 1831 1827 OValue* res = orRESULT;1828 1829 1832 if( orRefineSet(REF_TYPEQ_WORD) ) 1830 1833 { 1831 1834 // NOTE: This assumes word index/atom are the same as type. 1832 res->word.context = 0;1833 res->word.index = a1->type;1834 res->word.atom = a1->type;1835 orSetTF( res, OT_WORD );1835 a1->word.context = 0; 1836 a1->word.index = a1->type; 1837 a1->word.atom = a1->type; 1838 orSetTF( a1, OT_WORD ); 1836 1839 } 1837 1840 else 1838 1841 { 1839 res->index = a1->type;1840 orSetTF( res, OT_DATATYPE );1842 a1->index = a1->type; 1843 orSetTF( a1, OT_DATATYPE ); 1841 1844 } 1842 1845 } … … 1844 1847 1845 1848 /* 1846 try: native [ block [block!]]1849 try: native [block [block!]] 1847 1850 */ 1848 1851 OR_NATIVE( orTryNative ) … … 1851 1854 if( orErrorThrown ) 1852 1855 { 1853 OValue* res = orRESULT; 1854 if( res != orEnv->error ) 1855 *res = *orEnv->error; 1856 orCopyV(a1, *orEnv->error); 1856 1857 orErrorClear; 1858 } 1859 else 1860 { 1861 orCopyV(a1, a1[1]); 1857 1862 } 1858 1863 } … … 2324 2329 int ppos; 2325 2330 2326 wval = or RESULT;2331 wval = orTOS; 2327 2332 ppos = orEvalPath( orBLOCK(pc), pc->series.it, 0, wval ); 2328 2333 if( orErrorThrown ) … … 2568 2573 2569 2574 assert( data->used > 0 ); 2570 data->used -= funcv.argc + funcv.refc; 2575 { 2576 int total = funcv.argc + funcv.refc; 2577 int level = data->used; 2571 2578 2572 2579 // NOTE: Natives may need to orHold() any complex argument values since 2573 2580 // the stack no longer references them here. 2574 2581 2575 funcv.native.addr( DATA_TOP ); 2582 funcv.native.addr( DATA_TOP - total ); 2583 assert( level == data->used ); 2584 data->used -= total; 2585 } 2576 2586 goto sFinishNative; 2577 2587 … … 2984 2994 orRefPush( OT_BLOCK, nblkN ); 2985 2995 2986 or RESULT->type = OT_UNSET;2996 orTOS->type = OT_UNSET; 2987 2997 while( vi < used ) 2988 2998 { … … 2998 3008 rblk = orBlockPtr( nblkN ); 2999 3009 OA_EXPAND1( OValue, rblk, val ); 3000 orCopyV( val, *or RESULT);3010 orCopyV( val, *orTOS ); 3001 3011 } 3002 3012 … … 3022 3032 break; 3023 3033 3024 res = or RESULT;3034 res = orTOS; 3025 3035 if( orIs(res, OT_BLOCK) && ! only ) 3026 3036 { … … 3069 3079 3070 3080 /* 3081 any: native [block] 3082 3071 3083 Result is the first value that is not false or none! 3072 3084 */ … … 3080 3092 int reti; 3081 3093 3082 or RESULT->type = OT_UNSET;3094 orTOS->type = OT_UNSET; 3083 3095 3084 3096 while( vi < used ) … … 3092 3104 vi = reti; 3093 3105 3094 res = orRESULT; 3095 if( res->type != OT_NONE ) 3096 { 3097 if( (res->type != OT_LOGIC) || (orLogic(res) != 0) ) 3098 { 3099 return; 3100 } 3106 res = orTOS; 3107 if( orIfTrue(res) ) 3108 { 3109 orCopyV(a1, *res); 3110 return; 3101 3111 } 3102 3112 } … … 3106 3116 3107 3117 3118 /* 3119 all: native [block] 3120 */ 3108 3121 OR_NATIVE( orAllNative ) 3109 3122 { … … 3115 3128 int reti; 3116 3129 3117 or RESULT->type = OT_UNSET;3130 orTOS->type = OT_UNSET; 3118 3131 3119 3132 while( vi < used ) … … 3127 3140 vi = reti; 3128 3141 3129 res = or RESULT;3130 if( orI s(res, OT_NONE) )3142 res = orTOS; 3143 if( orIfFalse(res) ) 3131 3144 goto fail; 3132 if( orIs(res, OT_LOGIC) && (orLogic(res) == 0) )3133 goto fail; 3134 }3145 } 3146 3147 orCopyV(a1, a1[1]); 3135 3148 return; 3136 3149 … … 3158 3171 orRefPush( OT_BLOCK, blkN ); 3159 3172 3160 or RESULT->type = OT_UNSET;3173 orTOS->type = OT_UNSET; 3161 3174 3162 3175 while( vi < used ) … … 3334 3347 msg->used = cp - msg->charArray; 3335 3348 3336 res = or RESULT;3349 res = orTOS; 3337 3350 3338 3351 orSetError( res, type ); … … 4198 4211 OR_NATIVE_PUB( orNativeNative ) 4199 4212 { 4200 if( a1->type == OT_BLOCK)4213 if( orIs(a1, OT_BLOCK) ) 4201 4214 { 4202 4215 OBlock* blk; … … 4280 4293 #endif 4281 4294 4282 val = orRESULT;4295 val = a1; 4283 4296 val->type = OT_NATIVE; 4284 4297 val->flags = 0; … … 4297 4310 OR_NATIVE( orDoesNative ) 4298 4311 { 4299 if( a1->type == OT_BLOCK)4312 if( orIs(a1, OT_BLOCK) ) 4300 4313 { 4301 4314 OIndex bodyN; 4302 4303 4315 bodyN = a1->index; 4304 4316 4305 { 4306 OValue* res = orRESULT; 4307 res->type = OT_FUNCTION; 4308 res->flags = 0; 4309 res->argc = 0; 4310 res->refc = 0; 4311 res->func.bodyBlk = bodyN; 4312 res->func.specBlk = 0; 4313 res->func.context = 0; 4314 } 4317 a1->type = OT_FUNCTION; 4318 a1->flags = 0; 4319 a1->argc = 0; 4320 a1->refc = 0; 4321 a1->func.bodyBlk = bodyN; 4322 a1->func.specBlk = 0; 4323 a1->func.context = 0; 4315 4324 return; 4316 4325 } … … 4463 4472 int specIndex = a1->index; 4464 4473 4465 OValue* res = orRESULT; 4466 4467 res->type = OT_FUNCTION; 4468 res->flags = flags; 4469 res->argc = argc; 4470 res->refc = refc; 4471 res->func.bodyBlk = bodyN; 4472 res->func.specBlk = specIndex; 4473 res->func.context = ctx.vblkN; 4474 a1->type = OT_FUNCTION; 4475 a1->flags = flags; 4476 a1->argc = argc; 4477 a1->refc = refc; 4478 a1->func.bodyBlk = bodyN; 4479 a1->func.specBlk = specIndex; 4480 a1->func.context = ctx.vblkN; 4474 4481 4475 4482 #if 0
