summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--include/mruby/khash.h11
-rw-r--r--src/codegen.c5
-rw-r--r--test/t/syntax.rb32
3 files changed, 43 insertions, 5 deletions
diff --git a/include/mruby/khash.h b/include/mruby/khash.h
index 8a62e3ee6..6a4861bda 100644
--- a/include/mruby/khash.h
+++ b/include/mruby/khash.h
@@ -148,20 +148,23 @@ kh_fill_flags(uint8_t *p, uint8_t c, size_t len)
new_n_buckets = KHASH_MIN_SIZE; \
khash_power2(new_n_buckets); \
{ \
+ kh_##name##_t hh; \
uint8_t *old_ed_flags = h->ed_flags; \
khkey_t *old_keys = h->keys; \
khval_t *old_vals = h->vals; \
khint_t old_n_buckets = h->n_buckets; \
khint_t i; \
- h->n_buckets = new_n_buckets; \
- kh_alloc_##name(mrb, h); \
+ hh.n_buckets = new_n_buckets; \
+ kh_alloc_##name(mrb, &hh); \
/* relocate */ \
for (i=0 ; i<old_n_buckets ; i++) { \
if (!__ac_iseither(old_ed_flags, i)) { \
- khint_t k = kh_put_##name(mrb, h, old_keys[i], NULL); \
- if (kh_is_map) kh_value(h,k) = old_vals[i]; \
+ khint_t k = kh_put_##name(mrb, &hh, old_keys[i], NULL); \
+ if (kh_is_map) kh_value(&hh,k) = old_vals[i]; \
} \
} \
+ /* copy hh to h */ \
+ *h = hh; \
mrb_free(mrb, old_keys); \
} \
} \
diff --git a/src/codegen.c b/src/codegen.c
index d22892ecf..46d457885 100644
--- a/src/codegen.c
+++ b/src/codegen.c
@@ -1001,7 +1001,9 @@ gen_vmassignment(codegen_scope *s, node *tree, int rhs, int val)
}
if (val) {
genop(s, MKOP_AB(OP_MOVE, cursp(), rhs));
- push();
+ }
+ else {
+ pop();
}
genop(s, MKOP_ABC(OP_APOST, cursp(), n, post));
n = 1;
@@ -1016,6 +1018,7 @@ gen_vmassignment(codegen_scope *s, node *tree, int rhs, int val)
n++;
}
}
+ push();
}
}
diff --git a/test/t/syntax.rb b/test/t/syntax.rb
index e7a962441..7ec6272fe 100644
--- a/test/t/syntax.rb
+++ b/test/t/syntax.rb
@@ -181,6 +181,38 @@ assert('Splat and multiple assignment') do
assert_equal [1,nil,2], [a,b,c]
end
+assert('Splat and multiple assignment from variable') do
+ a = [1, 2, 3]
+ b, *c = a
+
+ assert_equal 1, b
+ assert_equal [2, 3], c
+end
+
+assert('Splat and multiple assignment from variables') do
+ a = [1, 2, 3]
+ b = [4, 5, 6, 7]
+ c, d, *e, f, g = *a, *b
+
+ assert_equal 1, c
+ assert_equal 2, d
+ assert_equal [3, 4, 5], e
+ assert_equal 6, f
+ assert_equal 7, g
+end
+
+assert('Splat and multiple assignment in for') do
+ a = [1, 2, 3, 4, 5, 6, 7]
+ for b, c, *d, e, f in [a] do
+ end
+
+ assert_equal 1, b
+ assert_equal 2, c
+ assert_equal [3, 4, 5], d
+ assert_equal 6, e
+ assert_equal 7, f
+end
+
assert('Return values of case statements') do
a = [] << case 1
when 3 then 2