Class: Duby::Typer::MathTyper

Inherits:
BaseTyper show all
Defined in:
lib/duby/plugin/math.rb

Constant Summary

Constants included from Duby

Duby::TransformError, VERSION

Instance Method Summary collapse

Methods inherited from BaseTyper

#log, #to_s

Methods included from Duby

compile, parse, run, typer_plugins

Instance Method Details

#method_type(typer, target_type, name, parameter_types) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/duby/plugin/math.rb', line 10

def method_type(typer, target_type, name, parameter_types)
  return nil unless parameter_types.size == 1

  result = case name
  when '-', '+', '*', '/', '%'
    case target_type
    when typer.fixnum_type
      case parameter_types[0]
      when typer.fixnum_type
        typer.fixnum_type
      when typer.float_type
        typer.float_type
      else
        nil
      end
    when typer.float_type
      case parameter_types[0]
      when typer.float_type
        typer.float_type
      when typer.fixnum_type
        typer.float_type
      else
        nil
      end
    else
      nil
    end
  when '<<', '>>', '>>>', '&', '|', '^'
    case target_type
    when typer.fixnum_type
      case parameter_types[0]
      when typer.fixnum_type
        typer.fixnum_type
      else
        nil
      end
    else
      nil
    end
  when '<', '>', '<=', '>=', '=='
    case target_type
    when typer.fixnum_type
      case parameter_types[0]
      when typer.fixnum_type
        typer.boolean_type
      else
        nil
      end
    when typer.float_type
      case parameter_types[0]
      when typer.float_type
        typer.boolean_type
      else
        nil
      end
    else
      nil
    end
  else
    nil
  end
  
  if result
    log "Method type for \"#{name}\" #{parameter_types} on #{target_type} = #{result}"
  else
    log "Method type for \"#{name}\" #{parameter_types} on #{target_type} not found"
  end
  
  result
end

#nameObject



6
7
8
# File 'lib/duby/plugin/math.rb', line 6

def name
  "Math"
end