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
@@ -1,4 +1,19 @@
|
|
1
|
-
|
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
|
+
module Mirah::JVM::Types
|
2
17
|
Boolean = BooleanType.new('boolean', java.lang.Boolean)
|
3
18
|
Byte = IntegerType.new('byte', java.lang.Byte)
|
4
19
|
Char = IntegerType.new('char', java.lang.Character)
|
@@ -1,4 +1,19 @@
|
|
1
|
-
|
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
|
+
module Mirah::JVM::Types
|
2
17
|
class BooleanType < PrimitiveType
|
3
18
|
def init_value(builder)
|
4
19
|
builder.iconst_0
|
@@ -9,7 +24,7 @@ module Duby::JVM::Types
|
|
9
24
|
end
|
10
25
|
|
11
26
|
def box(builder)
|
12
|
-
box_type =
|
27
|
+
box_type = Mirah::AST::type(nil, 'java.lang.Boolean')
|
13
28
|
builder.invokestatic box_type, "valueOf", [box_type, self]
|
14
29
|
end
|
15
30
|
|
@@ -1,7 +1,22 @@
|
|
1
|
-
|
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
|
+
module Mirah::JVM::Types
|
2
17
|
class Type
|
3
18
|
def expand_each(transformer, call)
|
4
|
-
arg_types = [
|
19
|
+
arg_types = [Mirah::AST.block_type]
|
5
20
|
code = intrinsics['each'][arg_types].return_type
|
6
21
|
code.inline(transformer, call)
|
7
22
|
end
|
@@ -36,11 +51,11 @@ module Duby::JVM::Types
|
|
36
51
|
|
37
52
|
# Loops don't have a return value, so we need somewhere to
|
38
53
|
# put the result.
|
39
|
-
result =
|
54
|
+
result = Mirah::AST::Body.new(call.parent, call.position)
|
40
55
|
result << forloop << transformer.eval("#{all}", '', nil, all)
|
41
56
|
end
|
42
57
|
add_macro('all?', &all_proc)
|
43
|
-
add_macro('all?',
|
58
|
+
add_macro('all?', Mirah::AST.block_type, &all_proc)
|
44
59
|
|
45
60
|
any_proc = proc do |transformer, call|
|
46
61
|
if !call.block
|
@@ -55,11 +70,11 @@ module Duby::JVM::Types
|
|
55
70
|
body.condition.predicate = call.block.body
|
56
71
|
forloop.body = call.block.body.parent = body
|
57
72
|
|
58
|
-
result =
|
73
|
+
result = Mirah::AST::Body.new(call.parent, call.position)
|
59
74
|
result << forloop << transformer.eval("#{any}", '', nil, any)
|
60
75
|
end
|
61
76
|
add_macro('any?', &any_proc)
|
62
|
-
add_macro('any?',
|
77
|
+
add_macro('any?', Mirah::AST.block_type, &any_proc)
|
63
78
|
end
|
64
79
|
end
|
65
80
|
end
|
@@ -1,6 +1,21 @@
|
|
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 'delegate'
|
2
17
|
|
3
|
-
module
|
18
|
+
module Mirah::JVM::Types
|
4
19
|
class ExtendedType < DelegateClass(Type)
|
5
20
|
def initialize(*args)
|
6
21
|
super
|
@@ -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 'jruby'
|
2
|
-
module
|
17
|
+
module Mirah::JVM::Types
|
3
18
|
class TypeFactory
|
4
19
|
BASIC_TYPES = {
|
5
20
|
"boolean" => Boolean,
|
@@ -45,7 +60,7 @@ module Duby::JVM::Types
|
|
45
60
|
def initialize_copy(other)
|
46
61
|
@known_types = other.known_types.dup
|
47
62
|
@known_types.delete_if do |key, value|
|
48
|
-
value.basic_type.kind_of?(
|
63
|
+
value.basic_type.kind_of?(Mirah::JVM::Types::TypeDefinition)
|
49
64
|
end
|
50
65
|
@declarations = []
|
51
66
|
end
|
@@ -160,7 +175,7 @@ module Duby::JVM::Types
|
|
160
175
|
existing.node ||= node
|
161
176
|
existing
|
162
177
|
else
|
163
|
-
if
|
178
|
+
if Mirah::AST::InterfaceDeclaration === node
|
164
179
|
klass = InterfaceDefinition
|
165
180
|
else
|
166
181
|
klass = TypeDefinition
|
@@ -1,4 +1,19 @@
|
|
1
|
-
|
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
|
+
module Mirah::JVM::Types
|
2
17
|
class FloatType < Number
|
3
18
|
def prefix
|
4
19
|
'f'
|
@@ -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
|
class BiteScript::MethodBuilder
|
2
17
|
def inot
|
3
18
|
iconst_m1
|
@@ -13,7 +28,7 @@ class BiteScript::MethodBuilder
|
|
13
28
|
end
|
14
29
|
end
|
15
30
|
|
16
|
-
module
|
31
|
+
module Mirah::JVM::Types
|
17
32
|
class IntegerType < Number
|
18
33
|
def literal(builder, value)
|
19
34
|
builder.push_int(value)
|
@@ -68,7 +83,7 @@ module Duby::JVM::Types
|
|
68
83
|
op = "-="
|
69
84
|
end
|
70
85
|
comparison << "=" if inclusive
|
71
|
-
forloop =
|
86
|
+
forloop = Mirah::AST::Loop.new(parent, position, true, false) do |forloop|
|
72
87
|
first, last = duby.tmp, duby.tmp
|
73
88
|
init = duby.eval("#{first} = 0; #{last} = 0;")
|
74
89
|
init.children[-2].value = first_value
|
@@ -82,7 +97,7 @@ module Duby::JVM::Types
|
|
82
97
|
end
|
83
98
|
forloop.post << duby.eval("#{first} #{op} 1")
|
84
99
|
[
|
85
|
-
|
100
|
+
Mirah::AST::Condition.new(forloop, position) do |c|
|
86
101
|
[duby.eval("#{first} #{comparison} #{last}",
|
87
102
|
'', forloop, first, last)]
|
88
103
|
end,
|
@@ -103,17 +118,17 @@ module Duby::JVM::Types
|
|
103
118
|
math_operator('^', 'xor')
|
104
119
|
unary_operator('~', 'not')
|
105
120
|
|
106
|
-
add_macro('downto', Int,
|
121
|
+
add_macro('downto', Int, Mirah::AST.block_type) do |transformer, call|
|
107
122
|
build_loop(call.parent, call.position, transformer,
|
108
123
|
call.block, call.target, call.parameters[0], false, true)
|
109
124
|
end
|
110
|
-
add_macro('upto', Int,
|
125
|
+
add_macro('upto', Int, Mirah::AST.block_type) do |transformer, call|
|
111
126
|
build_loop(call.parent, call.position, transformer,
|
112
127
|
call.block, call.target, call.parameters[0], true, true)
|
113
128
|
end
|
114
|
-
add_macro('times',
|
129
|
+
add_macro('times', Mirah::AST.block_type) do |transformer, call|
|
115
130
|
build_loop(call.parent, call.position, transformer,
|
116
|
-
call.block,
|
131
|
+
call.block, Mirah::AST::fixnum(nil, call.position, 0),
|
117
132
|
call.target, true, false)
|
118
133
|
end
|
119
134
|
end
|
@@ -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
|
require 'bitescript'
|
2
17
|
require 'mirah/jvm/types/enumerable'
|
3
18
|
|
@@ -15,7 +30,7 @@ class BiteScript::MethodBuilder
|
|
15
30
|
end
|
16
31
|
end
|
17
32
|
|
18
|
-
module
|
33
|
+
module Mirah::JVM::Types
|
19
34
|
class Type
|
20
35
|
|
21
36
|
def load(builder, index)
|
@@ -51,7 +66,7 @@ module Duby::JVM::Types
|
|
51
66
|
end
|
52
67
|
|
53
68
|
def add_macro(name, *args, &block)
|
54
|
-
type =
|
69
|
+
type = Mirah::AST::InlineCode.new(&block)
|
55
70
|
intrinsics[name][args] = Intrinsic.new(self, name, args, type) do
|
56
71
|
raise "Macro should be expanded, no called!"
|
57
72
|
end
|
@@ -63,7 +78,7 @@ module Duby::JVM::Types
|
|
63
78
|
ast = expander.expand
|
64
79
|
if ast
|
65
80
|
if call.target
|
66
|
-
body =
|
81
|
+
body = Mirah::AST::ScopedBody.new(call.parent, call.position)
|
67
82
|
body.static_scope.self_type = call.target.inferred_type!
|
68
83
|
body.static_scope.self_node = call.target
|
69
84
|
body << ast
|
@@ -72,7 +87,7 @@ module Duby::JVM::Types
|
|
72
87
|
ast
|
73
88
|
end
|
74
89
|
else
|
75
|
-
|
90
|
+
Mirah::AST::Noop.new(call.parent, call.position)
|
76
91
|
end
|
77
92
|
end
|
78
93
|
end
|
@@ -98,7 +113,7 @@ module Duby::JVM::Types
|
|
98
113
|
def load_extensions(klass=nil)
|
99
114
|
mirror = nil
|
100
115
|
if klass
|
101
|
-
factory =
|
116
|
+
factory = Mirah::AST.type_factory
|
102
117
|
mirror = factory.get_mirror(klass.getName)
|
103
118
|
elsif jvm_type
|
104
119
|
mirror = jvm_type
|
@@ -114,9 +129,9 @@ module Duby::JVM::Types
|
|
114
129
|
types = BiteScript::ASM::Type.get_argument_types(macro['signature'])
|
115
130
|
args = types.map do |type|
|
116
131
|
if type.class_name == 'duby.lang.compiler.Block'
|
117
|
-
|
132
|
+
Mirah::AST::TypeReference::BlockType
|
118
133
|
else
|
119
|
-
|
134
|
+
Mirah::AST.type(nil, type)
|
120
135
|
end
|
121
136
|
end
|
122
137
|
klass = JRuby.runtime.jruby_class_loader.loadClass(class_name)
|
@@ -160,7 +175,7 @@ module Duby::JVM::Types
|
|
160
175
|
|
161
176
|
add_macro('kind_of?', ClassType) do |transformer, call|
|
162
177
|
klass, object = call.parameters[0], call.target
|
163
|
-
|
178
|
+
Mirah::AST::Call.new(call.parent, call.position, 'isInstance') do |call2|
|
164
179
|
klass.parent = object.parent = call2
|
165
180
|
[
|
166
181
|
klass,
|
@@ -209,8 +224,8 @@ module Duby::JVM::Types
|
|
209
224
|
compiler.method.arraylength
|
210
225
|
end
|
211
226
|
|
212
|
-
add_macro('each',
|
213
|
-
|
227
|
+
add_macro('each', Mirah::AST.block_type) do |transformer, call|
|
228
|
+
Mirah::AST::Loop.new(call.parent,
|
214
229
|
call.position, true, false) do |forloop|
|
215
230
|
index = transformer.tmp
|
216
231
|
array = transformer.tmp
|
@@ -229,7 +244,7 @@ module Duby::JVM::Types
|
|
229
244
|
forloop.post << transformer.eval("#{index} += 1")
|
230
245
|
call.block.body.parent = forloop if call.block.body
|
231
246
|
[
|
232
|
-
|
247
|
+
Mirah::AST::Condition.new(forloop, call.position) do |c|
|
233
248
|
[transformer.eval("#{index} < #{array}.length",
|
234
249
|
'', forloop, index, array)]
|
235
250
|
end,
|
@@ -341,8 +356,8 @@ module Duby::JVM::Types
|
|
341
356
|
def add_intrinsics
|
342
357
|
super
|
343
358
|
add_enumerable_macros
|
344
|
-
add_macro('each',
|
345
|
-
|
359
|
+
add_macro('each', Mirah::AST.block_type) do |transformer, call|
|
360
|
+
Mirah::AST::Loop.new(call.parent,
|
346
361
|
call.position, true, false) do |forloop|
|
347
362
|
it = transformer.tmp
|
348
363
|
|
@@ -358,7 +373,7 @@ module Duby::JVM::Types
|
|
358
373
|
end
|
359
374
|
call.block.body.parent = forloop if call.block.body
|
360
375
|
[
|
361
|
-
|
376
|
+
Mirah::AST::Condition.new(forloop, call.position) do |c|
|
362
377
|
[transformer.eval("#{it}.hasNext", '', forloop, it)]
|
363
378
|
end,
|
364
379
|
call.block.body
|
@@ -1,6 +1,21 @@
|
|
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 'delegate'
|
2
17
|
|
3
|
-
module
|
18
|
+
module Mirah::JVM::Types
|
4
19
|
|
5
20
|
# Represents a literal number that can be represented
|
6
21
|
# in multiple types
|
@@ -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
|
require 'mirah/jvm/types'
|
2
17
|
|
3
18
|
class Java::JavaMethod
|
@@ -10,8 +25,8 @@ class Java::JavaMethod
|
|
10
25
|
end
|
11
26
|
end
|
12
27
|
|
13
|
-
module
|
14
|
-
AST ||=
|
28
|
+
module Mirah::JVM::Types
|
29
|
+
AST ||= Mirah::AST
|
15
30
|
|
16
31
|
module ArgumentConversion
|
17
32
|
def convert_args(compiler, values, types=nil)
|
@@ -106,10 +121,10 @@ module Duby::JVM::Types
|
|
106
121
|
|
107
122
|
def exceptions
|
108
123
|
@member.exception_types.map do |exception|
|
109
|
-
if exception.kind_of?(
|
124
|
+
if exception.kind_of?(Mirah::JVM::Types::Type)
|
110
125
|
exception
|
111
126
|
else
|
112
|
-
|
127
|
+
Mirah::AST.type(nil, exception.class_name)
|
113
128
|
end
|
114
129
|
end
|
115
130
|
end
|
@@ -348,7 +363,7 @@ module Duby::JVM::Types
|
|
348
363
|
end
|
349
364
|
end
|
350
365
|
|
351
|
-
class
|
366
|
+
class MirahMember
|
352
367
|
attr_reader :name, :argument_types, :declaring_class, :return_type
|
353
368
|
attr_reader :exception_types
|
354
369
|
|
@@ -477,11 +492,11 @@ module Duby::JVM::Types
|
|
477
492
|
|
478
493
|
def inner_class_getter(name)
|
479
494
|
full_name = "#{self.name}$#{name}"
|
480
|
-
inner_class =
|
495
|
+
inner_class = Mirah::AST.type(nil, full_name) rescue nil
|
481
496
|
return unless inner_class
|
482
497
|
inner_class.inner_class = true
|
483
498
|
add_macro(name) do |transformer, call|
|
484
|
-
|
499
|
+
Mirah::AST::Constant.new(call.parent, call.position, full_name)
|
485
500
|
end
|
486
501
|
intrinsics[name][[]]
|
487
502
|
end
|
@@ -554,7 +569,7 @@ module Duby::JVM::Types
|
|
554
569
|
|
555
570
|
def declare_method(name, arguments, type, exceptions)
|
556
571
|
raise "Bad args" unless arguments.all?
|
557
|
-
member =
|
572
|
+
member = MirahMember.new(self, name, arguments, type, false, exceptions)
|
558
573
|
if name == 'initialize'
|
559
574
|
if @default_constructor_added
|
560
575
|
unless arguments.empty?
|
@@ -569,7 +584,7 @@ module Duby::JVM::Types
|
|
569
584
|
end
|
570
585
|
|
571
586
|
def declare_static_method(name, arguments, type, exceptions)
|
572
|
-
member =
|
587
|
+
member = MirahMember.new(self, name, arguments, type, true, exceptions)
|
573
588
|
static_methods[name] << JavaStaticMethod.new(member)
|
574
589
|
end
|
575
590
|
|
@@ -1,4 +1,19 @@
|
|
1
|
-
|
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
|
+
module Mirah::JVM::Types
|
2
17
|
class ComparisonIntrinsic < Intrinsic
|
3
18
|
attr_reader :name, :op
|
4
19
|
def initialize(type, name, op, args)
|
data/lib/mirah/jvm/types.rb
CHANGED
@@ -1,20 +1,35 @@
|
|
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 'bitescript'
|
2
17
|
require 'mirah/ast'
|
3
18
|
require 'mirah/jvm/method_lookup'
|
4
19
|
require 'mirah/jvm/compiler'
|
5
20
|
require 'set'
|
6
21
|
|
7
|
-
module
|
22
|
+
module Mirah
|
8
23
|
module JVM
|
9
24
|
module Types
|
10
25
|
class Type < AST::TypeReference
|
11
26
|
include Java::DubyLangCompiler::Class
|
12
|
-
include
|
27
|
+
include Mirah::JVM::MethodLookup
|
13
28
|
|
14
29
|
attr_writer :inner_class
|
15
30
|
|
16
31
|
def log(message)
|
17
|
-
puts "* [JVM::Types] #{message}" if
|
32
|
+
puts "* [JVM::Types] #{message}" if Mirah::Compiler::JVM.verbose
|
18
33
|
end
|
19
34
|
|
20
35
|
def initialize(mirror_or_name)
|
@@ -111,7 +126,7 @@ module Duby
|
|
111
126
|
end
|
112
127
|
|
113
128
|
def array_type
|
114
|
-
@array_type ||=
|
129
|
+
@array_type ||= Mirah::JVM::Types::ArrayType.new(self)
|
115
130
|
end
|
116
131
|
|
117
132
|
def prefix
|
@@ -247,6 +262,10 @@ module Duby
|
|
247
262
|
def compatible?(other)
|
248
263
|
!other.primitive?
|
249
264
|
end
|
265
|
+
|
266
|
+
def assignable_from?(other)
|
267
|
+
!other.primitive?
|
268
|
+
end
|
250
269
|
end
|
251
270
|
|
252
271
|
class VoidType < PrimitiveType
|
data/lib/mirah/nbcompiler.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 NbCompiler
|
4
19
|
include org.mirah.DubyCompiler
|
5
20
|
|
@@ -19,9 +34,9 @@ module Duby
|
|
19
34
|
end
|
20
35
|
|
21
36
|
def parse(text)
|
22
|
-
|
23
|
-
ast =
|
24
|
-
transformer =
|
37
|
+
Mirah::AST.type_factory = Mirah::JVM::Types::TypeFactory.new
|
38
|
+
ast = Mirah::AST.parse_ruby(text)
|
39
|
+
transformer = Mirah::Transform::Transformer.new(Mirah::CompilationState.new)
|
25
40
|
return ParseResult.new(
|
26
41
|
transformer.transform(ast, nil), transformer.errors)
|
27
42
|
end
|
data/lib/mirah/plugin/edb.rb
CHANGED
@@ -1,6 +1,21 @@
|
|
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 'erb'
|
2
17
|
|
3
|
-
|
18
|
+
Mirah::AST.defmacro('def_edb') do |transformer, fcall, parent|
|
4
19
|
name = fcall.parameters[0].name
|
5
20
|
path = fcall.parameters[1].literal
|
6
21
|
compiler = ERB::Compiler.new(nil)
|
@@ -9,14 +24,14 @@ Duby::AST.defmacro('def_edb') do |transformer, fcall, parent|
|
|
9
24
|
compiler.pre_cmd = ["def #{name}", "_edbout = StringBuilder.new"]
|
10
25
|
compiler.post_cmd = ["_edbout.toString", "end"]
|
11
26
|
src = compiler.compile(IO.read(path))
|
12
|
-
ast =
|
27
|
+
ast = Mirah::AST.parse_ruby(src, path)
|
13
28
|
transformer.filename = path
|
14
29
|
script = transformer.transform(ast, parent)
|
15
30
|
script.body.parent = parent
|
16
31
|
script.body
|
17
32
|
end
|
18
33
|
|
19
|
-
|
34
|
+
Mirah::AST.defmacro('__edb_insert__') do |transformer, fcall, parent|
|
20
35
|
# ERB sticks in a .to_s that we don't want.
|
21
36
|
# the ast is __edb_insert__(_edbout.append(content.to_s))
|
22
37
|
append = fcall.parameters[0]
|