diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2023-10-30 14:25:59 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2023-10-30 14:25:59 -0300 |
commit | 43c8e5bded052801f54a7439d18933b83570eb82 (patch) | |
tree | 97f6d1e020110e14c798537c7bbb1f90feed4044 /ltable.h | |
parent | b8b709b6d40c5c18d9b8ef33bb50afc55f048ab8 (diff) | |
download | lua-43c8e5bded052801f54a7439d18933b83570eb82.tar.gz lua-43c8e5bded052801f54a7439d18933b83570eb82.tar.bz2 lua-43c8e5bded052801f54a7439d18933b83570eb82.zip |
Full abstraction for representation of array values
Diffstat (limited to 'ltable.h')
-rw-r--r-- | ltable.h | 21 |
1 files changed, 17 insertions, 4 deletions
@@ -51,20 +51,33 @@ | |||
51 | */ | 51 | */ |
52 | 52 | ||
53 | 53 | ||
54 | struct ArrayCell { | ||
55 | lu_byte tt; | ||
56 | Value value; | ||
57 | }; | ||
58 | |||
54 | 59 | ||
55 | /* fast access to components of array values */ | 60 | /* fast access to components of array values */ |
56 | #define getArrTag(t,k) (&(t)->array[k - 1].tt_) | 61 | #define getArrTag(t,k) (&(t)->array[k - 1].tt) |
57 | #define getArrVal(t,k) (&(t)->array[k - 1].value_) | 62 | #define getArrVal(t,k) (&(t)->array[k - 1].value) |
58 | 63 | ||
59 | #define tagisempty(tag) (novariant(tag) == LUA_TNIL) | 64 | #define tagisempty(tag) (novariant(tag) == LUA_TNIL) |
60 | 65 | ||
61 | #define arr2val(h,k,tag,res) \ | 66 | |
67 | #define farr2val(h,k,tag,res) \ | ||
62 | ((res)->tt_ = tag, (res)->value_ = *getArrVal(h,k)) | 68 | ((res)->tt_ = tag, (res)->value_ = *getArrVal(h,k)) |
63 | 69 | ||
64 | #define val2arr(h,k,tag,val) \ | 70 | #define fval2arr(h,k,tag,val) \ |
65 | (*tag = (val)->tt_, *getArrVal(h,k) = (val)->value_) | 71 | (*tag = (val)->tt_, *getArrVal(h,k) = (val)->value_) |
66 | 72 | ||
67 | 73 | ||
74 | #define obj2arr(h,k,val) \ | ||
75 | (*getArrTag(h,k) = (val)->tt_, *getArrVal(h,k) = (val)->value_) | ||
76 | |||
77 | #define arr2obj(h,k,val) \ | ||
78 | ((val)->tt_ = *getArrTag(h,k), (val)->value_ = *getArrVal(h,k)) | ||
79 | |||
80 | |||
68 | LUAI_FUNC int luaH_getshortstr (Table *t, TString *key, TValue *res); | 81 | LUAI_FUNC int luaH_getshortstr (Table *t, TString *key, TValue *res); |
69 | LUAI_FUNC int luaH_getstr (Table *t, TString *key, TValue *res); | 82 | LUAI_FUNC int luaH_getstr (Table *t, TString *key, TValue *res); |
70 | LUAI_FUNC int luaH_get (Table *t, const TValue *key, TValue *res); | 83 | LUAI_FUNC int luaH_get (Table *t, const TValue *key, TValue *res); |