diff options
author | Benoit Germain <bnt.germain@gmail.com> | 2013-01-09 15:53:10 +0100 |
---|---|---|
committer | Benoit Germain <bnt.germain@gmail.com> | 2013-01-09 15:53:10 +0100 |
commit | b2fd7d91a8f323567465f881e2b7f15c515a64f9 (patch) | |
tree | 8d450665e965e41f8c233e3c2356fec7c1550247 /src/tools.c | |
parent | 54938272316c7bbb5df7af4443cf95716bd20a63 (diff) | |
download | lanes-b2fd7d91a8f323567465f881e2b7f15c515a64f9.tar.gz lanes-b2fd7d91a8f323567465f881e2b7f15c515a64f9.tar.bz2 lanes-b2fd7d91a8f323567465f881e2b7f15c515a64f9.zip |
Added some upvalues inter-copy debug code
Diffstat (limited to 'src/tools.c')
-rw-r--r-- | src/tools.c | 49 |
1 files changed, 28 insertions, 21 deletions
diff --git a/src/tools.c b/src/tools.c index e89b340..0206897 100644 --- a/src/tools.c +++ b/src/tools.c | |||
@@ -532,7 +532,7 @@ void set_deep_lookup( lua_State *L ) { | |||
532 | lua_pushlightuserdata( L, DEEP_LOOKUP_KEY ); | 532 | lua_pushlightuserdata( L, DEEP_LOOKUP_KEY ); |
533 | lua_pushvalue(L,-2); | 533 | lua_pushvalue(L,-2); |
534 | // | 534 | // |
535 | // [-3]: {} (2nd ref) | 535 | // [-3]: {}Â (2nd ref) |
536 | // [-2]: DEEP_LOOKUP_KEY | 536 | // [-2]: DEEP_LOOKUP_KEY |
537 | // [-1]: {} | 537 | // [-1]: {} |
538 | 538 | ||
@@ -939,7 +939,7 @@ luaG_IdFunction luaG_copydeep( lua_State *L, lua_State *L2, int index ) | |||
939 | 939 | ||
940 | /* | 940 | /* |
941 | * 'reg[ REG_MT_KNOWN ]'= { | 941 | * 'reg[ REG_MT_KNOWN ]'= { |
942 | * [ table ]= id_uint, | 942 | * [Â table ]= id_uint, |
943 | * ... | 943 | * ... |
944 | * [ id_uint ]= table, | 944 | * [ id_uint ]= table, |
945 | * ... | 945 | * ... |
@@ -1354,6 +1354,11 @@ static void lookup_native_func( lua_State* L2, lua_State* L, uint_t i) | |||
1354 | } | 1354 | } |
1355 | 1355 | ||
1356 | #define LOG_FUNC_INFO 0 | 1356 | #define LOG_FUNC_INFO 0 |
1357 | #if LOG_FUNC_INFO | ||
1358 | #define LOG_FUNC_INFO_CODE(_code) _code | ||
1359 | #else // LOG_FUNC_INFO | ||
1360 | #define LOG_FUNC_INFO_CODE(_code) | ||
1361 | #endif // LOG_FUNC_INFO | ||
1357 | 1362 | ||
1358 | /* | 1363 | /* |
1359 | * Copy a function over, which has not been found in the cache. | 1364 | * Copy a function over, which has not been found in the cache. |
@@ -1374,7 +1379,7 @@ static void inter_copy_func( lua_State *L2, uint_t L2_cache_i, lua_State *L, uin | |||
1374 | 1379 | ||
1375 | if( funcSubType == FST_Bytecode) | 1380 | if( funcSubType == FST_Bytecode) |
1376 | { | 1381 | { |
1377 | unsigned n; | 1382 | int n; |
1378 | luaL_Buffer b; | 1383 | luaL_Buffer b; |
1379 | // 'lua_dump()' needs the function at top of stack | 1384 | // 'lua_dump()' needs the function at top of stack |
1380 | // if already on top of the stack, no need to push again | 1385 | // if already on top of the stack, no need to push again |
@@ -1443,49 +1448,51 @@ static void inter_copy_func( lua_State *L2, uint_t L2_cache_i, lua_State *L, uin | |||
1443 | /* push over any upvalues; references to this function will come from | 1448 | /* push over any upvalues; references to this function will come from |
1444 | * cache so we don't end up in eternal loop. | 1449 | * cache so we don't end up in eternal loop. |
1445 | */ | 1450 | */ |
1446 | for( n=0; lua_getupvalue( L, i, 1+n ) != NULL; n++ ) | ||
1447 | { | 1451 | { |
1448 | if ((!cfunc) && lua_equal(L,i,-1)) | 1452 | LOG_FUNC_INFO_CODE( char const* upname); |
1453 | for( n = 0; (LOG_FUNC_INFO_CODE( upname =) lua_getupvalue( L, i, 1 + n)) != NULL; ++ n) | ||
1449 | { | 1454 | { |
1450 | /* Lua closure that has a (recursive) upvalue to itself | 1455 | LOG_FUNC_INFO_CODE( fprintf( stderr, "UPNAME: %s\n", upname)); |
1451 | */ | 1456 | if( (!cfunc) && lua_equal( L, i, -1)) |
1452 | lua_pushvalue( L2, -((int)n)-1 ); | 1457 | { |
1458 | /* Lua closure that has a (recursive) upvalue to itself | ||
1459 | */ | ||
1460 | lua_pushvalue( L2, -n - 1); | ||
1461 | } | ||
1462 | else | ||
1463 | { | ||
1464 | if( !inter_copy_one_( L2, L2_cache_i, L, lua_gettop(L), VT_NORMAL)) | ||
1465 | luaL_error( L, "Cannot copy upvalue type '%s'", luaL_typename( L, -1)); | ||
1466 | } | ||
1467 | lua_pop( L, 1); | ||
1453 | } | 1468 | } |
1454 | else | ||
1455 | { | ||
1456 | if( !inter_copy_one_( L2, L2_cache_i, L, lua_gettop(L), VT_NORMAL)) | ||
1457 | luaL_error( L, "Cannot copy upvalue type '%s'", luaL_typename( L, -1)); | ||
1458 | } | ||
1459 | lua_pop( L, 1); | ||
1460 | } | 1469 | } |
1461 | // L2: function + 'n' upvalues (>=0) | 1470 | // L2: function + 'n' upvalues (>=0) |
1462 | 1471 | ||
1463 | STACK_MID(L,0) | 1472 | STACK_MID( L, 0) |
1464 | 1473 | ||
1465 | // Set upvalues (originally set to 'nil' by 'lua_load') | 1474 | // Set upvalues (originally set to 'nil' by 'lua_load') |
1466 | { | 1475 | { |
1467 | int func_index = lua_gettop( L2) - n; | 1476 | int func_index = lua_gettop( L2) - n; |
1468 | for( ; n > 0; -- n) | 1477 | for( ; n > 0; -- n) |
1469 | { | 1478 | { |
1470 | char const *rc = lua_setupvalue( L2, func_index, n); | 1479 | char const* rc = lua_setupvalue( L2, func_index, n); |
1471 | // | 1480 | // |
1472 | // "assigns the value at the top of the stack to the upvalue and returns its name. | 1481 | // "assigns the value at the top of the stack to the upvalue and returns its name. |
1473 | // It also pops the value from the stack." | 1482 | // It also pops the value from the stack." |
1474 | 1483 | ||
1475 | ASSERT_L(rc); // not having enough slots? | 1484 | ASSERT_L( rc); // not having enough slots? |
1476 | } | 1485 | } |
1477 | } | 1486 | } |
1478 | } | 1487 | } |
1479 | } | 1488 | } |
1480 | else // C function OR LuaJIT fast function!!! | 1489 | else // C function OR LuaJIT fast function!!! |
1481 | { | 1490 | { |
1482 | #if LOG_FUNC_INFO | 1491 | LOG_FUNC_INFO_CODE( fprintf( stderr, "NAME: [C] function %p \n", cfunc)); |
1483 | fprintf( stderr, "NAME: [C] function %p \n", cfunc); | ||
1484 | #endif // LOG_FUNC_INFO | ||
1485 | // No need to transfer upvalues for C/JIT functions since they weren't actually copied, only looked up | 1492 | // No need to transfer upvalues for C/JIT functions since they weren't actually copied, only looked up |
1486 | lookup_native_func( L2, L, i); | 1493 | lookup_native_func( L2, L, i); |
1487 | } | 1494 | } |
1488 | STACK_END(L,0) | 1495 | STACK_END( L, 0) |
1489 | } | 1496 | } |
1490 | 1497 | ||
1491 | /* | 1498 | /* |