+added support to duplicate a class instance by new statement with an identifier string; *fixed a string value copy issue in mb_pop_value.

This commit is contained in:
paladin-t 2016-01-04 13:35:14 +08:00
parent 7072aab05c
commit 468df58c6f
2 changed files with 19 additions and 0 deletions

View File

@ -1,3 +1,7 @@
Jan. 4 2016
Added support to duplicate a class instance by NEW statement with an identifier string
Fixed a string value copy issue in mb_pop_value
Jan. 2 2016 Jan. 2 2016
Added support to apply GET statement to a class instance Added support to apply GET statement to a class instance
Added support to access a collection by brackets Added support to access a collection by brackets

View File

@ -8291,6 +8291,7 @@ int mb_pop_value(struct mb_interpreter_t* s, void** l, mb_value_t* val) {
_ls_clear(s->temp_values); _ls_clear(s->temp_values);
val_ptr = _create_object(); val_ptr = _create_object();
memcpy(val_ptr, &val_obj, sizeof(_object_t));
_ls_pushback(s->temp_values, val_ptr); _ls_pushback(s->temp_values, val_ptr);
} }
_REF(val_ptr) _REF(val_ptr)
@ -11166,6 +11167,8 @@ int _core_new(mb_interpreter_t* s, void** l) {
_object_t obj; _object_t obj;
_object_t tgt; _object_t tgt;
mb_value_t ret; mb_value_t ret;
_ls_node_t* cs = 0;
_object_t* c = 0;
mb_assert(s && l); mb_assert(s && l);
@ -11179,6 +11182,17 @@ int _core_new(mb_interpreter_t* s, void** l) {
_MAKE_NIL(&obj); _MAKE_NIL(&obj);
switch(arg.type) { switch(arg.type) {
case MB_DT_STRING:
arg.value.string = mb_strupr(arg.value.string);
cs = _search_identifier_in_scope_chain(s, 0, arg.value.string, 0, 0);
if(!cs || !cs->data) goto _default;
c = (_object_t*)cs->data;
if(!c) goto _default;
c = _GET_CLASS(c);
if(!c) goto _default;
_internal_object_to_public_value(c, &arg);
_ref(&c->data.instance->ref, c->data.instance);
/* Fall through */
case MB_DT_CLASS: case MB_DT_CLASS:
_public_value_to_internal_object(&arg, &obj); _public_value_to_internal_object(&arg, &obj);
_clone_object(s, &obj, &tgt); _clone_object(s, &obj, &tgt);
@ -11187,6 +11201,7 @@ int _core_new(mb_interpreter_t* s, void** l) {
break; break;
default: default:
_default:
_handle_error_on_obj(s, SE_RN_CLASS_EXPECTED, 0, TON(l), MB_FUNC_ERR, _exit, result); _handle_error_on_obj(s, SE_RN_CLASS_EXPECTED, 0, TON(l), MB_FUNC_ERR, _exit, result);
break; break;