From c12aa468a1ffcbefdb3a260917452fbdb0f85bf2 Mon Sep 17 00:00:00 2001 From: Damien Date: Wed, 16 Oct 2013 20:57:49 +0100 Subject: [PATCH] Add SET_ADD opcode to VM. --- py/runtime.c | 5 +++++ py/runtime.h | 3 ++- py/vm.c | 7 +++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/py/runtime.c b/py/runtime.c index 0b76df8a5b..33a4c95e18 100644 --- a/py/runtime.c +++ b/py/runtime.c @@ -1305,6 +1305,11 @@ py_obj_t rt_build_set(int n_args, py_obj_t *items) { return o; } +py_obj_t rt_store_set(py_obj_t set, py_obj_t item) { + py_set_lookup(set, item, true); + return set; +} + py_obj_t rt_build_map(int n_args) { py_obj_base_t *o = m_new(py_obj_base_t, 1); o->kind = O_MAP; diff --git a/py/runtime.h b/py/runtime.h index 7a806eb55a..e7ac934bf5 100644 --- a/py/runtime.h +++ b/py/runtime.h @@ -119,9 +119,10 @@ py_obj_t rt_call_method_n(int n_args, const py_obj_t *args); py_obj_t rt_build_tuple(int n_args, py_obj_t *items); py_obj_t rt_build_list(int n_args, py_obj_t *items); py_obj_t rt_list_append(py_obj_t list, py_obj_t arg); +py_obj_t rt_build_set(int n_args, py_obj_t *items); +py_obj_t rt_store_set(py_obj_t set, py_obj_t item); py_obj_t rt_build_map(int n_args); py_obj_t rt_store_map(py_obj_t map, py_obj_t key, py_obj_t value); -py_obj_t rt_build_set(int n_args, py_obj_t *items); py_obj_t rt_load_attr(py_obj_t base, qstr attr); void rt_load_method(py_obj_t base, qstr attr, py_obj_t *dest); void rt_store_attr(py_obj_t base, qstr attr, py_obj_t val); diff --git a/py/vm.c b/py/vm.c index 2f5977d825..33970a0f6a 100644 --- a/py/vm.c +++ b/py/vm.c @@ -319,6 +319,13 @@ bool py_execute_byte_code_2(const byte *code, const byte **ip_in_out, py_obj_t * *sp = obj1; break; + case PYBC_SET_ADD: + DECODE_UINT; + // I think it's guaranteed by the compiler that sp[unum] is a set + rt_store_set(sp[unum], sp[0]); + sp++; + break; + case PYBC_MAKE_FUNCTION: DECODE_UINT; PUSH(rt_make_function_from_id(unum));