mirah 0.0.7-java → 0.0.8-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (182) hide show
  1. data/History.txt +181 -0
  2. data/README.txt +6 -10
  3. data/Rakefile +86 -9
  4. data/bin/mirah +2 -0
  5. data/bin/mirahc +2 -0
  6. data/bin/mirahp +2 -0
  7. data/{bin/dubyp → examples/interfaces.mirah} +16 -9
  8. data/examples/macros/square.mirah +12 -0
  9. data/examples/macros/square_int.mirah +12 -0
  10. data/examples/macros/string-each-char.mirah +14 -0
  11. data/examples/maven/README.txt +2 -0
  12. data/examples/maven/pom.xml +23 -0
  13. data/examples/maven/src/main/mirah/hello_mirah.mirah +9 -0
  14. data/examples/rosettacode/100-doors.mirah +44 -0
  15. data/examples/rosettacode/99-bottles-of-beer.mirah +13 -0
  16. data/examples/rosettacode/README.txt +9 -0
  17. data/examples/rosettacode/boolean-values.mirah +29 -0
  18. data/examples/rosettacode/comments.mirah +2 -0
  19. data/examples/rosettacode/copy-a-string.mirah +10 -0
  20. data/examples/rosettacode/count-occurrences-of-a-substring.mirah +40 -0
  21. data/examples/rosettacode/create-a-file.mirah +6 -0
  22. data/examples/rosettacode/empty-string.mirah +9 -0
  23. data/examples/rosettacode/factorial.mirah +10 -0
  24. data/examples/rosettacode/fibonacci.mirah +21 -0
  25. data/examples/rosettacode/file-size.mirah +5 -0
  26. data/examples/rosettacode/fizz-buzz.mirah +21 -0
  27. data/examples/rosettacode/flatten-a-list.mirah +24 -0
  28. data/examples/rosettacode/guess-the-number.mirah +21 -0
  29. data/examples/rosettacode/is-string-numeric.mirah +127 -0
  30. data/examples/rosettacode/palindrome.mirah +14 -0
  31. data/examples/rosettacode/repeat-a-string.mirah +9 -0
  32. data/examples/rosettacode/reverse-a-string.mirah +6 -0
  33. data/examples/rosettacode/rot-13.mirah +20 -0
  34. data/examples/rosettacode/user-input.mirah +4 -0
  35. data/examples/sort_closure.mirah +1 -1
  36. data/javalib/dynalink-0.2.jar +0 -0
  37. data/javalib/mirah-bootstrap.jar +0 -0
  38. data/lib/mirah.rb +7 -16
  39. data/lib/mirah/ast.rb +22 -92
  40. data/lib/mirah/ast/call.rb +41 -9
  41. data/lib/mirah/ast/class.rb +34 -6
  42. data/lib/mirah/ast/flow.rb +17 -5
  43. data/lib/mirah/ast/intrinsics.rb +50 -8
  44. data/lib/mirah/ast/literal.rb +7 -0
  45. data/lib/mirah/ast/local.rb +9 -1
  46. data/lib/mirah/ast/method.rb +21 -8
  47. data/lib/mirah/ast/scope.rb +1 -1
  48. data/lib/mirah/ast/structure.rb +81 -15
  49. data/lib/mirah/ast/type.rb +4 -0
  50. data/{bin/dubyc → lib/mirah/commands.rb} +4 -11
  51. data/lib/mirah/commands/base.rb +54 -0
  52. data/lib/mirah/commands/compile.rb +39 -0
  53. data/{examples/wiki/Rakefile → lib/mirah/commands/parse.rb} +18 -17
  54. data/lib/mirah/commands/run.rb +73 -0
  55. data/lib/mirah/compiler.rb +37 -417
  56. data/lib/mirah/compiler/call.rb +45 -0
  57. data/lib/mirah/compiler/class.rb +81 -0
  58. data/lib/mirah/compiler/flow.rb +109 -0
  59. data/lib/mirah/compiler/literal.rb +130 -0
  60. data/lib/mirah/compiler/local.rb +59 -0
  61. data/lib/mirah/compiler/method.rb +44 -0
  62. data/lib/mirah/compiler/structure.rb +65 -0
  63. data/lib/mirah/compiler/type.rb +27 -0
  64. data/lib/mirah/env.rb +4 -6
  65. data/lib/mirah/generator.rb +61 -0
  66. data/lib/mirah/jvm/compiler.rb +8 -867
  67. data/lib/mirah/jvm/compiler/base.rb +270 -0
  68. data/lib/mirah/jvm/compiler/java_source.rb +779 -0
  69. data/lib/mirah/jvm/compiler/jvm_bytecode.rb +851 -0
  70. data/lib/mirah/jvm/method_lookup.rb +21 -2
  71. data/lib/mirah/jvm/source_generator/builder.rb +10 -13
  72. data/lib/mirah/jvm/source_generator/loops.rb +99 -93
  73. data/lib/mirah/jvm/source_generator/precompile.rb +3 -2
  74. data/lib/mirah/jvm/typer.rb +3 -3
  75. data/lib/mirah/jvm/types.rb +10 -426
  76. data/lib/mirah/jvm/types/array_type.rb +62 -0
  77. data/lib/mirah/jvm/types/basic_types.rb +1 -0
  78. data/lib/mirah/jvm/types/dynamic_type.rb +46 -0
  79. data/lib/mirah/jvm/types/factory.rb +23 -5
  80. data/lib/mirah/jvm/types/interface_definition.rb +20 -0
  81. data/lib/mirah/jvm/types/intrinsics.rb +15 -3
  82. data/lib/mirah/jvm/types/meta_type.rb +45 -0
  83. data/lib/mirah/jvm/types/methods.rb +12 -5
  84. data/lib/mirah/jvm/types/null_type.rb +27 -0
  85. data/lib/mirah/jvm/types/primitive_type.rb +38 -0
  86. data/lib/mirah/jvm/types/source_mirror.rb +266 -0
  87. data/lib/mirah/jvm/types/type.rb +173 -0
  88. data/lib/mirah/jvm/types/type_definition.rb +55 -0
  89. data/lib/mirah/jvm/types/unreachable_type.rb +27 -0
  90. data/lib/mirah/jvm/types/void_type.rb +19 -0
  91. data/lib/mirah/parser.rb +90 -0
  92. data/lib/mirah/plugin/gwt.rb +5 -5
  93. data/lib/mirah/plugin/java.rb +1 -1
  94. data/lib/mirah/transform.rb +4 -321
  95. data/lib/mirah/transform/ast_ext.rb +63 -0
  96. data/lib/mirah/transform/error.rb +13 -0
  97. data/lib/mirah/transform/helper.rb +761 -0
  98. data/lib/mirah/transform/transformer.rb +255 -0
  99. data/lib/mirah/typer.rb +2 -383
  100. data/{bin/duby → lib/mirah/typer/base.rb} +12 -10
  101. data/lib/mirah/typer/simple.rb +377 -0
  102. data/lib/mirah/util/argument_processor.rb +114 -0
  103. data/lib/mirah/util/class_loader.rb +37 -0
  104. data/lib/mirah/util/compilation_state.rb +51 -0
  105. data/lib/mirah/util/process_errors.rb +33 -0
  106. data/lib/mirah/version.rb +1 -1
  107. data/lib/mirah_task.rb +3 -2
  108. data/test/{test_ast.rb → core/test_ast.rb} +6 -0
  109. data/test/{test_compilation.rb → core/test_compilation.rb} +0 -0
  110. data/test/{test_env.rb → core/test_env.rb} +24 -25
  111. data/test/{test_macros.rb → core/test_macros.rb} +2 -4
  112. data/test/{test_typer.rb → core/test_typer.rb} +0 -3
  113. data/test/jvm/bytecode_test_helper.rb +181 -0
  114. data/test/{test_javac_compiler.rb → jvm/javac_test_helper.rb} +38 -22
  115. data/test/jvm/test_enumerable.rb +304 -0
  116. data/test/{test_java_typer.rb → jvm/test_java_typer.rb} +2 -4
  117. data/test/{test_jvm_compiler.rb → jvm/test_jvm_compiler.rb} +146 -443
  118. data/test/jvm/test_macros.rb +147 -0
  119. data/test/jvm/test_main_method.rb +15 -0
  120. data/test/{test_gwt.rb → plugins/test_gwt.rb} +0 -2
  121. metadata +103 -91
  122. data/bin/jrubyp +0 -52
  123. data/examples/wiki/src/org/mirah/wiki/MirahWiki.duby +0 -339
  124. data/examples/wiki/src/org/mirah/wiki/edit.eduby.html +0 -42
  125. data/examples/wiki/src/org/mirah/wiki/error.eduby.html +0 -2
  126. data/examples/wiki/src/org/mirah/wiki/layout.eduby.html +0 -69
  127. data/examples/wiki/src/org/mirah/wiki/parser.eduby.html +0 -7
  128. data/examples/wiki/src/org/mirah/wiki/view.eduby.html +0 -15
  129. data/examples/wiki/war/WEB-INF/classes/test/HeredocContext.class +0 -0
  130. data/examples/wiki/war/WEB-INF/classes/test/MirahParser.class +0 -0
  131. data/examples/wiki/war/WEB-INF/lib/appengine-api.jar +0 -0
  132. data/examples/wiki/war/WEB-INF/lib/dubydatastore.jar +0 -0
  133. data/examples/wiki/war/WEB-INF/lib/jmeta-runtime.jar +0 -0
  134. data/examples/wiki/war/WEB-INF/lib/pegdown-stubs.jar +0 -0
  135. data/examples/wiki/war/WEB-INF/pegdown.jar +0 -0
  136. data/examples/wiki/war/app.yaml +0 -21
  137. data/examples/wiki/war/public/favicon.ico +0 -0
  138. data/examples/wiki/war/public/images/appengine_duby.png +0 -0
  139. data/examples/wiki/war/public/images/back.gif +0 -0
  140. data/examples/wiki/war/public/images/dir.gif +0 -0
  141. data/examples/wiki/war/public/images/file.gif +0 -0
  142. data/examples/wiki/war/public/javascripts/prettify.js +0 -61
  143. data/examples/wiki/war/public/robots.txt +0 -0
  144. data/examples/wiki/war/public/stylesheets/main.css +0 -156
  145. data/examples/wiki/war/public/stylesheets/prettify.css +0 -1
  146. data/examples/wiki/war/public/stylesheets/sh_style.css +0 -66
  147. data/examples/wiki/war/public/stylesheets/source.css +0 -21
  148. data/examples/wiki/war/public/wmd/images/bg-fill.png +0 -0
  149. data/examples/wiki/war/public/wmd/images/bg.png +0 -0
  150. data/examples/wiki/war/public/wmd/images/blockquote.png +0 -0
  151. data/examples/wiki/war/public/wmd/images/bold.png +0 -0
  152. data/examples/wiki/war/public/wmd/images/code.png +0 -0
  153. data/examples/wiki/war/public/wmd/images/h1.png +0 -0
  154. data/examples/wiki/war/public/wmd/images/hr.png +0 -0
  155. data/examples/wiki/war/public/wmd/images/img.png +0 -0
  156. data/examples/wiki/war/public/wmd/images/italic.png +0 -0
  157. data/examples/wiki/war/public/wmd/images/link.png +0 -0
  158. data/examples/wiki/war/public/wmd/images/ol.png +0 -0
  159. data/examples/wiki/war/public/wmd/images/redo.png +0 -0
  160. data/examples/wiki/war/public/wmd/images/separator.png +0 -0
  161. data/examples/wiki/war/public/wmd/images/ul.png +0 -0
  162. data/examples/wiki/war/public/wmd/images/undo.png +0 -0
  163. data/examples/wiki/war/public/wmd/images/wmd-on.png +0 -0
  164. data/examples/wiki/war/public/wmd/images/wmd.png +0 -0
  165. data/examples/wiki/war/public/wmd/showdown.js +0 -421
  166. data/examples/wiki/war/public/wmd/wmd-base.js +0 -1799
  167. data/examples/wiki/war/public/wmd/wmd-plus.js +0 -311
  168. data/examples/wiki/war/public/wmd/wmd.js +0 -73
  169. data/examples/wiki/war/src/org/mirah/wiki/MirahWiki.duby +0 -339
  170. data/examples/wiki/war/src/org/mirah/wiki/edit.eduby.html +0 -42
  171. data/examples/wiki/war/src/org/mirah/wiki/error.eduby.html +0 -2
  172. data/examples/wiki/war/src/org/mirah/wiki/layout.eduby.html +0 -69
  173. data/examples/wiki/war/src/org/mirah/wiki/parser.eduby.html +0 -7
  174. data/examples/wiki/war/src/org/mirah/wiki/view.eduby.html +0 -15
  175. data/javalib/dynalink-0.1.jar +0 -0
  176. data/javalib/jsr292-mock.jar +0 -0
  177. data/lib/mirah/class_loader.rb +0 -35
  178. data/lib/mirah/compilation_state.rb +0 -28
  179. data/lib/mirah/impl.rb +0 -273
  180. data/lib/mirah/jvm/base.rb +0 -267
  181. data/lib/mirah/jvm/source_compiler.rb +0 -760
  182. data/lib/mirah/transform2.rb +0 -752
@@ -1,42 +0,0 @@
1
- <div>
2
- <% if @error %>
3
- <div id=error><%=h @error %></div>
4
- <% end %>
5
- <div>
6
- <form method=post>
7
- <textarea id=body name=body style="width:95%;font-family:monospace" rows=5
8
- ><% if @page && @page.body %><%=h @page.body %><% end
9
- %></textarea><br>
10
- Your Name: <input name=nickname value="<%=h nickname %>"><br>
11
- Comment: <input name=comment value=<% if @page %>
12
- "Edited Page"
13
- <% else %>
14
- "Created Page"
15
- <% end %>><br>
16
- <input type=hidden name=version value="<%= @page ? @page.version : long(0) %>">
17
- <% if admin? %>
18
- Locked: <input name=locked value=locked type=checkbox <%= "checked" if @page && @page.locked%>><br>
19
- <% end %>
20
- <input type=submit name=Save>
21
- </form>
22
- </div>
23
- <hr style="clear:all">
24
- <div id=preview class="wmd-preview"></div>
25
- <script>
26
- (function(){
27
- var ta = document.getElementById("body");
28
- var sh = 0;
29
- function resize() {
30
- var nsh = ta.scrollHeight;
31
- if (nsh != sh) {
32
- ta.style.height = 0;
33
- ta.style.height = (nsh + 100) + "px";
34
- sh = ta.scrollHeight;
35
- }
36
- setTimeout(resize, 250);
37
- }
38
- resize();
39
- })();
40
- wmd_options={output:"markdown"};
41
- </script>
42
- <script type="text/javascript" src="/wmd/wmd.js""></script>
@@ -1,2 +0,0 @@
1
- <h1>error:</h1>
2
- <p><%=h @error %></p>
@@ -1,69 +0,0 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta http-equiv="content-type" content="text/html; charset=UTF-8">
5
- <title><%=h @title %></title>
6
- <link type="text/css" rel="stylesheet" href="/stylesheets/main.css">
7
- <link href="/stylesheets/prettify.css" type="text/css" rel="stylesheet" />
8
- <script type="text/javascript" src="/javascripts/prettify.js"></script>
9
- </head>
10
- <body onload="prettyPrint()">
11
- <div id="page">
12
- <div id="sidebar">
13
-
14
- <h1>Mirah</h1>
15
-
16
- <ul id="sidebar-items">
17
-
18
- <li>
19
- <h3>Join the community</h3>
20
- <ul class="links">
21
- <li><a href="/">Home Page</a></li>
22
- <li><a href="http://github.com/mirah/mirah">github</a></li>
23
- <li><a href="/wiki/Resources">Resources</a></li>
24
- <li><a href="/wiki/MirahHowto">Howto</a></li>
25
- <li><a
26
- href="http://groups.google.com/group/mirah/"
27
- target="_new">Send Feedback</a></li>
28
- </ul>
29
- </li>
30
-
31
- <li>
32
- <h3>Sample Apps</h3>
33
- <ul class="links">
34
- <li><a href="http://github.com/mirah/mirah/tree/master/examples/appengine/">Guestbook</a> |
35
- <a href="http://github.com/jacortinas/appengine-rails-jquery-demo">Mustache</a></li>
36
- </ul>
37
- <a href="/wiki/MirahSamples">Sample Code</a>
38
- </li>
39
-
40
- <li>
41
- <h3>Mirah Videos</h3>
42
- <ul class="links">
43
- <li><a href="http://www.youtube.com/watch?v=08rNKxW0PPo">ribrdb</a> |
44
- <a href="http://confreaks.net/videos/196-rubyconf2009-ruby-mutants">headius</a></li>
45
- </ul>
46
- </li>
47
-
48
- </div>
49
-
50
- <div id="content">
51
- <div id=hlinks>
52
- <% if user %>
53
- <%=h user.getEmail %>&nbsp;|&nbsp;
54
- <% extra_links.each do |_pair|;pair = List(_pair) %>
55
- <a href="<%=h pair.get(1)%>"><%=h pair.get(0)%></a>&nbsp;|&nbsp;
56
- <% end %>
57
- <a href="<%=h users.createLogoutURL('/')%>">Sign Out</a>
58
- <% else %>
59
- <a href="<%=users.createLoginURL(url)%>">Sign In</a>
60
- <% end %>
61
- </div>
62
- <div id=wikicontent>
63
- <%= @content %>
64
- </div>
65
- </div>
66
- </div>
67
- </body>
68
- </html>
69
-
@@ -1,7 +0,0 @@
1
- <form method=post>
2
- <p><textarea name="code" cols=80 rows=20><%=h @code %></textarea><br>
3
- <input type="submit" value="Parse"/>
4
- </p>
5
- </form>
6
- <h2>Parsed:</h2>
7
- <div><tt><%=h @parsed %></tt></div>
@@ -1,15 +0,0 @@
1
- <script>
2
- function newPage() {
3
- var p=prompt('Page name', '')
4
- if (p) {
5
- document.location = '/edit/' + p
6
- }
7
- }
8
- </script>
9
- <% if @page %>
10
- <%= markdown @page.body %>
11
- <% else %>
12
- <h1><%=h @name%></h1>
13
- <p>That page does not exist. Click <a href="/edit/<%=h @name%>">here</a>
14
- to create it.</p>
15
- <% end%>
Binary file
Binary file
@@ -1,35 +0,0 @@
1
- # This is a custom classloader impl to allow loading classes with
2
- # interdependencies by having findClass retrieve classes as needed from the
3
- # collection of all classes generated by the target script.
4
- module Mirah
5
- class ClassLoader < java::security::SecureClassLoader
6
- def initialize(parent, class_map)
7
- super(parent)
8
- @class_map = class_map
9
- end
10
-
11
- def findClass(name)
12
- if @class_map[name]
13
- bytes = @class_map[name].to_java_bytes
14
- defineClass(name, bytes, 0, bytes.length)
15
- else
16
- raise java.lang.ClassNotFoundException.new(name)
17
- end
18
- end
19
-
20
- def loadClass(name, resolve)
21
- cls = findLoadedClass(name)
22
- if cls == nil
23
- if @class_map[name]
24
- cls = findClass(name)
25
- else
26
- cls = super(name, false)
27
- end
28
- end
29
-
30
- resolveClass(cls) if resolve
31
-
32
- cls
33
- end
34
- end
35
- end
@@ -1,28 +0,0 @@
1
- module Mirah
2
- class CompilationState
3
- def initialize
4
- BiteScript.bytecode_version = BiteScript::JAVA1_5
5
- @save_extensions = true
6
- end
7
-
8
- attr_accessor :verbose, :destination
9
- attr_accessor :version_printed
10
- attr_accessor :help_printed
11
- attr_accessor :save_extensions
12
-
13
- def set_jvm_version(ver_str)
14
- case ver_str
15
- when '1.4'
16
- BiteScript.bytecode_version = BiteScript::JAVA1_4
17
- when '1.5'
18
- BiteScript.bytecode_version = BiteScript::JAVA1_5
19
- when '1.6'
20
- BiteScript.bytecode_version = BiteScript::JAVA1_6
21
- when '1.7'
22
- BiteScript.bytecode_version = BiteScript::JAVA1_7
23
- else
24
- $stderr.puts "invalid bytecode version specified: #{ver_str}"
25
- end
26
- end
27
- end
28
- end
@@ -1,273 +0,0 @@
1
- module Mirah
2
- class Impl
3
- def initialize
4
- Mirah::AST.type_factory = Mirah::JVM::Types::TypeFactory.new
5
- @running = false
6
- end
7
-
8
- def running?
9
- @running
10
- end
11
-
12
- def run(*args)
13
- main = nil
14
- class_map = {}
15
-
16
- # we're running!
17
- @running = true
18
-
19
- # generate all bytes for all classes
20
- generate(args) do |outfile, builder|
21
- bytes = builder.generate
22
- name = builder.class_name.gsub(/\//, '.')
23
- class_map[name] = bytes
24
- end
25
-
26
- # load all classes
27
- dcl = Mirah::ClassLoader.new(JRuby.runtime.jruby_class_loader, class_map)
28
- class_map.each do |name,|
29
- cls = dcl.load_class(name)
30
- # TODO: using first main; find correct one
31
- main ||= cls.get_method("main", java::lang::String[].java_class) #rescue nil
32
- end
33
-
34
- # run the main method we found
35
- if main
36
- begin
37
- main.invoke(nil, [args.to_java(:string)].to_java)
38
- rescue java.lang.Exception => e
39
- e = e.cause if e.cause
40
- raise e
41
- end
42
- else
43
- puts "No main found" unless @state.version_printed || @state.help_printed
44
- end
45
- rescue Mirah::InternalCompilerError => ice
46
- Mirah.print_error(ice.message, ice.position) if ice.node
47
- raise ice
48
- rescue Mirah::MirahError => ex
49
- Mirah.print_error(ex.message, ex.position)
50
- puts ex.backtrace if @state.verbose
51
- end
52
-
53
- def compile(*args)
54
- generate(args) do |filename, builder|
55
- filename = "#{@state.destination}#{filename}"
56
- FileUtils.mkdir_p(File.dirname(filename))
57
- bytes = builder.generate
58
- File.open(filename, 'wb') {|f| f.write(bytes)}
59
- end
60
- rescue Mirah::InternalCompilerError => ice
61
- Mirah.print_error(ice.message, ice.position) if ice.position
62
- puts "error on #{ice.node}(#{ice.node.object_id})"
63
- raise ice
64
- rescue Mirah::MirahError => ex
65
- Mirah.print_error(ex.message, ex.position)
66
- puts ex.backtrace if @state.verbose
67
- end
68
-
69
- def generate(args, &block)
70
- process_flags!(args)
71
-
72
- # collect all ASTs from all files
73
- all_nodes = []
74
- puts "Parsing..." unless running?
75
- expand_files(args).each do |duby_file|
76
- if duby_file == '-e'
77
- @filename = '-e'
78
- next
79
- elsif @filename == '-e'
80
- puts " <inline script>" unless running?
81
- all_nodes << parse('-e', duby_file)
82
- else
83
- puts " #{duby_file}" unless running?
84
- all_nodes << parse(duby_file)
85
- end
86
- @filename = nil
87
- exit 1 if @error
88
- end
89
-
90
- # enter all ASTs into inference engine
91
- puts "Inferring types..." unless running?
92
- infer_asts(all_nodes)
93
-
94
- # compile each AST in turn
95
- puts "Compiling..." unless running?
96
- all_nodes.each do |ast|
97
- puts " #{ast.position.file}" unless running?
98
- compile_ast(ast, &block)
99
- end
100
-
101
- puts "Done!" unless running?
102
- end
103
-
104
- def parse(*args)
105
- process_flags!(args)
106
- @filename = args.shift
107
-
108
- if @filename
109
- if @filename == '-e'
110
- @filename = 'DashE'
111
- src = args[0]
112
- else
113
- src = File.read(@filename)
114
- end
115
- else
116
- print_help
117
- exit(1)
118
- end
119
- begin
120
- ast = Mirah::AST.parse_ruby(src, @filename)
121
- # rescue org.jrubyparser.lexer.SyntaxException => ex
122
- # Mirah.print_error(ex.message, ex.position)
123
- # raise ex if @state.verbose
124
- end
125
- @transformer = Mirah::Transform::Transformer.new(@state)
126
- Java::MirahImpl::Builtin.initialize_builtins(@transformer)
127
- @transformer.filename = @filename
128
- ast = @transformer.transform(ast, nil)
129
- @transformer.errors.each do |ex|
130
- Mirah.print_error(ex.message, ex.position)
131
- raise ex.cause || ex if @state.verbose
132
- end
133
- @error = @transformer.errors.size > 0
134
-
135
- ast
136
- rescue Mirah::InternalCompilerError => ice
137
- Mirah.print_error(ice.message, ice.position) if ice.node
138
- raise ice
139
- rescue Mirah::MirahError => ex
140
- Mirah.print_error(ex.message, ex.position)
141
- puts ex.backtrace if @state.verbose
142
- end
143
-
144
- def infer_asts(asts)
145
- typer = Mirah::Typer::JVM.new(@transformer)
146
- asts.each {|ast| typer.infer(ast, true) }
147
- begin
148
- typer.resolve(false)
149
- ensure
150
- puts asts.inspect if @state.verbose
151
-
152
- failed = !typer.errors.empty?
153
- if failed
154
- puts "Inference Error:"
155
- typer.errors.each do |ex|
156
- if ex.node
157
- Mirah.print_error(ex.message, ex.position)
158
- else
159
- puts ex.message
160
- end
161
- puts ex.backtrace if @state.verbose
162
- end
163
- exit 1
164
- end
165
- end
166
- end
167
-
168
- def compile_ast(ast, &block)
169
- compiler = @compiler_class.new
170
- ast.compile(compiler, false)
171
- compiler.generate(&block)
172
- end
173
-
174
- def process_flags!(args)
175
- @state ||= Mirah::CompilationState.new
176
- while args.length > 0 && args[0] =~ /^-/
177
- case args[0]
178
- when '--classpath', '-c'
179
- args.shift
180
- Mirah::Env.decode_paths(args.shift, $CLASSPATH)
181
- when '--cd'
182
- args.shift
183
- Dir.chdir(args.shift)
184
- when '--dest', '-d'
185
- args.shift
186
- @state.destination = File.join(File.expand_path(args.shift), '')
187
- when '-e'
188
- break
189
- when '--explicit-packages'
190
- args.shift
191
- Mirah::AST::Script.explicit_packages = true
192
- when '--help', '-h'
193
- print_help
194
- args.clear
195
- when '--java', '-j'
196
- require 'mirah/jvm/source_compiler'
197
- @compiler_class = Mirah::Compiler::JavaSource
198
- args.shift
199
- when '--jvm'
200
- args.shift
201
- @state.set_jvm_version(args.shift)
202
- when '-I'
203
- args.shift
204
- $: << args.shift
205
- when '--plugin', '-p'
206
- args.shift
207
- plugin = args.shift
208
- require "mirah/plugin/#{plugin}"
209
- when '--verbose', '-V'
210
- Mirah::Typer.verbose = true
211
- Mirah::AST.verbose = true
212
- Mirah::Compiler::JVM.verbose = true
213
- @state.verbose = true
214
- args.shift
215
- when '--version', '-v'
216
- args.shift
217
- print_version
218
- when '--no-save-extensions'
219
- args.shift
220
- @state.save_extensions = false
221
- else
222
- puts "unrecognized flag: " + args[0]
223
- print_help
224
- args.clear
225
- end
226
- end
227
- @state.destination ||= File.join(File.expand_path('.'), '')
228
- @compiler_class ||= Mirah::Compiler::JVM
229
- end
230
-
231
- def print_help
232
- puts "#{$0} [flags] <files or -e SCRIPT>
233
- -c, --classpath PATH\tAdd PATH to the Java classpath for compilation
234
- --cd DIR\t\tSwitch to the specified DIR befor compilation
235
- -d, --dir DIR\t\tUse DIR as the base dir for compilation, packages
236
- -e CODE\t\tCompile or run the inline script following -e
237
- \t\t\t (the class will be named \"DashE\")
238
- --explicit-packages\tRequire explicit 'package' lines in source
239
- -h, --help\t\tPrint this help message
240
- -I DIR\t\tAdd DIR to the Ruby load path before running
241
- -j, --java\t\tOutput .java source (compile mode only)
242
- --jvm VERSION\t\tEmit JVM bytecode targeting specified JVM
243
- \t\t\t version (1.4, 1.5, 1.6, 1.7)
244
- -p, --plugin PLUGIN\trequire 'mirah/plugin/PLUGIN' before running
245
- -v, --version\t\tPrint the version of Mirah to the console
246
- -V, --verbose\t\tVerbose logging"
247
- @state.help_printed = true
248
- end
249
-
250
- def print_version
251
- puts "Mirah v#{Mirah::VERSION}"
252
- @state.version_printed = true
253
- end
254
-
255
- def expand_files(files)
256
- expanded = []
257
- files.each do |filename|
258
- if File.directory?(filename)
259
- Dir[File.join(filename, '*')].each do |child|
260
- if File.directory?(child)
261
- files << child
262
- elsif child =~ /\.(duby|mirah)$/
263
- expanded << child
264
- end
265
- end
266
- else
267
- expanded << filename
268
- end
269
- end
270
- expanded
271
- end
272
- end
273
- end