Module: Mirah

Included in:
Typer::Base
Defined in:
lib/mirah/version.rb,
lib/mirah.rb,
lib/mirah/ast.rb,
lib/mirah/env.rb,
lib/mirah_task.rb,
lib/mirah/typer.rb,
lib/mirah/errors.rb,
lib/mirah/parser.rb,
lib/mirah/ast/flow.rb,
lib/mirah/compiler.rb,
lib/mirah/ast/scope.rb,
lib/mirah/generator.rb,
lib/mirah/jvm/typer.rb,
lib/mirah/typer/base.rb,
lib/mirah/plugin/java.rb,
lib/mirah/commands/run.rb,
lib/mirah/jvm/compiler.rb,
lib/mirah/typer/simple.rb,
lib/mirah/commands/base.rb,
lib/mirah/compiler/call.rb,
lib/mirah/compiler/flow.rb,
lib/mirah/compiler/type.rb,
lib/mirah/commands/parse.rb,
lib/mirah/compiler/class.rb,
lib/mirah/compiler/local.rb,
lib/mirah/jvm/types/type.rb,
lib/mirah/compiler/method.rb,
lib/mirah/transform/error.rb,
lib/mirah/commands/compile.rb,
lib/mirah/compiler/literal.rb,
lib/mirah/transform/helper.rb,
lib/mirah/jvm/compiler/base.rb,
lib/mirah/jvm/method_lookup.rb,
lib/mirah/transform/ast_ext.rb,
lib/mirah/util/class_loader.rb,
lib/mirah/compiler/structure.rb,
lib/mirah/jvm/types/meta_type.rb,
lib/mirah/jvm/types/null_type.rb,
lib/mirah/jvm/types/void_type.rb,
lib/mirah/util/process_errors.rb,
lib/mirah/jvm/types/array_type.rb,
lib/mirah/transform/transformer.rb,
lib/mirah/jvm/types/dynamic_type.rb,
lib/mirah/util/compilation_state.rb,
lib/mirah/util/argument_processor.rb,
lib/mirah/jvm/compiler/java_source.rb,
lib/mirah/jvm/types/primitive_type.rb,
lib/mirah/jvm/compiler/jvm_bytecode.rb,
lib/mirah/jvm/types/type_definition.rb,
lib/mirah/jvm/source_generator/loops.rb,
lib/mirah/jvm/source_generator/typer.rb,
lib/mirah/jvm/types/unreachable_type.rb,
lib/mirah/jvm/source_generator/builder.rb,
lib/mirah/jvm/types/interface_definition.rb

Overview

Copyright © 2010 The Mirah project authors. All Rights Reserved. All contributing project authors may be found in the NOTICE file.

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Defined Under Namespace

Modules: AST, Commands, Compiler, Env, JVM, JavaSource, Transform, Typer, Util Classes: Generator, InferenceError, InternalCompilerError, MirahError, NodeError, Parser, PathArray, SyntaxError

Constant Summary collapse

VERSION =
"0.0.9"
TransformError =
Transform::Error

Class Method Summary collapse

Class Method Details

.compile(*args) ⇒ Object



39
40
41
# File 'lib/mirah.rb', line 39

def self.compile(*args)
  Mirah::Commands::Compile.new(args).execute
end

.compiler_optionsObject



85
86
87
# File 'lib/mirah_task.rb', line 85

def self.compiler_options
  @compiler_options ||= []
end

.compiler_options=(args) ⇒ Object



89
90
91
# File 'lib/mirah_task.rb', line 89

def self.compiler_options=(args)
  @compiler_options = args
end

.dest_pathObject



41
42
43
# File 'lib/mirah_task.rb', line 41

def self.dest_path
  dest_paths[0] ||= File.expand_path('.')
end

.dest_path=(path) ⇒ Object



45
46
47
# File 'lib/mirah_task.rb', line 45

def self.dest_path=(path)
  dest_paths[0] = File.expand_path(path)
end

.dest_pathsObject



37
38
39
# File 'lib/mirah_task.rb', line 37

def self.dest_paths
  @dest_paths ||= PathArray.new
end

.dest_to_source_path(target_path) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/mirah_task.rb', line 67

def self.dest_to_source_path(target_path)
  destdir = find_dest(target_path)
  path = File.expand_path(target_path).sub(/^#{destdir}\//, '')
  path.sub!(/\.(java|class)$/, '')
  snake_case = File.basename(path).gsub(/[A-Z]/, '_\0').sub(/_/, '').downcase
  snake_case = "#{File.dirname(path)}/#{snake_case}"
  source_paths.each do |source_path|
    ["mirah", "duby"].each do |suffix|
      filename = "#{source_path}/#{path}.#{suffix}"
      return filename if File.exist?(filename)
      filename = "#{source_path}/#{snake_case}.#{suffix}"
      return filename if File.exist?(filename)
    end
  end
  # No source file exists. Just go with the first source path and .mirah
  return "#{self.source_path}/#{path}.mirah"
end

.find_dest(path) ⇒ Object



49
50
51
52
53
54
55
56
# File 'lib/mirah_task.rb', line 49

def self.find_dest(path)
  expanded = File.expand_path(path)
  dest_paths.each do |destdir|
    if expanded =~ /^#{destdir}\//
      return destdir
    end
  end
end

.find_source(path) ⇒ Object



58
59
60
61
62
63
64
65
# File 'lib/mirah_task.rb', line 58

def self.find_source(path)
  expanded = File.expand_path(path)
  source_paths.each do |sourcedir|
    if expanded =~ /^#{sourcedir}\//
      return sourcedir
    end
  end
end

.parse(*args) ⇒ Object



43
44
45
# File 'lib/mirah.rb', line 43

def self.parse(*args)
  Mirah::Commands::Parse.new(args).execute
end

.pluginsObject



47
48
49
# File 'lib/mirah.rb', line 47

def self.plugins
  @plugins ||= []
end


55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/mirah.rb', line 55

def self.print_error(message, position)
  if position.nil?
    puts message
    return
  end
  puts "#{position.file}:#{position.start_line}: #{message}"
  file_offset = 0
  startline = position.start_line - 1
  endline = position.end_line - 1
  start_col = position.start_col - 1
  end_col = position.end_col - 1
  # don't try to search dash_e
  # TODO: show dash_e source the same way
  if File.exist? position.file
    File.open(position.file).each_with_index do |line, lineno|
      if lineno >= startline && lineno <= endline
        puts line.chomp
        if lineno == startline
          print ' ' * start_col
        else
          start_col = 0
        end
        if lineno < endline
          puts '^' * (line.size - start_col)
        else
          puts '^' * [end_col - start_col, 1].max
        end
      end
    end
  end
end

.resetObject



51
52
53
# File 'lib/mirah.rb', line 51

def self.reset
  plugins.each {|x| x.reset if x.respond_to?(:reset)}
end

.run(*args) ⇒ Object



35
36
37
# File 'lib/mirah.rb', line 35

def self.run(*args)
  Mirah::Commands::Run.new(args).execute
end

.source_pathObject



25
26
27
# File 'lib/mirah_task.rb', line 25

def self.source_path
  source_paths[0] ||= File.expand_path('.')
end

.source_path=(path) ⇒ Object



33
34
35
# File 'lib/mirah_task.rb', line 33

def self.source_path=(path)
  source_paths[0] = File.expand_path(path)
end

.source_pathsObject



29
30
31
# File 'lib/mirah_task.rb', line 29

def self.source_paths
  @source_paths ||= PathArray.new
end

.typer_pluginsObject



33
34
35
# File 'lib/mirah/typer.rb', line 33

def self.typer_plugins
  @typer_plugins ||= []
end