changed VM to emulate 'Dictionary new: ..' for MAKE_DICTIONARY

changed VM to emulate 'dic put_assoc: assoc' for POP_INTO_DICTIONARY
This commit is contained in:
hyunghwan.chung
2017-02-10 07:38:29 +00:00
parent 46f3e8635e
commit b1c28d03d7
6 changed files with 106 additions and 85 deletions

View File

@ -3716,7 +3716,7 @@ int moo_execute (moo_t* moo)
LOG_INST_3 (moo, "send_message%hs %zu @%zu", (((bcode >> 2) & 1)? "_to_super": ""), b1, b2);
if (send_message (moo, selector, ((bcode >> 2) & 1), b1) <= -1) goto oops;
break; /* CMD_SEND_MESSAGE */
break;
}
/* -------------------------------------------------------- */
@ -3795,32 +3795,36 @@ int moo_execute (moo_t* moo)
/* -------------------------------------------------------- */
case BCODE_MAKE_DICTIONARY:
{
moo_oop_t t;
FETCH_PARAM_CODE_TO (moo, b1);
LOG_INST_1 (moo, "make_dictionary %zu", b1);
/* create an empty array */
t = (moo_oop_t)moo_makedic (moo, moo->_dictionary, b1 + 10); /* TODO: find a better value than +10 for initial dictionary sizing */
if (!t) goto oops;
MOO_STACK_PUSH (moo, t); /* push the array created */
/* Dictionary new: b1
* doing this allows users to redefine Dictionary whatever way they like.
* if i did the followings instead, the internal of Dictionary would get
* tied to the system dictionary implementation. the system dictionary
* implementation is flawed in that it accepts only a variable character
* object as a key. it's better to invoke 'Dictionary new: ...'.
t = (moo_oop_t)moo_makedic (moo, moo->_dictionary, b1 + 10);
MOO_STACK_PUSH (moo, t);
*/
MOO_STACK_PUSH (moo, moo->_dictionary);
MOO_STACK_PUSH (moo, MOO_SMOOI_TO_OOP(b1));
if (send_message (moo, moo->dicnewsym, 0, 1) <= -1) goto oops;
break;
}
case BCODE_POP_INTO_DICTIONARY:
{
moo_oop_t t1, t2;
LOG_INST_0 (moo, "pop_into_dictionary");
/* dic __put_assoc: assoc
* whether the system dictinoary implementation is flawed or not,
* the code would look like this if it were used.
t1 = MOO_STACK_GETTOP(moo);
MOO_STACK_POP (moo);
t2 = MOO_STACK_GETTOP(moo);
moo_putatdic (moo, (moo_oop_set_t)t2, ((moo_oop_association_t)t1)->key, ((moo_oop_association_t)t1)->value); /* TODO: 1. erorr check 2. reuse association as it it */
moo_putatdic (moo, (moo_oop_set_t)t2, ((moo_oop_association_t)t1)->key, ((moo_oop_association_t)t1)->value);
*/
if (send_message (moo, moo->dicputassocsym, 0, 1) <= -1) goto oops;
break;
}
case BCODE_MAKE_ASSOCIATION:
{