immunio 1.2.1 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (291) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +13 -5
  3. data/ext/immunio/Rakefile +14 -6
  4. data/lib/immunio/context.rb +2 -0
  5. data/lib/immunio/plugins/action_view.rb +7 -668
  6. data/lib/immunio/plugins/action_view/action_view.rb +22 -0
  7. data/lib/immunio/plugins/action_view/active_support_hash.rb +29 -0
  8. data/lib/immunio/plugins/action_view/cache_store.rb +24 -0
  9. data/lib/immunio/plugins/action_view/erubi.rb +38 -0
  10. data/lib/immunio/plugins/action_view/erubis.rb +39 -0
  11. data/lib/immunio/plugins/action_view/fragment_caching.rb +29 -0
  12. data/lib/immunio/plugins/action_view/haml.rb +46 -0
  13. data/lib/immunio/plugins/action_view/slim.rb +42 -0
  14. data/lib/immunio/plugins/action_view/template.rb +431 -0
  15. data/lib/immunio/plugins/action_view/template_rendering.rb +45 -0
  16. data/lib/immunio/plugins/http_tracker.rb +2 -0
  17. data/lib/immunio/plugins/io.rb +34 -0
  18. data/lib/immunio/version.rb +1 -1
  19. data/lua-hooks/Makefile +36 -9
  20. data/lua-hooks/ext/luajit/COPYRIGHT +1 -1
  21. data/lua-hooks/ext/luajit/Makefile +22 -15
  22. data/lua-hooks/ext/luajit/README +2 -2
  23. data/lua-hooks/ext/luajit/doc/bluequad-print.css +1 -1
  24. data/lua-hooks/ext/luajit/doc/bluequad.css +1 -1
  25. data/lua-hooks/ext/luajit/doc/changes.html +69 -3
  26. data/lua-hooks/ext/luajit/doc/contact.html +10 -3
  27. data/lua-hooks/ext/luajit/doc/ext_c_api.html +2 -2
  28. data/lua-hooks/ext/luajit/doc/ext_ffi.html +2 -2
  29. data/lua-hooks/ext/luajit/doc/ext_ffi_api.html +2 -2
  30. data/lua-hooks/ext/luajit/doc/ext_ffi_semantics.html +3 -4
  31. data/lua-hooks/ext/luajit/doc/ext_ffi_tutorial.html +2 -2
  32. data/lua-hooks/ext/luajit/doc/ext_jit.html +3 -3
  33. data/lua-hooks/ext/luajit/doc/ext_profiler.html +2 -2
  34. data/lua-hooks/ext/luajit/doc/extensions.html +47 -20
  35. data/lua-hooks/ext/luajit/doc/faq.html +2 -2
  36. data/lua-hooks/ext/luajit/doc/install.html +74 -45
  37. data/lua-hooks/ext/luajit/doc/luajit.html +5 -5
  38. data/lua-hooks/ext/luajit/doc/running.html +3 -3
  39. data/lua-hooks/ext/luajit/doc/status.html +13 -8
  40. data/lua-hooks/ext/luajit/dynasm/dasm_arm.h +1 -1
  41. data/lua-hooks/ext/luajit/dynasm/dasm_arm.lua +1 -1
  42. data/lua-hooks/ext/luajit/dynasm/dasm_arm64.h +1 -1
  43. data/lua-hooks/ext/luajit/dynasm/dasm_arm64.lua +1 -1
  44. data/lua-hooks/ext/luajit/dynasm/dasm_mips.h +8 -5
  45. data/lua-hooks/ext/luajit/dynasm/dasm_mips.lua +66 -11
  46. data/lua-hooks/ext/luajit/dynasm/dasm_mips64.lua +12 -0
  47. data/lua-hooks/ext/luajit/dynasm/dasm_ppc.h +1 -1
  48. data/lua-hooks/ext/luajit/dynasm/dasm_ppc.lua +1 -1
  49. data/lua-hooks/ext/luajit/dynasm/dasm_proto.h +1 -1
  50. data/lua-hooks/ext/luajit/dynasm/dasm_x64.lua +1 -1
  51. data/lua-hooks/ext/luajit/dynasm/dasm_x86.h +1 -1
  52. data/lua-hooks/ext/luajit/dynasm/dasm_x86.lua +5 -1
  53. data/lua-hooks/ext/luajit/dynasm/dynasm.lua +2 -2
  54. data/lua-hooks/ext/luajit/etc/luajit.1 +1 -1
  55. data/lua-hooks/ext/luajit/etc/luajit.pc +1 -1
  56. data/lua-hooks/ext/luajit/src/Makefile +15 -11
  57. data/lua-hooks/ext/luajit/src/Makefile.dep +16 -16
  58. data/lua-hooks/ext/luajit/src/host/buildvm.c +2 -2
  59. data/lua-hooks/ext/luajit/src/host/buildvm.h +1 -1
  60. data/lua-hooks/ext/luajit/src/host/buildvm_asm.c +9 -4
  61. data/lua-hooks/ext/luajit/src/host/buildvm_fold.c +2 -2
  62. data/lua-hooks/ext/luajit/src/host/buildvm_lib.c +1 -1
  63. data/lua-hooks/ext/luajit/src/host/buildvm_libbc.h +14 -3
  64. data/lua-hooks/ext/luajit/src/host/buildvm_peobj.c +27 -3
  65. data/lua-hooks/ext/luajit/src/host/genlibbc.lua +1 -1
  66. data/lua-hooks/ext/luajit/src/host/genminilua.lua +6 -5
  67. data/lua-hooks/ext/luajit/src/host/minilua.c +1 -1
  68. data/lua-hooks/ext/luajit/src/jit/bc.lua +1 -1
  69. data/lua-hooks/ext/luajit/src/jit/bcsave.lua +8 -8
  70. data/lua-hooks/ext/luajit/src/jit/dis_arm.lua +2 -2
  71. data/lua-hooks/ext/luajit/src/jit/dis_arm64.lua +1216 -0
  72. data/lua-hooks/ext/luajit/src/jit/dis_arm64be.lua +12 -0
  73. data/lua-hooks/ext/luajit/src/jit/dis_mips.lua +35 -20
  74. data/lua-hooks/ext/luajit/src/jit/dis_mips64.lua +17 -0
  75. data/lua-hooks/ext/luajit/src/jit/dis_mips64el.lua +17 -0
  76. data/lua-hooks/ext/luajit/src/jit/dis_mipsel.lua +1 -1
  77. data/lua-hooks/ext/luajit/src/jit/dis_ppc.lua +2 -2
  78. data/lua-hooks/ext/luajit/src/jit/dis_x64.lua +1 -1
  79. data/lua-hooks/ext/luajit/src/jit/dis_x86.lua +7 -4
  80. data/lua-hooks/ext/luajit/src/jit/dump.lua +17 -12
  81. data/lua-hooks/ext/luajit/src/jit/p.lua +3 -2
  82. data/lua-hooks/ext/luajit/src/jit/v.lua +2 -2
  83. data/lua-hooks/ext/luajit/src/jit/zone.lua +1 -1
  84. data/lua-hooks/ext/luajit/src/lauxlib.h +14 -20
  85. data/lua-hooks/ext/luajit/src/lib_aux.c +38 -27
  86. data/lua-hooks/ext/luajit/src/lib_base.c +12 -5
  87. data/lua-hooks/ext/luajit/src/lib_bit.c +1 -1
  88. data/lua-hooks/ext/luajit/src/lib_debug.c +5 -5
  89. data/lua-hooks/ext/luajit/src/lib_ffi.c +2 -2
  90. data/lua-hooks/ext/luajit/src/lib_init.c +16 -16
  91. data/lua-hooks/ext/luajit/src/lib_io.c +6 -7
  92. data/lua-hooks/ext/luajit/src/lib_jit.c +14 -4
  93. data/lua-hooks/ext/luajit/src/lib_math.c +1 -5
  94. data/lua-hooks/ext/luajit/src/lib_os.c +1 -1
  95. data/lua-hooks/ext/luajit/src/lib_package.c +14 -23
  96. data/lua-hooks/ext/luajit/src/lib_string.c +1 -5
  97. data/lua-hooks/ext/luajit/src/lib_table.c +21 -1
  98. data/lua-hooks/ext/luajit/src/lj.supp +3 -3
  99. data/lua-hooks/ext/luajit/src/lj_alloc.c +174 -83
  100. data/lua-hooks/ext/luajit/src/lj_api.c +97 -18
  101. data/lua-hooks/ext/luajit/src/lj_arch.h +54 -22
  102. data/lua-hooks/ext/luajit/src/lj_asm.c +172 -53
  103. data/lua-hooks/ext/luajit/src/lj_asm.h +1 -1
  104. data/lua-hooks/ext/luajit/src/lj_asm_arm.h +19 -16
  105. data/lua-hooks/ext/luajit/src/lj_asm_arm64.h +2022 -0
  106. data/lua-hooks/ext/luajit/src/lj_asm_mips.h +564 -158
  107. data/lua-hooks/ext/luajit/src/lj_asm_ppc.h +19 -18
  108. data/lua-hooks/ext/luajit/src/lj_asm_x86.h +578 -92
  109. data/lua-hooks/ext/luajit/src/lj_bc.c +1 -1
  110. data/lua-hooks/ext/luajit/src/lj_bc.h +1 -1
  111. data/lua-hooks/ext/luajit/src/lj_bcdump.h +1 -1
  112. data/lua-hooks/ext/luajit/src/lj_bcread.c +1 -1
  113. data/lua-hooks/ext/luajit/src/lj_bcwrite.c +1 -1
  114. data/lua-hooks/ext/luajit/src/lj_buf.c +1 -1
  115. data/lua-hooks/ext/luajit/src/lj_buf.h +1 -1
  116. data/lua-hooks/ext/luajit/src/lj_carith.c +1 -1
  117. data/lua-hooks/ext/luajit/src/lj_carith.h +1 -1
  118. data/lua-hooks/ext/luajit/src/lj_ccall.c +172 -7
  119. data/lua-hooks/ext/luajit/src/lj_ccall.h +21 -5
  120. data/lua-hooks/ext/luajit/src/lj_ccallback.c +71 -17
  121. data/lua-hooks/ext/luajit/src/lj_ccallback.h +1 -1
  122. data/lua-hooks/ext/luajit/src/lj_cconv.c +4 -2
  123. data/lua-hooks/ext/luajit/src/lj_cconv.h +1 -1
  124. data/lua-hooks/ext/luajit/src/lj_cdata.c +7 -5
  125. data/lua-hooks/ext/luajit/src/lj_cdata.h +1 -1
  126. data/lua-hooks/ext/luajit/src/lj_clib.c +5 -5
  127. data/lua-hooks/ext/luajit/src/lj_clib.h +1 -1
  128. data/lua-hooks/ext/luajit/src/lj_cparse.c +11 -6
  129. data/lua-hooks/ext/luajit/src/lj_cparse.h +1 -1
  130. data/lua-hooks/ext/luajit/src/lj_crecord.c +70 -14
  131. data/lua-hooks/ext/luajit/src/lj_crecord.h +1 -1
  132. data/lua-hooks/ext/luajit/src/lj_ctype.c +1 -1
  133. data/lua-hooks/ext/luajit/src/lj_ctype.h +8 -8
  134. data/lua-hooks/ext/luajit/src/lj_debug.c +1 -1
  135. data/lua-hooks/ext/luajit/src/lj_debug.h +1 -1
  136. data/lua-hooks/ext/luajit/src/lj_def.h +6 -9
  137. data/lua-hooks/ext/luajit/src/lj_dispatch.c +3 -3
  138. data/lua-hooks/ext/luajit/src/lj_dispatch.h +2 -1
  139. data/lua-hooks/ext/luajit/src/lj_emit_arm.h +5 -4
  140. data/lua-hooks/ext/luajit/src/lj_emit_arm64.h +419 -0
  141. data/lua-hooks/ext/luajit/src/lj_emit_mips.h +100 -20
  142. data/lua-hooks/ext/luajit/src/lj_emit_ppc.h +4 -4
  143. data/lua-hooks/ext/luajit/src/lj_emit_x86.h +116 -25
  144. data/lua-hooks/ext/luajit/src/lj_err.c +34 -13
  145. data/lua-hooks/ext/luajit/src/lj_err.h +1 -1
  146. data/lua-hooks/ext/luajit/src/lj_errmsg.h +1 -1
  147. data/lua-hooks/ext/luajit/src/lj_ff.h +1 -1
  148. data/lua-hooks/ext/luajit/src/lj_ffrecord.c +58 -49
  149. data/lua-hooks/ext/luajit/src/lj_ffrecord.h +1 -1
  150. data/lua-hooks/ext/luajit/src/lj_frame.h +33 -6
  151. data/lua-hooks/ext/luajit/src/lj_func.c +4 -2
  152. data/lua-hooks/ext/luajit/src/lj_func.h +1 -1
  153. data/lua-hooks/ext/luajit/src/lj_gc.c +16 -7
  154. data/lua-hooks/ext/luajit/src/lj_gc.h +1 -1
  155. data/lua-hooks/ext/luajit/src/lj_gdbjit.c +31 -1
  156. data/lua-hooks/ext/luajit/src/lj_gdbjit.h +1 -1
  157. data/lua-hooks/ext/luajit/src/lj_ir.c +69 -96
  158. data/lua-hooks/ext/luajit/src/lj_ir.h +29 -18
  159. data/lua-hooks/ext/luajit/src/lj_ircall.h +24 -30
  160. data/lua-hooks/ext/luajit/src/lj_iropt.h +9 -9
  161. data/lua-hooks/ext/luajit/src/lj_jit.h +67 -9
  162. data/lua-hooks/ext/luajit/src/lj_lex.c +1 -1
  163. data/lua-hooks/ext/luajit/src/lj_lex.h +1 -1
  164. data/lua-hooks/ext/luajit/src/lj_lib.c +1 -1
  165. data/lua-hooks/ext/luajit/src/lj_lib.h +1 -1
  166. data/lua-hooks/ext/luajit/src/lj_load.c +1 -1
  167. data/lua-hooks/ext/luajit/src/lj_mcode.c +11 -10
  168. data/lua-hooks/ext/luajit/src/lj_mcode.h +1 -1
  169. data/lua-hooks/ext/luajit/src/lj_meta.c +1 -1
  170. data/lua-hooks/ext/luajit/src/lj_meta.h +1 -1
  171. data/lua-hooks/ext/luajit/src/lj_obj.c +1 -1
  172. data/lua-hooks/ext/luajit/src/lj_obj.h +7 -3
  173. data/lua-hooks/ext/luajit/src/lj_opt_dce.c +1 -1
  174. data/lua-hooks/ext/luajit/src/lj_opt_fold.c +84 -17
  175. data/lua-hooks/ext/luajit/src/lj_opt_loop.c +1 -1
  176. data/lua-hooks/ext/luajit/src/lj_opt_mem.c +3 -3
  177. data/lua-hooks/ext/luajit/src/lj_opt_narrow.c +24 -22
  178. data/lua-hooks/ext/luajit/src/lj_opt_sink.c +11 -6
  179. data/lua-hooks/ext/luajit/src/lj_opt_split.c +11 -2
  180. data/lua-hooks/ext/luajit/src/lj_parse.c +9 -7
  181. data/lua-hooks/ext/luajit/src/lj_parse.h +1 -1
  182. data/lua-hooks/ext/luajit/src/lj_profile.c +1 -1
  183. data/lua-hooks/ext/luajit/src/lj_profile.h +1 -1
  184. data/lua-hooks/ext/luajit/src/lj_record.c +201 -117
  185. data/lua-hooks/ext/luajit/src/lj_record.h +1 -1
  186. data/lua-hooks/ext/luajit/src/lj_snap.c +72 -26
  187. data/lua-hooks/ext/luajit/src/lj_snap.h +1 -1
  188. data/lua-hooks/ext/luajit/src/lj_state.c +6 -6
  189. data/lua-hooks/ext/luajit/src/lj_state.h +2 -2
  190. data/lua-hooks/ext/luajit/src/lj_str.c +1 -1
  191. data/lua-hooks/ext/luajit/src/lj_str.h +1 -1
  192. data/lua-hooks/ext/luajit/src/lj_strfmt.c +7 -3
  193. data/lua-hooks/ext/luajit/src/lj_strfmt.h +1 -1
  194. data/lua-hooks/ext/luajit/src/lj_strfmt_num.c +4 -3
  195. data/lua-hooks/ext/luajit/src/lj_strscan.c +1 -1
  196. data/lua-hooks/ext/luajit/src/lj_strscan.h +1 -1
  197. data/lua-hooks/ext/luajit/src/lj_tab.c +1 -2
  198. data/lua-hooks/ext/luajit/src/lj_tab.h +1 -1
  199. data/lua-hooks/ext/luajit/src/lj_target.h +3 -3
  200. data/lua-hooks/ext/luajit/src/lj_target_arm.h +1 -1
  201. data/lua-hooks/ext/luajit/src/lj_target_arm64.h +239 -7
  202. data/lua-hooks/ext/luajit/src/lj_target_mips.h +111 -22
  203. data/lua-hooks/ext/luajit/src/lj_target_ppc.h +1 -1
  204. data/lua-hooks/ext/luajit/src/lj_target_x86.h +21 -4
  205. data/lua-hooks/ext/luajit/src/lj_trace.c +63 -18
  206. data/lua-hooks/ext/luajit/src/lj_trace.h +2 -1
  207. data/lua-hooks/ext/luajit/src/lj_traceerr.h +1 -1
  208. data/lua-hooks/ext/luajit/src/lj_udata.c +1 -1
  209. data/lua-hooks/ext/luajit/src/lj_udata.h +1 -1
  210. data/lua-hooks/ext/luajit/src/lj_vm.h +5 -1
  211. data/lua-hooks/ext/luajit/src/lj_vmevent.c +1 -1
  212. data/lua-hooks/ext/luajit/src/lj_vmevent.h +1 -1
  213. data/lua-hooks/ext/luajit/src/lj_vmmath.c +1 -1
  214. data/lua-hooks/ext/luajit/src/ljamalg.c +1 -1
  215. data/lua-hooks/ext/luajit/src/lua.h +9 -1
  216. data/lua-hooks/ext/luajit/src/luaconf.h +3 -7
  217. data/lua-hooks/ext/luajit/src/luajit.c +69 -54
  218. data/lua-hooks/ext/luajit/src/luajit.h +4 -4
  219. data/lua-hooks/ext/luajit/src/lualib.h +1 -1
  220. data/lua-hooks/ext/luajit/src/msvcbuild.bat +12 -4
  221. data/lua-hooks/ext/luajit/src/vm_arm.dasc +1 -1
  222. data/lua-hooks/ext/luajit/src/vm_arm64.dasc +255 -32
  223. data/lua-hooks/ext/luajit/src/vm_mips.dasc +26 -23
  224. data/lua-hooks/ext/luajit/src/vm_mips64.dasc +5062 -0
  225. data/lua-hooks/ext/luajit/src/vm_ppc.dasc +1 -1
  226. data/lua-hooks/ext/luajit/src/vm_x64.dasc +24 -25
  227. data/lua-hooks/ext/luajit/src/vm_x86.dasc +77 -4
  228. data/lua-hooks/libluahooks.darwin.a +0 -0
  229. data/lua-hooks/libluahooks.linux.a +0 -0
  230. data/lua-hooks/options.mk +1 -1
  231. metadata +37 -77
  232. data/lua-hooks/ext/all.c +0 -69
  233. data/lua-hooks/ext/libinjection/COPYING +0 -37
  234. data/lua-hooks/ext/libinjection/libinjection.h +0 -65
  235. data/lua-hooks/ext/libinjection/libinjection_html5.c +0 -847
  236. data/lua-hooks/ext/libinjection/libinjection_html5.h +0 -54
  237. data/lua-hooks/ext/libinjection/libinjection_sqli.c +0 -2301
  238. data/lua-hooks/ext/libinjection/libinjection_sqli.h +0 -295
  239. data/lua-hooks/ext/libinjection/libinjection_sqli_data.h +0 -9349
  240. data/lua-hooks/ext/libinjection/libinjection_xss.c +0 -531
  241. data/lua-hooks/ext/libinjection/libinjection_xss.h +0 -21
  242. data/lua-hooks/ext/libinjection/lualib.c +0 -145
  243. data/lua-hooks/ext/libinjection/module.mk +0 -5
  244. data/lua-hooks/ext/lpeg/HISTORY +0 -96
  245. data/lua-hooks/ext/lpeg/lpcap.c +0 -537
  246. data/lua-hooks/ext/lpeg/lpcap.h +0 -56
  247. data/lua-hooks/ext/lpeg/lpcode.c +0 -1014
  248. data/lua-hooks/ext/lpeg/lpcode.h +0 -40
  249. data/lua-hooks/ext/lpeg/lpeg-128.gif +0 -0
  250. data/lua-hooks/ext/lpeg/lpeg.html +0 -1445
  251. data/lua-hooks/ext/lpeg/lpprint.c +0 -244
  252. data/lua-hooks/ext/lpeg/lpprint.h +0 -36
  253. data/lua-hooks/ext/lpeg/lptree.c +0 -1303
  254. data/lua-hooks/ext/lpeg/lptree.h +0 -82
  255. data/lua-hooks/ext/lpeg/lptypes.h +0 -149
  256. data/lua-hooks/ext/lpeg/lpvm.c +0 -364
  257. data/lua-hooks/ext/lpeg/lpvm.h +0 -58
  258. data/lua-hooks/ext/lpeg/makefile +0 -55
  259. data/lua-hooks/ext/lpeg/module.mk +0 -6
  260. data/lua-hooks/ext/lpeg/re.html +0 -498
  261. data/lua-hooks/ext/lua-cmsgpack/.gitignore +0 -13
  262. data/lua-hooks/ext/lua-cmsgpack/CMakeLists.txt +0 -45
  263. data/lua-hooks/ext/lua-cmsgpack/README.md +0 -115
  264. data/lua-hooks/ext/lua-cmsgpack/lua_cmsgpack.c +0 -970
  265. data/lua-hooks/ext/lua-cmsgpack/module.mk +0 -2
  266. data/lua-hooks/ext/lua-cmsgpack/test.lua +0 -570
  267. data/lua-hooks/ext/lua-snapshot/LICENSE +0 -7
  268. data/lua-hooks/ext/lua-snapshot/Makefile +0 -12
  269. data/lua-hooks/ext/lua-snapshot/README.md +0 -18
  270. data/lua-hooks/ext/lua-snapshot/dump.lua +0 -15
  271. data/lua-hooks/ext/lua-snapshot/module.mk +0 -2
  272. data/lua-hooks/ext/lua-snapshot/snapshot.c +0 -462
  273. data/lua-hooks/ext/luautf8/README.md +0 -152
  274. data/lua-hooks/ext/luautf8/lutf8lib.c +0 -1274
  275. data/lua-hooks/ext/luautf8/module.mk +0 -2
  276. data/lua-hooks/ext/luautf8/unidata.h +0 -3064
  277. data/lua-hooks/ext/module.mk +0 -15
  278. data/lua-hooks/ext/modules.h +0 -17
  279. data/lua-hooks/ext/perf/luacpu.c +0 -114
  280. data/lua-hooks/ext/perf/lualoadavg.c +0 -40
  281. data/lua-hooks/ext/perf/luameminfo.c +0 -38
  282. data/lua-hooks/ext/perf/luaoslib.c +0 -203
  283. data/lua-hooks/ext/perf/module.mk +0 -5
  284. data/lua-hooks/ext/sha1/luasha1.c +0 -74
  285. data/lua-hooks/ext/sha1/module.mk +0 -5
  286. data/lua-hooks/ext/sha1/sha1.c +0 -145
  287. data/lua-hooks/ext/sha2/luasha256.c +0 -77
  288. data/lua-hooks/ext/sha2/module.mk +0 -5
  289. data/lua-hooks/ext/sha2/sha256.c +0 -196
  290. data/lua-hooks/ext/sysutils/lua_utils.c +0 -56
  291. data/lua-hooks/ext/sysutils/module.mk +0 -2
@@ -1,6 +1,6 @@
1
1
  /*
2
2
  ** SPLIT: Split 64 bit IR instructions into 32 bit IR instructions.
3
- ** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h
3
+ ** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
4
4
  */
5
5
 
6
6
  #define lj_opt_split_c
@@ -16,6 +16,7 @@
16
16
  #include "lj_jit.h"
17
17
  #include "lj_ircall.h"
18
18
  #include "lj_iropt.h"
19
+ #include "lj_dispatch.h"
19
20
  #include "lj_vm.h"
20
21
 
21
22
  /* SPLIT pass:
@@ -353,6 +354,8 @@ static void split_ir(jit_State *J)
353
354
  ir->prev = ref; /* Identity substitution for loword. */
354
355
  hisubst[ref] = 0;
355
356
  }
357
+ if (irt_is64(ir->t) && ir->o != IR_KNULL)
358
+ ref++;
356
359
  }
357
360
 
358
361
  /* Process old IR instructions. */
@@ -433,7 +436,8 @@ static void split_ir(jit_State *J)
433
436
  nir->o = IR_CONV; /* Pass through loword. */
434
437
  nir->op2 = (IRT_INT << 5) | IRT_INT;
435
438
  hi = split_emit(J, IRT(ir->o == IR_NEG ? IR_BXOR : IR_BAND, IRT_SOFTFP),
436
- hisubst[ir->op1], hisubst[ir->op2]);
439
+ hisubst[ir->op1],
440
+ lj_ir_kint(J, (int32_t)(0x7fffffffu + (ir->o == IR_NEG))));
437
441
  break;
438
442
  case IR_SLOAD:
439
443
  if ((nir->op2 & IRSLOAD_CONVERT)) { /* Convert from int to number. */
@@ -448,6 +452,11 @@ static void split_ir(jit_State *J)
448
452
  case IR_STRTO:
449
453
  hi = split_emit(J, IRT(IR_HIOP, IRT_SOFTFP), nref, nref);
450
454
  break;
455
+ case IR_FLOAD:
456
+ lua_assert(ir->op1 == REF_NIL);
457
+ hi = lj_ir_kint(J, *(int32_t*)((char*)J2GG(J) + ir->op2 + LJ_LE*4));
458
+ nir->op2 += LJ_BE*4;
459
+ break;
451
460
  case IR_XLOAD: {
452
461
  IRIns inslo = *nir; /* Save/undo the emit of the lo XLOAD. */
453
462
  J->cur.nins--;
@@ -1,6 +1,6 @@
1
1
  /*
2
2
  ** Lua parser (source code -> bytecode).
3
- ** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h
3
+ ** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
4
4
  **
5
5
  ** Major portions taken verbatim or adapted from the Lua interpreter.
6
6
  ** Copyright (C) 1994-2008 Lua.org, PUC-Rio. See Copyright Notice in lua.h
@@ -1282,12 +1282,14 @@ static void fscope_end(FuncState *fs)
1282
1282
  MSize idx = gola_new(ls, NAME_BREAK, VSTACK_LABEL, fs->pc);
1283
1283
  ls->vtop = idx; /* Drop break label immediately. */
1284
1284
  gola_resolve(ls, bl, idx);
1285
+ } else { /* Need the fixup step to propagate the breaks. */
1286
+ gola_fixup(ls, bl);
1285
1287
  return;
1286
- } /* else: need the fixup step to propagate the breaks. */
1287
- } else if (!(bl->flags & FSCOPE_GOLA)) {
1288
- return;
1288
+ }
1289
+ }
1290
+ if ((bl->flags & FSCOPE_GOLA)) {
1291
+ gola_fixup(ls, bl);
1289
1292
  }
1290
- gola_fixup(ls, bl);
1291
1293
  }
1292
1294
 
1293
1295
  /* Mark scope as having an upvalue. */
@@ -2177,6 +2179,8 @@ static void assign_adjust(LexState *ls, BCReg nvars, BCReg nexps, ExpDesc *e)
2177
2179
  bcemit_nil(fs, reg, (BCReg)extra);
2178
2180
  }
2179
2181
  }
2182
+ if (nexps > nvars)
2183
+ ls->fs->freereg -= nexps - nvars; /* Drop leftover regs. */
2180
2184
  }
2181
2185
 
2182
2186
  /* Recursively parse assignment statement. */
@@ -2210,8 +2214,6 @@ static void parse_assignment(LexState *ls, LHSVarList *lh, BCReg nvars)
2210
2214
  return;
2211
2215
  }
2212
2216
  assign_adjust(ls, nvars, nexps, &e);
2213
- if (nexps > nvars)
2214
- ls->fs->freereg -= nexps - nvars; /* Drop leftover regs. */
2215
2217
  }
2216
2218
  /* Assign RHS to LHS and recurse downwards. */
2217
2219
  expr_init(&e, VNONRELOC, ls->fs->freereg-1);
@@ -1,6 +1,6 @@
1
1
  /*
2
2
  ** Lua parser (source code -> bytecode).
3
- ** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h
3
+ ** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
4
4
  */
5
5
 
6
6
  #ifndef _LJ_PARSE_H
@@ -1,6 +1,6 @@
1
1
  /*
2
2
  ** Low-overhead profiling.
3
- ** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h
3
+ ** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
4
4
  */
5
5
 
6
6
  #define lj_profile_c
@@ -1,6 +1,6 @@
1
1
  /*
2
2
  ** Low-overhead profiling.
3
- ** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h
3
+ ** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
4
4
  */
5
5
 
6
6
  #ifndef _LJ_PROFILE_H
@@ -1,6 +1,6 @@
1
1
  /*
2
2
  ** Trace recorder (bytecode -> SSA IR).
3
- ** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h
3
+ ** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
4
4
  */
5
5
 
6
6
  #define lj_record_c
@@ -51,7 +51,7 @@ static void rec_check_ir(jit_State *J)
51
51
  {
52
52
  IRRef i, nins = J->cur.nins, nk = J->cur.nk;
53
53
  lua_assert(nk <= REF_BIAS && nins >= REF_BIAS && nins < 65536);
54
- for (i = nins-1; i >= nk; i--) {
54
+ for (i = nk; i < nins; i++) {
55
55
  IRIns *ir = IR(i);
56
56
  uint32_t mode = lj_ir_mode[ir->o];
57
57
  IRRef op1 = ir->op1;
@@ -61,7 +61,10 @@ static void rec_check_ir(jit_State *J)
61
61
  case IRMref: lua_assert(op1 >= nk);
62
62
  lua_assert(i >= REF_BIAS ? op1 < i : op1 > i); break;
63
63
  case IRMlit: break;
64
- case IRMcst: lua_assert(i < REF_BIAS); continue;
64
+ case IRMcst: lua_assert(i < REF_BIAS);
65
+ if (irt_is64(ir->t) && ir->o != IR_KNULL)
66
+ i++;
67
+ continue;
65
68
  }
66
69
  switch (irm_op2(mode)) {
67
70
  case IRMnone: lua_assert(op2 == 0); break;
@@ -84,30 +87,48 @@ static void rec_check_slots(jit_State *J)
84
87
  BCReg s, nslots = J->baseslot + J->maxslot;
85
88
  int32_t depth = 0;
86
89
  cTValue *base = J->L->base - J->baseslot;
87
- lua_assert(J->baseslot >= 1 && J->baseslot < LJ_MAX_JSLOTS);
88
- lua_assert(J->baseslot == 1 || (J->slot[J->baseslot-1] & TREF_FRAME));
90
+ lua_assert(J->baseslot >= 1+LJ_FR2 && J->baseslot < LJ_MAX_JSLOTS);
91
+ lua_assert(J->baseslot == 1+LJ_FR2 || (J->slot[J->baseslot-1] & TREF_FRAME));
89
92
  lua_assert(nslots < LJ_MAX_JSLOTS);
90
93
  for (s = 0; s < nslots; s++) {
91
94
  TRef tr = J->slot[s];
92
95
  if (tr) {
93
96
  cTValue *tv = &base[s];
94
97
  IRRef ref = tref_ref(tr);
95
- IRIns *ir;
96
- lua_assert(ref >= J->cur.nk && ref < J->cur.nins);
97
- ir = IR(ref);
98
- lua_assert(irt_t(ir->t) == tref_t(tr));
98
+ IRIns *ir = NULL; /* Silence compiler. */
99
+ if (!LJ_FR2 || ref || !(tr & (TREF_FRAME | TREF_CONT))) {
100
+ lua_assert(ref >= J->cur.nk && ref < J->cur.nins);
101
+ ir = IR(ref);
102
+ lua_assert(irt_t(ir->t) == tref_t(tr));
103
+ }
99
104
  if (s == 0) {
100
105
  lua_assert(tref_isfunc(tr));
106
+ #if LJ_FR2
107
+ } else if (s == 1) {
108
+ lua_assert((tr & ~TREF_FRAME) == 0);
109
+ #endif
101
110
  } else if ((tr & TREF_FRAME)) {
102
111
  GCfunc *fn = gco2func(frame_gc(tv));
103
112
  BCReg delta = (BCReg)(tv - frame_prev(tv));
113
+ #if LJ_FR2
114
+ if (ref)
115
+ lua_assert(ir_knum(ir)->u64 == tv->u64);
116
+ tr = J->slot[s-1];
117
+ ir = IR(tref_ref(tr));
118
+ #endif
104
119
  lua_assert(tref_isfunc(tr));
105
120
  if (tref_isk(tr)) lua_assert(fn == ir_kfunc(ir));
106
- lua_assert(s > delta ? (J->slot[s-delta] & TREF_FRAME) : (s == delta));
121
+ lua_assert(s > delta + LJ_FR2 ? (J->slot[s-delta] & TREF_FRAME)
122
+ : (s == delta + LJ_FR2));
107
123
  depth++;
108
124
  } else if ((tr & TREF_CONT)) {
125
+ #if LJ_FR2
126
+ if (ref)
127
+ lua_assert(ir_knum(ir)->u64 == tv->u64);
128
+ #else
109
129
  lua_assert(ir_kptr(ir) == gcrefp(tv->gcr, void));
110
- lua_assert((J->slot[s+1] & TREF_FRAME));
130
+ #endif
131
+ lua_assert((J->slot[s+1+LJ_FR2] & TREF_FRAME));
111
132
  depth++;
112
133
  } else {
113
134
  if (tvisnumber(tv))
@@ -159,10 +180,10 @@ static TRef sload(jit_State *J, int32_t slot)
159
180
  /* Get TRef for current function. */
160
181
  static TRef getcurrf(jit_State *J)
161
182
  {
162
- if (J->base[-1])
163
- return J->base[-1];
164
- lua_assert(J->baseslot == 1);
165
- return sloadt(J, -1, IRT_FUNC, IRSLOAD_READONLY);
183
+ if (J->base[-1-LJ_FR2])
184
+ return J->base[-1-LJ_FR2];
185
+ lua_assert(J->baseslot == 1+LJ_FR2);
186
+ return sloadt(J, -1-LJ_FR2, IRT_FUNC, IRSLOAD_READONLY);
166
187
  }
167
188
 
168
189
  /* Compare for raw object equality.
@@ -506,7 +527,6 @@ static LoopEvent rec_for(jit_State *J, const BCIns *fori, int isforl)
506
527
  static LoopEvent rec_iterl(jit_State *J, const BCIns iterins)
507
528
  {
508
529
  BCReg ra = bc_a(iterins);
509
- lua_assert(!LJ_FR2); /* TODO_FR2: handle different frame setup. */
510
530
  if (!tref_isnil(getslot(J, ra))) { /* Looping back? */
511
531
  J->base[ra-1] = J->base[ra]; /* Copy result of ITERC to control var. */
512
532
  J->maxslot = ra-1+bc_b(J->pc[-1]);
@@ -643,8 +663,8 @@ static TRef rec_call_specialize(jit_State *J, GCfunc *fn, TRef tr)
643
663
  GCproto *pt = funcproto(fn);
644
664
  /* Too many closures created? Probably not a monomorphic function. */
645
665
  if (pt->flags >= PROTO_CLC_POLY) { /* Specialize to prototype instead. */
646
- TRef trpt = emitir(IRT(IR_FLOAD, IRT_P32), tr, IRFL_FUNC_PC);
647
- emitir(IRTG(IR_EQ, IRT_P32), trpt, lj_ir_kptr(J, proto_bc(pt)));
666
+ TRef trpt = emitir(IRT(IR_FLOAD, IRT_PGC), tr, IRFL_FUNC_PC);
667
+ emitir(IRTG(IR_EQ, IRT_PGC), trpt, lj_ir_kptr(J, proto_bc(pt)));
648
668
  (void)lj_ir_kgc(J, obj2gco(pt), IRT_PROTO); /* Prevent GC of proto. */
649
669
  return tr;
650
670
  }
@@ -675,22 +695,31 @@ static void rec_call_setup(jit_State *J, BCReg func, ptrdiff_t nargs)
675
695
  {
676
696
  RecordIndex ix;
677
697
  TValue *functv = &J->L->base[func];
678
- TRef *fbase = &J->base[func];
698
+ TRef kfunc, *fbase = &J->base[func];
679
699
  ptrdiff_t i;
680
- lua_assert(!LJ_FR2); /* TODO_FR2: handle different frame setup. */
681
- for (i = 0; i <= nargs; i++)
682
- (void)getslot(J, func+i); /* Ensure func and all args have a reference. */
700
+ (void)getslot(J, func); /* Ensure func has a reference. */
701
+ for (i = 1; i <= nargs; i++)
702
+ (void)getslot(J, func+LJ_FR2+i); /* Ensure all args have a reference. */
683
703
  if (!tref_isfunc(fbase[0])) { /* Resolve __call metamethod. */
684
704
  ix.tab = fbase[0];
685
705
  copyTV(J->L, &ix.tabv, functv);
686
706
  if (!lj_record_mm_lookup(J, &ix, MM_call) || !tref_isfunc(ix.mobj))
687
707
  lj_trace_err(J, LJ_TRERR_NOMM);
688
- for (i = ++nargs; i > 0; i--) /* Shift arguments up. */
689
- fbase[i] = fbase[i-1];
708
+ for (i = ++nargs; i > LJ_FR2; i--) /* Shift arguments up. */
709
+ fbase[i+LJ_FR2] = fbase[i+LJ_FR2-1];
710
+ #if LJ_FR2
711
+ fbase[2] = fbase[0];
712
+ #endif
690
713
  fbase[0] = ix.mobj; /* Replace function. */
691
714
  functv = &ix.mobjv;
692
715
  }
693
- fbase[0] = TREF_FRAME | rec_call_specialize(J, funcV(functv), fbase[0]);
716
+ kfunc = rec_call_specialize(J, funcV(functv), fbase[0]);
717
+ #if LJ_FR2
718
+ fbase[0] = kfunc;
719
+ fbase[1] = TREF_FRAME;
720
+ #else
721
+ fbase[0] = kfunc | TREF_FRAME;
722
+ #endif
694
723
  J->maxslot = (BCReg)nargs;
695
724
  }
696
725
 
@@ -700,8 +729,8 @@ void lj_record_call(jit_State *J, BCReg func, ptrdiff_t nargs)
700
729
  rec_call_setup(J, func, nargs);
701
730
  /* Bump frame. */
702
731
  J->framedepth++;
703
- J->base += func+1;
704
- J->baseslot += func+1;
732
+ J->base += func+1+LJ_FR2;
733
+ J->baseslot += func+1+LJ_FR2;
705
734
  }
706
735
 
707
736
  /* Record tail call. */
@@ -717,7 +746,9 @@ void lj_record_tailcall(jit_State *J, BCReg func, ptrdiff_t nargs)
717
746
  func += cbase;
718
747
  }
719
748
  /* Move func + args down. */
720
- memmove(&J->base[-1], &J->base[func], sizeof(TRef)*(J->maxslot+1));
749
+ if (LJ_FR2 && J->baseslot == 2)
750
+ J->base[func+1] = TREF_FRAME;
751
+ memmove(&J->base[-1-LJ_FR2], &J->base[func], sizeof(TRef)*(J->maxslot+1+LJ_FR2));
721
752
  /* Note: the new TREF_FRAME is now at J->base[-1] (even for slot #0). */
722
753
  /* Tailcalls can form a loop, so count towards the loop unroll limit. */
723
754
  if (++J->tailcalled > J->loopunroll)
@@ -758,9 +789,9 @@ void lj_record_ret(jit_State *J, BCReg rbase, ptrdiff_t gotresults)
758
789
  (void)getslot(J, rbase+i); /* Ensure all results have a reference. */
759
790
  while (frame_ispcall(frame)) { /* Immediately resolve pcall() returns. */
760
791
  BCReg cbase = (BCReg)frame_delta(frame);
761
- if (--J->framedepth < 0)
792
+ if (--J->framedepth <= 0)
762
793
  lj_trace_err(J, LJ_TRERR_NYIRETL);
763
- lua_assert(J->baseslot > 1);
794
+ lua_assert(J->baseslot > 1+LJ_FR2);
764
795
  gotresults++;
765
796
  rbase += cbase;
766
797
  J->baseslot -= (BCReg)cbase;
@@ -784,7 +815,7 @@ void lj_record_ret(jit_State *J, BCReg rbase, ptrdiff_t gotresults)
784
815
  BCReg cbase = (BCReg)frame_delta(frame);
785
816
  if (--J->framedepth < 0) /* NYI: return of vararg func to lower frame. */
786
817
  lj_trace_err(J, LJ_TRERR_NYIRETL);
787
- lua_assert(J->baseslot > 1);
818
+ lua_assert(J->baseslot > 1+LJ_FR2);
788
819
  rbase += cbase;
789
820
  J->baseslot -= (BCReg)cbase;
790
821
  J->base -= cbase;
@@ -794,8 +825,7 @@ void lj_record_ret(jit_State *J, BCReg rbase, ptrdiff_t gotresults)
794
825
  BCIns callins = *(frame_pc(frame)-1);
795
826
  ptrdiff_t nresults = bc_b(callins) ? (ptrdiff_t)bc_b(callins)-1 :gotresults;
796
827
  BCReg cbase = bc_a(callins);
797
- GCproto *pt = funcproto(frame_func(frame - (cbase+1-LJ_FR2)));
798
- lua_assert(!LJ_FR2); /* TODO_FR2: handle different frame teardown. */
828
+ GCproto *pt = funcproto(frame_func(frame - (cbase+1+LJ_FR2)));
799
829
  if ((pt->flags & PROTO_NOJIT))
800
830
  lj_trace_err(J, LJ_TRERR_CJITOFF);
801
831
  if (J->framedepth == 0 && J->pt && frame == J->L->base - 1) {
@@ -808,13 +838,13 @@ void lj_record_ret(jit_State *J, BCReg rbase, ptrdiff_t gotresults)
808
838
  lj_snap_add(J);
809
839
  }
810
840
  for (i = 0; i < nresults; i++) /* Adjust results. */
811
- J->base[i-1] = i < gotresults ? J->base[rbase+i] : TREF_NIL;
841
+ J->base[i-1-LJ_FR2] = i < gotresults ? J->base[rbase+i] : TREF_NIL;
812
842
  J->maxslot = cbase+(BCReg)nresults;
813
843
  if (J->framedepth > 0) { /* Return to a frame that is part of the trace. */
814
844
  J->framedepth--;
815
- lua_assert(J->baseslot > cbase+1);
816
- J->baseslot -= cbase+1;
817
- J->base -= cbase+1;
845
+ lua_assert(J->baseslot > cbase+1+LJ_FR2);
846
+ J->baseslot -= cbase+1+LJ_FR2;
847
+ J->base -= cbase+1+LJ_FR2;
818
848
  } else if (J->parent == 0 && J->exitno == 0 &&
819
849
  !bc_isret(bc_op(J->cur.startins))) {
820
850
  /* Return to lower frame would leave the loop in a root trace. */
@@ -824,13 +854,13 @@ void lj_record_ret(jit_State *J, BCReg rbase, ptrdiff_t gotresults)
824
854
  } else { /* Return to lower frame. Guard for the target we return to. */
825
855
  TRef trpt = lj_ir_kgc(J, obj2gco(pt), IRT_PROTO);
826
856
  TRef trpc = lj_ir_kptr(J, (void *)frame_pc(frame));
827
- emitir(IRTG(IR_RETF, IRT_P32), trpt, trpc);
857
+ emitir(IRTG(IR_RETF, IRT_PGC), trpt, trpc);
828
858
  J->retdepth++;
829
859
  J->needsnap = 1;
830
- lua_assert(J->baseslot == 1);
860
+ lua_assert(J->baseslot == 1+LJ_FR2);
831
861
  /* Shift result slots up and clear the slots of the new frame below. */
832
- memmove(J->base + cbase, J->base-1, sizeof(TRef)*nresults);
833
- memset(J->base-1, 0, sizeof(TRef)*(cbase+1));
862
+ memmove(J->base + cbase, J->base-1-LJ_FR2, sizeof(TRef)*nresults);
863
+ memset(J->base-1-LJ_FR2, 0, sizeof(TRef)*(cbase+1+LJ_FR2));
834
864
  }
835
865
  } else if (frame_iscont(frame)) { /* Return to continuation frame. */
836
866
  ASMFunction cont = frame_contf(frame);
@@ -839,32 +869,39 @@ void lj_record_ret(jit_State *J, BCReg rbase, ptrdiff_t gotresults)
839
869
  lj_trace_err(J, LJ_TRERR_NYIRETL);
840
870
  J->baseslot -= (BCReg)cbase;
841
871
  J->base -= cbase;
842
- J->maxslot = cbase-2;
872
+ J->maxslot = cbase-(2<<LJ_FR2);
843
873
  if (cont == lj_cont_ra) {
844
874
  /* Copy result to destination slot. */
845
875
  BCReg dst = bc_a(*(frame_contpc(frame)-1));
846
876
  J->base[dst] = gotresults ? J->base[cbase+rbase] : TREF_NIL;
847
- if (dst >= J->maxslot) J->maxslot = dst+1;
877
+ if (dst >= J->maxslot) {
878
+ J->maxslot = dst+1;
879
+ }
848
880
  } else if (cont == lj_cont_nop) {
849
881
  /* Nothing to do here. */
850
882
  } else if (cont == lj_cont_cat) {
851
883
  BCReg bslot = bc_b(*(frame_contpc(frame)-1));
852
884
  TRef tr = gotresults ? J->base[cbase+rbase] : TREF_NIL;
853
- if (bslot != cbase-2) { /* Concatenate the remainder. */
885
+ if (bslot != J->maxslot) { /* Concatenate the remainder. */
854
886
  TValue *b = J->L->base, save; /* Simulate lower frame and result. */
855
- J->base[cbase-2] = tr;
856
- copyTV(J->L, &save, b-2);
857
- if (gotresults) copyTV(J->L, b-2, b+rbase); else setnilV(b-2);
887
+ J->base[J->maxslot] = tr;
888
+ copyTV(J->L, &save, b-(2<<LJ_FR2));
889
+ if (gotresults)
890
+ copyTV(J->L, b-(2<<LJ_FR2), b+rbase);
891
+ else
892
+ setnilV(b-(2<<LJ_FR2));
858
893
  J->L->base = b - cbase;
859
- tr = rec_cat(J, bslot, cbase-2);
894
+ tr = rec_cat(J, bslot, cbase-(2<<LJ_FR2));
860
895
  b = J->L->base + cbase; /* Undo. */
861
896
  J->L->base = b;
862
- copyTV(J->L, b-2, &save);
897
+ copyTV(J->L, b-(2<<LJ_FR2), &save);
863
898
  }
864
899
  if (tr) { /* Store final result. */
865
900
  BCReg dst = bc_a(*(frame_contpc(frame)-1));
866
901
  J->base[dst] = tr;
867
- if (dst >= J->maxslot) J->maxslot = dst+1;
902
+ if (dst >= J->maxslot) {
903
+ J->maxslot = dst+1;
904
+ }
868
905
  } /* Otherwise continue with another __concat call. */
869
906
  } else {
870
907
  /* Result type already specialized. */
@@ -873,7 +910,7 @@ void lj_record_ret(jit_State *J, BCReg rbase, ptrdiff_t gotresults)
873
910
  } else {
874
911
  lj_trace_err(J, LJ_TRERR_NYIRETL); /* NYI: handle return to C frame. */
875
912
  }
876
- lua_assert(J->baseslot >= 1);
913
+ lua_assert(J->baseslot >= 1+LJ_FR2);
877
914
  }
878
915
 
879
916
  /* -- Metamethod handling ------------------------------------------------- */
@@ -882,16 +919,16 @@ void lj_record_ret(jit_State *J, BCReg rbase, ptrdiff_t gotresults)
882
919
  static BCReg rec_mm_prep(jit_State *J, ASMFunction cont)
883
920
  {
884
921
  BCReg s, top = cont == lj_cont_cat ? J->maxslot : curr_proto(J->L)->framesize;
885
- #if LJ_64
886
- TRef trcont = lj_ir_kptr(J, (void *)((int64_t)cont-(int64_t)lj_vm_asm_begin));
922
+ #if LJ_FR2
923
+ J->base[top] = lj_ir_k64(J, IR_KNUM, u64ptr(contptr(cont)));
924
+ J->base[top+1] = TREF_CONT;
887
925
  #else
888
- TRef trcont = lj_ir_kptr(J, (void *)cont);
926
+ J->base[top] = lj_ir_kptr(J, contptr(cont)) | TREF_CONT;
889
927
  #endif
890
- J->base[top] = trcont | TREF_CONT;
891
928
  J->framedepth++;
892
929
  for (s = J->maxslot; s < top; s++)
893
930
  J->base[s] = 0; /* Clear frame gap to avoid resurrecting previous refs. */
894
- return top+1;
931
+ return top+1+LJ_FR2;
895
932
  }
896
933
 
897
934
  /* Record metamethod lookup. */
@@ -910,7 +947,7 @@ int lj_record_mm_lookup(jit_State *J, RecordIndex *ix, MMS mm)
910
947
  cTValue *mo;
911
948
  if (LJ_HASFFI && udtype == UDTYPE_FFI_CLIB) {
912
949
  /* Specialize to the C library namespace object. */
913
- emitir(IRTG(IR_EQ, IRT_P32), ix->tab, lj_ir_kptr(J, udataV(&ix->tabv)));
950
+ emitir(IRTG(IR_EQ, IRT_PGC), ix->tab, lj_ir_kptr(J, udataV(&ix->tabv)));
914
951
  } else {
915
952
  /* Specialize to the type of userdata. */
916
953
  TRef tr = emitir(IRT(IR_FLOAD, IRT_U8), ix->tab, IRFL_UDATA_UDTYPE);
@@ -939,7 +976,13 @@ int lj_record_mm_lookup(jit_State *J, RecordIndex *ix, MMS mm)
939
976
  }
940
977
  /* The cdata metatable is treated as immutable. */
941
978
  if (LJ_HASFFI && tref_iscdata(ix->tab)) goto immutable_mt;
979
+ #if LJ_GC64
980
+ /* TODO: fix ARM32 asm_fload(), so we can use this for all archs. */
981
+ ix->mt = mix.tab = lj_ir_ggfload(J, IRT_TAB,
982
+ GG_OFS(g.gcroot[GCROOT_BASEMT+itypemap(&ix->tabv)]));
983
+ #else
942
984
  ix->mt = mix.tab = lj_ir_ktab(J, mt);
985
+ #endif
943
986
  goto nocheck;
944
987
  }
945
988
  ix->mt = mt ? mix.tab : TREF_NIL;
@@ -969,9 +1012,9 @@ static TRef rec_mm_arith(jit_State *J, RecordIndex *ix, MMS mm)
969
1012
  BCReg func = rec_mm_prep(J, mm == MM_concat ? lj_cont_cat : lj_cont_ra);
970
1013
  TRef *base = J->base + func;
971
1014
  TValue *basev = J->L->base + func;
972
- base[1] = ix->tab; base[2] = ix->key;
973
- copyTV(J->L, basev+1, &ix->tabv);
974
- copyTV(J->L, basev+2, &ix->keyv);
1015
+ base[1+LJ_FR2] = ix->tab; base[2+LJ_FR2] = ix->key;
1016
+ copyTV(J->L, basev+1+LJ_FR2, &ix->tabv);
1017
+ copyTV(J->L, basev+2+LJ_FR2, &ix->keyv);
975
1018
  if (!lj_record_mm_lookup(J, ix, mm)) { /* Lookup mm on 1st operand. */
976
1019
  if (mm != MM_unm) {
977
1020
  ix->tab = ix->key;
@@ -982,8 +1025,10 @@ static TRef rec_mm_arith(jit_State *J, RecordIndex *ix, MMS mm)
982
1025
  lj_trace_err(J, LJ_TRERR_NOMM);
983
1026
  }
984
1027
  ok:
985
- lua_assert(!LJ_FR2); /* TODO_FR2: handle different frame setup. */
986
1028
  base[0] = ix->mobj;
1029
+ #if LJ_FR2
1030
+ base[1] = 0;
1031
+ #endif
987
1032
  copyTV(J->L, basev+0, &ix->mobjv);
988
1033
  lj_record_call(J, func, 2);
989
1034
  return 0; /* No result yet. */
@@ -999,8 +1044,9 @@ static TRef rec_mm_len(jit_State *J, TRef tr, TValue *tv)
999
1044
  BCReg func = rec_mm_prep(J, lj_cont_ra);
1000
1045
  TRef *base = J->base + func;
1001
1046
  TValue *basev = J->L->base + func;
1002
- lua_assert(!LJ_FR2); /* TODO_FR2: handle different frame setup. */
1003
1047
  base[0] = ix.mobj; copyTV(J->L, basev+0, &ix.mobjv);
1048
+ base += LJ_FR2;
1049
+ basev += LJ_FR2;
1004
1050
  base[1] = tr; copyTV(J->L, basev+1, tv);
1005
1051
  #if LJ_52
1006
1052
  base[2] = tr; copyTV(J->L, basev+2, tv);
@@ -1020,11 +1066,10 @@ static TRef rec_mm_len(jit_State *J, TRef tr, TValue *tv)
1020
1066
  static void rec_mm_callcomp(jit_State *J, RecordIndex *ix, int op)
1021
1067
  {
1022
1068
  BCReg func = rec_mm_prep(J, (op&1) ? lj_cont_condf : lj_cont_condt);
1023
- TRef *base = J->base + func;
1024
- TValue *tv = J->L->base + func;
1025
- lua_assert(!LJ_FR2); /* TODO_FR2: handle different frame setup. */
1026
- base[0] = ix->mobj; base[1] = ix->val; base[2] = ix->key;
1027
- copyTV(J->L, tv+0, &ix->mobjv);
1069
+ TRef *base = J->base + func + LJ_FR2;
1070
+ TValue *tv = J->L->base + func + LJ_FR2;
1071
+ base[-LJ_FR2] = ix->mobj; base[1] = ix->val; base[2] = ix->key;
1072
+ copyTV(J->L, tv-LJ_FR2, &ix->mobjv);
1028
1073
  copyTV(J->L, tv+1, &ix->valv);
1029
1074
  copyTV(J->L, tv+2, &ix->keyv);
1030
1075
  lj_record_call(J, func, 2);
@@ -1257,8 +1302,8 @@ static TRef rec_idx_key(jit_State *J, RecordIndex *ix, IRRef *rbref,
1257
1302
  if ((MSize)k < t->asize) { /* Currently an array key? */
1258
1303
  TRef arrayref;
1259
1304
  rec_idx_abc(J, asizeref, ikey, t->asize);
1260
- arrayref = emitir(IRT(IR_FLOAD, IRT_P32), ix->tab, IRFL_TAB_ARRAY);
1261
- return emitir(IRT(IR_AREF, IRT_P32), arrayref, ikey);
1305
+ arrayref = emitir(IRT(IR_FLOAD, IRT_PGC), ix->tab, IRFL_TAB_ARRAY);
1306
+ return emitir(IRT(IR_AREF, IRT_PGC), arrayref, ikey);
1262
1307
  } else { /* Currently not in array (may be an array extension)? */
1263
1308
  emitir(IRTGI(IR_ULE), asizeref, ikey); /* Inv. bounds check. */
1264
1309
  if (k == 0 && tref_isk(key))
@@ -1298,13 +1343,13 @@ static TRef rec_idx_key(jit_State *J, RecordIndex *ix, IRRef *rbref,
1298
1343
  *rbguard = J->guardemit;
1299
1344
  hm = emitir(IRTI(IR_FLOAD), ix->tab, IRFL_TAB_HMASK);
1300
1345
  emitir(IRTGI(IR_EQ), hm, lj_ir_kint(J, (int32_t)t->hmask));
1301
- node = emitir(IRT(IR_FLOAD, IRT_P32), ix->tab, IRFL_TAB_NODE);
1346
+ node = emitir(IRT(IR_FLOAD, IRT_PGC), ix->tab, IRFL_TAB_NODE);
1302
1347
  kslot = lj_ir_kslot(J, key, hslot / sizeof(Node));
1303
- return emitir(IRTG(IR_HREFK, IRT_P32), node, kslot);
1348
+ return emitir(IRTG(IR_HREFK, IRT_PGC), node, kslot);
1304
1349
  }
1305
1350
  }
1306
1351
  /* Fall back to a regular hash lookup. */
1307
- return emitir(IRT(IR_HREF, IRT_P32), ix->tab, key);
1352
+ return emitir(IRT(IR_HREF, IRT_PGC), ix->tab, key);
1308
1353
  }
1309
1354
 
1310
1355
  /* Determine whether a key is NOT one of the fast metamethod names. */
@@ -1341,11 +1386,10 @@ TRef lj_record_idx(jit_State *J, RecordIndex *ix)
1341
1386
  handlemm:
1342
1387
  if (tref_isfunc(ix->mobj)) { /* Handle metamethod call. */
1343
1388
  BCReg func = rec_mm_prep(J, ix->val ? lj_cont_nop : lj_cont_ra);
1344
- TRef *base = J->base + func;
1345
- TValue *tv = J->L->base + func;
1346
- lua_assert(!LJ_FR2); /* TODO_FR2: handle different frame setup. */
1347
- base[0] = ix->mobj; base[1] = ix->tab; base[2] = ix->key;
1348
- setfuncV(J->L, tv+0, funcV(&ix->mobjv));
1389
+ TRef *base = J->base + func + LJ_FR2;
1390
+ TValue *tv = J->L->base + func + LJ_FR2;
1391
+ base[-LJ_FR2] = ix->mobj; base[1] = ix->tab; base[2] = ix->key;
1392
+ setfuncV(J->L, tv-LJ_FR2, funcV(&ix->mobjv));
1349
1393
  copyTV(J->L, tv+1, &ix->tabv);
1350
1394
  copyTV(J->L, tv+2, &ix->keyv);
1351
1395
  if (ix->val) {
@@ -1387,7 +1431,7 @@ TRef lj_record_idx(jit_State *J, RecordIndex *ix)
1387
1431
  IRType t = itype2irt(oldv);
1388
1432
  TRef res;
1389
1433
  if (oldv == niltvg(J2G(J))) {
1390
- emitir(IRTG(IR_EQ, IRT_P32), xref, lj_ir_kkptr(J, niltvg(J2G(J))));
1434
+ emitir(IRTG(IR_EQ, IRT_PGC), xref, lj_ir_kkptr(J, niltvg(J2G(J))));
1391
1435
  res = TREF_NIL;
1392
1436
  } else {
1393
1437
  res = emitir(IRTG(loadop, t), xref, 0);
@@ -1417,7 +1461,7 @@ TRef lj_record_idx(jit_State *J, RecordIndex *ix)
1417
1461
  if (hasmm)
1418
1462
  emitir(IRTG(loadop, IRT_NIL), xref, 0); /* Guard for nil value. */
1419
1463
  else if (xrefop == IR_HREF)
1420
- emitir(IRTG(oldv == niltvg(J2G(J)) ? IR_EQ : IR_NE, IRT_P32),
1464
+ emitir(IRTG(oldv == niltvg(J2G(J)) ? IR_EQ : IR_NE, IRT_PGC),
1421
1465
  xref, lj_ir_kkptr(J, niltvg(J2G(J))));
1422
1466
  if (ix->idxchain && lj_record_mm_lookup(J, ix, MM_newindex)) {
1423
1467
  lua_assert(hasmm);
@@ -1428,7 +1472,7 @@ TRef lj_record_idx(jit_State *J, RecordIndex *ix)
1428
1472
  TRef key = ix->key;
1429
1473
  if (tref_isinteger(key)) /* NEWREF needs a TValue as a key. */
1430
1474
  key = emitir(IRTN(IR_CONV), key, IRCONV_NUM_INT);
1431
- xref = emitir(IRT(IR_NEWREF, IRT_P32), ix->tab, key);
1475
+ xref = emitir(IRT(IR_NEWREF, IRT_PGC), ix->tab, key);
1432
1476
  keybarrier = 0; /* NEWREF already takes care of the key barrier. */
1433
1477
  #ifdef LUAJIT_ENABLE_TABLE_BUMP
1434
1478
  if ((J->flags & JIT_F_OPT_SINK)) /* Avoid a separate flag. */
@@ -1438,7 +1482,7 @@ TRef lj_record_idx(jit_State *J, RecordIndex *ix)
1438
1482
  } else if (!lj_opt_fwd_wasnonnil(J, loadop, tref_ref(xref))) {
1439
1483
  /* Cannot derive that the previous value was non-nil, must do checks. */
1440
1484
  if (xrefop == IR_HREF) /* Guard against store to niltv. */
1441
- emitir(IRTG(IR_NE, IRT_P32), xref, lj_ir_kkptr(J, niltvg(J2G(J))));
1485
+ emitir(IRTG(IR_NE, IRT_PGC), xref, lj_ir_kkptr(J, niltvg(J2G(J))));
1442
1486
  if (ix->idxchain) { /* Metamethod lookup required? */
1443
1487
  /* A check for NULL metatable is cheaper (hoistable) than a load. */
1444
1488
  if (!mt) {
@@ -1460,7 +1504,7 @@ TRef lj_record_idx(jit_State *J, RecordIndex *ix)
1460
1504
  emitir(IRT(IR_TBAR, IRT_NIL), ix->tab, 0);
1461
1505
  /* Invalidate neg. metamethod cache for stores with certain string keys. */
1462
1506
  if (!nommstr(J, ix->key)) {
1463
- TRef fref = emitir(IRT(IR_FREF, IRT_P32), ix->tab, IRFL_TAB_NOMM);
1507
+ TRef fref = emitir(IRT(IR_FREF, IRT_PGC), ix->tab, IRFL_TAB_NOMM);
1464
1508
  emitir(IRT(IR_FSTORE, IRT_U8), fref, lj_ir_kint(J, 0));
1465
1509
  }
1466
1510
  J->needsnap = 1;
@@ -1535,7 +1579,11 @@ static TRef rec_upvalue(jit_State *J, uint32_t uv, TRef val)
1535
1579
  goto noconstify;
1536
1580
  kfunc = lj_ir_kfunc(J, J->fn);
1537
1581
  emitir(IRTG(IR_EQ, IRT_FUNC), fn, kfunc);
1538
- J->base[-1] = TREF_FRAME | kfunc;
1582
+ #if LJ_FR2
1583
+ J->base[-2] = kfunc;
1584
+ #else
1585
+ J->base[-1] = kfunc | TREF_FRAME;
1586
+ #endif
1539
1587
  fn = kfunc;
1540
1588
  }
1541
1589
  tr = lj_record_constify(J, uvval(uvp));
@@ -1546,13 +1594,17 @@ noconstify:
1546
1594
  /* Note: this effectively limits LJ_MAX_UPVAL to 127. */
1547
1595
  uv = (uv << 8) | (hashrot(uvp->dhash, uvp->dhash + HASH_BIAS) & 0xff);
1548
1596
  if (!uvp->closed) {
1597
+ uref = tref_ref(emitir(IRTG(IR_UREFO, IRT_PGC), fn, uv));
1549
1598
  /* In current stack? */
1550
1599
  if (uvval(uvp) >= tvref(J->L->stack) &&
1551
1600
  uvval(uvp) < tvref(J->L->maxstack)) {
1552
1601
  int32_t slot = (int32_t)(uvval(uvp) - (J->L->base - J->baseslot));
1553
1602
  if (slot >= 0) { /* Aliases an SSA slot? */
1603
+ emitir(IRTG(IR_EQ, IRT_PGC),
1604
+ REF_BASE,
1605
+ emitir(IRT(IR_ADD, IRT_PGC), uref,
1606
+ lj_ir_kint(J, (slot - 1 - LJ_FR2) * -8)));
1554
1607
  slot -= (int32_t)J->baseslot; /* Note: slot number may be negative! */
1555
- /* NYI: add IR to guard that it's still aliasing the same slot. */
1556
1608
  if (val == 0) {
1557
1609
  return getslot(J, slot);
1558
1610
  } else {
@@ -1562,10 +1614,12 @@ noconstify:
1562
1614
  }
1563
1615
  }
1564
1616
  }
1565
- uref = tref_ref(emitir(IRTG(IR_UREFO, IRT_P32), fn, uv));
1617
+ emitir(IRTG(IR_UGT, IRT_PGC),
1618
+ emitir(IRT(IR_SUB, IRT_PGC), uref, REF_BASE),
1619
+ lj_ir_kint(J, (J->baseslot + J->maxslot) * 8));
1566
1620
  } else {
1567
1621
  needbarrier = 1;
1568
- uref = tref_ref(emitir(IRTG(IR_UREFC, IRT_P32), fn, uv));
1622
+ uref = tref_ref(emitir(IRTG(IR_UREFC, IRT_PGC), fn, uv));
1569
1623
  }
1570
1624
  if (val == 0) { /* Upvalue load */
1571
1625
  IRType t = itype2irt(uvval(uvp));
@@ -1640,11 +1694,14 @@ static void rec_func_setup(jit_State *J)
1640
1694
  static void rec_func_vararg(jit_State *J)
1641
1695
  {
1642
1696
  GCproto *pt = J->pt;
1643
- BCReg s, fixargs, vframe = J->maxslot+1;
1697
+ BCReg s, fixargs, vframe = J->maxslot+1+LJ_FR2;
1644
1698
  lua_assert((pt->flags & PROTO_VARARG));
1645
1699
  if (J->baseslot + vframe + pt->framesize >= LJ_MAX_JSLOTS)
1646
1700
  lj_trace_err(J, LJ_TRERR_STACKOV);
1647
- J->base[vframe-1] = J->base[-1]; /* Copy function up. */
1701
+ J->base[vframe-1-LJ_FR2] = J->base[-1-LJ_FR2]; /* Copy function up. */
1702
+ #if LJ_FR2
1703
+ J->base[vframe-1] = TREF_FRAME;
1704
+ #endif
1648
1705
  /* Copy fixarg slots up and set their original slots to nil. */
1649
1706
  fixargs = pt->numparams < J->maxslot ? pt->numparams : J->maxslot;
1650
1707
  for (s = 0; s < fixargs; s++) {
@@ -1693,8 +1750,11 @@ static int select_detect(jit_State *J)
1693
1750
  BCIns ins = J->pc[1];
1694
1751
  if (bc_op(ins) == BC_CALLM && bc_b(ins) == 2 && bc_c(ins) == 1) {
1695
1752
  cTValue *func = &J->L->base[bc_a(ins)];
1696
- if (tvisfunc(func) && funcV(func)->c.ffid == FF_select)
1753
+ if (tvisfunc(func) && funcV(func)->c.ffid == FF_select) {
1754
+ TRef kfunc = lj_ir_kfunc(J, funcV(func));
1755
+ emitir(IRTG(IR_EQ, IRT_FUNC), getslot(J, bc_a(ins)), kfunc);
1697
1756
  return 1;
1757
+ }
1698
1758
  }
1699
1759
  return 0;
1700
1760
  }
@@ -1703,8 +1763,10 @@ static int select_detect(jit_State *J)
1703
1763
  static void rec_varg(jit_State *J, BCReg dst, ptrdiff_t nresults)
1704
1764
  {
1705
1765
  int32_t numparams = J->pt->numparams;
1706
- ptrdiff_t nvararg = frame_delta(J->L->base-1) - numparams - 1;
1766
+ ptrdiff_t nvararg = frame_delta(J->L->base-1) - numparams - 1 - LJ_FR2;
1707
1767
  lua_assert(frame_isvarg(J->L->base-1));
1768
+ if (LJ_FR2 && dst > J->maxslot)
1769
+ J->base[dst-1] = 0; /* Prevent resurrection of unrelated slot. */
1708
1770
  if (J->framedepth > 0) { /* Simple case: varargs defined on-trace. */
1709
1771
  ptrdiff_t i;
1710
1772
  if (nvararg < 0) nvararg = 0;
@@ -1715,10 +1777,10 @@ static void rec_varg(jit_State *J, BCReg dst, ptrdiff_t nresults)
1715
1777
  J->maxslot = dst + (BCReg)nresults;
1716
1778
  }
1717
1779
  for (i = 0; i < nresults; i++)
1718
- J->base[dst+i] = i < nvararg ? getslot(J, i - nvararg - 1) : TREF_NIL;
1780
+ J->base[dst+i] = i < nvararg ? getslot(J, i - nvararg - 1 - LJ_FR2) : TREF_NIL;
1719
1781
  } else { /* Unknown number of varargs passed to trace. */
1720
- TRef fr = emitir(IRTI(IR_SLOAD), 0, IRSLOAD_READONLY|IRSLOAD_FRAME);
1721
- int32_t frofs = 8*(1+numparams)+FRAME_VARG;
1782
+ TRef fr = emitir(IRTI(IR_SLOAD), LJ_FR2, IRSLOAD_READONLY|IRSLOAD_FRAME);
1783
+ int32_t frofs = 8*(1+LJ_FR2+numparams)+FRAME_VARG;
1722
1784
  if (nresults >= 0) { /* Known fixed number of results. */
1723
1785
  ptrdiff_t i;
1724
1786
  if (nvararg > 0) {
@@ -1729,11 +1791,11 @@ static void rec_varg(jit_State *J, BCReg dst, ptrdiff_t nresults)
1729
1791
  else
1730
1792
  emitir(IRTGI(IR_EQ), fr,
1731
1793
  lj_ir_kint(J, (int32_t)frame_ftsz(J->L->base-1)));
1732
- vbase = emitir(IRTI(IR_SUB), REF_BASE, fr);
1733
- vbase = emitir(IRT(IR_ADD, IRT_P32), vbase, lj_ir_kint(J, frofs-8));
1794
+ vbase = emitir(IRT(IR_SUB, IRT_IGC), REF_BASE, fr);
1795
+ vbase = emitir(IRT(IR_ADD, IRT_PGC), vbase, lj_ir_kint(J, frofs-8));
1734
1796
  for (i = 0; i < nload; i++) {
1735
- IRType t = itype2irt(&J->L->base[i-1-nvararg]);
1736
- TRef aref = emitir(IRT(IR_AREF, IRT_P32),
1797
+ IRType t = itype2irt(&J->L->base[i-1-LJ_FR2-nvararg]);
1798
+ TRef aref = emitir(IRT(IR_AREF, IRT_PGC),
1737
1799
  vbase, lj_ir_kint(J, (int32_t)i));
1738
1800
  TRef tr = emitir(IRTG(IR_VLOAD, t), aref, 0);
1739
1801
  if (irtype_ispri(t)) tr = TREF_PRI(t); /* Canonicalize primitives. */
@@ -1779,15 +1841,16 @@ static void rec_varg(jit_State *J, BCReg dst, ptrdiff_t nresults)
1779
1841
  }
1780
1842
  if (idx != 0 && idx <= nvararg) {
1781
1843
  IRType t;
1782
- TRef aref, vbase = emitir(IRTI(IR_SUB), REF_BASE, fr);
1783
- vbase = emitir(IRT(IR_ADD, IRT_P32), vbase, lj_ir_kint(J, frofs-8));
1784
- t = itype2irt(&J->L->base[idx-2-nvararg]);
1785
- aref = emitir(IRT(IR_AREF, IRT_P32), vbase, tridx);
1844
+ TRef aref, vbase = emitir(IRT(IR_SUB, IRT_IGC), REF_BASE, fr);
1845
+ vbase = emitir(IRT(IR_ADD, IRT_PGC), vbase,
1846
+ lj_ir_kint(J, frofs-(8<<LJ_FR2)));
1847
+ t = itype2irt(&J->L->base[idx-2-LJ_FR2-nvararg]);
1848
+ aref = emitir(IRT(IR_AREF, IRT_PGC), vbase, tridx);
1786
1849
  tr = emitir(IRTG(IR_VLOAD, t), aref, 0);
1787
1850
  if (irtype_ispri(t)) tr = TREF_PRI(t); /* Canonicalize primitives. */
1788
1851
  }
1789
- J->base[dst-2] = tr;
1790
- J->maxslot = dst-1;
1852
+ J->base[dst-2-LJ_FR2] = tr;
1853
+ J->maxslot = dst-1-LJ_FR2;
1791
1854
  J->bcskip = 2; /* Skip CALLM + select. */
1792
1855
  } else {
1793
1856
  nyivarg:
@@ -1836,10 +1899,10 @@ static TRef rec_cat(jit_State *J, BCReg baseslot, BCReg topslot)
1836
1899
  break;
1837
1900
  }
1838
1901
  xbase = ++trp;
1839
- tr = hdr = emitir(IRT(IR_BUFHDR, IRT_P32),
1902
+ tr = hdr = emitir(IRT(IR_BUFHDR, IRT_PGC),
1840
1903
  lj_ir_kptr(J, &J2G(J)->tmpbuf), IRBUFHDR_RESET);
1841
1904
  do {
1842
- tr = emitir(IRT(IR_BUFPUT, IRT_P32), tr, *trp++);
1905
+ tr = emitir(IRT(IR_BUFPUT, IRT_PGC), tr, *trp++);
1843
1906
  } while (trp <= top);
1844
1907
  tr = emitir(IRT(IR_BUFSTR, IRT_STR), tr, hdr);
1845
1908
  J->maxslot = (BCReg)(xbase - J->base);
@@ -1880,7 +1943,15 @@ static void rec_comp_fixup(jit_State *J, const BCIns *pc, int cond)
1880
1943
  const BCIns *npc = pc + 2 + (cond ? bc_j(jmpins) : 0);
1881
1944
  SnapShot *snap = &J->cur.snap[J->cur.nsnap-1];
1882
1945
  /* Set PC to opposite target to avoid re-recording the comp. in side trace. */
1946
+ #if LJ_FR2
1947
+ SnapEntry *flink = &J->cur.snapmap[snap->mapofs + snap->nent];
1948
+ uint64_t pcbase;
1949
+ memcpy(&pcbase, flink, sizeof(uint64_t));
1950
+ pcbase = (pcbase & 0xff) | (u64ptr(npc) << 8);
1951
+ memcpy(flink, &pcbase, sizeof(uint64_t));
1952
+ #else
1883
1953
  J->cur.snapmap[snap->mapofs + snap->nent] = SNAP_MKPC(npc);
1954
+ #endif
1884
1955
  J->needsnap = 1;
1885
1956
  if (bc_a(jmpins) < J->maxslot) J->maxslot = bc_a(jmpins);
1886
1957
  lj_snap_shrink(J); /* Shrink last snapshot if possible. */
@@ -2156,14 +2227,14 @@ void lj_record_ins(jit_State *J)
2156
2227
  case BC_MODVN: case BC_MODVV:
2157
2228
  recmod:
2158
2229
  if (tref_isnumber_str(rb) && tref_isnumber_str(rc))
2159
- rc = lj_opt_narrow_mod(J, rb, rc, rcv);
2230
+ rc = lj_opt_narrow_mod(J, rb, rc, rbv, rcv);
2160
2231
  else
2161
2232
  rc = rec_mm_arith(J, &ix, MM_mod);
2162
2233
  break;
2163
2234
 
2164
2235
  case BC_POW:
2165
2236
  if (tref_isnumber_str(rb) && tref_isnumber_str(rc))
2166
- rc = lj_opt_narrow_pow(J, lj_ir_tonum(J, rb), rc, rcv);
2237
+ rc = lj_opt_narrow_pow(J, rb, rc, rbv, rcv);
2167
2238
  else
2168
2239
  rc = rec_mm_arith(J, &ix, MM_pow);
2169
2240
  break;
@@ -2178,7 +2249,13 @@ void lj_record_ins(jit_State *J)
2178
2249
 
2179
2250
  case BC_MOV:
2180
2251
  /* Clear gap of method call to avoid resurrecting previous refs. */
2181
- if (ra > J->maxslot) J->base[ra-1] = 0;
2252
+ if (ra > J->maxslot) {
2253
+ #if LJ_FR2
2254
+ memset(J->base + J->maxslot, 0, (ra - J->maxslot) * sizeof(TRef));
2255
+ #else
2256
+ J->base[ra-1] = 0;
2257
+ #endif
2258
+ }
2182
2259
  break;
2183
2260
  case BC_KSTR: case BC_KNUM: case BC_KPRI:
2184
2261
  break;
@@ -2186,6 +2263,8 @@ void lj_record_ins(jit_State *J)
2186
2263
  rc = lj_ir_kint(J, (int32_t)(int16_t)rc);
2187
2264
  break;
2188
2265
  case BC_KNIL:
2266
+ if (LJ_FR2 && ra > J->maxslot)
2267
+ J->base[ra-1] = 0;
2189
2268
  while (ra <= rc)
2190
2269
  J->base[ra++] = TREF_NIL;
2191
2270
  if (rc >= J->maxslot) J->maxslot = rc+1;
@@ -2247,14 +2326,14 @@ void lj_record_ins(jit_State *J)
2247
2326
  /* -- Calls and vararg handling ----------------------------------------- */
2248
2327
 
2249
2328
  case BC_ITERC:
2250
- J->base[ra] = getslot(J, ra-3-LJ_FR2);
2251
- J->base[ra+1] = getslot(J, ra-2-LJ_FR2);
2252
- J->base[ra+2] = getslot(J, ra-1-LJ_FR2);
2329
+ J->base[ra] = getslot(J, ra-3);
2330
+ J->base[ra+1+LJ_FR2] = getslot(J, ra-2);
2331
+ J->base[ra+2+LJ_FR2] = getslot(J, ra-1);
2253
2332
  { /* Do the actual copy now because lj_record_call needs the values. */
2254
2333
  TValue *b = &J->L->base[ra];
2255
- copyTV(J->L, b, b-3-LJ_FR2);
2256
- copyTV(J->L, b+1, b-2-LJ_FR2);
2257
- copyTV(J->L, b+2, b-1-LJ_FR2);
2334
+ copyTV(J->L, b, b-3);
2335
+ copyTV(J->L, b+1+LJ_FR2, b-2);
2336
+ copyTV(J->L, b+2+LJ_FR2, b-1);
2258
2337
  }
2259
2338
  lj_record_call(J, ra, (ptrdiff_t)rc-1);
2260
2339
  break;
@@ -2377,7 +2456,12 @@ void lj_record_ins(jit_State *J)
2377
2456
  /* rc == 0 if we have no result yet, e.g. pending __index metamethod call. */
2378
2457
  if (bcmode_a(op) == BCMdst && rc) {
2379
2458
  J->base[ra] = rc;
2380
- if (ra >= J->maxslot) J->maxslot = ra+1;
2459
+ if (ra >= J->maxslot) {
2460
+ #if LJ_FR2
2461
+ if (ra > J->maxslot) J->base[ra-1] = 0;
2462
+ #endif
2463
+ J->maxslot = ra+1;
2464
+ }
2381
2465
  }
2382
2466
 
2383
2467
  #undef rav
@@ -2462,7 +2546,7 @@ void lj_record_setup(jit_State *J)
2462
2546
  J->scev.idx = REF_NIL;
2463
2547
  setmref(J->scev.pc, NULL);
2464
2548
 
2465
- J->baseslot = 1; /* Invoking function is at base[-1]. */
2549
+ J->baseslot = 1+LJ_FR2; /* Invoking function is at base[-1-LJ_FR2]. */
2466
2550
  J->base = J->slot + J->baseslot;
2467
2551
  J->maxslot = 0;
2468
2552
  J->framedepth = 0;
@@ -2477,7 +2561,7 @@ void lj_record_setup(jit_State *J)
2477
2561
  J->bc_extent = ~(MSize)0;
2478
2562
 
2479
2563
  /* Emit instructions for fixed references. Also triggers initial IR alloc. */
2480
- emitir_raw(IRT(IR_BASE, IRT_P32), J->parent, J->exitno);
2564
+ emitir_raw(IRT(IR_BASE, IRT_PGC), J->parent, J->exitno);
2481
2565
  for (i = 0; i <= 2; i++) {
2482
2566
  IRIns *ir = IR(REF_NIL-i);
2483
2567
  ir->i = 0;