aboutsummaryrefslogtreecommitdiff
path: root/src/lj_bcread.c
diff options
context:
space:
mode:
authorMike Pall <mike>2013-02-22 01:40:41 +0100
committerMike Pall <mike>2013-02-22 01:40:41 +0100
commite20157c6e68472e7c4d82d9ed4c0bb5be029c388 (patch)
treeb26bfadc10b7301d73b84293630c44e7d1fb37f9 /src/lj_bcread.c
parentc3219b7d177f6722b9de808cfd3d3dbfc6808e6f (diff)
downloadluajit-e20157c6e68472e7c4d82d9ed4c0bb5be029c388.tar.gz
luajit-e20157c6e68472e7c4d82d9ed4c0bb5be029c388.tar.bz2
luajit-e20157c6e68472e7c4d82d9ed4c0bb5be029c388.zip
Add support for embedding LuaJIT bytecode for builtins.
Diffstat (limited to 'src/lj_bcread.c')
-rw-r--r--src/lj_bcread.c34
1 files changed, 16 insertions, 18 deletions
diff --git a/src/lj_bcread.c b/src/lj_bcread.c
index 2b5ba855..7a8c08f5 100644
--- a/src/lj_bcread.c
+++ b/src/lj_bcread.c
@@ -326,25 +326,13 @@ static void bcread_uv(LexState *ls, GCproto *pt, MSize sizeuv)
326} 326}
327 327
328/* Read a prototype. */ 328/* Read a prototype. */
329static GCproto *bcread_proto(LexState *ls) 329GCproto *lj_bcread_proto(LexState *ls)
330{ 330{
331 GCproto *pt; 331 GCproto *pt;
332 MSize framesize, numparams, flags, sizeuv, sizekgc, sizekn, sizebc, sizept; 332 MSize framesize, numparams, flags, sizeuv, sizekgc, sizekn, sizebc, sizept;
333 MSize ofsk, ofsuv, ofsdbg; 333 MSize ofsk, ofsuv, ofsdbg;
334 MSize sizedbg = 0; 334 MSize sizedbg = 0;
335 BCLine firstline = 0, numline = 0; 335 BCLine firstline = 0, numline = 0;
336 MSize len, startn;
337
338 /* Read length. */
339 if (ls->n > 0 && ls->p[0] == 0) { /* Shortcut EOF. */
340 ls->n--; ls->p++;
341 return NULL;
342 }
343 bcread_want(ls, 5);
344 len = bcread_uleb128(ls);
345 if (!len) return NULL; /* EOF */
346 bcread_need(ls, len);
347 startn = ls->n;
348 336
349 /* Read prototype header. */ 337 /* Read prototype header. */
350 flags = bcread_byte(ls); 338 flags = bcread_byte(ls);
@@ -413,9 +401,6 @@ static GCproto *bcread_proto(LexState *ls)
413 setmref(pt->uvinfo, NULL); 401 setmref(pt->uvinfo, NULL);
414 setmref(pt->varinfo, NULL); 402 setmref(pt->varinfo, NULL);
415 } 403 }
416
417 if (len != startn - ls->n)
418 bcread_error(ls, LJ_ERR_BCBAD);
419 return pt; 404 return pt;
420} 405}
421 406
@@ -462,8 +447,21 @@ GCproto *lj_bcread(LexState *ls)
462 if (!bcread_header(ls)) 447 if (!bcread_header(ls))
463 bcread_error(ls, LJ_ERR_BCFMT); 448 bcread_error(ls, LJ_ERR_BCFMT);
464 for (;;) { /* Process all prototypes in the bytecode dump. */ 449 for (;;) { /* Process all prototypes in the bytecode dump. */
465 GCproto *pt = bcread_proto(ls); 450 GCproto *pt;
466 if (!pt) break; 451 MSize len, startn;
452 /* Read length. */
453 if (ls->n > 0 && ls->p[0] == 0) { /* Shortcut EOF. */
454 ls->n--; ls->p++;
455 break;
456 }
457 bcread_want(ls, 5);
458 len = bcread_uleb128(ls);
459 if (!len) break; /* EOF */
460 bcread_need(ls, len);
461 startn = ls->n;
462 pt = lj_bcread_proto(ls);
463 if (len != startn - ls->n)
464 bcread_error(ls, LJ_ERR_BCBAD);
467 setprotoV(L, L->top, pt); 465 setprotoV(L, L->top, pt);
468 incr_top(L); 466 incr_top(L);
469 } 467 }