From 468df58c6fec42e08ca1fd3a04a4e558c013b482 Mon Sep 17 00:00:00 2001 From: paladin-t Date: Mon, 4 Jan 2016 13:35:14 +0800 Subject: [PATCH] +added support to duplicate a class instance by new statement with an identifier string; *fixed a string value copy issue in mb_pop_value. --- HISTORY | 4 ++++ core/my_basic.c | 15 +++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/HISTORY b/HISTORY index fe3d8b6..54b381f 100755 --- a/HISTORY +++ b/HISTORY @@ -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 Added support to apply GET statement to a class instance Added support to access a collection by brackets diff --git a/core/my_basic.c b/core/my_basic.c index 262b17d..0459672 100755 --- a/core/my_basic.c +++ b/core/my_basic.c @@ -8291,6 +8291,7 @@ int mb_pop_value(struct mb_interpreter_t* s, void** l, mb_value_t* val) { _ls_clear(s->temp_values); val_ptr = _create_object(); + memcpy(val_ptr, &val_obj, sizeof(_object_t)); _ls_pushback(s->temp_values, val_ptr); } _REF(val_ptr) @@ -11166,6 +11167,8 @@ int _core_new(mb_interpreter_t* s, void** l) { _object_t obj; _object_t tgt; mb_value_t ret; + _ls_node_t* cs = 0; + _object_t* c = 0; mb_assert(s && l); @@ -11179,6 +11182,17 @@ int _core_new(mb_interpreter_t* s, void** l) { _MAKE_NIL(&obj); 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: _public_value_to_internal_object(&arg, &obj); _clone_object(s, &obj, &tgt); @@ -11187,6 +11201,7 @@ int _core_new(mb_interpreter_t* s, void** l) { break; default: +_default: _handle_error_on_obj(s, SE_RN_CLASS_EXPECTED, 0, TON(l), MB_FUNC_ERR, _exit, result); break;