Example #1
0
		public static void luaS_resize (lua_State L, int newsize) {
		  GCObject[] newhash;
		  stringtable tb;
		  int i;
		  if (G(L).gcstate == GCSsweepstring)
			return;  /* cannot resize during GC traverse */		  
		  newhash = new GCObject[newsize];
		  AddTotalBytes(L, newsize * GetUnmanagedSize(typeof(GCObjectRef)));
		  tb = G(L).strt;
		  for (i=0; i<newsize; i++) newhash[i] = null;

		  /* rehash */
		  for (i=0; i<tb.size; i++) {
			GCObject p = tb.hash[i];
			while (p != null) {  /* for each node in the list */
			  GCObject next = p.gch.next;  /* save next */
			  uint h = gco2ts(p).hash;
			  int h1 = (int)lmod(h, newsize);  /* new position */
			  lua_assert((int)(h%newsize) == lmod(h, newsize));
			  p.gch.next = newhash[h1];  /* chain it */
			  newhash[h1] = p;
			  p = next;
			}
		  }
		  //luaM_freearray(L, tb.hash);
		  if (tb.hash != null)
			  SubtractTotalBytes(L, tb.hash.Length * GetUnmanagedSize(typeof(GCObjectRef)));
		  tb.size = newsize;
		  tb.hash = newhash;
		}
Example #2
0
        //static void reallymarkobject (global_State *g, GCObject *o);


        /*
        ** {======================================================
        ** Generic functions
        ** =======================================================
        */

        private static void linktable(Table h, ref GCObject p)
        {
            h.gclist = p;
            p        = obj2gco(h);
        }
Example #3
0
File: lobject.cs Project: oathx/Six
		internal static void SetSValue(LuaState L, Lua.LuaTypeValue obj, GCObject x) {
			obj.value.gc = x;
			obj.tt = LUA_TSTRING;
			CheckLiveness(G(L), obj);
		}
Example #4
0
 public static void black2gray(GCObject x)
 {
     resetbit(ref x.gch.marked, BLACKBIT);
 }
Example #5
0
 public static void white2gray(GCObject x)
 {
     reset2bits(ref x.gch.marked, WHITE0BIT, WHITE1BIT);
 }
Example #6
0
 public static bool iswhite(GCObject x)
 {
     return test2bits(x.gch.marked, WHITE0BIT, WHITE1BIT);
 }
Example #7
0
 public static void gray2black(GCObject x)
 {
     l_setbit(ref x.gch.marked, BLACKBIT);
 }
Example #8
0
File: lgc.cs Project: NLua/KopiLua
 /*
 ** clear collected entries from weaktables
 */
 private static void ClearTable(GCObject l)
 {
     while (l != null) {
     Table h = gco2h(l);
     int i = h.sizearray;
     LuaAssert(TestBit(h.marked, VALUEWEAKBIT) ||
                TestBit(h.marked, KEYWEAKBIT));
     if (TestBit(h.marked, VALUEWEAKBIT)) {
       while (i--!= 0) {
         TValue o = h.array[i];
         if (IsCleared(o, false))  /* value was collected? */
           SetNilValue(o);  /* remove value */
       }
     }
     i = SizeNode(h);
     while (i-- != 0) {
       Node n = gnode(h, i);
       if (!TTIsNil(gval(n)) &&  /* non-empty entry? */
           (IsCleared(key2tval(n), true) || IsCleared(gval(n), false))) {
         SetNilValue(gval(n));  /* remove value ... */
         RemoveEntry(n);  /* remove entry from Table */
       }
     }
     l = h.gclist;
       }
 }
Example #9
0
 public static void gray2black(GCObject x)
 {
     l_setbit(ref x.marked, BLACKBIT);
 }
Example #10
0
 public static void changewhite(GCObject x)
 {
     x.marked ^= (byte)WHITEBITS;
 }
Example #11
0
 public static bool isdead(global_State g, GCObject v)
 {
     return(isdeadm(otherwhite(g), v.marked));
 }
Example #12
0
 public static bool tofinalize(GCObject x)
 {
     return(testbit(x.marked, FINALIZEDBIT));
 }
Example #13
0
 public static bool isgray(GCObject x)           /* neither white nor black */
 {
     return(!testbits(x.marked, WHITEBITS | bitmask(BLACKBIT)));
 }
Example #14
0
 public static bool isblack(GCObject x)
 {
     return(testbit(x.marked, BLACKBIT));
 }
Example #15
0
 public static bool iswhite(GCObject x)
 {
     return(testbits(x.marked, WHITEBITS));
 }
Example #16
0
File: lgc.cs Project: NLua/KopiLua
 public static void LuaCBarrierF(LuaState L, GCObject o, GCObject v)
 {
     GlobalState g = G(L);
       LuaAssert(IsBlack(o) && IsWhite(v) && !IsDead(g, v) && !IsDead(g, o));
       LuaAssert(g.gcstate != GCSfinalize && g.gcstate != GCSpause);
       LuaAssert(TType(o.gch) != LUA_TTABLE);
       /* must keep invariant? */
       if (g.gcstate == GCSpropagate)
     ReallyMarkObject(g, v);  /* restore invariant */
       else  /* don't mind */
     MakeWhite(g, o);  /* mark as white just to avoid other barriers */
 }
Example #17
0
File: lgc.cs Project: NLua/KopiLua
 public static void MakeWhite(GlobalState g, GCObject x)
 {
     x.gch.marked = (byte)(x.gch.marked & maskmarks | LuaCWhite(g));
 }
Example #18
0
 public static GCheader gch(GCObject o)
 {
     return(o.gch);
 }
Example #19
0
File: lgc.cs Project: NLua/KopiLua
 private static void ReallyMarkObject(GlobalState g, GCObject o)
 {
     LuaAssert(IsWhite(o) && !IsDead(g, o));
       White2Gray(o);
       switch (o.gch.tt) {
     case LUA_TSTRING: {
       return;
     }
     case LUA_TUSERDATA: {
       Table mt = gco2u(o).metatable;
       Gray2Black(o);  /* udata are never gray */
       if (mt != null) MarkObject(g, mt);
       MarkObject(g, gco2u(o).env);
       return;
     }
     case LUATUPVAL: {
       UpVal uv = gco2uv(o);
       MarkValue(g, uv.v);
       if (uv.v == uv.u.value)  /* closed? */
         Gray2Black(o);  /* open upvalues are never black */
       return;
     }
     case LUA_TFUNCTION: {
       gco2cl(o).c.gclist = g.gray;
       g.gray = o;
       break;
     }
     case LUA_TTABLE: {
       gco2h(o).gclist = g.gray;
       g.gray = o;
       break;
     }
     case LUA_TTHREAD: {
       gco2th(o).gclist = g.gray;
       g.gray = o;
       break;
     }
     case LUATPROTO: {
       gco2p(o).gclist = g.gray;
       g.gray = o;
       break;
     }
     default: LuaAssert(0); break;
       }
 }
Example #20
0
 public void set(GCObject value)
 {
     array_elements[array_index] = value;
 }
Example #21
0
 public static bool isdead(global_State g, GCObject v)
 {
     return (v.gch.marked & otherwhite(g) & WHITEBITS) != 0;
 }
Example #22
0
 public void set(GCObject value)
 {
     this.g.allgc = value;
 }
Example #23
0
 public static void luaC_link(lua_State L, GCObject o, lu_byte tt)
 {
     global_State g = G(L);
       o.gch.next = g.rootgc;
       g.rootgc = o;
       o.gch.marked = luaC_white(g);
       o.gch.tt = tt;
 }
Example #24
0
 public void set(GCObject value)
 {
     this.header.next = value;
 }
Example #25
0
 private static void freeobj(lua_State L, GCObject o)
 {
     switch (o.gch.tt) {
     case LUA_TPROTO: luaF_freeproto(L, gco2p(o)); break;
     case LUA_TFUNCTION: luaF_freeclosure(L, gco2cl(o)); break;
     case LUA_TUPVAL: luaF_freeupval(L, gco2uv(o)); break;
     case LUA_TTABLE: luaH_free(L, gco2h(o)); break;
     case LUA_TTHREAD: {
       lua_assert(gco2th(o) != L && gco2th(o) != G(L).mainthread);
       luaE_freethread(L, gco2th(o));
       break;
     }
     case LUA_TSTRING: {
       G(L).strt.nuse--;
       SubtractTotalBytes(L, sizestring(gco2ts(o)));
       luaM_freemem(L, gco2ts(o));
       break;
     }
     case LUA_TUSERDATA: {
       SubtractTotalBytes(L, sizeudata(gco2u(o)));
       luaM_freemem(L, gco2u(o));
       break;
     }
     default: lua_assert(0); break;
       }
 }
Example #26
0
 public void set(GCObject value)
 {
     this.g.finobj = value;
 }
Example #27
0
 internal static void setthvalue(lua_State L, TValue obj, GCObject x)
 {
     obj.value.gc = x;
     obj.tt = LUA_TTHREAD;
     checkliveness(G(L), obj);
 }
Example #28
0
 public void set(GCObject value)
 {
     this.g.tobefnz = value;
 }
Example #29
0
 internal static void SetUValue(LuaState L, TValue obj, GCObject x)
 {
     obj.value.gc = x;
     obj.tt = LUA_TUSERDATA;
     CheckLiveness(G(L), obj);
 }
Example #30
0
 public void set(GCObject value)
 {
     this.g.fixedgc = value;
 }
Example #31
0
File: lgc.cs Project: NLua/KopiLua
 public static bool IsWhite(GCObject x)
 {
     return Test2Bits(x.gch.marked, WHITE0BIT, WHITE1BIT);
 }
Example #32
0
 public void set(GCObject value)
 {
     this.g.mt_ = value;
 }
Example #33
0
File: lgc.cs Project: NLua/KopiLua
 public static void LuaCLink(LuaState L, GCObject o, LuaByteType tt)
 {
     GlobalState g = G(L);
       o.gch.next = g.rootgc;
       g.rootgc = o;
       o.gch.marked = LuaCWhite(g);
       o.gch.tt = tt;
 }
Example #34
0
 public void set(GCObject value)
 {
     this.g.nullp = value;
 }
Example #35
0
File: lgc.cs Project: NLua/KopiLua
 public static void White2Gray(GCObject x)
 {
     Reset2Bits(ref x.gch.marked, WHITE0BIT, WHITE1BIT);
 }
Example #36
0
 /* macros to convert a GCObject into a specific value */
 public static TString rawgco2ts(GCObject o)
 {
     return((TString)check_exp(novariant(o.gch.tt) == LUA_TSTRING, o.ts));
 }
Example #37
0
File: lgc.cs Project: NLua/KopiLua
 private static void FreeObj(LuaState L, GCObject o)
 {
     switch (o.gch.tt) {
     case LUATPROTO: LuaFFreeProto(L, gco2p(o)); break;
     case LUA_TFUNCTION: LuaFFreeClosure(L, gco2cl(o)); break;
     case LUATUPVAL: LuaFreeUpVal(L, gco2uv(o)); break;
     case LUA_TTABLE: luaH_free(L, gco2h(o)); break;
     case LUA_TTHREAD: {
       LuaAssert(gco2th(o) != L && gco2th(o) != G(L).mainthread);
       luaE_freethread(L, gco2th(o));
       break;
     }
     case LUA_TSTRING: {
       G(L).strt.nuse--;
       SubtractTotalBytes(L, sizestring(gco2ts(o)));
       LuaMFreeMem(L, gco2ts(o));
       break;
     }
     case LUA_TUSERDATA: {
       SubtractTotalBytes(L, sizeudata(gco2u(o)));
       LuaMFreeMem(L, gco2u(o));
       break;
     }
     default: LuaAssert(0); break;
       }
 }
Example #38
0
 public static TString gco2ts(GCObject o)
 {
     return((TString)(rawgco2ts(o).tsv));
 }
Example #39
0
File: lgc.cs Project: NLua/KopiLua
 public static void Black2Gray(GCObject x)
 {
     ResetBit(ref x.gch.marked, BLACKBIT);
 }
Example #40
0
 public static Udata rawgco2u(GCObject o)
 {
     return((Udata)check_exp(o.gch.tt == LUA_TUSERDATA, o.u));
 }
Example #41
0
 public static bool isblack(GCObject x)
 {
     return testbit(x.gch.marked, BLACKBIT);
 }
Example #42
0
 public static Udata gco2u(GCObject o)
 {
     return((Udata)(rawgco2u(o).uv));
 }
Example #43
0
 public static bool isgray(GCObject x)
 {
     return (!isblack(x) && !iswhite(x));
 }
Example #44
0
 public static LClosure gco2lcl(GCObject o)
 {
     return((LClosure)check_exp(o.gch.tt == LUA_TLCL, o.cl.l));
 }
Example #45
0
 public static void luaC_barrierf(lua_State L, GCObject o, GCObject v)
 {
     global_State g = G(L);
       lua_assert(isblack(o) && iswhite(v) && !isdead(g, v) && !isdead(g, o));
       lua_assert(g.gcstate != GCSfinalize && g.gcstate != GCSpause);
       lua_assert(ttype(o.gch) != LUA_TTABLE);
       /* must keep invariant? */
       if (g.gcstate == GCSpropagate)
     reallymarkobject(g, v);  /* restore invariant */
       else  /* don't mind */
     makewhite(g, o);  /* mark as white just to avoid other barriers */
 }
Example #46
0
 public static CClosure gco2ccl(GCObject o)
 {
     return((CClosure)check_exp(o.gch.tt == LUA_TCCL, o.cl.c));
 }
Example #47
0
 public static void makewhite(global_State g, GCObject x)
 {
     x.gch.marked = (byte)(x.gch.marked & maskmarks | luaC_white(g));
 }
Example #48
0
 public static Closure gco2cl(GCObject o)
 {
     return((Closure)check_exp(novariant(o.gch.tt) == LUA_TFUNCTION, o.cl));
 }
Example #49
0
 /*
 ** clear collected entries from weaktables
 */
 private static void cleartable(GCObject l)
 {
     while (l != null) {
     Table h = gco2h(l);
     int i = h.sizearray;
     lua_assert(testbit(h.marked, VALUEWEAKBIT) ||
                testbit(h.marked, KEYWEAKBIT));
     if (testbit(h.marked, VALUEWEAKBIT)) {
       while (i--!= 0) {
         TValue o = h.array[i];
         if (iscleared(o, false))  /* value was collected? */
           setnilvalue(o);  /* remove value */
       }
     }
     i = sizenode(h);
     while (i-- != 0) {
       Node n = gnode(h, i);
       if (!ttisnil(gval(n)) &&  /* non-empty entry? */
           (iscleared(key2tval(n), true) || iscleared(gval(n), false))) {
         setnilvalue(gval(n));  /* remove value ... */
         removeentry(n);  /* remove entry from Table */
       }
     }
     l = h.gclist;
       }
 }
Example #50
0
 public static Table gco2t(GCObject o)
 {
     return((Table)check_exp(o.gch.tt == LUA_TTABLE, o.h));
 }
Example #51
0
 private static void reallymarkobject(global_State g, GCObject o)
 {
     lua_assert(iswhite(o) && !isdead(g, o));
       white2gray(o);
       switch (o.gch.tt) {
     case LUA_TSTRING: {
       return;
     }
     case LUA_TUSERDATA: {
       Table mt = gco2u(o).metatable;
       gray2black(o);  /* udata are never gray */
       if (mt != null) markobject(g, mt);
       markobject(g, gco2u(o).env);
       return;
     }
     case LUA_TUPVAL: {
       UpVal uv = gco2uv(o);
       markvalue(g, uv.v);
       if (uv.v == uv.u.value)  /* closed? */
         gray2black(o);  /* open upvalues are never black */
       return;
     }
     case LUA_TFUNCTION: {
       gco2cl(o).c.gclist = g.gray;
       g.gray = o;
       break;
     }
     case LUA_TTABLE: {
       gco2h(o).gclist = g.gray;
       g.gray = o;
       break;
     }
     case LUA_TTHREAD: {
       gco2th(o).gclist = g.gray;
       g.gray = o;
       break;
     }
     case LUA_TPROTO: {
       gco2p(o).gclist = g.gray;
       g.gray = o;
       break;
     }
     default: lua_assert(0); break;
       }
 }
Example #52
0
 public static Proto gco2p(GCObject o)
 {
     return((Proto)check_exp(o.gch.tt == LUA_TPROTO, o.p));
 }
Example #53
0
 public static void changewhite(GCObject x)
 {
     x.gch.marked ^= (byte)WHITEBITS;
 }
Example #54
0
 public static lua_State gco2th(GCObject o)
 {
     return((lua_State)check_exp(o.gch.tt == LUA_TTHREAD, o.th));
 }
Example #55
0
 internal static void setuvalue(lua_State L, TValue obj, GCObject x)
 {
     obj.value.gc = x;
     obj.tt = LUA_TUSERDATA;
     checkliveness(G(L), obj);
 }
Example #56
0
 internal static void setuvalue(lua_State L, TValue obj, GCObject x)
 {
     obj.value.gc = x;
     obj.tt       = LUA_TUSERDATA;
     checkliveness(G(L), obj);
 }
Example #57
0
 internal static void SetTTHValue(LuaState L, TValue obj, GCObject x)
 {
     obj.value.gc = x;
     obj.tt = LUA_TTHREAD;
     CheckLiveness(G(L), obj);
 }
Example #58
0
 internal static void setthvalue(lua_State L, TValue obj, GCObject x)
 {
     obj.value.gc = x;
     obj.tt       = LUA_TTHREAD;
     checkliveness(G(L), obj);
 }
Example #59
0
File: lgc.cs Project: NLua/KopiLua
 public static bool IsGray(GCObject x)
 {
     return (!IsBlack(x) && !IsWhite(x));
 }
Example #60
0
 public static void black2gray(GCObject x)
 {
     resetbit(ref gch(x).marked, BLACKBIT);
 }