diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2003-12-09 14:56:11 -0200 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2003-12-09 14:56:11 -0200 |
| commit | df429f163ada6581d921e7f51b016f1abfeefddd (patch) | |
| tree | a1af3ce961377e6548074f706f65e2b34181918f /lapi.c | |
| parent | fe595a45c246faf2cf12084e7aac4b772f8f72da (diff) | |
| download | lua-df429f163ada6581d921e7f51b016f1abfeefddd.tar.gz lua-df429f163ada6581d921e7f51b016f1abfeefddd.tar.bz2 lua-df429f163ada6581d921e7f51b016f1abfeefddd.zip | |
First version of incremental GC
Diffstat (limited to 'lapi.c')
| -rw-r--r-- | lapi.c | 31 |
1 files changed, 19 insertions, 12 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lapi.c,v 1.249 2003/10/20 17:42:41 roberto Exp roberto $ | 2 | ** $Id: lapi.c,v 1.250 2003/12/01 18:22:56 roberto Exp roberto $ |
| 3 | ** Lua API | 3 | ** Lua API |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -193,7 +193,7 @@ LUA_API void lua_replace (lua_State *L, int idx) { | |||
| 193 | api_checknelems(L, 1); | 193 | api_checknelems(L, 1); |
| 194 | o = luaA_index(L, idx); | 194 | o = luaA_index(L, idx); |
| 195 | api_checkvalidindex(L, o); | 195 | api_checkvalidindex(L, o); |
| 196 | setobj(o, L->top - 1); /* write barrier */ | 196 | setobj(o, L->top - 1); /* write barrier???? */ |
| 197 | L->top--; | 197 | L->top--; |
| 198 | lua_unlock(L); | 198 | lua_unlock(L); |
| 199 | } | 199 | } |
| @@ -615,7 +615,8 @@ LUA_API void lua_rawset (lua_State *L, int idx) { | |||
| 615 | api_checknelems(L, 2); | 615 | api_checknelems(L, 2); |
| 616 | t = luaA_index(L, idx); | 616 | t = luaA_index(L, idx); |
| 617 | api_check(L, ttistable(t)); | 617 | api_check(L, ttistable(t)); |
| 618 | setobj2t(luaH_set(L, hvalue(t), L->top-2), L->top-1); /* write barrier */ | 618 | setobj2t(luaH_set(L, hvalue(t), L->top-2), L->top-1); |
| 619 | luaC_barrier(L, hvalue(t), L->top-1); | ||
| 619 | L->top -= 2; | 620 | L->top -= 2; |
| 620 | lua_unlock(L); | 621 | lua_unlock(L); |
| 621 | } | 622 | } |
| @@ -627,7 +628,8 @@ LUA_API void lua_rawseti (lua_State *L, int idx, int n) { | |||
| 627 | api_checknelems(L, 1); | 628 | api_checknelems(L, 1); |
| 628 | o = luaA_index(L, idx); | 629 | o = luaA_index(L, idx); |
| 629 | api_check(L, ttistable(o)); | 630 | api_check(L, ttistable(o)); |
| 630 | setobj2t(luaH_setnum(L, hvalue(o), n), L->top-1); /* write barrier */ | 631 | setobj2t(luaH_setnum(L, hvalue(o), n), L->top-1); |
| 632 | luaC_barrier(L, hvalue(o), L->top-1); | ||
| 631 | L->top--; | 633 | L->top--; |
| 632 | lua_unlock(L); | 634 | lua_unlock(L); |
| 633 | } | 635 | } |
| @@ -649,11 +651,15 @@ LUA_API int lua_setmetatable (lua_State *L, int objindex) { | |||
| 649 | } | 651 | } |
| 650 | switch (ttype(obj)) { | 652 | switch (ttype(obj)) { |
| 651 | case LUA_TTABLE: { | 653 | case LUA_TTABLE: { |
| 652 | hvalue(obj)->metatable = mt; /* write barrier */ | 654 | hvalue(obj)->metatable = mt; |
| 655 | if (mt) | ||
| 656 | luaC_objbarrier(L, hvalue(obj), mt); | ||
| 653 | break; | 657 | break; |
| 654 | } | 658 | } |
| 655 | case LUA_TUSERDATA: { | 659 | case LUA_TUSERDATA: { |
| 656 | uvalue(obj)->uv.metatable = mt; /* write barrier */ | 660 | uvalue(obj)->uv.metatable = mt; |
| 661 | if (mt) | ||
| 662 | luaC_objbarrier(L, uvalue(obj), mt); | ||
| 657 | break; | 663 | break; |
| 658 | } | 664 | } |
| 659 | default: { | 665 | default: { |
| @@ -907,10 +913,8 @@ LUA_API void *lua_newuserdata (lua_State *L, size_t size) { | |||
| 907 | 913 | ||
| 908 | 914 | ||
| 909 | 915 | ||
| 910 | static const char *aux_upvalue (lua_State *L, int funcindex, int n, | 916 | static const char *aux_upvalue (lua_State *L, StkId fi, int n, TObject **val) { |
| 911 | TObject **val) { | ||
| 912 | Closure *f; | 917 | Closure *f; |
| 913 | StkId fi = luaA_index(L, funcindex); | ||
| 914 | if (!ttisfunction(fi)) return NULL; | 918 | if (!ttisfunction(fi)) return NULL; |
| 915 | f = clvalue(fi); | 919 | f = clvalue(fi); |
| 916 | if (f->c.isC) { | 920 | if (f->c.isC) { |
| @@ -931,7 +935,7 @@ LUA_API const char *lua_getupvalue (lua_State *L, int funcindex, int n) { | |||
| 931 | const char *name; | 935 | const char *name; |
| 932 | TObject *val; | 936 | TObject *val; |
| 933 | lua_lock(L); | 937 | lua_lock(L); |
| 934 | name = aux_upvalue(L, funcindex, n, &val); | 938 | name = aux_upvalue(L, luaA_index(L, funcindex), n, &val); |
| 935 | if (name) { | 939 | if (name) { |
| 936 | setobj2s(L->top, val); | 940 | setobj2s(L->top, val); |
| 937 | api_incr_top(L); | 941 | api_incr_top(L); |
| @@ -944,12 +948,15 @@ LUA_API const char *lua_getupvalue (lua_State *L, int funcindex, int n) { | |||
| 944 | LUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n) { | 948 | LUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n) { |
| 945 | const char *name; | 949 | const char *name; |
| 946 | TObject *val; | 950 | TObject *val; |
| 951 | StkId fi; | ||
| 947 | lua_lock(L); | 952 | lua_lock(L); |
| 953 | fi = luaA_index(L, funcindex); | ||
| 948 | api_checknelems(L, 1); | 954 | api_checknelems(L, 1); |
| 949 | name = aux_upvalue(L, funcindex, n, &val); | 955 | name = aux_upvalue(L, fi, n, &val); |
| 950 | if (name) { | 956 | if (name) { |
| 951 | L->top--; | 957 | L->top--; |
| 952 | setobj(val, L->top); /* write barrier */ | 958 | setobj(val, L->top); |
| 959 | luaC_barrier(L, clvalue(fi), L->top); | ||
| 953 | } | 960 | } |
| 954 | lua_unlock(L); | 961 | lua_unlock(L); |
| 955 | return name; | 962 | return name; |
