diff options
author | Damien <damien.p.george@gmail.com> | 2013-10-10 22:06:54 +0100 |
---|---|---|
committer | Damien <damien.p.george@gmail.com> | 2013-10-10 22:06:54 +0100 |
commit | eb19efb27e3f4a25b9b6bf90ab68eec5d08960c3 (patch) | |
tree | bdf225c1836647e895fd58be0cd4dc0838c93047 /py/vm.c | |
parent | 5609cca2ce7d2212d971ada0c3262adac25b508e (diff) | |
download | micropython-eb19efb27e3f4a25b9b6bf90ab68eec5d08960c3.tar.gz micropython-eb19efb27e3f4a25b9b6bf90ab68eec5d08960c3.zip |
Simplify and improve function & method calling.
Diffstat (limited to 'py/vm.c')
-rw-r--r-- | py/vm.c | 36 |
1 files changed, 8 insertions, 28 deletions
@@ -7,7 +7,7 @@ #include "misc.h" #include "machine.h" #include "runtime.h" -#include "vm.h" +#include "bc.h" #define DECODE_UINT do { unum = *ip++; if (unum > 127) { unum = ((unum & 0x3f) << 8) | (*ip++); } } while (0) #define DECODE_QSTR do { qstr = *ip++; if (qstr > 127) { qstr = ((qstr & 0x3f) << 8) | (*ip++); } } while (0) @@ -236,38 +236,18 @@ py_obj_t py_execute_byte_code(const byte *code, uint len, const py_obj_t *args, case PYBC_CALL_FUNCTION: DECODE_UINT; assert((unum & 0xff00) == 0); // n_keyword - // switch on n_positional - if ((unum & 0xff) == 0) { - *sp = rt_call_function_0(*sp); - } else if ((unum & 0xff) == 1) { - obj1 = *sp++; // the single argument - *sp = rt_call_function_1(*sp, obj1); - } else if ((unum & 0xff) == 2) { - obj2 = *sp++; // the second argument - obj1 = *sp++; // the first argument - *sp = rt_call_function_2(*sp, obj1, obj2); - } else { - assert(0); - } + unum &= 0xff; // n_positional + sp += unum; + *sp = rt_call_function_n(*sp, unum, sp - unum); break; case PYBC_CALL_METHOD: DECODE_UINT; assert((unum & 0xff00) == 0); // n_keyword - // switch on n_positional - if ((unum & 0xff) == 0) { - obj1 = *sp++; // the self object (or NULL) - *sp = rt_call_method_1(*sp, obj1); - } else if ((unum & 0xff) == 1) { - obj2 = *sp++; // the first argument - obj1 = *sp++; // the self object (or NULL) - *sp = rt_call_method_2(*sp, obj1, obj2); - } else { - unum = unum & 0xff; - obj1 = rt_call_method_n(unum, sp); - sp += unum + 1; - *sp = obj1; - } + unum &= 0xff; + obj1 = rt_call_method_n(unum, sp); + sp += unum + 1; + *sp = obj1; break; case PYBC_RETURN_VALUE: |