aboutsummaryrefslogtreecommitdiff
path: root/testes
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2019-07-12 16:13:50 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2019-07-12 16:13:50 -0300
commit1fb4d539254b67e7e35ed698250c66d1edff0e08 (patch)
tree8f48b7ca736a7fb02834bcfac1415cd43307f529 /testes
parentf6aab3ec1f111cd8d968bdcb7ca800e93b819d24 (diff)
downloadlua-1fb4d539254b67e7e35ed698250c66d1edff0e08.tar.gz
lua-1fb4d539254b67e7e35ed698250c66d1edff0e08.tar.bz2
lua-1fb4d539254b67e7e35ed698250c66d1edff0e08.zip
OP_NEWTABLE keeps exact size of arrays
OP_NEWTABLE is followed by an OP_EXTRAARG, so that it can keep the exact size of the array part of the table to be created. (Functions 'luaO_int2fb'/'luaO_fb2int' were removed.)
Diffstat (limited to 'testes')
-rw-r--r--testes/code.lua6
-rw-r--r--testes/nextvar.lua52
2 files changed, 23 insertions, 35 deletions
diff --git a/testes/code.lua b/testes/code.lua
index 49d682f8..b2702c61 100644
--- a/testes/code.lua
+++ b/testes/code.lua
@@ -93,11 +93,13 @@ end
93-- some basic instructions 93-- some basic instructions
94check(function () -- function does not create upvalues 94check(function () -- function does not create upvalues
95 (function () end){f()} 95 (function () end){f()}
96end, 'CLOSURE', 'NEWTABLE', 'GETTABUP', 'CALL', 'SETLIST', 'CALL', 'RETURN0') 96end, 'CLOSURE', 'NEWTABLE', 'EXTRAARG', 'GETTABUP', 'CALL',
97 'SETLIST', 'CALL', 'RETURN0')
97 98
98check(function (x) -- function creates upvalues 99check(function (x) -- function creates upvalues
99 (function () return x end){f()} 100 (function () return x end){f()}
100end, 'CLOSURE', 'NEWTABLE', 'GETTABUP', 'CALL', 'SETLIST', 'CALL', 'RETURN') 101end, 'CLOSURE', 'NEWTABLE', 'EXTRAARG', 'GETTABUP', 'CALL',
102 'SETLIST', 'CALL', 'RETURN')
101 103
102 104
103-- sequence of LOADNILs 105-- sequence of LOADNILs
diff --git a/testes/nextvar.lua b/testes/nextvar.lua
index 87a6bfa8..bdc9fc29 100644
--- a/testes/nextvar.lua
+++ b/testes/nextvar.lua
@@ -49,33 +49,13 @@ if not T then
49else --[ 49else --[
50-- testing table sizes 50-- testing table sizes
51 51
52local function log2 (x) return math.log(x, 2) end
53 52
54local function mp2 (n) -- minimum power of 2 >= n 53local function mp2 (n) -- minimum power of 2 >= n
55 local mp = 2^math.ceil(log2(n)) 54 local mp = 2^math.ceil(math.log(n, 2))
56 assert(n == 0 or (mp/2 < n and n <= mp)) 55 assert(n == 0 or (mp/2 < n and n <= mp))
57 return mp 56 return mp
58end 57end
59 58
60local function fb (n)
61 local r, nn = T.int2fb(n)
62 assert(r < 256)
63 return nn
64end
65
66-- test fb function
67for a = 1, 10000 do -- all numbers up to 10^4
68 local n = fb(a)
69 assert(a <= n and n <= a*1.125)
70end
71local a = 1024 -- plus a few up to 2 ^30
72local lim = 2^30
73while a < lim do
74 local n = fb(a)
75 assert(a <= n and n <= a*1.125)
76 a = math.ceil(a*1.3)
77end
78
79 59
80local function check (t, na, nh) 60local function check (t, na, nh)
81 local a, h = T.querytab(t) 61 local a, h = T.querytab(t)
@@ -95,24 +75,30 @@ end
95 75
96 76
97-- testing constructor sizes 77-- testing constructor sizes
98local lim = 40 78local sizes = {0, 1, 2, 3, 4, 5, 7, 8, 9, 15, 16, 17,
99local s = 'return {' 79 30, 31, 32, 33, 34, 500, 1000}
100for i=1,lim do 80
101 s = s..i..',' 81for _, sa in ipairs(sizes) do -- 'sa' is size of the array part
102 local s = s 82 local arr = {"return {"}
103 for k=0,lim do 83 -- array part
104 local t = load(s..'}', '')() 84 for i = 1, sa do arr[1 + i] = "1," end
105 assert(#t == i) 85 for _, sh in ipairs(sizes) do -- 'sh' is size of the hash part
106 check(t, fb(i), mp2(k)) 86 for j = 1, sh do -- hash part
107 s = string.format('%sa%d=%d,', s, k, k) 87 arr[1 + sa + j] = string.format('k%x=%d,', j, j)
88 end
89 arr[1 + sa + sh + 1] = "}"
90 local prog = table.concat(arr)
91 local t = assert(load(prog))()
92 assert(#t == sa)
93 check(t, sa, mp2(sh))
108 end 94 end
109end 95end
110 96
111 97
112-- tests with unknown number of elements 98-- tests with unknown number of elements
113local a = {} 99local a = {}
114for i=1,lim do a[i] = i end -- build auxiliary table 100for i=1,sizes[#sizes] do a[i] = i end -- build auxiliary table
115for k=0,lim do 101for k in ipairs(sizes) do
116 local a = {table.unpack(a,1,k)} 102 local a = {table.unpack(a,1,k)}
117 assert(#a == k) 103 assert(#a == k)
118 check(a, k, 0) 104 check(a, k, 0)