avatar

566

Upgrade to JRuby 1.1.3 for the scripting side of things. by mrs, 23 Jul, 2008 08:53 PM
Diff this changeset:
math.rb
      require 'duby/typer'

module Duby
  module Typer
    class MathTyper < BaseTyper
      def name
        "Math"
      end
      
      def method_type(typer, target_type, name, parameter_types)
        return nil unless parameter_types.size == 1
        
        result = case target_type
        when typer.fixnum_type
          case name
          when :-
            case parameter_types[0]
            when typer.fixnum_type
              typer.fixnum_type
            else
              nil
            end
          when :+
            case parameter_types[0]
            when typer.fixnum_type
              typer.fixnum_type
            else
              nil
            end
          when :*
            case parameter_types[0]
            when typer.fixnum_type
              typer.fixnum_type
            else
              nil
            end
          when :/
            case parameter_types[0]
            when typer.fixnum_type
              typer.fixnum_type
            else
              nil
            end
          when :<
            case parameter_types[0]
            when typer.fixnum_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
    end
  end

  typer_plugins << Typer::MathTyper.new
end
    

Check out the code: svn co jbidwatcher/trunk/lib/ruby/site_ruby/1.8/duby/plugin/math.rb