mirah 0.1.4-java → 0.2.0-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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +0 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/History.txt +531 -0
- data/README.md +23 -10
- data/Rakefile +239 -156
- data/TODO.md +71 -10
- data/bin/mirah +1 -1
- data/bin/mirahc +1 -1
- data/dist/mirahc.jar +0 -0
- data/examples/bintrees.mirah +2 -2
- data/examples/construction.mirah +2 -2
- data/examples/fields.mirah +1 -1
- data/examples/fractal.mirah +1 -1
- data/examples/fractal.rb +70 -0
- data/examples/interfaces.mirah +1 -1
- data/examples/java_thing.mirah +1 -1
- data/examples/macros/square.mirah +3 -3
- data/examples/macros/square_int.mirah +3 -3
- data/examples/macros/string_each_char.mirah +6 -6
- data/examples/rosettacode/100-doors.mirah +0 -2
- data/examples/rosettacode/count-occurrences-of-a-substring.mirah +3 -3
- data/examples/rosettacode/empty-string.mirah +1 -1
- data/examples/rosettacode/fizz-buzz.mirah +4 -4
- data/examples/rosettacode/is-string-numeric.mirah +7 -7
- data/examples/rosettacode/palindrome.mirah +2 -2
- data/examples/rosettacode/reverse-a-string.mirah +1 -1
- data/examples/rosettacode/rot-13.mirah +1 -1
- data/examples/{edb.mirah → rosettacode/simple_character_math.mirah} +13 -4
- data/examples/rosettacode/string-case.mirah +2 -2
- data/examples/rosettacode/string-length.mirah +1 -1
- data/examples/swing.mirah +9 -14
- data/extensions_and_macros.md +117 -0
- data/lib/mirah.rb +1 -1
- data/lib/mirah/errors.rb +3 -1
- data/lib/mirah/transform/ast_ext.rb +3 -2
- data/lib/mirah/util/process_errors.rb +1 -2
- data/lib/mirah/version.rb +1 -1
- data/test/A.class +0 -0
- data/test/core/util/jvm_version_test.rb +10 -0
- data/test/core/util/mirah_arguments_test.rb +51 -4
- data/test/fixtures/cp1251_test.mirah +7 -0
- data/test/fixtures/org/foo/AbstractExecutorJava8.java +30 -0
- data/test/fixtures/org/foo/ClassWithSelfReferencingTypeParameter.java +24 -0
- data/test/fixtures/org/foo/InnerInterfaceClass.java +12 -0
- data/test/fixtures/org/foo/IntAnno.class +0 -0
- data/test/fixtures/org/foo/TypeFixtureJava8.java +10 -0
- data/test/fixtures/utf8_test.mirah +7 -0
- data/test/jvm/access_levels_test.rb +31 -0
- data/test/jvm/annotations_test.rb +3 -6
- data/test/jvm/blocks_test.rb +303 -120
- data/test/jvm/cast_test.rb +123 -50
- data/test/jvm/closure_test.rb +242 -0
- data/test/jvm/constructors_test.rb +1 -3
- data/test/jvm/example_test.rb +6 -2
- data/test/jvm/extensions/array_extensions_test.rb +181 -0
- data/test/jvm/extensions/collection_extensions_test.rb +195 -0
- data/test/jvm/{enumerable_test.rb → extensions/enumerable_test.rb} +81 -13
- data/test/jvm/extensions/hash_extensions_test.rb +56 -0
- data/test/jvm/extensions/list_extensions_test.rb +143 -0
- data/test/jvm/extensions/lock_extensions_test.rb +43 -0
- data/test/jvm/{numeric_extensions_test.rb → extensions/numeric_extensions_test.rb} +0 -0
- data/test/jvm/extensions/numeric_operators_test.rb +86 -0
- data/test/jvm/extensions/object_extensions_test.rb +122 -0
- data/test/jvm/{string_builder_extensions_test.rb → extensions/string_builder_extensions_test.rb} +0 -0
- data/test/jvm/{string_extensions_test.rb → extensions/string_extensions_test.rb} +57 -4
- data/test/jvm/generics_test.rb +14 -6
- data/test/jvm/import_test.rb +38 -1
- data/test/jvm/interface_test.rb +17 -0
- data/test/jvm/jvm_commands_test.rb +9 -0
- data/test/jvm/jvm_compiler_test.rb +568 -43
- data/test/jvm/macros_test.rb +343 -19
- data/test/jvm/main_method_test.rb +1 -3
- data/test/jvm/new_backend_test_helper.rb +54 -7
- data/test/jvm/rescue_test.rb +20 -5
- data/test/jvm/static_fields_test.rb +52 -10
- data/test/jvm/{mirror_compilation_test_helper.rb → string_test.rb} +10 -9
- data/test/jvm/varargs_test.rb +6 -16
- data/test/mirrors/base_type_test.rb +20 -7
- data/test/mirrors/bytecode_mirror_test.rb +8 -3
- data/test/mirrors/generics_test.rb +89 -10
- data/test/mirrors/member_test.rb +1 -1
- data/test/mirrors/method_lookup_test.rb +10 -3
- data/test/mirrors/mirrors_test.rb +20 -20
- data/test/mirrors/simple_async_mirror_loader_test.rb +1 -1
- data/test/mirrors/simple_mirror_loader_test.rb +1 -1
- data/test/newMirahClass$Closure2.class +0 -0
- data/test/newMirahClass.class +0 -0
- data/test/test_helper.rb +8 -1
- metadata +31 -16
- data/bin/bundler +0 -16
- data/bin/rake +0 -16
- data/examples/ant/example-build.xml~ +0 -7
- data/examples/test.edb +0 -9
- data/lib/mirah/compiler.rb +0 -67
- data/lib/mirah/parser.rb +0 -224
- data/lib/mirah/util/delegate.rb +0 -65
- data/test/jvm/list_extensions_test.rb +0 -23
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (c)
|
1
|
+
# Copyright (c) 2015 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");
|
@@ -13,6 +13,15 @@
|
|
13
13
|
# See the License for the specific language governing permissions and
|
14
14
|
# limitations under the License.
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
|
17
|
+
# A simple example of counting
|
18
|
+
# the characters in a name. Part of a test
|
19
|
+
# to kick the tires - @aspleenic
|
20
|
+
|
21
|
+
puts "Enter a name: "
|
22
|
+
|
23
|
+
s = System.console.readLine()
|
24
|
+
puts "The name you entered was #{s}"
|
25
|
+
|
26
|
+
name_length = s.length
|
27
|
+
puts "Your Name is #{name_length} characters long (that includes spaces)"
|
data/examples/swing.mirah
CHANGED
@@ -16,20 +16,15 @@
|
|
16
16
|
import javax.swing.JFrame
|
17
17
|
import javax.swing.JButton
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
def self.run
|
22
|
-
frame = JFrame.new "Welcome to Mirah"
|
23
|
-
frame.setSize 300, 300
|
24
|
-
frame.setVisible true
|
19
|
+
frame = JFrame.new "Welcome to Mirah"
|
20
|
+
frame.setSize 300, 300
|
25
21
|
|
26
|
-
|
27
|
-
|
28
|
-
|
22
|
+
button = JButton.new "Press me"
|
23
|
+
frame.add button
|
24
|
+
frame.show
|
29
25
|
|
30
|
-
|
31
|
-
|
32
|
-
end
|
26
|
+
button.addActionListener do |event|
|
27
|
+
JButton(event.getSource).setText "Mirah Rocks!"
|
33
28
|
end
|
34
|
-
|
35
|
-
|
29
|
+
frame.setVisible true
|
30
|
+
frame.setDefaultCloseOperation JFrame.EXIT_ON_CLOSE
|
@@ -0,0 +1,117 @@
|
|
1
|
+
Extensions and Macros
|
2
|
+
==============
|
3
|
+
|
4
|
+
|
5
|
+
macro compile & load:
|
6
|
+
|
7
|
+
compile klass$Extension1,
|
8
|
+
load klass$Extension1,
|
9
|
+
1..n
|
10
|
+
*hand wave*
|
11
|
+
|
12
|
+
if encounter klass with annotation $Extensions,
|
13
|
+
then
|
14
|
+
- strip $Extensions
|
15
|
+
- create klass$Extensions with just the annotation
|
16
|
+
- compile to macrodest
|
17
|
+
|
18
|
+
compile klass$Extensions referring to Extension1..n, so that it can be loaded from bytecode later
|
19
|
+
|
20
|
+
|
21
|
+
macro load from bytecode:
|
22
|
+
look up klass$Extensions
|
23
|
+
gather Extension1..n
|
24
|
+
|
25
|
+
Maybe could do:
|
26
|
+
|
27
|
+
klass$Extensions
|
28
|
+
klass$Extensions$Macro1
|
29
|
+
|
30
|
+
instead of Extension...
|
31
|
+
|
32
|
+
$Extensions(....)
|
33
|
+
class klass$Extensions
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
#-------
|
39
|
+
|
40
|
+
|
41
|
+
extension compile &load
|
42
|
+
|
43
|
+
extension AExt
|
44
|
+
for_class A
|
45
|
+
|
46
|
+
def aa: String
|
47
|
+
toString
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
transform ->
|
52
|
+
|
53
|
+
|
54
|
+
class AExt
|
55
|
+
def self.aa(zelf: A)
|
56
|
+
zelf.toString
|
57
|
+
end
|
58
|
+
|
59
|
+
macro def aa
|
60
|
+
quote {`@call.target`.toString}
|
61
|
+
end
|
62
|
+
macro_register A
|
63
|
+
end
|
64
|
+
|
65
|
+
$Extensions[....]
|
66
|
+
class AExt$Extensions;end
|
67
|
+
|
68
|
+
compile
|
69
|
+
|
70
|
+
macro loading:
|
71
|
+
|
72
|
+
load klass
|
73
|
+
look in macroclasspath for klass$mirahExtensions, which has references to all the extensions
|
74
|
+
|
75
|
+
|
76
|
+
class A
|
77
|
+
macro def a
|
78
|
+
quote { puts "a" }
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
->
|
83
|
+
|
84
|
+
options:
|
85
|
+
->
|
86
|
+
$Extensions[A$Extension1]
|
87
|
+
class A
|
88
|
+
#...
|
89
|
+
end
|
90
|
+
|
91
|
+
-> $Extensions ->
|
92
|
+
|
93
|
+
mirah -d classes --macro-dest macro-classes
|
94
|
+
classes/A.class
|
95
|
+
macro-classes/A$mirahExtensions.class
|
96
|
+
macro-classes/A$Extension1.class
|
97
|
+
|
98
|
+
loading macros / extensions
|
99
|
+
|
100
|
+
|
101
|
+
macros on classpath
|
102
|
+
macros on macroclasspath
|
103
|
+
extensions on classpath
|
104
|
+
extensions on macroclasspath
|
105
|
+
|
106
|
+
|
107
|
+
extension decomposition
|
108
|
+
|
109
|
+
extension Foo of String
|
110
|
+
def hello
|
111
|
+
puts "hello, #{self}"
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
->
|
116
|
+
|
117
|
+
class
|
data/lib/mirah.rb
CHANGED
@@ -16,7 +16,7 @@
|
|
16
16
|
require 'fileutils'
|
17
17
|
require 'rbconfig'
|
18
18
|
|
19
|
-
$CLASSPATH << File.
|
19
|
+
$CLASSPATH << ENV.fetch('MIRAHC_JAR',File.expand_path("../../dist/mirahc.jar",__FILE__))
|
20
20
|
|
21
21
|
require 'mirah/version'
|
22
22
|
require 'mirah/transform'
|
data/lib/mirah/errors.rb
CHANGED
@@ -16,11 +16,13 @@
|
|
16
16
|
module Mirah
|
17
17
|
class MirahError < StandardError
|
18
18
|
attr_accessor :position
|
19
|
+
attr_accessor :diagnostic
|
19
20
|
attr_accessor :cause
|
20
21
|
|
21
|
-
def initialize(message, position=nil)
|
22
|
+
def initialize(message, position=nil, diagnostic=nil)
|
22
23
|
super(message)
|
23
24
|
@position = position
|
25
|
+
@diagnostic = diagnostic
|
24
26
|
end
|
25
27
|
|
26
28
|
def inspect
|
@@ -16,10 +16,11 @@ module Mirah
|
|
16
16
|
#filename = transformer.tag_filename(src, filename)
|
17
17
|
parser = MirahParser.new
|
18
18
|
source = StringCodeSource.new(filename, src)
|
19
|
-
|
19
|
+
diagnostics = SimpleDiagnostics.new(true)
|
20
|
+
# parser.diagnostics = diagnostics # Field "diagnostics" does not seem to exist in the current mirah/mmeta source code, but it did exist in an ancient mmeta.jar.
|
20
21
|
begin
|
21
22
|
ast = parser.parse(source)
|
22
|
-
if
|
23
|
+
if diagnostics.error_count > 0
|
23
24
|
puts "#{parser.diagnostics.error_count} errors, exiting"
|
24
25
|
throw :exit, 1
|
25
26
|
end
|
@@ -51,8 +51,7 @@ module Mirah
|
|
51
51
|
@typer = typer
|
52
52
|
end
|
53
53
|
def exitDefault(node, arg)
|
54
|
-
type = @typer.
|
55
|
-
type = type.resolve if type
|
54
|
+
type = @typer.getResolvedType(node)
|
56
55
|
if (type && type.isError)
|
57
56
|
@errors[type] ||= begin
|
58
57
|
if type.message.size == 1
|
data/lib/mirah/version.rb
CHANGED
data/test/A.class
ADDED
Binary file
|
@@ -36,6 +36,16 @@ class JvmVersionTest < Test::Unit::TestCase
|
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
|
+
def test_java_8_supports_default_methods
|
40
|
+
jvm_version = JvmVersion.new "1.8"
|
41
|
+
assert jvm_version.supports_default_interface_methods
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_java_7_does_not_support_default_methods
|
45
|
+
jvm_version = JvmVersion.new "1.7"
|
46
|
+
assert !jvm_version.supports_default_interface_methods
|
47
|
+
end
|
48
|
+
|
39
49
|
def opcode spec_version
|
40
50
|
Opcodes.const_get("V#{spec_version.sub('.','_')}")
|
41
51
|
end
|
@@ -16,6 +16,8 @@ require 'test_helper'
|
|
16
16
|
|
17
17
|
class MirahArgumentsTest < Test::Unit::TestCase
|
18
18
|
java_import 'org.mirah.tool.MirahArguments'
|
19
|
+
java_import 'java.io.File'
|
20
|
+
|
19
21
|
def test_arg_dash_v_prints_version_and_has_exit_0
|
20
22
|
arg_processor = MirahArguments.new
|
21
23
|
|
@@ -27,7 +29,6 @@ class MirahArgumentsTest < Test::Unit::TestCase
|
|
27
29
|
assert_equal 0, arg_processor.exit_status
|
28
30
|
end
|
29
31
|
|
30
|
-
|
31
32
|
def test_on_invalid_arg_prints_error_and_exits_1
|
32
33
|
arg_processor = MirahArguments.new
|
33
34
|
|
@@ -40,13 +41,52 @@ class MirahArgumentsTest < Test::Unit::TestCase
|
|
40
41
|
end
|
41
42
|
|
42
43
|
def test_arg_bootclasspath_sets_bootclasspath_with_absolute_paths
|
43
|
-
path =
|
44
|
+
path = Mirah::Env.encode_paths %w[class path]
|
44
45
|
arg_processor = MirahArguments.new
|
45
46
|
|
46
47
|
arg_processor.apply_args ["--bootclasspath", path]
|
47
48
|
|
48
|
-
|
49
|
-
arg_processor.real_bootclasspath
|
49
|
+
assert_equal_classpaths path,
|
50
|
+
arg_processor.real_bootclasspath
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_flag_classpath_overrides_env
|
54
|
+
env = { "CLASSPATH" => Mirah::Env.encode_paths(%w[some classpath]) }
|
55
|
+
|
56
|
+
path = Mirah::Env.encode_paths %w[class path]
|
57
|
+
|
58
|
+
arg_processor = MirahArguments.new env
|
59
|
+
arg_processor.apply_args ["--classpath", path]
|
60
|
+
|
61
|
+
assert_equal_classpaths path,
|
62
|
+
arg_processor.real_classpath
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_classpath_is_from_env_without_flag
|
66
|
+
path = Mirah::Env.encode_paths %w[class path]
|
67
|
+
env = { "CLASSPATH" => path }
|
68
|
+
|
69
|
+
arg_processor = MirahArguments.new env
|
70
|
+
arg_processor.apply_args []
|
71
|
+
|
72
|
+
assert_equal_classpaths path,
|
73
|
+
arg_processor.real_classpath
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_classpath_defaults_to_cwd
|
77
|
+
arg_processor = MirahArguments.new({})
|
78
|
+
arg_processor.apply_args []
|
79
|
+
|
80
|
+
assert_equal_classpaths ".",
|
81
|
+
arg_processor.real_classpath
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_classpath_is_destination_when_no_flag_or_env
|
85
|
+
arg_processor = MirahArguments.new({})
|
86
|
+
arg_processor.apply_args ["-d", "some/path"]
|
87
|
+
|
88
|
+
assert_equal_classpaths "some/path",
|
89
|
+
arg_processor.real_classpath
|
50
90
|
end
|
51
91
|
|
52
92
|
def test_dash_h_prints_help_and_exits
|
@@ -62,4 +102,11 @@ class MirahArgumentsTest < Test::Unit::TestCase
|
|
62
102
|
assert arg_processor.exit?
|
63
103
|
assert_equal 0, arg_processor.exit_status
|
64
104
|
end
|
105
|
+
|
106
|
+
def assert_equal_classpaths expected, actual_classpath_list
|
107
|
+
normalized_expected = Mirah::Env.decode_paths(expected).
|
108
|
+
map { |p| "#{File.new(::File.expand_path(p)).toURI.toURL}#{"./" if p == "." }" }
|
109
|
+
assert_equal Mirah::Env.encode_paths(normalized_expected),
|
110
|
+
Mirah::Env.encode_paths(actual_classpath_list.map{ |u| u.to_s })
|
111
|
+
end
|
65
112
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
/*
|
2
|
+
Copyright (c) 2015 The Mirah project authors. All Rights Reserved.
|
3
|
+
All contributing project authors may be found in the NOTICE file.
|
4
|
+
|
5
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
you may not use this file except in compliance with the License.
|
7
|
+
You may obtain a copy of the License at
|
8
|
+
|
9
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
|
11
|
+
Unless required by applicable law or agreed to in writing, software
|
12
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
See the License for the specific language governing permissions and
|
15
|
+
limitations under the License.
|
16
|
+
*/
|
17
|
+
package org.foo;
|
18
|
+
|
19
|
+
import java.util.Arrays;
|
20
|
+
|
21
|
+
public abstract class AbstractExecutorJava8 {
|
22
|
+
|
23
|
+
public abstract void execute();
|
24
|
+
|
25
|
+
public static void execute(AbstractExecutorJava8 o){
|
26
|
+
//to test inner classes generated by lambda do not prevent abstract method lookup
|
27
|
+
Arrays.asList(1, 2, 3).stream().filter((v) -> v > 1);
|
28
|
+
o.execute();
|
29
|
+
}
|
30
|
+
}
|
@@ -0,0 +1,24 @@
|
|
1
|
+
package org.foo;
|
2
|
+
|
3
|
+
public class ClassWithSelfReferencingTypeParameter<P extends ClassWithSelfReferencingTypeParameter<P>> {
|
4
|
+
|
5
|
+
P self;
|
6
|
+
|
7
|
+
@SuppressWarnings("unchecked")
|
8
|
+
public ClassWithSelfReferencingTypeParameter() {
|
9
|
+
this.self = (P) this;
|
10
|
+
}
|
11
|
+
|
12
|
+
public P foo() {
|
13
|
+
return self;
|
14
|
+
}
|
15
|
+
|
16
|
+
public P bar() {
|
17
|
+
return self;
|
18
|
+
}
|
19
|
+
|
20
|
+
public void baz() {
|
21
|
+
System.out.println("baz");
|
22
|
+
}
|
23
|
+
}
|
24
|
+
|