aboutsummaryrefslogtreecommitdiff
path: root/lcode.c
diff options
context:
space:
mode:
Diffstat (limited to 'lcode.c')
-rw-r--r--lcode.c108
1 files changed, 53 insertions, 55 deletions
diff --git a/lcode.c b/lcode.c
index 98ad5078..4163c66d 100644
--- a/lcode.c
+++ b/lcode.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lcode.c,v 1.38 2000/06/21 18:13:56 roberto Exp roberto $ 2** $Id: lcode.c,v 1.39 2000/06/26 19:28:31 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*/
@@ -423,12 +423,9 @@ int luaK_code1 (FuncState *fs, OpCode o, int arg1) {
423} 423}
424 424
425 425
426#define VD 100 /* flag for variable delta */
427
428
429int luaK_code2 (FuncState *fs, OpCode o, int arg1, int arg2) { 426int luaK_code2 (FuncState *fs, OpCode o, int arg1, int arg2) {
430 Instruction i = previous_instruction(fs); 427 Instruction i = previous_instruction(fs);
431 int delta = luaK_opproperties[o].delta; 428 int delta = luaK_opproperties[o].push - luaK_opproperties[o].pop;
432 int optm = 0; /* 1 when there is an optimization */ 429 int optm = 0; /* 1 when there is an optimization */
433 switch (o) { 430 switch (o) {
434 case OP_CLOSURE: { 431 case OP_CLOSURE: {
@@ -621,7 +618,7 @@ int luaK_code2 (FuncState *fs, OpCode o, int arg1, int arg2) {
621 case iS: i = CREATE_S(o, arg1); break; 618 case iS: i = CREATE_S(o, arg1); break;
622 case iAB: i = CREATE_AB(o, arg1, arg2); break; 619 case iAB: i = CREATE_AB(o, arg1, arg2); break;
623 } 620 }
624 if (fs->f->debug) { 621 if (fs->debug) {
625 LexState *ls = fs->ls; 622 LexState *ls = fs->ls;
626 luaX_checklimit(ls, ls->lastline, MAXARG_U, "lines in a chunk"); 623 luaX_checklimit(ls, ls->lastline, MAXARG_U, "lines in a chunk");
627 luaM_growvector(fs->L, fs->f->lines, fs->pc, 1, int, "??", MAXARG_U); 624 luaM_growvector(fs->L, fs->f->lines, fs->pc, 1, int, "??", MAXARG_U);
@@ -636,53 +633,54 @@ int luaK_code2 (FuncState *fs, OpCode o, int arg1, int arg2) {
636 633
637 634
638const struct OpProperties luaK_opproperties[NUM_OPCODES] = { 635const struct OpProperties luaK_opproperties[NUM_OPCODES] = {
639 {iO, 0}, /* OP_END */ 636 {iO, 0, 0}, /* OP_END */
640 {iU, 0}, /* OP_RETURN */ 637 {iU, 0, 0}, /* OP_RETURN */
641 {iAB, 0}, /* OP_CALL */ 638 {iAB, 0, 0}, /* OP_CALL */
642 {iAB, 0}, /* OP_TAILCALL */ 639 {iAB, 0, 0}, /* OP_TAILCALL */
643 {iU, VD}, /* OP_PUSHNIL */ 640 {iU, VD, 0}, /* OP_PUSHNIL */
644 {iU, VD}, /* OP_POP */ 641 {iU, VD, 0}, /* OP_POP */
645 {iS, 1}, /* OP_PUSHINT */ 642 {iS, 1, 0}, /* OP_PUSHINT */
646 {iU, 1}, /* OP_PUSHSTRING */ 643 {iU, 1, 0}, /* OP_PUSHSTRING */
647 {iU, 1}, /* OP_PUSHNUM */ 644 {iU, 1, 0}, /* OP_PUSHNUM */
648 {iU, 1}, /* OP_PUSHNEGNUM */ 645 {iU, 1, 0}, /* OP_PUSHNEGNUM */
649 {iU, 1}, /* OP_PUSHUPVALUE */ 646 {iU, 1, 0}, /* OP_PUSHUPVALUE */
650 {iU, 1}, /* OP_GETLOCAL */ 647 {iU, 1, 0}, /* OP_GETLOCAL */
651 {iU, 1}, /* OP_GETGLOBAL */ 648 {iU, 1, 0}, /* OP_GETGLOBAL */
652 {iO, -1}, /* OP_GETTABLE */ 649 {iO, 1, 2}, /* OP_GETTABLE */
653 {iU, 0}, /* OP_GETDOTTED */ 650 {iU, 1, 1}, /* OP_GETDOTTED */
654 {iU, 0}, /* OP_GETINDEXED */ 651 {iU, 1, 1}, /* OP_GETINDEXED */
655 {iU, 1}, /* OP_PUSHSELF */ 652 {iU, 2, 1}, /* OP_PUSHSELF */
656 {iU, 1}, /* OP_CREATETABLE */ 653 {iU, 1, 0}, /* OP_CREATETABLE */
657 {iU, -1}, /* OP_SETLOCAL */ 654 {iU, 0, 1}, /* OP_SETLOCAL */
658 {iU, -1}, /* OP_SETGLOBAL */ 655 {iU, 0, 1}, /* OP_SETGLOBAL */
659 {iAB, VD}, /* OP_SETTABLE */ 656 {iAB, VD, 0}, /* OP_SETTABLE */
660 {iAB, VD}, /* OP_SETLIST */ 657 {iAB, VD, 0}, /* OP_SETLIST */
661 {iU, VD}, /* OP_SETMAP */ 658 {iU, VD, 0}, /* OP_SETMAP */
662 {iO, -1}, /* OP_ADD */ 659 {iO, 1, 2}, /* OP_ADD */
663 {iS, 0}, /* OP_ADDI */ 660 {iS, 1, 1}, /* OP_ADDI */
664 {iO, -1}, /* OP_SUB */ 661 {iO, 1, 2}, /* OP_SUB */
665 {iO, -1}, /* OP_MULT */ 662 {iO, 1, 2}, /* OP_MULT */
666 {iO, -1}, /* OP_DIV */ 663 {iO, 1, 2}, /* OP_DIV */
667 {iO, -1}, /* OP_POW */ 664 {iO, 1, 2}, /* OP_POW */
668 {iU, VD}, /* OP_CONCAT */ 665 {iU, VD, 0}, /* OP_CONCAT */
669 {iO, 0}, /* OP_MINUS */ 666 {iO, 1, 1}, /* OP_MINUS */
670 {iO, 0}, /* OP_NOT */ 667 {iO, 1, 1}, /* OP_NOT */
671 {iS, -2}, /* OP_JMPNE */ 668 {iS, 0, 2}, /* OP_JMPNE */
672 {iS, -2}, /* OP_JMPEQ */ 669 {iS, 0, 2}, /* OP_JMPEQ */
673 {iS, -2}, /* OP_JMPLT */ 670 {iS, 0, 2}, /* OP_JMPLT */
674 {iS, -2}, /* OP_JMPLE */ 671 {iS, 0, 2}, /* OP_JMPLE */
675 {iS, -2}, /* OP_JMPGT */ 672 {iS, 0, 2}, /* OP_JMPGT */
676 {iS, -2}, /* OP_JMPGE */ 673 {iS, 0, 2}, /* OP_JMPGE */
677 {iS, -1}, /* OP_JMPT */ 674 {iS, 0, 1}, /* OP_JMPT */
678 {iS, -1}, /* OP_JMPF */ 675 {iS, 0, 1}, /* OP_JMPF */
679 {iS, -1}, /* OP_JMPONT */ 676 {iS, 0, 1}, /* OP_JMPONT */
680 {iS, -1}, /* OP_JMPONF */ 677 {iS, 0, 1}, /* OP_JMPONF */
681 {iS, 0}, /* OP_JMP */ 678 {iS, 0, 0}, /* OP_JMP */
682 {iO, 1}, /* OP_PUSHNILJMP */ 679 {iO, 1, 0}, /* OP_PUSHNILJMP */
683 {iS, 0}, /* OP_FORPREP */ 680 {iS, 0, 0}, /* OP_FORPREP */
684 {iS, -3}, /* OP_FORLOOP */ 681 {iS, 0, 3}, /* OP_FORLOOP */
685 {iS, 3}, /* OP_LFORPREP */ 682 {iS, 3, 0}, /* OP_LFORPREP */
686 {iS, -4}, /* OP_LFORLOOP */ 683 {iS, 0, 4}, /* OP_LFORLOOP */
687 {iAB, VD} /* OP_CLOSURE */ 684 {iAB, VD, 0} /* OP_CLOSURE */
688}; 685};
686