summaryrefslogtreecommitdiffstatshomepage
path: root/py/vm.c
diff options
context:
space:
mode:
authorDamien <damien.p.george@gmail.com>2013-10-09 23:10:10 +0100
committerDamien <damien.p.george@gmail.com>2013-10-09 23:10:10 +0100
commita397776d6bf1a9d0b07d7138b289cd661c5e1b99 (patch)
treec56f96f5abb6b3a57117702875a868d2d020949d /py/vm.c
parent91d387de7df9e19bb5b00e6ad4c94790eb3422e3 (diff)
downloadmicropython-a397776d6bf1a9d0b07d7138b289cd661c5e1b99.tar.gz
micropython-a397776d6bf1a9d0b07d7138b289cd661c5e1b99.zip
Implement basic class/object functionality in runtime.
Diffstat (limited to 'py/vm.c')
-rw-r--r--py/vm.c26
1 files changed, 18 insertions, 8 deletions
diff --git a/py/vm.c b/py/vm.c
index 63a478fcf3..ac76089a16 100644
--- a/py/vm.c
+++ b/py/vm.c
@@ -14,8 +14,9 @@
#define PUSH(val) *--sp = (val)
#define POP() (*sp++)
-py_obj_t py_execute_byte_code(byte *code, uint len, py_obj_t *args, uint n_args) {
- byte *ip = code;
+// args are in reverse order in array
+py_obj_t py_execute_byte_code(const byte *code, uint len, const py_obj_t *args, uint n_args) {
+ const byte *ip = code;
py_obj_t stack[10];
py_obj_t *sp = &stack[10]; // stack grows down, sp points to top of stack
machine_uint_t unum;
@@ -27,14 +28,14 @@ py_obj_t py_execute_byte_code(byte *code, uint len, py_obj_t *args, uint n_args)
// init args
for (int i = 0; i < n_args; i++) {
if (i == 0) {
- fast0 = args[0];
+ fast0 = args[n_args - 1];
} else if (i == 1) {
- fast1 = args[1];
+ fast1 = args[n_args - 2];
} else if (i == 2) {
- fast2 = args[2];
+ fast2 = args[n_args - 3];
} else {
assert(i - 3 < 4);
- fastn[i - 3] = args[i];
+ fastn[i - 3] = args[n_args - 1 - i];
}
}
@@ -137,6 +138,12 @@ py_obj_t py_execute_byte_code(byte *code, uint len, py_obj_t *args, uint n_args)
rt_store_name(qstr, POP());
break;
+ case PYBC_STORE_ATTR:
+ DECODE_QSTR;
+ rt_store_attr(sp[0], qstr, sp[1]);
+ sp += 2;
+ break;
+
case PYBC_STORE_SUBSCR:
rt_store_subscr(sp[1], sp[0], sp[2]);
sp += 3;
@@ -254,9 +261,12 @@ py_obj_t py_execute_byte_code(byte *code, uint len, py_obj_t *args, uint n_args)
} else if ((unum & 0xff) == 1) {
obj2 = *sp++; // the first argument
obj1 = *sp++; // the self object (or NULL)
- *sp = rt_call_function_2(*sp, obj1, obj2);
+ *sp = rt_call_method_2(*sp, obj1, obj2);
} else {
- assert(0);
+ unum = unum & 0xff;
+ obj1 = rt_call_method_n(unum, sp);
+ sp += unum + 1;
+ *sp = obj1;
}
break;