path: root/tool
diff options
authorshyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-10-29 03:21:22 (GMT)
committershyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-10-29 03:21:22 (GMT)
commitc80f3f709fc94dac52726b5d9a2f486e6c3be745 (patch)
treef0b76377a91af5378b117e72ffe1223151c2bda8 /tool
parent08e47ab98a7b205f64ec89d7dcc7c347b55f0dfe (diff)
less verbose code by sharing attribute definitions
The idea behind this commit is that handles_sp and leaf are two concepts that are not mutually independent. By making one explicitly depend another, we can reduces the number of lines of codes written, thus making things concise. git-svn-id: svn+ssh:// b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'tool')
1 files changed, 19 insertions, 5 deletions
diff --git a/tool/ruby_vm/models/bare_instructions.rb b/tool/ruby_vm/models/bare_instructions.rb
index 7d9ed6d..2767f38 100755
--- a/tool/ruby_vm/models/bare_instructions.rb
+++ b/tool/ruby_vm/models/bare_instructions.rb
@@ -144,6 +144,7 @@ class RubyVM::BareInstructions
def predefine_attributes
+ # Beware: order matters here because some attribute depends another.
generate_attribute 'const char*', 'name', "insn_name(#{bin})"
generate_attribute 'enum ruby_vminsn_type', 'bin', bin
generate_attribute 'rb_num_t', 'open', opes.size
@@ -151,11 +152,24 @@ class RubyVM::BareInstructions
generate_attribute 'rb_num_t', 'retn', rets.size
generate_attribute 'rb_num_t', 'width', width
generate_attribute 'rb_snum_t', 'sp_inc', rets.size - pops.size
- generate_attribute 'bool', 'handles_sp', false
- generate_attribute 'bool', 'leaf', opes.all? {|o|
- # Insn with ISEQ should yield it; can never be a leaf.
- o[:type] != 'ISEQ'
- }
+ generate_attribute 'bool', 'handles_sp', default_definition_of_handles_sp
+ generate_attribute 'bool', 'leaf', default_definition_of_leaf
+ end
+ def default_definition_of_handles_sp
+ # Insn with ISEQ should yield it; can handle sp.
+ return opes.any? {|o| o[:type] == 'ISEQ' }
+ end
+ def default_definition_of_leaf
+ # Insn that handles SP can never be a leaf.
+ if not has_attribute? 'handles_sp' then
+ return ! default_definition_of_handles_sp
+ elsif handles_sp? then
+ return "! #{call_attribute 'handles_sp'}"
+ else
+ return true
+ end
def typesplit a