From eae16445d5f6ca4bcd693422fc93ccf4fd7e215e Mon Sep 17 00:00:00 2001 From: Damien George Date: Sat, 11 Jan 2014 19:22:29 +0000 Subject: py: Implement staticmethod and classmethod (internally). Still need to make built-ins by these names, and write tests. --- py/obj.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'py/obj.h') diff --git a/py/obj.h b/py/obj.h index 8d236008e..b92f1e2a7 100644 --- a/py/obj.h +++ b/py/obj.h @@ -59,6 +59,15 @@ typedef struct _mp_obj_base_t mp_obj_base_t; #define MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(obj_name, n_args_min, n_args_max, fun_name) MP_DEFINE_CONST_FUN_OBJ_VOID_PTR(obj_name, false, n_args_min, n_args_max, (mp_fun_var_t)fun_name) #define MP_DEFINE_CONST_FUN_OBJ_KW(obj_name, fun_name) MP_DEFINE_CONST_FUN_OBJ_VOID_PTR(obj_name, true, 0, (~((machine_uint_t)0)), (mp_fun_kw_t)fun_name) +// These macros are used to declare and define constant staticmethond and classmethod objects +// You can put "static" in front of the definitions to make them local + +#define MP_DECLARE_CONST_STATICMETHOD_OBJ(obj_name) extern const mp_obj_staticmethod_t obj_name +#define MP_DECLARE_CONST_CLASSMETHOD_OBJ(obj_name) extern const mp_obj_classmethod_t obj_name + +#define MP_DEFINE_CONST_STATICMETHOD_OBJ(obj_name, fun_name) const mp_obj_staticmethod_t obj_name = {{&mp_type_staticmethod}, fun_name} +#define MP_DEFINE_CONST_CLASSMETHOD_OBJ(obj_name, fun_name) const mp_obj_classmethod_t obj_name = {{&mp_type_classmethod}, fun_name} + // Need to declare this here so we are not dependent on map.h struct _mp_map_t; struct _mp_map_elem_t; @@ -316,3 +325,18 @@ extern const mp_obj_type_t gen_instance_type; extern const mp_obj_type_t module_type; mp_obj_t mp_obj_new_module(qstr module_name); struct _mp_map_t *mp_obj_module_get_globals(mp_obj_t self_in); + +// staticmethod and classmethod types; defined here so we can make const versions + +extern const mp_obj_type_t mp_type_staticmethod; +extern const mp_obj_type_t mp_type_classmethod; + +typedef struct _mp_obj_staticmethod_t { + mp_obj_base_t base; + mp_obj_t fun; +} mp_obj_staticmethod_t; + +typedef struct _mp_obj_classmethod_t { + mp_obj_base_t base; + mp_obj_t fun; +} mp_obj_classmethod_t; -- cgit v1.2.3