From 98b0b73c22aa0dc630f40d46e349a3ae3d6a6c48 Mon Sep 17 00:00:00 2001
From: Eric Wong <e@80x24.org>
Date: Sun, 21 Sep 2014 06:23:33 +0000
Subject: [PATCH 1/2] iseq: reduce from 280 to 272 bytes

- arg_simple is limited to 3 possible values: 0, 1, and 2
- arg_keyword_check is a boolean
- flip_cnt should be int to enforce portable code between 64-bit and
  32-bit systems and must fit in FIXNUM space.
  I doubt anybody would notice if flip_cnt (or any arg counters)
  were 8 bits, even.
---
 compile.c |  7 +++++--
 vm_core.h | 11 ++++++++---
 2 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/compile.c b/compile.c
index 923f7ae..56397d4 100644
--- a/compile.c
+++ b/compile.c
@@ -5184,7 +5184,7 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped)
 	LABEL *lfin = NEW_LABEL(line);
 	LABEL *ltrue = NEW_LABEL(line);
 	rb_iseq_t *local_iseq = iseq->local_iseq;
-	rb_num_t cnt;
+	unsigned int cnt;
 	VALUE key;
 
 	cnt = local_iseq->flip_cnt++ + DEFAULT_SPECIAL_VAR_COUNT;
@@ -5955,7 +5955,10 @@ rb_iseq_build_from_ary(rb_iseq_t *iseq, VALUE locals, VALUE args,
 				    rb_ary_entry(arg_opt_labels, i));
 	}
 
-	iseq->arg_simple = NUM2INT(arg_simple);
+	i = FIX2INT(arg_simple);
+	if (i < 0 || i > 2)
+	    rb_raise(rb_eRangeError, "arg_simple must be 0..2: %d", i);
+	iseq->arg_simple = i;
     }
 
     /* exception */
diff --git a/vm_core.h b/vm_core.h
index ce2fb76..9b91602 100644
--- a/vm_core.h
+++ b/vm_core.h
@@ -259,7 +259,13 @@ struct rb_iseq_struct {
      */
 
     int argc;
-    int arg_simple;
+
+    uint8_t arg_simple; /* 0..2 */
+
+    /* bool, if this is true, raise an ArgumentError when unknown
+     * keyword argument is passed */
+    uint8_t arg_keyword_check;
+
     int arg_rest;
     int arg_block;
     int arg_opts;
@@ -267,8 +273,8 @@ struct rb_iseq_struct {
     int arg_post_start;
     int arg_size;
     VALUE *arg_opt_table;
+    unsigned int flip_cnt; /* used at compile time */
     int arg_keyword;
-    int arg_keyword_check; /* if this is true, raise an ArgumentError when unknown keyword argument is passed */
     int arg_keywords;
     int arg_keyword_required;
     ID *arg_keyword_table;
@@ -301,7 +307,6 @@ struct rb_iseq_struct {
 
     /* misc */
     ID defined_method_id;	/* for define_method */
-    rb_num_t flip_cnt;
 
     /* used at compile time */
     struct iseq_compile_data *compile_data;
-- 
EW

