mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
Hash splat ** should not be ignored.
Implemented by adding `OP_HASHCAT` that merges hashes.
This commit is contained in:
@@ -94,6 +94,7 @@ OPCODE(STRING, BB) /* R(a) = str_dup(Lit(b)) */
|
||||
OPCODE(STRCAT, B) /* str_cat(R(a),R(a+1)) */
|
||||
OPCODE(HASH, BB) /* R(a) = hash_new(R(a),R(a+1)..R(a+b)) */
|
||||
OPCODE(HASHADD, BB) /* R(a) = hash_push(R(a),R(a+1)..R(a+b)) */
|
||||
OPCODE(HASHCAT, B) /* R(a) = hash_cat(R(a),R(a+1)) */
|
||||
OPCODE(LAMBDA, BB) /* R(a) = lambda(SEQ[b],L_LAMBDA) */
|
||||
OPCODE(BLOCK, BB) /* R(a) = lambda(SEQ[b],L_BLOCK) */
|
||||
OPCODE(METHOD, BB) /* R(a) = lambda(SEQ[b],L_METHOD) */
|
||||
|
||||
@@ -1874,15 +1874,32 @@ codegen(codegen_scope *s, node *tree, int val)
|
||||
mrb_bool update = FALSE;
|
||||
|
||||
while (tree) {
|
||||
if (nt == NODE_KW_HASH &&
|
||||
nint(tree->car->car->car) == NODE_KW_REST_ARGS) {
|
||||
tree = tree->cdr;
|
||||
continue;
|
||||
if (nint(tree->car->car->car) == NODE_KW_REST_ARGS) {
|
||||
if (len > 0) {
|
||||
pop_n(len*2);
|
||||
if (!update) {
|
||||
genop_2(s, OP_HASH, cursp(), len);
|
||||
}
|
||||
else {
|
||||
pop();
|
||||
genop_2(s, OP_HASHADD, cursp(), len);
|
||||
}
|
||||
push();
|
||||
}
|
||||
codegen(s, tree->car->cdr, VAL);
|
||||
if (len > 0) {
|
||||
pop(); pop();
|
||||
genop_1(s, OP_HASHCAT, cursp());
|
||||
push();
|
||||
}
|
||||
update = TRUE;
|
||||
len = 0;
|
||||
}
|
||||
else {
|
||||
codegen(s, tree->car->car, VAL);
|
||||
codegen(s, tree->car->cdr, VAL);
|
||||
len++;
|
||||
}
|
||||
|
||||
codegen(s, tree->car->car, val);
|
||||
codegen(s, tree->car->cdr, val);
|
||||
len++;
|
||||
tree = tree->cdr;
|
||||
if (val && len == 255) {
|
||||
pop_n(len*2);
|
||||
@@ -1905,7 +1922,9 @@ codegen(codegen_scope *s, node *tree, int val)
|
||||
}
|
||||
else {
|
||||
pop();
|
||||
genop_2(s, OP_HASHADD, cursp(), len);
|
||||
if (len > 0) {
|
||||
genop_2(s, OP_HASHADD, cursp(), len);
|
||||
}
|
||||
}
|
||||
push();
|
||||
}
|
||||
|
||||
+5
-1
@@ -416,7 +416,11 @@ codedump(mrb_state *mrb, mrb_irep *irep)
|
||||
print_lv_a(mrb, irep, a);
|
||||
break;
|
||||
CASE(OP_HASHADD, BB):
|
||||
printf("OP_HASHADD\tR%d\t%d", a, b);
|
||||
printf("OP_HASHADD\tR%d\t%d\t", a, b);
|
||||
print_lv_a(mrb, irep, a);
|
||||
break;
|
||||
CASE(OP_HASHCAT, B):
|
||||
printf("OP_HASHCAT\tR%d\t", a);
|
||||
print_lv_a(mrb, irep, a);
|
||||
break;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user