verybig.lua 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. -- $Id: testes/verybig.lua $
  2. -- See Copyright Notice in file all.lua
  3. print "testing RK"
  4. -- testing opcodes with RK arguments larger than K limit
  5. local function foo ()
  6. local dummy = {
  7. -- fill first 256 entries in table of constants
  8. 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
  9. 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32,
  10. 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48,
  11. 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64,
  12. 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80,
  13. 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96,
  14. 97, 98, 99, 100, 101, 102, 103, 104,
  15. 105, 106, 107, 108, 109, 110, 111, 112,
  16. 113, 114, 115, 116, 117, 118, 119, 120,
  17. 121, 122, 123, 124, 125, 126, 127, 128,
  18. 129, 130, 131, 132, 133, 134, 135, 136,
  19. 137, 138, 139, 140, 141, 142, 143, 144,
  20. 145, 146, 147, 148, 149, 150, 151, 152,
  21. 153, 154, 155, 156, 157, 158, 159, 160,
  22. 161, 162, 163, 164, 165, 166, 167, 168,
  23. 169, 170, 171, 172, 173, 174, 175, 176,
  24. 177, 178, 179, 180, 181, 182, 183, 184,
  25. 185, 186, 187, 188, 189, 190, 191, 192,
  26. 193, 194, 195, 196, 197, 198, 199, 200,
  27. 201, 202, 203, 204, 205, 206, 207, 208,
  28. 209, 210, 211, 212, 213, 214, 215, 216,
  29. 217, 218, 219, 220, 221, 222, 223, 224,
  30. 225, 226, 227, 228, 229, 230, 231, 232,
  31. 233, 234, 235, 236, 237, 238, 239, 240,
  32. 241, 242, 243, 244, 245, 246, 247, 248,
  33. 249, 250, 251, 252, 253, 254, 255, 256,
  34. }
  35. assert(24.5 + 0.6 == 25.1)
  36. local t = {foo = function (self, x) return x + self.x end, x = 10}
  37. t.t = t
  38. assert(t:foo(1.5) == 11.5)
  39. assert(t.t:foo(0.5) == 10.5) -- bug in 5.2 alpha
  40. assert(24.3 == 24.3)
  41. assert((function () return t.x end)() == 10)
  42. end
  43. foo()
  44. foo = nil
  45. if _soft then return 10 end
  46. print "testing large programs (>64k)"
  47. -- template to create a very big test file
  48. local prog = [[$
  49. local a,b
  50. b = {$1$
  51. b30009 = 65534,
  52. b30010 = 65535,
  53. b30011 = 65536,
  54. b30012 = 65537,
  55. b30013 = 16777214,
  56. b30014 = 16777215,
  57. b30015 = 16777216,
  58. b30016 = 16777217,
  59. b30017 = 0x7fffff,
  60. b30018 = -0x7fffff,
  61. b30019 = 0x1ffffff,
  62. b30020 = -0x1ffffd,
  63. b30021 = -65534,
  64. b30022 = -65535,
  65. b30023 = -65536,
  66. b30024 = -0xffffff,
  67. b30025 = 15012.5,
  68. $2$
  69. };
  70. assert(b.a50008 == 25004 and b["a11"] == -5.5)
  71. assert(b.a33007 == -16503.5 and b.a50009 == -25004.5)
  72. assert(b["b"..30024] == -0xffffff)
  73. function b:xxx (a,b) return a+b end
  74. assert(b:xxx(10, 12) == 22) -- pushself with non-constant index
  75. b["xxx"] = undef
  76. local s = 0; local n=0
  77. for a,b in pairs(b) do s=s+b; n=n+1 end
  78. -- with 32-bit floats, exact value of 's' depends on summation order
  79. assert(81800000.0 < s and s < 81860000 and n == 70001)
  80. a = nil; b = nil
  81. print'+'
  82. local function f(x) b=x end
  83. a = f{$3$} or 10
  84. assert(a==10)
  85. assert(b[1] == "a10" and b[2] == 5 and b[#b-1] == "a50009")
  86. function xxxx (x) return b[x] end
  87. assert(xxxx(3) == "a11")
  88. a = nil; b=nil
  89. xxxx = nil
  90. return 10
  91. ]]
  92. -- functions to fill in the $n$
  93. local function sig (x)
  94. return (x % 2 == 0) and '' or '-'
  95. end
  96. local F = {
  97. function () -- $1$
  98. for i=10,50009 do
  99. io.write('a', i, ' = ', sig(i), 5+((i-10)/2), ',\n')
  100. end
  101. end,
  102. function () -- $2$
  103. for i=30026,50009 do
  104. io.write('b', i, ' = ', sig(i), 15013+((i-30026)/2), ',\n')
  105. end
  106. end,
  107. function () -- $3$
  108. for i=10,50009 do
  109. io.write('"a', i, '", ', sig(i), 5+((i-10)/2), ',\n')
  110. end
  111. end,
  112. }
  113. local file = os.tmpname()
  114. io.output(file)
  115. for s in string.gmatch(prog, "$([^$]+)") do
  116. local n = tonumber(s)
  117. if not n then io.write(s) else F[n]() end
  118. end
  119. io.close()
  120. local result = dofile(file)
  121. assert(os.remove(file))
  122. print'OK'
  123. return result