diff options
| author | Damien George | 2014-01-11 19:22:29 +0000 |
|---|---|---|
| committer | Damien George | 2014-01-11 19:22:29 +0000 |
| commit | eae16445d5f6ca4bcd693422fc93ccf4fd7e215e (patch) | |
| tree | c07206dcad354d366c1a42d6fa81d6a1868de2e1 /py/obj.h | |
| parent | bcbeea0a477ed977a668e67f6f5402260d26ceb9 (diff) | |
py: Implement staticmethod and classmethod (internally).
Still need to make built-ins by these names, and write tests.
Diffstat (limited to 'py/obj.h')
| -rw-r--r-- | py/obj.h | 24 |
1 files changed, 24 insertions, 0 deletions
@@ -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; |
