added make_association, pop_into_association_key, pop_into_association_value byte codes to support assocation expressions

This commit is contained in:
hyunghwan.chung 2017-02-05 15:05:25 +00:00
parent eb83c8d83a
commit 60c38a1ecb
5 changed files with 77 additions and 5 deletions

View File

@ -215,14 +215,33 @@ class MyObject(Object)
## end of elimination.
a :=999.
a := #{
a := #{
1,
2,
a,
4,
1 + 1,
2 + 2
#{ 1, 2, #{a, a := a + 1, a, if (a > 10) { a + 20 } }, 3},
2 + 2,
#'a b c'
}.
(* Dictionary ???
a := #{
"a": 20,
b : 30
}.
a := #{
{ key, value },
{ key, value },
{ key, value },
{ key, value }
}
*)
abc := { key, value }.
{ key, value } dump.
a do: [ :v | v dump].
(*

View File

@ -3993,7 +3993,6 @@ static int compile_array_expression (moo_t* moo)
index = 0;
do
{
/* TODO: check if index exceeds the index that the BCODE_POP_INTO_ARRAY and BCODE_MAKE_ARRAY can support */
if (compile_method_expression (moo, 0) <= -1) return -1;
if (emit_single_param_instruction (moo, BCODE_POP_INTO_ARRAY, index) <= -1) return -1;
index++;

View File

@ -488,6 +488,18 @@ int moo_decode (moo_t* moo, moo_oop_method_t mth, const moo_oocs_t* classfqn)
break;
/* -------------------------------------------------------- */
case BCODE_MAKE_ASSOCIATION:
LOG_INST_0 (moo, "make_association");
break;
case BCODE_POP_INTO_ASSOCIATION_KEY:
LOG_INST_0 (moo, "pop_into_association_key");
break;
case BCODE_POP_INTO_ASSOCIATION_VALUE:
LOG_INST_0 (moo, "pop_into_association_value");
break;
case BCODE_MAKE_ARRAY:
FETCH_PARAM_CODE_TO (moo, b1);
LOG_INST_1 (moo, "make_array %zu", b1);

View File

@ -3795,6 +3795,45 @@ int moo_execute (moo_t* moo)
break;
/* -------------------------------------------------------- */
case BCODE_MAKE_ASSOCIATION:
{
moo_oop_t t;
LOG_INST_0 (moo, "make_association");
t = moo_instantiate (moo, moo->_association, MOO_NULL, 0);
if (!t) goto oops;
MOO_STACK_PUSH (moo, t); /* push the association created */
break;
}
case BCODE_POP_INTO_ASSOCIATION_KEY:
{
moo_oop_t t1, t2;
LOG_INST_0 (moo, "pop_into_association_key");
t1 = MOO_STACK_GETTOP(moo);
MOO_STACK_POP (moo);
t2 = MOO_STACK_GETTOP(moo);
((moo_oop_association_t)t2)->key = t1;
break;
}
case BCODE_POP_INTO_ASSOCIATION_VALUE:
{
moo_oop_t t1, t2;
LOG_INST_0 (moo, "pop_into_association_value");
t1 = MOO_STACK_GETTOP(moo);
MOO_STACK_POP (moo);
t2 = MOO_STACK_GETTOP(moo);
((moo_oop_association_t)t2)->value = t1;
break;
}
case BCODE_MAKE_ARRAY:
{
moo_oop_t t;

View File

@ -858,8 +858,11 @@ enum moo_bcode_t
BCODE_STORE_INTO_OBJVAR_X = 0xE8, /* 232 ## */
BCODE_POP_INTO_OBJVAR_X = 0xEC, /* 236 ## */
BCODE_SEND_MESSAGE_X = 0xF0, /* 240 ## */
BCODE_SEND_MESSAGE_TO_SUPER_X = 0xF4, /* 244 ## */
BCODE_SEND_MESSAGE_X = 0xF0, /* 240 ## */
BCODE_MAKE_ASSOCIATION = 0xF1, /* 241 */
BCODE_POP_INTO_ASSOCIATION_KEY = 0xF2, /* 242 */
BCODE_POP_INTO_ASSOCIATION_VALUE = 0xF3, /* 243 */
BCODE_SEND_MESSAGE_TO_SUPER_X = 0xF4, /* 244 ## */
/* -------------------------------------- */