Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

ruby 1.9 compatible case statements

  • Loading branch information...
commit e77ac481d846f8d5d73bf7dbf14da01d45e5dc50 1 parent 88a7ca9
@samsonjs authored
Showing with 54 additions and 27 deletions.
  1. +4 −2 asm/binary.rb
  2. +4 −2 asm/machofile.rb
  3. +8 −4 build.rb
  4. +38 −19 compiler.rb
View
6 asm/binary.rb
@@ -637,8 +637,10 @@ def movzx(dest, src)
if register?(dest)
opcode = case
- when rm?(src, :byte): 0xb6 # movzx Gv, Eb
- when rm?(src, :word): 0xb7 # movzx Gv, Ew
+ when rm?(src, :byte)
+ 0xb6 # movzx Gv, Eb
+ when rm?(src, :word)
+ 0xb7 # movzx Gv, Ew
else
raise "unsupported MOVZX instruction, dest=#{dest.inspect} << src=#{src.inspect} >>"
end
View
6 asm/machofile.rb
@@ -358,8 +358,10 @@ def calculate_offsets
def segname_based_on_filetype(segname)
case @header[:filetype]
- when MH_OBJECT: ''
- when MH_EXECUTE: segname
+ when MH_OBJECT
+ ''
+ when MH_EXECUTE
+ segname
else
raise "unsupported MachO file type: #{@header.inspect}"
end
View
12 build.rb
@@ -76,8 +76,10 @@ def assemble(filename, binformat='elf')
def link(filename, outdir, platform='linux')
f = base(filename)
cmd, args = *case platform
- when 'darwin': ['gcc', '-arch i386']
- when 'linux': ['ld', '']
+ when 'darwin'
+ ['gcc', '-arch i386']
+ when 'linux'
+ ['ld', '']
else
raise "unsupported platform: #{platform}"
end
@@ -90,8 +92,10 @@ def build(filename, outdir, platform='linux', binformat='elf')
objfile = File.join(outdir, base(filename) + '.o')
symtab, objwriter_class =
case binformat
- when 'elf': [Assembler::ELFSymtab.new, Assembler::ELFFile]
- when 'macho': [Assembler::MachOSymtab.new, Assembler::MachOFile]
+ when 'elf'
+ [Assembler::ELFSymtab.new, Assembler::ELFFile]
+ when 'macho'
+ [Assembler::MachOSymtab.new, Assembler::MachOFile]
else
raise "unsupported binary format: #{binformat}"
end
View
57 compiler.rb
@@ -156,8 +156,10 @@ def term
while op?(:mul, @look)
asm.push(EAX)
case @look
- when '*': multiply
- when '/': divide
+ when '*'
+ multiply
+ when '/'
+ divide
end
end
end
@@ -170,8 +172,10 @@ def arithmetic_expression
while op_char?(@look, :add)
asm.push(EAX)
case @look
- when '+': add
- when '-': subtract
+ when '+'
+ add
+ when '-'
+ subtract
end
end
end
@@ -230,9 +234,12 @@ def bit_expression
while op?(:bit, @look)
scan
case @value
- when '|': bitor_expression
- when '^': bitxor_expression
- when '&': bitand_expression
+ when '|'
+ bitor_expression
+ when '^'
+ bitxor_expression
+ when '&'
+ bitand_expression
else
backtrack
return
@@ -357,12 +364,18 @@ def relation
scan
asm.push(EAX)
case @value
- when '==': eq_relation
- when '!=': neq_relation
- when '>': gt_relation
- when '>=': ge_relation
- when '<': lt_relation
- when '<=': le_relation
+ when '=='
+ eq_relation
+ when '!='
+ neq_relation
+ when '>'
+ gt_relation
+ when '>='
+ ge_relation
+ when '<'
+ lt_relation
+ when '<='
+ le_relation
end
end
end
@@ -921,12 +934,18 @@ def hook(callback, *methods)
def print_token
print(case @token
- when :keyword: '[kw] '
- when :number: '[nu] '
- when :identifier: '[id] '
- when :op: '[op] '
- when :boolean: '[bo] '
- when :newline: ''
+ when :keyword
+ '[kw] '
+ when :number
+ '[nu] '
+ when :identifier
+ '[id] '
+ when :op
+ '[op] '
+ when :boolean
+ '[bo] '
+ when :newline
+ ''
else
raise "print doesn't know about #{@token}: #{@value}"
end)
Please sign in to comment.
Something went wrong with that request. Please try again.