Module: JRubyVisualizer

Defined in:
lib/jruby_visualizer/version.rb,
lib/jruby_visualizer/jruby_visualizer.rb

Overview

The Visualizer module enables to launch the visualizer components via an API call or ARGV

Constant Summary collapse

VERSION =
'0.2'
@@main_app =
nil
@@compiler_data =
nil

Class Method Summary collapse

Class Method Details

.compiler_dataObject



31
32
33
# File 'lib/jruby_visualizer/jruby_visualizer.rb', line 31

def self.compiler_data
  @@compiler_data
end

.compiler_data=(new_data) ⇒ Object



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

def self.compiler_data=(new_data)
  @@compiler_data = new_data
end

.inject_pass_listenerObject



54
55
56
57
58
59
60
61
62
# File 'lib/jruby_visualizer/jruby_visualizer.rb', line 54

def self.inject_pass_listener
  # create and add listener
  vis_pass_listener = VisualizerCompilerPassListener.new
  ir_manager = JRuby::runtime.ir_manager
  ir_manager.add_listener(vis_pass_listener)

  # activate visualization listener
  JRuby::IR.visualize = true
end

.launchObject



43
44
45
46
47
48
49
50
51
52
# File 'lib/jruby_visualizer/jruby_visualizer.rb', line 43

def self.launch
  if launched?
    return
  end
  unless @@compiler_data
    raise 'Cannot launch Visualizer without a ComiplerData object'
  end
  VisualizerMainApp.launch
  @@main_app = VisualizerMainApp
end

.launched?Boolean

Returns:

  • (Boolean)


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

def self.launched?
  !!@@main_app
end

.pass_listener?Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/jruby_visualizer/jruby_visualizer.rb', line 64

def self.pass_listener?
  JRuby::IR.visualize
end

.visualize(ruby_code) ⇒ Object



68
69
70
71
72
73
74
75
# File 'lib/jruby_visualizer/jruby_visualizer.rb', line 68

def self.visualize(ruby_code)
  unless pass_listener?
    inject_pass_listener
  end
  @@compiler_data = CompilerData.new(ruby_code)
  # launch App with Ruby code as input
  launch
end

.visualize_with_argvObject



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/jruby_visualizer/jruby_visualizer.rb', line 77

def self.visualize_with_argv
  unless ARGV.length == 1
    usage_message =
    %#No ruby input for the JRuby Visualizer
Usage: 
  ./lib/jruby_visualizer.rb "def foo; 42; end; foo"
or
  ./lib/jruby_visualizer.rb foo.rb#
    raise usage_message
  end
  ruby_input = ARGV[0]
  ruby_code =
  if ruby_input.end_with?('.rb')
    File.read(ruby_input)
  else
    ruby_input
  end
  visualize(ruby_code)
end