Sha256: d0d9c727d055883498b3009ba70dcd9bc44e92526b3c2cc136f0c80fb08fe1fa

Contents?: true

Size: 1.97 KB

Versions: 7

Compression:

Stored size: 1.97 KB

Contents

# coding=utf-8

module CastOff::Compiler
  module SimpleIR
    class ReturnIR < IR
      attr_reader :return_value, :variables_without_result, :variables, :result_variable, :values

      class ThrowObj
        attr_reader :type, :raw_state, :state

        def initialize(type, raw_state, state, flag, level)
          @type = type
          @raw_state = raw_state
          @state = state
        end
      end

      def initialize(retval, throwobj, insn, cfg)
        super(insn, cfg)
        @throwobj = throwobj
        @return_value = retval
        @values = [@return_value]
        @variables = []
        @variables_without_result = []
        if @return_value.is_a?(Variable)
          @variables << @return_value
          @variables_without_result << @return_value
        end
        @result_variable = nil
      end

      ### unboxing begin ###
      def unboxing_prelude()
        @return_value.box()
      end

      def propergate_boxed_value(defs)
        bug() unless @return_value.boxed?
        defs.propergate_boxed_value_backward(@return_value)
      end
      ### unboxing end ###

      def propergate_exact_class(defs)
        false
      end

      def to_c()
        if @insn.iseq.catch_exception?
          prereturn = "  TH_POP_TAG2();\n"
        else
          prereturn = ''
        end
        case @throwobj
        when ThrowObj 
          if @translator.inline_block?
            return prereturn + "  return_from_execute(#{@throwobj.raw_state}, #{@return_value});"
          else
            return prereturn + "  return return_block(#{@throwobj.raw_state}, #{@return_value}, lambda_p);"
          end
        when NilClass
          return prereturn + "  return #{@return_value};"
        end
        bug()
      end

      def type_propergation(defs)
        defs.type_resolve(@return_value)
      end

      def mark(defs)
        if !alive?
          alive()
          defs.mark(@return_value)
          true
        else
          false
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
cast_off-0.4.1 lib/cast_off/compile/ir/return_ir.rb
cast_off-0.4.0 lib/cast_off/compile/ir/return_ir.rb
cast_off-0.3.7 lib/cast_off/compile/ir/return_ir.rb
cast_off-0.3.6 lib/cast_off/compile/ir/return_ir.rb
cast_off-0.3.5 lib/cast_off/compile/ir/return_ir.rb
cast_off-0.3.4 lib/cast_off/compile/ir/return_ir.rb
cast_off-0.3.2 lib/cast_off/compile/ir/return_ir.rb