aboutsummaryrefslogtreecommitdiff
path: root/lcode.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2010-07-02 17:42:40 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2010-07-02 17:42:40 -0300
commit6a02bbe1e2f8ad1b98a077bd2aac44e776fd107c (patch)
treef9923894e45cf4fcfe40c69bd198cd263fcc5529 /lcode.c
parent7631c29b2f1d57866e2ab885aedc19c29e93a653 (diff)
downloadlua-6a02bbe1e2f8ad1b98a077bd2aac44e776fd107c.tar.gz
lua-6a02bbe1e2f8ad1b98a077bd2aac44e776fd107c.tar.bz2
lua-6a02bbe1e2f8ad1b98a077bd2aac44e776fd107c.zip
better organization for fields in struct 'expdesc'
Diffstat (limited to 'lcode.c')
-rw-r--r--lcode.c85
1 files changed, 43 insertions, 42 deletions
diff --git a/lcode.c b/lcode.c
index 7a9e680b..084354fd 100644
--- a/lcode.c
+++ b/lcode.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lcode.c,v 2.46 2010/04/17 12:46:32 roberto Exp roberto $ 2** $Id: lcode.c,v 2.47 2010/06/30 14:11:17 roberto Exp roberto $
3** Code generator for Lua 3** Code generator for Lua
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -266,7 +266,7 @@ static void freereg (FuncState *fs, int reg) {
266 266
267static void freeexp (FuncState *fs, expdesc *e) { 267static void freeexp (FuncState *fs, expdesc *e) {
268 if (e->k == VNONRELOC) 268 if (e->k == VNONRELOC)
269 freereg(fs, e->u.s.info); 269 freereg(fs, e->u.info);
270} 270}
271 271
272 272
@@ -352,7 +352,7 @@ void luaK_setreturns (FuncState *fs, expdesc *e, int nresults) {
352void luaK_setoneret (FuncState *fs, expdesc *e) { 352void luaK_setoneret (FuncState *fs, expdesc *e) {
353 if (e->k == VCALL) { /* expression is an open function call? */ 353 if (e->k == VCALL) { /* expression is an open function call? */
354 e->k = VNONRELOC; 354 e->k = VNONRELOC;
355 e->u.s.info = GETARG_A(getcode(fs, e)); 355 e->u.info = GETARG_A(getcode(fs, e));
356 } 356 }
357 else if (e->k == VVARARG) { 357 else if (e->k == VVARARG) {
358 SETARG_B(getcode(fs, e), 2); 358 SETARG_B(getcode(fs, e), 2);
@@ -368,20 +368,20 @@ void luaK_dischargevars (FuncState *fs, expdesc *e) {
368 break; 368 break;
369 } 369 }
370 case VUPVAL: { 370 case VUPVAL: {
371 e->u.s.info = luaK_codeABC(fs, OP_GETUPVAL, 0, e->u.s.info, 0); 371 e->u.info = luaK_codeABC(fs, OP_GETUPVAL, 0, e->u.info, 0);
372 e->k = VRELOCABLE; 372 e->k = VRELOCABLE;
373 break; 373 break;
374 } 374 }
375 case VINDEXED: { 375 case VINDEXED: {
376 freereg(fs, e->u.s.aux); 376 freereg(fs, e->u.ind.idx);
377 freereg(fs, e->u.s.info); 377 freereg(fs, e->u.ind.t);
378 e->u.s.info = luaK_codeABC(fs, OP_GETTABLE, 0, e->u.s.info, e->u.s.aux); 378 e->u.info = luaK_codeABC(fs, OP_GETTABLE, 0, e->u.ind.t, e->u.ind.idx);
379 e->k = VRELOCABLE; 379 e->k = VRELOCABLE;
380 break; 380 break;
381 } 381 }
382 case VINDEXEDUP: { 382 case VINDEXEDUP: {
383 freereg(fs, e->u.s.aux); 383 freereg(fs, e->u.ind.idx);
384 e->u.s.info = luaK_codeABC(fs, OP_GETTABUP, 0, e->u.s.info, e->u.s.aux); 384 e->u.info = luaK_codeABC(fs, OP_GETTABUP, 0, e->u.ind.t, e->u.ind.idx);
385 e->k = VRELOCABLE; 385 e->k = VRELOCABLE;
386 break; 386 break;
387 } 387 }
@@ -413,7 +413,7 @@ static void discharge2reg (FuncState *fs, expdesc *e, int reg) {
413 break; 413 break;
414 } 414 }
415 case VK: { 415 case VK: {
416 luaK_codek(fs, reg, e->u.s.info); 416 luaK_codek(fs, reg, e->u.info);
417 break; 417 break;
418 } 418 }
419 case VKNUM: { 419 case VKNUM: {
@@ -426,8 +426,8 @@ static void discharge2reg (FuncState *fs, expdesc *e, int reg) {
426 break; 426 break;
427 } 427 }
428 case VNONRELOC: { 428 case VNONRELOC: {
429 if (reg != e->u.s.info) 429 if (reg != e->u.info)
430 luaK_codeABC(fs, OP_MOVE, reg, e->u.s.info, 0); 430 luaK_codeABC(fs, OP_MOVE, reg, e->u.info, 0);
431 break; 431 break;
432 } 432 }
433 default: { 433 default: {
@@ -435,7 +435,7 @@ static void discharge2reg (FuncState *fs, expdesc *e, int reg) {
435 return; /* nothing to do... */ 435 return; /* nothing to do... */
436 } 436 }
437 } 437 }
438 e->u.s.info = reg; 438 e->u.info = reg;
439 e->k = VNONRELOC; 439 e->k = VNONRELOC;
440} 440}
441 441
@@ -451,7 +451,7 @@ static void discharge2anyreg (FuncState *fs, expdesc *e) {
451static void exp2reg (FuncState *fs, expdesc *e, int reg) { 451static void exp2reg (FuncState *fs, expdesc *e, int reg) {
452 discharge2reg(fs, e, reg); 452 discharge2reg(fs, e, reg);
453 if (e->k == VJMP) 453 if (e->k == VJMP)
454 luaK_concat(fs, &e->t, e->u.s.info); /* put this jump in `t' list */ 454 luaK_concat(fs, &e->t, e->u.info); /* put this jump in `t' list */
455 if (hasjumps(e)) { 455 if (hasjumps(e)) {
456 int final; /* position after whole expression */ 456 int final; /* position after whole expression */
457 int p_f = NO_JUMP; /* position of an eventual LOAD false */ 457 int p_f = NO_JUMP; /* position of an eventual LOAD false */
@@ -467,7 +467,7 @@ static void exp2reg (FuncState *fs, expdesc *e, int reg) {
467 patchlistaux(fs, e->t, final, reg, p_t); 467 patchlistaux(fs, e->t, final, reg, p_t);
468 } 468 }
469 e->f = e->t = NO_JUMP; 469 e->f = e->t = NO_JUMP;
470 e->u.s.info = reg; 470 e->u.info = reg;
471 e->k = VNONRELOC; 471 e->k = VNONRELOC;
472} 472}
473 473
@@ -483,14 +483,14 @@ void luaK_exp2nextreg (FuncState *fs, expdesc *e) {
483int luaK_exp2anyreg (FuncState *fs, expdesc *e) { 483int luaK_exp2anyreg (FuncState *fs, expdesc *e) {
484 luaK_dischargevars(fs, e); 484 luaK_dischargevars(fs, e);
485 if (e->k == VNONRELOC) { 485 if (e->k == VNONRELOC) {
486 if (!hasjumps(e)) return e->u.s.info; /* exp is already in a register */ 486 if (!hasjumps(e)) return e->u.info; /* exp is already in a register */
487 if (e->u.s.info >= fs->nactvar) { /* reg. is not a local? */ 487 if (e->u.info >= fs->nactvar) { /* reg. is not a local? */
488 exp2reg(fs, e, e->u.s.info); /* put value on it */ 488 exp2reg(fs, e, e->u.info); /* put value on it */
489 return e->u.s.info; 489 return e->u.info;
490 } 490 }
491 } 491 }
492 luaK_exp2nextreg(fs, e); /* default */ 492 luaK_exp2nextreg(fs, e); /* default */
493 return e->u.s.info; 493 return e->u.info;
494} 494}
495 495
496 496
@@ -515,20 +515,20 @@ int luaK_exp2RK (FuncState *fs, expdesc *e) {
515 case VFALSE: 515 case VFALSE:
516 case VNIL: { 516 case VNIL: {
517 if (fs->nk <= MAXINDEXRK) { /* constant fits in RK operand? */ 517 if (fs->nk <= MAXINDEXRK) { /* constant fits in RK operand? */
518 e->u.s.info = (e->k == VNIL) ? nilK(fs) : boolK(fs, (e->k == VTRUE)); 518 e->u.info = (e->k == VNIL) ? nilK(fs) : boolK(fs, (e->k == VTRUE));
519 e->k = VK; 519 e->k = VK;
520 return RKASK(e->u.s.info); 520 return RKASK(e->u.info);
521 } 521 }
522 else break; 522 else break;
523 } 523 }
524 case VKNUM: { 524 case VKNUM: {
525 e->u.s.info = luaK_numberK(fs, e->u.nval); 525 e->u.info = luaK_numberK(fs, e->u.nval);
526 e->k = VK; 526 e->k = VK;
527 /* go through */ 527 /* go through */
528 } 528 }
529 case VK: { 529 case VK: {
530 if (e->u.s.info <= MAXINDEXRK) /* constant fits in argC? */ 530 if (e->u.info <= MAXINDEXRK) /* constant fits in argC? */
531 return RKASK(e->u.s.info); 531 return RKASK(e->u.info);
532 else break; 532 else break;
533 } 533 }
534 default: break; 534 default: break;
@@ -542,22 +542,22 @@ void luaK_storevar (FuncState *fs, expdesc *var, expdesc *ex) {
542 switch (var->k) { 542 switch (var->k) {
543 case VLOCAL: { 543 case VLOCAL: {
544 freeexp(fs, ex); 544 freeexp(fs, ex);
545 exp2reg(fs, ex, var->u.s.info); 545 exp2reg(fs, ex, var->u.info);
546 return; 546 return;
547 } 547 }
548 case VUPVAL: { 548 case VUPVAL: {
549 int e = luaK_exp2anyreg(fs, ex); 549 int e = luaK_exp2anyreg(fs, ex);
550 luaK_codeABC(fs, OP_SETUPVAL, e, var->u.s.info, 0); 550 luaK_codeABC(fs, OP_SETUPVAL, e, var->u.info, 0);
551 break; 551 break;
552 } 552 }
553 case VINDEXED: { 553 case VINDEXED: {
554 int e = luaK_exp2RK(fs, ex); 554 int e = luaK_exp2RK(fs, ex);
555 luaK_codeABC(fs, OP_SETTABLE, var->u.s.info, var->u.s.aux, e); 555 luaK_codeABC(fs, OP_SETTABLE, var->u.ind.t, var->u.ind.idx, e);
556 break; 556 break;
557 } 557 }
558 case VINDEXEDUP: { 558 case VINDEXEDUP: {
559 int e = luaK_exp2RK(fs, ex); 559 int e = luaK_exp2RK(fs, ex);
560 luaK_codeABC(fs, OP_SETTABUP, var->u.s.info, var->u.s.aux, e); 560 luaK_codeABC(fs, OP_SETTABUP, var->u.ind.t, var->u.ind.idx, e);
561 break; 561 break;
562 } 562 }
563 default: { 563 default: {
@@ -574,16 +574,16 @@ void luaK_self (FuncState *fs, expdesc *e, expdesc *key) {
574 luaK_exp2anyreg(fs, e); 574 luaK_exp2anyreg(fs, e);
575 freeexp(fs, e); 575 freeexp(fs, e);
576 func = fs->freereg; 576 func = fs->freereg;
577 luaK_codeABC(fs, OP_SELF, func, e->u.s.info, luaK_exp2RK(fs, key)); 577 luaK_codeABC(fs, OP_SELF, func, e->u.info, luaK_exp2RK(fs, key));
578 freeexp(fs, key); 578 freeexp(fs, key);
579 luaK_reserveregs(fs, 2); 579 luaK_reserveregs(fs, 2);
580 e->u.s.info = func; 580 e->u.info = func;
581 e->k = VNONRELOC; 581 e->k = VNONRELOC;
582} 582}
583 583
584 584
585static void invertjump (FuncState *fs, expdesc *e) { 585static void invertjump (FuncState *fs, expdesc *e) {
586 Instruction *pc = getjumpcontrol(fs, e->u.s.info); 586 Instruction *pc = getjumpcontrol(fs, e->u.info);
587 lua_assert(testTMode(GET_OPCODE(*pc)) && GET_OPCODE(*pc) != OP_TESTSET && 587 lua_assert(testTMode(GET_OPCODE(*pc)) && GET_OPCODE(*pc) != OP_TESTSET &&
588 GET_OPCODE(*pc) != OP_TEST); 588 GET_OPCODE(*pc) != OP_TEST);
589 SETARG_A(*pc, !(GETARG_A(*pc))); 589 SETARG_A(*pc, !(GETARG_A(*pc)));
@@ -601,7 +601,7 @@ static int jumponcond (FuncState *fs, expdesc *e, int cond) {
601 } 601 }
602 discharge2anyreg(fs, e); 602 discharge2anyreg(fs, e);
603 freeexp(fs, e); 603 freeexp(fs, e);
604 return condjump(fs, OP_TESTSET, NO_REG, e->u.s.info, cond); 604 return condjump(fs, OP_TESTSET, NO_REG, e->u.info, cond);
605} 605}
606 606
607 607
@@ -615,7 +615,7 @@ void luaK_goiftrue (FuncState *fs, expdesc *e) {
615 } 615 }
616 case VJMP: { 616 case VJMP: {
617 invertjump(fs, e); 617 invertjump(fs, e);
618 pc = e->u.s.info; 618 pc = e->u.info;
619 break; 619 break;
620 } 620 }
621 case VFALSE: { 621 case VFALSE: {
@@ -645,7 +645,7 @@ static void luaK_goiffalse (FuncState *fs, expdesc *e) {
645 break; 645 break;
646 } 646 }
647 case VJMP: { 647 case VJMP: {
648 pc = e->u.s.info; 648 pc = e->u.info;
649 break; 649 break;
650 } 650 }
651 case VTRUE: { 651 case VTRUE: {
@@ -685,7 +685,7 @@ static void codenot (FuncState *fs, expdesc *e) {
685 case VNONRELOC: { 685 case VNONRELOC: {
686 discharge2anyreg(fs, e); 686 discharge2anyreg(fs, e);
687 freeexp(fs, e); 687 freeexp(fs, e);
688 e->u.s.info = luaK_codeABC(fs, OP_NOT, 0, e->u.s.info, 0); 688 e->u.info = luaK_codeABC(fs, OP_NOT, 0, e->u.info, 0);
689 e->k = VRELOCABLE; 689 e->k = VRELOCABLE;
690 break; 690 break;
691 } 691 }
@@ -703,7 +703,8 @@ static void codenot (FuncState *fs, expdesc *e) {
703 703
704void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k) { 704void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k) {
705 lua_assert(!hasjumps(t)); 705 lua_assert(!hasjumps(t));
706 t->u.s.aux = luaK_exp2RK(fs, k); 706 t->u.ind.t = t->u.info;
707 t->u.ind.idx = luaK_exp2RK(fs, k);
707 t->k = (t->k == VUPVAL) ? VINDEXEDUP : VINDEXED; 708 t->k = (t->k == VUPVAL) ? VINDEXEDUP : VINDEXED;
708} 709}
709 710
@@ -734,7 +735,7 @@ static void codearith (FuncState *fs, OpCode op,
734 freeexp(fs, e2); 735 freeexp(fs, e2);
735 freeexp(fs, e1); 736 freeexp(fs, e1);
736 } 737 }
737 e1->u.s.info = luaK_codeABC(fs, op, 0, o1, o2); 738 e1->u.info = luaK_codeABC(fs, op, 0, o1, o2);
738 e1->k = VRELOCABLE; 739 e1->k = VRELOCABLE;
739 luaK_fixline(fs, line); 740 luaK_fixline(fs, line);
740 } 741 }
@@ -752,7 +753,7 @@ static void codecomp (FuncState *fs, OpCode op, int cond, expdesc *e1,
752 temp = o1; o1 = o2; o2 = temp; /* o1 <==> o2 */ 753 temp = o1; o1 = o2; o2 = temp; /* o1 <==> o2 */
753 cond = 1; 754 cond = 1;
754 } 755 }
755 e1->u.s.info = condjump(fs, op, cond, o1, o2); 756 e1->u.info = condjump(fs, op, cond, o1, o2);
756 e1->k = VJMP; 757 e1->k = VJMP;
757} 758}
758 759
@@ -828,10 +829,10 @@ void luaK_posfix (FuncState *fs, BinOpr op,
828 case OPR_CONCAT: { 829 case OPR_CONCAT: {
829 luaK_exp2val(fs, e2); 830 luaK_exp2val(fs, e2);
830 if (e2->k == VRELOCABLE && GET_OPCODE(getcode(fs, e2)) == OP_CONCAT) { 831 if (e2->k == VRELOCABLE && GET_OPCODE(getcode(fs, e2)) == OP_CONCAT) {
831 lua_assert(e1->u.s.info == GETARG_B(getcode(fs, e2))-1); 832 lua_assert(e1->u.info == GETARG_B(getcode(fs, e2))-1);
832 freeexp(fs, e1); 833 freeexp(fs, e1);
833 SETARG_B(getcode(fs, e2), e1->u.s.info); 834 SETARG_B(getcode(fs, e2), e1->u.info);
834 e1->k = VRELOCABLE; e1->u.s.info = e2->u.s.info; 835 e1->k = VRELOCABLE; e1->u.info = e2->u.info;
835 } 836 }
836 else { 837 else {
837 luaK_exp2nextreg(fs, e2); /* operand must be on the 'stack' */ 838 luaK_exp2nextreg(fs, e2); /* operand must be on the 'stack' */