From 6a2199afb393ff371869900c900d42aaaabd114d Mon Sep 17 00:00:00 2001 From: Dong Feng Date: Tue, 22 Oct 2013 16:53:32 +0800 Subject: [PATCH] Table, hashing, meta-table (tagged method). --- lgc.c | 8 +++++++- lobject.h | 13 +++++++++++++ ltable.c | 40 ++++++++++++++++++++++++++++++++++++++++ ltm.c | 5 +++++ lua.h | 20 ++++++++++++++++++++ 5 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 ltm.c create mode 100644 lua.h diff --git a/lgc.c b/lgc.c index 5a8ec15..ece82e7 100644 --- a/lgc.c +++ b/lgc.c @@ -16,7 +16,9 @@ General Process 6. A current-white object MUST be unreachable at "atomic" step because at that point all reachable and some just-becoming-unreachable objects have all been marked. 7. At "atomic" step, all current-white objects are added to the sweep lists, and - then they become other-white because the while flag is flipped. + then they become other-white because the while flag is flipped. After "atomic" step, + all "other-white" objects are guranteed to be unreachable until the next "pause" + step. @@ -80,6 +82,10 @@ isdeadm(ow,m) Ture if "m" has "other_than_current_white" marked. +linktable(h,p) +================================================================================ +Link table "h" on to list "p". The *next* pointer is h->gclist. + static GCObject *udata2finalize (global_State *g) ================================================================================ diff --git a/lobject.h b/lobject.h index 63bafb1..99cc431 100644 --- a/lobject.h +++ b/lobject.h @@ -34,6 +34,19 @@ GCObject ------------------------------------------------- +------------------------------------------------- + GCObject* next | + lu_byte tt | Common header + lu_byte marked | +------------------------------------------------- + lu_byte extra | + unsigned int hash | tsv + size_t len | +------------------------------------------------- + + + + UpVal diff --git a/ltable.c b/ltable.c index 4b9f5a3..8d6f779 100644 --- a/ltable.c +++ b/ltable.c @@ -8,3 +8,43 @@ t: table Return the hashed slot corresponding to "n" in table "t". + + +hashmod(t,n) +========================================================================== +This method differs from "hashpow2()" in that the underlying algorithm of +moduling is the ordinary "C" moduling rather than a bit-manipulating one optimized +for 2-base-powered size of "t". + +"n" is actually moduled by size of t minues 1, rather than size of t. + + + + + +const TValue *luaH_getstr (Table *t, TString *key) +========================================================================== +Get value if "key" is a short-string. + + + + +static Node *mainposition (const Table *t, const TValue *key) +========================================================================== +Get the main hash-ed position for "key". + + + + +static Node *hashnum (const Table *t, lua_Number n) +========================================================================== +Return the main hash-ed position for "n". + + + + +luai_hashnum(i,n) +========================================================================== +Compute the hashcode of "n" and put it to "i". + + diff --git a/ltm.c b/ltm.c new file mode 100644 index 0000000..365bab2 --- /dev/null +++ b/ltm.c @@ -0,0 +1,5 @@ + + + +const TValue *luaT_gettm (Table *events, TMS event, TString *ename) +====================================================================== \ No newline at end of file diff --git a/lua.h b/lua.h new file mode 100644 index 0000000..93b39c9 --- /dev/null +++ b/lua.h @@ -0,0 +1,20 @@ + + +Basic Types +----------------------------------------------------------- +The enum of "basic types" is: LUA_T... +A "basic type" enum occupies only the right-most forth bits. +The fifth right-most bit represent the "sub-type": + - short/long string + - c/Lua closure + ... +The seventh right-most bit represent if the type is collectable. + + + /* + ** tags for Tagged Values have the following use of bits: + ** bits 0-3: actual tag (a LUA_T* value) + ** bits 4-5: variant bits + ** bit 6: whether value is collectable + */ +