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.
- data/History.txt +181 -0
- data/README.txt +6 -10
- data/Rakefile +86 -9
- data/bin/mirah +2 -0
- data/bin/mirahc +2 -0
- data/bin/mirahp +2 -0
- data/{bin/dubyp → examples/interfaces.mirah} +16 -9
- data/examples/macros/square.mirah +12 -0
- data/examples/macros/square_int.mirah +12 -0
- data/examples/macros/string-each-char.mirah +14 -0
- data/examples/maven/README.txt +2 -0
- data/examples/maven/pom.xml +23 -0
- data/examples/maven/src/main/mirah/hello_mirah.mirah +9 -0
- data/examples/rosettacode/100-doors.mirah +44 -0
- data/examples/rosettacode/99-bottles-of-beer.mirah +13 -0
- data/examples/rosettacode/README.txt +9 -0
- data/examples/rosettacode/boolean-values.mirah +29 -0
- data/examples/rosettacode/comments.mirah +2 -0
- data/examples/rosettacode/copy-a-string.mirah +10 -0
- data/examples/rosettacode/count-occurrences-of-a-substring.mirah +40 -0
- data/examples/rosettacode/create-a-file.mirah +6 -0
- data/examples/rosettacode/empty-string.mirah +9 -0
- data/examples/rosettacode/factorial.mirah +10 -0
- data/examples/rosettacode/fibonacci.mirah +21 -0
- data/examples/rosettacode/file-size.mirah +5 -0
- data/examples/rosettacode/fizz-buzz.mirah +21 -0
- data/examples/rosettacode/flatten-a-list.mirah +24 -0
- data/examples/rosettacode/guess-the-number.mirah +21 -0
- data/examples/rosettacode/is-string-numeric.mirah +127 -0
- data/examples/rosettacode/palindrome.mirah +14 -0
- data/examples/rosettacode/repeat-a-string.mirah +9 -0
- data/examples/rosettacode/reverse-a-string.mirah +6 -0
- data/examples/rosettacode/rot-13.mirah +20 -0
- data/examples/rosettacode/user-input.mirah +4 -0
- data/examples/sort_closure.mirah +1 -1
- data/javalib/dynalink-0.2.jar +0 -0
- data/javalib/mirah-bootstrap.jar +0 -0
- data/lib/mirah.rb +7 -16
- data/lib/mirah/ast.rb +22 -92
- data/lib/mirah/ast/call.rb +41 -9
- data/lib/mirah/ast/class.rb +34 -6
- data/lib/mirah/ast/flow.rb +17 -5
- data/lib/mirah/ast/intrinsics.rb +50 -8
- data/lib/mirah/ast/literal.rb +7 -0
- data/lib/mirah/ast/local.rb +9 -1
- data/lib/mirah/ast/method.rb +21 -8
- data/lib/mirah/ast/scope.rb +1 -1
- data/lib/mirah/ast/structure.rb +81 -15
- data/lib/mirah/ast/type.rb +4 -0
- data/{bin/dubyc → lib/mirah/commands.rb} +4 -11
- data/lib/mirah/commands/base.rb +54 -0
- data/lib/mirah/commands/compile.rb +39 -0
- data/{examples/wiki/Rakefile → lib/mirah/commands/parse.rb} +18 -17
- data/lib/mirah/commands/run.rb +73 -0
- data/lib/mirah/compiler.rb +37 -417
- data/lib/mirah/compiler/call.rb +45 -0
- data/lib/mirah/compiler/class.rb +81 -0
- data/lib/mirah/compiler/flow.rb +109 -0
- data/lib/mirah/compiler/literal.rb +130 -0
- data/lib/mirah/compiler/local.rb +59 -0
- data/lib/mirah/compiler/method.rb +44 -0
- data/lib/mirah/compiler/structure.rb +65 -0
- data/lib/mirah/compiler/type.rb +27 -0
- data/lib/mirah/env.rb +4 -6
- data/lib/mirah/generator.rb +61 -0
- data/lib/mirah/jvm/compiler.rb +8 -867
- data/lib/mirah/jvm/compiler/base.rb +270 -0
- data/lib/mirah/jvm/compiler/java_source.rb +779 -0
- data/lib/mirah/jvm/compiler/jvm_bytecode.rb +851 -0
- data/lib/mirah/jvm/method_lookup.rb +21 -2
- data/lib/mirah/jvm/source_generator/builder.rb +10 -13
- data/lib/mirah/jvm/source_generator/loops.rb +99 -93
- data/lib/mirah/jvm/source_generator/precompile.rb +3 -2
- data/lib/mirah/jvm/typer.rb +3 -3
- data/lib/mirah/jvm/types.rb +10 -426
- data/lib/mirah/jvm/types/array_type.rb +62 -0
- data/lib/mirah/jvm/types/basic_types.rb +1 -0
- data/lib/mirah/jvm/types/dynamic_type.rb +46 -0
- data/lib/mirah/jvm/types/factory.rb +23 -5
- data/lib/mirah/jvm/types/interface_definition.rb +20 -0
- data/lib/mirah/jvm/types/intrinsics.rb +15 -3
- data/lib/mirah/jvm/types/meta_type.rb +45 -0
- data/lib/mirah/jvm/types/methods.rb +12 -5
- data/lib/mirah/jvm/types/null_type.rb +27 -0
- data/lib/mirah/jvm/types/primitive_type.rb +38 -0
- data/lib/mirah/jvm/types/source_mirror.rb +266 -0
- data/lib/mirah/jvm/types/type.rb +173 -0
- data/lib/mirah/jvm/types/type_definition.rb +55 -0
- data/lib/mirah/jvm/types/unreachable_type.rb +27 -0
- data/lib/mirah/jvm/types/void_type.rb +19 -0
- data/lib/mirah/parser.rb +90 -0
- data/lib/mirah/plugin/gwt.rb +5 -5
- data/lib/mirah/plugin/java.rb +1 -1
- data/lib/mirah/transform.rb +4 -321
- data/lib/mirah/transform/ast_ext.rb +63 -0
- data/lib/mirah/transform/error.rb +13 -0
- data/lib/mirah/transform/helper.rb +761 -0
- data/lib/mirah/transform/transformer.rb +255 -0
- data/lib/mirah/typer.rb +2 -383
- data/{bin/duby → lib/mirah/typer/base.rb} +12 -10
- data/lib/mirah/typer/simple.rb +377 -0
- data/lib/mirah/util/argument_processor.rb +114 -0
- data/lib/mirah/util/class_loader.rb +37 -0
- data/lib/mirah/util/compilation_state.rb +51 -0
- data/lib/mirah/util/process_errors.rb +33 -0
- data/lib/mirah/version.rb +1 -1
- data/lib/mirah_task.rb +3 -2
- data/test/{test_ast.rb → core/test_ast.rb} +6 -0
- data/test/{test_compilation.rb → core/test_compilation.rb} +0 -0
- data/test/{test_env.rb → core/test_env.rb} +24 -25
- data/test/{test_macros.rb → core/test_macros.rb} +2 -4
- data/test/{test_typer.rb → core/test_typer.rb} +0 -3
- data/test/jvm/bytecode_test_helper.rb +181 -0
- data/test/{test_javac_compiler.rb → jvm/javac_test_helper.rb} +38 -22
- data/test/jvm/test_enumerable.rb +304 -0
- data/test/{test_java_typer.rb → jvm/test_java_typer.rb} +2 -4
- data/test/{test_jvm_compiler.rb → jvm/test_jvm_compiler.rb} +146 -443
- data/test/jvm/test_macros.rb +147 -0
- data/test/jvm/test_main_method.rb +15 -0
- data/test/{test_gwt.rb → plugins/test_gwt.rb} +0 -2
- metadata +103 -91
- data/bin/jrubyp +0 -52
- data/examples/wiki/src/org/mirah/wiki/MirahWiki.duby +0 -339
- data/examples/wiki/src/org/mirah/wiki/edit.eduby.html +0 -42
- data/examples/wiki/src/org/mirah/wiki/error.eduby.html +0 -2
- data/examples/wiki/src/org/mirah/wiki/layout.eduby.html +0 -69
- data/examples/wiki/src/org/mirah/wiki/parser.eduby.html +0 -7
- data/examples/wiki/src/org/mirah/wiki/view.eduby.html +0 -15
- data/examples/wiki/war/WEB-INF/classes/test/HeredocContext.class +0 -0
- data/examples/wiki/war/WEB-INF/classes/test/MirahParser.class +0 -0
- data/examples/wiki/war/WEB-INF/lib/appengine-api.jar +0 -0
- data/examples/wiki/war/WEB-INF/lib/dubydatastore.jar +0 -0
- data/examples/wiki/war/WEB-INF/lib/jmeta-runtime.jar +0 -0
- data/examples/wiki/war/WEB-INF/lib/pegdown-stubs.jar +0 -0
- data/examples/wiki/war/WEB-INF/pegdown.jar +0 -0
- data/examples/wiki/war/app.yaml +0 -21
- data/examples/wiki/war/public/favicon.ico +0 -0
- data/examples/wiki/war/public/images/appengine_duby.png +0 -0
- data/examples/wiki/war/public/images/back.gif +0 -0
- data/examples/wiki/war/public/images/dir.gif +0 -0
- data/examples/wiki/war/public/images/file.gif +0 -0
- data/examples/wiki/war/public/javascripts/prettify.js +0 -61
- data/examples/wiki/war/public/robots.txt +0 -0
- data/examples/wiki/war/public/stylesheets/main.css +0 -156
- data/examples/wiki/war/public/stylesheets/prettify.css +0 -1
- data/examples/wiki/war/public/stylesheets/sh_style.css +0 -66
- data/examples/wiki/war/public/stylesheets/source.css +0 -21
- data/examples/wiki/war/public/wmd/images/bg-fill.png +0 -0
- data/examples/wiki/war/public/wmd/images/bg.png +0 -0
- data/examples/wiki/war/public/wmd/images/blockquote.png +0 -0
- data/examples/wiki/war/public/wmd/images/bold.png +0 -0
- data/examples/wiki/war/public/wmd/images/code.png +0 -0
- data/examples/wiki/war/public/wmd/images/h1.png +0 -0
- data/examples/wiki/war/public/wmd/images/hr.png +0 -0
- data/examples/wiki/war/public/wmd/images/img.png +0 -0
- data/examples/wiki/war/public/wmd/images/italic.png +0 -0
- data/examples/wiki/war/public/wmd/images/link.png +0 -0
- data/examples/wiki/war/public/wmd/images/ol.png +0 -0
- data/examples/wiki/war/public/wmd/images/redo.png +0 -0
- data/examples/wiki/war/public/wmd/images/separator.png +0 -0
- data/examples/wiki/war/public/wmd/images/ul.png +0 -0
- data/examples/wiki/war/public/wmd/images/undo.png +0 -0
- data/examples/wiki/war/public/wmd/images/wmd-on.png +0 -0
- data/examples/wiki/war/public/wmd/images/wmd.png +0 -0
- data/examples/wiki/war/public/wmd/showdown.js +0 -421
- data/examples/wiki/war/public/wmd/wmd-base.js +0 -1799
- data/examples/wiki/war/public/wmd/wmd-plus.js +0 -311
- data/examples/wiki/war/public/wmd/wmd.js +0 -73
- data/examples/wiki/war/src/org/mirah/wiki/MirahWiki.duby +0 -339
- data/examples/wiki/war/src/org/mirah/wiki/edit.eduby.html +0 -42
- data/examples/wiki/war/src/org/mirah/wiki/error.eduby.html +0 -2
- data/examples/wiki/war/src/org/mirah/wiki/layout.eduby.html +0 -69
- data/examples/wiki/war/src/org/mirah/wiki/parser.eduby.html +0 -7
- data/examples/wiki/war/src/org/mirah/wiki/view.eduby.html +0 -15
- data/javalib/dynalink-0.1.jar +0 -0
- data/javalib/jsr292-mock.jar +0 -0
- data/lib/mirah/class_loader.rb +0 -35
- data/lib/mirah/compilation_state.rb +0 -28
- data/lib/mirah/impl.rb +0 -273
- data/lib/mirah/jvm/base.rb +0 -267
- data/lib/mirah/jvm/source_compiler.rb +0 -760
- data/lib/mirah/transform2.rb +0 -752
data/lib/mirah/ast/intrinsics.rb
CHANGED
@@ -40,7 +40,12 @@ module Mirah::AST
|
|
40
40
|
else
|
41
41
|
position, index = Marshal.load(str)
|
42
42
|
holder = UnquotedValue.new(nil, position)
|
43
|
-
|
43
|
+
value = Unquote.__injected[index]
|
44
|
+
begin
|
45
|
+
holder << value.dup
|
46
|
+
rescue TypeError
|
47
|
+
holder << value
|
48
|
+
end
|
44
49
|
holder
|
45
50
|
end
|
46
51
|
end
|
@@ -97,10 +102,14 @@ module Mirah::AST
|
|
97
102
|
when Node
|
98
103
|
value.string_value
|
99
104
|
else
|
100
|
-
raise "Bad unquote value #{value}"
|
105
|
+
raise "Bad unquote value for name #{value} (#{value.class})"
|
101
106
|
end
|
102
107
|
end
|
103
108
|
|
109
|
+
def type
|
110
|
+
Constant.new(nil, position, name)
|
111
|
+
end
|
112
|
+
|
104
113
|
def node
|
105
114
|
case value
|
106
115
|
when Node
|
@@ -114,12 +123,24 @@ module Mirah::AST
|
|
114
123
|
else
|
115
124
|
return Local.new(nil, position, value)
|
116
125
|
end
|
126
|
+
when ::Fixnum
|
127
|
+
return Fixnum.new(nil, position, value)
|
117
128
|
else
|
118
|
-
raise "Bad unquote value"
|
129
|
+
raise "Bad unquote value for node #{value} (#{value.class})"
|
119
130
|
end
|
120
131
|
end
|
121
132
|
|
122
|
-
def
|
133
|
+
def nodes
|
134
|
+
case value
|
135
|
+
when ::Array, Java::JavaUtil::List
|
136
|
+
# TODO convert items to nodes.
|
137
|
+
value.to_a
|
138
|
+
else
|
139
|
+
[node]
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
def f_arg_item(value)
|
123
144
|
case value
|
124
145
|
when Arguments, Argument
|
125
146
|
value
|
@@ -127,8 +148,26 @@ module Mirah::AST
|
|
127
148
|
RequiredArgument.new(nil, position, value.string_value)
|
128
149
|
when ::String
|
129
150
|
RequiredArgument.new(nil, position, value)
|
151
|
+
when ::Array, java.util.List
|
152
|
+
name, type = value.map do |item|
|
153
|
+
if item.kind_of?(Node)
|
154
|
+
item.string_value
|
155
|
+
else
|
156
|
+
item.to_s
|
157
|
+
end
|
158
|
+
end
|
159
|
+
RequiredArgument.new(nil, position, name, type)
|
130
160
|
else
|
131
|
-
raise "Bad unquote value"
|
161
|
+
raise "Bad unquote value for arg #{value} (#{value.class})"
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
def f_arg
|
166
|
+
case value
|
167
|
+
when ::Array, java.util.List
|
168
|
+
value.map {|item| f_arg_item(item)}
|
169
|
+
else
|
170
|
+
f_arg_item(value)
|
132
171
|
end
|
133
172
|
end
|
134
173
|
end
|
@@ -277,7 +316,7 @@ module Mirah::AST
|
|
277
316
|
Mirah::AST.type_factory = new_factory
|
278
317
|
ast = build_ast(name, parent, transformer)
|
279
318
|
classes = compile_ast(name, ast, transformer)
|
280
|
-
loader = Mirah::ClassLoader.new(
|
319
|
+
loader = Mirah::Util::ClassLoader.new(
|
281
320
|
JRuby.runtime.jruby_class_loader, classes)
|
282
321
|
klass = loader.loadClass(name, true)
|
283
322
|
if state.save_extensions
|
@@ -312,7 +351,8 @@ module Mirah::AST
|
|
312
351
|
|
313
352
|
def compile_ast(name, ast, transformer)
|
314
353
|
begin
|
315
|
-
|
354
|
+
# FIXME: This is JVM specific, and should move out of platform-independent code
|
355
|
+
typer = Mirah::JVM::Typer.new(transformer)
|
316
356
|
typer.infer(ast, false)
|
317
357
|
typer.resolve(true)
|
318
358
|
typer.errors.each do |e|
|
@@ -321,7 +361,8 @@ module Mirah::AST
|
|
321
361
|
ensure
|
322
362
|
puts ast.inspect if transformer.state.verbose
|
323
363
|
end
|
324
|
-
|
364
|
+
# FIXME: This is JVM specific, and should move out of platform-independent code
|
365
|
+
compiler = Mirah::JVM::Compiler::JVMBytecode.new
|
325
366
|
ast.compile(compiler, false)
|
326
367
|
class_map = {}
|
327
368
|
compiler.generate do |outfile, builder|
|
@@ -351,6 +392,7 @@ module Mirah::AST
|
|
351
392
|
extension.implements(Mirah::AST.type(nil, 'duby.lang.compiler.Macro'))
|
352
393
|
|
353
394
|
extension.static_scope.import('duby.lang.compiler.Node', 'Node')
|
395
|
+
extension.static_scope.package = scope.static_scope.package
|
354
396
|
|
355
397
|
# The constructor just saves the state
|
356
398
|
extension.define_constructor(
|
data/lib/mirah/ast/literal.rb
CHANGED
data/lib/mirah/ast/local.rb
CHANGED
@@ -67,7 +67,11 @@ module Mirah::AST
|
|
67
67
|
def infer(typer, expression)
|
68
68
|
resolve_if(typer) do
|
69
69
|
scope.static_scope << name
|
70
|
-
typer.infer(value, true)
|
70
|
+
type = typer.infer(value, true)
|
71
|
+
if type && type.null?
|
72
|
+
type = typer.local_type(containing_scope, name) unless typer.last_chance
|
73
|
+
end
|
74
|
+
type
|
71
75
|
end
|
72
76
|
end
|
73
77
|
|
@@ -94,6 +98,10 @@ module Mirah::AST
|
|
94
98
|
"Local(name = #{name}, scope = #{scope}, captured = #{captured? == true})"
|
95
99
|
end
|
96
100
|
|
101
|
+
def type_reference(typer)
|
102
|
+
typer.type_reference(scope, @name)
|
103
|
+
end
|
104
|
+
|
97
105
|
def infer(typer, expression)
|
98
106
|
resolve_if(typer) do
|
99
107
|
scope.static_scope << name
|
data/lib/mirah/ast/method.rb
CHANGED
@@ -46,7 +46,7 @@ module Mirah::AST
|
|
46
46
|
end
|
47
47
|
|
48
48
|
def validate_child(args, child_index)
|
49
|
-
if args.kind_of?(Array)
|
49
|
+
if args.kind_of?(::Array)
|
50
50
|
args.each_with_index do |arg, arg_index|
|
51
51
|
if UnquotedValue === arg
|
52
52
|
actual_arg = arg.f_arg
|
@@ -70,7 +70,7 @@ module Mirah::AST
|
|
70
70
|
case args
|
71
71
|
when Arguments
|
72
72
|
args.children.each_with_index {|child, i| merge_args(child, i)}
|
73
|
-
when Array
|
73
|
+
when ::Array
|
74
74
|
args.each {|arg| merge_args(arg, child_index)}
|
75
75
|
when RequiredArgument
|
76
76
|
if child_index > 2
|
@@ -127,13 +127,23 @@ module Mirah::AST
|
|
127
127
|
signature = method_def.signature
|
128
128
|
|
129
129
|
if type_node
|
130
|
-
|
130
|
+
if ::String === type_node # How does this happen?
|
131
|
+
signature[name.intern] = typer.type_reference(scope, type_node)
|
132
|
+
else
|
133
|
+
signature[name.intern] = type_node.type_reference(typer)
|
134
|
+
end
|
131
135
|
end
|
132
136
|
|
133
137
|
# if signature, search for this argument
|
134
138
|
signature[name.intern] || typer.local_type(containing_scope, name)
|
135
139
|
end
|
136
140
|
end
|
141
|
+
|
142
|
+
def validate_type_node
|
143
|
+
if UnquotedValue === type_node
|
144
|
+
self.type_node = type_node.type
|
145
|
+
end
|
146
|
+
end
|
137
147
|
end
|
138
148
|
|
139
149
|
class OptionalArgument < Argument
|
@@ -191,7 +201,6 @@ module Mirah::AST
|
|
191
201
|
|
192
202
|
def infer(typer, expression)
|
193
203
|
scope.static_scope << name
|
194
|
-
super
|
195
204
|
end
|
196
205
|
end
|
197
206
|
|
@@ -237,11 +246,15 @@ module Mirah::AST
|
|
237
246
|
end
|
238
247
|
@annotations.each {|a| a.infer(typer, true)} if @annotations
|
239
248
|
typer.infer(arguments, true)
|
240
|
-
if @return_type
|
241
|
-
|
242
|
-
|
249
|
+
if @return_type
|
250
|
+
if @return_type.kind_of?(UnquotedValue)
|
251
|
+
@return_type = @return_type.node
|
252
|
+
@return_type.parent = self
|
253
|
+
else
|
254
|
+
@return_type.parent = self
|
255
|
+
end
|
256
|
+
signature[:return] = @return_type.type_reference(typer)
|
243
257
|
end
|
244
|
-
signature[:return] = @return_type.type_reference(typer) if @return_type
|
245
258
|
if @exceptions
|
246
259
|
signature[:throws] = @exceptions.map {|e| e.type_reference(typer)}
|
247
260
|
end
|
data/lib/mirah/ast/scope.rb
CHANGED
@@ -93,7 +93,7 @@ module Mirah
|
|
93
93
|
return unless type
|
94
94
|
existing_type = local_type(name)
|
95
95
|
if existing_type
|
96
|
-
unless existing_type.
|
96
|
+
unless existing_type.compatible?(type)
|
97
97
|
raise Mirah::Typer::InferenceError.new(
|
98
98
|
"Can't assign #{type.full_name} to " \
|
99
99
|
"variable of type #{existing_type.full_name}")
|
data/lib/mirah/ast/structure.rb
CHANGED
@@ -95,8 +95,8 @@ module Mirah::AST
|
|
95
95
|
super
|
96
96
|
end
|
97
97
|
|
98
|
-
def binding_type(
|
99
|
-
static_scope.binding_type(defining_class,
|
98
|
+
def binding_type(mirah=nil)
|
99
|
+
static_scope.binding_type(defining_class, mirah)
|
100
100
|
end
|
101
101
|
|
102
102
|
def binding_type=(type)
|
@@ -142,16 +142,19 @@ module Mirah::AST
|
|
142
142
|
end
|
143
143
|
|
144
144
|
def prepare(typer, method)
|
145
|
-
|
145
|
+
mirah = typer.transformer
|
146
146
|
interface = method.argument_types[-1]
|
147
147
|
outer_class = scope.defining_class
|
148
|
-
|
149
|
-
|
150
|
-
|
148
|
+
|
149
|
+
binding = scope.binding_type(mirah)
|
150
|
+
|
151
|
+
name = "#{outer_class.name}$#{mirah.tmp}"
|
152
|
+
|
153
|
+
klass = mirah.define_closure(position, name, outer_class)
|
151
154
|
klass.interfaces = [interface]
|
152
155
|
klass.define_constructor(position,
|
153
156
|
['binding', binding]) do |c|
|
154
|
-
|
157
|
+
mirah.eval("@binding = binding", '-', c, 'binding')
|
155
158
|
end
|
156
159
|
|
157
160
|
# TODO We need a special scope here that allows access to the
|
@@ -200,16 +203,17 @@ module Mirah::AST
|
|
200
203
|
next false
|
201
204
|
end
|
202
205
|
|
203
|
-
raise "Multiple abstract methods found; cannot use block" if impl_methods.size > 1
|
206
|
+
raise "Multiple abstract methods found within given interface [#{impl_methods.map(&:name).join(', ')}]; cannot use block" if impl_methods.size > 1
|
204
207
|
impl_methods.each do |method|
|
205
208
|
mdef = klass.define_method(position,
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
209
|
+
method.name,
|
210
|
+
method.return_type,
|
211
|
+
args.dup) do |mdef|
|
212
|
+
mdef.static_scope = static_scope
|
213
|
+
mdef.binding_type = binding
|
214
|
+
mdef.body = body.dup
|
215
|
+
end
|
216
|
+
typer.infer(mdef.body, method.return_type != typer.no_type)
|
213
217
|
end
|
214
218
|
end
|
215
219
|
|
@@ -282,4 +286,66 @@ module Mirah::AST
|
|
282
286
|
attr_accessor :explicit_packages
|
283
287
|
end
|
284
288
|
end
|
289
|
+
|
290
|
+
class Annotation < Node
|
291
|
+
attr_reader :values
|
292
|
+
attr_accessor :runtime
|
293
|
+
alias runtime? runtime
|
294
|
+
|
295
|
+
child :name_node
|
296
|
+
|
297
|
+
def initialize(parent, position, name=nil, &block)
|
298
|
+
super(parent, position, &block)
|
299
|
+
if name
|
300
|
+
@name = if name.respond_to?(:class_name)
|
301
|
+
name.class_name
|
302
|
+
else
|
303
|
+
name.name
|
304
|
+
end
|
305
|
+
end
|
306
|
+
@values = {}
|
307
|
+
end
|
308
|
+
|
309
|
+
def name
|
310
|
+
@name
|
311
|
+
end
|
312
|
+
|
313
|
+
def type
|
314
|
+
BiteScript::ASM::Type.getObjectType(@name.tr('.', '/'))
|
315
|
+
end
|
316
|
+
|
317
|
+
def []=(name, value)
|
318
|
+
@values[name] = value
|
319
|
+
end
|
320
|
+
|
321
|
+
def [](name)
|
322
|
+
@values[name]
|
323
|
+
end
|
324
|
+
|
325
|
+
def infer(typer, expression)
|
326
|
+
@inferred ||= begin
|
327
|
+
@name = name_node.type_reference(typer).name if name_node
|
328
|
+
@values.each do |name, value|
|
329
|
+
if Node === value
|
330
|
+
@values[name] = annotation_value(value, typer)
|
331
|
+
end
|
332
|
+
end
|
333
|
+
true
|
334
|
+
end
|
335
|
+
end
|
336
|
+
|
337
|
+
def annotation_value(node, typer)
|
338
|
+
case node
|
339
|
+
when String
|
340
|
+
java.lang.String.new(node.literal)
|
341
|
+
when Array
|
342
|
+
node.children.map {|node| annotation_value(node, typer)}
|
343
|
+
else
|
344
|
+
# TODO Support other types
|
345
|
+
ref = value.type_refence(typer)
|
346
|
+
desc = BiteScript::Signature.class_id(ref)
|
347
|
+
BiteScript::ASM::Type.getType(desc)
|
348
|
+
end
|
349
|
+
end
|
350
|
+
end
|
285
351
|
end
|
data/lib/mirah/ast/type.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
#!/usr/bin/env jruby
|
2
|
-
|
3
1
|
# Copyright (c) 2010 The Mirah project authors. All Rights Reserved.
|
4
2
|
# All contributing project authors may be found in the NOTICE file.
|
5
3
|
#
|
@@ -15,12 +13,7 @@
|
|
15
13
|
# See the License for the specific language governing permissions and
|
16
14
|
# limitations under the License.
|
17
15
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
require 'mirah'
|
23
|
-
end
|
24
|
-
|
25
|
-
puts 'WARNING: Duby is now Mirah. Please use the `mirahc` command.'
|
26
|
-
Duby.compile(*ARGV)
|
16
|
+
require 'mirah/commands/base'
|
17
|
+
require 'mirah/commands/run'
|
18
|
+
require 'mirah/commands/compile'
|
19
|
+
require 'mirah/commands/parse'
|
@@ -0,0 +1,54 @@
|
|
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
|
+
require 'mirah/jvm/types'
|
17
|
+
require 'mirah/util/compilation_state'
|
18
|
+
require 'mirah/util/argument_processor'
|
19
|
+
require 'mirah/errors'
|
20
|
+
|
21
|
+
module Mirah
|
22
|
+
module Commands
|
23
|
+
class Base
|
24
|
+
def initialize(args)
|
25
|
+
Mirah::AST.type_factory = Mirah::JVM::Types::TypeFactory.new
|
26
|
+
@state = Mirah::Util::CompilationState.new
|
27
|
+
@state.command = command_name
|
28
|
+
@args = args
|
29
|
+
@argument_processor = Mirah::Util::ArgumentProcessor.new(@state, @args)
|
30
|
+
end
|
31
|
+
|
32
|
+
attr_accessor :state, :args, :argument_processor
|
33
|
+
|
34
|
+
def execute_base
|
35
|
+
# because MirahCommand is a JRuby Java class, SystemExit bubbles through and makes noise
|
36
|
+
# so we use a catch/throw to early exit instead
|
37
|
+
# see process_errors.rb
|
38
|
+
catch(:exit) do
|
39
|
+
begin
|
40
|
+
argument_processor.process
|
41
|
+
yield
|
42
|
+
rescue Mirah::InternalCompilerError => ice
|
43
|
+
Mirah.print_error(ice.message, ice.position) if ice.node
|
44
|
+
raise ice.cause if (ice.cause && state.verbose)
|
45
|
+
raise ice
|
46
|
+
rescue Mirah::MirahError => ex
|
47
|
+
Mirah.print_error(ex.message, ex.position)
|
48
|
+
puts ex.backtrace if state.verbose
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|