mirah 0.0.4-java → 0.0.5-java
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +23 -0
- data/README.txt +13 -5
- data/Rakefile +30 -2
- data/bin/duby +16 -0
- data/bin/dubyc +16 -0
- data/bin/dubyp +16 -0
- data/bin/jrubyp +16 -0
- data/bin/mirah +17 -1
- data/bin/mirah.cmd +15 -0
- data/bin/mirahc +17 -1
- data/bin/mirahc.cmd +16 -1
- data/bin/mirahp +17 -1
- data/bin/mirahp.cmd +16 -1
- data/examples/appengine/Rakefile +17 -2
- data/examples/appengine/src/org/mirah/MirahApp.mirah +15 -0
- data/examples/bintrees.mirah +15 -0
- data/examples/construction.mirah +15 -0
- data/examples/dynamic.mirah +15 -0
- data/examples/edb.mirah +15 -0
- data/examples/fib.mirah +15 -0
- data/examples/fields.mirah +15 -0
- data/examples/fractal.mirah +15 -0
- data/examples/java_thing.mirah +15 -0
- data/examples/plugins/appengine/Rakefile +19 -4
- data/examples/plugins/appengine/lib/com/google/appengine/ext/duby/db/datastore.rb +21 -6
- data/examples/plugins/appengine/src/com/google/appengine/ext/duby/db/Model.duby +15 -0
- data/examples/plugins/appengine/test/com/google/appengine/ext/duby/db/ModelTest.duby +15 -0
- data/examples/simple_class.mirah +16 -1
- data/examples/sort_closure.mirah +15 -0
- data/examples/swing.mirah +17 -2
- data/examples/tak.mirah +15 -0
- data/examples/wiki/Rakefile +17 -2
- data/examples/wiki/src/org/mirah/wiki/MirahWiki.duby +15 -0
- data/examples/wiki/war/src/org/mirah/wiki/MirahWiki.duby +339 -0
- data/examples/wiki/war/src/org/mirah/wiki/edit.eduby.html +42 -0
- data/examples/wiki/war/src/org/mirah/wiki/error.eduby.html +2 -0
- data/examples/wiki/war/src/org/mirah/wiki/layout.eduby.html +69 -0
- data/examples/wiki/war/src/org/mirah/wiki/parser.eduby.html +7 -0
- data/examples/wiki/war/src/org/mirah/wiki/view.eduby.html +15 -0
- data/javalib/mirah-bootstrap.jar +0 -0
- data/javalib/mirah-parser.jar +0 -0
- data/lib/duby.rb +15 -0
- data/lib/mirah/appengine_tasks.rb +20 -6
- data/lib/mirah/ast/call.rb +19 -4
- data/lib/mirah/ast/class.rb +19 -4
- data/lib/mirah/ast/flow.rb +16 -1
- data/lib/mirah/ast/intrinsics.rb +36 -21
- data/lib/mirah/ast/literal.rb +16 -1
- data/lib/mirah/ast/local.rb +16 -1
- data/lib/mirah/ast/method.rb +18 -3
- data/lib/mirah/ast/scope.rb +19 -4
- data/lib/mirah/ast/structure.rb +16 -1
- data/lib/mirah/ast/type.rb +24 -9
- data/lib/mirah/ast.rb +24 -9
- data/lib/mirah/compiler.rb +16 -1
- data/lib/mirah/env.rb +16 -1
- data/lib/mirah/jvm/base.rb +18 -3
- data/lib/mirah/jvm/compiler.rb +35 -21
- data/lib/mirah/jvm/method_lookup.rb +16 -1
- data/lib/mirah/jvm/source_compiler.rb +29 -14
- data/lib/mirah/jvm/source_generator/builder.rb +21 -6
- data/lib/mirah/jvm/source_generator/loops.rb +16 -1
- data/lib/mirah/jvm/source_generator/precompile.rb +17 -2
- data/lib/mirah/jvm/source_generator/typer.rb +17 -2
- data/lib/mirah/jvm/typer.rb +19 -4
- data/lib/mirah/jvm/types/basic_types.rb +16 -1
- data/lib/mirah/jvm/types/boolean.rb +17 -2
- data/lib/mirah/jvm/types/enumerable.rb +21 -6
- data/lib/mirah/jvm/types/extensions.rb +16 -1
- data/lib/mirah/jvm/types/factory.rb +18 -3
- data/lib/mirah/jvm/types/floats.rb +16 -1
- data/lib/mirah/jvm/types/integers.rb +22 -7
- data/lib/mirah/jvm/types/intrinsics.rb +29 -14
- data/lib/mirah/jvm/types/literals.rb +16 -1
- data/lib/mirah/jvm/types/methods.rb +24 -9
- data/lib/mirah/jvm/types/number.rb +16 -1
- data/lib/mirah/jvm/types.rb +23 -4
- data/lib/mirah/nbcompiler.rb +19 -4
- data/lib/mirah/plugin/edb.rb +18 -3
- data/lib/mirah/plugin/gwt.rb +22 -7
- data/lib/mirah/plugin/java.rb +18 -3
- data/lib/mirah/transform.rb +35 -20
- data/lib/mirah/transform2.rb +20 -5
- data/lib/mirah/typer.rb +23 -8
- data/lib/mirah/version.rb +18 -0
- data/lib/mirah.rb +101 -50
- data/lib/mirah_task.rb +27 -12
- data/test/test_ast.rb +16 -1
- data/test/test_compilation.rb +18 -3
- data/test/test_env.rb +26 -11
- data/test/test_gwt.rb +18 -3
- data/test/test_java_typer.rb +27 -12
- data/test/test_javac_compiler.rb +17 -2
- data/test/test_jvm_compiler.rb +44 -14
- data/test/test_typer.rb +16 -1
- metadata +203 -193
data/lib/mirah/plugin/gwt.rb
CHANGED
|
@@ -1,10 +1,25 @@
|
|
|
1
|
+
# Copyright (c) 2010 The Mirah project authors. All Rights Reserved.
|
|
2
|
+
# All contributing project authors may be found in the NOTICE file.
|
|
3
|
+
#
|
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
# you may not use this file except in compliance with the License.
|
|
6
|
+
# You may obtain a copy of the License at
|
|
7
|
+
#
|
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
#
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
# See the License for the specific language governing permissions and
|
|
14
|
+
# limitations under the License.
|
|
15
|
+
|
|
1
16
|
require 'mirah/jvm/source_generator/builder'
|
|
2
17
|
|
|
3
|
-
module
|
|
18
|
+
module Mirah::JavaSource
|
|
4
19
|
class ClassBuilder
|
|
5
20
|
def build_jsni_method(name, visibility, static, exceptions, type, *args)
|
|
6
21
|
finish_declaration
|
|
7
|
-
type ||=
|
|
22
|
+
type ||= Mirah::AST.type(nil, :void)
|
|
8
23
|
@methods << JsniMethodBuilder.new(self,
|
|
9
24
|
:name => name,
|
|
10
25
|
:visibility => visibility,
|
|
@@ -50,11 +65,11 @@ module Duby::JavaSource
|
|
|
50
65
|
end
|
|
51
66
|
end
|
|
52
67
|
|
|
53
|
-
module
|
|
68
|
+
module Mirah::Compiler
|
|
54
69
|
class JVMCompilerBase
|
|
55
70
|
# arg_types must be an Array
|
|
56
71
|
def create_method_builder(name, node, static, exceptions, return_type, arg_types)
|
|
57
|
-
unless node.class ==
|
|
72
|
+
unless node.class == Mirah::AST::JsniMethodDefinition
|
|
58
73
|
@class.build_method(name.to_s, node.visibility, static,
|
|
59
74
|
exceptions, return_type, *arg_types)
|
|
60
75
|
else
|
|
@@ -81,7 +96,7 @@ module Duby::Compiler
|
|
|
81
96
|
end
|
|
82
97
|
end
|
|
83
98
|
|
|
84
|
-
module
|
|
99
|
+
module Mirah::AST
|
|
85
100
|
class JsniMethodDefinition < MethodDefinition
|
|
86
101
|
def initialize(static, parent, line_number, name, annotations=[], &block)
|
|
87
102
|
super(parent, line_number, name, annotations, &block)
|
|
@@ -138,7 +153,7 @@ module Duby::AST
|
|
|
138
153
|
call_node.name,
|
|
139
154
|
transformer.annotations) do |defn|
|
|
140
155
|
|
|
141
|
-
signature = {:return =>
|
|
156
|
+
signature = {:return => Mirah::AST.type(nil, args[0].name)}
|
|
142
157
|
method = call_node.parameters[0]
|
|
143
158
|
|
|
144
159
|
unless method.nil?
|
|
@@ -149,7 +164,7 @@ module Duby::AST
|
|
|
149
164
|
hash_node.child_nodes.each_slice(2) do |name, type|
|
|
150
165
|
position = name.position + type.position
|
|
151
166
|
name = name.literal
|
|
152
|
-
type =
|
|
167
|
+
type = Mirah::AST.type(nil, type.name)
|
|
153
168
|
signature[name.intern] = type
|
|
154
169
|
arg_list.push(RequiredArgument.new(args_new, position, name))
|
|
155
170
|
end
|
data/lib/mirah/plugin/java.rb
CHANGED
|
@@ -1,13 +1,28 @@
|
|
|
1
|
+
# Copyright (c) 2010 The Mirah project authors. All Rights Reserved.
|
|
2
|
+
# All contributing project authors may be found in the NOTICE file.
|
|
3
|
+
#
|
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
# you may not use this file except in compliance with the License.
|
|
6
|
+
# You may obtain a copy of the License at
|
|
7
|
+
#
|
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
#
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
# See the License for the specific language governing permissions and
|
|
14
|
+
# limitations under the License.
|
|
15
|
+
|
|
1
16
|
require 'mirah/typer'
|
|
2
17
|
require 'mirah/jvm/method_lookup'
|
|
3
18
|
require 'mirah/jvm/types'
|
|
4
19
|
require 'java'
|
|
5
20
|
|
|
6
|
-
module
|
|
21
|
+
module Mirah
|
|
7
22
|
module Typer
|
|
8
23
|
class JavaTyper < BaseTyper
|
|
9
|
-
include
|
|
10
|
-
include
|
|
24
|
+
include Mirah::JVM::MethodLookup
|
|
25
|
+
include Mirah::JVM::Types
|
|
11
26
|
|
|
12
27
|
def initialize
|
|
13
28
|
end
|
data/lib/mirah/transform.rb
CHANGED
|
@@ -1,7 +1,22 @@
|
|
|
1
|
+
# Copyright (c) 2010 The Mirah project authors. All Rights Reserved.
|
|
2
|
+
# All contributing project authors may be found in the NOTICE file.
|
|
3
|
+
#
|
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
# you may not use this file except in compliance with the License.
|
|
6
|
+
# You may obtain a copy of the License at
|
|
7
|
+
#
|
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
#
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
# See the License for the specific language governing permissions and
|
|
14
|
+
# limitations under the License.
|
|
15
|
+
|
|
1
16
|
require 'base64'
|
|
2
17
|
require 'jruby'
|
|
3
18
|
|
|
4
|
-
module
|
|
19
|
+
module Mirah
|
|
5
20
|
module Transform
|
|
6
21
|
class Error < StandardError
|
|
7
22
|
attr_reader :position, :cause
|
|
@@ -30,7 +45,7 @@ module Duby
|
|
|
30
45
|
@scopes = []
|
|
31
46
|
@extra_body = nil
|
|
32
47
|
@state = state
|
|
33
|
-
@helper =
|
|
48
|
+
@helper = Mirah::AST::TransformHelper.new(self)
|
|
34
49
|
end
|
|
35
50
|
|
|
36
51
|
def destination
|
|
@@ -48,7 +63,7 @@ module Duby
|
|
|
48
63
|
|
|
49
64
|
def add_annotation(annotation)
|
|
50
65
|
@annotations << annotation
|
|
51
|
-
|
|
66
|
+
Mirah::AST::Noop.new(annotation.parent, annotation.position)
|
|
52
67
|
end
|
|
53
68
|
|
|
54
69
|
def tmp(format="__xform_tmp_%d")
|
|
@@ -88,13 +103,13 @@ module Duby
|
|
|
88
103
|
begin
|
|
89
104
|
top = @extra_body.nil?
|
|
90
105
|
if top
|
|
91
|
-
@extra_body =
|
|
106
|
+
@extra_body = Mirah::AST::Body.new(nil, position(node))
|
|
92
107
|
end
|
|
93
108
|
method = "transform_#{camelize(node[0])}"
|
|
94
109
|
result = @helper.send method, node, parent
|
|
95
110
|
if top
|
|
96
111
|
body = result.body
|
|
97
|
-
if body.kind_of?(
|
|
112
|
+
if body.kind_of?(Mirah::AST::Body) && @extra_body.empty?
|
|
98
113
|
@extra_body = body
|
|
99
114
|
else
|
|
100
115
|
result.body = @extra_body
|
|
@@ -105,11 +120,11 @@ module Duby
|
|
|
105
120
|
return result
|
|
106
121
|
rescue Error => ex
|
|
107
122
|
@errors << ex
|
|
108
|
-
|
|
123
|
+
Mirah::AST::ErrorNode.new(parent, ex)
|
|
109
124
|
rescue Exception => ex
|
|
110
125
|
error = Error.new(ex.message, position(node), ex)
|
|
111
126
|
@errors << error
|
|
112
|
-
|
|
127
|
+
Mirah::AST::ErrorNode.new(parent, error)
|
|
113
128
|
end
|
|
114
129
|
end
|
|
115
130
|
|
|
@@ -124,7 +139,7 @@ module Duby
|
|
|
124
139
|
end
|
|
125
140
|
|
|
126
141
|
def eval(src, filename='-', parent=nil, *vars)
|
|
127
|
-
node =
|
|
142
|
+
node = Mirah::AST.parse_ruby(src, filename)
|
|
128
143
|
duby_node = transform(node, nil).body
|
|
129
144
|
duby_node.parent = parent
|
|
130
145
|
duby_node
|
|
@@ -132,11 +147,11 @@ module Duby
|
|
|
132
147
|
|
|
133
148
|
def dump_ast(node)
|
|
134
149
|
encoded = nil
|
|
135
|
-
values =
|
|
150
|
+
values = Mirah::AST::Unquote.extract_values do
|
|
136
151
|
encoded = Base64.encode64(Marshal.dump(node))
|
|
137
152
|
end
|
|
138
|
-
result =
|
|
139
|
-
result <<
|
|
153
|
+
result = Mirah::AST::Array.new(nil, node.position)
|
|
154
|
+
result << Mirah::AST::String.new(result, node.position, encoded)
|
|
140
155
|
values.each {|value| result << value}
|
|
141
156
|
return result
|
|
142
157
|
end
|
|
@@ -144,9 +159,9 @@ module Duby
|
|
|
144
159
|
def load_ast(args)
|
|
145
160
|
nodes = args.to_a
|
|
146
161
|
encoded = nodes.shift
|
|
147
|
-
|
|
162
|
+
Mirah::AST::Unquote.inject_values(nodes) do
|
|
148
163
|
result = Marshal.load(Base64.decode64(encoded))
|
|
149
|
-
if
|
|
164
|
+
if Mirah::AST::UnquotedValue === result
|
|
150
165
|
result.node
|
|
151
166
|
else
|
|
152
167
|
result
|
|
@@ -155,7 +170,7 @@ module Duby
|
|
|
155
170
|
end
|
|
156
171
|
|
|
157
172
|
def __ruby_eval(code, arg)
|
|
158
|
-
|
|
173
|
+
self.instance_eval(code)
|
|
159
174
|
end
|
|
160
175
|
|
|
161
176
|
def fixnum(value)
|
|
@@ -188,7 +203,7 @@ module Duby
|
|
|
188
203
|
end
|
|
189
204
|
|
|
190
205
|
def define_class(position, name, &block)
|
|
191
|
-
append_node
|
|
206
|
+
append_node Mirah::AST::ClassDefinition.new(@extra_body, position, name, &block)
|
|
192
207
|
end
|
|
193
208
|
|
|
194
209
|
def define_closure(position, name, enclosing_type)
|
|
@@ -198,7 +213,7 @@ module Duby
|
|
|
198
213
|
if enclosing_type.respond_to?(:node) && enclosing_type.node
|
|
199
214
|
parent = target = enclosing_type.node
|
|
200
215
|
end
|
|
201
|
-
target.append_node(
|
|
216
|
+
target.append_node(Mirah::AST::ClosureDefinition.new(
|
|
202
217
|
parent, position, name, enclosing_type))
|
|
203
218
|
end
|
|
204
219
|
end
|
|
@@ -221,9 +236,9 @@ module Duby
|
|
|
221
236
|
messages.each_with_index do |message, i|
|
|
222
237
|
jpos = positions[i]
|
|
223
238
|
if jpos
|
|
224
|
-
dpos =
|
|
239
|
+
dpos = Mirah::Transform::Transformer::JMetaPosition.new(jpos, jpos)
|
|
225
240
|
print "#{message} at "
|
|
226
|
-
|
|
241
|
+
Mirah.print_error("", dpos)
|
|
227
242
|
else
|
|
228
243
|
print message
|
|
229
244
|
end
|
|
@@ -233,7 +248,7 @@ module Duby
|
|
|
233
248
|
|
|
234
249
|
def parse(src, filename='dash_e', raise_errors=false, transformer=nil)
|
|
235
250
|
ast = parse_ruby(src, filename)
|
|
236
|
-
transformer ||= Transform::Transformer.new(
|
|
251
|
+
transformer ||= Transform::Transformer.new(Mirah::CompilationState.new)
|
|
237
252
|
transformer.filename = filename
|
|
238
253
|
ast = transformer.transform(ast, nil)
|
|
239
254
|
if raise_errors
|
|
@@ -255,7 +270,7 @@ module Duby
|
|
|
255
270
|
rescue => ex
|
|
256
271
|
if ex.cause.respond_to? :position
|
|
257
272
|
position = ex.cause.position
|
|
258
|
-
|
|
273
|
+
Mirah.print_error(ex.cause.message, position)
|
|
259
274
|
end
|
|
260
275
|
raise ex
|
|
261
276
|
end
|
data/lib/mirah/transform2.rb
CHANGED
|
@@ -1,4 +1,19 @@
|
|
|
1
|
-
|
|
1
|
+
# Copyright (c) 2010 The Mirah project authors. All Rights Reserved.
|
|
2
|
+
# All contributing project authors may be found in the NOTICE file.
|
|
3
|
+
#
|
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
# you may not use this file except in compliance with the License.
|
|
6
|
+
# You may obtain a copy of the License at
|
|
7
|
+
#
|
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
#
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
# See the License for the specific language governing permissions and
|
|
14
|
+
# limitations under the License.
|
|
15
|
+
|
|
16
|
+
module Mirah::AST
|
|
2
17
|
class TransformHelper
|
|
3
18
|
java_import 'jmeta.Ast'
|
|
4
19
|
def initialize(transformer)
|
|
@@ -25,11 +40,11 @@ module Duby::AST
|
|
|
25
40
|
end
|
|
26
41
|
|
|
27
42
|
def transform_fixnum(node, parent)
|
|
28
|
-
|
|
43
|
+
Mirah::AST::fixnum(parent, position(node), node[1])
|
|
29
44
|
end
|
|
30
45
|
|
|
31
46
|
def transform_float(node, parent)
|
|
32
|
-
|
|
47
|
+
Mirah::AST::float(parent, position(node), node[1])
|
|
33
48
|
end
|
|
34
49
|
|
|
35
50
|
def transform_true(node, parent)
|
|
@@ -257,7 +272,7 @@ module Duby::AST
|
|
|
257
272
|
iter_node ? transformer.transform(iter_node, call) : nil
|
|
258
273
|
]
|
|
259
274
|
end
|
|
260
|
-
macro =
|
|
275
|
+
macro = Mirah::AST.macro(name)
|
|
261
276
|
if macro
|
|
262
277
|
transformer.expand(fcall, parent, ¯o)
|
|
263
278
|
else
|
|
@@ -334,7 +349,7 @@ module Duby::AST
|
|
|
334
349
|
elsif ['public', 'private', 'protected'].include?(name)
|
|
335
350
|
AccessLevel.new(parent, position, name)
|
|
336
351
|
else
|
|
337
|
-
macro =
|
|
352
|
+
macro = Mirah::AST.macro(name)
|
|
338
353
|
fcall = FunctionalCall.new(parent, position, name) do |call|
|
|
339
354
|
[
|
|
340
355
|
[],
|
data/lib/mirah/typer.rb
CHANGED
|
@@ -1,7 +1,22 @@
|
|
|
1
|
+
# Copyright (c) 2010 The Mirah project authors. All Rights Reserved.
|
|
2
|
+
# All contributing project authors may be found in the NOTICE file.
|
|
3
|
+
#
|
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
# you may not use this file except in compliance with the License.
|
|
6
|
+
# You may obtain a copy of the License at
|
|
7
|
+
#
|
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
#
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
# See the License for the specific language governing permissions and
|
|
14
|
+
# limitations under the License.
|
|
15
|
+
|
|
1
16
|
require 'mirah/ast'
|
|
2
17
|
require 'mirah/transform'
|
|
3
18
|
|
|
4
|
-
module
|
|
19
|
+
module Mirah
|
|
5
20
|
module Typer
|
|
6
21
|
class << self
|
|
7
22
|
attr_accessor :verbose
|
|
@@ -20,7 +35,7 @@ module Duby
|
|
|
20
35
|
end
|
|
21
36
|
|
|
22
37
|
class BaseTyper
|
|
23
|
-
include
|
|
38
|
+
include Mirah
|
|
24
39
|
|
|
25
40
|
def log(message); Typer.log(message); end
|
|
26
41
|
|
|
@@ -219,7 +234,7 @@ module Duby
|
|
|
219
234
|
|
|
220
235
|
def plugins
|
|
221
236
|
if cycling?
|
|
222
|
-
|
|
237
|
+
Mirah.typer_plugins.each do |plugin|
|
|
223
238
|
log "Invoking plugin: #{plugin}"
|
|
224
239
|
|
|
225
240
|
result = yield plugin
|
|
@@ -391,14 +406,14 @@ module Duby
|
|
|
391
406
|
end
|
|
392
407
|
|
|
393
408
|
if __FILE__ == $0
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
ast =
|
|
397
|
-
typer =
|
|
409
|
+
Mirah::AST.verbose = true
|
|
410
|
+
Mirah::Typer.verbose = true
|
|
411
|
+
ast = Mirah::AST.parse(File.read(ARGV[0]))
|
|
412
|
+
typer = Mirah::Typer::Simple.new("script")
|
|
398
413
|
typer.infer(ast)
|
|
399
414
|
begin
|
|
400
415
|
typer.resolve(true)
|
|
401
|
-
rescue
|
|
416
|
+
rescue Mirah::Typer::InferenceError => e
|
|
402
417
|
puts e.message
|
|
403
418
|
end
|
|
404
419
|
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# Copyright (c) 2010 The Mirah project authors. All Rights Reserved.
|
|
2
|
+
# All contributing project authors may be found in the NOTICE file.
|
|
3
|
+
#
|
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
# you may not use this file except in compliance with the License.
|
|
6
|
+
# You may obtain a copy of the License at
|
|
7
|
+
#
|
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
#
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
# See the License for the specific language governing permissions and
|
|
14
|
+
# limitations under the License.
|
|
15
|
+
|
|
16
|
+
module Mirah
|
|
17
|
+
VERSION = "0.0.5"
|
|
18
|
+
end
|
data/lib/mirah.rb
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
|
+
# Copyright (c) 2010 The Mirah project authors. All Rights Reserved.
|
|
2
|
+
# All contributing project authors may be found in the NOTICE file.
|
|
3
|
+
#
|
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
# you may not use this file except in compliance with the License.
|
|
6
|
+
# You may obtain a copy of the License at
|
|
7
|
+
#
|
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
#
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
# See the License for the specific language governing permissions and
|
|
14
|
+
# limitations under the License.
|
|
15
|
+
|
|
1
16
|
require 'fileutils'
|
|
2
17
|
require 'rbconfig'
|
|
18
|
+
require 'mirah/version'
|
|
3
19
|
require 'mirah/transform'
|
|
4
20
|
require 'mirah/ast'
|
|
5
21
|
require 'mirah/typer'
|
|
@@ -16,17 +32,17 @@ require 'mirah/jvm/typer'
|
|
|
16
32
|
Dir[File.dirname(__FILE__) + "/mirah/plugin/*"].each {|file| require "#{file}" if file =~ /\.rb$/}
|
|
17
33
|
require 'jruby'
|
|
18
34
|
|
|
19
|
-
module
|
|
35
|
+
module Mirah
|
|
20
36
|
def self.run(*args)
|
|
21
|
-
|
|
37
|
+
MirahImpl.new.run(*args)
|
|
22
38
|
end
|
|
23
39
|
|
|
24
40
|
def self.compile(*args)
|
|
25
|
-
|
|
41
|
+
MirahImpl.new.compile(*args)
|
|
26
42
|
end
|
|
27
43
|
|
|
28
44
|
def self.parse(*args)
|
|
29
|
-
|
|
45
|
+
MirahImpl.new.parse(*args)
|
|
30
46
|
end
|
|
31
47
|
|
|
32
48
|
def self.plugins
|
|
@@ -66,14 +82,34 @@ module Duby
|
|
|
66
82
|
end
|
|
67
83
|
|
|
68
84
|
class CompilationState
|
|
85
|
+
def initialize
|
|
86
|
+
BiteScript.bytecode_version = BiteScript::JAVA1_5
|
|
87
|
+
end
|
|
88
|
+
|
|
69
89
|
attr_accessor :verbose, :destination
|
|
90
|
+
attr_accessor :version_printed
|
|
91
|
+
|
|
92
|
+
def set_jvm_version(ver_str)
|
|
93
|
+
case ver_str
|
|
94
|
+
when '1.4'
|
|
95
|
+
BiteScript.bytecode_version = BiteScript::JAVA1_4
|
|
96
|
+
when '1.5'
|
|
97
|
+
BiteScript.bytecode_version = BiteScript::JAVA1_5
|
|
98
|
+
when '1.6'
|
|
99
|
+
BiteScript.bytecode_version = BiteScript::JAVA1_6
|
|
100
|
+
when '1.7'
|
|
101
|
+
BiteScript.bytecode_version = BiteScript::JAVA1_7
|
|
102
|
+
else
|
|
103
|
+
$stderr.puts "invalid bytecode version specified: #{ver_str}"
|
|
104
|
+
end
|
|
105
|
+
end
|
|
70
106
|
end
|
|
71
107
|
end
|
|
72
108
|
|
|
73
109
|
# This is a custom classloader impl to allow loading classes with
|
|
74
110
|
# interdependencies by having findClass retrieve classes as needed from the
|
|
75
111
|
# collection of all classes generated by the target script.
|
|
76
|
-
class
|
|
112
|
+
class MirahClassLoader < java::security::SecureClassLoader
|
|
77
113
|
def initialize(parent, class_map)
|
|
78
114
|
super(parent)
|
|
79
115
|
@class_map = class_map
|
|
@@ -104,9 +140,9 @@ class DubyClassLoader < java::security::SecureClassLoader
|
|
|
104
140
|
end
|
|
105
141
|
end
|
|
106
142
|
|
|
107
|
-
class
|
|
143
|
+
class MirahImpl
|
|
108
144
|
def initialize
|
|
109
|
-
|
|
145
|
+
Mirah::AST.type_factory = Mirah::JVM::Types::TypeFactory.new
|
|
110
146
|
end
|
|
111
147
|
|
|
112
148
|
def run(*args)
|
|
@@ -121,7 +157,7 @@ class DubyImpl
|
|
|
121
157
|
end
|
|
122
158
|
|
|
123
159
|
# load all classes
|
|
124
|
-
dcl =
|
|
160
|
+
dcl = MirahClassLoader.new(JRuby.runtime.jruby_class_loader, class_map)
|
|
125
161
|
class_map.each do |name,|
|
|
126
162
|
cls = dcl.load_class(name)
|
|
127
163
|
# TODO: using first main; find correct one
|
|
@@ -137,7 +173,7 @@ class DubyImpl
|
|
|
137
173
|
raise e
|
|
138
174
|
end
|
|
139
175
|
else
|
|
140
|
-
puts "No main found"
|
|
176
|
+
puts "No main found" unless @state.version_printed
|
|
141
177
|
end
|
|
142
178
|
end
|
|
143
179
|
|
|
@@ -193,17 +229,17 @@ class DubyImpl
|
|
|
193
229
|
exit(1)
|
|
194
230
|
end
|
|
195
231
|
begin
|
|
196
|
-
ast =
|
|
232
|
+
ast = Mirah::AST.parse_ruby(src, @filename)
|
|
197
233
|
# rescue org.jrubyparser.lexer.SyntaxException => ex
|
|
198
|
-
#
|
|
234
|
+
# Mirah.print_error(ex.message, ex.position)
|
|
199
235
|
# raise ex if @state.verbose
|
|
200
236
|
end
|
|
201
|
-
@transformer =
|
|
237
|
+
@transformer = Mirah::Transform::Transformer.new(@state)
|
|
202
238
|
Java::MirahImpl::Builtin.initialize_builtins(@transformer)
|
|
203
239
|
@transformer.filename = @filename
|
|
204
240
|
ast = @transformer.transform(ast, nil)
|
|
205
241
|
@transformer.errors.each do |ex|
|
|
206
|
-
|
|
242
|
+
Mirah.print_error(ex.message, ex.position)
|
|
207
243
|
raise ex.cause || ex if @state.verbose
|
|
208
244
|
end
|
|
209
245
|
@error = @transformer.errors.size > 0
|
|
@@ -212,7 +248,7 @@ class DubyImpl
|
|
|
212
248
|
end
|
|
213
249
|
|
|
214
250
|
def infer_asts(asts)
|
|
215
|
-
typer =
|
|
251
|
+
typer = Mirah::Typer::JVM.new(@transformer)
|
|
216
252
|
asts.each {|ast| typer.infer(ast) }
|
|
217
253
|
begin
|
|
218
254
|
typer.resolve(false)
|
|
@@ -224,7 +260,7 @@ class DubyImpl
|
|
|
224
260
|
puts "Inference Error:"
|
|
225
261
|
typer.errors.each do |ex|
|
|
226
262
|
if ex.node
|
|
227
|
-
|
|
263
|
+
Mirah.print_error(ex.message, ex.node.position)
|
|
228
264
|
else
|
|
229
265
|
puts ex.message
|
|
230
266
|
end
|
|
@@ -242,7 +278,7 @@ class DubyImpl
|
|
|
242
278
|
compiler.generate(&block)
|
|
243
279
|
rescue Exception => ex
|
|
244
280
|
if ex.respond_to? :node
|
|
245
|
-
|
|
281
|
+
Mirah.print_error(ex.message, ex.node.position)
|
|
246
282
|
puts ex.backtrace if @state.verbose
|
|
247
283
|
exit 1
|
|
248
284
|
else
|
|
@@ -253,43 +289,49 @@ class DubyImpl
|
|
|
253
289
|
end
|
|
254
290
|
|
|
255
291
|
def process_flags!(args)
|
|
256
|
-
@state ||=
|
|
292
|
+
@state ||= Mirah::CompilationState.new
|
|
257
293
|
while args.length > 0 && args[0] =~ /^-/
|
|
258
294
|
case args[0]
|
|
259
|
-
when '--
|
|
260
|
-
Duby::Typer.verbose = true
|
|
261
|
-
Duby::AST.verbose = true
|
|
262
|
-
Duby::Compiler::JVM.verbose = true
|
|
263
|
-
@state.verbose = true
|
|
295
|
+
when '--classpath', '-c'
|
|
264
296
|
args.shift
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
@compiler_class = Duby::Compiler::JavaSource
|
|
297
|
+
Mirah::Env.decode_paths(args.shift, $CLASSPATH)
|
|
298
|
+
when '--cd'
|
|
268
299
|
args.shift
|
|
300
|
+
Dir.chdir(args.shift)
|
|
269
301
|
when '--dest', '-d'
|
|
270
302
|
args.shift
|
|
271
303
|
@state.destination = File.join(File.expand_path(args.shift), '')
|
|
272
|
-
when '
|
|
304
|
+
when '-e'
|
|
305
|
+
break
|
|
306
|
+
when '--explicit-packages'
|
|
273
307
|
args.shift
|
|
274
|
-
|
|
275
|
-
when '--
|
|
308
|
+
Mirah::AST::Script.explicit_packages = true
|
|
309
|
+
when '--help', '-h'
|
|
310
|
+
print_help
|
|
311
|
+
exit(0)
|
|
312
|
+
when '--java', '-j'
|
|
313
|
+
require 'mirah/jvm/source_compiler'
|
|
314
|
+
@compiler_class = Mirah::Compiler::JavaSource
|
|
276
315
|
args.shift
|
|
277
|
-
|
|
278
|
-
|
|
316
|
+
when '--jvm'
|
|
317
|
+
args.shift
|
|
318
|
+
@state.set_jvm_version(args.shift)
|
|
279
319
|
when '-I'
|
|
280
320
|
args.shift
|
|
281
321
|
$: << args.shift
|
|
282
|
-
when '--
|
|
322
|
+
when '--plugin', '-p'
|
|
283
323
|
args.shift
|
|
284
|
-
|
|
285
|
-
|
|
324
|
+
plugin = args.shift
|
|
325
|
+
require "mirah/plugin/#{plugin}"
|
|
326
|
+
when '--verbose', '-V'
|
|
327
|
+
Mirah::Typer.verbose = true
|
|
328
|
+
Mirah::AST.verbose = true
|
|
329
|
+
Mirah::Compiler::JVM.verbose = true
|
|
330
|
+
@state.verbose = true
|
|
286
331
|
args.shift
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
exit(0)
|
|
291
|
-
when '-e'
|
|
292
|
-
break
|
|
332
|
+
when '--version', '-v'
|
|
333
|
+
args.shift
|
|
334
|
+
print_version
|
|
293
335
|
else
|
|
294
336
|
puts "unrecognized flag: " + args[0]
|
|
295
337
|
print_help
|
|
@@ -297,19 +339,30 @@ class DubyImpl
|
|
|
297
339
|
end
|
|
298
340
|
end
|
|
299
341
|
@state.destination ||= File.join(File.expand_path('.'), '')
|
|
300
|
-
@compiler_class ||=
|
|
342
|
+
@compiler_class ||= Mirah::Compiler::JVM
|
|
301
343
|
end
|
|
302
344
|
|
|
303
345
|
def print_help
|
|
304
|
-
|
|
305
|
-
-V, --verbose\t\tVerbose logging
|
|
306
|
-
-j, --java\t\tOutput .java source (jrubyc only)
|
|
307
|
-
-d, --dir DIR\t\tUse DIR as the base dir for compilation, packages
|
|
308
|
-
-p, --plugin PLUGIN\tLoad and use plugin during compilation
|
|
346
|
+
puts "#{$0} [flags] <files or \"-e SCRIPT\">
|
|
309
347
|
-c, --classpath PATH\tAdd PATH to the Java classpath for compilation
|
|
310
|
-
--
|
|
348
|
+
--cd DIR\t\tSwitch to the specified DIR befor compilation
|
|
349
|
+
-d, --dir DIR\t\tUse DIR as the base dir for compilation, packages
|
|
350
|
+
-e CODE\t\tCompile or run the inline script following -e
|
|
351
|
+
\t\t\t (the class will be named \"DashE\")
|
|
352
|
+
--explicit-packages\tRequire explicit 'package' lines in source
|
|
311
353
|
-h, --help\t\tPrint this help message
|
|
312
|
-
-
|
|
354
|
+
-I DIR\t\tAdd DIR to the Ruby load path before running
|
|
355
|
+
-j, --java\t\tOutput .java source (jrubyc only)
|
|
356
|
+
--jvm VERSION\t\tEmit JVM bytecode targeting specified JVM
|
|
357
|
+
\t\t\t version (1.4, 1.5, 1.6, 1.7)
|
|
358
|
+
-p, --plugin PLUGIN\trequire 'mirah/plugin/PLUGIN' before running
|
|
359
|
+
-v, --version\t\tPrint the version of Mirah to the console
|
|
360
|
+
-V, --verbose\t\tVerbose logging"
|
|
361
|
+
end
|
|
362
|
+
|
|
363
|
+
def print_version
|
|
364
|
+
puts "Mirah v#{Mirah::VERSION}"
|
|
365
|
+
@state.version_printed = true
|
|
313
366
|
end
|
|
314
367
|
|
|
315
368
|
def expand_files(files)
|
|
@@ -331,8 +384,6 @@ class DubyImpl
|
|
|
331
384
|
end
|
|
332
385
|
end
|
|
333
386
|
|
|
334
|
-
Mirah = Duby
|
|
335
|
-
|
|
336
387
|
if __FILE__ == $0
|
|
337
|
-
|
|
388
|
+
Mirah.run(ARGV[0], *ARGV[1..-1])
|
|
338
389
|
end
|