aboutsummaryrefslogtreecommitdiffstats
path: root/insns.def
diff options
context:
space:
mode:
authorJeremy Evans <code@jeremyevans.net>2019-09-02 08:21:30 -0700
committerGitHub <noreply@github.com>2019-09-02 08:21:30 -0700
commitf560609d66502101264706877577220e3ebf5a38 (patch)
treed30a77b807ed0d4eb5363270b7119f1f31165b54 /insns.def
parentbe86591458c5f29db0d97601f29e15e43d5fe23c (diff)
downloadruby-f560609d66502101264706877577220e3ebf5a38.tar.gz
Merge pull request #2418 from jeremyevans/array-empty-kwsplat
Ignore empty keyword splats in arrays
Diffstat (limited to 'insns.def')
-rw-r--r--insns.def20
1 files changed, 20 insertions, 0 deletions
diff --git a/insns.def b/insns.def
index 35a6aa9def..1399687578 100644
--- a/insns.def
+++ b/insns.def
@@ -441,6 +441,26 @@ newarray
val = rb_ary_new4(num, STACK_ADDR_FROM_TOP(num));
}
+/* put new array initialized with num values on the stack. There
+ should be at least one element on the stack, and the top element
+ should be a hash. If the top element is empty, it is not
+ included in the array.
+ */
+DEFINE_INSN
+newarraykwsplat
+(rb_num_t num)
+(...)
+(VALUE val)
+// attr rb_snum_t sp_inc = 1 - (rb_snum_t)num;
+{
+ if (RHASH_EMPTY_P(*STACK_ADDR_FROM_TOP(1))) {
+ val = rb_ary_new4(num-1, STACK_ADDR_FROM_TOP(num));
+ }
+ else {
+ val = rb_ary_new4(num, STACK_ADDR_FROM_TOP(num));
+ }
+}
+
/* dup array */
DEFINE_INSN
duparray