mirah 0.1.3-java → 0.1.4-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.
@@ -95,4 +95,18 @@ class InterfaceTest < Test::Unit::TestCase
95
95
  end
96
96
  EOF
97
97
  end
98
+
99
+
100
+ def test_interface_adds_to_list
101
+ interface, a_impl = compile(<<-EOF)
102
+ interface Stringy
103
+ def act(messages:String):void; end
104
+ end
105
+
106
+ class Something implements Stringy
107
+ def initialize; @a = []; end
108
+ def act(messages) @a.add(messages); puts @a ;end
109
+ end
110
+ EOF
111
+ end
98
112
  end
@@ -1832,4 +1832,15 @@ class JVMCompilerTest < Test::Unit::TestCase
1832
1832
  assert_output("2\n") { cls.foo(arg.new)}
1833
1833
  end
1834
1834
 
1835
+ def test_incompatible_return_type_error_message
1836
+ e = assert_raise_kind_of Mirah::MirahError do
1837
+ compile(<<-EOF)
1838
+ def a: int
1839
+ return 1.2 if true
1840
+ 1
1841
+ end
1842
+ EOF
1843
+ end
1844
+ assert_equal "Invalid return type double, expected int",e.message
1845
+ end
1835
1846
  end
@@ -89,7 +89,7 @@ module JVMCompiler
89
89
  end
90
90
 
91
91
  def tmp_script_name
92
- "script#{name.gsub(/\)|\(/,'_').capitalize}#{System.nano_time}"
92
+ "#{name.gsub(/\)|\(/,'_').capitalize}#{System.nano_time.to_s[10..15]}"
93
93
  end
94
94
 
95
95
  def assert_raise_java(type, message=nil)
@@ -16,7 +16,7 @@ require 'test_helper'
16
16
 
17
17
  class StaticFieldsTest < Test::Unit::TestCase
18
18
  def test_static_field_inheritance_lookup_with_dot
19
- cls, = with_finest_logging{compile(<<-EOF)}
19
+ cls, = compile(<<-EOF)
20
20
  import java.util.GregorianCalendar
21
21
  puts GregorianCalendar.AM
22
22
  EOF
@@ -39,4 +39,14 @@ class StaticFieldsTest < Test::Unit::TestCase
39
39
  end
40
40
  }
41
41
  end
42
+
43
+ def test_create_constant
44
+ cls, = compile(<<-EOF)
45
+ CONSTANT = 1
46
+ puts CONSTANT
47
+ EOF
48
+ assert_output "1\n" do
49
+ cls.main(nil)
50
+ end
51
+ end
42
52
  end
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2010 The Mirah project authors. All Rights Reserved.
1
+ # Copyright (c) 2010-2014 The Mirah project authors. All Rights Reserved.
2
2
  # All contributing project authors may be found in the NOTICE file.
3
3
  #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -19,7 +19,7 @@ require 'dist/mirahc.jar'
19
19
 
20
20
  class BaseMethodLookupTest < Test::Unit::TestCase
21
21
  java_import 'org.mirah.jvm.mirrors.MirrorTypeSystem'
22
- java_import 'org.mirah.jvm.mirrors.JVMScope'
22
+ java_import 'org.mirah.jvm.mirrors.BetterScopeFactory'
23
23
  java_import 'org.mirah.jvm.mirrors.BaseType'
24
24
  java_import 'org.mirah.jvm.mirrors.MethodLookup'
25
25
  java_import 'org.mirah.jvm.mirrors.LookupState'
@@ -31,6 +31,8 @@ class BaseMethodLookupTest < Test::Unit::TestCase
31
31
  java_import 'org.mirah.jvm.types.MemberKind'
32
32
  java_import 'org.mirah.typer.BaseTypeFuture'
33
33
  java_import 'org.mirah.typer.ErrorType'
34
+ java_import 'org.mirah.typer.simple.SimpleScoper'
35
+ java_import 'mirah.lang.ast.Script'
34
36
  java_import 'org.objectweb.asm.Opcodes'
35
37
  java_import 'org.objectweb.asm.Type'
36
38
 
@@ -41,7 +43,6 @@ class BaseMethodLookupTest < Test::Unit::TestCase
41
43
  end
42
44
 
43
45
  def add_field(name, flags=Opcodes.ACC_PUBLIC)
44
-
45
46
  kind = if (flags & Opcodes.ACC_STATIC) == 0
46
47
  MemberKind::FIELD_ACCESS
47
48
  else
@@ -57,10 +58,14 @@ class BaseMethodLookupTest < Test::Unit::TestCase
57
58
 
58
59
  def setup
59
60
  @types = MirrorTypeSystem.new
60
- @scope = JVMScope.new
61
+ @scope = new_scope
61
62
  @lookup = MethodLookup.new(@types.context)
62
63
  end
63
64
 
65
+ def new_scope opts={}
66
+ BetterScopeFactory.new.newScope(SimpleScoper.new, opts[:context] || Script.new)
67
+ end
68
+
64
69
  def jvmtype(internal_name, flags=0, superclass=nil)
65
70
  BaseType.new(@types.context, Type.getObjectType(internal_name), flags, superclass || wrap('Ljava/lang/Object;'))
66
71
  end
@@ -83,10 +88,13 @@ class MethodLookupTest < BaseMethodLookupTest
83
88
  main_future = @types.getMainType(nil, nil)
84
89
  object = @types.getSuperClass(main_future).resolve
85
90
  main = main_future.resolve
91
+
86
92
  assert(MethodLookup.isSubType(main, main))
87
93
  assert(MethodLookup.isSubType(main, object))
88
94
  assert_false(MethodLookup.isSubType(object, main))
95
+
89
96
  error = ErrorType.new([['Error']])
97
+
90
98
  assert(MethodLookup.isSubType(error, main))
91
99
  assert(MethodLookup.isSubType(main, error))
92
100
  end
@@ -123,6 +131,7 @@ class MethodLookupTest < BaseMethodLookupTest
123
131
  char = wrap('C')
124
132
  byte = wrap('B')
125
133
  bool = wrap('Z')
134
+
126
135
  check_supertypes(double, double)
127
136
  check_not_supertypes(double, float, long, int, short, char, byte, bool)
128
137
  check_supertypes(float, double, float)
@@ -180,6 +189,7 @@ class MethodLookupTest < BaseMethodLookupTest
180
189
  double = wrap('D')
181
190
  int = wrap('I')
182
191
  short = wrap('S')
192
+
183
193
  assert_equal(0.0, MethodLookup.subtypeComparison(double, double))
184
194
  assert_equal(0.0, MethodLookup.subtypeComparison(int, int))
185
195
  assert_equal(1.0, MethodLookup.subtypeComparison(int, double))
@@ -188,6 +198,7 @@ class MethodLookupTest < BaseMethodLookupTest
188
198
  assert_equal(1.0, MethodLookup.subtypeComparison(short, int))
189
199
 
190
200
  main = @types.getMainType(nil, nil).resolve
201
+
191
202
  assert_equal(0.0, MethodLookup.subtypeComparison(main, main))
192
203
  assert(MethodLookup.subtypeComparison(double, main).nan?)
193
204
  assert(MethodLookup.subtypeComparison(main, int).nan?)
@@ -197,6 +208,7 @@ class MethodLookupTest < BaseMethodLookupTest
197
208
  a = @types.getBooleanType.resolve
198
209
  b = @types.wrap(Type.getType('Ljava/lang/Boolean;')).resolve
199
210
  c = @types.getFixnumType(1).resolve
211
+
200
212
  assert(!MethodLookup.isSubType(a, b))
201
213
  assert(!MethodLookup.isSubType(b, a))
202
214
  assert(MethodLookup.isSubTypeWithConversion(a, b))
@@ -534,7 +546,7 @@ class FieldTest < BaseMethodLookupTest
534
546
  super
535
547
  @a = FakeMirror.new('LA;')
536
548
  @b = FakeMirror.new('LB;', @a)
537
- @scope = JVMScope.new
549
+ @scope = new_scope
538
550
  @selfType = BaseTypeFuture.new
539
551
  @selfType.resolved(@b)
540
552
  @scope.selfType_set(@selfType)
@@ -545,15 +557,16 @@ class FieldTest < BaseMethodLookupTest
545
557
  a_bar = @a.add_field("bar")
546
558
  b_foo = @b.add_field("foo")
547
559
  foos = @lookup.gatherFields(@b, 'foo').to_a
560
+
548
561
  assert_equal([b_foo, a_foo], foos)
549
-
550
562
  assert_equal([a_bar], @lookup.gatherFields(@b, 'bar').to_a)
551
563
  end
552
564
 
553
565
  def test_find_super_field
554
566
  @a.add_field("foo")
555
567
  future = @lookup.findMethod(@scope, @b, 'foo', [], nil, nil, false)
556
- assert_equal("LA;", future.resolve.returnType.asm_type.descriptor)
568
+
569
+ assert_equal("LA;", future.resolve.returnType.asm_type.descriptor)
557
570
  end
558
571
 
559
572
  def test_field_override
@@ -19,13 +19,14 @@ require 'dist/mirahc.jar'
19
19
 
20
20
  class BaseMirrorsTest < Test::Unit::TestCase
21
21
  java_import 'org.mirah.jvm.mirrors.MirrorTypeSystem'
22
- java_import 'org.mirah.jvm.mirrors.JVMScope'
22
+ java_import 'org.mirah.jvm.mirrors.BetterScopeFactory'
23
23
  java_import 'org.mirah.jvm.types.JVMType'
24
24
  java_import 'org.mirah.jvm.types.JVMTypeUtils'
25
25
  java_import 'org.mirah.typer.AssignableTypeFuture'
26
26
  java_import 'org.mirah.typer.BaseTypeFuture'
27
27
  java_import 'org.mirah.typer.CallFuture'
28
28
  java_import 'org.mirah.typer.TypeFuture'
29
+ java_import 'org.mirah.typer.simple.SimpleScoper'
29
30
  java_import 'mirah.lang.ast.ClassDefinition'
30
31
  java_import 'mirah.lang.ast.ConstructorDefinition'
31
32
  java_import 'mirah.lang.ast.PositionImpl'
@@ -37,10 +38,14 @@ class BaseMirrorsTest < Test::Unit::TestCase
37
38
 
38
39
  def setup
39
40
  @types = MirrorTypeSystem.new
40
- @scope = JVMScope.new
41
+ @scope = new_scope
41
42
  set_filename('foo-bar.mirah')
42
43
  end
43
44
 
45
+ def new_scope opts={}
46
+ BetterScopeFactory.new.newScope(SimpleScoper.new, opts[:context] || Script.new)
47
+ end
48
+
44
49
  def set_filename(filename)
45
50
  @script = Script.new(PositionImpl.new(StringCodeSource.new(filename, ""),
46
51
  0, 0, 0, 0, 0, 0))
@@ -251,7 +256,7 @@ class MirrorsTest < BaseMirrorsTest
251
256
 
252
257
  def test_multiple_scopes
253
258
  type1 = @types.getLocalType(@scope, "a", nil)
254
- type2 = @types.getLocalType(JVMScope.new, "a", nil)
259
+ type2 = @types.getLocalType(new_scope, "a", nil)
255
260
  assert_error(type1)
256
261
  assert_error(type2)
257
262
  type1.assign(@types.getFixnumType(0), nil)
@@ -268,6 +273,12 @@ class MirrorsTest < BaseMirrorsTest
268
273
  assert_descriptor("LFooBar;", @types.getSuperClass(type))
269
274
  end
270
275
 
276
+ def test_define_inner_class_type
277
+ type = define_type("Subclass$Inner", main_type)
278
+ assert_descriptor("LSubclass$Inner;", type)
279
+ assert_descriptor("LFooBar;", @types.getSuperClass(type))
280
+ end
281
+
271
282
  def test_redefine_main_type
272
283
  existing = main_type.resolve.unmeta
273
284
  type = @types.defineType(@scope, ClassDefinition.new, "FooBar", nil, [])
@@ -353,15 +364,47 @@ class MirrorsTest < BaseMirrorsTest
353
364
  '[S', @types.getArrayType(@types.get(@scope, typeref('short'))))
354
365
  end
355
366
 
356
- def test_field
357
- # TODO use instance field from static method
367
+
368
+ # TODO write test checking
369
+ # use of instance field from static method
370
+
371
+ def test_field_before_declaration
358
372
  a = @types.getFieldType(main_type, 'a', nil)
359
373
  b = @types.getFieldType(main_type, 'b', nil)
360
374
  assert_not_same(a, b)
361
375
  assert_same(a, @types.getFieldType(main_type, 'a', nil))
376
+
377
+ field = main_type.resolve.getDeclaredField('a')
378
+ assert(field.nil?, "expected field to be undeclared yet")
379
+ end
380
+
381
+ def test_separate_fields_without_declare_return_separate_futures
382
+ a = @types.getFieldType(main_type, 'a', nil)
383
+ b = @types.getFieldType(main_type, 'b', nil)
384
+ assert_not_same(a, b)
385
+ end
386
+
387
+ def test_separate_fields_with_declare_return_separate_futures
388
+ a = @types.getFieldTypeOrDeclare(main_type, 'a', nil)
389
+ b = @types.getFieldTypeOrDeclare(main_type, 'b', nil)
390
+ assert_not_same(a, b)
391
+ end
392
+
393
+ def test_declared_field_is_same_as_get_field_when_declared_first
394
+ a = @types.getFieldTypeOrDeclare(main_type, 'a', nil)
395
+ assert_same(a, @types.getFieldType(main_type, 'a', nil))
396
+ end
397
+
398
+ def test_declared_field_is_same_as_get_field_when_declared_second
399
+ a = @types.getFieldType(main_type, 'a', nil)
400
+ assert_same(a, @types.getFieldTypeOrDeclare(main_type, 'a', nil))
401
+ end
402
+
403
+ def test_field_attrs_of_declared_field
404
+ a = @types.getFieldTypeOrDeclare(main_type, 'a', nil)
362
405
 
363
406
  field = main_type.resolve.getDeclaredField('a')
364
- assert_not_nil(field)
407
+
365
408
  assert_same(a, field.async_return_type)
366
409
  assert_equal("STATIC_FIELD_ACCESS", field.kind.name)
367
410
 
@@ -558,8 +601,9 @@ class MTS_MethodLookupTest < BaseMirrorsTest
558
601
  end
559
602
 
560
603
  def test_super_in_constructor
604
+ @scope = new_scope context: ConstructorDefinition.new
561
605
  @scope.selfType_set(main_type)
562
- @scope.context_set(ConstructorDefinition.new)
606
+
563
607
  future = CallFuture.new(
564
608
  @types, @scope,
565
609
  @types.getSuperClass(main_type), true, 'initialize', [], [], nil)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mirah
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: java
6
6
  authors:
7
7
  - Charles Oliver Nutter
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2014-08-07 00:00:00.000000000 Z
13
+ date: 2014-11-13 00:00:00.000000000 Z
14
14
  dependencies: []
15
15
  description: |-
16
16
  Mirah is a customizable programming language featuring static types,
@@ -49,8 +49,6 @@ files:
49
49
  - lib/mirah/plugin/edb.rb
50
50
  - lib/mirah/transform/ast_ext.rb
51
51
  - lib/mirah/transform/transformer.rb
52
- - lib/mirah/util/argument_processor.rb
53
- - lib/mirah/util/class_loader.rb
54
52
  - lib/mirah/util/delegate.rb
55
53
  - lib/mirah/util/logging.rb
56
54
  - lib/mirah/util/process_errors.rb
@@ -62,9 +60,9 @@ files:
62
60
  - test/core/typer/assignable_type_future_test.rb
63
61
  - test/core/typer/error_type_test.rb
64
62
  - test/core/typer/simple_type_test.rb
65
- - test/core/util/argument_processor_test.rb
66
63
  - test/core/util/class_loader_test.rb
67
64
  - test/core/util/jvm_version_test.rb
65
+ - test/core/util/mirah_arguments_test.rb
68
66
  - test/fixtures/my.properties
69
67
  - test/fixtures/org/foo/A.class
70
68
  - test/fixtures/org/foo/ImplicitClassRetAnno.java
@@ -116,6 +114,9 @@ files:
116
114
  - examples/tak.mirah
117
115
  - examples/test.edb
118
116
  - examples/ant/example-build.xml
117
+ - examples/ant/example-build.xml~
118
+ - examples/ant/README.md
119
+ - examples/ant/build/Fib.class
119
120
  - examples/appengine/Rakefile
120
121
  - examples/appengine/Readme
121
122
  - examples/appengine/src/org/mirah/list.dhtml
@@ -1,150 +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 'mirah/jvm/compiler'
17
- require 'mirah/util/logging'
18
-
19
- module Mirah
20
- module Util
21
-
22
- class ArgumentProcessor
23
- def initialize(state, args)
24
- @state = state
25
- @args = args
26
- end
27
-
28
- attr_accessor :state, :args, :exit_status_code
29
-
30
- alias exit? exit_status_code
31
-
32
- def process
33
- state.args = args
34
- while args.length > 0 && args[0] =~ /^-/
35
- case args[0]
36
- when '--classpath', '-c'
37
- args.shift
38
- state.classpath = args.shift
39
- when '--bootclasspath'
40
- args.shift
41
- state.bootclasspath = args.shift
42
- when '--cd'
43
- args.shift
44
- Dir.chdir(args.shift)
45
- when '--dest', '-d'
46
- args.shift
47
- state.destination = File.join(File.expand_path(args.shift), '')
48
- when '-e'
49
- break
50
- when '--explicit-packages'
51
- args.shift
52
- Mirah::AST::Script.explicit_packages = true
53
- when '--help', '-h'
54
- args.shift
55
- print_help
56
-
57
- self.exit_status_code = 0
58
- break
59
- when '--jvm'
60
- args.shift
61
- state.set_jvm_version(args.shift)
62
- when '-I'
63
- args.shift
64
- $: << args.shift
65
- when '--plugin', '-p'
66
- args.shift
67
- plugin = args.shift
68
- require "mirah/plugin/#{plugin}"
69
- when '--verbose', '-V'
70
- Mirah::Logging::MirahLogger.level = Mirah::Logging::Level::FINE
71
- state.verbose = true
72
- args.shift
73
- when '--vmodule'
74
- args.shift
75
- spec = args.shift
76
- spec.split(',').each do |item|
77
- logger, level = item.split("=")
78
- logger = java.util.logging.Logger.getLogger(logger)
79
- (state.loggers ||= []) << logger
80
- level = java.util.logging.Level.parse(level)
81
- logger.setLevel(level)
82
- end
83
- when '--no-color'
84
- args.shift
85
- Mirah::Logging::MirahHandler.formatter = Mirah::Logging::LogFormatter.new(false)
86
- when '--version', '-v'
87
- args.shift
88
- print_version
89
-
90
- self.exit_status_code = 0 if args.empty?
91
- break
92
- when '--no-save-extensions'
93
- args.shift
94
- state.save_extensions = false
95
- when '--new-backend', '-N'
96
- args.shift
97
- state.compiler_class = Mirah::JVM::Compiler::Backend
98
- when '--new-types', '-T'
99
- args.shift
100
- java_import 'org.mirah.jvm.mirrors.MirrorTypeSystem'
101
- state.type_system = MirrorTypeSystem.new
102
- else
103
- $stderr.puts "unrecognized flag: " + args[0]
104
-
105
- self.exit_status_code = 1
106
- break
107
- end
108
- end
109
-
110
- return if exit?
111
-
112
- state.destination ||= File.join(File.expand_path('.'), '')
113
- state.compiler_class ||= Mirah::JVM::Compiler::JVMBytecode
114
- end
115
-
116
- def print_help
117
- puts help_message
118
- state.help_printed = true
119
- end
120
-
121
- def help_message
122
- "#{$0} [flags] <files or -e SCRIPT>
123
- -c, --classpath PATH\tAdd PATH to the Java classpath for compilation
124
- --bootclasspath PATH\tSet the Java bootclasspath to PATH for compilation
125
- --cd DIR\t\tSwitch to the specified DIR before compilation
126
- -d, --dest DIR\t\tUse DIR as the dir to place the generated class files
127
- -e CODE\t\tCompile or run the inline script following -e
128
- \t\t\t (the class will be named \"DashE\")
129
- --explicit-packages\tRequire explicit 'package' lines in source
130
- -h, --help\t\tPrint this help message
131
- -I DIR\t\tAdd DIR to the Ruby load path before running
132
- --jvm VERSION\t\tEmit JVM bytecode targeting specified JVM
133
- \t\t\t version (1.4, 1.5, 1.6, 1.7)
134
- --no-save-extensions\tDon't write macro classes to files
135
- --no-color\t\tDon't use color when writing logs
136
- -N, --new-backend\tUse the new backend
137
- -T, --new-types\tUse the new type system
138
- -p, --plugin PLUGIN\trequire 'mirah/plugin/PLUGIN' before running
139
- -v, --version\t\tPrint the version of Mirah to the console
140
- -V, --verbose\t\tVerbose logging
141
- --vmodule logger.name=LEVEL[,...]\t\tSet the Level for the specified Java loggers"
142
- end
143
-
144
- def print_version
145
- puts "Mirah v#{Mirah::VERSION}"
146
- state.version_printed = true
147
- end
148
- end
149
- end
150
- end