Class: Mirah::AST::Script

Inherits:
Node
  • Object
show all
Includes:
Binding, Scope
Defined in:
lib/mirah/ast/structure.rb,
lib/mirah/compiler/structure.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Attributes included from Scope

#static_scope, #type_scope

Attributes inherited from Node

#children, #inferred_type, #newline, #parent, #position

Instance Method Summary collapse

Methods included from Binding

#binding_type, #binding_type=, #has_binding?

Methods included from Scoped

#containing_scope, #scope

Methods inherited from Node

#<<, ===, #[], #[]=, #_dump, _load, #_set_parent, child, child_name, #child_nodes, #each, #empty?, #expr?, #inferred_type!, #initialize_copy, #insert, #inspect, #inspect_children, #line_number, #log, #precompile, #resolve_if, #resolved!, #resolved?, #simple_name, #string_value, #temp, #to_s, #top_level?, #validate_child, #validate_children

Constructor Details

#initialize(parent, line_number, &block) ⇒ Script

Returns a new instance of Script.



262
263
264
265
# File 'lib/mirah/ast/structure.rb', line 262

def initialize(parent, line_number, &block)
  super(parent, line_number, &block)
  @package = ""
end

Class Attribute Details

.explicit_packagesObject

Returns the value of attribute explicit_packages.



289
290
291
# File 'lib/mirah/ast/structure.rb', line 289

def explicit_packages
  @explicit_packages
end

Instance Attribute Details

#defining_classObject

Returns the value of attribute defining_class.



259
260
261
# File 'lib/mirah/ast/structure.rb', line 259

def defining_class
  @defining_class
end

#filenameObject

Returns the value of attribute filename.



260
261
262
# File 'lib/mirah/ast/structure.rb', line 260

def filename
  @filename
end

Instance Method Details

#compile(compiler, expression) ⇒ Object



48
49
50
51
52
53
# File 'lib/mirah/compiler/structure.rb', line 48

def compile(compiler, expression)
  # TODO: what does it mean for a script to be an expression? possible?
  compiler.define_main(self)
rescue Exception => ex
  raise Mirah::InternalCompilerError.wrap(ex, self)
end

#infer(typer, expression) ⇒ Object



267
268
269
270
271
272
273
274
275
# File 'lib/mirah/ast/structure.rb', line 267

def infer(typer, expression)
  resolve_if(typer) do
    typer.set_filename(self, filename)
    @defining_class ||= begin
      static_scope.self_type = typer.self_type
    end
    typer.infer(body, false)
  end
end