Sha256: b200ea6917b73b042ac6fa18e6b85afc17a38fcc011ecf0f47dd1e9ae7caf182

Contents?: true

Size: 1.24 KB

Versions: 1

Compression:

Stored size: 1.24 KB

Contents

module Duby::AST
  class Body < Node
    def initialize(parent, line_number, &block)
      super(parent, line_number, &block)
    end
        
    # Type of a block is the type of its final element
    def infer(typer)
      unless @inferred_type
        if children.size == 0
          @inferred_type = typer.default_type
        else
          children.each {|child| @inferred_type = typer.infer(child)}
        end
          
        unless @inferred_type
          typer.defer(self)
        end
      end

      @inferred_type
    end
    
    def <<(node)
      @children << node
      node.parent = self
    end
    
    def empty?
      @children.empty?
    end
  end
  
  class Block < Node
    attr_accessor :args, :body

    def initialize(parent, position, &block)
      super(parent, position, &block)
      @args, @body = children
    end
  end
  
  class Noop < Node
    def infer(typer)
      @inferred_type ||= typer.no_type
    end
  end
  
  class Script < Node
    include Scope
    attr_accessor :body
    
    def initialize(parent, line_number, &block)
      super(parent, line_number, children, &block)
      @body = children[0]
    end
    
    def infer(typer)
      @inferred_type ||= typer.infer(body) || (typer.defer(self); nil)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

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