verybig.lua 3.4 KB

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