diff --git a/HISTORY b/HISTORY index a05bb79..4453454 100755 --- a/HISTORY +++ b/HISTORY @@ -1,3 +1,6 @@ +Jan. 21 2016 +Improved type handling + Jan. 20 2016 Fixed an unknown type handling bug diff --git a/core/my_basic.c b/core/my_basic.c index 25be55d..09d28da 100755 --- a/core/my_basic.c +++ b/core/my_basic.c @@ -10727,6 +10727,8 @@ const char* mb_get_type_string(mb_data_e t) { return "DICT"; case MB_DT_DICT_IT: return "DICT_ITERATOR"; + case MB_DT_COLLECTION: + return "COLLECTION"; #endif /* MB_ENABLE_COLLECTION_LIB */ #ifdef MB_ENABLE_CLASS case MB_DT_CLASS: @@ -11337,10 +11339,12 @@ int _core_is(mb_interpreter_t* s, void** l) { } if(scd->type == _DT_TYPE) { val->type = _DT_INT; - if((fst->type == _DT_INT || fst->type == _DT_REAL) && scd->data.type == MB_DT_NUM) - val->data.integer = 1; - else - val->data.integer = (int_t)(_internal_type_to_public_type(fst->type) == scd->data.type); + val->data.integer = (int_t)( + !!( + _internal_type_to_public_type(fst->type) == scd->data.type || + _internal_type_to_public_type(fst->type) & scd->data.type + ) + ); } else { #ifdef MB_ENABLE_CLASS if(!_IS_CLASS(fst) || !_IS_CLASS(scd)) { @@ -12785,7 +12789,6 @@ int _core_type(mb_interpreter_t* s, void** l) { int result = MB_FUNC_OK; mb_value_t arg; int i = 0; - unsigned e = 0; mb_assert(s && l); @@ -12798,8 +12801,33 @@ int _core_type(mb_interpreter_t* s, void** l) { mb_check(mb_attempt_close_bracket(s, l)); if(arg.type == MB_DT_STRING) { - for(i = 0; i < sizeof(mb_data_e) * 8; i++) { - e = 1 << i; + mb_data_e types[] = { + MB_DT_NIL, + MB_DT_UNKNOWN, + MB_DT_TYPE, + MB_DT_INT, + MB_DT_REAL, + MB_DT_NUM, + MB_DT_STRING, + MB_DT_USERTYPE, +#ifdef MB_ENABLE_USERTYPE_REF + MB_DT_USERTYPE_REF, +#endif /* MB_ENABLE_USERTYPE_REF */ + MB_DT_ARRAY, +#ifdef MB_ENABLE_COLLECTION_LIB + MB_DT_LIST, + MB_DT_LIST_IT, + MB_DT_DICT, + MB_DT_DICT_IT, + MB_DT_COLLECTION, +#endif /* MB_ENABLE_COLLECTION_LIB */ +#ifdef MB_ENABLE_CLASS + MB_DT_CLASS, +#endif /* MB_ENABLE_CLASS */ + MB_DT_ROUTINE + }; + for(i = 0; i < _countof(types); i++) { + unsigned e = types[i]; if(!mb_stricmp(mb_get_type_string((mb_data_e)e), arg.value.string)) { arg.value.type = (mb_data_e)e; arg.type = MB_DT_TYPE; diff --git a/core/my_basic.h b/core/my_basic.h index a946237..0b9a4f3 100755 --- a/core/my_basic.h +++ b/core/my_basic.h @@ -362,23 +362,24 @@ typedef enum mb_data_e { MB_DT_TYPE = 1 << 1, MB_DT_INT = 1 << 2, MB_DT_REAL = 1 << 3, - MB_DT_NUM = 1 << 4, - MB_DT_STRING = 1 << 5, - MB_DT_USERTYPE = 1 << 6, + MB_DT_NUM = MB_DT_INT | MB_DT_REAL, + MB_DT_STRING = 1 << 4, + MB_DT_USERTYPE = 1 << 5, #ifdef MB_ENABLE_USERTYPE_REF - MB_DT_USERTYPE_REF = 1 << 7, + MB_DT_USERTYPE_REF = 1 << 6, #endif /* MB_ENABLE_USERTYPE_REF */ - MB_DT_ARRAY = 1 << 8, + MB_DT_ARRAY = 1 << 7, #ifdef MB_ENABLE_COLLECTION_LIB - MB_DT_LIST = 1 << 9, - MB_DT_LIST_IT = 1 << 10, - MB_DT_DICT = 1 << 11, - MB_DT_DICT_IT = 1 << 12, + MB_DT_LIST = 1 << 8, + MB_DT_LIST_IT = 1 << 9, + MB_DT_DICT = 1 << 10, + MB_DT_DICT_IT = 1 << 11, + MB_DT_COLLECTION = MB_DT_LIST | MB_DT_DICT, #endif /* MB_ENABLE_COLLECTION_LIB */ #ifdef MB_ENABLE_CLASS - MB_DT_CLASS = 1 << 13, + MB_DT_CLASS = 1 << 12, #endif /* MB_ENABLE_CLASS */ - MB_DT_ROUTINE = 1 << 14 + MB_DT_ROUTINE = 1 << 13 } mb_data_e; typedef unsigned char mb_val_bytes_t[sizeof(void*) > sizeof(unsigned long) ? sizeof(void*) : sizeof(unsigned long)]; diff --git a/output/my_basic.exe b/output/my_basic.exe index 083e6c7..70115ff 100755 Binary files a/output/my_basic.exe and b/output/my_basic.exe differ