diff options
author | Mike Pall <mike> | 2013-05-13 10:15:07 +0200 |
---|---|---|
committer | Mike Pall <mike> | 2013-05-13 10:15:07 +0200 |
commit | 8f90a1279e125a8cb9727751f76fb75214208f89 (patch) | |
tree | b65706b5b10231780735fcf80966e14f616f39b7 /src/lj_bcwrite.c | |
parent | 625ffca739a703906fbc321ef9405514d72480fe (diff) | |
download | luajit-8f90a1279e125a8cb9727751f76fb75214208f89.tar.gz luajit-8f90a1279e125a8cb9727751f76fb75214208f89.tar.bz2 luajit-8f90a1279e125a8cb9727751f76fb75214208f89.zip |
Big renaming of string buffer/formatting/conversion functions.
Diffstat (limited to 'src/lj_bcwrite.c')
-rw-r--r-- | src/lj_bcwrite.c | 48 |
1 files changed, 24 insertions, 24 deletions
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), |