vm/codegen/instructions_gen.rb
# Wraps instruction implementation code provided by instructions.rb.
# It also captures some meta info using parsetree to generate
# better output.
#
Wraps instruction implementation code provided by instructions.rb.
It also captures some meta info using parsetree to generate
better output.
Wraps instruction implementation code provided by instructions . rb . It also captures some meta info using parsetree to generate better output .
def output_node(indent, code, node, distance)
    regular = InstructionSet::OpCodes.size
    if node.size == 1 and node.key?(:__superop__)
      code << "#{' ' * indent}return #{node[:__superop__] + regular};\n"
      return
    end
    term = false
    code << "#{' ' * indent}switch(stream[#{distance}]) {\n"
    node.each do |name, sub|
      if name == :__superop__
        term = true
        code << "#{' ' * indent}default: return #{sub + regular};\n"
      else
        inst = InstructionSet[name]
        code << "#{' ' * indent}case #{inst.bytecode}: // #{name}\n"
        output_node(indent + 2, code, sub, distance + inst.width)
      end
    end
    unless term
      code << "#{' ' * indent}default: return -1;\n"
    end
    code << "#{' ' * indent}}\n"
    return code
  end
def output_node ( indent , code , node , distance ) regular = InstructionSet :: OpCodes . size if node . size == 1 and node . key? ( :__superop__ ) code << "#{' ' * indent}return #{node[:__superop__] + regular};\n" return end term = false code << "#{' ' * indent}switch(stream[#{distance}]) {\n" node . each do | name , sub | if name == :__superop__ term = true code << "#{' ' * indent}default: return #{sub + regular};\n" else inst = InstructionSet [ name ] code << "#{' ' * indent}case #{inst.bytecode}: // #{name}\n" output_node ( indent + 2 , code , sub , distance + inst . width ) end end unless term code << "#{' ' * indent}default: return -1;\n" end code << "#{' ' * indent}}\n" return code end
Wraps instruction implementation code provided by instructions.rb.
Wraps instruction implementation code provided by instructions . rb .
indent
<not_specific>
code
<not_specific>
node
<not_specific>
distance
<not_specific>