diff options
40 files changed, 393 insertions, 354 deletions
diff --git a/src/Makefile.dep b/src/Makefile.dep index 1b8b05a0..06ad20b1 100644 --- a/src/Makefile.dep +++ b/src/Makefile.dep | |||
| @@ -7,9 +7,9 @@ lib_base.o: lib_base.c lua.h luaconf.h lauxlib.h lualib.h lj_obj.h \ | |||
| 7 | lj_ffdef.h lj_dispatch.h lj_jit.h lj_ir.h lj_char.h lj_strscan.h \ | 7 | lj_ffdef.h lj_dispatch.h lj_jit.h lj_ir.h lj_char.h lj_strscan.h \ |
| 8 | lj_strfmt.h lj_lib.h lj_libdef.h | 8 | lj_strfmt.h lj_lib.h lj_libdef.h |
| 9 | lib_bit.o: lib_bit.c lua.h luaconf.h lauxlib.h lualib.h lj_obj.h lj_def.h \ | 9 | lib_bit.o: lib_bit.c lua.h luaconf.h lauxlib.h lualib.h lj_obj.h lj_def.h \ |
| 10 | lj_arch.h lj_err.h lj_errmsg.h lj_buf.h lj_gc.h lj_str.h lj_strfmt.h \ | 10 | lj_arch.h lj_err.h lj_errmsg.h lj_buf.h lj_gc.h lj_str.h lj_strscan.h \ |
| 11 | lj_ctype.h lj_cdata.h lj_cconv.h lj_carith.h lj_ff.h lj_ffdef.h lj_lib.h \ | 11 | lj_strfmt.h lj_ctype.h lj_cdata.h lj_cconv.h lj_carith.h lj_ff.h \ |
| 12 | lj_libdef.h | 12 | lj_ffdef.h lj_lib.h lj_libdef.h |
| 13 | lib_debug.o: lib_debug.c lua.h luaconf.h lauxlib.h lualib.h lj_obj.h \ | 13 | lib_debug.o: lib_debug.c lua.h luaconf.h lauxlib.h lualib.h lj_obj.h \ |
| 14 | lj_def.h lj_arch.h lj_gc.h lj_err.h lj_errmsg.h lj_debug.h lj_lib.h \ | 14 | lj_def.h lj_arch.h lj_gc.h lj_err.h lj_errmsg.h lj_debug.h lj_lib.h \ |
| 15 | lj_libdef.h | 15 | lj_libdef.h |
| @@ -59,15 +59,15 @@ lj_bcread.o: lj_bcread.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ | |||
| 59 | lj_strfmt.h | 59 | lj_strfmt.h |
| 60 | lj_bcwrite.o: lj_bcwrite.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ | 60 | lj_bcwrite.o: lj_bcwrite.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ |
| 61 | lj_gc.h lj_buf.h lj_str.h lj_bc.h lj_ctype.h lj_dispatch.h lj_jit.h \ | 61 | lj_gc.h lj_buf.h lj_str.h lj_bc.h lj_ctype.h lj_dispatch.h lj_jit.h \ |
| 62 | lj_ir.h lj_bcdump.h lj_lex.h lj_err.h lj_errmsg.h lj_vm.h | 62 | lj_ir.h lj_strfmt.h lj_bcdump.h lj_lex.h lj_err.h lj_errmsg.h lj_vm.h |
| 63 | lj_buf.o: lj_buf.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_gc.h \ | 63 | lj_buf.o: lj_buf.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_gc.h \ |
| 64 | lj_err.h lj_errmsg.h lj_buf.h lj_str.h lj_tab.h | 64 | lj_err.h lj_errmsg.h lj_buf.h lj_str.h lj_tab.h lj_strfmt.h |
| 65 | lj_carith.o: lj_carith.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ | 65 | lj_carith.o: lj_carith.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ |
| 66 | lj_gc.h lj_err.h lj_errmsg.h lj_tab.h lj_meta.h lj_ir.h lj_ctype.h \ | 66 | lj_gc.h lj_err.h lj_errmsg.h lj_tab.h lj_meta.h lj_ir.h lj_ctype.h \ |
| 67 | lj_cconv.h lj_cdata.h lj_carith.h lj_strscan.h | 67 | lj_cconv.h lj_cdata.h lj_carith.h lj_strscan.h |
| 68 | lj_ccall.o: lj_ccall.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ | 68 | lj_ccall.o: lj_ccall.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ |
| 69 | lj_gc.h lj_err.h lj_errmsg.h lj_str.h lj_tab.h lj_ctype.h lj_cconv.h \ | 69 | lj_gc.h lj_err.h lj_errmsg.h lj_tab.h lj_ctype.h lj_cconv.h lj_cdata.h \ |
| 70 | lj_cdata.h lj_ccall.h lj_trace.h lj_jit.h lj_ir.h lj_dispatch.h lj_bc.h \ | 70 | lj_ccall.h lj_trace.h lj_jit.h lj_ir.h lj_dispatch.h lj_bc.h \ |
| 71 | lj_traceerr.h | 71 | lj_traceerr.h |
| 72 | lj_ccallback.o: lj_ccallback.c lj_obj.h lua.h luaconf.h lj_def.h \ | 72 | lj_ccallback.o: lj_ccallback.c lj_obj.h lua.h luaconf.h lj_def.h \ |
| 73 | lj_arch.h lj_gc.h lj_err.h lj_errmsg.h lj_tab.h lj_state.h lj_frame.h \ | 73 | lj_arch.h lj_gc.h lj_err.h lj_errmsg.h lj_tab.h lj_state.h lj_frame.h \ |
| @@ -78,8 +78,7 @@ lj_cconv.o: lj_cconv.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ | |||
| 78 | lj_err.h lj_errmsg.h lj_tab.h lj_ctype.h lj_gc.h lj_cdata.h lj_cconv.h \ | 78 | lj_err.h lj_errmsg.h lj_tab.h lj_ctype.h lj_gc.h lj_cdata.h lj_cconv.h \ |
| 79 | lj_ccallback.h | 79 | lj_ccallback.h |
| 80 | lj_cdata.o: lj_cdata.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ | 80 | lj_cdata.o: lj_cdata.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ |
| 81 | lj_gc.h lj_err.h lj_errmsg.h lj_str.h lj_tab.h lj_ctype.h lj_cconv.h \ | 81 | lj_gc.h lj_err.h lj_errmsg.h lj_tab.h lj_ctype.h lj_cconv.h lj_cdata.h |
| 82 | lj_cdata.h | ||
| 83 | lj_char.o: lj_char.c lj_char.h lj_def.h lua.h luaconf.h | 82 | lj_char.o: lj_char.c lj_char.h lj_def.h lua.h luaconf.h |
| 84 | lj_clib.o: lj_clib.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_gc.h \ | 83 | lj_clib.o: lj_clib.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_gc.h \ |
| 85 | lj_err.h lj_errmsg.h lj_tab.h lj_str.h lj_udata.h lj_ctype.h lj_cconv.h \ | 84 | lj_err.h lj_errmsg.h lj_tab.h lj_str.h lj_udata.h lj_ctype.h lj_cconv.h \ |
| @@ -88,21 +87,22 @@ lj_cparse.o: lj_cparse.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ | |||
| 88 | lj_gc.h lj_err.h lj_errmsg.h lj_buf.h lj_str.h lj_ctype.h lj_cparse.h \ | 87 | lj_gc.h lj_err.h lj_errmsg.h lj_buf.h lj_str.h lj_ctype.h lj_cparse.h \ |
| 89 | lj_frame.h lj_bc.h lj_vm.h lj_char.h lj_strscan.h lj_strfmt.h | 88 | lj_frame.h lj_bc.h lj_vm.h lj_char.h lj_strscan.h lj_strfmt.h |
| 90 | lj_crecord.o: lj_crecord.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ | 89 | lj_crecord.o: lj_crecord.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ |
| 91 | lj_err.h lj_errmsg.h lj_str.h lj_tab.h lj_frame.h lj_bc.h lj_ctype.h \ | 90 | lj_err.h lj_errmsg.h lj_tab.h lj_frame.h lj_bc.h lj_ctype.h lj_gc.h \ |
| 92 | lj_gc.h lj_cdata.h lj_cparse.h lj_cconv.h lj_clib.h lj_ccall.h lj_ff.h \ | 91 | lj_cdata.h lj_cparse.h lj_cconv.h lj_clib.h lj_ccall.h lj_ff.h \ |
| 93 | lj_ffdef.h lj_ir.h lj_jit.h lj_ircall.h lj_iropt.h lj_trace.h \ | 92 | lj_ffdef.h lj_ir.h lj_jit.h lj_ircall.h lj_iropt.h lj_trace.h \ |
| 94 | lj_dispatch.h lj_traceerr.h lj_record.h lj_ffrecord.h lj_snap.h \ | 93 | lj_dispatch.h lj_traceerr.h lj_record.h lj_ffrecord.h lj_snap.h \ |
| 95 | lj_crecord.h | 94 | lj_crecord.h |
| 96 | lj_ctype.o: lj_ctype.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ | 95 | lj_ctype.o: lj_ctype.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ |
| 97 | lj_gc.h lj_err.h lj_errmsg.h lj_str.h lj_tab.h lj_ctype.h lj_ccallback.h | 96 | lj_gc.h lj_err.h lj_errmsg.h lj_str.h lj_tab.h lj_strfmt.h lj_ctype.h \ |
| 97 | lj_ccallback.h | ||
| 98 | lj_debug.o: lj_debug.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ | 98 | lj_debug.o: lj_debug.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ |
| 99 | lj_err.h lj_errmsg.h lj_debug.h lj_buf.h lj_gc.h lj_str.h lj_tab.h \ | 99 | lj_err.h lj_errmsg.h lj_debug.h lj_buf.h lj_gc.h lj_str.h lj_tab.h \ |
| 100 | lj_state.h lj_frame.h lj_bc.h lj_strfmt.h lj_jit.h lj_ir.h | 100 | lj_state.h lj_frame.h lj_bc.h lj_strfmt.h lj_jit.h lj_ir.h |
| 101 | lj_dispatch.o: lj_dispatch.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ | 101 | lj_dispatch.o: lj_dispatch.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ |
| 102 | lj_err.h lj_errmsg.h lj_buf.h lj_gc.h lj_str.h lj_func.h lj_tab.h \ | 102 | lj_err.h lj_errmsg.h lj_buf.h lj_gc.h lj_str.h lj_func.h lj_tab.h \ |
| 103 | lj_meta.h lj_debug.h lj_state.h lj_frame.h lj_bc.h lj_ff.h lj_ffdef.h \ | 103 | lj_meta.h lj_debug.h lj_state.h lj_frame.h lj_bc.h lj_ff.h lj_ffdef.h \ |
| 104 | lj_jit.h lj_ir.h lj_ccallback.h lj_ctype.h lj_trace.h lj_dispatch.h \ | 104 | lj_strfmt.h lj_jit.h lj_ir.h lj_ccallback.h lj_ctype.h lj_trace.h \ |
| 105 | lj_traceerr.h lj_vm.h luajit.h | 105 | lj_dispatch.h lj_traceerr.h lj_vm.h luajit.h |
| 106 | lj_err.o: lj_err.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_err.h \ | 106 | lj_err.o: lj_err.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_err.h \ |
| 107 | lj_errmsg.h lj_debug.h lj_str.h lj_func.h lj_state.h lj_frame.h lj_bc.h \ | 107 | lj_errmsg.h lj_debug.h lj_str.h lj_func.h lj_state.h lj_frame.h lj_bc.h \ |
| 108 | lj_ff.h lj_ffdef.h lj_trace.h lj_jit.h lj_ir.h lj_dispatch.h \ | 108 | lj_ff.h lj_ffdef.h lj_trace.h lj_jit.h lj_ir.h lj_dispatch.h \ |
| @@ -121,19 +121,19 @@ lj_gc.o: lj_gc.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_gc.h \ | |||
| 121 | lj_jit.h lj_ir.h lj_dispatch.h lj_traceerr.h lj_vm.h | 121 | lj_jit.h lj_ir.h lj_dispatch.h lj_traceerr.h lj_vm.h |
| 122 | lj_gdbjit.o: lj_gdbjit.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ | 122 | lj_gdbjit.o: lj_gdbjit.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ |
| 123 | lj_gc.h lj_err.h lj_errmsg.h lj_debug.h lj_frame.h lj_bc.h lj_buf.h \ | 123 | lj_gc.h lj_err.h lj_errmsg.h lj_debug.h lj_frame.h lj_bc.h lj_buf.h \ |
| 124 | lj_str.h lj_jit.h lj_ir.h lj_dispatch.h | 124 | lj_str.h lj_strfmt.h lj_jit.h lj_ir.h lj_dispatch.h |
| 125 | lj_ir.o: lj_ir.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_gc.h \ | 125 | lj_ir.o: lj_ir.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_gc.h \ |
| 126 | lj_buf.h lj_str.h lj_tab.h lj_ir.h lj_jit.h lj_ircall.h lj_iropt.h \ | 126 | lj_buf.h lj_str.h lj_tab.h lj_ir.h lj_jit.h lj_ircall.h lj_iropt.h \ |
| 127 | lj_trace.h lj_dispatch.h lj_bc.h lj_traceerr.h lj_ctype.h lj_cdata.h \ | 127 | lj_trace.h lj_dispatch.h lj_bc.h lj_traceerr.h lj_ctype.h lj_cdata.h \ |
| 128 | lj_carith.h lj_vm.h lj_strscan.h lj_lib.h | 128 | lj_carith.h lj_vm.h lj_strscan.h lj_strfmt.h lj_lib.h |
| 129 | lj_lex.o: lj_lex.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_gc.h \ | 129 | lj_lex.o: lj_lex.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_gc.h \ |
| 130 | lj_err.h lj_errmsg.h lj_buf.h lj_str.h lj_tab.h lj_ctype.h lj_cdata.h \ | 130 | lj_err.h lj_errmsg.h lj_buf.h lj_str.h lj_tab.h lj_ctype.h lj_cdata.h \ |
| 131 | lualib.h lj_state.h lj_lex.h lj_parse.h lj_char.h lj_strscan.h \ | 131 | lualib.h lj_state.h lj_lex.h lj_parse.h lj_char.h lj_strscan.h \ |
| 132 | lj_strfmt.h | 132 | lj_strfmt.h |
| 133 | lj_lib.o: lj_lib.c lauxlib.h lua.h luaconf.h lj_obj.h lj_def.h lj_arch.h \ | 133 | lj_lib.o: lj_lib.c lauxlib.h lua.h luaconf.h lj_obj.h lj_def.h lj_arch.h \ |
| 134 | lj_gc.h lj_err.h lj_errmsg.h lj_str.h lj_tab.h lj_func.h lj_bc.h \ | 134 | lj_gc.h lj_err.h lj_errmsg.h lj_str.h lj_tab.h lj_func.h lj_bc.h \ |
| 135 | lj_dispatch.h lj_jit.h lj_ir.h lj_vm.h lj_strscan.h lj_lex.h lj_bcdump.h \ | 135 | lj_dispatch.h lj_jit.h lj_ir.h lj_vm.h lj_strscan.h lj_strfmt.h lj_lex.h \ |
| 136 | lj_lib.h | 136 | lj_bcdump.h lj_lib.h |
| 137 | lj_load.o: lj_load.c lua.h luaconf.h lauxlib.h lj_obj.h lj_def.h \ | 137 | lj_load.o: lj_load.c lua.h luaconf.h lauxlib.h lj_obj.h lj_def.h \ |
| 138 | lj_arch.h lj_gc.h lj_err.h lj_errmsg.h lj_buf.h lj_str.h lj_func.h \ | 138 | lj_arch.h lj_gc.h lj_err.h lj_errmsg.h lj_buf.h lj_str.h lj_func.h \ |
| 139 | lj_frame.h lj_bc.h lj_vm.h lj_lex.h lj_bcdump.h lj_parse.h | 139 | lj_frame.h lj_bc.h lj_vm.h lj_lex.h lj_bcdump.h lj_parse.h |
| @@ -142,14 +142,14 @@ lj_mcode.o: lj_mcode.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ | |||
| 142 | lj_traceerr.h lj_vm.h | 142 | lj_traceerr.h lj_vm.h |
| 143 | lj_meta.o: lj_meta.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_gc.h \ | 143 | lj_meta.o: lj_meta.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_gc.h \ |
| 144 | lj_err.h lj_errmsg.h lj_buf.h lj_str.h lj_tab.h lj_meta.h lj_frame.h \ | 144 | lj_err.h lj_errmsg.h lj_buf.h lj_str.h lj_tab.h lj_meta.h lj_frame.h \ |
| 145 | lj_bc.h lj_vm.h lj_strscan.h lj_lib.h | 145 | lj_bc.h lj_vm.h lj_strscan.h lj_strfmt.h lj_lib.h |
| 146 | lj_obj.o: lj_obj.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h | 146 | lj_obj.o: lj_obj.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h |
| 147 | lj_opt_dce.o: lj_opt_dce.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ | 147 | lj_opt_dce.o: lj_opt_dce.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ |
| 148 | lj_ir.h lj_jit.h lj_iropt.h | 148 | lj_ir.h lj_jit.h lj_iropt.h |
| 149 | lj_opt_fold.o: lj_opt_fold.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ | 149 | lj_opt_fold.o: lj_opt_fold.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ |
| 150 | lj_buf.h lj_gc.h lj_str.h lj_tab.h lj_ir.h lj_jit.h lj_ircall.h \ | 150 | lj_buf.h lj_gc.h lj_str.h lj_tab.h lj_ir.h lj_jit.h lj_ircall.h \ |
| 151 | lj_iropt.h lj_trace.h lj_dispatch.h lj_bc.h lj_traceerr.h lj_ctype.h \ | 151 | lj_iropt.h lj_trace.h lj_dispatch.h lj_bc.h lj_traceerr.h lj_ctype.h \ |
| 152 | lj_carith.h lj_vm.h lj_strscan.h lj_folddef.h | 152 | lj_carith.h lj_vm.h lj_strscan.h lj_strfmt.h lj_folddef.h |
| 153 | lj_opt_loop.o: lj_opt_loop.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ | 153 | lj_opt_loop.o: lj_opt_loop.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ |
| 154 | lj_err.h lj_errmsg.h lj_buf.h lj_gc.h lj_str.h lj_ir.h lj_jit.h \ | 154 | lj_err.h lj_errmsg.h lj_buf.h lj_gc.h lj_str.h lj_ir.h lj_jit.h \ |
| 155 | lj_iropt.h lj_trace.h lj_dispatch.h lj_bc.h lj_traceerr.h lj_snap.h \ | 155 | lj_iropt.h lj_trace.h lj_dispatch.h lj_bc.h lj_traceerr.h lj_snap.h \ |
| @@ -166,13 +166,13 @@ lj_opt_split.o: lj_opt_split.c lj_obj.h lua.h luaconf.h lj_def.h \ | |||
| 166 | lj_jit.h lj_ircall.h lj_iropt.h lj_vm.h | 166 | lj_jit.h lj_ircall.h lj_iropt.h lj_vm.h |
| 167 | lj_parse.o: lj_parse.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ | 167 | lj_parse.o: lj_parse.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ |
| 168 | lj_gc.h lj_err.h lj_errmsg.h lj_debug.h lj_buf.h lj_str.h lj_tab.h \ | 168 | lj_gc.h lj_err.h lj_errmsg.h lj_debug.h lj_buf.h lj_str.h lj_tab.h \ |
| 169 | lj_func.h lj_state.h lj_bc.h lj_ctype.h lj_lex.h lj_parse.h lj_vm.h \ | 169 | lj_func.h lj_state.h lj_bc.h lj_ctype.h lj_strfmt.h lj_lex.h lj_parse.h \ |
| 170 | lj_vmevent.h | 170 | lj_vm.h lj_vmevent.h |
| 171 | lj_record.o: lj_record.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ | 171 | lj_record.o: lj_record.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ |
| 172 | lj_err.h lj_errmsg.h lj_buf.h lj_gc.h lj_str.h lj_tab.h lj_meta.h \ | 172 | lj_err.h lj_errmsg.h lj_str.h lj_tab.h lj_meta.h lj_frame.h lj_bc.h \ |
| 173 | lj_frame.h lj_bc.h lj_ctype.h lj_ff.h lj_ffdef.h lj_ir.h lj_jit.h \ | 173 | lj_ctype.h lj_gc.h lj_ff.h lj_ffdef.h lj_ir.h lj_jit.h lj_ircall.h \ |
| 174 | lj_ircall.h lj_iropt.h lj_trace.h lj_dispatch.h lj_traceerr.h \ | 174 | lj_iropt.h lj_trace.h lj_dispatch.h lj_traceerr.h lj_record.h \ |
| 175 | lj_record.h lj_ffrecord.h lj_snap.h lj_vm.h | 175 | lj_ffrecord.h lj_snap.h lj_vm.h |
| 176 | lj_snap.o: lj_snap.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_gc.h \ | 176 | lj_snap.o: lj_snap.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_gc.h \ |
| 177 | lj_tab.h lj_state.h lj_frame.h lj_bc.h lj_ir.h lj_jit.h lj_iropt.h \ | 177 | lj_tab.h lj_state.h lj_frame.h lj_bc.h lj_ir.h lj_jit.h lj_iropt.h \ |
| 178 | lj_trace.h lj_dispatch.h lj_traceerr.h lj_snap.h lj_target.h \ | 178 | lj_trace.h lj_dispatch.h lj_traceerr.h lj_snap.h lj_target.h \ |
| @@ -182,7 +182,7 @@ lj_state.o: lj_state.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ | |||
| 182 | lj_meta.h lj_state.h lj_frame.h lj_bc.h lj_ctype.h lj_trace.h lj_jit.h \ | 182 | lj_meta.h lj_state.h lj_frame.h lj_bc.h lj_ctype.h lj_trace.h lj_jit.h \ |
| 183 | lj_ir.h lj_dispatch.h lj_traceerr.h lj_vm.h lj_lex.h lj_alloc.h | 183 | lj_ir.h lj_dispatch.h lj_traceerr.h lj_vm.h lj_lex.h lj_alloc.h |
| 184 | lj_str.o: lj_str.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_gc.h \ | 184 | lj_str.o: lj_str.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_gc.h \ |
| 185 | lj_err.h lj_errmsg.h lj_buf.h lj_str.h lj_char.h | 185 | lj_err.h lj_errmsg.h lj_str.h lj_char.h |
| 186 | lj_strfmt.o: lj_strfmt.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ | 186 | lj_strfmt.o: lj_strfmt.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ |
| 187 | lj_buf.h lj_gc.h lj_str.h lj_state.h lj_char.h lj_strfmt.h | 187 | lj_buf.h lj_gc.h lj_str.h lj_state.h lj_char.h lj_strfmt.h |
| 188 | lj_strscan.o: lj_strscan.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ | 188 | lj_strscan.o: lj_strscan.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ |
diff --git a/src/lib_base.c b/src/lib_base.c index 84bf1ef2..44817187 100644 --- a/src/lib_base.c +++ b/src/lib_base.c | |||
| @@ -492,11 +492,11 @@ LJLIB_CF(print) | |||
| 492 | shortcut = (tvisfunc(tv) && funcV(tv)->c.ffid == FF_tostring); | 492 | shortcut = (tvisfunc(tv) && funcV(tv)->c.ffid == FF_tostring); |
| 493 | for (i = 0; i < nargs; i++) { | 493 | for (i = 0; i < nargs; i++) { |
| 494 | cTValue *o = &L->base[i]; | 494 | cTValue *o = &L->base[i]; |
| 495 | char buf[LJ_STR_NUMBERBUF]; | 495 | char buf[STRFMT_MAXBUF_NUM]; |
| 496 | const char *str; | 496 | const char *str; |
| 497 | size_t size; | 497 | size_t size; |
| 498 | MSize len; | 498 | MSize len; |
| 499 | if (shortcut && (str = lj_str_buftv(buf, o, &len)) != NULL) { | 499 | if (shortcut && (str = lj_strfmt_wstrnum(buf, o, &len)) != NULL) { |
| 500 | size = len; | 500 | size = len; |
| 501 | } else { | 501 | } else { |
| 502 | copyTV(L, L->top+1, o); | 502 | copyTV(L, L->top+1, o); |
diff --git a/src/lib_bit.c b/src/lib_bit.c index b1f0beb2..dec0cb87 100644 --- a/src/lib_bit.c +++ b/src/lib_bit.c | |||
| @@ -13,7 +13,7 @@ | |||
| 13 | #include "lj_obj.h" | 13 | #include "lj_obj.h" |
| 14 | #include "lj_err.h" | 14 | #include "lj_err.h" |
| 15 | #include "lj_buf.h" | 15 | #include "lj_buf.h" |
| 16 | #include "lj_str.h" | 16 | #include "lj_strscan.h" |
| 17 | #include "lj_strfmt.h" | 17 | #include "lj_strfmt.h" |
| 18 | #if LJ_HASFFI | 18 | #if LJ_HASFFI |
| 19 | #include "lj_ctype.h" | 19 | #include "lj_ctype.h" |
| @@ -157,7 +157,7 @@ LJLIB_CF(bit_tohex) | |||
| 157 | SFormat sf = (STRFMT_UINT|STRFMT_T_HEX); | 157 | SFormat sf = (STRFMT_UINT|STRFMT_T_HEX); |
| 158 | if (n < 0) { n = -n; sf |= STRFMT_F_UPPER; } | 158 | if (n < 0) { n = -n; sf |= STRFMT_F_UPPER; } |
| 159 | sf |= ((SFormat)(n+1) << STRFMT_SH_PREC); | 159 | sf |= ((SFormat)(n+1) << STRFMT_SH_PREC); |
| 160 | sb = lj_strfmt_putxint(sb, sf, b); | 160 | sb = lj_strfmt_putfxint(sb, sf, b); |
| 161 | setstrV(L, L->top-1, lj_buf_str(L, sb)); | 161 | setstrV(L, L->top-1, lj_buf_str(L, sb)); |
| 162 | lj_gc_check(L); | 162 | lj_gc_check(L); |
| 163 | return 1; | 163 | return 1; |
diff --git a/src/lib_io.c b/src/lib_io.c index cae56579..ca87ec4d 100644 --- a/src/lib_io.c +++ b/src/lib_io.c | |||
| @@ -232,9 +232,9 @@ static int io_file_write(lua_State *L, FILE *fp, int start) | |||
| 232 | cTValue *tv; | 232 | cTValue *tv; |
| 233 | int status = 1; | 233 | int status = 1; |
| 234 | for (tv = L->base+start; tv < L->top; tv++) { | 234 | for (tv = L->base+start; tv < L->top; tv++) { |
| 235 | char buf[LJ_STR_NUMBERBUF]; | 235 | char buf[STRFMT_MAXBUF_NUM]; |
| 236 | MSize len; | 236 | MSize len; |
| 237 | const char *p = lj_str_buftv(buf, tv, &len); | 237 | const char *p = lj_strfmt_wstrnum(buf, tv, &len); |
| 238 | if (!p) | 238 | if (!p) |
| 239 | lj_err_argt(L, (int)(tv - L->base) + 1, LUA_TSTRING); | 239 | lj_err_argt(L, (int)(tv - L->base) + 1, LUA_TSTRING); |
| 240 | status = status && (fwrite(p, 1, len, fp) == len); | 240 | status = status && (fwrite(p, 1, len, fp) == len); |
diff --git a/src/lib_os.c b/src/lib_os.c index 9bfc418b..de2bc623 100644 --- a/src/lib_os.c +++ b/src/lib_os.c | |||
| @@ -21,6 +21,7 @@ | |||
| 21 | #include "lj_gc.h" | 21 | #include "lj_gc.h" |
| 22 | #include "lj_err.h" | 22 | #include "lj_err.h" |
| 23 | #include "lj_buf.h" | 23 | #include "lj_buf.h" |
| 24 | #include "lj_str.h" | ||
| 24 | #include "lj_lib.h" | 25 | #include "lj_lib.h" |
| 25 | 26 | ||
| 26 | #if LJ_TARGET_POSIX | 27 | #if LJ_TARGET_POSIX |
diff --git a/src/lib_string.c b/src/lib_string.c index ec01594f..cc1affbd 100644 --- a/src/lib_string.c +++ b/src/lib_string.c | |||
| @@ -684,21 +684,21 @@ again: | |||
| 684 | if (tvisint(L->base+arg-1)) { | 684 | if (tvisint(L->base+arg-1)) { |
| 685 | int32_t k = intV(L->base+arg-1); | 685 | int32_t k = intV(L->base+arg-1); |
| 686 | if (sf == STRFMT_INT) | 686 | if (sf == STRFMT_INT) |
| 687 | lj_buf_putint(sb, k); /* Shortcut for plain %d. */ | 687 | lj_strfmt_putint(sb, k); /* Shortcut for plain %d. */ |
| 688 | else | 688 | else |
| 689 | lj_strfmt_putxint(sb, sf, k); | 689 | lj_strfmt_putfxint(sb, sf, k); |
| 690 | } else { | 690 | } else { |
| 691 | lj_strfmt_putnum_int(sb, sf, lj_lib_checknum(L, arg)); | 691 | lj_strfmt_putfnum_int(sb, sf, lj_lib_checknum(L, arg)); |
| 692 | } | 692 | } |
| 693 | break; | 693 | break; |
| 694 | case STRFMT_UINT: | 694 | case STRFMT_UINT: |
| 695 | if (tvisint(L->base+arg-1)) | 695 | if (tvisint(L->base+arg-1)) |
| 696 | lj_strfmt_putxint(sb, sf, intV(L->base+arg-1)); | 696 | lj_strfmt_putfxint(sb, sf, intV(L->base+arg-1)); |
| 697 | else | 697 | else |
| 698 | lj_strfmt_putnum_uint(sb, sf, lj_lib_checknum(L, arg)); | 698 | lj_strfmt_putfnum_uint(sb, sf, lj_lib_checknum(L, arg)); |
| 699 | break; | 699 | break; |
| 700 | case STRFMT_NUM: | 700 | case STRFMT_NUM: |
| 701 | lj_strfmt_putnum(sb, sf, lj_lib_checknum(L, arg)); | 701 | lj_strfmt_putfnum(sb, sf, lj_lib_checknum(L, arg)); |
| 702 | break; | 702 | break; |
| 703 | case STRFMT_STR: { | 703 | case STRFMT_STR: { |
| 704 | GCstr *str = string_fmt_tostring(L, arg, retry); | 704 | GCstr *str = string_fmt_tostring(L, arg, retry); |
| @@ -707,15 +707,15 @@ again: | |||
| 707 | else if ((sf & STRFMT_T_QUOTED)) | 707 | else if ((sf & STRFMT_T_QUOTED)) |
| 708 | lj_strfmt_putquoted(sb, str); | 708 | lj_strfmt_putquoted(sb, str); |
| 709 | else | 709 | else |
| 710 | lj_strfmt_putstr(sb, sf, str); | 710 | lj_strfmt_putfstr(sb, sf, str); |
| 711 | break; | 711 | break; |
| 712 | } | 712 | } |
| 713 | case STRFMT_CHAR: | 713 | case STRFMT_CHAR: |
| 714 | lj_strfmt_putchar(sb, sf, lj_lib_checkint(L, arg)); | 714 | lj_strfmt_putfchar(sb, sf, lj_lib_checkint(L, arg)); |
| 715 | break; | 715 | break; |
| 716 | case STRFMT_PTR: /* No formatting. */ | 716 | case STRFMT_PTR: /* No formatting. */ |
| 717 | setsbufP(sb, lj_str_bufptr(lj_buf_more(sb, LJ_STR_PTRBUF), | 717 | setsbufP(sb, lj_strfmt_wptr(lj_buf_more(sb, STRFMT_MAXBUF_PTR), |
| 718 | lj_obj_ptr(L->base+arg-1))); | 718 | lj_obj_ptr(L->base+arg-1))); |
| 719 | break; | 719 | break; |
| 720 | default: | 720 | default: |
| 721 | lua_assert(0); | 721 | lua_assert(0); |
diff --git a/src/lib_table.c b/src/lib_table.c index 80c7c8dc..d7df8399 100644 --- a/src/lib_table.c +++ b/src/lib_table.c | |||
| @@ -17,7 +17,6 @@ | |||
| 17 | #include "lj_gc.h" | 17 | #include "lj_gc.h" |
| 18 | #include "lj_err.h" | 18 | #include "lj_err.h" |
| 19 | #include "lj_buf.h" | 19 | #include "lj_buf.h" |
| 20 | #include "lj_str.h" | ||
| 21 | #include "lj_tab.h" | 20 | #include "lj_tab.h" |
| 22 | #include "lj_lib.h" | 21 | #include "lj_lib.h" |
| 23 | 22 | ||
diff --git a/src/lj_api.c b/src/lj_api.c index 0b7855d7..8aaafdc5 100644 --- a/src/lj_api.c +++ b/src/lj_api.c | |||
| @@ -435,7 +435,7 @@ LUA_API const char *lua_tolstring(lua_State *L, int idx, size_t *len) | |||
| 435 | } else if (tvisnumber(o)) { | 435 | } else if (tvisnumber(o)) { |
| 436 | lj_gc_check(L); | 436 | lj_gc_check(L); |
| 437 | o = index2adr(L, idx); /* GC may move the stack. */ | 437 | o = index2adr(L, idx); /* GC may move the stack. */ |
| 438 | s = lj_str_fromnumber(L, o); | 438 | s = lj_strfmt_number(L, o); |
| 439 | setstrV(L, o, s); | 439 | setstrV(L, o, s); |
| 440 | } else { | 440 | } else { |
| 441 | if (len != NULL) *len = 0; | 441 | if (len != NULL) *len = 0; |
| @@ -454,7 +454,7 @@ LUALIB_API const char *luaL_checklstring(lua_State *L, int idx, size_t *len) | |||
| 454 | } else if (tvisnumber(o)) { | 454 | } else if (tvisnumber(o)) { |
| 455 | lj_gc_check(L); | 455 | lj_gc_check(L); |
| 456 | o = index2adr(L, idx); /* GC may move the stack. */ | 456 | o = index2adr(L, idx); /* GC may move the stack. */ |
| 457 | s = lj_str_fromnumber(L, o); | 457 | s = lj_strfmt_number(L, o); |
| 458 | setstrV(L, o, s); | 458 | setstrV(L, o, s); |
| 459 | } else { | 459 | } else { |
| 460 | lj_err_argt(L, idx, LUA_TSTRING); | 460 | lj_err_argt(L, idx, LUA_TSTRING); |
| @@ -476,7 +476,7 @@ LUALIB_API const char *luaL_optlstring(lua_State *L, int idx, | |||
| 476 | } else if (tvisnumber(o)) { | 476 | } else if (tvisnumber(o)) { |
| 477 | lj_gc_check(L); | 477 | lj_gc_check(L); |
| 478 | o = index2adr(L, idx); /* GC may move the stack. */ | 478 | o = index2adr(L, idx); /* GC may move the stack. */ |
| 479 | s = lj_str_fromnumber(L, o); | 479 | s = lj_strfmt_number(L, o); |
| 480 | setstrV(L, o, s); | 480 | setstrV(L, o, s); |
| 481 | } else { | 481 | } else { |
| 482 | lj_err_argt(L, idx, LUA_TSTRING); | 482 | lj_err_argt(L, idx, LUA_TSTRING); |
| @@ -508,7 +508,7 @@ LUA_API size_t lua_objlen(lua_State *L, int idx) | |||
| 508 | } else if (tvisudata(o)) { | 508 | } else if (tvisudata(o)) { |
| 509 | return udataV(o)->len; | 509 | return udataV(o)->len; |
| 510 | } else if (tvisnumber(o)) { | 510 | } else if (tvisnumber(o)) { |
| 511 | GCstr *s = lj_str_fromnumber(L, o); | 511 | GCstr *s = lj_strfmt_number(L, o); |
| 512 | setstrV(L, o, s); | 512 | setstrV(L, o, s); |
| 513 | return s->len; | 513 | return s->len; |
| 514 | } else { | 514 | } else { |
diff --git a/src/lj_asm.c b/src/lj_asm.c index b8d20f2d..9d874ddb 100644 --- a/src/lj_asm.c +++ b/src/lj_asm.c | |||
| @@ -1086,12 +1086,12 @@ static void asm_bufput(ASMState *as, IRIns *ir) | |||
| 1086 | if (irs->o == IR_TOSTR) { /* Fuse number to string conversions. */ | 1086 | if (irs->o == IR_TOSTR) { /* Fuse number to string conversions. */ |
| 1087 | if (irs->op2 == IRTOSTR_NUM) { | 1087 | if (irs->op2 == IRTOSTR_NUM) { |
| 1088 | args[1] = ASMREF_TMP1; /* TValue * */ | 1088 | args[1] = ASMREF_TMP1; /* TValue * */ |
| 1089 | ci = &lj_ir_callinfo[IRCALL_lj_buf_putnum]; | 1089 | ci = &lj_ir_callinfo[IRCALL_lj_strfmt_putnum]; |
| 1090 | } else { | 1090 | } else { |
| 1091 | lua_assert(irt_isinteger(IR(irs->op1)->t)); | 1091 | lua_assert(irt_isinteger(IR(irs->op1)->t)); |
| 1092 | args[1] = irs->op1; /* int */ | 1092 | args[1] = irs->op1; /* int */ |
| 1093 | if (irs->op2 == IRTOSTR_INT) | 1093 | if (irs->op2 == IRTOSTR_INT) |
| 1094 | ci = &lj_ir_callinfo[IRCALL_lj_buf_putint]; | 1094 | ci = &lj_ir_callinfo[IRCALL_lj_strfmt_putint]; |
| 1095 | else | 1095 | else |
| 1096 | ci = &lj_ir_callinfo[IRCALL_lj_buf_putchar]; | 1096 | ci = &lj_ir_callinfo[IRCALL_lj_buf_putchar]; |
| 1097 | } | 1097 | } |
| @@ -1131,14 +1131,14 @@ static void asm_tostr(ASMState *as, IRIns *ir) | |||
| 1131 | args[0] = ASMREF_L; | 1131 | args[0] = ASMREF_L; |
| 1132 | as->gcsteps++; | 1132 | as->gcsteps++; |
| 1133 | if (ir->op2 == IRTOSTR_NUM) { | 1133 | if (ir->op2 == IRTOSTR_NUM) { |
| 1134 | args[1] = ASMREF_TMP1; /* const lua_Number * */ | 1134 | args[1] = ASMREF_TMP1; /* cTValue * */ |
| 1135 | ci = &lj_ir_callinfo[IRCALL_lj_str_fromnum]; | 1135 | ci = &lj_ir_callinfo[IRCALL_lj_strfmt_num]; |
| 1136 | } else { | 1136 | } else { |
| 1137 | args[1] = ir->op1; /* int32_t k */ | 1137 | args[1] = ir->op1; /* int32_t k */ |
| 1138 | if (ir->op2 == IRTOSTR_INT) | 1138 | if (ir->op2 == IRTOSTR_INT) |
| 1139 | ci = &lj_ir_callinfo[IRCALL_lj_str_fromint]; | 1139 | ci = &lj_ir_callinfo[IRCALL_lj_strfmt_int]; |
| 1140 | else | 1140 | else |
| 1141 | ci = &lj_ir_callinfo[IRCALL_lj_str_fromchar]; | 1141 | ci = &lj_ir_callinfo[IRCALL_lj_strfmt_char]; |
| 1142 | } | 1142 | } |
| 1143 | asm_setupresult(as, ir, ci); /* GCstr * */ | 1143 | asm_setupresult(as, ir, ci); /* GCstr * */ |
| 1144 | asm_gencall(as, ci, args); | 1144 | asm_gencall(as, ci, args); |
diff --git a/src/lj_bcwrite.c b/src/lj_bcwrite.c index b3289a13..c95086c7 100644 --- a/src/lj_bcwrite.c +++ b/src/lj_bcwrite.c | |||
| @@ -9,7 +9,6 @@ | |||
| 9 | #include "lj_obj.h" | 9 | #include "lj_obj.h" |
| 10 | #include "lj_gc.h" | 10 | #include "lj_gc.h" |
| 11 | #include "lj_buf.h" | 11 | #include "lj_buf.h" |
| 12 | #include "lj_str.h" | ||
| 13 | #include "lj_bc.h" | 12 | #include "lj_bc.h" |
| 14 | #if LJ_HASFFI | 13 | #if LJ_HASFFI |
| 15 | #include "lj_ctype.h" | 14 | #include "lj_ctype.h" |
| @@ -18,6 +17,7 @@ | |||
| 18 | #include "lj_dispatch.h" | 17 | #include "lj_dispatch.h" |
| 19 | #include "lj_jit.h" | 18 | #include "lj_jit.h" |
| 20 | #endif | 19 | #endif |
| 20 | #include "lj_strfmt.h" | ||
| 21 | #include "lj_bcdump.h" | 21 | #include "lj_bcdump.h" |
| 22 | #include "lj_vm.h" | 22 | #include "lj_vm.h" |
| 23 | 23 | ||
| @@ -41,25 +41,25 @@ static void bcwrite_ktabk(BCWriteCtx *ctx, cTValue *o, int narrow) | |||
| 41 | const GCstr *str = strV(o); | 41 | const GCstr *str = strV(o); |
| 42 | MSize len = str->len; | 42 | MSize len = str->len; |
| 43 | p = lj_buf_more(&ctx->sb, 5+len); | 43 | p = lj_buf_more(&ctx->sb, 5+len); |
| 44 | p = lj_buf_wuleb128(p, BCDUMP_KTAB_STR+len); | 44 | p = lj_strfmt_wuleb128(p, BCDUMP_KTAB_STR+len); |
| 45 | p = lj_buf_wmem(p, strdata(str), len); | 45 | p = lj_buf_wmem(p, strdata(str), len); |
| 46 | } else if (tvisint(o)) { | 46 | } else if (tvisint(o)) { |
| 47 | *p++ = BCDUMP_KTAB_INT; | 47 | *p++ = BCDUMP_KTAB_INT; |
| 48 | p = lj_buf_wuleb128(p, intV(o)); | 48 | p = lj_strfmt_wuleb128(p, intV(o)); |
| 49 | } else if (tvisnum(o)) { | 49 | } else if (tvisnum(o)) { |
| 50 | if (!LJ_DUALNUM && narrow) { /* Narrow number constants to integers. */ | 50 | if (!LJ_DUALNUM && narrow) { /* Narrow number constants to integers. */ |
| 51 | lua_Number num = numV(o); | 51 | lua_Number num = numV(o); |
| 52 | int32_t k = lj_num2int(num); | 52 | int32_t k = lj_num2int(num); |
| 53 | if (num == (lua_Number)k) { /* -0 is never a constant. */ | 53 | if (num == (lua_Number)k) { /* -0 is never a constant. */ |
| 54 | *p++ = BCDUMP_KTAB_INT; | 54 | *p++ = BCDUMP_KTAB_INT; |
| 55 | p = lj_buf_wuleb128(p, k); | 55 | p = lj_strfmt_wuleb128(p, k); |
| 56 | setsbufP(&ctx->sb, p); | 56 | setsbufP(&ctx->sb, p); |
| 57 | return; | 57 | return; |
| 58 | } | 58 | } |
| 59 | } | 59 | } |
| 60 | *p++ = BCDUMP_KTAB_NUM; | 60 | *p++ = BCDUMP_KTAB_NUM; |
| 61 | p = lj_buf_wuleb128(p, o->u32.lo); | 61 | p = lj_strfmt_wuleb128(p, o->u32.lo); |
| 62 | p = lj_buf_wuleb128(p, o->u32.hi); | 62 | p = lj_strfmt_wuleb128(p, o->u32.hi); |
| 63 | } else { | 63 | } else { |
| 64 | lua_assert(tvispri(o)); | 64 | lua_assert(tvispri(o)); |
| 65 | *p++ = BCDUMP_KTAB_NIL+~itype(o); | 65 | *p++ = BCDUMP_KTAB_NIL+~itype(o); |
| @@ -86,8 +86,8 @@ static void bcwrite_ktab(BCWriteCtx *ctx, char *p, const GCtab *t) | |||
| 86 | nhash += !tvisnil(&node[i].val); | 86 | nhash += !tvisnil(&node[i].val); |
| 87 | } | 87 | } |
| 88 | /* Write number of array slots and hash slots. */ | 88 | /* Write number of array slots and hash slots. */ |
| 89 | p = lj_buf_wuleb128(p, narray); | 89 | p = lj_strfmt_wuleb128(p, narray); |
| 90 | p = lj_buf_wuleb128(p, nhash); | 90 | p = lj_strfmt_wuleb128(p, nhash); |
| 91 | setsbufP(&ctx->sb, p); | 91 | setsbufP(&ctx->sb, p); |
| 92 | if (narray) { /* Write array entries (may contain nil). */ | 92 | if (narray) { /* Write array entries (may contain nil). */ |
| 93 | MSize i; | 93 | MSize i; |
| @@ -143,7 +143,7 @@ static void bcwrite_kgc(BCWriteCtx *ctx, GCproto *pt) | |||
| 143 | } | 143 | } |
| 144 | /* Write constant type. */ | 144 | /* Write constant type. */ |
| 145 | p = lj_buf_more(&ctx->sb, need); | 145 | p = lj_buf_more(&ctx->sb, need); |
| 146 | p = lj_buf_wuleb128(p, tp); | 146 | p = lj_strfmt_wuleb128(p, tp); |
| 147 | /* Write constant data (if any). */ | 147 | /* Write constant data (if any). */ |
| 148 | if (tp >= BCDUMP_KGC_STR) { | 148 | if (tp >= BCDUMP_KGC_STR) { |
| 149 | p = lj_buf_wmem(p, strdata(gco2str(o)), gco2str(o)->len); | 149 | p = lj_buf_wmem(p, strdata(gco2str(o)), gco2str(o)->len); |
| @@ -153,11 +153,11 @@ static void bcwrite_kgc(BCWriteCtx *ctx, GCproto *pt) | |||
| 153 | #if LJ_HASFFI | 153 | #if LJ_HASFFI |
| 154 | } else if (tp != BCDUMP_KGC_CHILD) { | 154 | } else if (tp != BCDUMP_KGC_CHILD) { |
| 155 | cTValue *q = (TValue *)cdataptr(gco2cd(o)); | 155 | cTValue *q = (TValue *)cdataptr(gco2cd(o)); |
| 156 | p = lj_buf_wuleb128(p, q[0].u32.lo); | 156 | p = lj_strfmt_wuleb128(p, q[0].u32.lo); |
| 157 | p = lj_buf_wuleb128(p, q[0].u32.hi); | 157 | p = lj_strfmt_wuleb128(p, q[0].u32.hi); |
| 158 | if (tp == BCDUMP_KGC_COMPLEX) { | 158 | if (tp == BCDUMP_KGC_COMPLEX) { |
| 159 | p = lj_buf_wuleb128(p, q[1].u32.lo); | 159 | p = lj_strfmt_wuleb128(p, q[1].u32.lo); |
| 160 | p = lj_buf_wuleb128(p, q[1].u32.hi); | 160 | p = lj_strfmt_wuleb128(p, q[1].u32.hi); |
| 161 | } | 161 | } |
| 162 | #endif | 162 | #endif |
| 163 | } | 163 | } |
| @@ -183,16 +183,16 @@ static void bcwrite_knum(BCWriteCtx *ctx, GCproto *pt) | |||
| 183 | k = lj_num2int(num); | 183 | k = lj_num2int(num); |
| 184 | if (num == (lua_Number)k) { /* -0 is never a constant. */ | 184 | if (num == (lua_Number)k) { /* -0 is never a constant. */ |
| 185 | save_int: | 185 | save_int: |
| 186 | p = lj_buf_wuleb128(p, 2*(uint32_t)k | ((uint32_t)k & 0x80000000u)); | 186 | p = lj_strfmt_wuleb128(p, 2*(uint32_t)k | ((uint32_t)k&0x80000000u)); |
| 187 | if (k < 0) | 187 | if (k < 0) |
| 188 | p[-1] = (p[-1] & 7) | ((k>>27) & 0x18); | 188 | p[-1] = (p[-1] & 7) | ((k>>27) & 0x18); |
| 189 | continue; | 189 | continue; |
| 190 | } | 190 | } |
| 191 | } | 191 | } |
| 192 | p = lj_buf_wuleb128(p, 1+(2*o->u32.lo | (o->u32.lo & 0x80000000u))); | 192 | p = lj_strfmt_wuleb128(p, 1+(2*o->u32.lo | (o->u32.lo & 0x80000000u))); |
| 193 | if (o->u32.lo >= 0x80000000u) | 193 | if (o->u32.lo >= 0x80000000u) |
| 194 | p[-1] = (p[-1] & 7) | ((o->u32.lo>>27) & 0x18); | 194 | p[-1] = (p[-1] & 7) | ((o->u32.lo>>27) & 0x18); |
| 195 | p = lj_buf_wuleb128(p, o->u32.hi); | 195 | p = lj_strfmt_wuleb128(p, o->u32.hi); |
| 196 | } | 196 | } |
| 197 | } | 197 | } |
| 198 | setsbufP(&ctx->sb, p); | 198 | setsbufP(&ctx->sb, p); |
| @@ -257,16 +257,16 @@ static void bcwrite_proto(BCWriteCtx *ctx, GCproto *pt) | |||
| 257 | *p++ = pt->numparams; | 257 | *p++ = pt->numparams; |
| 258 | *p++ = pt->framesize; | 258 | *p++ = pt->framesize; |
| 259 | *p++ = pt->sizeuv; | 259 | *p++ = pt->sizeuv; |
| 260 | p = lj_buf_wuleb128(p, pt->sizekgc); | 260 | p = lj_strfmt_wuleb128(p, pt->sizekgc); |
| 261 | p = lj_buf_wuleb128(p, pt->sizekn); | 261 | p = lj_strfmt_wuleb128(p, pt->sizekn); |
| 262 | p = lj_buf_wuleb128(p, pt->sizebc-1); | 262 | p = lj_strfmt_wuleb128(p, pt->sizebc-1); |
| 263 | if (!ctx->strip) { | 263 | if (!ctx->strip) { |
| 264 | if (proto_lineinfo(pt)) | 264 | if (proto_lineinfo(pt)) |
| 265 | sizedbg = pt->sizept - (MSize)((char *)proto_lineinfo(pt) - (char *)pt); | 265 | sizedbg = pt->sizept - (MSize)((char *)proto_lineinfo(pt) - (char *)pt); |
| 266 | p = lj_buf_wuleb128(p, sizedbg); | 266 | p = lj_strfmt_wuleb128(p, sizedbg); |
| 267 | if (sizedbg) { | 267 | if (sizedbg) { |
| 268 | p = lj_buf_wuleb128(p, pt->firstline); | 268 | p = lj_strfmt_wuleb128(p, pt->firstline); |
| 269 | p = lj_buf_wuleb128(p, pt->numline); | 269 | p = lj_strfmt_wuleb128(p, pt->numline); |
| 270 | } | 270 | } |
| 271 | } | 271 | } |
| 272 | 272 | ||
| @@ -291,7 +291,7 @@ static void bcwrite_proto(BCWriteCtx *ctx, GCproto *pt) | |||
| 291 | MSize n = sbuflen(&ctx->sb) - 5; | 291 | MSize n = sbuflen(&ctx->sb) - 5; |
| 292 | MSize nn = (lj_fls(n)+8)*9 >> 6; | 292 | MSize nn = (lj_fls(n)+8)*9 >> 6; |
| 293 | char *q = sbufB(&ctx->sb) + (5 - nn); | 293 | char *q = sbufB(&ctx->sb) + (5 - nn); |
| 294 | p = lj_buf_wuleb128(q, n); /* Fill in final size. */ | 294 | p = lj_strfmt_wuleb128(q, n); /* Fill in final size. */ |
| 295 | lua_assert(p == sbufB(&ctx->sb) + 5); | 295 | lua_assert(p == sbufB(&ctx->sb) + 5); |
| 296 | ctx->status = ctx->wfunc(sbufL(&ctx->sb), q, nn+n, ctx->wdata); | 296 | ctx->status = ctx->wfunc(sbufL(&ctx->sb), q, nn+n, ctx->wdata); |
| 297 | } | 297 | } |
| @@ -312,7 +312,7 @@ static void bcwrite_header(BCWriteCtx *ctx) | |||
| 312 | (LJ_BE ? BCDUMP_F_BE : 0) + | 312 | (LJ_BE ? BCDUMP_F_BE : 0) + |
| 313 | ((ctx->pt->flags & PROTO_FFI) ? BCDUMP_F_FFI : 0); | 313 | ((ctx->pt->flags & PROTO_FFI) ? BCDUMP_F_FFI : 0); |
| 314 | if (!ctx->strip) { | 314 | if (!ctx->strip) { |
| 315 | p = lj_buf_wuleb128(p, len); | 315 | p = lj_strfmt_wuleb128(p, len); |
| 316 | p = lj_buf_wmem(p, name, len); | 316 | p = lj_buf_wmem(p, name, len); |
| 317 | } | 317 | } |
| 318 | ctx->status = ctx->wfunc(sbufL(&ctx->sb), sbufB(&ctx->sb), | 318 | ctx->status = ctx->wfunc(sbufL(&ctx->sb), sbufB(&ctx->sb), |
diff --git a/src/lj_buf.c b/src/lj_buf.c index c60cc51f..2a1d7f8e 100644 --- a/src/lj_buf.c +++ b/src/lj_buf.c | |||
| @@ -14,6 +14,9 @@ | |||
| 14 | #include "lj_buf.h" | 14 | #include "lj_buf.h" |
| 15 | #include "lj_str.h" | 15 | #include "lj_str.h" |
| 16 | #include "lj_tab.h" | 16 | #include "lj_tab.h" |
| 17 | #include "lj_strfmt.h" | ||
| 18 | |||
| 19 | /* -- Buffer management --------------------------------------------------- */ | ||
| 17 | 20 | ||
| 18 | LJ_NOINLINE void LJ_FASTCALL lj_buf_grow(SBuf *sb, char *en) | 21 | LJ_NOINLINE void LJ_FASTCALL lj_buf_grow(SBuf *sb, char *en) |
| 19 | { | 22 | { |
| @@ -32,13 +35,6 @@ LJ_NOINLINE void LJ_FASTCALL lj_buf_grow(SBuf *sb, char *en) | |||
| 32 | setmref(sb->e, b + nsz); | 35 | setmref(sb->e, b + nsz); |
| 33 | } | 36 | } |
| 34 | 37 | ||
| 35 | char * LJ_FASTCALL lj_buf_tmp(lua_State *L, MSize sz) | ||
| 36 | { | ||
| 37 | SBuf *sb = &G(L)->tmpbuf; | ||
| 38 | setsbufL(sb, L); | ||
| 39 | return lj_buf_need(sb, sz); | ||
| 40 | } | ||
| 41 | |||
| 42 | void LJ_FASTCALL lj_buf_shrink(lua_State *L, SBuf *sb) | 38 | void LJ_FASTCALL lj_buf_shrink(lua_State *L, SBuf *sb) |
| 43 | { | 39 | { |
| 44 | char *b = sbufB(sb); | 40 | char *b = sbufB(sb); |
| @@ -52,6 +48,16 @@ void LJ_FASTCALL lj_buf_shrink(lua_State *L, SBuf *sb) | |||
| 52 | } | 48 | } |
| 53 | } | 49 | } |
| 54 | 50 | ||
| 51 | char * LJ_FASTCALL lj_buf_tmp(lua_State *L, MSize sz) | ||
| 52 | { | ||
| 53 | SBuf *sb = &G(L)->tmpbuf; | ||
| 54 | setsbufL(sb, L); | ||
| 55 | return lj_buf_need(sb, sz); | ||
| 56 | } | ||
| 57 | |||
| 58 | /* -- Low-level buffer put operations ------------------------------------- */ | ||
| 59 | |||
| 60 | /* Write memory block to buffer. */ | ||
| 55 | char *lj_buf_wmem(char *p, const void *q, MSize len) | 61 | char *lj_buf_wmem(char *p, const void *q, MSize len) |
| 56 | { | 62 | { |
| 57 | const char *s = (const char *)q, *e = s + len; | 63 | const char *s = (const char *)q, *e = s + len; |
| @@ -68,15 +74,6 @@ SBuf * lj_buf_putmem(SBuf *sb, const void *q, MSize len) | |||
| 68 | } | 74 | } |
| 69 | 75 | ||
| 70 | #if LJ_HASJIT | 76 | #if LJ_HASJIT |
| 71 | SBuf * LJ_FASTCALL lj_buf_putstr(SBuf *sb, GCstr *s) | ||
| 72 | { | ||
| 73 | MSize len = s->len; | ||
| 74 | char *p = lj_buf_more(sb, len); | ||
| 75 | p = lj_buf_wmem(p, strdata(s), len); | ||
| 76 | setsbufP(sb, p); | ||
| 77 | return sb; | ||
| 78 | } | ||
| 79 | |||
| 80 | SBuf * LJ_FASTCALL lj_buf_putchar(SBuf *sb, int c) | 77 | SBuf * LJ_FASTCALL lj_buf_putchar(SBuf *sb, int c) |
| 81 | { | 78 | { |
| 82 | char *p = lj_buf_more(sb, 1); | 79 | char *p = lj_buf_more(sb, 1); |
| @@ -84,19 +81,18 @@ SBuf * LJ_FASTCALL lj_buf_putchar(SBuf *sb, int c) | |||
| 84 | setsbufP(sb, p); | 81 | setsbufP(sb, p); |
| 85 | return sb; | 82 | return sb; |
| 86 | } | 83 | } |
| 84 | #endif | ||
| 87 | 85 | ||
| 88 | SBuf * LJ_FASTCALL lj_buf_putint(SBuf *sb, int32_t k) | 86 | SBuf * LJ_FASTCALL lj_buf_putstr(SBuf *sb, GCstr *s) |
| 89 | { | 87 | { |
| 90 | setsbufP(sb, lj_str_bufint(lj_buf_more(sb, LJ_STR_INTBUF), k)); | 88 | MSize len = s->len; |
| 89 | char *p = lj_buf_more(sb, len); | ||
| 90 | p = lj_buf_wmem(p, strdata(s), len); | ||
| 91 | setsbufP(sb, p); | ||
| 91 | return sb; | 92 | return sb; |
| 92 | } | 93 | } |
| 93 | 94 | ||
| 94 | SBuf * LJ_FASTCALL lj_buf_putnum(SBuf *sb, cTValue *o) | 95 | /* -- High-level buffer put operations ------------------------------------ */ |
| 95 | { | ||
| 96 | setsbufP(sb, lj_str_bufnum(lj_buf_more(sb, LJ_STR_NUMBUF), o)); | ||
| 97 | return sb; | ||
| 98 | } | ||
| 99 | #endif | ||
| 100 | 96 | ||
| 101 | SBuf * LJ_FASTCALL lj_buf_putstr_reverse(SBuf *sb, GCstr *s) | 97 | SBuf * LJ_FASTCALL lj_buf_putstr_reverse(SBuf *sb, GCstr *s) |
| 102 | { | 98 | { |
| @@ -184,9 +180,9 @@ SBuf *lj_buf_puttab(SBuf *sb, GCtab *t, GCstr *sep, int32_t i, int32_t e) | |||
| 184 | MSize len = strV(o)->len; | 180 | MSize len = strV(o)->len; |
| 185 | p = lj_buf_wmem(lj_buf_more(sb, len + seplen), strVdata(o), len); | 181 | p = lj_buf_wmem(lj_buf_more(sb, len + seplen), strVdata(o), len); |
| 186 | } else if (tvisint(o)) { | 182 | } else if (tvisint(o)) { |
| 187 | p = lj_str_bufint(lj_buf_more(sb, LJ_STR_INTBUF + seplen), intV(o)); | 183 | p = lj_strfmt_wint(lj_buf_more(sb, STRFMT_MAXBUF_INT+seplen), intV(o)); |
| 188 | } else if (tvisnum(o)) { | 184 | } else if (tvisnum(o)) { |
| 189 | p = lj_str_bufnum(lj_buf_more(sb, LJ_STR_NUMBUF + seplen), o); | 185 | p = lj_strfmt_wnum(lj_buf_more(sb, STRFMT_MAXBUF_NUM+seplen), o); |
| 190 | } else { | 186 | } else { |
| 191 | goto badtype; | 187 | goto badtype; |
| 192 | } | 188 | } |
| @@ -201,11 +197,14 @@ SBuf *lj_buf_puttab(SBuf *sb, GCtab *t, GCstr *sep, int32_t i, int32_t e) | |||
| 201 | return sb; | 197 | return sb; |
| 202 | } | 198 | } |
| 203 | 199 | ||
| 200 | /* -- Miscellaneous buffer operations ------------------------------------- */ | ||
| 201 | |||
| 204 | GCstr * LJ_FASTCALL lj_buf_tostr(SBuf *sb) | 202 | GCstr * LJ_FASTCALL lj_buf_tostr(SBuf *sb) |
| 205 | { | 203 | { |
| 206 | return lj_str_new(sbufL(sb), sbufB(sb), sbuflen(sb)); | 204 | return lj_str_new(sbufL(sb), sbufB(sb), sbuflen(sb)); |
| 207 | } | 205 | } |
| 208 | 206 | ||
| 207 | /* Concatenate two strings. */ | ||
| 209 | GCstr *lj_buf_cat2str(lua_State *L, GCstr *s1, GCstr *s2) | 208 | GCstr *lj_buf_cat2str(lua_State *L, GCstr *s1, GCstr *s2) |
| 210 | { | 209 | { |
| 211 | MSize len1 = s1->len, len2 = s2->len; | 210 | MSize len1 = s1->len, len2 = s2->len; |
| @@ -215,6 +214,7 @@ GCstr *lj_buf_cat2str(lua_State *L, GCstr *s1, GCstr *s2) | |||
| 215 | return lj_str_new(L, buf, len1 + len2); | 214 | return lj_str_new(L, buf, len1 + len2); |
| 216 | } | 215 | } |
| 217 | 216 | ||
| 217 | /* Read ULEB128 from buffer. */ | ||
| 218 | uint32_t LJ_FASTCALL lj_buf_ruleb128(const char **pp) | 218 | uint32_t LJ_FASTCALL lj_buf_ruleb128(const char **pp) |
| 219 | { | 219 | { |
| 220 | const uint8_t *p = (const uint8_t *)*pp; | 220 | const uint8_t *p = (const uint8_t *)*pp; |
| @@ -228,11 +228,3 @@ uint32_t LJ_FASTCALL lj_buf_ruleb128(const char **pp) | |||
| 228 | return v; | 228 | return v; |
| 229 | } | 229 | } |
| 230 | 230 | ||
| 231 | char * LJ_FASTCALL lj_buf_wuleb128(char *p, uint32_t v) | ||
| 232 | { | ||
| 233 | for (; v >= 0x80; v >>= 7) | ||
| 234 | *p++ = (char)((v & 0x7f) | 0x80); | ||
| 235 | *p++ = (char)v; | ||
| 236 | return p; | ||
| 237 | } | ||
| 238 | |||
diff --git a/src/lj_buf.h b/src/lj_buf.h index 6931a693..951d39fd 100644 --- a/src/lj_buf.h +++ b/src/lj_buf.h | |||
| @@ -20,28 +20,10 @@ | |||
| 20 | #define setsbufP(sb, q) (setmref((sb)->p, (q))) | 20 | #define setsbufP(sb, q) (setmref((sb)->p, (q))) |
| 21 | #define setsbufL(sb, l) (setmref((sb)->L, (l))) | 21 | #define setsbufL(sb, l) (setmref((sb)->L, (l))) |
| 22 | 22 | ||
| 23 | LJ_FUNC char * LJ_FASTCALL lj_buf_tmp(lua_State *L, MSize sz); | 23 | /* Buffer management */ |
| 24 | LJ_FUNC void LJ_FASTCALL lj_buf_grow(SBuf *sb, char *en); | 24 | LJ_FUNC void LJ_FASTCALL lj_buf_grow(SBuf *sb, char *en); |
| 25 | LJ_FUNC void LJ_FASTCALL lj_buf_shrink(lua_State *L, SBuf *sb); | 25 | LJ_FUNC void LJ_FASTCALL lj_buf_shrink(lua_State *L, SBuf *sb); |
| 26 | 26 | LJ_FUNC char * LJ_FASTCALL lj_buf_tmp(lua_State *L, MSize sz); | |
| 27 | LJ_FUNC char *lj_buf_wmem(char *p, const void *q, MSize len); | ||
| 28 | LJ_FUNC SBuf * lj_buf_putmem(SBuf *sb, const void *q, MSize len); | ||
| 29 | #if LJ_HASJIT | ||
| 30 | LJ_FUNC SBuf * LJ_FASTCALL lj_buf_putstr(SBuf *sb, GCstr *s); | ||
| 31 | LJ_FUNC SBuf * LJ_FASTCALL lj_buf_putchar(SBuf *sb, int c); | ||
| 32 | LJ_FUNC SBuf * LJ_FASTCALL lj_buf_putint(SBuf *sb, int32_t k); | ||
| 33 | LJ_FUNC SBuf * LJ_FASTCALL lj_buf_putnum(SBuf *sb, cTValue *o); | ||
| 34 | #endif | ||
| 35 | LJ_FUNCA SBuf * LJ_FASTCALL lj_buf_putstr_reverse(SBuf *sb, GCstr *s); | ||
| 36 | LJ_FUNCA SBuf * LJ_FASTCALL lj_buf_putstr_lower(SBuf *sb, GCstr *s); | ||
| 37 | LJ_FUNCA SBuf * LJ_FASTCALL lj_buf_putstr_upper(SBuf *sb, GCstr *s); | ||
| 38 | LJ_FUNC SBuf *lj_buf_putstr_rep(SBuf *sb, GCstr *s, int32_t rep); | ||
| 39 | LJ_FUNC SBuf *lj_buf_puttab(SBuf *sb, GCtab *t, GCstr *sep, | ||
| 40 | int32_t i, int32_t e); | ||
| 41 | LJ_FUNCA GCstr * LJ_FASTCALL lj_buf_tostr(SBuf *sb); | ||
| 42 | LJ_FUNC GCstr *lj_buf_cat2str(lua_State *L, GCstr *s1, GCstr *s2); | ||
| 43 | LJ_FUNC uint32_t LJ_FASTCALL lj_buf_ruleb128(const char **pp); | ||
| 44 | LJ_FUNC char * LJ_FASTCALL lj_buf_wuleb128(char *p, uint32_t v); | ||
| 45 | 27 | ||
| 46 | static LJ_AINLINE void lj_buf_init(lua_State *L, SBuf *sb) | 28 | static LJ_AINLINE void lj_buf_init(lua_State *L, SBuf *sb) |
| 47 | { | 29 | { |
| @@ -67,11 +49,6 @@ static LJ_AINLINE void lj_buf_free(global_State *g, SBuf *sb) | |||
| 67 | lj_mem_free(g, sbufB(sb), sbufsz(sb)); | 49 | lj_mem_free(g, sbufB(sb), sbufsz(sb)); |
| 68 | } | 50 | } |
| 69 | 51 | ||
| 70 | static LJ_AINLINE GCstr *lj_buf_str(lua_State *L, SBuf *sb) | ||
| 71 | { | ||
| 72 | return lj_str_new(L, sbufB(sb), sbuflen(sb)); | ||
| 73 | } | ||
| 74 | |||
| 75 | static LJ_AINLINE char *lj_buf_need(SBuf *sb, MSize sz) | 52 | static LJ_AINLINE char *lj_buf_need(SBuf *sb, MSize sz) |
| 76 | { | 53 | { |
| 77 | char *en = sbufB(sb) + sz; | 54 | char *en = sbufB(sb) + sz; |
| @@ -88,6 +65,14 @@ static LJ_AINLINE char *lj_buf_more(SBuf *sb, MSize sz) | |||
| 88 | return sbufP(sb); | 65 | return sbufP(sb); |
| 89 | } | 66 | } |
| 90 | 67 | ||
| 68 | /* Low-level buffer put operations */ | ||
| 69 | LJ_FUNC char *lj_buf_wmem(char *p, const void *q, MSize len); | ||
| 70 | LJ_FUNC SBuf * lj_buf_putmem(SBuf *sb, const void *q, MSize len); | ||
| 71 | #if LJ_HASJIT | ||
| 72 | LJ_FUNC SBuf * LJ_FASTCALL lj_buf_putchar(SBuf *sb, int c); | ||
| 73 | #endif | ||
| 74 | LJ_FUNC SBuf * LJ_FASTCALL lj_buf_putstr(SBuf *sb, GCstr *s); | ||
| 75 | |||
| 91 | static LJ_AINLINE void lj_buf_putb(SBuf *sb, int c) | 76 | static LJ_AINLINE void lj_buf_putb(SBuf *sb, int c) |
| 92 | { | 77 | { |
| 93 | char *p = lj_buf_more(sb, 1); | 78 | char *p = lj_buf_more(sb, 1); |
| @@ -95,4 +80,22 @@ static LJ_AINLINE void lj_buf_putb(SBuf *sb, int c) | |||
| 95 | setsbufP(sb, p); | 80 | setsbufP(sb, p); |
| 96 | } | 81 | } |
| 97 | 82 | ||
| 83 | /* High-level buffer put operations */ | ||
| 84 | LJ_FUNCA SBuf * LJ_FASTCALL lj_buf_putstr_reverse(SBuf *sb, GCstr *s); | ||
| 85 | LJ_FUNCA SBuf * LJ_FASTCALL lj_buf_putstr_lower(SBuf *sb, GCstr *s); | ||
| 86 | LJ_FUNCA SBuf * LJ_FASTCALL lj_buf_putstr_upper(SBuf *sb, GCstr *s); | ||
| 87 | LJ_FUNC SBuf *lj_buf_putstr_rep(SBuf *sb, GCstr *s, int32_t rep); | ||
| 88 | LJ_FUNC SBuf *lj_buf_puttab(SBuf *sb, GCtab *t, GCstr *sep, | ||
| 89 | int32_t i, int32_t e); | ||
| 90 | |||
| 91 | /* Miscellaneous buffer operations */ | ||
| 92 | LJ_FUNCA GCstr * LJ_FASTCALL lj_buf_tostr(SBuf *sb); | ||
| 93 | LJ_FUNC GCstr *lj_buf_cat2str(lua_State *L, GCstr *s1, GCstr *s2); | ||
| 94 | LJ_FUNC uint32_t LJ_FASTCALL lj_buf_ruleb128(const char **pp); | ||
| 95 | |||
| 96 | static LJ_AINLINE GCstr *lj_buf_str(lua_State *L, SBuf *sb) | ||
| 97 | { | ||
| 98 | return lj_str_new(L, sbufB(sb), sbuflen(sb)); | ||
| 99 | } | ||
| 100 | |||
| 98 | #endif | 101 | #endif |
diff --git a/src/lj_ccall.c b/src/lj_ccall.c index 6196364a..34866dd2 100644 --- a/src/lj_ccall.c +++ b/src/lj_ccall.c | |||
| @@ -9,7 +9,6 @@ | |||
| 9 | 9 | ||
| 10 | #include "lj_gc.h" | 10 | #include "lj_gc.h" |
| 11 | #include "lj_err.h" | 11 | #include "lj_err.h" |
| 12 | #include "lj_str.h" | ||
| 13 | #include "lj_tab.h" | 12 | #include "lj_tab.h" |
| 14 | #include "lj_ctype.h" | 13 | #include "lj_ctype.h" |
| 15 | #include "lj_cconv.h" | 14 | #include "lj_cconv.h" |
diff --git a/src/lj_cdata.c b/src/lj_cdata.c index 10f4809c..caa9a8f5 100644 --- a/src/lj_cdata.c +++ b/src/lj_cdata.c | |||
| @@ -9,7 +9,6 @@ | |||
| 9 | 9 | ||
| 10 | #include "lj_gc.h" | 10 | #include "lj_gc.h" |
| 11 | #include "lj_err.h" | 11 | #include "lj_err.h" |
| 12 | #include "lj_str.h" | ||
| 13 | #include "lj_tab.h" | 12 | #include "lj_tab.h" |
| 14 | #include "lj_ctype.h" | 13 | #include "lj_ctype.h" |
| 15 | #include "lj_cconv.h" | 14 | #include "lj_cconv.h" |
diff --git a/src/lj_cparse.c b/src/lj_cparse.c index 484a2c15..4392b7c4 100644 --- a/src/lj_cparse.c +++ b/src/lj_cparse.c | |||
| @@ -10,7 +10,6 @@ | |||
| 10 | #include "lj_gc.h" | 10 | #include "lj_gc.h" |
| 11 | #include "lj_err.h" | 11 | #include "lj_err.h" |
| 12 | #include "lj_buf.h" | 12 | #include "lj_buf.h" |
| 13 | #include "lj_str.h" | ||
| 14 | #include "lj_ctype.h" | 13 | #include "lj_ctype.h" |
| 15 | #include "lj_cparse.h" | 14 | #include "lj_cparse.h" |
| 16 | #include "lj_frame.h" | 15 | #include "lj_frame.h" |
diff --git a/src/lj_crecord.c b/src/lj_crecord.c index c4f138c3..398ca2a7 100644 --- a/src/lj_crecord.c +++ b/src/lj_crecord.c | |||
| @@ -11,7 +11,6 @@ | |||
| 11 | #if LJ_HASJIT && LJ_HASFFI | 11 | #if LJ_HASJIT && LJ_HASFFI |
| 12 | 12 | ||
| 13 | #include "lj_err.h" | 13 | #include "lj_err.h" |
| 14 | #include "lj_str.h" | ||
| 15 | #include "lj_tab.h" | 14 | #include "lj_tab.h" |
| 16 | #include "lj_frame.h" | 15 | #include "lj_frame.h" |
| 17 | #include "lj_ctype.h" | 16 | #include "lj_ctype.h" |
diff --git a/src/lj_ctype.c b/src/lj_ctype.c index f9e75fd1..19a79c45 100644 --- a/src/lj_ctype.c +++ b/src/lj_ctype.c | |||
| @@ -11,6 +11,7 @@ | |||
| 11 | #include "lj_err.h" | 11 | #include "lj_err.h" |
| 12 | #include "lj_str.h" | 12 | #include "lj_str.h" |
| 13 | #include "lj_tab.h" | 13 | #include "lj_tab.h" |
| 14 | #include "lj_strfmt.h" | ||
| 14 | #include "lj_ctype.h" | 15 | #include "lj_ctype.h" |
| 15 | #include "lj_ccallback.h" | 16 | #include "lj_ccallback.h" |
| 16 | 17 | ||
| @@ -568,16 +569,16 @@ GCstr *lj_ctype_repr_int64(lua_State *L, uint64_t n, int isunsigned) | |||
| 568 | /* Convert complex to string with 'i' or 'I' suffix. */ | 569 | /* Convert complex to string with 'i' or 'I' suffix. */ |
| 569 | GCstr *lj_ctype_repr_complex(lua_State *L, void *sp, CTSize size) | 570 | GCstr *lj_ctype_repr_complex(lua_State *L, void *sp, CTSize size) |
| 570 | { | 571 | { |
| 571 | char buf[2*LJ_STR_NUMBUF+2+1], *p = buf; | 572 | char buf[2*STRFMT_MAXBUF_NUM+2+1], *p = buf; |
| 572 | TValue re, im; | 573 | TValue re, im; |
| 573 | if (size == 2*sizeof(double)) { | 574 | if (size == 2*sizeof(double)) { |
| 574 | re.n = *(double *)sp; im.n = ((double *)sp)[1]; | 575 | re.n = *(double *)sp; im.n = ((double *)sp)[1]; |
| 575 | } else { | 576 | } else { |
| 576 | re.n = (double)*(float *)sp; im.n = (double)((float *)sp)[1]; | 577 | re.n = (double)*(float *)sp; im.n = (double)((float *)sp)[1]; |
| 577 | } | 578 | } |
| 578 | p = lj_str_bufnum(p, &re); | 579 | p = lj_strfmt_wnum(p, &re); |
| 579 | if (!(im.u32.hi & 0x80000000u) || im.n != im.n) *p++ = '+'; | 580 | if (!(im.u32.hi & 0x80000000u) || im.n != im.n) *p++ = '+'; |
| 580 | p = lj_str_bufnum(p, &im); | 581 | p = lj_strfmt_wnum(p, &im); |
| 581 | *p = *(p-1) >= 'a' ? 'I' : 'i'; | 582 | *p = *(p-1) >= 'a' ? 'I' : 'i'; |
| 582 | p++; | 583 | p++; |
| 583 | return lj_str_new(L, buf, p-buf); | 584 | return lj_str_new(L, buf, p-buf); |
diff --git a/src/lj_debug.c b/src/lj_debug.c index 48364069..54f7db74 100644 --- a/src/lj_debug.c +++ b/src/lj_debug.c | |||
| @@ -10,7 +10,6 @@ | |||
| 10 | #include "lj_err.h" | 10 | #include "lj_err.h" |
| 11 | #include "lj_debug.h" | 11 | #include "lj_debug.h" |
| 12 | #include "lj_buf.h" | 12 | #include "lj_buf.h" |
| 13 | #include "lj_str.h" | ||
| 14 | #include "lj_tab.h" | 13 | #include "lj_tab.h" |
| 15 | #include "lj_state.h" | 14 | #include "lj_state.h" |
| 16 | #include "lj_frame.h" | 15 | #include "lj_frame.h" |
diff --git a/src/lj_dispatch.c b/src/lj_dispatch.c index c144afce..a78075a7 100644 --- a/src/lj_dispatch.c +++ b/src/lj_dispatch.c | |||
| @@ -18,6 +18,7 @@ | |||
| 18 | #include "lj_frame.h" | 18 | #include "lj_frame.h" |
| 19 | #include "lj_bc.h" | 19 | #include "lj_bc.h" |
| 20 | #include "lj_ff.h" | 20 | #include "lj_ff.h" |
| 21 | #include "lj_strfmt.h" | ||
| 21 | #if LJ_HASJIT | 22 | #if LJ_HASJIT |
| 22 | #include "lj_jit.h" | 23 | #include "lj_jit.h" |
| 23 | #endif | 24 | #endif |
diff --git a/src/lj_dispatch.h b/src/lj_dispatch.h index 1ca29329..326297cd 100644 --- a/src/lj_dispatch.h +++ b/src/lj_dispatch.h | |||
| @@ -34,7 +34,7 @@ | |||
| 34 | _(lj_gc_barrieruv) _(lj_gc_step) _(lj_gc_step_fixtop) _(lj_meta_arith) \ | 34 | _(lj_gc_barrieruv) _(lj_gc_step) _(lj_gc_step_fixtop) _(lj_meta_arith) \ |
| 35 | _(lj_meta_call) _(lj_meta_cat) _(lj_meta_comp) _(lj_meta_equal) \ | 35 | _(lj_meta_call) _(lj_meta_cat) _(lj_meta_comp) _(lj_meta_equal) \ |
| 36 | _(lj_meta_for) _(lj_meta_istype) _(lj_meta_len) _(lj_meta_tget) \ | 36 | _(lj_meta_for) _(lj_meta_istype) _(lj_meta_len) _(lj_meta_tget) \ |
| 37 | _(lj_meta_tset) _(lj_state_growstack) _(lj_str_fromnum) _(lj_str_fromnumber) \ | 37 | _(lj_meta_tset) _(lj_state_growstack) _(lj_strfmt_num) \ |
| 38 | _(lj_str_new) _(lj_tab_dup) _(lj_tab_get) _(lj_tab_getinth) _(lj_tab_len) \ | 38 | _(lj_str_new) _(lj_tab_dup) _(lj_tab_get) _(lj_tab_getinth) _(lj_tab_len) \ |
| 39 | _(lj_tab_new) _(lj_tab_newkey) _(lj_tab_next) _(lj_tab_reasize) \ | 39 | _(lj_tab_new) _(lj_tab_newkey) _(lj_tab_next) _(lj_tab_reasize) \ |
| 40 | _(lj_tab_setinth) _(lj_buf_putstr_reverse) _(lj_buf_putstr_lower) \ | 40 | _(lj_tab_setinth) _(lj_buf_putstr_reverse) _(lj_buf_putstr_lower) \ |
diff --git a/src/lj_ffrecord.c b/src/lj_ffrecord.c index bebcf08b..dd8912ee 100644 --- a/src/lj_ffrecord.c +++ b/src/lj_ffrecord.c | |||
| @@ -80,7 +80,7 @@ static GCstr *argv2str(jit_State *J, TValue *o) | |||
| 80 | GCstr *s; | 80 | GCstr *s; |
| 81 | if (!tvisnumber(o)) | 81 | if (!tvisnumber(o)) |
| 82 | lj_trace_err(J, LJ_TRERR_BADTYPE); | 82 | lj_trace_err(J, LJ_TRERR_BADTYPE); |
| 83 | s = lj_str_fromnumber(J->L, o); | 83 | s = lj_strfmt_number(J->L, o); |
| 84 | setstrV(J->L, o, s); | 84 | setstrV(J->L, o, s); |
| 85 | return s; | 85 | return s; |
| 86 | } | 86 | } |
diff --git a/src/lj_gdbjit.c b/src/lj_gdbjit.c index 334a906e..4dbc9593 100644 --- a/src/lj_gdbjit.c +++ b/src/lj_gdbjit.c | |||
| @@ -15,6 +15,7 @@ | |||
| 15 | #include "lj_debug.h" | 15 | #include "lj_debug.h" |
| 16 | #include "lj_frame.h" | 16 | #include "lj_frame.h" |
| 17 | #include "lj_buf.h" | 17 | #include "lj_buf.h" |
| 18 | #include "lj_strfmt.h" | ||
| 18 | #include "lj_jit.h" | 19 | #include "lj_jit.h" |
| 19 | #include "lj_dispatch.h" | 20 | #include "lj_dispatch.h" |
| 20 | 21 | ||
| @@ -443,7 +444,7 @@ static void gdbjit_sleb128(GDBJITctx *ctx, int32_t v) | |||
| 443 | #define DU16(x) (*(uint16_t *)p = (x), p += 2) | 444 | #define DU16(x) (*(uint16_t *)p = (x), p += 2) |
| 444 | #define DU32(x) (*(uint32_t *)p = (x), p += 4) | 445 | #define DU32(x) (*(uint32_t *)p = (x), p += 4) |
| 445 | #define DADDR(x) (*(uintptr_t *)p = (x), p += sizeof(uintptr_t)) | 446 | #define DADDR(x) (*(uintptr_t *)p = (x), p += sizeof(uintptr_t)) |
| 446 | #define DUV(x) (p = (uint8_t *)lj_buf_wuleb128((char *)p, (x))) | 447 | #define DUV(x) (p = (uint8_t *)lj_strfmt_wuleb128((char *)p, (x))) |
| 447 | #define DSV(x) (ctx->p = p, gdbjit_sleb128(ctx, (x)), p = ctx->p) | 448 | #define DSV(x) (ctx->p = p, gdbjit_sleb128(ctx, (x)), p = ctx->p) |
| 448 | #define DSTR(str) (ctx->p = p, gdbjit_strz(ctx, (str)), p = ctx->p) | 449 | #define DSTR(str) (ctx->p = p, gdbjit_strz(ctx, (str)), p = ctx->p) |
| 449 | #define DALIGNNOP(s) while ((uintptr_t)p & ((s)-1)) *p++ = DW_CFA_nop | 450 | #define DALIGNNOP(s) while ((uintptr_t)p & ((s)-1)) *p++ = DW_CFA_nop |
diff --git a/src/lj_ir.c b/src/lj_ir.c index 0ac9d0e6..fc2fc2ce 100644 --- a/src/lj_ir.c +++ b/src/lj_ir.c | |||
| @@ -30,6 +30,7 @@ | |||
| 30 | #endif | 30 | #endif |
| 31 | #include "lj_vm.h" | 31 | #include "lj_vm.h" |
| 32 | #include "lj_strscan.h" | 32 | #include "lj_strscan.h" |
| 33 | #include "lj_strfmt.h" | ||
| 33 | #include "lj_lib.h" | 34 | #include "lj_lib.h" |
| 34 | 35 | ||
| 35 | /* Some local macros to save typing. Undef'd at the end. */ | 36 | /* Some local macros to save typing. Undef'd at the end. */ |
diff --git a/src/lj_ircall.h b/src/lj_ircall.h index 03563cd6..bf83a3b3 100644 --- a/src/lj_ircall.h +++ b/src/lj_ircall.h | |||
| @@ -104,14 +104,14 @@ typedef struct CCallInfo { | |||
| 104 | _(ANY, lj_str_find, 4, N, P32, 0) \ | 104 | _(ANY, lj_str_find, 4, N, P32, 0) \ |
| 105 | _(ANY, lj_str_new, 3, S, STR, CCI_L) \ | 105 | _(ANY, lj_str_new, 3, S, STR, CCI_L) \ |
| 106 | _(ANY, lj_strscan_num, 2, FN, INT, 0) \ | 106 | _(ANY, lj_strscan_num, 2, FN, INT, 0) \ |
| 107 | _(ANY, lj_str_fromint, 2, FN, STR, CCI_L) \ | 107 | _(ANY, lj_strfmt_int, 2, FN, STR, CCI_L) \ |
| 108 | _(ANY, lj_str_fromnum, 2, FN, STR, CCI_L) \ | 108 | _(ANY, lj_strfmt_num, 2, FN, STR, CCI_L) \ |
| 109 | _(ANY, lj_str_fromchar, 2, FN, STR, CCI_L) \ | 109 | _(ANY, lj_strfmt_char, 2, FN, STR, CCI_L) \ |
| 110 | _(ANY, lj_strfmt_putint, 2, FL, P32, 0) \ | ||
| 111 | _(ANY, lj_strfmt_putnum, 2, FL, P32, 0) \ | ||
| 110 | _(ANY, lj_buf_putmem, 3, S, P32, 0) \ | 112 | _(ANY, lj_buf_putmem, 3, S, P32, 0) \ |
| 111 | _(ANY, lj_buf_putstr, 2, FL, P32, 0) \ | 113 | _(ANY, lj_buf_putstr, 2, FL, P32, 0) \ |
| 112 | _(ANY, lj_buf_putchar, 2, FL, P32, 0) \ | 114 | _(ANY, lj_buf_putchar, 2, FL, P32, 0) \ |
| 113 | _(ANY, lj_buf_putint, 2, FL, P32, 0) \ | ||
| 114 | _(ANY, lj_buf_putnum, 2, FL, P32, 0) \ | ||
| 115 | _(ANY, lj_buf_putstr_reverse, 2, FL, P32, 0) \ | 115 | _(ANY, lj_buf_putstr_reverse, 2, FL, P32, 0) \ |
| 116 | _(ANY, lj_buf_putstr_lower, 2, FL, P32, 0) \ | 116 | _(ANY, lj_buf_putstr_lower, 2, FL, P32, 0) \ |
| 117 | _(ANY, lj_buf_putstr_upper, 2, FL, P32, 0) \ | 117 | _(ANY, lj_buf_putstr_upper, 2, FL, P32, 0) \ |
diff --git a/src/lj_lib.c b/src/lj_lib.c index a4bde57a..bdbaba1d 100644 --- a/src/lj_lib.c +++ b/src/lj_lib.c | |||
| @@ -18,6 +18,7 @@ | |||
| 18 | #include "lj_dispatch.h" | 18 | #include "lj_dispatch.h" |
| 19 | #include "lj_vm.h" | 19 | #include "lj_vm.h" |
| 20 | #include "lj_strscan.h" | 20 | #include "lj_strscan.h" |
| 21 | #include "lj_strfmt.h" | ||
| 21 | #include "lj_lex.h" | 22 | #include "lj_lex.h" |
| 22 | #include "lj_bcdump.h" | 23 | #include "lj_bcdump.h" |
| 23 | #include "lj_lib.h" | 24 | #include "lj_lib.h" |
| @@ -164,7 +165,7 @@ GCstr *lj_lib_checkstr(lua_State *L, int narg) | |||
| 164 | if (LJ_LIKELY(tvisstr(o))) { | 165 | if (LJ_LIKELY(tvisstr(o))) { |
| 165 | return strV(o); | 166 | return strV(o); |
| 166 | } else if (tvisnumber(o)) { | 167 | } else if (tvisnumber(o)) { |
| 167 | GCstr *s = lj_str_fromnumber(L, o); | 168 | GCstr *s = lj_strfmt_number(L, o); |
| 168 | setstrV(L, o, s); | 169 | setstrV(L, o, s); |
| 169 | return s; | 170 | return s; |
| 170 | } | 171 | } |
diff --git a/src/lj_load.c b/src/lj_load.c index b5cbb3ba..37dde79f 100644 --- a/src/lj_load.c +++ b/src/lj_load.c | |||
| @@ -16,7 +16,6 @@ | |||
| 16 | #include "lj_gc.h" | 16 | #include "lj_gc.h" |
| 17 | #include "lj_err.h" | 17 | #include "lj_err.h" |
| 18 | #include "lj_buf.h" | 18 | #include "lj_buf.h" |
| 19 | #include "lj_str.h" | ||
| 20 | #include "lj_func.h" | 19 | #include "lj_func.h" |
| 21 | #include "lj_frame.h" | 20 | #include "lj_frame.h" |
| 22 | #include "lj_vm.h" | 21 | #include "lj_vm.h" |
diff --git a/src/lj_meta.c b/src/lj_meta.c index 2601af94..6cbfd927 100644 --- a/src/lj_meta.c +++ b/src/lj_meta.c | |||
| @@ -20,6 +20,7 @@ | |||
| 20 | #include "lj_bc.h" | 20 | #include "lj_bc.h" |
| 21 | #include "lj_vm.h" | 21 | #include "lj_vm.h" |
| 22 | #include "lj_strscan.h" | 22 | #include "lj_strscan.h" |
| 23 | #include "lj_strfmt.h" | ||
| 23 | #include "lj_lib.h" | 24 | #include "lj_lib.h" |
| 24 | 25 | ||
| 25 | /* -- Metamethod handling ------------------------------------------------- */ | 26 | /* -- Metamethod handling ------------------------------------------------- */ |
| @@ -269,10 +270,10 @@ TValue *lj_meta_cat(lua_State *L, TValue *top, int left) | |||
| 269 | ** next step: [...][CAT stack ............] | 270 | ** next step: [...][CAT stack ............] |
| 270 | */ | 271 | */ |
| 271 | TValue *e, *o = top; | 272 | TValue *e, *o = top; |
| 272 | uint64_t tlen = tvisstr(o) ? strV(o)->len : LJ_STR_NUMBERBUF; | 273 | uint64_t tlen = tvisstr(o) ? strV(o)->len : STRFMT_MAXBUF_NUM; |
| 273 | char *p, *buf; | 274 | char *p, *buf; |
| 274 | do { | 275 | do { |
| 275 | o--; tlen += tvisstr(o) ? strV(o)->len : LJ_STR_NUMBERBUF; | 276 | o--; tlen += tvisstr(o) ? strV(o)->len : STRFMT_MAXBUF_NUM; |
| 276 | } while (--left > 0 && (tvisstr(o-1) || tvisnumber(o-1))); | 277 | } while (--left > 0 && (tvisstr(o-1) || tvisnumber(o-1))); |
| 277 | if (tlen >= LJ_MAX_STR) lj_err_msg(L, LJ_ERR_STROV); | 278 | if (tlen >= LJ_MAX_STR) lj_err_msg(L, LJ_ERR_STROV); |
| 278 | p = buf = lj_buf_tmp(L, (MSize)tlen); | 279 | p = buf = lj_buf_tmp(L, (MSize)tlen); |
| @@ -282,10 +283,10 @@ TValue *lj_meta_cat(lua_State *L, TValue *top, int left) | |||
| 282 | MSize len = s->len; | 283 | MSize len = s->len; |
| 283 | p = lj_buf_wmem(p, strdata(s), len); | 284 | p = lj_buf_wmem(p, strdata(s), len); |
| 284 | } else if (tvisint(o)) { | 285 | } else if (tvisint(o)) { |
| 285 | p = lj_str_bufint(p, intV(o)); | 286 | p = lj_strfmt_wint(p, intV(o)); |
| 286 | } else { | 287 | } else { |
| 287 | lua_assert(tvisnum(o)); | 288 | lua_assert(tvisnum(o)); |
| 288 | p = lj_str_bufnum(p, o); | 289 | p = lj_strfmt_wnum(p, o); |
| 289 | } | 290 | } |
| 290 | } | 291 | } |
| 291 | setstrV(L, top, lj_str_new(L, buf, (size_t)(p-buf))); | 292 | setstrV(L, top, lj_str_new(L, buf, (size_t)(p-buf))); |
diff --git a/src/lj_opt_fold.c b/src/lj_opt_fold.c index d8b6e884..e2ac28f2 100644 --- a/src/lj_opt_fold.c +++ b/src/lj_opt_fold.c | |||
| @@ -28,6 +28,7 @@ | |||
| 28 | #endif | 28 | #endif |
| 29 | #include "lj_vm.h" | 29 | #include "lj_vm.h" |
| 30 | #include "lj_strscan.h" | 30 | #include "lj_strscan.h" |
| 31 | #include "lj_strfmt.h" | ||
| 31 | 32 | ||
| 32 | /* Here's a short description how the FOLD engine processes instructions: | 33 | /* Here's a short description how the FOLD engine processes instructions: |
| 33 | ** | 34 | ** |
| @@ -809,15 +810,15 @@ LJFOLDF(kfold_conv_knum_u64_num) | |||
| 809 | LJFOLD(TOSTR KNUM any) | 810 | LJFOLD(TOSTR KNUM any) |
| 810 | LJFOLDF(kfold_tostr_knum) | 811 | LJFOLDF(kfold_tostr_knum) |
| 811 | { | 812 | { |
| 812 | return lj_ir_kstr(J, lj_str_fromnum(J->L, &knumleft)); | 813 | return lj_ir_kstr(J, lj_strfmt_num(J->L, ir_knum(fleft))); |
| 813 | } | 814 | } |
| 814 | 815 | ||
| 815 | LJFOLD(TOSTR KINT any) | 816 | LJFOLD(TOSTR KINT any) |
| 816 | LJFOLDF(kfold_tostr_kint) | 817 | LJFOLDF(kfold_tostr_kint) |
| 817 | { | 818 | { |
| 818 | return lj_ir_kstr(J, fins->op2 == IRTOSTR_INT ? | 819 | return lj_ir_kstr(J, fins->op2 == IRTOSTR_INT ? |
| 819 | lj_str_fromint(J->L, fleft->i) : | 820 | lj_strfmt_int(J->L, fleft->i) : |
| 820 | lj_str_fromchar(J->L, fleft->i)); | 821 | lj_strfmt_char(J->L, fleft->i)); |
| 821 | } | 822 | } |
| 822 | 823 | ||
| 823 | LJFOLD(STRTO KGC) | 824 | LJFOLD(STRTO KGC) |
diff --git a/src/lj_opt_loop.c b/src/lj_opt_loop.c index 2d574089..9637263c 100644 --- a/src/lj_opt_loop.c +++ b/src/lj_opt_loop.c | |||
| @@ -12,7 +12,6 @@ | |||
| 12 | 12 | ||
| 13 | #include "lj_err.h" | 13 | #include "lj_err.h" |
| 14 | #include "lj_buf.h" | 14 | #include "lj_buf.h" |
| 15 | #include "lj_str.h" | ||
| 16 | #include "lj_ir.h" | 15 | #include "lj_ir.h" |
| 17 | #include "lj_jit.h" | 16 | #include "lj_jit.h" |
| 18 | #include "lj_iropt.h" | 17 | #include "lj_iropt.h" |
diff --git a/src/lj_opt_split.c b/src/lj_opt_split.c index 6ab509eb..89db0e92 100644 --- a/src/lj_opt_split.c +++ b/src/lj_opt_split.c | |||
| @@ -12,7 +12,6 @@ | |||
| 12 | 12 | ||
| 13 | #include "lj_err.h" | 13 | #include "lj_err.h" |
| 14 | #include "lj_buf.h" | 14 | #include "lj_buf.h" |
| 15 | #include "lj_str.h" | ||
| 16 | #include "lj_ir.h" | 15 | #include "lj_ir.h" |
| 17 | #include "lj_jit.h" | 16 | #include "lj_jit.h" |
| 18 | #include "lj_ircall.h" | 17 | #include "lj_ircall.h" |
diff --git a/src/lj_parse.c b/src/lj_parse.c index c1ef2593..cdb89baf 100644 --- a/src/lj_parse.c +++ b/src/lj_parse.c | |||
| @@ -22,6 +22,7 @@ | |||
| 22 | #if LJ_HASFFI | 22 | #if LJ_HASFFI |
| 23 | #include "lj_ctype.h" | 23 | #include "lj_ctype.h" |
| 24 | #endif | 24 | #endif |
| 25 | #include "lj_strfmt.h" | ||
| 25 | #include "lj_lex.h" | 26 | #include "lj_lex.h" |
| 26 | #include "lj_parse.h" | 27 | #include "lj_parse.h" |
| 27 | #include "lj_vm.h" | 28 | #include "lj_vm.h" |
| @@ -1462,8 +1463,8 @@ static size_t fs_prep_var(LexState *ls, FuncState *fs, size_t *ofsvar) | |||
| 1462 | p = lj_buf_wmem(p, strdata(s), len); | 1463 | p = lj_buf_wmem(p, strdata(s), len); |
| 1463 | } | 1464 | } |
| 1464 | startpc = vs->startpc; | 1465 | startpc = vs->startpc; |
| 1465 | p = lj_buf_wuleb128(p, startpc-lastpc); | 1466 | p = lj_strfmt_wuleb128(p, startpc-lastpc); |
| 1466 | p = lj_buf_wuleb128(p, vs->endpc-startpc); | 1467 | p = lj_strfmt_wuleb128(p, vs->endpc-startpc); |
| 1467 | setsbufP(&ls->sb, p); | 1468 | setsbufP(&ls->sb, p); |
| 1468 | lastpc = startpc; | 1469 | lastpc = startpc; |
| 1469 | } | 1470 | } |
diff --git a/src/lj_record.c b/src/lj_record.c index 76309acd..bdf0212a 100644 --- a/src/lj_record.c +++ b/src/lj_record.c | |||
| @@ -11,7 +11,6 @@ | |||
| 11 | #if LJ_HASJIT | 11 | #if LJ_HASJIT |
| 12 | 12 | ||
| 13 | #include "lj_err.h" | 13 | #include "lj_err.h" |
| 14 | #include "lj_buf.h" | ||
| 15 | #include "lj_str.h" | 14 | #include "lj_str.h" |
| 16 | #include "lj_tab.h" | 15 | #include "lj_tab.h" |
| 17 | #include "lj_meta.h" | 16 | #include "lj_meta.h" |
diff --git a/src/lj_str.c b/src/lj_str.c index d21cecd0..24d96067 100644 --- a/src/lj_str.c +++ b/src/lj_str.c | |||
| @@ -11,7 +11,6 @@ | |||
| 11 | #include "lj_obj.h" | 11 | #include "lj_obj.h" |
| 12 | #include "lj_gc.h" | 12 | #include "lj_gc.h" |
| 13 | #include "lj_err.h" | 13 | #include "lj_err.h" |
| 14 | #include "lj_buf.h" | ||
| 15 | #include "lj_str.h" | 14 | #include "lj_str.h" |
| 16 | #include "lj_char.h" | 15 | #include "lj_char.h" |
| 17 | 16 | ||
| @@ -198,120 +197,3 @@ void LJ_FASTCALL lj_str_free(global_State *g, GCstr *s) | |||
| 198 | lj_mem_free(g, s, sizestring(s)); | 197 | lj_mem_free(g, s, sizestring(s)); |
| 199 | } | 198 | } |
| 200 | 199 | ||
| 201 | /* -- Type conversions ---------------------------------------------------- */ | ||
| 202 | |||
| 203 | /* Print number to buffer. Canonicalizes non-finite values. */ | ||
| 204 | char * LJ_FASTCALL lj_str_bufnum(char *p, cTValue *o) | ||
| 205 | { | ||
| 206 | if (LJ_LIKELY((o->u32.hi << 1) < 0xffe00000)) { /* Finite? */ | ||
| 207 | #if __BIONIC__ | ||
| 208 | if (tvismzero(o)) { *p++ = '-'; *p++ = '0'; return p; } | ||
| 209 | #endif | ||
| 210 | return p + lua_number2str(p, o->n); | ||
| 211 | } else if (((o->u32.hi & 0x000fffff) | o->u32.lo) != 0) { | ||
| 212 | *p++ = 'n'; *p++ = 'a'; *p++ = 'n'; | ||
| 213 | } else if ((o->u32.hi & 0x80000000) == 0) { | ||
| 214 | *p++ = 'i'; *p++ = 'n'; *p++ = 'f'; | ||
| 215 | } else { | ||
| 216 | *p++ = '-'; *p++ = 'i'; *p++ = 'n'; *p++ = 'f'; | ||
| 217 | } | ||
| 218 | return p; | ||
| 219 | } | ||
| 220 | |||
| 221 | #define STR_BUFINT_R(x, sh, sc) \ | ||
| 222 | { uint32_t d = (x*(((1<<sh)+sc-1)/sc))>>sh; x -= d*sc; *p++ = (char)('0'+d); } | ||
| 223 | |||
| 224 | /* Print integer to buffer. */ | ||
| 225 | char * LJ_FASTCALL lj_str_bufint(char *p, int32_t k) | ||
| 226 | { | ||
| 227 | uint32_t u = (uint32_t)k; | ||
| 228 | if (k < 0) { u = (uint32_t)-k; *p++ = '-'; } | ||
| 229 | if (u < 10000) { | ||
| 230 | if (u < 10) goto dig1; if (u < 100) goto dig2; if (u < 1000) goto dig3; | ||
| 231 | } else { | ||
| 232 | uint32_t v = u / 10000; u -= v * 10000; | ||
| 233 | if (v < 10000) { | ||
| 234 | if (v < 10) goto dig5; if (v < 100) goto dig6; if (v < 1000) goto dig7; | ||
| 235 | } else { | ||
| 236 | uint32_t w = v / 10000; v -= w * 10000; | ||
| 237 | if (w >= 10) STR_BUFINT_R(w, 10, 10) | ||
| 238 | *p++ = (char)('0'+w); | ||
| 239 | } | ||
| 240 | STR_BUFINT_R(v, 23, 1000) | ||
| 241 | dig7: STR_BUFINT_R(v, 12, 100) | ||
| 242 | dig6: STR_BUFINT_R(v, 10, 10) | ||
| 243 | dig5: *p++ = (char)('0'+v); | ||
| 244 | } | ||
| 245 | STR_BUFINT_R(u, 23, 1000) | ||
| 246 | dig3: STR_BUFINT_R(u, 12, 100) | ||
| 247 | dig2: STR_BUFINT_R(u, 10, 10) | ||
| 248 | dig1: *p++ = (char)('0'+u); | ||
| 249 | return p; | ||
| 250 | } | ||
| 251 | |||
| 252 | /* Print pointer to buffer. */ | ||
| 253 | char * LJ_FASTCALL lj_str_bufptr(char *p, const void *v) | ||
| 254 | { | ||
| 255 | ptrdiff_t x = (ptrdiff_t)v; | ||
| 256 | MSize i, n = LJ_STR_PTRBUF; | ||
| 257 | if (x == 0) { | ||
| 258 | *p++ = 'N'; *p++ = 'U'; *p++ = 'L'; *p++ = 'L'; | ||
| 259 | return p; | ||
| 260 | } | ||
| 261 | #if LJ_64 | ||
| 262 | /* Shorten output for 64 bit pointers. */ | ||
| 263 | n = 2+2*4+((x >> 32) ? 2+2*(lj_fls((uint32_t)(x >> 32))>>3) : 0); | ||
| 264 | #endif | ||
| 265 | p[0] = '0'; | ||
| 266 | p[1] = 'x'; | ||
| 267 | for (i = n-1; i >= 2; i--, x >>= 4) | ||
| 268 | p[i] = "0123456789abcdef"[(x & 15)]; | ||
| 269 | return p+n; | ||
| 270 | } | ||
| 271 | |||
| 272 | /* Print TValue to buffer (only for numbers) and return pointer to start. */ | ||
| 273 | const char *lj_str_buftv(char *buf, cTValue *o, MSize *lenp) | ||
| 274 | { | ||
| 275 | if (tvisstr(o)) { | ||
| 276 | *lenp = strV(o)->len; | ||
| 277 | return strVdata(o); | ||
| 278 | } else if (tvisint(o)) { | ||
| 279 | *lenp = (MSize)(lj_str_bufint(buf, intV(o)) - buf); | ||
| 280 | return buf; | ||
| 281 | } else if (tvisnum(o)) { | ||
| 282 | *lenp = (MSize)(lj_str_bufnum(buf, o) - buf); | ||
| 283 | return buf; | ||
| 284 | } else { | ||
| 285 | return NULL; | ||
| 286 | } | ||
| 287 | } | ||
| 288 | |||
| 289 | /* Convert number to string. */ | ||
| 290 | GCstr * LJ_FASTCALL lj_str_fromnum(lua_State *L, const lua_Number *np) | ||
| 291 | { | ||
| 292 | char buf[LJ_STR_NUMBUF]; | ||
| 293 | MSize len = (MSize)(lj_str_bufnum(buf, (TValue *)np) - buf); | ||
| 294 | return lj_str_new(L, buf, len); | ||
| 295 | } | ||
| 296 | |||
| 297 | /* Convert integer to string. */ | ||
| 298 | GCstr * LJ_FASTCALL lj_str_fromint(lua_State *L, int32_t k) | ||
| 299 | { | ||
| 300 | char buf[LJ_STR_INTBUF]; | ||
| 301 | MSize len = (MSize)(lj_str_bufint(buf, k) - buf); | ||
| 302 | return lj_str_new(L, buf, len); | ||
| 303 | } | ||
| 304 | |||
| 305 | GCstr * LJ_FASTCALL lj_str_fromnumber(lua_State *L, cTValue *o) | ||
| 306 | { | ||
| 307 | return tvisint(o) ? lj_str_fromint(L, intV(o)) : lj_str_fromnum(L, &o->n); | ||
| 308 | } | ||
| 309 | |||
| 310 | /* Convert char value to string. */ | ||
| 311 | GCstr * LJ_FASTCALL lj_str_fromchar(lua_State *L, int c) | ||
| 312 | { | ||
| 313 | char buf[1]; | ||
| 314 | buf[0] = c; | ||
| 315 | return lj_str_new(L, buf, 1); | ||
| 316 | } | ||
| 317 | |||
diff --git a/src/lj_str.h b/src/lj_str.h index b929cbac..f156ff6f 100644 --- a/src/lj_str.h +++ b/src/lj_str.h | |||
| @@ -24,19 +24,4 @@ LJ_FUNC void LJ_FASTCALL lj_str_free(global_State *g, GCstr *s); | |||
| 24 | #define lj_str_newz(L, s) (lj_str_new(L, s, strlen(s))) | 24 | #define lj_str_newz(L, s) (lj_str_new(L, s, strlen(s))) |
| 25 | #define lj_str_newlit(L, s) (lj_str_new(L, "" s, sizeof(s)-1)) | 25 | #define lj_str_newlit(L, s) (lj_str_new(L, "" s, sizeof(s)-1)) |
| 26 | 26 | ||
| 27 | /* Type conversions. */ | ||
| 28 | LJ_FUNC char * LJ_FASTCALL lj_str_bufint(char *p, int32_t k); | ||
| 29 | LJ_FUNC char * LJ_FASTCALL lj_str_bufnum(char *p, cTValue *o); | ||
| 30 | LJ_FUNC char * LJ_FASTCALL lj_str_bufptr(char *p, const void *v); | ||
| 31 | LJ_FUNC const char *lj_str_buftv(char *buf, cTValue *o, MSize *lenp); | ||
| 32 | LJ_FUNCA GCstr * LJ_FASTCALL lj_str_fromnum(lua_State *L, const lua_Number *np); | ||
| 33 | LJ_FUNC GCstr * LJ_FASTCALL lj_str_fromint(lua_State *L, int32_t k); | ||
| 34 | LJ_FUNCA GCstr * LJ_FASTCALL lj_str_fromnumber(lua_State *L, cTValue *o); | ||
| 35 | LJ_FUNC GCstr * LJ_FASTCALL lj_str_fromchar(lua_State *L, int c); | ||
| 36 | |||
| 37 | #define LJ_STR_INTBUF (1+10) | ||
| 38 | #define LJ_STR_NUMBUF LUAI_MAXNUMBER2STR | ||
| 39 | #define LJ_STR_NUMBERBUF LUAI_MAXNUMBER2STR | ||
| 40 | #define LJ_STR_PTRBUF (2*sizeof(ptrdiff_t)+2) | ||
| 41 | |||
| 42 | #endif | 27 | #endif |
diff --git a/src/lj_strfmt.c b/src/lj_strfmt.c index e8fe2538..b44350e7 100644 --- a/src/lj_strfmt.c +++ b/src/lj_strfmt.c | |||
| @@ -10,6 +10,7 @@ | |||
| 10 | 10 | ||
| 11 | #include "lj_obj.h" | 11 | #include "lj_obj.h" |
| 12 | #include "lj_buf.h" | 12 | #include "lj_buf.h" |
| 13 | #include "lj_str.h" | ||
| 13 | #include "lj_state.h" | 14 | #include "lj_state.h" |
| 14 | #include "lj_char.h" | 15 | #include "lj_char.h" |
| 15 | #include "lj_strfmt.h" | 16 | #include "lj_strfmt.h" |
| @@ -86,35 +87,124 @@ retlit: | |||
| 86 | return fs->len ? STRFMT_LIT : STRFMT_EOF; | 87 | return fs->len ? STRFMT_LIT : STRFMT_EOF; |
| 87 | } | 88 | } |
| 88 | 89 | ||
| 89 | /* -- Formatted conversions to buffer ------------------------------------- */ | 90 | /* -- Raw conversions ----------------------------------------------------- */ |
| 90 | 91 | ||
| 91 | /* Add formatted char to buffer. */ | 92 | /* Write number to bufer. */ |
| 92 | SBuf *lj_strfmt_putchar(SBuf *sb, SFormat sf, int32_t c) | 93 | char * LJ_FASTCALL lj_strfmt_wnum(char *p, cTValue *o) |
| 93 | { | 94 | { |
| 94 | MSize width = STRFMT_WIDTH(sf); | 95 | if (LJ_LIKELY((o->u32.hi << 1) < 0xffe00000)) { /* Finite? */ |
| 95 | char *p = lj_buf_more(sb, width > 1 ? width : 1); | 96 | #if __BIONIC__ |
| 96 | if ((sf & STRFMT_F_LEFT)) *p++ = (char)c; | 97 | if (tvismzero(o)) { *p++ = '-'; *p++ = '0'; return p; } |
| 97 | while (width-- > 1) *p++ = ' '; | 98 | #endif |
| 98 | if (!(sf & STRFMT_F_LEFT)) *p++ = (char)c; | 99 | return p + lua_number2str(p, o->n); |
| 99 | setsbufP(sb, p); | 100 | } else if (((o->u32.hi & 0x000fffff) | o->u32.lo) != 0) { |
| 101 | *p++ = 'n'; *p++ = 'a'; *p++ = 'n'; | ||
| 102 | } else if ((o->u32.hi & 0x80000000) == 0) { | ||
| 103 | *p++ = 'i'; *p++ = 'n'; *p++ = 'f'; | ||
| 104 | } else { | ||
| 105 | *p++ = '-'; *p++ = 'i'; *p++ = 'n'; *p++ = 'f'; | ||
| 106 | } | ||
| 107 | return p; | ||
| 108 | } | ||
| 109 | |||
| 110 | #define WINT_R(x, sh, sc) \ | ||
| 111 | { uint32_t d = (x*(((1<<sh)+sc-1)/sc))>>sh; x -= d*sc; *p++ = (char)('0'+d); } | ||
| 112 | |||
| 113 | /* Write integer to buffer. */ | ||
| 114 | char * LJ_FASTCALL lj_strfmt_wint(char *p, int32_t k) | ||
| 115 | { | ||
| 116 | uint32_t u = (uint32_t)k; | ||
| 117 | if (k < 0) { u = (uint32_t)-k; *p++ = '-'; } | ||
| 118 | if (u < 10000) { | ||
| 119 | if (u < 10) goto dig1; if (u < 100) goto dig2; if (u < 1000) goto dig3; | ||
| 120 | } else { | ||
| 121 | uint32_t v = u / 10000; u -= v * 10000; | ||
| 122 | if (v < 10000) { | ||
| 123 | if (v < 10) goto dig5; if (v < 100) goto dig6; if (v < 1000) goto dig7; | ||
| 124 | } else { | ||
| 125 | uint32_t w = v / 10000; v -= w * 10000; | ||
| 126 | if (w >= 10) WINT_R(w, 10, 10) | ||
| 127 | *p++ = (char)('0'+w); | ||
| 128 | } | ||
| 129 | WINT_R(v, 23, 1000) | ||
| 130 | dig7: WINT_R(v, 12, 100) | ||
| 131 | dig6: WINT_R(v, 10, 10) | ||
| 132 | dig5: *p++ = (char)('0'+v); | ||
| 133 | } | ||
| 134 | WINT_R(u, 23, 1000) | ||
| 135 | dig3: WINT_R(u, 12, 100) | ||
| 136 | dig2: WINT_R(u, 10, 10) | ||
| 137 | dig1: *p++ = (char)('0'+u); | ||
| 138 | return p; | ||
| 139 | } | ||
| 140 | #undef WINT_R | ||
| 141 | |||
| 142 | /* Write pointer to buffer. */ | ||
| 143 | char * LJ_FASTCALL lj_strfmt_wptr(char *p, const void *v) | ||
| 144 | { | ||
| 145 | ptrdiff_t x = (ptrdiff_t)v; | ||
| 146 | MSize i, n = STRFMT_MAXBUF_PTR; | ||
| 147 | if (x == 0) { | ||
| 148 | *p++ = 'N'; *p++ = 'U'; *p++ = 'L'; *p++ = 'L'; | ||
| 149 | return p; | ||
| 150 | } | ||
| 151 | #if LJ_64 | ||
| 152 | /* Shorten output for 64 bit pointers. */ | ||
| 153 | n = 2+2*4+((x >> 32) ? 2+2*(lj_fls((uint32_t)(x >> 32))>>3) : 0); | ||
| 154 | #endif | ||
| 155 | p[0] = '0'; | ||
| 156 | p[1] = 'x'; | ||
| 157 | for (i = n-1; i >= 2; i--, x >>= 4) | ||
| 158 | p[i] = "0123456789abcdef"[(x & 15)]; | ||
| 159 | return p+n; | ||
| 160 | } | ||
| 161 | |||
| 162 | /* Write ULEB128 to buffer. */ | ||
| 163 | char * LJ_FASTCALL lj_strfmt_wuleb128(char *p, uint32_t v) | ||
| 164 | { | ||
| 165 | for (; v >= 0x80; v >>= 7) | ||
| 166 | *p++ = (char)((v & 0x7f) | 0x80); | ||
| 167 | *p++ = (char)v; | ||
| 168 | return p; | ||
| 169 | } | ||
| 170 | |||
| 171 | /* Return string or write number to buffer and return pointer to start. */ | ||
| 172 | const char *lj_strfmt_wstrnum(char *buf, cTValue *o, MSize *lenp) | ||
| 173 | { | ||
| 174 | if (tvisstr(o)) { | ||
| 175 | *lenp = strV(o)->len; | ||
| 176 | return strVdata(o); | ||
| 177 | } else if (tvisint(o)) { | ||
| 178 | *lenp = (MSize)(lj_strfmt_wint(buf, intV(o)) - buf); | ||
| 179 | return buf; | ||
| 180 | } else if (tvisnum(o)) { | ||
| 181 | *lenp = (MSize)(lj_strfmt_wnum(buf, o) - buf); | ||
| 182 | return buf; | ||
| 183 | } else { | ||
| 184 | return NULL; | ||
| 185 | } | ||
| 186 | } | ||
| 187 | |||
| 188 | /* -- Unformatted conversions to buffer ----------------------------------- */ | ||
| 189 | |||
| 190 | /* Add integer to buffer. */ | ||
| 191 | SBuf * LJ_FASTCALL lj_strfmt_putint(SBuf *sb, int32_t k) | ||
| 192 | { | ||
| 193 | setsbufP(sb, lj_strfmt_wint(lj_buf_more(sb, STRFMT_MAXBUF_INT), k)); | ||
| 100 | return sb; | 194 | return sb; |
| 101 | } | 195 | } |
| 102 | 196 | ||
| 103 | /* Add formatted string to buffer. */ | 197 | #if LJ_HASJIT |
| 104 | SBuf *lj_strfmt_putstr(SBuf *sb, SFormat sf, GCstr *str) | 198 | /* Add number to buffer. */ |
| 199 | SBuf * LJ_FASTCALL lj_strfmt_putnum(SBuf *sb, cTValue *o) | ||
| 105 | { | 200 | { |
| 106 | MSize len = str->len <= STRFMT_PREC(sf) ? str->len : STRFMT_PREC(sf); | 201 | setsbufP(sb, lj_strfmt_wnum(lj_buf_more(sb, STRFMT_MAXBUF_NUM), o)); |
| 107 | MSize width = STRFMT_WIDTH(sf); | ||
| 108 | char *p = lj_buf_more(sb, width > len ? width : len); | ||
| 109 | if ((sf & STRFMT_F_LEFT)) p = lj_buf_wmem(p, strdata(str), len); | ||
| 110 | while (width-- > len) *p++ = ' '; | ||
| 111 | if (!(sf & STRFMT_F_LEFT)) p = lj_buf_wmem(p, strdata(str), len); | ||
| 112 | setsbufP(sb, p); | ||
| 113 | return sb; | 202 | return sb; |
| 114 | } | 203 | } |
| 204 | #endif | ||
| 115 | 205 | ||
| 116 | /* Add quoted string to buffer (no formatting). */ | 206 | /* Add quoted string to buffer. */ |
| 117 | SBuf *lj_strfmt_putquoted(SBuf *sb, GCstr *str) | 207 | SBuf * LJ_FASTCALL lj_strfmt_putquoted(SBuf *sb, GCstr *str) |
| 118 | { | 208 | { |
| 119 | const char *s = strdata(str); | 209 | const char *s = strdata(str); |
| 120 | MSize len = str->len; | 210 | MSize len = str->len; |
| @@ -143,10 +233,37 @@ SBuf *lj_strfmt_putquoted(SBuf *sb, GCstr *str) | |||
| 143 | return sb; | 233 | return sb; |
| 144 | } | 234 | } |
| 145 | 235 | ||
| 236 | /* -- Formatted conversions to buffer ------------------------------------- */ | ||
| 237 | |||
| 238 | /* Add formatted char to buffer. */ | ||
| 239 | SBuf *lj_strfmt_putfchar(SBuf *sb, SFormat sf, int32_t c) | ||
| 240 | { | ||
| 241 | MSize width = STRFMT_WIDTH(sf); | ||
| 242 | char *p = lj_buf_more(sb, width > 1 ? width : 1); | ||
| 243 | if ((sf & STRFMT_F_LEFT)) *p++ = (char)c; | ||
| 244 | while (width-- > 1) *p++ = ' '; | ||
| 245 | if (!(sf & STRFMT_F_LEFT)) *p++ = (char)c; | ||
| 246 | setsbufP(sb, p); | ||
| 247 | return sb; | ||
| 248 | } | ||
| 249 | |||
| 250 | /* Add formatted string to buffer. */ | ||
| 251 | SBuf *lj_strfmt_putfstr(SBuf *sb, SFormat sf, GCstr *str) | ||
| 252 | { | ||
| 253 | MSize len = str->len <= STRFMT_PREC(sf) ? str->len : STRFMT_PREC(sf); | ||
| 254 | MSize width = STRFMT_WIDTH(sf); | ||
| 255 | char *p = lj_buf_more(sb, width > len ? width : len); | ||
| 256 | if ((sf & STRFMT_F_LEFT)) p = lj_buf_wmem(p, strdata(str), len); | ||
| 257 | while (width-- > len) *p++ = ' '; | ||
| 258 | if (!(sf & STRFMT_F_LEFT)) p = lj_buf_wmem(p, strdata(str), len); | ||
| 259 | setsbufP(sb, p); | ||
| 260 | return sb; | ||
| 261 | } | ||
| 262 | |||
| 146 | /* Add formatted signed/unsigned integer to buffer. */ | 263 | /* Add formatted signed/unsigned integer to buffer. */ |
| 147 | SBuf *lj_strfmt_putxint(SBuf *sb, SFormat sf, uint64_t k) | 264 | SBuf *lj_strfmt_putfxint(SBuf *sb, SFormat sf, uint64_t k) |
| 148 | { | 265 | { |
| 149 | char buf[1+22], *q = buf + sizeof(buf), *p; | 266 | char buf[STRFMT_MAXBUF_XINT], *q = buf + sizeof(buf), *p; |
| 150 | #ifdef LUA_USE_ASSERT | 267 | #ifdef LUA_USE_ASSERT |
| 151 | char *ps; | 268 | char *ps; |
| 152 | #endif | 269 | #endif |
| @@ -217,31 +334,31 @@ SBuf *lj_strfmt_putxint(SBuf *sb, SFormat sf, uint64_t k) | |||
| 217 | } | 334 | } |
| 218 | 335 | ||
| 219 | /* Add number formatted as signed integer to buffer. */ | 336 | /* Add number formatted as signed integer to buffer. */ |
| 220 | SBuf *lj_strfmt_putnum_int(SBuf *sb, SFormat sf, lua_Number n) | 337 | SBuf *lj_strfmt_putfnum_int(SBuf *sb, SFormat sf, lua_Number n) |
| 221 | { | 338 | { |
| 222 | int64_t k = (int64_t)n; | 339 | int64_t k = (int64_t)n; |
| 223 | if (checki32(k) && sf == STRFMT_INT) | 340 | if (checki32(k) && sf == STRFMT_INT) |
| 224 | return lj_buf_putint(sb, k); /* Shortcut for plain %d. */ | 341 | return lj_strfmt_putint(sb, k); /* Shortcut for plain %d. */ |
| 225 | else | 342 | else |
| 226 | return lj_strfmt_putxint(sb, sf, (uint64_t)k); | 343 | return lj_strfmt_putfxint(sb, sf, (uint64_t)k); |
| 227 | } | 344 | } |
| 228 | 345 | ||
| 229 | /* Add number formatted as unsigned integer to buffer. */ | 346 | /* Add number formatted as unsigned integer to buffer. */ |
| 230 | SBuf *lj_strfmt_putnum_uint(SBuf *sb, SFormat sf, lua_Number n) | 347 | SBuf *lj_strfmt_putfnum_uint(SBuf *sb, SFormat sf, lua_Number n) |
| 231 | { | 348 | { |
| 232 | int64_t k; | 349 | int64_t k; |
| 233 | if (n >= 9223372036854775808.0) | 350 | if (n >= 9223372036854775808.0) |
| 234 | k = (int64_t)(n - 18446744073709551616.0); | 351 | k = (int64_t)(n - 18446744073709551616.0); |
| 235 | else | 352 | else |
| 236 | k = (int64_t)n; | 353 | k = (int64_t)n; |
| 237 | return lj_strfmt_putxint(sb, sf, (uint64_t)k); | 354 | return lj_strfmt_putfxint(sb, sf, (uint64_t)k); |
| 238 | } | 355 | } |
| 239 | 356 | ||
| 240 | /* Max. sprintf buffer size needed. At least #string.format("%.99f", -1e308). */ | 357 | /* Max. sprintf buffer size needed. At least #string.format("%.99f", -1e308). */ |
| 241 | #define STRFMT_FMTNUMBUF 512 | 358 | #define STRFMT_FMTNUMBUF 512 |
| 242 | 359 | ||
| 243 | /* Add formatted floating-point number to buffer. */ | 360 | /* Add formatted floating-point number to buffer. */ |
| 244 | SBuf *lj_strfmt_putnum(SBuf *sb, SFormat sf, lua_Number n) | 361 | SBuf *lj_strfmt_putfnum(SBuf *sb, SFormat sf, lua_Number n) |
| 245 | { | 362 | { |
| 246 | TValue tv; | 363 | TValue tv; |
| 247 | tv.n = n; | 364 | tv.n = n; |
| @@ -296,13 +413,45 @@ SBuf *lj_strfmt_putnum(SBuf *sb, SFormat sf, lua_Number n) | |||
| 296 | 413 | ||
| 297 | /* -- Conversions to strings ---------------------------------------------- */ | 414 | /* -- Conversions to strings ---------------------------------------------- */ |
| 298 | 415 | ||
| 416 | /* Convert integer to string. */ | ||
| 417 | GCstr * LJ_FASTCALL lj_strfmt_int(lua_State *L, int32_t k) | ||
| 418 | { | ||
| 419 | char buf[STRFMT_MAXBUF_INT]; | ||
| 420 | MSize len = (MSize)(lj_strfmt_wint(buf, k) - buf); | ||
| 421 | return lj_str_new(L, buf, len); | ||
| 422 | } | ||
| 423 | |||
| 424 | /* Convert number to string. */ | ||
| 425 | GCstr * LJ_FASTCALL lj_strfmt_num(lua_State *L, cTValue *o) | ||
| 426 | { | ||
| 427 | char buf[STRFMT_MAXBUF_NUM]; | ||
| 428 | MSize len = (MSize)(lj_strfmt_wnum(buf, o) - buf); | ||
| 429 | return lj_str_new(L, buf, len); | ||
| 430 | } | ||
| 431 | |||
| 432 | /* Convert integer or number to string. */ | ||
| 433 | GCstr * LJ_FASTCALL lj_strfmt_number(lua_State *L, cTValue *o) | ||
| 434 | { | ||
| 435 | return tvisint(o) ? lj_strfmt_int(L, intV(o)) : lj_strfmt_num(L, o); | ||
| 436 | } | ||
| 437 | |||
| 438 | #if LJ_HASJIT | ||
| 439 | /* Convert char value to string. */ | ||
| 440 | GCstr * LJ_FASTCALL lj_strfmt_char(lua_State *L, int c) | ||
| 441 | { | ||
| 442 | char buf[1]; | ||
| 443 | buf[0] = c; | ||
| 444 | return lj_str_new(L, buf, 1); | ||
| 445 | } | ||
| 446 | #endif | ||
| 447 | |||
| 299 | /* Raw conversion of object to string. */ | 448 | /* Raw conversion of object to string. */ |
| 300 | GCstr *lj_strfmt_obj(lua_State *L, cTValue *o) | 449 | GCstr *lj_strfmt_obj(lua_State *L, cTValue *o) |
| 301 | { | 450 | { |
| 302 | if (tvisstr(o)) { | 451 | if (tvisstr(o)) { |
| 303 | return strV(o); | 452 | return strV(o); |
| 304 | } else if (tvisnumber(o)) { | 453 | } else if (tvisnumber(o)) { |
| 305 | return lj_str_fromnumber(L, o); | 454 | return lj_strfmt_number(L, o); |
| 306 | } else if (tvisnil(o)) { | 455 | } else if (tvisnil(o)) { |
| 307 | return lj_str_newlit(L, "nil"); | 456 | return lj_str_newlit(L, "nil"); |
| 308 | } else if (tvisfalse(o)) { | 457 | } else if (tvisfalse(o)) { |
| @@ -315,9 +464,9 @@ GCstr *lj_strfmt_obj(lua_State *L, cTValue *o) | |||
| 315 | *p++ = ':'; *p++ = ' '; | 464 | *p++ = ':'; *p++ = ' '; |
| 316 | if (tvisfunc(o) && isffunc(funcV(o))) { | 465 | if (tvisfunc(o) && isffunc(funcV(o))) { |
| 317 | p = lj_buf_wmem(p, "builtin#", 8); | 466 | p = lj_buf_wmem(p, "builtin#", 8); |
| 318 | p = lj_str_bufint(p, funcV(o)->c.ffid); | 467 | p = lj_strfmt_wint(p, funcV(o)->c.ffid); |
| 319 | } else { | 468 | } else { |
| 320 | p = lj_str_bufptr(p, lj_obj_ptr(o)); | 469 | p = lj_strfmt_wptr(p, lj_obj_ptr(o)); |
| 321 | } | 470 | } |
| 322 | return lj_str_new(L, buf, (size_t)(p - buf)); | 471 | return lj_str_new(L, buf, (size_t)(p - buf)); |
| 323 | } | 472 | } |
| @@ -350,15 +499,15 @@ const char *lj_strfmt_pushvf(lua_State *L, const char *fmt, va_list argp) | |||
| 350 | lj_buf_putmem(sb, fs.str, fs.len); | 499 | lj_buf_putmem(sb, fs.str, fs.len); |
| 351 | break; | 500 | break; |
| 352 | case STRFMT_INT: | 501 | case STRFMT_INT: |
| 353 | lj_strfmt_putxint(sb, sf, va_arg(argp, int32_t)); | 502 | lj_strfmt_putfxint(sb, sf, va_arg(argp, int32_t)); |
| 354 | break; | 503 | break; |
| 355 | case STRFMT_UINT: | 504 | case STRFMT_UINT: |
| 356 | lj_strfmt_putxint(sb, sf, va_arg(argp, uint32_t)); | 505 | lj_strfmt_putfxint(sb, sf, va_arg(argp, uint32_t)); |
| 357 | break; | 506 | break; |
| 358 | case STRFMT_NUM: { | 507 | case STRFMT_NUM: { |
| 359 | TValue tv; | 508 | TValue tv; |
| 360 | tv.n = va_arg(argp, lua_Number); | 509 | tv.n = va_arg(argp, lua_Number); |
| 361 | setsbufP(sb, lj_str_bufnum(lj_buf_more(sb, LJ_STR_NUMBUF), &tv)); | 510 | setsbufP(sb, lj_strfmt_wnum(lj_buf_more(sb, STRFMT_MAXBUF_NUM), &tv)); |
| 362 | break; | 511 | break; |
| 363 | } | 512 | } |
| 364 | case STRFMT_STR: { | 513 | case STRFMT_STR: { |
| @@ -371,8 +520,8 @@ const char *lj_strfmt_pushvf(lua_State *L, const char *fmt, va_list argp) | |||
| 371 | lj_buf_putb(sb, va_arg(argp, int)); | 520 | lj_buf_putb(sb, va_arg(argp, int)); |
| 372 | break; | 521 | break; |
| 373 | case STRFMT_PTR: | 522 | case STRFMT_PTR: |
| 374 | setsbufP(sb, lj_str_bufptr(lj_buf_more(sb, LJ_STR_PTRBUF), | 523 | setsbufP(sb, lj_strfmt_wptr(lj_buf_more(sb, STRFMT_MAXBUF_PTR), |
| 375 | va_arg(argp, void *))); | 524 | va_arg(argp, void *))); |
| 376 | break; | 525 | break; |
| 377 | case STRFMT_ERR: | 526 | case STRFMT_ERR: |
| 378 | default: | 527 | default: |
diff --git a/src/lj_strfmt.h b/src/lj_strfmt.h index 6f3dc0be..5454336f 100644 --- a/src/lj_strfmt.h +++ b/src/lj_strfmt.h | |||
| @@ -65,6 +65,15 @@ typedef enum FormatType { | |||
| 65 | #define STRFMT_U (STRFMT_UINT) | 65 | #define STRFMT_U (STRFMT_UINT) |
| 66 | #define STRFMT_X (STRFMT_UINT|STRFMT_T_HEX) | 66 | #define STRFMT_X (STRFMT_UINT|STRFMT_T_HEX) |
| 67 | 67 | ||
| 68 | /* Maximum buffer sizes for conversions. */ | ||
| 69 | #define STRFMT_MAXBUF_XINT (1+22) /* '0' prefix + uint64_t in octal. */ | ||
| 70 | #define STRFMT_MAXBUF_INT (1+10) /* Sign + int32_t in decimal. */ | ||
| 71 | #define STRFMT_MAXBUF_NUM LUAI_MAXNUMBER2STR | ||
| 72 | #define STRFMT_MAXBUF_PTR (2+2*sizeof(ptrdiff_t)) /* "0x" + hex ptr. */ | ||
| 73 | |||
| 74 | /* Format parser. */ | ||
| 75 | LJ_FUNC SFormat LJ_FASTCALL lj_strfmt_parse(FormatState *fs); | ||
| 76 | |||
| 68 | static LJ_AINLINE void lj_strfmt_init(FormatState *fs, const char *p, MSize len) | 77 | static LJ_AINLINE void lj_strfmt_init(FormatState *fs, const char *p, MSize len) |
| 69 | { | 78 | { |
| 70 | fs->p = (const uint8_t *)p; | 79 | fs->p = (const uint8_t *)p; |
| @@ -72,18 +81,38 @@ static LJ_AINLINE void lj_strfmt_init(FormatState *fs, const char *p, MSize len) | |||
| 72 | lua_assert(*fs->e == 0); /* Must be NUL-terminated (may have NULs inside). */ | 81 | lua_assert(*fs->e == 0); /* Must be NUL-terminated (may have NULs inside). */ |
| 73 | } | 82 | } |
| 74 | 83 | ||
| 75 | LJ_FUNC SFormat LJ_FASTCALL lj_strfmt_parse(FormatState *fs); | 84 | /* Raw conversions. */ |
| 76 | 85 | LJ_FUNC char * LJ_FASTCALL lj_strfmt_wint(char *p, int32_t k); | |
| 77 | LJ_FUNC SBuf *lj_strfmt_putchar(SBuf *sb, SFormat, int32_t c); | 86 | LJ_FUNC char * LJ_FASTCALL lj_strfmt_wnum(char *p, cTValue *o); |
| 78 | LJ_FUNC SBuf *lj_strfmt_putstr(SBuf *sb, SFormat, GCstr *str); | 87 | LJ_FUNC char * LJ_FASTCALL lj_strfmt_wptr(char *p, const void *v); |
| 79 | LJ_FUNC SBuf *lj_strfmt_putquoted(SBuf *sb, GCstr *str); | 88 | LJ_FUNC char * LJ_FASTCALL lj_strfmt_wuleb128(char *p, uint32_t v); |
| 80 | LJ_FUNC SBuf *lj_strfmt_putxint(SBuf *sb, SFormat sf, uint64_t k); | 89 | LJ_FUNC const char *lj_strfmt_wstrnum(char *buf, cTValue *o, MSize *lenp); |
| 81 | LJ_FUNC SBuf *lj_strfmt_putnum_int(SBuf *sb, SFormat sf, lua_Number n); | 90 | |
| 82 | LJ_FUNC SBuf *lj_strfmt_putnum_uint(SBuf *sb, SFormat sf, lua_Number n); | 91 | /* Unformatted conversions to buffer. */ |
| 83 | LJ_FUNC SBuf *lj_strfmt_putnum(SBuf *sb, SFormat, lua_Number n); | 92 | LJ_FUNC SBuf * LJ_FASTCALL lj_strfmt_putint(SBuf *sb, int32_t k); |
| 84 | 93 | #if LJ_HASJIT | |
| 85 | LJ_FUNC GCstr *lj_strfmt_obj(lua_State *L, cTValue *o); | 94 | LJ_FUNC SBuf * LJ_FASTCALL lj_strfmt_putnum(SBuf *sb, cTValue *o); |
| 95 | #endif | ||
| 96 | LJ_FUNC SBuf * LJ_FASTCALL lj_strfmt_putquoted(SBuf *sb, GCstr *str); | ||
| 97 | |||
| 98 | /* Formatted conversions to buffer. */ | ||
| 99 | LJ_FUNC SBuf *lj_strfmt_putfxint(SBuf *sb, SFormat sf, uint64_t k); | ||
| 100 | LJ_FUNC SBuf *lj_strfmt_putfnum_int(SBuf *sb, SFormat sf, lua_Number n); | ||
| 101 | LJ_FUNC SBuf *lj_strfmt_putfnum_uint(SBuf *sb, SFormat sf, lua_Number n); | ||
| 102 | LJ_FUNC SBuf *lj_strfmt_putfnum(SBuf *sb, SFormat, lua_Number n); | ||
| 103 | LJ_FUNC SBuf *lj_strfmt_putfchar(SBuf *sb, SFormat, int32_t c); | ||
| 104 | LJ_FUNC SBuf *lj_strfmt_putfstr(SBuf *sb, SFormat, GCstr *str); | ||
| 105 | |||
| 106 | /* Conversions to strings. */ | ||
| 107 | LJ_FUNC GCstr * LJ_FASTCALL lj_strfmt_int(lua_State *L, int32_t k); | ||
| 108 | LJ_FUNCA GCstr * LJ_FASTCALL lj_strfmt_num(lua_State *L, cTValue *o); | ||
| 109 | LJ_FUNCA GCstr * LJ_FASTCALL lj_strfmt_number(lua_State *L, cTValue *o); | ||
| 110 | #if LJ_HASJIT | ||
| 111 | LJ_FUNC GCstr * LJ_FASTCALL lj_strfmt_char(lua_State *L, int c); | ||
| 112 | #endif | ||
| 113 | LJ_FUNC GCstr * LJ_FASTCALL lj_strfmt_obj(lua_State *L, cTValue *o); | ||
| 86 | 114 | ||
| 115 | /* Internal string formatting. */ | ||
| 87 | LJ_FUNC const char *lj_strfmt_pushvf(lua_State *L, const char *fmt, | 116 | LJ_FUNC const char *lj_strfmt_pushvf(lua_State *L, const char *fmt, |
| 88 | va_list argp); | 117 | va_list argp); |
| 89 | LJ_FUNC const char *lj_strfmt_pushf(lua_State *L, const char *fmt, ...) | 118 | LJ_FUNC const char *lj_strfmt_pushf(lua_State *L, const char *fmt, ...) |
diff --git a/src/vm_arm.dasc b/src/vm_arm.dasc index 0c542e1e..83341e41 100644 --- a/src/vm_arm.dasc +++ b/src/vm_arm.dasc | |||
| @@ -1084,7 +1084,7 @@ static void build_subroutines(BuildCtx *ctx) | |||
| 1084 | | ffgccheck | 1084 | | ffgccheck |
| 1085 | | mov CARG1, L | 1085 | | mov CARG1, L |
| 1086 | | mov CARG2, BASE | 1086 | | mov CARG2, BASE |
| 1087 | | bl extern lj_str_fromnumber // (lua_State *L, cTValue *o) | 1087 | | bl extern lj_strfmt_number // (lua_State *L, cTValue *o) |
| 1088 | | // Returns GCstr *. | 1088 | | // Returns GCstr *. |
| 1089 | | ldr BASE, L->base | 1089 | | ldr BASE, L->base |
| 1090 | | mvn CARG2, #~LJ_TSTR | 1090 | | mvn CARG2, #~LJ_TSTR |
diff --git a/src/vm_mips.dasc b/src/vm_mips.dasc index 9ab68981..41ed303d 100644 --- a/src/vm_mips.dasc +++ b/src/vm_mips.dasc | |||
| @@ -1152,9 +1152,9 @@ static void build_subroutines(BuildCtx *ctx) | |||
| 1152 | |. sw BASE, L->base // Add frame since C call can throw. | 1152 | |. sw BASE, L->base // Add frame since C call can throw. |
| 1153 | | ffgccheck | 1153 | | ffgccheck |
| 1154 | |. sw PC, SAVE_PC // Redundant (but a defined value). | 1154 | |. sw PC, SAVE_PC // Redundant (but a defined value). |
| 1155 | | load_got lj_str_fromnum | 1155 | | load_got lj_strfmt_num |
| 1156 | | move CARG1, L | 1156 | | move CARG1, L |
| 1157 | | call_intern lj_str_fromnum // (lua_State *L, lua_Number *np) | 1157 | | call_intern lj_strfmt_num // (lua_State *L, lua_Number *np) |
| 1158 | |. move CARG2, BASE | 1158 | |. move CARG2, BASE |
| 1159 | | // Returns GCstr *. | 1159 | | // Returns GCstr *. |
| 1160 | | li CARG3, LJ_TSTR | 1160 | | li CARG3, LJ_TSTR |
diff --git a/src/vm_ppc.dasc b/src/vm_ppc.dasc index 733eeb8f..6bceff9c 100644 --- a/src/vm_ppc.dasc +++ b/src/vm_ppc.dasc | |||
| @@ -1394,9 +1394,9 @@ static void build_subroutines(BuildCtx *ctx) | |||
| 1394 | | mr CARG1, L | 1394 | | mr CARG1, L |
| 1395 | | mr CARG2, BASE | 1395 | | mr CARG2, BASE |
| 1396 | |.if DUALNUM | 1396 | |.if DUALNUM |
| 1397 | | bl extern lj_str_fromnumber // (lua_State *L, cTValue *o) | 1397 | | bl extern lj_strfmt_number // (lua_State *L, cTValue *o) |
| 1398 | |.else | 1398 | |.else |
| 1399 | | bl extern lj_str_fromnum // (lua_State *L, lua_Number *np) | 1399 | | bl extern lj_strfmt_num // (lua_State *L, lua_Number *np) |
| 1400 | |.endif | 1400 | |.endif |
| 1401 | | // Returns GCstr *. | 1401 | | // Returns GCstr *. |
| 1402 | | li CARG3, LJ_TSTR | 1402 | | li CARG3, LJ_TSTR |
diff --git a/src/vm_x86.dasc b/src/vm_x86.dasc index 338916a7..6c8302a0 100644 --- a/src/vm_x86.dasc +++ b/src/vm_x86.dasc | |||
| @@ -1586,9 +1586,9 @@ static void build_subroutines(BuildCtx *ctx) | |||
| 1586 | |.endif | 1586 | |.endif |
| 1587 | | mov L:FCARG1, L:RB | 1587 | | mov L:FCARG1, L:RB |
| 1588 | |.if DUALNUM | 1588 | |.if DUALNUM |
| 1589 | | call extern lj_str_fromnumber@8 // (lua_State *L, cTValue *o) | 1589 | | call extern lj_strfmt_number@8 // (lua_State *L, cTValue *o) |
| 1590 | |.else | 1590 | |.else |
| 1591 | | call extern lj_str_fromnum@8 // (lua_State *L, lua_Number *np) | 1591 | | call extern lj_strfmt_num@8 // (lua_State *L, lua_Number *np) |
| 1592 | |.endif | 1592 | |.endif |
| 1593 | | // GCstr returned in eax (RD). | 1593 | | // GCstr returned in eax (RD). |
| 1594 | | mov BASE, L:RB->base | 1594 | | mov BASE, L:RB->base |
