scmno****@osdn*****
scmno****@osdn*****
Tue Jun 26 05:11:27 JST 2018
changeset 1deed614687f in quipu/quipu details: http://hg.osdn.jp/view/quipu/quipu?cmd=changeset;node=1deed614687f user: Agustina Arzille <avarz****@riseu*****> date: Mon Jun 25 17:11:18 2018 -0300 description: Implement LDCALLER opcode for (t)recur(.l) diffstat: bytecode.cpp | 133 ++++++++++++++++++++++++++------------------------- bytecode.h | 1 + compiler.cpp | 2 +- eval.cpp | 38 +++++++------- utils/genopnames.py | 2 +- utils/opnames | 1 + 6 files changed, 91 insertions(+), 86 deletions(-) diffs (259 lines): diff -r b09334915327 -r 1deed614687f bytecode.cpp --- a/bytecode.cpp Mon Jun 25 16:55:22 2018 -0300 +++ b/bytecode.cpp Mon Jun 25 17:11:18 2018 -0300 @@ -18,14 +18,14 @@ "nop\0dup\0pop\0ret\0is\0not\0cons\0list\0car\0cdr\0cadr\0nputcar\0" "nputcdr\0apply\0tapply\0loadt\0loadnil\0load0\0load1\0loadi8\0loada0\0" "loada1\0loadc00\0loadc01\0loadap0\0loadap1\0mkcont\0captenv\0closure\0" - "tryend\0raise\0raise2\0argc\0argc.l\0vargc\0vargc.l\0jmp\0jmp.l\0" - "brt\0brt.l\0brn\0brn.l\0brneq\0brneq.l\0tcall\0tcall.l\0call\0call.l\0" - "setc\0setc.l\0seta\0seta.l\0setap\0setap.l\0setg\0setg.l\0loadc\0" - "loadc.l\0loada\0loada.l\0loadap\0loadap.l\0loadg\0loadg.l\0loadv\0" - "loadv.l\0loadx\0loadx.l\0bind\0bind.l\0recur\0recur.l\0trecur\0trecur.l\0" - "mkframe\0mkframe.l\0unwind\0unwind.l\0trybegin\0trybegin.l\0setapop\0" - "setapop.l\0irtjmp\0irtjmp.l\0optargs\0optargs.l\0brbound\0brbound.l\0" - "kwargs\0kwargs.l"; + "tryend\0raise\0raise2\0ldcaller\0argc\0argc.l\0vargc\0vargc.l\0jmp\0" + "jmp.l\0brt\0brt.l\0brn\0brn.l\0brneq\0brneq.l\0tcall\0tcall.l\0call\0" + "call.l\0setc\0setc.l\0seta\0seta.l\0setap\0setap.l\0setg\0setg.l\0" + "loadc\0loadc.l\0loada\0loada.l\0loadap\0loadap.l\0loadg\0loadg.l\0" + "loadv\0loadv.l\0loadx\0loadx.l\0bind\0bind.l\0recur\0recur.l\0trecur\0" + "trecur.l\0mkframe\0mkframe.l\0unwind\0unwind.l\0trybegin\0trybegin.l\0" + "setapop\0setapop.l\0irtjmp\0irtjmp.l\0optargs\0optargs.l\0brbound\0" + "brbound.l\0kwargs\0kwargs.l"; #define F_(n) 1 << (BC_FLG_FBIT + n) @@ -71,64 +71,65 @@ { 177, 0 }, // tryend { 184, 0 }, // raise { 190, 0 }, // raise2 - { 197, 1 }, // argc - { 202, 1 | BC_LONG_FORM }, // argc.l - { 209, 1 }, // vargc - { 215, 1 | BC_LONG_FORM }, // vargc.l - { 223, 1 | BC_BRANCH_FORM }, // jmp - { 227, 1 | BC_BRANCH_FORM | BC_LONG_FORM }, // jmp.l - { 233, 1 | BC_BRANCH_FORM }, // brt - { 237, 1 | BC_BRANCH_FORM | BC_LONG_FORM }, // brt.l - { 243, 1 | BC_BRANCH_FORM }, // brn - { 247, 1 | BC_BRANCH_FORM | BC_LONG_FORM }, // brn.l - { 253, 1 | BC_BRANCH_FORM }, // brneq - { 259, 1 | BC_BRANCH_FORM | BC_LONG_FORM }, // brneq.l - { 267, 1 | BC_CALL_FORM }, // tcall - { 273, 1 | BC_CALL_FORM | BC_LONG_FORM }, // tcall.l - { 281, 1 | BC_CALL_FORM }, // call - { 286, 1 | BC_CALL_FORM | BC_LONG_FORM }, // call.l - { 293, 2 }, // setc - { 298, 2 | BC_LONG_FORM }, // setc.l - { 305, 1 }, // seta - { 310, 1 | BC_LONG_FORM }, // seta.l - { 317, 2 }, // setap - { 323, 2 | BC_LONG_FORM }, // setap.l - { 331, 1 }, // setg - { 336, 1 | BC_LONG_FORM }, // setg.l - { 343, 2 | BC_LOAD_FORM | BC_PURE_FORM }, // loadc - { 349, 2 | BC_LOAD_FORM | BC_PURE_FORM | BC_LONG_FORM }, // loadc.l - { 357, 1 | BC_LOAD_FORM | BC_PURE_FORM }, // loada - { 363, 1 | BC_LOAD_FORM | BC_PURE_FORM | BC_LONG_FORM }, // loada.l - { 371, 2 | BC_LOAD_FORM | BC_PURE_FORM }, // loadap - { 378, 2 | BC_LOAD_FORM | BC_PURE_FORM | BC_LONG_FORM }, // loadap.l - { 387, 1 | BC_LOAD_FORM }, // loadg - { 393, 1 | BC_LOAD_FORM | BC_LONG_FORM }, // loadg.l - { 401, 1 | BC_LOAD_FORM | BC_PURE_FORM }, // loadv - { 407, 1 | BC_LOAD_FORM | BC_PURE_FORM | BC_LONG_FORM }, // loadv.l - { 415, 1 | BC_LOAD_FORM }, // loadx - { 421, 1 | BC_LOAD_FORM | BC_LONG_FORM }, // loadx.l - { 429, 1 }, // bind - { 434, 1 | BC_LONG_FORM }, // bind.l - { 441, 1 | BC_CALL_FORM }, // recur - { 447, 1 | BC_CALL_FORM | BC_LONG_FORM }, // recur.l - { 455, 1 | BC_CALL_FORM }, // trecur - { 462, 1 | BC_CALL_FORM | BC_LONG_FORM }, // trecur.l - { 471, 1 }, // mkframe - { 479, 1 | BC_LONG_FORM }, // mkframe.l - { 489, 1 }, // unwind - { 496, 1 | BC_LONG_FORM }, // unwind.l - { 505, 1 | BC_BRANCH_FORM }, // trybegin - { 514, 1 | BC_BRANCH_FORM | BC_LONG_FORM }, // trybegin.l - { 525, 1 }, // setapop - { 533, 1 | BC_LONG_FORM }, // setapop.l - { 543, 1 | BC_BRANCH_FORM }, // irtjmp - { 550, 1 | BC_BRANCH_FORM | BC_LONG_FORM }, // irtjmp.l - { 559, 2 }, // optargs - { 567, 2 | BC_LONG_FORM }, // optargs.l - { 577, 1 }, // brbound - { 585, 1 | BC_LONG_FORM }, // brbound.l - { 595, 3 }, // kwargs - { 602, 3 | BC_LONG_FORM }, // kwargs.l + { 197, 0 }, // ldcaller + { 206, 1 }, // argc + { 211, 1 | BC_LONG_FORM }, // argc.l + { 218, 1 }, // vargc + { 224, 1 | BC_LONG_FORM }, // vargc.l + { 232, 1 | BC_BRANCH_FORM }, // jmp + { 236, 1 | BC_BRANCH_FORM | BC_LONG_FORM }, // jmp.l + { 242, 1 | BC_BRANCH_FORM }, // brt + { 246, 1 | BC_BRANCH_FORM | BC_LONG_FORM }, // brt.l + { 252, 1 | BC_BRANCH_FORM }, // brn + { 256, 1 | BC_BRANCH_FORM | BC_LONG_FORM }, // brn.l + { 262, 1 | BC_BRANCH_FORM }, // brneq + { 268, 1 | BC_BRANCH_FORM | BC_LONG_FORM }, // brneq.l + { 276, 1 | BC_CALL_FORM }, // tcall + { 282, 1 | BC_CALL_FORM | BC_LONG_FORM }, // tcall.l + { 290, 1 | BC_CALL_FORM }, // call + { 295, 1 | BC_CALL_FORM | BC_LONG_FORM }, // call.l + { 302, 2 }, // setc + { 307, 2 | BC_LONG_FORM }, // setc.l + { 314, 1 }, // seta + { 319, 1 | BC_LONG_FORM }, // seta.l + { 326, 2 }, // setap + { 332, 2 | BC_LONG_FORM }, // setap.l + { 340, 1 }, // setg + { 345, 1 | BC_LONG_FORM }, // setg.l + { 352, 2 | BC_LOAD_FORM | BC_PURE_FORM }, // loadc + { 358, 2 | BC_LOAD_FORM | BC_PURE_FORM | BC_LONG_FORM }, // loadc.l + { 366, 1 | BC_LOAD_FORM | BC_PURE_FORM }, // loada + { 372, 1 | BC_LOAD_FORM | BC_PURE_FORM | BC_LONG_FORM }, // loada.l + { 380, 2 | BC_LOAD_FORM | BC_PURE_FORM }, // loadap + { 387, 2 | BC_LOAD_FORM | BC_PURE_FORM | BC_LONG_FORM }, // loadap.l + { 396, 1 | BC_LOAD_FORM }, // loadg + { 402, 1 | BC_LOAD_FORM | BC_LONG_FORM }, // loadg.l + { 410, 1 | BC_LOAD_FORM | BC_PURE_FORM }, // loadv + { 416, 1 | BC_LOAD_FORM | BC_PURE_FORM | BC_LONG_FORM }, // loadv.l + { 424, 1 | BC_LOAD_FORM }, // loadx + { 430, 1 | BC_LOAD_FORM | BC_LONG_FORM }, // loadx.l + { 438, 1 }, // bind + { 443, 1 | BC_LONG_FORM }, // bind.l + { 450, 1 | BC_CALL_FORM }, // recur + { 456, 1 | BC_CALL_FORM | BC_LONG_FORM }, // recur.l + { 464, 1 | BC_CALL_FORM }, // trecur + { 471, 1 | BC_CALL_FORM | BC_LONG_FORM }, // trecur.l + { 480, 1 }, // mkframe + { 488, 1 | BC_LONG_FORM }, // mkframe.l + { 498, 1 }, // unwind + { 505, 1 | BC_LONG_FORM }, // unwind.l + { 514, 1 | BC_BRANCH_FORM }, // trybegin + { 523, 1 | BC_BRANCH_FORM | BC_LONG_FORM }, // trybegin.l + { 534, 1 }, // setapop + { 542, 1 | BC_LONG_FORM }, // setapop.l + { 552, 1 | BC_BRANCH_FORM }, // irtjmp + { 559, 1 | BC_BRANCH_FORM | BC_LONG_FORM }, // irtjmp.l + { 568, 2 }, // optargs + { 576, 2 | BC_LONG_FORM }, // optargs.l + { 586, 1 }, // brbound + { 594, 1 | BC_LONG_FORM }, // brbound.l + { 604, 3 }, // kwargs + { 611, 3 | BC_LONG_FORM }, // kwargs.l { 0, 0 } }; diff -r b09334915327 -r 1deed614687f bytecode.h --- a/bytecode.h Mon Jun 25 16:55:22 2018 -0300 +++ b/bytecode.h Mon Jun 25 17:11:18 2018 -0300 @@ -39,6 +39,7 @@ OP_TRYEND, OP_RAISE, OP_RAISE2, + OP_LDCALLER, // Opcodes with long forms. OP_ARGC, OP_ARGCL, diff -r b09334915327 -r 1deed614687f compiler.cpp --- a/compiler.cpp Mon Jun 25 16:55:22 2018 -0300 +++ b/compiler.cpp Mon Jun 25 17:11:18 2018 -0300 @@ -1521,7 +1521,7 @@ outside_error (this->interp, "recur", "function"); { - this->emit (OPX_(LOADNIL)); // XXX: Should be LOADCALLER + this->emit (OPX_(LDCALLER)); int n = this->compile_arglist (env, xcdr (expr)); this->emit (tail ? OPX_(TRECUR) : OPX_(RECUR), intobj (n)); break; diff -r b09334915327 -r 1deed614687f eval.cpp --- a/eval.cpp Mon Jun 25 16:55:22 2018 -0300 +++ b/eval.cpp Mon Jun 25 17:11:18 2018 -0300 @@ -229,22 +229,22 @@ const void* const LABELS[] = { # define P_(opc) [OP_##opc] = &&OP_LBL_##opc - P_(NOP), P_(DUP), P_(POP), P_(RET), P_(IS), P_(NOT), P_(CONS), P_(LIST), - P_(CAR), P_(CDR), P_(CADR), P_(NPUTCAR), P_(NPUTCDR), P_(APPLY), - P_(TAPPLY), P_(LOADT), P_(LOADNIL), P_(LOAD0), P_(LOAD1), P_(LOADI8), - P_(LOADA0), P_(LOADA1), P_(LOADC00), P_(LOADC01), P_(LOADAP0), - P_(LOADAP1), P_(MKCONT), P_(CAPTENV), P_(CLOSURE), P_(TRYEND), P_(RAISE), - P_(RAISE2), P_(ARGC), P_(ARGCL), P_(VARGC), P_(VARGCL), P_(JMP), - P_(JMPL), P_(BRT), P_(BRTL), P_(BRN), P_(BRNL), P_(BRNEQ), P_(BRNEQL), - P_(TCALL), P_(TCALLL), P_(CALL), P_(CALLL), P_(SETC), P_(SETCL), - P_(SETA), P_(SETAL), P_(SETAP), P_(SETAPL), P_(SETG), P_(SETGL), - P_(LOADC), P_(LOADCL), P_(LOADA), P_(LOADAL), P_(LOADAP), P_(LOADAPL), - P_(LOADG), P_(LOADGL), P_(LOADV), P_(LOADVL), P_(LOADX), P_(LOADXL), - P_(BIND), P_(BINDL), P_(RECUR), P_(RECURL), P_(TRECUR), P_(TRECURL), - P_(MKFRAME), P_(MKFRAMEL), P_(UNWIND), P_(UNWINDL), P_(TRYBEGIN), - P_(TRYBEGINL), P_(SETAPOP), P_(SETAPOPL), P_(IRTJMP), P_(IRTJMPL), - P_(OPTARGS), P_(OPTARGSL), P_(BRBOUND), P_(BRBOUNDL), P_(KWARGS), - P_(KWARGSL) + P_(NOP), P_(DUP), P_(POP), P_(RET), P_(IS), P_(NOT), P_(CONS), + P_(LIST), P_(CAR), P_(CDR), P_(CADR), P_(NPUTCAR), P_(NPUTCDR), + P_(APPLY), P_(TAPPLY), P_(LOADT), P_(LOADNIL), P_(LOAD0), P_(LOAD1), + P_(LOADI8), P_(LOADA0), P_(LOADA1), P_(LOADC00), P_(LOADC01), + P_(LOADAP0), P_(LOADAP1), P_(MKCONT), P_(CAPTENV), P_(CLOSURE), + P_(TRYEND), P_(RAISE), P_(RAISE2), P_(LDCALLER), P_(ARGC), P_(ARGCL), + P_(VARGC), P_(VARGCL), P_(JMP), P_(JMPL), P_(BRT), P_(BRTL), P_(BRN), + P_(BRNL), P_(BRNEQ), P_(BRNEQL), P_(TCALL), P_(TCALLL), P_(CALL), + P_(CALLL), P_(SETC), P_(SETCL), P_(SETA), P_(SETAL), P_(SETAP), + P_(SETAPL), P_(SETG), P_(SETGL), P_(LOADC), P_(LOADCL), P_(LOADA), + P_(LOADAL), P_(LOADAP), P_(LOADAPL), P_(LOADG), P_(LOADGL), P_(LOADV), + P_(LOADVL), P_(LOADX), P_(LOADXL), P_(BIND), P_(BINDL), P_(RECUR), + P_(RECURL), P_(TRECUR), P_(TRECURL), P_(MKFRAME), P_(MKFRAMEL), + P_(UNWIND), P_(UNWINDL), P_(TRYBEGIN), P_(TRYBEGINL), P_(SETAPOP), + P_(SETAPOPL), P_(IRTJMP), P_(IRTJMPL), P_(OPTARGS), P_(OPTARGSL), + P_(BRBOUND), P_(BRBOUNDL), P_(KWARGS), P_(KWARGSL) }; # undef P_ @@ -742,16 +742,18 @@ NEXT_OP; + OP_(LDCALLER): + U_PUSH (stack[bp - 1]); + NEXT_OP; + OP_(RECUR): OP_(RECURL): n = ip_ival (ip); - r_stkend(n + 1) = stack[bp - 1]; goto do_call; OP_(TRECUR): OP_(TRECURL): n = ip_ival (ip); - r_stkend(n + 1) = stack[bp - 1]; interp->cur_frame = lastf; move_objs (&stack[interp->cur_frame], stkend - n - 1, n + 1); bp = interp->cur_frame, stkend = stack + bp + n + 1; diff -r b09334915327 -r 1deed614687f utils/genopnames.py --- a/utils/genopnames.py Mon Jun 25 16:55:22 2018 -0300 +++ b/utils/genopnames.py Mon Jun 25 17:11:18 2018 -0300 @@ -46,7 +46,7 @@ print ("\n %s" % s, end = '') ulen = 2 else: - print ("%s " % s, end = '') + print (" %s" % s, end = '') ulen += 1 print ("\n};") diff -r b09334915327 -r 1deed614687f utils/opnames --- a/utils/opnames Mon Jun 25 16:55:22 2018 -0300 +++ b/utils/opnames Mon Jun 25 17:11:18 2018 -0300 @@ -30,6 +30,7 @@ tryend 0 0 raise 0 0 raise2 0 0 +ldcaller 0 0 argc 1 0 argc.l 1 long vargc 1 0