diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-07-15 14:59:35 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-07-15 14:59:35 -0300 |
commit | 758c1ef445ab27d89bace746111add04083a8e20 (patch) | |
tree | 8136726cfaa1dc0841547987f2cb0555d02f2303 /testes | |
parent | dd6d8db49acda5d5353a0a9c42485d9b4bde419d (diff) | |
download | lua-758c1ef445ab27d89bace746111add04083a8e20.tar.gz lua-758c1ef445ab27d89bace746111add04083a8e20.tar.bz2 lua-758c1ef445ab27d89bace746111add04083a8e20.zip |
Unification of size representation in OP_NEWTABLE and OP_SETLIST
Opcodes OP_NEWTABLE and OP_SETLIST use the same representation to
store the size of the array part of a table. This new representation
can go up to 2^33 (8 + 25 bits).
Diffstat (limited to 'testes')
-rw-r--r-- | testes/nextvar.lua | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/testes/nextvar.lua b/testes/nextvar.lua index bdc9fc29..a7fe625e 100644 --- a/testes/nextvar.lua +++ b/testes/nextvar.lua | |||
@@ -80,15 +80,23 @@ local sizes = {0, 1, 2, 3, 4, 5, 7, 8, 9, 15, 16, 17, | |||
80 | 80 | ||
81 | for _, sa in ipairs(sizes) do -- 'sa' is size of the array part | 81 | for _, sa in ipairs(sizes) do -- 'sa' is size of the array part |
82 | local arr = {"return {"} | 82 | local arr = {"return {"} |
83 | -- array part | 83 | for i = 1, sa do arr[1 + i] = "1," end -- build array part |
84 | for i = 1, sa do arr[1 + i] = "1," end | ||
85 | for _, sh in ipairs(sizes) do -- 'sh' is size of the hash part | 84 | for _, sh in ipairs(sizes) do -- 'sh' is size of the hash part |
86 | for j = 1, sh do -- hash part | 85 | for j = 1, sh do -- build hash part |
87 | arr[1 + sa + j] = string.format('k%x=%d,', j, j) | 86 | arr[1 + sa + j] = string.format('k%x=%d,', j, j) |
88 | end | 87 | end |
89 | arr[1 + sa + sh + 1] = "}" | 88 | arr[1 + sa + sh + 1] = "}" |
90 | local prog = table.concat(arr) | 89 | local prog = table.concat(arr) |
91 | local t = assert(load(prog))() | 90 | local f = assert(load(prog)) |
91 | f() -- call once to ensure stack space | ||
92 | -- make sure table is not resized after being created | ||
93 | if sa == 0 or sh == 0 then | ||
94 | T.alloccount(2); -- header + array or hash part | ||
95 | else | ||
96 | T.alloccount(3); -- header + array part + hash part | ||
97 | end | ||
98 | local t = f() | ||
99 | T.alloccount(); | ||
92 | assert(#t == sa) | 100 | assert(#t == sa) |
93 | check(t, sa, mp2(sh)) | 101 | check(t, sa, mp2(sh)) |
94 | end | 102 | end |
@@ -99,12 +107,12 @@ end | |||
99 | local a = {} | 107 | local a = {} |
100 | for i=1,sizes[#sizes] do a[i] = i end -- build auxiliary table | 108 | for i=1,sizes[#sizes] do a[i] = i end -- build auxiliary table |
101 | for k in ipairs(sizes) do | 109 | for k in ipairs(sizes) do |
102 | local a = {table.unpack(a,1,k)} | 110 | local t = {table.unpack(a,1,k)} |
103 | assert(#a == k) | 111 | assert(#t == k) |
104 | check(a, k, 0) | 112 | check(t, k, 0) |
105 | a = {1,2,3,table.unpack(a,1,k)} | 113 | t = {1,2,3,table.unpack(a,1,k)} |
106 | check(a, k+3, 0) | 114 | check(t, k+3, 0) |
107 | assert(#a == k + 3) | 115 | assert(#t == k + 3) |
108 | end | 116 | end |
109 | 117 | ||
110 | 118 | ||