+added function overriding support for referenced usertype.

This commit is contained in:
Wang Renxin 2016-07-07 13:10:03 +08:00 committed by GitHub
parent 9b725b32fc
commit 8d28db64b7

View File

@ -375,6 +375,8 @@ typedef struct _usertype_ref_t {
mb_cmp_func_t cmp;
mb_fmt_func_t fmt;
_calculation_operator_info_t* calc_operators;
mb_meta_func_t coll_func;
mb_meta_func_t generic_func;
} _usertype_ref_t;
typedef struct _func_t {
@ -1595,6 +1597,7 @@ static _usertype_ref_t* _create_usertype_ref(mb_interpreter_t* s, void* val, mb_
static void _destroy_usertype_ref(_usertype_ref_t* c);
static void _unref_usertype_ref(_ref_t* ref, void* data);
#endif /* MB_ENABLE_USERTYPE_REF */
static mb_meta_status_u _try_overridden_usertype_ref(mb_interpreter_t* s, void** l, mb_value_t* d, const char* f, mb_meta_func_u t);
static _array_t* _create_array(mb_interpreter_t* s, const char* n, _data_e t);
#ifdef MB_ENABLE_ARRAY_REF
@ -1956,6 +1959,8 @@ static int _coll_move_next(mb_interpreter_t* s, void** l);
/** Lib information */
#define _CORE_ID_TYPE "TYPE"
static const _func_t _core_libs[] = {
{ _DUMMY_ASSIGN_CHAR, _core_dummy_assign },
{ "+", _core_add },
@ -2028,11 +2033,16 @@ static const _func_t _core_libs[] = {
{ "MEM", _core_mem },
#endif /* MB_ENABLE_ALLOC_STAT */
{ "TYPE", _core_type },
{ _CORE_ID_TYPE, _core_type },
{ "IMPORT", _core_import },
{ "END", _core_end }
};
#define _STD_ID_VAL "VAL"
#define _STD_ID_LEN "LEN"
#define _STD_ID_GET "GET"
#define _STD_ID_SET "SET"
static const _func_t _std_libs[] = {
{ "ABS", _std_abs },
{ "SGN", _std_sgn },
@ -2058,33 +2068,49 @@ static const _func_t _std_libs[] = {
{ "MID", _std_mid },
{ "RIGHT", _std_right },
{ "STR", _std_str },
{ "VAL", _std_val },
{ _STD_ID_VAL, _std_val },
{ "LEN", _std_len },
{ "GET", _std_get },
{ "SET", _std_set },
{ _STD_ID_LEN, _std_len },
{ _STD_ID_GET, _std_get },
{ _STD_ID_SET, _std_set },
{ "PRINT", _std_print },
{ "INPUT", _std_input }
};
#ifdef MB_ENABLE_COLLECTION_LIB
# define _COLL_ID_LIST "LIST"
# define _COLL_ID_DICT "DICT"
# define _COLL_ID_PUSH "PUSH"
# define _COLL_ID_POP "POP"
# define _COLL_ID_PEEK "PEEK"
# define _COLL_ID_INSERT "INSERT"
# define _COLL_ID_SORT "SORT"
# define _COLL_ID_EXIST "EXIST"
# define _COLL_ID_INDEX_OF "INDEX_OF"
# define _COLL_ID_REMOVE "REMOVE"
# define _COLL_ID_CLEAR "CLEAR"
# define _COLL_ID_CLONE "CLONE"
# define _COLL_ID_TO_ARRAY "TO_ARRAY"
# define _COLL_ID_ITERATOR "ITERATOR"
# define _COLL_ID_MOVE_NEXT "MOVE_NEXT"
static const _func_t _coll_libs[] = {
{ "LIST", _coll_list },
{ "DICT", _coll_dict },
{ "PUSH", _coll_push },
{ "POP", _coll_pop },
{ "PEEK", _coll_peek },
{ "INSERT", _coll_insert },
{ "SORT", _coll_sort },
{ "EXIST", _coll_exist },
{ "INDEX_OF", _coll_index_of },
{ "REMOVE", _coll_remove },
{ "CLEAR", _coll_clear },
{ "CLONE", _coll_clone },
{ "TO_ARRAY", _coll_to_array },
{ "ITERATOR", _coll_iterator },
{ "MOVE_NEXT", _coll_move_next }
{ _COLL_ID_LIST, _coll_list },
{ _COLL_ID_DICT, _coll_dict },
{ _COLL_ID_PUSH, _coll_push },
{ _COLL_ID_POP, _coll_pop },
{ _COLL_ID_PEEK, _coll_peek },
{ _COLL_ID_INSERT, _coll_insert },
{ _COLL_ID_SORT, _coll_sort },
{ _COLL_ID_EXIST, _coll_exist },
{ _COLL_ID_INDEX_OF, _coll_index_of },
{ _COLL_ID_REMOVE, _coll_remove },
{ _COLL_ID_CLEAR, _coll_clear },
{ _COLL_ID_CLONE, _coll_clone },
{ _COLL_ID_TO_ARRAY, _coll_to_array },
{ _COLL_ID_ITERATOR, _coll_iterator },
{ _COLL_ID_MOVE_NEXT, _coll_move_next }
};
#endif /* MB_ENABLE_COLLECTION_LIB */
@ -6243,6 +6269,26 @@ static void _unref_usertype_ref(_ref_t* ref, void* data) {
}
#endif /* MB_ENABLE_USERTYPE_REF */
/* Try to call overridden referenced usertype function */
static mb_meta_status_u _try_overridden_usertype_ref(mb_interpreter_t* s, void** l, mb_value_t* d, const char* f, mb_meta_func_u t) {
mb_assert(s && l && d && f);
#ifdef MB_ENABLE_USERTYPE_REF
if(d->type == MB_DT_USERTYPE_REF) {
_object_t obj;
_MAKE_NIL(&obj);
_public_value_to_internal_object(d, &obj);
if(t == MB_MF_COLL && obj.data.usertype_ref->coll_func) {
return obj.data.usertype_ref->coll_func(s, l, f);
} else if(t == MB_MF_FUNC && obj.data.usertype_ref->generic_func) {
return obj.data.usertype_ref->generic_func(s, l, f);
}
}
#endif /* MB_ENABLE_USERTYPE_REF */
return MB_MS_NONE;
}
/* Create an array */
static _array_t* _create_array(mb_interpreter_t* s, const char* n, _data_e t) {
_array_t* result = 0;
@ -8635,6 +8681,8 @@ static int _clone_object(mb_interpreter_t* s, _object_t* obj, _object_t* tgt, bo
if(obj->data.usertype_ref->calc_operators)
tgt->data.usertype_ref->calc_operators = (_calculation_operator_info_t*)mb_malloc(sizeof(_calculation_operator_info_t));
memcpy(tgt->data.usertype_ref->calc_operators, obj->data.usertype_ref->calc_operators, sizeof(_calculation_operator_info_t));
tgt->data.usertype_ref->coll_func = obj->data.usertype_ref->coll_func;
tgt->data.usertype_ref->generic_func = obj->data.usertype_ref->generic_func;
_ref(&tgt->data.usertype_ref->ref, tgt->data.usertype_ref);
break;
@ -11937,7 +11985,7 @@ _exit:
}
/* Override a meta function of a value */
int mb_override_value(struct mb_interpreter_t* s, void** l, mb_value_t val, mb_meta_func_u m, mb_meta_operator_t f) {
int mb_override_value(struct mb_interpreter_t* s, void** l, mb_value_t val, mb_meta_func_u m, void* f) {
int result = MB_FUNC_OK;
_object_t obj;
@ -11949,7 +11997,7 @@ int mb_override_value(struct mb_interpreter_t* s, void** l, mb_value_t val, mb_m
_usertype_ref_t* user = 0;
_public_value_to_internal_object(&val, &obj);
user = obj.data.usertype_ref;
if(m & (MB_MF_IS | MB_MF_ADD | MB_MF_SUB | MB_MF_MUL | MB_MF_DIV | MB_MF_NEG)) {
if(m & MB_MF_CALC) {
if(!user->calc_operators) {
user->calc_operators = (_calculation_operator_info_t*)mb_malloc(sizeof(_calculation_operator_info_t));
memset(user->calc_operators, 0, sizeof(_calculation_operator_info_t));
@ -11957,27 +12005,35 @@ int mb_override_value(struct mb_interpreter_t* s, void** l, mb_value_t val, mb_m
}
switch(m) {
case MB_MF_IS:
user->calc_operators->is = f;
user->calc_operators->is = (mb_meta_operator_t)(intptr_t)f;
break;
case MB_MF_ADD:
user->calc_operators->add = f;
user->calc_operators->add = (mb_meta_operator_t)(intptr_t)f;
break;
case MB_MF_SUB:
user->calc_operators->sub = f;
user->calc_operators->sub = (mb_meta_operator_t)(intptr_t)f;
break;
case MB_MF_MUL:
user->calc_operators->mul = f;
user->calc_operators->mul = (mb_meta_operator_t)(intptr_t)f;
break;
case MB_MF_DIV:
user->calc_operators->div = f;
user->calc_operators->div = (mb_meta_operator_t)(intptr_t)f;
break;
case MB_MF_NEG:
user->calc_operators->neg = f;
user->calc_operators->neg = (mb_meta_operator_t)(intptr_t)f;
break;
case MB_MF_COLL:
user->coll_func = (mb_meta_func_t)(intptr_t)f;
break;
case MB_MF_FUNC:
user->generic_func = (mb_meta_func_t)(intptr_t)f;
break;
}
@ -14580,6 +14636,7 @@ static int _core_type(mb_interpreter_t* s, void** l) {
int result = MB_FUNC_OK;
mb_value_t arg;
int i = 0;
mb_meta_status_u os = MB_MS_NONE;
mb_assert(s && l);
@ -14588,9 +14645,6 @@ static int _core_type(mb_interpreter_t* s, void** l) {
mb_check(mb_attempt_open_bracket(s, l));
mb_check(mb_pop_value(s, l, &arg));
mb_check(mb_attempt_close_bracket(s, l));
if(arg.type == MB_DT_STRING) {
mb_data_e types[] = {
MB_DT_NIL,
@ -14628,11 +14682,18 @@ static int _core_type(mb_interpreter_t* s, void** l) {
}
}
}
os = _try_overridden_usertype_ref(s, l, &arg, _CORE_ID_TYPE, MB_MF_FUNC);
if((os & MB_MS_DONE) == MB_MS_NONE) {
arg.value.type = arg.type;
arg.type = MB_DT_TYPE;
}
mb_check(mb_attempt_close_bracket(s, l));
_found:
if((os & MB_MS_RETURNED) == MB_MS_NONE) {
mb_check(mb_push_value(s, l, arg));
}
return result;
}
@ -15395,6 +15456,7 @@ static int _std_val(mb_interpreter_t* s, void** l) {
_object_t ocoi;
#endif /* MB_ENABLE_COLLECTION_LIB */
mb_value_t ret;
mb_meta_status_u os = MB_MS_NONE;
mb_assert(s && l);
@ -15404,9 +15466,8 @@ static int _std_val(mb_interpreter_t* s, void** l) {
mb_check(mb_attempt_open_bracket(s, l));
mb_check(mb_pop_value(s, l, &arg));
mb_check(mb_attempt_close_bracket(s, l));
os = _try_overridden_usertype_ref(s, l, &arg, _STD_ID_VAL, MB_MF_FUNC);
if((os & MB_MS_DONE) == MB_MS_NONE) {
switch(arg.type) {
case MB_DT_STRING:
ret.value.integer = (int_t)mb_strtol(arg.value.string, &conv_suc, 0);
@ -15444,6 +15505,13 @@ static int _std_val(mb_interpreter_t* s, void** l) {
break;
}
} else {
if((os & MB_MS_RETURNED) == MB_MS_NONE) {
mb_check(mb_push_value(s, l, ret));
}
}
mb_check(mb_attempt_close_bracket(s, l));
_exit:
return result;
@ -15460,6 +15528,7 @@ static int _std_len(mb_interpreter_t* s, void** l) {
_list_t* lst = 0;
_dict_t* dct = 0;
#endif /* MB_ENABLE_COLLECTION_LIB */
mb_meta_status_u os = MB_MS_NONE;
mb_assert(s && l);
@ -15479,9 +15548,8 @@ static int _std_len(mb_interpreter_t* s, void** l) {
goto _exit;
}
mb_check(mb_pop_value(s, l, &arg));
mb_check(mb_attempt_close_bracket(s, l));
os = _try_overridden_usertype_ref(s, l, &arg, _STD_ID_LEN, MB_MF_FUNC);
if((os & MB_MS_DONE) == MB_MS_NONE) {
switch(arg.type) {
case MB_DT_STRING:
#ifdef MB_ENABLE_UNICODE
@ -15515,6 +15583,13 @@ static int _std_len(mb_interpreter_t* s, void** l) {
break;
}
} else {
if((os & MB_MS_RETURNED) == MB_MS_NONE) {
mb_check(mb_push_int(s, l, 0));
}
}
mb_check(mb_attempt_close_bracket(s, l));
_exit:
return result;
@ -15535,6 +15610,7 @@ static int _std_get(mb_interpreter_t* s, void** l) {
_object_t* fobj = 0;
#endif /* MB_ENABLE_CLASS */
mb_value_t ret;
mb_meta_status_u os = MB_MS_NONE;
mb_assert(s && l);
@ -15545,6 +15621,8 @@ static int _std_get(mb_interpreter_t* s, void** l) {
mb_check(mb_attempt_open_bracket(s, l));
mb_check(mb_pop_value(s, l, &coi));
os = _try_overridden_usertype_ref(s, l, &coi, _STD_ID_GET, MB_MF_FUNC);
if((os & MB_MS_DONE) == MB_MS_NONE) {
_MAKE_NIL(&ocoi);
switch(coi.type) {
#ifdef MB_ENABLE_COLLECTION_LIB
@ -15603,10 +15681,13 @@ static int _std_get(mb_interpreter_t* s, void** l) {
break;
}
}
mb_check(mb_attempt_close_bracket(s, l));
if((os & MB_MS_RETURNED) == MB_MS_NONE) {
mb_check(mb_push_value(s, l, ret));
}
_exit:
_assign_public_value(&coi, 0);
@ -15625,6 +15706,7 @@ static int _std_set(mb_interpreter_t* s, void** l) {
_object_t* oval = 0;
int_t idx = 0;
#endif /* MB_ENABLE_COLLECTION_LIB */
mb_meta_status_u os = MB_MS_NONE;
mb_assert(s && l);
@ -15635,6 +15717,8 @@ static int _std_set(mb_interpreter_t* s, void** l) {
mb_check(mb_attempt_open_bracket(s, l));
mb_check(mb_pop_value(s, l, &coll));
os = _try_overridden_usertype_ref(s, l, &coll, _STD_ID_SET, MB_MF_FUNC);
if((os & MB_MS_DONE) == MB_MS_NONE) {
_MAKE_NIL(&ocoll);
switch(coll.type) {
#ifdef MB_ENABLE_COLLECTION_LIB
@ -15669,10 +15753,13 @@ static int _std_set(mb_interpreter_t* s, void** l) {
break;
}
}
mb_check(mb_attempt_close_bracket(s, l));
if((os & MB_MS_RETURNED) == MB_MS_NONE) {
mb_check(mb_push_value(s, l, coll));
}
_exit:
_assign_public_value(&coll, 0);
@ -16039,36 +16126,42 @@ _error:
/* PUSH statement */
static int _coll_push(mb_interpreter_t* s, void** l) {
int result = MB_FUNC_OK;
mb_value_t lst;
mb_value_t coll;
mb_value_t arg;
_object_t olst;
mb_meta_status_u os = MB_MS_NONE;
mb_assert(s && l);
mb_make_nil(lst);
mb_make_nil(coll);
mb_make_nil(arg);
mb_check(mb_attempt_open_bracket(s, l));
mb_check(mb_pop_value(s, l, &lst));
if(lst.type != MB_DT_LIST) {
mb_check(mb_pop_value(s, l, &coll));
os = _try_overridden_usertype_ref(s, l, &coll, _COLL_ID_PUSH, MB_MF_COLL);
if((os & MB_MS_DONE) == MB_MS_NONE) {
if(coll.type != MB_DT_LIST) {
_handle_error_on_obj(s, SE_RN_LIST_EXPECTED, s->source_file, DON2(l), MB_FUNC_ERR, _exit, result);
}
_MAKE_NIL(&olst);
_public_value_to_internal_object(&lst, &olst);
_public_value_to_internal_object(&coll, &olst);
while(mb_has_arg(s, l)) {
mb_make_nil(arg);
mb_check(mb_pop_value(s, l, &arg));
_push_list(olst.data.list, &arg, 0);
}
}
mb_check(mb_attempt_close_bracket(s, l));
mb_check(mb_push_value(s, l, lst));
if((os & MB_MS_RETURNED) == MB_MS_NONE) {
mb_check(mb_push_value(s, l, coll));
}
_exit:
_assign_public_value(&lst, 0);
_assign_public_value(&coll, 0);
return result;
}
@ -16076,42 +16169,49 @@ _exit:
/* POP statement */
static int _coll_pop(mb_interpreter_t* s, void** l) {
int result = MB_FUNC_OK;
mb_value_t lst;
mb_value_t coll;
mb_value_t val;
_object_t olst;
_object_t ocoll;
mb_meta_status_u os = MB_MS_NONE;
mb_assert(s && l);
mb_make_nil(lst);
mb_make_nil(coll);
mb_make_nil(val);
mb_check(mb_attempt_open_bracket(s, l));
mb_check(mb_pop_value(s, l, &lst));
mb_check(mb_attempt_close_bracket(s, l));
if(lst.type != MB_DT_LIST) {
mb_check(mb_pop_value(s, l, &coll));
os = _try_overridden_usertype_ref(s, l, &coll, _COLL_ID_POP, MB_MF_COLL);
if((os & MB_MS_DONE) == MB_MS_NONE) {
if(coll.type != MB_DT_LIST) {
_handle_error_on_obj(s, SE_RN_LIST_EXPECTED, s->source_file, DON2(l), MB_FUNC_ERR, _exit, result);
}
_MAKE_NIL(&olst);
_public_value_to_internal_object(&lst, &olst);
_public_value_to_internal_object(&coll, &olst);
if(_pop_list(olst.data.list, &val, s)) {
mb_check(mb_push_value(s, l, val));
_MAKE_NIL(&ocoll);
_public_value_to_internal_object(&val, &ocoll);
_UNREF(&ocoll)
_assign_public_value(&lst, 0);
_assign_public_value(&coll, 0);
} else {
mb_check(mb_push_value(s, l, val));
_assign_public_value(&lst, 0);
_assign_public_value(&coll, 0);
_handle_error_on_obj(s, SE_RN_EMPTY_COLLECTION, s->source_file, DON2(l), MB_FUNC_WARNING, _exit, result);
}
} else {
if((os & MB_MS_RETURNED) == MB_MS_NONE) {
mb_check(mb_push_value(s, l, val));
}
}
mb_check(mb_attempt_close_bracket(s, l));
_exit:
return result;
@ -16120,29 +16220,29 @@ _exit:
/* PEEK statement */
static int _coll_peek(mb_interpreter_t* s, void** l) {
int result = MB_FUNC_OK;
mb_value_t lst;
mb_value_t coll;
mb_value_t val;
_object_t olst;
_object_t* oval = 0;
_ls_node_t* node = 0;
mb_meta_status_u os = MB_MS_NONE;
mb_assert(s && l);
mb_make_nil(lst);
mb_make_nil(coll);
mb_make_nil(val);
mb_check(mb_attempt_open_bracket(s, l));
mb_check(mb_pop_value(s, l, &lst));
mb_check(mb_attempt_close_bracket(s, l));
if(lst.type != MB_DT_LIST) {
mb_check(mb_pop_value(s, l, &coll));
os = _try_overridden_usertype_ref(s, l, &coll, _COLL_ID_PEEK, MB_MF_COLL);
if((os & MB_MS_DONE) == MB_MS_NONE) {
if(coll.type != MB_DT_LIST) {
_handle_error_on_obj(s, SE_RN_LIST_EXPECTED, s->source_file, DON2(l), MB_FUNC_ERR, _exit, result);
}
_MAKE_NIL(&olst);
_public_value_to_internal_object(&lst, &olst);
_public_value_to_internal_object(&coll, &olst);
node = _ls_back(olst.data.list->list);
oval = node ? (_object_t*)node->data : 0;
if(oval) {
@ -16150,14 +16250,21 @@ static int _coll_peek(mb_interpreter_t* s, void** l) {
mb_check(mb_push_value(s, l, val));
_assign_public_value(&lst, 0);
_assign_public_value(&coll, 0);
} else {
mb_check(mb_push_value(s, l, val));
_assign_public_value(&lst, 0);
_assign_public_value(&coll, 0);
_handle_error_on_obj(s, SE_RN_EMPTY_COLLECTION, s->source_file, DON2(l), MB_FUNC_WARNING, _exit, result);
}
} else {
if((os & MB_MS_RETURNED) == MB_MS_NONE) {
mb_check(mb_push_value(s, l, val));
}
}
mb_check(mb_attempt_close_bracket(s, l));
_exit:
return result;
@ -16166,30 +16273,31 @@ _exit:
/* INSERT statement */
static int _coll_insert(mb_interpreter_t* s, void** l) {
int result = MB_FUNC_OK;
mb_value_t lst;
mb_value_t coll;
int_t idx = 0;
mb_value_t arg;
_object_t olst;
_object_t* oval = 0;
mb_meta_status_u os = MB_MS_NONE;
mb_assert(s && l);
mb_make_nil(lst);
mb_make_nil(coll);
mb_make_nil(arg);
mb_check(mb_attempt_open_bracket(s, l));
mb_check(mb_pop_value(s, l, &lst));
mb_check(mb_pop_value(s, l, &coll));
os = _try_overridden_usertype_ref(s, l, &coll, _COLL_ID_INSERT, MB_MF_COLL);
if((os & MB_MS_DONE) == MB_MS_NONE) {
mb_check(mb_pop_int(s, l, &idx));
mb_check(mb_pop_value(s, l, &arg));
mb_check(mb_attempt_close_bracket(s, l));
if(lst.type != MB_DT_LIST) {
if(coll.type != MB_DT_LIST) {
_handle_error_on_obj(s, SE_RN_LIST_EXPECTED, s->source_file, DON2(l), MB_FUNC_ERR, _exit, result);
}
_MAKE_NIL(&olst);
_public_value_to_internal_object(&lst, &olst);
_public_value_to_internal_object(&coll, &olst);
if(!_insert_list(olst.data.list, idx, &arg, &oval)) {
_destroy_object(oval, 0);
@ -16197,10 +16305,17 @@ static int _coll_insert(mb_interpreter_t* s, void** l) {
_handle_error_on_obj(s, SE_RN_INDEX_OUT_OF_BOUND, s->source_file, DON2(l), MB_FUNC_ERR, _exit, result);
}
mb_check(mb_push_value(s, l, lst));
mb_check(mb_push_value(s, l, coll));
} else {
if((os & MB_MS_RETURNED) == MB_MS_NONE) {
mb_check(mb_push_value(s, l, coll));
}
}
mb_check(mb_attempt_close_bracket(s, l));
_exit:
_assign_public_value(&lst, 0);
_assign_public_value(&coll, 0);
return result;
}
@ -16208,31 +16323,36 @@ _exit:
/* SORT statement */
static int _coll_sort(mb_interpreter_t* s, void** l) {
int result = MB_FUNC_OK;
mb_value_t lst;
mb_value_t coll;
_object_t olst;
mb_meta_status_u os = MB_MS_NONE;
mb_assert(s && l);
mb_make_nil(lst);
mb_make_nil(coll);
mb_check(mb_attempt_open_bracket(s, l));
mb_check(mb_pop_value(s, l, &lst));
mb_check(mb_attempt_close_bracket(s, l));
if(lst.type != MB_DT_LIST) {
mb_check(mb_pop_value(s, l, &coll));
os = _try_overridden_usertype_ref(s, l, &coll, _COLL_ID_SORT, MB_MF_COLL);
if((os & MB_MS_DONE) == MB_MS_NONE) {
if(coll.type != MB_DT_LIST) {
_handle_error_on_obj(s, SE_RN_LIST_EXPECTED, s->source_file, DON2(l), MB_FUNC_ERR, _exit, result);
}
_MAKE_NIL(&olst);
_public_value_to_internal_object(&lst, &olst);
_public_value_to_internal_object(&coll, &olst);
_sort_list(olst.data.list);
}
mb_check(mb_push_value(s, l, lst));
mb_check(mb_attempt_close_bracket(s, l));
if((os & MB_MS_RETURNED) == MB_MS_NONE) {
mb_check(mb_push_value(s, l, coll));
}
_exit:
_assign_public_value(&lst, 0);
_assign_public_value(&coll, 0);
return result;
}
@ -16244,6 +16364,7 @@ static int _coll_exist(mb_interpreter_t* s, void** l){
mb_value_t arg;
_object_t ocoll;
mb_value_t ret;
mb_meta_status_u os = MB_MS_NONE;
mb_assert(s && l);
@ -16254,10 +16375,10 @@ static int _coll_exist(mb_interpreter_t* s, void** l){
mb_check(mb_attempt_open_bracket(s, l));
mb_check(mb_pop_value(s, l, &coll));
os = _try_overridden_usertype_ref(s, l, &coll, _COLL_ID_EXIST, MB_MF_COLL);
if((os & MB_MS_DONE) == MB_MS_NONE) {
mb_check(mb_pop_value(s, l, &arg));
mb_check(mb_attempt_close_bracket(s, l));
ret.type = MB_DT_INT;
_MAKE_NIL(&ocoll);
switch(coll.type) {
@ -16277,6 +16398,13 @@ static int _coll_exist(mb_interpreter_t* s, void** l){
break;
}
mb_check(mb_push_value(s, l, ret));
} else {
if((os & MB_MS_RETURNED) == MB_MS_NONE) {
mb_check(mb_push_value(s, l, coll));
}
}
mb_check(mb_attempt_close_bracket(s, l));
_exit:
_assign_public_value(&coll, 0);
@ -16292,6 +16420,7 @@ static int _coll_index_of(mb_interpreter_t* s, void** l) {
_object_t ocoll;
mb_value_t val;
mb_value_t ret;
mb_meta_status_u os = MB_MS_NONE;
mb_assert(s && l);
@ -16301,9 +16430,10 @@ static int _coll_index_of(mb_interpreter_t* s, void** l) {
mb_check(mb_attempt_open_bracket(s, l));
mb_make_nil(ret);
ret.type = MB_DT_UNKNOWN;
mb_check(mb_pop_value(s, l, &coll));
os = _try_overridden_usertype_ref(s, l, &coll, _COLL_ID_INDEX_OF, MB_MF_COLL);
if((os & MB_MS_DONE) == MB_MS_NONE) {
ret.type = MB_DT_UNKNOWN;
mb_check(mb_pop_value(s, l, &val));
_MAKE_NIL(&ocoll);
switch(coll.type) {
@ -16319,10 +16449,13 @@ static int _coll_index_of(mb_interpreter_t* s, void** l) {
break;
}
}
mb_check(mb_attempt_close_bracket(s, l));
if((os & MB_MS_RETURNED) == MB_MS_NONE) {
mb_check(mb_push_value(s, l, ret));
}
_exit:
_assign_public_value(&coll, 0);
@ -16337,6 +16470,7 @@ static int _coll_remove(mb_interpreter_t* s, void** l) {
int_t idx = 0;
mb_value_t key;
_object_t ocoll;
mb_meta_status_u os = MB_MS_NONE;
mb_assert(s && l);
@ -16346,6 +16480,8 @@ static int _coll_remove(mb_interpreter_t* s, void** l) {
mb_check(mb_attempt_open_bracket(s, l));
mb_check(mb_pop_value(s, l, &coll));
os = _try_overridden_usertype_ref(s, l, &coll, _COLL_ID_REMOVE, MB_MF_COLL);
if((os & MB_MS_DONE) == MB_MS_NONE) {
_MAKE_NIL(&ocoll);
switch(coll.type) {
case MB_DT_LIST:
@ -16375,10 +16511,13 @@ static int _coll_remove(mb_interpreter_t* s, void** l) {
break;
}
}
mb_check(mb_attempt_close_bracket(s, l));
if((os & MB_MS_RETURNED) == MB_MS_NONE) {
mb_check(mb_push_value(s, l, coll));
}
_exit:
_assign_public_value(&coll, 0);
@ -16391,6 +16530,7 @@ static int _coll_clear(mb_interpreter_t* s, void** l) {
int result = MB_FUNC_OK;
mb_value_t coll;
_object_t ocoll;
mb_meta_status_u os = MB_MS_NONE;
mb_assert(s && l);
@ -16399,9 +16539,8 @@ static int _coll_clear(mb_interpreter_t* s, void** l) {
mb_check(mb_attempt_open_bracket(s, l));
mb_check(mb_pop_value(s, l, &coll));
mb_check(mb_attempt_close_bracket(s, l));
os = _try_overridden_usertype_ref(s, l, &coll, _COLL_ID_CLEAR, MB_MF_COLL);
if((os & MB_MS_DONE) == MB_MS_NONE) {
_MAKE_NIL(&ocoll);
switch(coll.type) {
case MB_DT_LIST:
@ -16419,8 +16558,13 @@ static int _coll_clear(mb_interpreter_t* s, void** l) {
break;
}
}
mb_check(mb_attempt_close_bracket(s, l));
if((os & MB_MS_RETURNED) == MB_MS_NONE) {
mb_check(mb_push_value(s, l, coll));
}
_exit:
_assign_public_value(&coll, 0);