From 5ec676aa37b1c6e345b29ffa02ea8210b7a94da5 Mon Sep 17 00:00:00 2001 From: Kouhei Sutou Date: Tue, 23 Dec 2014 21:16:01 +0900 Subject: Fix splat and multiple assignments Case1: From variable Code: a = [1, 2, 3, 4, 5] b, c, *d = a p [a, b, c, d] Before: [[1, 2, 3, 4, 5], 1, 2, []] After: [[1, 2, 3, 4, 5], 1, 2, [3, 4, 5]] Ruby: [[1, 2, 3, 4, 5], 1, 2, [3, 4, 5]] Case2: From variables Code: a = [1, 2, 3] b = [4, 5, 6, 7] c, d, *e, f, g = *a, *b p [a, b, c, d, e, f, g] Before: [[1, 2, 3], [4, 5, 6, 7], 1, 2, [], 6, 7] After: [[1, 2, 3], [4, 5, 6, 7], 1, 2, [3, 4, 5], 6, 7] Ruby: [[1, 2, 3], [4, 5, 6, 7], 1, 2, [3, 4, 5], 6, 7] Case 3: "for" Code: a = [1, 2, 3, 4, 5, 6, 7] for b, c, *d, e, f in [a] do p [a, b, c, d, e, f] end Before: [[1, 2, 3, 4, 5, 6, 7], 1, 2, [], nil, nil] After: [[1, 2, 3, 4, 5, 6, 7], 1, 2, [3, 4, 5], 6, 7] Ruby: [[1, 2, 3, 4, 5, 6, 7], 1, 2, [3, 4, 5], 6, 7] --- src/codegen.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src') 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(); } } -- cgit v1.2.3