mirah 0.0.4-java → 0.0.5-java
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +23 -0
- data/README.txt +13 -5
- data/Rakefile +30 -2
- data/bin/duby +16 -0
- data/bin/dubyc +16 -0
- data/bin/dubyp +16 -0
- data/bin/jrubyp +16 -0
- data/bin/mirah +17 -1
- data/bin/mirah.cmd +15 -0
- data/bin/mirahc +17 -1
- data/bin/mirahc.cmd +16 -1
- data/bin/mirahp +17 -1
- data/bin/mirahp.cmd +16 -1
- data/examples/appengine/Rakefile +17 -2
- data/examples/appengine/src/org/mirah/MirahApp.mirah +15 -0
- data/examples/bintrees.mirah +15 -0
- data/examples/construction.mirah +15 -0
- data/examples/dynamic.mirah +15 -0
- data/examples/edb.mirah +15 -0
- data/examples/fib.mirah +15 -0
- data/examples/fields.mirah +15 -0
- data/examples/fractal.mirah +15 -0
- data/examples/java_thing.mirah +15 -0
- data/examples/plugins/appengine/Rakefile +19 -4
- data/examples/plugins/appengine/lib/com/google/appengine/ext/duby/db/datastore.rb +21 -6
- data/examples/plugins/appengine/src/com/google/appengine/ext/duby/db/Model.duby +15 -0
- data/examples/plugins/appengine/test/com/google/appengine/ext/duby/db/ModelTest.duby +15 -0
- data/examples/simple_class.mirah +16 -1
- data/examples/sort_closure.mirah +15 -0
- data/examples/swing.mirah +17 -2
- data/examples/tak.mirah +15 -0
- data/examples/wiki/Rakefile +17 -2
- data/examples/wiki/src/org/mirah/wiki/MirahWiki.duby +15 -0
- data/examples/wiki/war/src/org/mirah/wiki/MirahWiki.duby +339 -0
- data/examples/wiki/war/src/org/mirah/wiki/edit.eduby.html +42 -0
- data/examples/wiki/war/src/org/mirah/wiki/error.eduby.html +2 -0
- data/examples/wiki/war/src/org/mirah/wiki/layout.eduby.html +69 -0
- data/examples/wiki/war/src/org/mirah/wiki/parser.eduby.html +7 -0
- data/examples/wiki/war/src/org/mirah/wiki/view.eduby.html +15 -0
- data/javalib/mirah-bootstrap.jar +0 -0
- data/javalib/mirah-parser.jar +0 -0
- data/lib/duby.rb +15 -0
- data/lib/mirah/appengine_tasks.rb +20 -6
- data/lib/mirah/ast/call.rb +19 -4
- data/lib/mirah/ast/class.rb +19 -4
- data/lib/mirah/ast/flow.rb +16 -1
- data/lib/mirah/ast/intrinsics.rb +36 -21
- data/lib/mirah/ast/literal.rb +16 -1
- data/lib/mirah/ast/local.rb +16 -1
- data/lib/mirah/ast/method.rb +18 -3
- data/lib/mirah/ast/scope.rb +19 -4
- data/lib/mirah/ast/structure.rb +16 -1
- data/lib/mirah/ast/type.rb +24 -9
- data/lib/mirah/ast.rb +24 -9
- data/lib/mirah/compiler.rb +16 -1
- data/lib/mirah/env.rb +16 -1
- data/lib/mirah/jvm/base.rb +18 -3
- data/lib/mirah/jvm/compiler.rb +35 -21
- data/lib/mirah/jvm/method_lookup.rb +16 -1
- data/lib/mirah/jvm/source_compiler.rb +29 -14
- data/lib/mirah/jvm/source_generator/builder.rb +21 -6
- data/lib/mirah/jvm/source_generator/loops.rb +16 -1
- data/lib/mirah/jvm/source_generator/precompile.rb +17 -2
- data/lib/mirah/jvm/source_generator/typer.rb +17 -2
- data/lib/mirah/jvm/typer.rb +19 -4
- data/lib/mirah/jvm/types/basic_types.rb +16 -1
- data/lib/mirah/jvm/types/boolean.rb +17 -2
- data/lib/mirah/jvm/types/enumerable.rb +21 -6
- data/lib/mirah/jvm/types/extensions.rb +16 -1
- data/lib/mirah/jvm/types/factory.rb +18 -3
- data/lib/mirah/jvm/types/floats.rb +16 -1
- data/lib/mirah/jvm/types/integers.rb +22 -7
- data/lib/mirah/jvm/types/intrinsics.rb +29 -14
- data/lib/mirah/jvm/types/literals.rb +16 -1
- data/lib/mirah/jvm/types/methods.rb +24 -9
- data/lib/mirah/jvm/types/number.rb +16 -1
- data/lib/mirah/jvm/types.rb +23 -4
- data/lib/mirah/nbcompiler.rb +19 -4
- data/lib/mirah/plugin/edb.rb +18 -3
- data/lib/mirah/plugin/gwt.rb +22 -7
- data/lib/mirah/plugin/java.rb +18 -3
- data/lib/mirah/transform.rb +35 -20
- data/lib/mirah/transform2.rb +20 -5
- data/lib/mirah/typer.rb +23 -8
- data/lib/mirah/version.rb +18 -0
- data/lib/mirah.rb +101 -50
- data/lib/mirah_task.rb +27 -12
- data/test/test_ast.rb +16 -1
- data/test/test_compilation.rb +18 -3
- data/test/test_env.rb +26 -11
- data/test/test_gwt.rb +18 -3
- data/test/test_java_typer.rb +27 -12
- data/test/test_javac_compiler.rb +17 -2
- data/test/test_jvm_compiler.rb +44 -14
- data/test/test_typer.rb +16 -1
- metadata +203 -193
data/lib/mirah_task.rb
CHANGED
@@ -1,5 +1,20 @@
|
|
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
|
+
|
1
16
|
require 'mirah'
|
2
|
-
module
|
17
|
+
module Mirah
|
3
18
|
class PathArray < Array
|
4
19
|
def <<(value)
|
5
20
|
super(File.expand_path(value))
|
@@ -81,27 +96,27 @@ def mirahc(*files)
|
|
81
96
|
else
|
82
97
|
options = {}
|
83
98
|
end
|
84
|
-
source_dir = options.fetch(:dir,
|
85
|
-
dest = File.expand_path(options.fetch(:dest,
|
99
|
+
source_dir = options.fetch(:dir, Mirah.source_path)
|
100
|
+
dest = File.expand_path(options.fetch(:dest, Mirah.dest_path))
|
86
101
|
files = files.map {|f| f.sub(/^#{source_dir}\//, '')}
|
87
|
-
flags = options.fetch(:options,
|
102
|
+
flags = options.fetch(:options, Mirah.compiler_options)
|
88
103
|
args = ['-d', dest, *flags] + files
|
89
104
|
chdir(source_dir) do
|
90
105
|
puts "mirahc #{args.join ' '}"
|
91
|
-
|
92
|
-
|
106
|
+
Mirah.compile(*args)
|
107
|
+
Mirah.reset
|
93
108
|
end
|
94
109
|
end
|
95
110
|
|
96
|
-
rule '.java' => [proc {|n|
|
111
|
+
rule '.java' => [proc {|n| Mirah.dest_to_source_path(n)}] do |t|
|
97
112
|
mirahc(t.source,
|
98
|
-
:dir=>
|
99
|
-
:dest=>
|
113
|
+
:dir=>Mirah.find_source(t.source),
|
114
|
+
:dest=>Mirah.find_dest(t.name),
|
100
115
|
:options=>['-java'])
|
101
116
|
end
|
102
117
|
|
103
|
-
rule '.class' => [proc {|n|
|
118
|
+
rule '.class' => [proc {|n| Mirah.dest_to_source_path(n)}] do |t|
|
104
119
|
mirahc(t.source,
|
105
|
-
:dir=>
|
106
|
-
:dest=>
|
120
|
+
:dir=>Mirah.find_source(t.source),
|
121
|
+
:dest=>Mirah.find_dest(t.name))
|
107
122
|
end
|
data/test/test_ast.rb
CHANGED
@@ -1,9 +1,24 @@
|
|
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
|
+
|
1
16
|
require 'mirah'
|
2
17
|
require 'test/unit'
|
3
18
|
require 'jruby'
|
4
19
|
|
5
20
|
class TestAst < Test::Unit::TestCase
|
6
|
-
include
|
21
|
+
include Mirah
|
7
22
|
|
8
23
|
def test_args
|
9
24
|
new_ast = AST.parse("def foo(a, *c, &d); end").body[0]
|
data/test/test_compilation.rb
CHANGED
@@ -1,10 +1,25 @@
|
|
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
|
+
|
1
16
|
require 'mirah'
|
2
17
|
require 'mirah/compiler'
|
3
18
|
require 'test/unit'
|
4
19
|
require 'jruby'
|
5
20
|
|
6
21
|
class TestAst < Test::Unit::TestCase
|
7
|
-
include
|
22
|
+
include Mirah
|
8
23
|
|
9
24
|
class MockCompiler
|
10
25
|
attr_accessor :calls
|
@@ -81,7 +96,7 @@ class TestAst < Test::Unit::TestCase
|
|
81
96
|
|
82
97
|
new_ast.compile(@compiler, true)
|
83
98
|
|
84
|
-
assert_equal([[:local_assign, a(
|
99
|
+
assert_equal([[:local_assign, a(Mirah::AST::StaticScope), "a", nil, true, AST.fixnum(nil, nil, 1)]], @compiler.calls)
|
85
100
|
end
|
86
101
|
|
87
102
|
def test_local_typed
|
@@ -90,7 +105,7 @@ class TestAst < Test::Unit::TestCase
|
|
90
105
|
new_ast.infer(typer)
|
91
106
|
new_ast.compile(@compiler, true)
|
92
107
|
|
93
|
-
assert_equal([[:local_assign, a(
|
108
|
+
assert_equal([[:local_assign, a(Mirah::AST::StaticScope), "a", AST.type(nil, :fixnum), true, AST.fixnum(nil, nil, 1)]], @compiler.calls)
|
94
109
|
end
|
95
110
|
|
96
111
|
def test_return
|
data/test/test_env.rb
CHANGED
@@ -1,42 +1,57 @@
|
|
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
|
+
|
1
16
|
require 'test/unit'
|
2
17
|
require 'mirah'
|
3
18
|
|
4
19
|
class TestEnv < Test::Unit::TestCase
|
5
|
-
include
|
20
|
+
include Mirah
|
6
21
|
|
7
22
|
def test_path_seperator
|
8
23
|
# Check that env var PATH_SEPERATOR is used
|
9
24
|
RbConfig::CONFIG['PATH_SEPARATOR'] = '*'
|
10
|
-
assert_equal('*',
|
25
|
+
assert_equal('*', Mirah::Env.path_seperator)
|
11
26
|
|
12
27
|
# Check that : (colon) is returned if no PATH_SEPERATOR env var set
|
13
28
|
RbConfig::CONFIG['PATH_SEPARATOR'] = ''
|
14
|
-
assert_equal(':',
|
29
|
+
assert_equal(':', Mirah::Env.path_seperator)
|
15
30
|
end
|
16
31
|
|
17
32
|
def test_encode_paths
|
18
33
|
RbConfig::CONFIG['PATH_SEPARATOR'] = ':'
|
19
34
|
|
20
|
-
assert_equal('a:b:c',
|
21
|
-
assert_equal('a',
|
22
|
-
assert_equal('',
|
35
|
+
assert_equal('a:b:c', Mirah::Env.encode_paths(['a','b','c']))
|
36
|
+
assert_equal('a', Mirah::Env.encode_paths(['a']))
|
37
|
+
assert_equal('', Mirah::Env.encode_paths([]))
|
23
38
|
|
24
39
|
RbConfig::CONFIG['PATH_SEPARATOR'] = ';'
|
25
40
|
|
26
|
-
assert_equal('a;b;c',
|
41
|
+
assert_equal('a;b;c', Mirah::Env.encode_paths(['a','b','c']))
|
27
42
|
end
|
28
43
|
|
29
44
|
def test_decode_paths
|
30
45
|
RbConfig::CONFIG['PATH_SEPARATOR'] = ':'
|
31
46
|
|
32
47
|
path_array = ['1','2']
|
33
|
-
assert_equal(['1','2','a','b','c','d'],
|
48
|
+
assert_equal(['1','2','a','b','c','d'], Mirah::Env.decode_paths('a:b:c:d', path_array))
|
34
49
|
assert_equal(['1','2','a','b','c','d'], path_array)
|
35
50
|
|
36
|
-
assert_equal(['a','b','c','d'],
|
37
|
-
assert_equal(['a'],
|
51
|
+
assert_equal(['a','b','c','d'], Mirah::Env.decode_paths('a:b:c:d'))
|
52
|
+
assert_equal(['a'], Mirah::Env.decode_paths('a'))
|
38
53
|
|
39
54
|
RbConfig::CONFIG['PATH_SEPARATOR'] = ';'
|
40
|
-
assert_equal(['a','b','c','d'],
|
55
|
+
assert_equal(['a','b','c','d'], Mirah::Env.decode_paths('a;b;c;d'))
|
41
56
|
end
|
42
57
|
end
|
data/test/test_gwt.rb
CHANGED
@@ -1,3 +1,18 @@
|
|
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
|
+
|
1
16
|
$:.unshift File.join(File.dirname(__FILE__),'..','lib')
|
2
17
|
|
3
18
|
require 'test/unit'
|
@@ -5,7 +20,7 @@ require 'mirah'
|
|
5
20
|
require 'jruby'
|
6
21
|
|
7
22
|
class TestGWT < Test::Unit::TestCase
|
8
|
-
include
|
23
|
+
include Mirah::AST
|
9
24
|
|
10
25
|
def test_jsni_static
|
11
26
|
new_ast = parse("def_jsni void, _log(), 'hi'").body[0]
|
@@ -33,7 +48,7 @@ class TestGWT < Test::Unit::TestCase
|
|
33
48
|
assert_equal(body, 'hi')
|
34
49
|
|
35
50
|
signature = new_ast.signature
|
36
|
-
return_type = signature[:return] ==
|
51
|
+
return_type = signature[:return] == Mirah::AST::TypeReference.new('void')
|
37
52
|
assert_equal(return_type, true)
|
38
53
|
|
39
54
|
has_arguments = new_ast.arguments.args
|
@@ -43,7 +58,7 @@ class TestGWT < Test::Unit::TestCase
|
|
43
58
|
def test_jsni_one_arg
|
44
59
|
new_ast = parse("def_jsni void, _log(message:Object), 'hi'").body[0]
|
45
60
|
|
46
|
-
message_type = new_ast.signature[:message] ==
|
61
|
+
message_type = new_ast.signature[:message] == Mirah::AST::TypeReference.new('Object')
|
47
62
|
assert_equal(message_type, true)
|
48
63
|
|
49
64
|
arg_size = new_ast.arguments.args.size
|
data/test/test_java_typer.rb
CHANGED
@@ -1,3 +1,18 @@
|
|
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
|
+
|
1
16
|
$:.unshift File.join(File.dirname(__FILE__),'..','lib')
|
2
17
|
|
3
18
|
require 'test/unit'
|
@@ -7,12 +22,12 @@ require 'mirah/jvm/compiler'
|
|
7
22
|
require 'mirah/jvm/typer'
|
8
23
|
|
9
24
|
class TestJavaTyper < Test::Unit::TestCase
|
10
|
-
include
|
25
|
+
include Mirah
|
11
26
|
|
12
27
|
def setup
|
13
|
-
AST.type_factory =
|
28
|
+
AST.type_factory = Mirah::JVM::Types::TypeFactory.new
|
14
29
|
@typer = Typer::JVM.new(nil)
|
15
|
-
compiler =
|
30
|
+
compiler = Mirah::Compiler::JVM.new
|
16
31
|
|
17
32
|
@java_typer = Typer::JavaTyper.new
|
18
33
|
end
|
@@ -77,7 +92,7 @@ class TestJavaTyper < Test::Unit::TestCase
|
|
77
92
|
end
|
78
93
|
end
|
79
94
|
|
80
|
-
include
|
95
|
+
include Mirah::JVM::MethodLookup
|
81
96
|
|
82
97
|
def test_is_more_specific
|
83
98
|
object = java.lang.Object.java_class
|
@@ -90,14 +105,14 @@ class TestJavaTyper < Test::Unit::TestCase
|
|
90
105
|
end
|
91
106
|
|
92
107
|
def test_primitive_convertible
|
93
|
-
boolean =
|
94
|
-
byte =
|
95
|
-
short =
|
96
|
-
char =
|
97
|
-
int =
|
98
|
-
long =
|
99
|
-
float =
|
100
|
-
double =
|
108
|
+
boolean = Mirah::JVM::Types::Boolean
|
109
|
+
byte = Mirah::JVM::Types::Byte
|
110
|
+
short = Mirah::JVM::Types::Short
|
111
|
+
char = Mirah::JVM::Types::Char
|
112
|
+
int = Mirah::JVM::Types::Int
|
113
|
+
long = Mirah::JVM::Types::Long
|
114
|
+
float = Mirah::JVM::Types::Float
|
115
|
+
double = Mirah::JVM::Types::Double
|
101
116
|
|
102
117
|
assert !primitive_convertible?(boolean, byte)
|
103
118
|
assert !primitive_convertible?(boolean, short)
|
data/test/test_javac_compiler.rb
CHANGED
@@ -1,3 +1,18 @@
|
|
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
|
+
|
1
16
|
$:.unshift File.join(File.dirname(__FILE__),'..','lib')
|
2
17
|
|
3
18
|
require 'test/unit'
|
@@ -39,8 +54,8 @@ class TestJavacCompiler < TestJVMCompiler
|
|
39
54
|
def compile(code)
|
40
55
|
File.unlink(*@tmp_classes)
|
41
56
|
@tmp_classes.clear
|
42
|
-
AST.type_factory =
|
43
|
-
transformer =
|
57
|
+
AST.type_factory = Mirah::JVM::Types::TypeFactory.new
|
58
|
+
transformer = Mirah::Transform::Transformer.new(Mirah::CompilationState.new)
|
44
59
|
Java::MirahImpl::Builtin.initialize_builtins(transformer)
|
45
60
|
name = "script" + System.nano_time.to_s
|
46
61
|
ast = AST.parse(code, name, true, transformer)
|
data/test/test_jvm_compiler.rb
CHANGED
@@ -1,3 +1,18 @@
|
|
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
|
+
|
1
16
|
$:.unshift File.join(File.dirname(__FILE__),'..','lib')
|
2
17
|
|
3
18
|
require 'test/unit'
|
@@ -6,13 +21,13 @@ require 'jruby'
|
|
6
21
|
require 'stringio'
|
7
22
|
require 'fileutils'
|
8
23
|
|
9
|
-
unless
|
10
|
-
|
11
|
-
|
24
|
+
unless Mirah::AST.macro "__gloop__"
|
25
|
+
Mirah::AST.defmacro "__gloop__" do |transformer, fcall, parent|
|
26
|
+
Mirah::AST::Loop.new(parent, parent.position, true, false) do |loop|
|
12
27
|
init, condition, check_first, pre, post = fcall.parameters
|
13
28
|
loop.check_first = check_first.literal
|
14
29
|
|
15
|
-
nil_t =
|
30
|
+
nil_t = Mirah::AST::Null
|
16
31
|
loop.init = init
|
17
32
|
loop.pre = pre
|
18
33
|
loop.post = post
|
@@ -20,7 +35,7 @@ unless Duby::AST.macro "__gloop__"
|
|
20
35
|
body = fcall.block.body
|
21
36
|
body.parent = loop
|
22
37
|
[
|
23
|
-
|
38
|
+
Mirah::AST::Condition.new(loop, parent.position) do |c|
|
24
39
|
condition.parent = c
|
25
40
|
[condition]
|
26
41
|
end,
|
@@ -31,7 +46,7 @@ unless Duby::AST.macro "__gloop__"
|
|
31
46
|
end
|
32
47
|
|
33
48
|
class TestJVMCompiler < Test::Unit::TestCase
|
34
|
-
include
|
49
|
+
include Mirah
|
35
50
|
import java.lang.System
|
36
51
|
import java.io.PrintStream
|
37
52
|
|
@@ -54,9 +69,9 @@ class TestJVMCompiler < Test::Unit::TestCase
|
|
54
69
|
def compile(code)
|
55
70
|
File.unlink(*@tmp_classes)
|
56
71
|
@tmp_classes.clear
|
57
|
-
AST.type_factory =
|
72
|
+
AST.type_factory = Mirah::JVM::Types::TypeFactory.new
|
58
73
|
name = "script" + System.nano_time.to_s
|
59
|
-
transformer =
|
74
|
+
transformer = Mirah::Transform::Transformer.new(Mirah::CompilationState.new)
|
60
75
|
Java::MirahImpl::Builtin.initialize_builtins(transformer)
|
61
76
|
ast = AST.parse(code, name, true, transformer)
|
62
77
|
typer = Typer::JVM.new(transformer)
|
@@ -65,7 +80,7 @@ class TestJVMCompiler < Test::Unit::TestCase
|
|
65
80
|
compiler = Compiler::JVM.new
|
66
81
|
compiler.compile(ast)
|
67
82
|
classes = {}
|
68
|
-
loader =
|
83
|
+
loader = MirahClassLoader.new(JRuby.runtime.jruby_class_loader, classes)
|
69
84
|
compiler.generate do |name, builder|
|
70
85
|
bytes = builder.generate
|
71
86
|
FileUtils.mkdir_p(File.dirname(name))
|
@@ -787,6 +802,14 @@ class TestJVMCompiler < Test::Unit::TestCase
|
|
787
802
|
def a
|
788
803
|
@a
|
789
804
|
end
|
805
|
+
|
806
|
+
def self.set_b(b:fixnum)
|
807
|
+
@@b = b
|
808
|
+
end
|
809
|
+
|
810
|
+
def b
|
811
|
+
@@b
|
812
|
+
end
|
790
813
|
end
|
791
814
|
EOF
|
792
815
|
first = cls.new(1)
|
@@ -795,6 +818,13 @@ class TestJVMCompiler < Test::Unit::TestCase
|
|
795
818
|
second = cls.new(2)
|
796
819
|
assert_equal(1, first.a)
|
797
820
|
assert_equal(2, second.a)
|
821
|
+
|
822
|
+
cls.set_b 0
|
823
|
+
assert_equal(0, first.b)
|
824
|
+
assert_equal(0, second.b)
|
825
|
+
assert_equal(1, cls.set_b(1))
|
826
|
+
assert_equal(1, first.b)
|
827
|
+
assert_equal(1, second.b)
|
798
828
|
end
|
799
829
|
|
800
830
|
def test_object_intrinsics
|
@@ -894,7 +924,7 @@ class TestJVMCompiler < Test::Unit::TestCase
|
|
894
924
|
assert_equal('B', b.java_class.name)
|
895
925
|
assert_equal('C', c.java_class.name)
|
896
926
|
|
897
|
-
assert_raise
|
927
|
+
assert_raise Mirah::Typer::InferenceError do
|
898
928
|
compile(<<-EOF)
|
899
929
|
interface A do
|
900
930
|
def a
|
@@ -911,12 +941,12 @@ class TestJVMCompiler < Test::Unit::TestCase
|
|
911
941
|
end
|
912
942
|
end
|
913
943
|
|
914
|
-
def assert_throw(type, message=
|
944
|
+
def assert_throw(type, message="")
|
915
945
|
ex = assert_raise(NativeException) do
|
916
946
|
yield
|
917
947
|
end
|
918
948
|
assert_equal type, ex.cause.class
|
919
|
-
assert_equal message, ex.cause.message
|
949
|
+
assert_equal message, ex.cause.message.to_s
|
920
950
|
end
|
921
951
|
|
922
952
|
def test_raise
|
@@ -2489,7 +2519,7 @@ class TestJVMCompiler < Test::Unit::TestCase
|
|
2489
2519
|
end
|
2490
2520
|
|
2491
2521
|
def test_return_type
|
2492
|
-
assert_raise
|
2522
|
+
assert_raise Mirah::Typer::InferenceError do
|
2493
2523
|
compile(<<-EOF)
|
2494
2524
|
class ReturnsA
|
2495
2525
|
def a:int
|
@@ -2499,7 +2529,7 @@ class TestJVMCompiler < Test::Unit::TestCase
|
|
2499
2529
|
EOF
|
2500
2530
|
end
|
2501
2531
|
|
2502
|
-
assert_raise
|
2532
|
+
assert_raise Mirah::Typer::InferenceError do
|
2503
2533
|
compile(<<-EOF)
|
2504
2534
|
class ReturnsB
|
2505
2535
|
def self.a:String
|
data/test/test_typer.rb
CHANGED
@@ -1,8 +1,23 @@
|
|
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
|
+
|
1
16
|
require 'test/unit'
|
2
17
|
require 'mirah'
|
3
18
|
|
4
19
|
class TestTyper < Test::Unit::TestCase
|
5
|
-
include
|
20
|
+
include Mirah
|
6
21
|
|
7
22
|
def test_fixnum
|
8
23
|
ast = AST.parse("1")
|