Sha256: 363b42338f10959034a7f171ad1102bc462e37b4ca6ac90a1fd14fcd6c2e2b67

Contents?: true

Size: 1.3 KB

Versions: 1

Compression:

Stored size: 1.3 KB

Contents

module Duby::AST
  class Print < Node
    attr_accessor :parameters
    attr_accessor :println
    
    def initialize(parent, line_number, println, &block)
      super(parent, line_number, &block)
      @parameters = children
      @println = println
    end

    def infer(typer)
      if parameters.size > 0
        resolved = parameters.select {|param| typer.infer(param); param.resolved?}
        resolved! if resolved.size == parameters.size
      else
        resolved!
      end
      typer.no_type
    end
  end
  
  defmacro('puts') do |transformer, fcall, parent|
    Print.new(parent, fcall.position, true) do |print|
      if fcall.respond_to?(:args_node) && fcall.args_node
        fcall.args_node.child_nodes.map do |arg|
          transformer.transform(arg, print)
        end
      else
        []
      end
    end
  end

  defmacro('print') do |transformer, fcall, parent|
    Print.new(parent, fcall.position, false) do |print|
      if fcall.respond_to?(:args_node) && fcall.args_node
        fcall.args_node.child_nodes.map do |arg|
          transformer.transform(arg, print)
        end
      else
        []
      end
    end
  end
  
  class InlineCode
    def initialize(&block)
      @block = block
    end
    
    def inline(transformer, call)
      @block.call(transformer, call)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
duby-0.0.2-java lib/duby/ast/intrinsics.rb