mirah 0.0.5-java → 0.0.6-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.
Files changed (63) hide show
  1. data/History.txt +33 -0
  2. data/README.txt +2 -3
  3. data/Rakefile +5 -0
  4. data/bin/duby +0 -0
  5. data/bin/dubyc +0 -0
  6. data/bin/dubyp +0 -0
  7. data/bin/jrubyp +0 -0
  8. data/bin/mirah +0 -0
  9. data/bin/mirah.cmd +14 -14
  10. data/bin/mirahc +0 -0
  11. data/bin/mirahc.cmd +14 -14
  12. data/bin/mirahp +0 -0
  13. data/bin/mirahp.cmd +14 -14
  14. data/examples/Dynamic.class +0 -0
  15. data/examples/SizeThing.class +0 -0
  16. data/examples/plugins/appengine/Rakefile +3 -1
  17. data/examples/plugins/appengine/src/com/google/appengine/ext/duby/db/MetaModel.mirah +385 -0
  18. data/examples/plugins/appengine/src/com/google/appengine/ext/duby/db/Model.duby +58 -15
  19. data/examples/wiki/war/public/javascripts/prettify.js +0 -0
  20. data/examples/wiki/war/public/stylesheets/prettify.css +0 -0
  21. data/javalib/dynalink-0.1.jar +0 -0
  22. data/javalib/jsr292-mock.jar +0 -0
  23. data/javalib/mirah-bootstrap.jar +0 -0
  24. data/javalib/mirah-parser.jar +0 -0
  25. data/lib/mirah.rb +45 -25
  26. data/lib/mirah/ast.rb +81 -27
  27. data/lib/mirah/ast/call.rb +62 -71
  28. data/lib/mirah/ast/class.rb +23 -26
  29. data/lib/mirah/ast/flow.rb +38 -62
  30. data/lib/mirah/ast/intrinsics.rb +59 -37
  31. data/lib/mirah/ast/literal.rb +16 -14
  32. data/lib/mirah/ast/local.rb +8 -8
  33. data/lib/mirah/ast/method.rb +33 -19
  34. data/lib/mirah/ast/structure.rb +54 -13
  35. data/lib/mirah/ast/type.rb +8 -11
  36. data/lib/mirah/compiler.rb +86 -0
  37. data/lib/mirah/errors.rb +60 -0
  38. data/lib/mirah/jvm/base.rb +5 -11
  39. data/lib/mirah/jvm/compiler.rb +12 -1
  40. data/lib/mirah/jvm/source_compiler.rb +10 -2
  41. data/lib/mirah/jvm/source_generator/builder.rb +3 -1
  42. data/lib/mirah/jvm/source_generator/precompile.rb +6 -0
  43. data/lib/mirah/jvm/typer.rb +6 -1
  44. data/lib/mirah/jvm/types.rb +8 -0
  45. data/lib/mirah/jvm/types/factory.rb +34 -10
  46. data/lib/mirah/jvm/types/intrinsics.rb +12 -5
  47. data/lib/mirah/jvm/types/methods.rb +5 -9
  48. data/lib/mirah/plugin/gwt.rb +3 -2
  49. data/lib/mirah/transform.rb +68 -10
  50. data/lib/mirah/transform2.rb +10 -1
  51. data/lib/mirah/typer.rb +5 -10
  52. data/lib/mirah/version.rb +1 -1
  53. data/test/test_compilation.rb +1 -1
  54. data/test/test_java_typer.rb +10 -0
  55. data/test/test_javac_compiler.rb +4 -2
  56. data/test/test_jvm_compiler.rb +132 -9
  57. data/test/test_macros.rb +51 -0
  58. data/test/test_typer.rb +29 -25
  59. metadata +13 -21
  60. data/examples/plugins/appengine/lib/com/google/appengine/ext/duby/db/datastore.rb +0 -390
  61. data/javalib/JRubyParser.jar +0 -0
  62. data/javalib/dynalang-invoke-0.1.jar +0 -0
  63. data/lib/mirah/nbcompiler.rb +0 -44
@@ -15,19 +15,25 @@
15
15
 
16
16
  module Mirah::AST
17
17
  class Body < Node
18
+ include Java::DubyLangCompiler.Body
19
+
18
20
  def initialize(parent, line_number, &block)
19
21
  super(parent, line_number, &block)
20
22
  end
21
23
 
22
24
  # Type of a block is the type of its final element
23
- def infer(typer)
25
+ def infer(typer, expression)
24
26
  unless @inferred_type
25
27
  @typer ||= typer
26
28
  @self_type ||= typer.self_type
27
29
  if children.size == 0
28
30
  @inferred_type = typer.no_type
29
31
  else
30
- children.each {|child| @inferred_type = typer.infer(child)}
32
+ last = children.size - 1
33
+ children.each_with_index do |child, i|
34
+ child_is_expression = (i == last && expression)
35
+ @inferred_type = typer.infer(child, child_is_expression)
36
+ end
31
37
  end
32
38
 
33
39
  if @inferred_type
@@ -40,16 +46,29 @@ module Mirah::AST
40
46
  @inferred_type
41
47
  end
42
48
 
49
+ def string_value
50
+ if children.size == 1
51
+ children[0].string_value
52
+ else
53
+ super
54
+ end
55
+ end
56
+
43
57
  def <<(node)
44
58
  super
45
59
  if @typer
46
60
  orig_self = @typer.self_type
47
61
  @typer.known_types['self'] = @self_type
48
- @typer.infer(node)
62
+ @typer.infer(node, true)
49
63
  @typer.known_types['self'] = orig_self
50
64
  end
51
65
  self
52
66
  end
67
+
68
+ def add_node(node)
69
+ self << node
70
+ end
71
+
53
72
  end
54
73
 
55
74
  # class << self
@@ -61,7 +80,7 @@ module Mirah::AST
61
80
  super(parent, line_number, &block)
62
81
  end
63
82
 
64
- def infer(typer)
83
+ def infer(typer, expression)
65
84
  static_scope.self_type = scope.static_scope.self_type.meta
66
85
  super
67
86
  end
@@ -71,16 +90,38 @@ module Mirah::AST
71
90
  include Scope
72
91
  include Scoped
73
92
 
74
- def infer(typer)
93
+ def infer(typer, expression)
75
94
  static_scope.self_type ||= typer.self_type
76
95
  super
77
96
  end
78
97
 
98
+ def binding_type(duby=nil)
99
+ static_scope.binding_type(defining_class, duby)
100
+ end
101
+
102
+ def binding_type=(type)
103
+ static_scope.binding_type = type
104
+ end
105
+
106
+ def has_binding?
107
+ static_scope.has_binding?
108
+ end
109
+
110
+ def type_reference(typer)
111
+ raise Mirah::SyntaxError.new("Invalid type", self) unless children.size == 1
112
+ children[0].type_reference(typer)
113
+ end
114
+
79
115
  def inspect_children(indent=0)
80
116
  indent_str = ' ' * indent
81
117
  str = ''
82
118
  if static_scope.self_node
83
- str << "\n#{indent_str}self:\n" << static_scope.self_node.inspect(indent + 1)
119
+ str << "\n#{indent_str}self: "
120
+ if Node === static_scope.self_node
121
+ str << "\n" << static_scope.self_node.inspect(indent + 1)
122
+ else
123
+ str << static_scope.self_node.inspect
124
+ end
84
125
  end
85
126
  str << "\n#{indent_str}body:" << super(indent + 1)
86
127
  end
@@ -115,7 +156,7 @@ module Mirah::AST
115
156
 
116
157
  # TODO We need a special scope here that allows access to the
117
158
  # outer class.
118
- static_scope.self_type = typer.infer(klass)
159
+ static_scope.self_type = typer.infer(klass, true)
119
160
 
120
161
  add_methods(klass, binding, typer)
121
162
 
@@ -127,7 +168,7 @@ module Mirah::AST
127
168
  ]
128
169
  call.parameters << instance
129
170
  call.block = nil
130
- typer.infer(instance)
171
+ typer.infer(instance, true)
131
172
  end
132
173
 
133
174
  def add_methods(klass, binding, typer)
@@ -165,7 +206,7 @@ module Mirah::AST
165
206
  mdef.static_scope = static_scope
166
207
  mdef.body = body.dup
167
208
  mdef.binding_type = binding
168
- typer.infer(mdef.body)
209
+ typer.infer(mdef.body, true)
169
210
  end
170
211
  end
171
212
 
@@ -187,14 +228,14 @@ module Mirah::AST
187
228
  @inferred_type = type
188
229
  end
189
230
 
190
- def infer(typer)
231
+ def infer(typer, expression)
191
232
  resolved! unless resolved?
192
233
  @inferred_type
193
234
  end
194
235
  end
195
236
 
196
237
  class Noop < Node
197
- def infer(typer)
238
+ def infer(typer, expression)
198
239
  resolved!
199
240
  @inferred_type ||= typer.no_type
200
241
  end
@@ -213,13 +254,13 @@ module Mirah::AST
213
254
  @package = ""
214
255
  end
215
256
 
216
- def infer(typer)
257
+ def infer(typer, expression)
217
258
  resolve_if(typer) do
218
259
  typer.set_filename(self, filename)
219
260
  @defining_class ||= begin
220
261
  static_scope.self_type = typer.self_type
221
262
  end
222
- typer.infer(body)
263
+ typer.infer(body, false)
223
264
  end
224
265
  end
225
266
 
@@ -22,21 +22,18 @@ module Mirah::AST
22
22
  @short = short
23
23
  @long = long
24
24
  super(parent, line_number, [])
25
- scope.static_scope.import(long, short)
26
25
  end
27
26
 
28
27
  def to_s
29
28
  "Import(#{short} = #{long})"
30
29
  end
31
30
 
32
- def infer(typer)
33
- begin
34
- typer.type_reference(scope, @long)
35
- rescue NameError => ex
36
- typer.known_types[short] = Mirah::AST.error_type
37
- raise ex
31
+ def infer(typer, expression)
32
+ resolve_if(typer) do
33
+ scope.static_scope.import(long, short)
34
+ typer.type_reference(scope, @long) if short != '*'
35
+ typer.no_type
38
36
  end
39
- typer.no_type
40
37
  end
41
38
  end
42
39
 
@@ -128,17 +125,17 @@ module Mirah::AST
128
125
  super(*args)
129
126
  end
130
127
 
131
- def infer(typer)
128
+ def infer(typer, expression)
132
129
  resolve_if(typer) do
133
130
  @component_type = type_node.type_reference(typer)
134
- typer.infer(size)
131
+ typer.infer(size, true)
135
132
  typer.type_reference(nil, @component_type, true)
136
133
  end
137
134
  end
138
135
  end
139
136
 
140
137
  class Builtin < Node
141
- def infer(typer)
138
+ def infer(typer, expression)
142
139
  resolve_if(typer) {Mirah::AST.type(nil, 'mirah.impl.Builtin')}
143
140
  end
144
141
  end
@@ -23,6 +23,8 @@ module Mirah
23
23
  compiler.line(line_number)
24
24
  compiler.fixnum(inferred_type, literal)
25
25
  end
26
+ rescue Exception => ex
27
+ raise Mirah::InternalCompilerError.wrap(ex, self)
26
28
  end
27
29
  end
28
30
 
@@ -32,6 +34,8 @@ module Mirah
32
34
  compiler.line(line_number)
33
35
  compiler.regexp(literal)
34
36
  end
37
+ rescue Exception => ex
38
+ raise Mirah::InternalCompilerError.wrap(ex, self)
35
39
  end
36
40
  end
37
41
 
@@ -41,18 +45,24 @@ module Mirah
41
45
  compiler.line(line_number)
42
46
  compiler.string(literal)
43
47
  end
48
+ rescue Exception => ex
49
+ raise Mirah::InternalCompilerError.wrap(ex, self)
44
50
  end
45
51
  end
46
52
 
47
53
  class StringConcat
48
54
  def compile(compiler, expression)
49
55
  compiler.build_string(children, expression)
56
+ rescue Exception => ex
57
+ raise Mirah::InternalCompilerError.wrap(ex, self)
50
58
  end
51
59
  end
52
60
 
53
61
  class ToString
54
62
  def compile(compiler, expression)
55
63
  compiler.to_string(body, expression)
64
+ rescue Exception => ex
65
+ raise Mirah::InternalCompilerError.wrap(ex, self)
56
66
  end
57
67
  end
58
68
 
@@ -62,6 +72,8 @@ module Mirah
62
72
  compiler.line(line_number)
63
73
  compiler.float(inferred_type, literal)
64
74
  end
75
+ rescue Exception => ex
76
+ raise Mirah::InternalCompilerError.wrap(ex, self)
65
77
  end
66
78
  end
67
79
 
@@ -71,12 +83,16 @@ module Mirah
71
83
  compiler.line(line_number)
72
84
  compiler.boolean(literal)
73
85
  end
86
+ rescue Exception => ex
87
+ raise Mirah::InternalCompilerError.wrap(ex, self)
74
88
  end
75
89
  end
76
90
 
77
91
  class Array
78
92
  def compile(compiler, expression)
79
93
  compiler.array(self, expression)
94
+ rescue Exception => ex
95
+ raise Mirah::InternalCompilerError.wrap(ex, self)
80
96
  end
81
97
  end
82
98
 
@@ -84,6 +100,8 @@ module Mirah
84
100
  def compile(compiler, expression)
85
101
  compiler.line(line_number)
86
102
  compiler.body(self, expression)
103
+ rescue Exception => ex
104
+ raise Mirah::InternalCompilerError.wrap(ex, self)
87
105
  end
88
106
  end
89
107
 
@@ -91,6 +109,8 @@ module Mirah
91
109
  def compile(compiler, expression)
92
110
  compiler.line(line_number)
93
111
  compiler.scoped_body(self, expression)
112
+ rescue Exception => ex
113
+ raise Mirah::InternalCompilerError.wrap(ex, self)
94
114
  end
95
115
  end
96
116
 
@@ -98,6 +118,8 @@ module Mirah
98
118
  def compile(compiler, expression)
99
119
  # TODO: what does it mean for import to be an expression?
100
120
  compiler.import(short, long)
121
+ rescue Exception => ex
122
+ raise Mirah::InternalCompilerError.wrap(ex, self)
101
123
  end
102
124
  end
103
125
 
@@ -107,6 +129,8 @@ module Mirah
107
129
  compiler.line(line_number)
108
130
  compiler.constant(self)
109
131
  end
132
+ rescue Exception => ex
133
+ raise Mirah::InternalCompilerError.wrap(ex, self)
110
134
  end
111
135
  end
112
136
 
@@ -115,6 +139,8 @@ module Mirah
115
139
  # TODO: what does it mean for printline to be an expression?
116
140
  compiler.line(line_number)
117
141
  compiler.print(self)
142
+ rescue Exception => ex
143
+ raise Mirah::InternalCompilerError.wrap(ex, self)
118
144
  end
119
145
  end
120
146
 
@@ -128,6 +154,8 @@ module Mirah
128
154
  compiler.local(containing_scope, name, inferred_type)
129
155
  end
130
156
  end
157
+ rescue Exception => ex
158
+ raise Mirah::InternalCompilerError.wrap(ex, self)
131
159
  end
132
160
  end
133
161
 
@@ -139,6 +167,8 @@ module Mirah
139
167
  else
140
168
  compiler.local_declare(containing_scope, name, type)
141
169
  end
170
+ rescue Exception => ex
171
+ raise Mirah::InternalCompilerError.wrap(ex, self)
142
172
  end
143
173
  end
144
174
 
@@ -150,6 +180,8 @@ module Mirah
150
180
  else
151
181
  compiler.local_assign(containing_scope, name, inferred_type, expression, value)
152
182
  end
183
+ rescue Exception => ex
184
+ raise Mirah::InternalCompilerError.wrap(ex, self)
153
185
  end
154
186
  end
155
187
 
@@ -157,6 +189,8 @@ module Mirah
157
189
  def compile(compiler, expression)
158
190
  # TODO: what does it mean for a script to be an expression? possible?
159
191
  compiler.define_main(self)
192
+ rescue Exception => ex
193
+ raise Mirah::InternalCompilerError.wrap(ex, self)
160
194
  end
161
195
  end
162
196
 
@@ -164,12 +198,16 @@ module Mirah
164
198
  def compile(compiler, expression)
165
199
  # TODO: what does it mean for a method to be an expression?
166
200
  compiler.define_method(self)
201
+ rescue Exception => ex
202
+ raise Mirah::InternalCompilerError.wrap(ex, self)
167
203
  end
168
204
  end
169
205
 
170
206
  class ConstructorDefinition
171
207
  def compile(compiler, expression)
172
208
  compiler.constructor(self)
209
+ rescue Exception => ex
210
+ raise Mirah::InternalCompilerError.wrap(ex, self)
173
211
  end
174
212
  end
175
213
 
@@ -177,6 +215,8 @@ module Mirah
177
215
  def compile(compiler, expression)
178
216
  # TODO: what does it mean for a method to be an expression?
179
217
  args.each {|arg| compiler.declare_argument(arg.name, arg.inferred_type)} if args
218
+ rescue Exception => ex
219
+ raise Mirah::InternalCompilerError.wrap(ex, self)
180
220
  end
181
221
  end
182
222
 
@@ -184,6 +224,8 @@ module Mirah
184
224
  def compile(compiler, expression)
185
225
  # TODO: what does it mean for a noop to be an expression
186
226
  # nothing
227
+ rescue Exception => ex
228
+ raise Mirah::InternalCompilerError.wrap(ex, self)
187
229
  end
188
230
  end
189
231
 
@@ -191,6 +233,8 @@ module Mirah
191
233
  def compile(compiler, expression)
192
234
  compiler.line(line_number)
193
235
  compiler.branch(self, expression)
236
+ rescue Exception => ex
237
+ raise Mirah::InternalCompilerError.wrap(ex, self)
194
238
  end
195
239
  end
196
240
 
@@ -199,6 +243,8 @@ module Mirah
199
243
  # TODO: can a condition ever be an expression? I don't think it can...
200
244
  compiler.line(line_number)
201
245
  predicate.compile(compiler, expression)
246
+ rescue Exception => ex
247
+ raise Mirah::InternalCompilerError.wrap(ex, self)
202
248
  end
203
249
  end
204
250
 
@@ -206,6 +252,8 @@ module Mirah
206
252
  def compile(compiler, expression)
207
253
  compiler.line(line_number)
208
254
  compiler.self_call(self, expression)
255
+ rescue Exception => ex
256
+ raise Mirah::InternalCompilerError.wrap(ex, self)
209
257
  end
210
258
  end
211
259
 
@@ -213,6 +261,8 @@ module Mirah
213
261
  def compile(compiler, expression)
214
262
  compiler.line(line_number)
215
263
  compiler.call(self, expression)
264
+ rescue Exception => ex
265
+ raise Mirah::InternalCompilerError.wrap(ex, self)
216
266
  end
217
267
  end
218
268
 
@@ -220,6 +270,8 @@ module Mirah
220
270
  def compile(compiler, expression)
221
271
  compiler.line(line_number)
222
272
  compiler.super_call(self, expression)
273
+ rescue Exception => ex
274
+ raise Mirah::InternalCompilerError.wrap(ex, self)
223
275
  end
224
276
  end
225
277
 
@@ -227,24 +279,32 @@ module Mirah
227
279
  def compile(compiler, expression)
228
280
  compiler.line(line_number)
229
281
  compiler.loop(self, expression)
282
+ rescue Exception => ex
283
+ raise Mirah::InternalCompilerError.wrap(ex, self)
230
284
  end
231
285
  end
232
286
 
233
287
  class ClassDefinition
234
288
  def compile(compiler, expression)
235
289
  compiler.define_class(self, expression)
290
+ rescue Exception => ex
291
+ raise Mirah::InternalCompilerError.wrap(ex, self)
236
292
  end
237
293
  end
238
294
 
239
295
  class ClosureDefinition
240
296
  def compile(compiler, expression)
241
297
  compiler.define_closure(self, expression)
298
+ rescue Exception => ex
299
+ raise Mirah::InternalCompilerError.wrap(ex, self)
242
300
  end
243
301
  end
244
302
 
245
303
  class FieldDeclaration
246
304
  def compile(compiler, expression)
247
305
  compiler.field_declare(name, inferred_type, annotations, static)
306
+ rescue Exception => ex
307
+ raise Mirah::InternalCompilerError.wrap(ex, self)
248
308
  end
249
309
  end
250
310
 
@@ -252,6 +312,8 @@ module Mirah
252
312
  def compile(compiler, expression)
253
313
  compiler.line(line_number)
254
314
  compiler.field_assign(name, inferred_type, expression, value, annotations, static)
315
+ rescue Exception => ex
316
+ raise Mirah::InternalCompilerError.wrap(ex, self)
255
317
  end
256
318
  end
257
319
 
@@ -261,6 +323,8 @@ module Mirah
261
323
  if expression
262
324
  compiler.field(name, inferred_type, annotations, static)
263
325
  end
326
+ rescue Exception => ex
327
+ raise Mirah::InternalCompilerError.wrap(ex, self)
264
328
  end
265
329
  end
266
330
 
@@ -272,6 +336,8 @@ module Mirah
272
336
  def compile(compiler, expression)
273
337
  compiler.line(line_number)
274
338
  compiler.return(self)
339
+ rescue Exception => ex
340
+ raise Mirah::InternalCompilerError.wrap(ex, self)
275
341
  end
276
342
  end
277
343
 
@@ -281,6 +347,8 @@ module Mirah
281
347
  compiler.line(line_number)
282
348
  compiler.empty_array(component_type, size)
283
349
  end
350
+ rescue Exception => ex
351
+ raise Mirah::InternalCompilerError.wrap(ex, self)
284
352
  end
285
353
  end
286
354
 
@@ -290,6 +358,8 @@ module Mirah
290
358
  compiler.line(line_number)
291
359
  compiler.null
292
360
  end
361
+ rescue Exception => ex
362
+ raise Mirah::InternalCompilerError.wrap(ex, self)
293
363
  end
294
364
  end
295
365
 
@@ -297,6 +367,8 @@ module Mirah
297
367
  def compile(compiler, expression)
298
368
  compiler.line(line_number)
299
369
  compiler.break(self)
370
+ rescue Exception => ex
371
+ raise Mirah::InternalCompilerError.wrap(ex, self)
300
372
  end
301
373
  end
302
374
 
@@ -304,6 +376,8 @@ module Mirah
304
376
  def compile(compiler, expression)
305
377
  compiler.line(line_number)
306
378
  compiler.next(self)
379
+ rescue Exception => ex
380
+ raise Mirah::InternalCompilerError.wrap(ex, self)
307
381
  end
308
382
  end
309
383
 
@@ -311,6 +385,8 @@ module Mirah
311
385
  def compile(compiler, expression)
312
386
  compiler.line(line_number)
313
387
  compiler.redo(self)
388
+ rescue Exception => ex
389
+ raise Mirah::InternalCompilerError.wrap(ex, self)
314
390
  end
315
391
  end
316
392
 
@@ -318,6 +394,8 @@ module Mirah
318
394
  def compile(compiler, expression)
319
395
  compiler.line(line_number)
320
396
  compiler._raise(exception)
397
+ rescue Exception => ex
398
+ raise Mirah::InternalCompilerError.wrap(ex, self)
321
399
  end
322
400
  end
323
401
 
@@ -325,6 +403,8 @@ module Mirah
325
403
  def compile(compiler, expression)
326
404
  compiler.line(line_number)
327
405
  compiler.rescue(self, expression)
406
+ rescue Exception => ex
407
+ raise Mirah::InternalCompilerError.wrap(ex, self)
328
408
  end
329
409
  end
330
410
 
@@ -332,6 +412,8 @@ module Mirah
332
412
  def compile(compiler, expression)
333
413
  compiler.line(line_number)
334
414
  compiler.ensure(self, expression)
415
+ rescue Exception => ex
416
+ raise Mirah::InternalCompilerError.wrap(ex, self)
335
417
  end
336
418
  end
337
419
 
@@ -341,6 +423,8 @@ module Mirah
341
423
  compiler.line(line_number)
342
424
  compiler.compile_self
343
425
  end
426
+ rescue Exception => ex
427
+ raise Mirah::InternalCompilerError.wrap(ex, self)
344
428
  end
345
429
  end
346
430
 
@@ -350,6 +434,8 @@ module Mirah
350
434
  compiler.line(line_number)
351
435
  compiler.binding_reference
352
436
  end
437
+ rescue Exception => ex
438
+ raise Mirah::InternalCompilerError.wrap(ex, self)
353
439
  end
354
440
  end
355
441
  end