mirah 0.1.2-java → 0.1.3-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (102) hide show
  1. checksums.yaml +4 -4
  2. data/History.txt +225 -0
  3. data/Rakefile +108 -315
  4. data/TODO.md +100 -0
  5. data/bin/bundler +16 -0
  6. data/bin/rake +16 -0
  7. data/dist/mirahc.jar +0 -0
  8. data/examples/appengine/Readme +0 -1
  9. data/examples/literals.mirah +17 -0
  10. data/examples/macros/string_each_char.mirah +1 -1
  11. data/lib/mirah.rb +11 -21
  12. data/lib/mirah/transform/transformer.rb +1 -2
  13. data/lib/mirah/util/class_loader.rb +1 -1
  14. data/lib/mirah/util/logging.rb +0 -63
  15. data/lib/mirah/util/process_errors.rb +1 -0
  16. data/lib/mirah/version.rb +1 -1
  17. data/{examples/simple_class.mirah~ → test/artifacts/jar_test.rb} +7 -11
  18. data/{lib/mirah/commands.rb → test/artifacts/jruby_test.rb} +8 -5
  19. data/test/core/typer_test.rb +29 -11
  20. data/test/core/util/argument_processor_test.rb +24 -23
  21. data/test/core/util/class_loader_test.rb +7 -4
  22. data/test/core/util/{compilation_state_test.rb → jvm_version_test.rb} +20 -16
  23. data/test/fixtures/org/foo/ImplicitClassRetAnno.java +4 -0
  24. data/test/fixtures/org/foo/IntAnno.java +9 -0
  25. data/test/jvm/annotations_test.rb +11 -11
  26. data/test/jvm/blocks_test.rb +16 -12
  27. data/test/jvm/constructors_test.rb +8 -8
  28. data/test/jvm/enumerable_test.rb +48 -24
  29. data/test/jvm/generics_test.rb +3 -7
  30. data/test/jvm/import_test.rb +14 -0
  31. data/test/jvm/interface_test.rb +9 -24
  32. data/test/jvm/jvm_commands_test.rb +22 -4
  33. data/test/jvm/jvm_compiler_test.rb +124 -79
  34. data/test/jvm/list_extensions_test.rb +1 -1
  35. data/test/jvm/macros_test.rb +67 -14
  36. data/test/jvm/main_method_test.rb +1 -1
  37. data/test/jvm/new_backend_test_helper.rb +100 -3
  38. data/{lib/mirah/jvm/types/bitescript_ext.rb → test/jvm/static_fields_test.rb} +22 -21
  39. data/test/mirrors/base_type_test.rb +4 -3
  40. data/test/mirrors/bytecode_mirror_test.rb +35 -15
  41. data/test/mirrors/generics_test.rb +14 -5
  42. data/test/mirrors/member_test.rb +2 -1
  43. data/test/mirrors/method_lookup_test.rb +18 -6
  44. data/test/mirrors/mirrors_test.rb +87 -20
  45. data/test/mirrors/simple_async_mirror_loader_test.rb +7 -3
  46. data/test/mirrors/simple_mirror_loader_test.rb +5 -5
  47. data/test/test_helper.rb +25 -1
  48. metadata +18 -78
  49. data/bin/mirahp +0 -27
  50. data/bin/mirahp.cmd +0 -16
  51. data/examples/Fib.class +0 -0
  52. data/javalib/mirah-bootstrap.jar +0 -0
  53. data/javalib/mirah-builtins.jar +0 -0
  54. data/javalib/mirah-compiler.jar +0 -0
  55. data/javalib/mirah-mirrors.jar +0 -0
  56. data/javalib/mirah-newast-transitional.jar +0 -0
  57. data/javalib/mirah-parser.jar +0 -0
  58. data/javalib/mirah-util.jar +0 -0
  59. data/lib/mirah/ast.rb +0 -43
  60. data/lib/mirah/ast/scope.rb +0 -262
  61. data/lib/mirah/commands/base.rb +0 -59
  62. data/lib/mirah/commands/compile.rb +0 -39
  63. data/lib/mirah/commands/parse.rb +0 -36
  64. data/lib/mirah/commands/run.rb +0 -78
  65. data/lib/mirah/generator.rb +0 -150
  66. data/lib/mirah/jvm/compiler.rb +0 -50
  67. data/lib/mirah/jvm/compiler/base.rb +0 -421
  68. data/lib/mirah/jvm/compiler/jvm_bytecode.rb +0 -1194
  69. data/lib/mirah/jvm/method_lookup.rb +0 -307
  70. data/lib/mirah/jvm/types.rb +0 -45
  71. data/lib/mirah/jvm/types/array_type.rb +0 -60
  72. data/lib/mirah/jvm/types/ast_ext.rb +0 -31
  73. data/lib/mirah/jvm/types/basic_types.rb +0 -41
  74. data/lib/mirah/jvm/types/block_type.rb +0 -15
  75. data/lib/mirah/jvm/types/boolean.rb +0 -70
  76. data/lib/mirah/jvm/types/enumerable.rb +0 -80
  77. data/lib/mirah/jvm/types/extensions.rb +0 -110
  78. data/lib/mirah/jvm/types/factory.rb +0 -830
  79. data/lib/mirah/jvm/types/floats.rb +0 -99
  80. data/lib/mirah/jvm/types/generic_type.rb +0 -72
  81. data/lib/mirah/jvm/types/implicit_nil_type.rb +0 -29
  82. data/lib/mirah/jvm/types/integers.rb +0 -131
  83. data/lib/mirah/jvm/types/interface_definition.rb +0 -20
  84. data/lib/mirah/jvm/types/intrinsics.rb +0 -385
  85. data/lib/mirah/jvm/types/literals.rb +0 -89
  86. data/lib/mirah/jvm/types/meta_type.rb +0 -54
  87. data/lib/mirah/jvm/types/methods.rb +0 -946
  88. data/lib/mirah/jvm/types/null_type.rb +0 -39
  89. data/lib/mirah/jvm/types/number.rb +0 -184
  90. data/lib/mirah/jvm/types/primitive_type.rb +0 -76
  91. data/lib/mirah/jvm/types/source_mirror.rb +0 -274
  92. data/lib/mirah/jvm/types/type.rb +0 -311
  93. data/lib/mirah/jvm/types/type_definition.rb +0 -72
  94. data/lib/mirah/jvm/types/void_type.rb +0 -19
  95. data/lib/mirah/util/compilation_state.rb +0 -60
  96. data/test/core/commands_test.rb +0 -89
  97. data/test/core/generator_test.rb +0 -26
  98. data/test/fixtures/org/foo/LowerCaseInnerClass$inner.class +0 -0
  99. data/test/fixtures/org/foo/LowerCaseInnerClass.class +0 -0
  100. data/test/jvm/bytecode_test_helper.rb +0 -193
  101. data/test/jvm/factory_test.rb +0 -28
  102. data/test/jvm/java_typer_test.rb +0 -283
@@ -1,311 +0,0 @@
1
- module Mirah
2
- module JVM
3
- module Types
4
- class Type
5
- java_import 'org.mirah.typer.ErrorType'
6
- java_import 'org.mirah.typer.SpecialType'
7
- java_import 'org.mirah.typer.InlineCode'
8
- java_import 'org.mirah.typer.ResolvedType'
9
-
10
- class SpecialType
11
- def full_name
12
- name
13
- end
14
- end
15
-
16
- include Mirah::JVM::MethodLookup
17
- include Mirah::Logging::Logged
18
-
19
- include ResolvedType
20
- begin
21
- java_import 'org.mirah.jvm.types.JVMType'
22
- include JVMType
23
- rescue NameError
24
- $CLASSPATH << File.dirname(__FILE__) + '/../../../../javalib/mirah-compiler.jar'
25
- begin
26
- java_import 'org.mirah.jvm.types.JVMType'
27
- include JVMType
28
- rescue
29
- puts "Unable to load new type interface"
30
- end
31
- end
32
-
33
- attr_reader :name, :type_system
34
- attr_writer :inner_class
35
-
36
- def initialize(type_system, mirror_or_name)
37
- @type_system = type_system
38
- raise ArgumentError if type_system.nil?
39
- if mirror_or_name.kind_of?(BiteScript::ASM::ClassMirror)
40
- @type = mirror_or_name
41
- @name = mirror_or_name.type.class_name
42
- else
43
- @name = mirror_or_name.to_s
44
- end
45
- raise ArgumentError, "Bad type #{mirror_or_name}" if name =~ /Java::/
46
- end
47
-
48
- def full_name
49
- desc = BiteScript::Signature.class_id(self)
50
- BiteScript::ASM::Type.get_type(desc).class_name
51
- end
52
-
53
- def internal_name
54
- full_name.tr('.', '/')
55
- end
56
- def class_id
57
- BiteScript::Signature.class_id(self)
58
- end
59
- def getAsmType
60
- BiteScript::ASM::Type.get_type(class_id)
61
- end
62
- def isAnnotation
63
- jvm_type ? jvm_type.annotation? : false
64
- end
65
- def isEnum
66
- jvm_type ? jvm_type.enum? : false
67
- end
68
- def flags
69
- flags = BiteScript::ASM::Opcodes::ACC_PUBLIC
70
- flags |= BiteScript::ASM::Opcodes::ACC_ANNOTATION if isAnnotation
71
- flags |= BiteScript::ASM::Opcodes::ACC_ENUM if isEnum
72
- flags |= BiteScript::ASM::Opcodes::ACC_INTERFACE if self.interface?
73
- flags |= BiteScript::ASM::Opcodes::ACC_ABSTRACT if self.abstract?
74
- flags
75
- end
76
- def retention
77
- if jvm_type.respond_to?(:getDeclaredAnnotation)
78
- retention = jvm_type.getDeclaredAnnotation('java.lang.annotation.Retention')
79
- retention.value.name
80
- else
81
- nil
82
- end
83
- end
84
-
85
- def jvm_type
86
- @type
87
- end
88
-
89
- def void?
90
- false
91
- end
92
-
93
- def meta?
94
- false
95
- end
96
- def isMeta
97
- self.meta?
98
- end
99
-
100
-
101
- def generic?
102
- false
103
- end
104
- def isGeneric
105
- self.generic?
106
- end
107
-
108
- def isBlock
109
- false
110
- end
111
-
112
- def array?
113
- false
114
- end
115
- def isArray
116
- self.array?
117
- end
118
-
119
- def primitive?
120
- false
121
- end
122
- def isPrimitive
123
- self.primitive?
124
- end
125
-
126
- def interface?
127
- # FIXME: Don't do rescue nil. Figure out a cleaner way to handle
128
- # mirrors for all incoming types without blowing up on e.g. 'boolean' or 'int'
129
- (@type || BiteScript::ASM::ClassMirror.for_name(@name)).interface? rescue nil
130
- end
131
-
132
- def abstract?
133
- (@type || BiteScript::ASM::ClassMirror.for_name(@name)).abstract? rescue nil
134
- end
135
-
136
- def dynamic?
137
- false
138
- end
139
-
140
- def inner_class?
141
- @inner_class
142
- end
143
-
144
- def is_parent(other)
145
- assignable_from?(other)
146
- end
147
-
148
- def compatible?(other)
149
- assignable_from?(other)
150
- end
151
-
152
- def error?
153
- false
154
- end
155
- def isError
156
- false
157
- end
158
-
159
- def assignable_from?(other)
160
- return false unless other
161
- return true if !primitive? && other.kind_of?(NullType)
162
- return true if other == self
163
- return true if other.matchesAnything
164
- return true if other.kind_of?(InlineCode)
165
-
166
- return interface? || abstract? if other.isBlock
167
-
168
- return true if jvm_type && (jvm_type == other.jvm_type)
169
-
170
- return assignable_from?(other.ungeneric) if other.generic?
171
-
172
- return other.convertible_to?(self) if other.primitive?
173
-
174
- assignable_from?(other.superclass) ||
175
- other.interfaces.any? {|i| assignable_from?(i)}
176
- end
177
-
178
- def assignableFrom(other)
179
- assignable_from?(other)
180
- end
181
-
182
- def widen(other)
183
- return self if assignable_from?(other)
184
- common_parent = (ancestors_and_interfaces & ([other] + other.ancestors_and_interfaces))[0]
185
- common_parent || ErrorType.new([["Incompatible types #{self} and #{other}."]])
186
- end
187
-
188
- def matchesAnything; false; end
189
-
190
- def iterable?
191
- ['java.lang.Iterable',
192
- 'java.util.Iterator',
193
- 'java.util.Enumeration'].any? {|n| @type_system.type(nil, n).assignable_from(self)}
194
- end
195
-
196
- def component_type
197
- @type_system.type(nil, 'java.lang.Object') if iterable?
198
- end
199
-
200
- def meta
201
- @meta ||= MetaType.new(self)
202
- end
203
-
204
- def unmeta
205
- self
206
- end
207
-
208
- def generic
209
- @generic ||= GenericType.new(self)
210
- end
211
-
212
- def ungeneric
213
- self
214
- end
215
-
216
- def type_parameters
217
- return nil unless jvm_type
218
- jvm_type.type_parameters
219
- end
220
-
221
- def basic_type
222
- self
223
- end
224
-
225
- def array_type
226
- @array_type ||= Mirah::JVM::Types::ArrayType.new(self)
227
- end
228
-
229
- def prefix
230
- 'a'
231
- end
232
-
233
- # is this a 64 bit type?
234
- def wide?
235
- false
236
- end
237
-
238
- def inspect(indent=0)
239
- "#{' ' * indent}#<#{self.class.name.split(/::/)[-1]} #{name}>"
240
- end
241
-
242
- def to_s
243
- inspect
244
- end
245
-
246
- def newarray(method)
247
- method.anewarray(self)
248
- end
249
-
250
- def pop(method)
251
- if wide?
252
- method.pop2
253
- else
254
- method.pop
255
- end
256
- end
257
-
258
- def superclass
259
- raise "Incomplete type #{self}" unless jvm_type
260
- @type_system.type(nil, jvm_type.superclass) if jvm_type.superclass
261
- end
262
-
263
- def interfaces(include_parent=true)
264
- raise "Incomplete type #{self} (#{self.class})" unless jvm_type
265
- @interfaces ||= begin
266
- interfaces = jvm_type.interfaces.map {|i| @type_system.type(nil, i)}.to_set
267
- if superclass && include_parent
268
- interfaces |= superclass.interfaces
269
- end
270
- interfaces.to_a
271
- end
272
- @interfaces
273
- end
274
-
275
- def ancestors_and_interfaces
276
- if self.primitive?
277
- []
278
- else
279
- ancestors = []
280
- get_ancestors = lambda {|c| [c.superclass] + c.interfaces(false)}
281
- new_ancestors = get_ancestors.call(self)
282
- until new_ancestors.empty?
283
- klass = new_ancestors.shift
284
- next if klass.nil? || klass.name == 'java.lang.Object' || klass.isError
285
- ancestors << klass
286
- new_ancestors.concat(get_ancestors.call(klass))
287
- end
288
- ancestors << @type_system.type(nil, 'java.lang.Object')
289
- ancestors
290
- end
291
- end
292
-
293
- def astore(builder)
294
- if primitive?
295
- builder.send "#{name[0,1]}astore"
296
- else
297
- builder.aastore
298
- end
299
- end
300
-
301
- def aload(builder)
302
- if primitive?
303
- builder.send "#{name[0,1]}aload"
304
- else
305
- builder.aaload
306
- end
307
- end
308
- end
309
- end
310
- end
311
- end
@@ -1,72 +0,0 @@
1
- module Mirah
2
- module JVM
3
- module Types
4
- class TypeDefinition < Type
5
- java_import 'mirah.lang.ast.InterfaceDeclaration'
6
- attr_accessor :node, :scope
7
-
8
- def initialize(types, scope, name, node)
9
- raise ArgumentError, "Bad name #{name}" if name[0,1] == '.'
10
- raise ArgumentError, "Bad name #{name}" if name.include? ?/
11
- @type_system = types
12
- @scope = scope
13
- @name = name
14
- @node = node
15
- @fields = {}
16
- raise ArgumentError, "Bad type #{name}" if self.name =~ /Java::/
17
- end
18
-
19
- def name
20
- if @type
21
- @type.name.tr('/', '.')
22
- else
23
- if !@name.include?(?.) && scope.package
24
- "#{scope.package}.#{@name}"
25
- else
26
- @name
27
- end
28
- end
29
- end
30
-
31
- def superclass
32
- if node && node.superclass
33
- @type_system.get(scope, node.superclass.typeref).resolve
34
- else
35
- @type_system.type(nil, 'java.lang.Object')
36
- end
37
- end
38
-
39
- def interfaces(include_parent=true)
40
- if node
41
- node.interfaces.map {|n| @type_system.get(scope, n.typeref).resolve}
42
- else
43
- []
44
- end
45
- end
46
-
47
- def abstract?
48
- node && (node.kind_of?(InterfaceDeclaration) || node.annotated_abstract?)
49
- end
50
-
51
- def define(builder)
52
- class_name = name.tr('.', '/')
53
- is_interface = node && node.kind_of?(InterfaceDeclaration)
54
- @type ||= builder.define_class(
55
- class_name,
56
- :visibility => :public,
57
- :abstract => abstract?,
58
- :interface => is_interface,
59
- :superclass => superclass,
60
- :interfaces => interfaces)
61
- end
62
-
63
- def meta
64
- @meta ||= TypeDefMeta.new(self)
65
- end
66
- end
67
-
68
- class TypeDefMeta < MetaType
69
- end
70
- end
71
- end
72
- end
@@ -1,19 +0,0 @@
1
- module Mirah
2
- module JVM
3
- module Types
4
- class VoidType < PrimitiveType
5
- def initialize(types)
6
- super(types, 'void', Java::JavaLang::Void)
7
- end
8
-
9
- def void?
10
- true
11
- end
12
-
13
- def return(builder)
14
- builder.returnvoid
15
- end
16
- end
17
- end
18
- end
19
- end
@@ -1,60 +0,0 @@
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 'bitescript'
17
-
18
- module Mirah
19
- module Util
20
- class CompilationState
21
- def initialize
22
- @save_extensions = true
23
- set_jvm_version ENV_JAVA['java.specification.version']
24
- end
25
-
26
- attr_accessor :verbose, :destination
27
- attr_accessor :version_printed
28
- attr_accessor :help_printed
29
- attr_accessor :save_extensions
30
- attr_accessor :running
31
- alias running? running
32
- attr_accessor :compiler_class
33
- attr_accessor :args
34
- attr_accessor :command
35
- attr_accessor :loggers
36
- attr_accessor :type_system
37
-
38
- attr_accessor :classpath, :bootclasspath
39
- attr_reader :target_jvm_version, :bytecode_version
40
-
41
- def set_jvm_version(ver_str)
42
- @target_jvm_version = ver_str
43
- @bytecode_version = case ver_str
44
- when '1.4' then BiteScript::JAVA1_4
45
- when '1.5' then BiteScript::JAVA1_5
46
- when '1.6' then BiteScript::JAVA1_6
47
- when '1.7' then BiteScript::JAVA1_7
48
- when '1.8' then BiteScript::JAVA1_8
49
- else
50
- $stderr.puts "invalid bytecode version specified: #{ver_str}"
51
- end
52
- BiteScript.bytecode_version = @bytecode_version
53
- end
54
-
55
- def supports_invokedynamic?
56
- @bytecode_version == BiteScript::JAVA1_7
57
- end
58
- end
59
- end
60
- end