scmno****@osdn*****
scmno****@osdn*****
Sat Jun 2 00:39:59 JST 2018
changeset 4a20d9c7334b in quipu/quipu details: http://hg.osdn.jp/view/quipu/quipu?cmd=changeset;node=4a20d9c7334b user: Agustina Arzille <avarz****@riseu*****> date: Fri Jun 01 12:39:49 2018 -0300 description: Rework 3 old bytecodes diffstat: bytecode.cpp | 156 +++++++++++++++++++++++++++++---------------------------- bytecode.h | 11 ++- compiler.cpp | 56 +++++++++++++------- memory.cpp | 2 +- utils/opnames | 9 ++- 5 files changed, 129 insertions(+), 105 deletions(-) diffs (truncated from 358 to 300 lines): diff -r ca65cd5f4e81 -r 4a20d9c7334b bytecode.cpp --- a/bytecode.cpp Wed May 30 19:12:35 2018 -0300 +++ b/bytecode.cpp Fri Jun 01 12:39:49 2018 -0300 @@ -17,23 +17,23 @@ static const char OPC_NAMES[] = "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\0loadap1\0optargs\0brbound\0kwargs\0mkcont\0" - "captenv\0closure\0tryend\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\0setb\0setb.l\0" - "loadc\0loadc.l\0loada\0loada.l\0loadap\0loadap.l\0loadg\0loadg.l\0" - "loadv\0loadv.l\0loadx\0loadx.l\0loadb\0loadb.l\0bind\0bind.l\0recur\0" - "recur.l\0trecur\0trecur.l\0mkframe\0mkframe.l\0unwind\0unwind.l\0" - "trybegin\0trybegin.l\0setapop\0setapop.l\0irtjmp\0irtjmp.l"; + "loada1\0loadc00\0loadc01\0loadap1\0mkcont\0captenv\0closure\0tryend\0" + "argc\0argc.l\0vargc\0vargc.l\0jmp\0jmp.l\0brt\0brt.l\0brn\0brn.l\0" + "brneq\0brneq.l\0tcall\0tcall.l\0call\0call.l\0setc\0setc.l\0seta\0" + "seta.l\0setap\0setap.l\0setg\0setg.l\0setb\0setb.l\0loadc\0loadc.l\0" + "loada\0loada.l\0loadap\0loadap.l\0loadg\0loadg.l\0loadv\0loadv.l\0" + "loadx\0loadx.l\0loadb\0loadb.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) static const int BC_CALL_FORM = F_(0); static const int BC_LOAD_FORM = F_(1); -static const int BC_INT32_FORM = F_(2); -static const int BC_BRANCH_FORM = F_(3); -static const int BC_LONG_FORM = F_(4); -static const int BC_PURE_FORM = F_(5); +static const int BC_BRANCH_FORM = F_(2); +static const int BC_LONG_FORM = F_(3); +static const int BC_PURE_FORM = F_(4); #undef F_ @@ -64,71 +64,73 @@ { 122, 0 | BC_LOAD_FORM | BC_PURE_FORM }, // loadc00 { 130, 0 | BC_LOAD_FORM | BC_PURE_FORM }, // loadc01 { 138, 1 | BC_LOAD_FORM | BC_PURE_FORM }, // loadap1 - { 146, 2 | BC_INT32_FORM }, // optargs - { 154, 1 | BC_INT32_FORM }, // brbound - { 162, 3 | BC_INT32_FORM }, // kwargs - { 169, 1 | BC_LOAD_FORM }, // mkcont - { 176, 0 }, // captenv - { 184, 0 }, // closure - { 192, 0 }, // tryend - { 199, 1 }, // argc - { 204, 1 | BC_LONG_FORM }, // argc.l - { 211, 1 }, // vargc - { 217, 1 | BC_LONG_FORM }, // vargc.l - { 225, 1 | BC_BRANCH_FORM }, // jmp - { 229, 1 | BC_BRANCH_FORM | BC_LONG_FORM }, // jmp.l - { 235, 1 | BC_BRANCH_FORM }, // brt - { 239, 1 | BC_BRANCH_FORM | BC_LONG_FORM }, // brt.l - { 245, 1 | BC_BRANCH_FORM }, // brn - { 249, 1 | BC_BRANCH_FORM | BC_LONG_FORM }, // brn.l - { 255, 1 | BC_BRANCH_FORM }, // brneq - { 261, 1 | BC_BRANCH_FORM | BC_LONG_FORM }, // brneq.l - { 269, 1 | BC_CALL_FORM }, // tcall - { 275, 1 | BC_CALL_FORM | BC_LONG_FORM }, // tcall.l - { 283, 1 | BC_CALL_FORM }, // call - { 288, 1 | BC_CALL_FORM | BC_LONG_FORM }, // call.l - { 295, 2 }, // setc - { 300, 2 | BC_LONG_FORM }, // setc.l - { 307, 1 }, // seta - { 312, 1 | BC_LONG_FORM }, // seta.l - { 319, 2 }, // setap - { 325, 2 | BC_LONG_FORM }, // setap.l - { 333, 1 }, // setg - { 338, 1 | BC_LONG_FORM }, // setg.l - { 345, 1 }, // setb - { 350, 1 | BC_LONG_FORM }, // setb.l - { 357, 2 | BC_LOAD_FORM | BC_PURE_FORM }, // loadc - { 363, 2 | BC_LOAD_FORM | BC_PURE_FORM | BC_LONG_FORM }, // loadc.l - { 371, 1 | BC_LOAD_FORM | BC_PURE_FORM }, // loada - { 377, 1 | BC_LOAD_FORM | BC_PURE_FORM | BC_LONG_FORM }, // loada.l - { 385, 2 | BC_LOAD_FORM | BC_PURE_FORM }, // loadap - { 392, 2 | BC_LOAD_FORM | BC_PURE_FORM | BC_LONG_FORM }, // loadap.l - { 401, 1 | BC_LOAD_FORM }, // loadg - { 407, 1 | BC_LOAD_FORM | BC_LONG_FORM }, // loadg.l - { 415, 1 | BC_LOAD_FORM | BC_PURE_FORM }, // loadv - { 421, 1 | BC_LOAD_FORM | BC_PURE_FORM | BC_LONG_FORM }, // loadv.l - { 429, 1 | BC_LOAD_FORM }, // loadx - { 435, 1 | BC_LOAD_FORM | BC_LONG_FORM }, // loadx.l - { 443, 1 | BC_LOAD_FORM | BC_PURE_FORM }, // loadb - { 449, 1 | BC_LOAD_FORM | BC_PURE_FORM | BC_LONG_FORM }, // loadb.l - { 457, 1 }, // bind - { 462, 1 | BC_LONG_FORM }, // bind.l - { 469, 1 | BC_CALL_FORM }, // recur - { 475, 1 | BC_CALL_FORM | BC_LONG_FORM }, // recur.l - { 483, 1 | BC_CALL_FORM }, // trecur - { 490, 1 | BC_CALL_FORM | BC_LONG_FORM }, // trecur.l - { 499, 1 }, // mkframe - { 507, 1 | BC_LONG_FORM }, // mkframe.l - { 517, 1 }, // unwind - { 524, 1 | BC_LONG_FORM }, // unwind.l - { 533, 1 | BC_BRANCH_FORM }, // trybegin - { 542, 1 | BC_BRANCH_FORM | BC_LONG_FORM }, // trybegin.l - { 553, 1 }, // setapop - { 561, 1 | BC_LONG_FORM }, // setapop.l - { 571, 1 | BC_BRANCH_FORM }, // irtjmp - { 578, 1 | BC_BRANCH_FORM | BC_LONG_FORM }, // irtjmp.l + { 146, 1 | BC_LOAD_FORM }, // mkcont + { 153, 0 }, // captenv + { 161, 0 }, // closure + { 169, 0 }, // tryend + { 176, 1 }, // argc + { 181, 1 | BC_LONG_FORM }, // argc.l + { 188, 1 }, // vargc + { 194, 1 | BC_LONG_FORM }, // vargc.l + { 202, 1 | BC_BRANCH_FORM }, // jmp + { 206, 1 | BC_BRANCH_FORM | BC_LONG_FORM }, // jmp.l + { 212, 1 | BC_BRANCH_FORM }, // brt + { 216, 1 | BC_BRANCH_FORM | BC_LONG_FORM }, // brt.l + { 222, 1 | BC_BRANCH_FORM }, // brn + { 226, 1 | BC_BRANCH_FORM | BC_LONG_FORM }, // brn.l + { 232, 1 | BC_BRANCH_FORM }, // brneq + { 238, 1 | BC_BRANCH_FORM | BC_LONG_FORM }, // brneq.l + { 246, 1 | BC_CALL_FORM }, // tcall + { 252, 1 | BC_CALL_FORM | BC_LONG_FORM }, // tcall.l + { 260, 1 | BC_CALL_FORM }, // call + { 265, 1 | BC_CALL_FORM | BC_LONG_FORM }, // call.l + { 272, 2 }, // setc + { 277, 2 | BC_LONG_FORM }, // setc.l + { 284, 1 }, // seta + { 289, 1 | BC_LONG_FORM }, // seta.l + { 296, 2 }, // setap + { 302, 2 | BC_LONG_FORM }, // setap.l + { 310, 1 }, // setg + { 315, 1 | BC_LONG_FORM }, // setg.l + { 322, 1 }, // setb + { 327, 1 | BC_LONG_FORM }, // setb.l + { 334, 2 | BC_LOAD_FORM | BC_PURE_FORM }, // loadc + { 340, 2 | BC_LOAD_FORM | BC_PURE_FORM | BC_LONG_FORM }, // loadc.l + { 348, 1 | BC_LOAD_FORM | BC_PURE_FORM }, // loada + { 354, 1 | BC_LOAD_FORM | BC_PURE_FORM | BC_LONG_FORM }, // loada.l + { 362, 2 | BC_LOAD_FORM | BC_PURE_FORM }, // loadap + { 369, 2 | BC_LOAD_FORM | BC_PURE_FORM | BC_LONG_FORM }, // loadap.l + { 378, 1 | BC_LOAD_FORM }, // loadg + { 384, 1 | BC_LOAD_FORM | BC_LONG_FORM }, // loadg.l + { 392, 1 | BC_LOAD_FORM | BC_PURE_FORM }, // loadv + { 398, 1 | BC_LOAD_FORM | BC_PURE_FORM | BC_LONG_FORM }, // loadv.l + { 406, 1 | BC_LOAD_FORM }, // loadx + { 412, 1 | BC_LOAD_FORM | BC_LONG_FORM }, // loadx.l + { 420, 1 | BC_LOAD_FORM | BC_PURE_FORM }, // loadb + { 426, 1 | BC_LOAD_FORM | BC_PURE_FORM | BC_LONG_FORM }, // loadb.l + { 434, 1 }, // bind + { 439, 1 | BC_LONG_FORM }, // bind.l + { 446, 1 | BC_CALL_FORM }, // recur + { 452, 1 | BC_CALL_FORM | BC_LONG_FORM }, // recur.l + { 460, 1 | BC_CALL_FORM }, // trecur + { 467, 1 | BC_CALL_FORM | BC_LONG_FORM }, // trecur.l + { 476, 1 }, // mkframe + { 484, 1 | BC_LONG_FORM }, // mkframe.l + { 494, 1 }, // unwind + { 501, 1 | BC_LONG_FORM }, // unwind.l + { 510, 1 | BC_BRANCH_FORM }, // trybegin + { 519, 1 | BC_BRANCH_FORM | BC_LONG_FORM }, // trybegin.l + { 530, 1 }, // setapop + { 538, 1 | BC_LONG_FORM }, // setapop.l + { 548, 1 | BC_BRANCH_FORM }, // irtjmp + { 555, 1 | BC_BRANCH_FORM | BC_LONG_FORM }, // irtjmp.l + { 564, 2 }, // optargs + { 572, 2 | BC_LONG_FORM }, // optargs.l + { 582, 1 }, // brbound + { 590, 1 | BC_LONG_FORM }, // brbound.l + { 600, 3 }, // kwargs + { 607, 3 | BC_LONG_FORM }, // kwargs.l { 0, 0 } - }; const bcode_instr* bcode_get (int opc) @@ -178,7 +180,7 @@ int bcode_instr::argsize () const { - return ((this->flg_ex & (BC_LONG_FORM | BC_INT32_FORM)) ? + return ((this->flg_ex & BC_LONG_FORM) ? sizeof (int32_t) : (this->flg_ex & BC_BRANCH_FORM) ? sizeof (int16_t) : 1); } diff -r ca65cd5f4e81 -r 4a20d9c7334b bytecode.h --- a/bytecode.h Wed May 30 19:12:35 2018 -0300 +++ b/bytecode.h Fri Jun 01 12:39:49 2018 -0300 @@ -32,9 +32,6 @@ OP_LOADC00, OP_LOADC01, OP_LOADAP1, - OP_OPTARGS, - OP_BRBOUND, - OP_KWARGS, OP_MKCONT, OP_CAPTENV, OP_CLOSURE, @@ -95,7 +92,13 @@ OP_SETAPOP, OP_SETAPOPL, OP_IRTJMP, - OP_IRTJMPL + OP_IRTJMPL, + OP_OPTARGS, + OP_OPTARGSL, + OP_BRBOUND, + OP_BRBOUNDL, + OP_KWARGS, + OP_KWARGSL }; class bcode_instr diff -r ca65cd5f4e81 -r 4a20d9c7334b compiler.cpp --- a/compiler.cpp Wed May 30 19:12:35 2018 -0300 +++ b/compiler.cpp Fri Jun 01 12:39:49 2018 -0300 @@ -1564,7 +1564,7 @@ } static object -make_kwtab (interpreter *interp, arglist& args) +make_kwtab (interpreter *interp, arglist& args, int off = 0) { int n = upsize (args.n + 1); array *tab = as_array (alloc_array (interp, n * 2)); @@ -1577,7 +1577,7 @@ if (tab->data[idx * 2] == UNBOUND) { tab->data[idx * 2 + 0] = obj; - tab->data[idx * 2 + 1] = intobj (i); + tab->data[idx * 2 + 1] = intobj (i + off); break; } } @@ -1615,7 +1615,7 @@ intobj (atail == NIL ? nargs : -nargs)); else { - (void)this->index (make_kwtab (interp, pa.kw)); + (void)this->index (make_kwtab (interp, pa.kw, pa.opt.n)); this->emit (OPX_(KWARGS), intobj (nreq), intobj (pa.kw.n), intobj (atail == NIL ? nargs : -nargs)); } @@ -2195,17 +2195,18 @@ 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_(LOADAP1), - P_(OPTARGS), P_(BRBOUND), P_(KWARGS), P_(MKCONT), P_(CAPTENV), - P_(CLOSURE), P_(TRYEND), 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_(SETB), P_(SETBL), 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_(LOADB), P_(LOADBL), 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_(MKCONT), P_(CAPTENV), P_(CLOSURE), P_(TRYEND), 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_(SETB), P_(SETBL), 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_(LOADB), + P_(LOADBL), 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_ @@ -2310,7 +2311,8 @@ NEXT_OP; OP_(BRBOUND): - U_PUSH (locals[fetch32 (ip)] != UNBOUND ? QP_S(t) : NIL); + OP_(BRBOUNDL): + U_PUSH (locals[ip_ival (ip)] != UNBOUND ? QP_S(t) : NIL); NEXT_OP; OP_(DUP): @@ -2697,8 +2699,11 @@ NEXT_OP; OP_(OPTARGS): - ix = fetch32 (ip); - n = fetch32 (ip); + OP_(OPTARGSL): + if (qp_likely (!bcode_long_p (*(ip - 1)))) + ix = *ip++, n = (int8_t)*ip++; + else + ix = fetch32 (ip), n = fetch32 (ip); if (nargs < ix) interp->raise2 ("arg-error", "apply: too few arguments"); @@ -2742,10 +2747,21 @@ goto do_tcall;