mirah 0.0.7-java → 0.0.8-java
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +181 -0
- data/README.txt +6 -10
- data/Rakefile +86 -9
- data/bin/mirah +2 -0
- data/bin/mirahc +2 -0
- data/bin/mirahp +2 -0
- data/{bin/dubyp → examples/interfaces.mirah} +16 -9
- data/examples/macros/square.mirah +12 -0
- data/examples/macros/square_int.mirah +12 -0
- data/examples/macros/string-each-char.mirah +14 -0
- data/examples/maven/README.txt +2 -0
- data/examples/maven/pom.xml +23 -0
- data/examples/maven/src/main/mirah/hello_mirah.mirah +9 -0
- data/examples/rosettacode/100-doors.mirah +44 -0
- data/examples/rosettacode/99-bottles-of-beer.mirah +13 -0
- data/examples/rosettacode/README.txt +9 -0
- data/examples/rosettacode/boolean-values.mirah +29 -0
- data/examples/rosettacode/comments.mirah +2 -0
- data/examples/rosettacode/copy-a-string.mirah +10 -0
- data/examples/rosettacode/count-occurrences-of-a-substring.mirah +40 -0
- data/examples/rosettacode/create-a-file.mirah +6 -0
- data/examples/rosettacode/empty-string.mirah +9 -0
- data/examples/rosettacode/factorial.mirah +10 -0
- data/examples/rosettacode/fibonacci.mirah +21 -0
- data/examples/rosettacode/file-size.mirah +5 -0
- data/examples/rosettacode/fizz-buzz.mirah +21 -0
- data/examples/rosettacode/flatten-a-list.mirah +24 -0
- data/examples/rosettacode/guess-the-number.mirah +21 -0
- data/examples/rosettacode/is-string-numeric.mirah +127 -0
- data/examples/rosettacode/palindrome.mirah +14 -0
- data/examples/rosettacode/repeat-a-string.mirah +9 -0
- data/examples/rosettacode/reverse-a-string.mirah +6 -0
- data/examples/rosettacode/rot-13.mirah +20 -0
- data/examples/rosettacode/user-input.mirah +4 -0
- data/examples/sort_closure.mirah +1 -1
- data/javalib/dynalink-0.2.jar +0 -0
- data/javalib/mirah-bootstrap.jar +0 -0
- data/lib/mirah.rb +7 -16
- data/lib/mirah/ast.rb +22 -92
- data/lib/mirah/ast/call.rb +41 -9
- data/lib/mirah/ast/class.rb +34 -6
- data/lib/mirah/ast/flow.rb +17 -5
- data/lib/mirah/ast/intrinsics.rb +50 -8
- data/lib/mirah/ast/literal.rb +7 -0
- data/lib/mirah/ast/local.rb +9 -1
- data/lib/mirah/ast/method.rb +21 -8
- data/lib/mirah/ast/scope.rb +1 -1
- data/lib/mirah/ast/structure.rb +81 -15
- data/lib/mirah/ast/type.rb +4 -0
- data/{bin/dubyc → lib/mirah/commands.rb} +4 -11
- data/lib/mirah/commands/base.rb +54 -0
- data/lib/mirah/commands/compile.rb +39 -0
- data/{examples/wiki/Rakefile → lib/mirah/commands/parse.rb} +18 -17
- data/lib/mirah/commands/run.rb +73 -0
- data/lib/mirah/compiler.rb +37 -417
- data/lib/mirah/compiler/call.rb +45 -0
- data/lib/mirah/compiler/class.rb +81 -0
- data/lib/mirah/compiler/flow.rb +109 -0
- data/lib/mirah/compiler/literal.rb +130 -0
- data/lib/mirah/compiler/local.rb +59 -0
- data/lib/mirah/compiler/method.rb +44 -0
- data/lib/mirah/compiler/structure.rb +65 -0
- data/lib/mirah/compiler/type.rb +27 -0
- data/lib/mirah/env.rb +4 -6
- data/lib/mirah/generator.rb +61 -0
- data/lib/mirah/jvm/compiler.rb +8 -867
- data/lib/mirah/jvm/compiler/base.rb +270 -0
- data/lib/mirah/jvm/compiler/java_source.rb +779 -0
- data/lib/mirah/jvm/compiler/jvm_bytecode.rb +851 -0
- data/lib/mirah/jvm/method_lookup.rb +21 -2
- data/lib/mirah/jvm/source_generator/builder.rb +10 -13
- data/lib/mirah/jvm/source_generator/loops.rb +99 -93
- data/lib/mirah/jvm/source_generator/precompile.rb +3 -2
- data/lib/mirah/jvm/typer.rb +3 -3
- data/lib/mirah/jvm/types.rb +10 -426
- data/lib/mirah/jvm/types/array_type.rb +62 -0
- data/lib/mirah/jvm/types/basic_types.rb +1 -0
- data/lib/mirah/jvm/types/dynamic_type.rb +46 -0
- data/lib/mirah/jvm/types/factory.rb +23 -5
- data/lib/mirah/jvm/types/interface_definition.rb +20 -0
- data/lib/mirah/jvm/types/intrinsics.rb +15 -3
- data/lib/mirah/jvm/types/meta_type.rb +45 -0
- data/lib/mirah/jvm/types/methods.rb +12 -5
- data/lib/mirah/jvm/types/null_type.rb +27 -0
- data/lib/mirah/jvm/types/primitive_type.rb +38 -0
- data/lib/mirah/jvm/types/source_mirror.rb +266 -0
- data/lib/mirah/jvm/types/type.rb +173 -0
- data/lib/mirah/jvm/types/type_definition.rb +55 -0
- data/lib/mirah/jvm/types/unreachable_type.rb +27 -0
- data/lib/mirah/jvm/types/void_type.rb +19 -0
- data/lib/mirah/parser.rb +90 -0
- data/lib/mirah/plugin/gwt.rb +5 -5
- data/lib/mirah/plugin/java.rb +1 -1
- data/lib/mirah/transform.rb +4 -321
- data/lib/mirah/transform/ast_ext.rb +63 -0
- data/lib/mirah/transform/error.rb +13 -0
- data/lib/mirah/transform/helper.rb +761 -0
- data/lib/mirah/transform/transformer.rb +255 -0
- data/lib/mirah/typer.rb +2 -383
- data/{bin/duby → lib/mirah/typer/base.rb} +12 -10
- data/lib/mirah/typer/simple.rb +377 -0
- data/lib/mirah/util/argument_processor.rb +114 -0
- data/lib/mirah/util/class_loader.rb +37 -0
- data/lib/mirah/util/compilation_state.rb +51 -0
- data/lib/mirah/util/process_errors.rb +33 -0
- data/lib/mirah/version.rb +1 -1
- data/lib/mirah_task.rb +3 -2
- data/test/{test_ast.rb → core/test_ast.rb} +6 -0
- data/test/{test_compilation.rb → core/test_compilation.rb} +0 -0
- data/test/{test_env.rb → core/test_env.rb} +24 -25
- data/test/{test_macros.rb → core/test_macros.rb} +2 -4
- data/test/{test_typer.rb → core/test_typer.rb} +0 -3
- data/test/jvm/bytecode_test_helper.rb +181 -0
- data/test/{test_javac_compiler.rb → jvm/javac_test_helper.rb} +38 -22
- data/test/jvm/test_enumerable.rb +304 -0
- data/test/{test_java_typer.rb → jvm/test_java_typer.rb} +2 -4
- data/test/{test_jvm_compiler.rb → jvm/test_jvm_compiler.rb} +146 -443
- data/test/jvm/test_macros.rb +147 -0
- data/test/jvm/test_main_method.rb +15 -0
- data/test/{test_gwt.rb → plugins/test_gwt.rb} +0 -2
- metadata +103 -91
- data/bin/jrubyp +0 -52
- data/examples/wiki/src/org/mirah/wiki/MirahWiki.duby +0 -339
- data/examples/wiki/src/org/mirah/wiki/edit.eduby.html +0 -42
- data/examples/wiki/src/org/mirah/wiki/error.eduby.html +0 -2
- data/examples/wiki/src/org/mirah/wiki/layout.eduby.html +0 -69
- data/examples/wiki/src/org/mirah/wiki/parser.eduby.html +0 -7
- data/examples/wiki/src/org/mirah/wiki/view.eduby.html +0 -15
- data/examples/wiki/war/WEB-INF/classes/test/HeredocContext.class +0 -0
- data/examples/wiki/war/WEB-INF/classes/test/MirahParser.class +0 -0
- data/examples/wiki/war/WEB-INF/lib/appengine-api.jar +0 -0
- data/examples/wiki/war/WEB-INF/lib/dubydatastore.jar +0 -0
- data/examples/wiki/war/WEB-INF/lib/jmeta-runtime.jar +0 -0
- data/examples/wiki/war/WEB-INF/lib/pegdown-stubs.jar +0 -0
- data/examples/wiki/war/WEB-INF/pegdown.jar +0 -0
- data/examples/wiki/war/app.yaml +0 -21
- data/examples/wiki/war/public/favicon.ico +0 -0
- data/examples/wiki/war/public/images/appengine_duby.png +0 -0
- data/examples/wiki/war/public/images/back.gif +0 -0
- data/examples/wiki/war/public/images/dir.gif +0 -0
- data/examples/wiki/war/public/images/file.gif +0 -0
- data/examples/wiki/war/public/javascripts/prettify.js +0 -61
- data/examples/wiki/war/public/robots.txt +0 -0
- data/examples/wiki/war/public/stylesheets/main.css +0 -156
- data/examples/wiki/war/public/stylesheets/prettify.css +0 -1
- data/examples/wiki/war/public/stylesheets/sh_style.css +0 -66
- data/examples/wiki/war/public/stylesheets/source.css +0 -21
- data/examples/wiki/war/public/wmd/images/bg-fill.png +0 -0
- data/examples/wiki/war/public/wmd/images/bg.png +0 -0
- data/examples/wiki/war/public/wmd/images/blockquote.png +0 -0
- data/examples/wiki/war/public/wmd/images/bold.png +0 -0
- data/examples/wiki/war/public/wmd/images/code.png +0 -0
- data/examples/wiki/war/public/wmd/images/h1.png +0 -0
- data/examples/wiki/war/public/wmd/images/hr.png +0 -0
- data/examples/wiki/war/public/wmd/images/img.png +0 -0
- data/examples/wiki/war/public/wmd/images/italic.png +0 -0
- data/examples/wiki/war/public/wmd/images/link.png +0 -0
- data/examples/wiki/war/public/wmd/images/ol.png +0 -0
- data/examples/wiki/war/public/wmd/images/redo.png +0 -0
- data/examples/wiki/war/public/wmd/images/separator.png +0 -0
- data/examples/wiki/war/public/wmd/images/ul.png +0 -0
- data/examples/wiki/war/public/wmd/images/undo.png +0 -0
- data/examples/wiki/war/public/wmd/images/wmd-on.png +0 -0
- data/examples/wiki/war/public/wmd/images/wmd.png +0 -0
- data/examples/wiki/war/public/wmd/showdown.js +0 -421
- data/examples/wiki/war/public/wmd/wmd-base.js +0 -1799
- data/examples/wiki/war/public/wmd/wmd-plus.js +0 -311
- data/examples/wiki/war/public/wmd/wmd.js +0 -73
- data/examples/wiki/war/src/org/mirah/wiki/MirahWiki.duby +0 -339
- data/examples/wiki/war/src/org/mirah/wiki/edit.eduby.html +0 -42
- data/examples/wiki/war/src/org/mirah/wiki/error.eduby.html +0 -2
- data/examples/wiki/war/src/org/mirah/wiki/layout.eduby.html +0 -69
- data/examples/wiki/war/src/org/mirah/wiki/parser.eduby.html +0 -7
- data/examples/wiki/war/src/org/mirah/wiki/view.eduby.html +0 -15
- data/javalib/dynalink-0.1.jar +0 -0
- data/javalib/jsr292-mock.jar +0 -0
- data/lib/mirah/class_loader.rb +0 -35
- data/lib/mirah/compilation_state.rb +0 -28
- data/lib/mirah/impl.rb +0 -273
- data/lib/mirah/jvm/base.rb +0 -267
- data/lib/mirah/jvm/source_compiler.rb +0 -760
- data/lib/mirah/transform2.rb +0 -752
@@ -0,0 +1,39 @@
|
|
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/generator'
|
17
|
+
require 'fileutils'
|
18
|
+
|
19
|
+
module Mirah
|
20
|
+
module Commands
|
21
|
+
class Compile < Base
|
22
|
+
def execute
|
23
|
+
execute_base do
|
24
|
+
generator = Mirah::Generator.new(@state, @state.compiler_class, true, @state.verbose)
|
25
|
+
|
26
|
+
generator.generate(@state.args).each do |result|
|
27
|
+
filename = "#{@state.destination}#{result.filename}"
|
28
|
+
FileUtils.mkdir_p(File.dirname(filename))
|
29
|
+
File.open(filename, 'wb') {|f| f.write(result.bytes)}
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def command_name
|
35
|
+
:compile
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -13,21 +13,22 @@
|
|
13
13
|
# See the License for the specific language governing permissions and
|
14
14
|
# limitations under the License.
|
15
15
|
|
16
|
-
|
17
|
-
if File.exist?('../../lib/mirah.rb')
|
18
|
-
$: << File.expand_path('../../lib')
|
19
|
-
end
|
20
|
-
if File.exist?('../../../bitescript/lib/bitescript.rb')
|
21
|
-
$: << File.expand_path('../../../bitescript/lib/')
|
22
|
-
end
|
23
|
-
require 'mirah/appengine_tasks'
|
16
|
+
require 'mirah/parser'
|
24
17
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
18
|
+
module Mirah
|
19
|
+
module Commands
|
20
|
+
class Parse < Base
|
21
|
+
def execute
|
22
|
+
execute_base do
|
23
|
+
parser = Mirah::Parser.new(@state, false)
|
24
|
+
|
25
|
+
parser.parse_from_args(args)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def command_name
|
30
|
+
:parse
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,73 @@
|
|
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/generator'
|
17
|
+
require 'mirah/util/class_loader'
|
18
|
+
|
19
|
+
module Mirah
|
20
|
+
module Commands
|
21
|
+
class Run < Base
|
22
|
+
def execute
|
23
|
+
execute_base do
|
24
|
+
main = nil
|
25
|
+
class_map = {}
|
26
|
+
|
27
|
+
# generate all bytes for all classes
|
28
|
+
generator = Mirah::Generator.new(@state, @state.compiler_class, false, @state.verbose)
|
29
|
+
|
30
|
+
generator.generate(args).each do |result|
|
31
|
+
class_map[result.classname.gsub(/\//, '.')] = result.bytes
|
32
|
+
end
|
33
|
+
|
34
|
+
# load all classes
|
35
|
+
main = load_classes_and_find_main(class_map)
|
36
|
+
|
37
|
+
# run the main method we found
|
38
|
+
run_main(main)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def command_name
|
43
|
+
:run
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def load_classes_and_find_main(class_map)
|
49
|
+
main = nil
|
50
|
+
dcl = Mirah::Util::ClassLoader.new(JRuby.runtime.jruby_class_loader, class_map)
|
51
|
+
class_map.each do |name,|
|
52
|
+
cls = dcl.load_class(name)
|
53
|
+
# TODO: using first main; find correct one?
|
54
|
+
main ||= cls.get_method("main", java::lang::String[].java_class)
|
55
|
+
end
|
56
|
+
main
|
57
|
+
end
|
58
|
+
|
59
|
+
def run_main(main)
|
60
|
+
if main
|
61
|
+
begin
|
62
|
+
main.invoke(nil, [args.to_java(:string)].to_java)
|
63
|
+
rescue java.lang.Exception => e
|
64
|
+
e = e.cause if e.cause
|
65
|
+
raise e
|
66
|
+
end
|
67
|
+
else
|
68
|
+
puts "No main found" unless @state.version_printed || @state.help_printed
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
data/lib/mirah/compiler.rb
CHANGED
@@ -13,430 +13,50 @@
|
|
13
13
|
# See the License for the specific language governing permissions and
|
14
14
|
# limitations under the License.
|
15
15
|
|
16
|
-
require 'mirah'
|
16
|
+
require 'mirah/compiler/call'
|
17
|
+
require 'mirah/compiler/class'
|
18
|
+
require 'mirah/compiler/flow'
|
19
|
+
require 'mirah/compiler/literal'
|
20
|
+
require 'mirah/compiler/local'
|
21
|
+
require 'mirah/compiler/method'
|
22
|
+
require 'mirah/compiler/structure'
|
23
|
+
require 'mirah/compiler/type'
|
17
24
|
|
18
25
|
module Mirah
|
19
|
-
module
|
20
|
-
class
|
21
|
-
def
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
compiler.regexp(literal)
|
36
|
-
end
|
37
|
-
rescue Exception => ex
|
38
|
-
raise Mirah::InternalCompilerError.wrap(ex, self)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
class String
|
43
|
-
def compile(compiler, expression)
|
44
|
-
if expression
|
45
|
-
compiler.line(line_number)
|
46
|
-
compiler.string(literal)
|
47
|
-
end
|
48
|
-
rescue Exception => ex
|
49
|
-
raise Mirah::InternalCompilerError.wrap(ex, self)
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
class StringConcat
|
54
|
-
def compile(compiler, expression)
|
55
|
-
compiler.build_string(children, expression)
|
56
|
-
rescue Exception => ex
|
57
|
-
raise Mirah::InternalCompilerError.wrap(ex, self)
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
class ToString
|
62
|
-
def compile(compiler, expression)
|
63
|
-
compiler.to_string(body, expression)
|
64
|
-
rescue Exception => ex
|
65
|
-
raise Mirah::InternalCompilerError.wrap(ex, self)
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
class Float
|
70
|
-
def compile(compiler, expression)
|
71
|
-
if expression
|
72
|
-
compiler.line(line_number)
|
73
|
-
compiler.float(inferred_type, literal)
|
74
|
-
end
|
75
|
-
rescue Exception => ex
|
76
|
-
raise Mirah::InternalCompilerError.wrap(ex, self)
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
class Boolean
|
81
|
-
def compile(compiler, expression)
|
82
|
-
if expression
|
83
|
-
compiler.line(line_number)
|
84
|
-
compiler.boolean(literal)
|
85
|
-
end
|
86
|
-
rescue Exception => ex
|
87
|
-
raise Mirah::InternalCompilerError.wrap(ex, self)
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
class Array
|
92
|
-
def compile(compiler, expression)
|
93
|
-
compiler.array(self, expression)
|
94
|
-
rescue Exception => ex
|
95
|
-
raise Mirah::InternalCompilerError.wrap(ex, self)
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
class Body
|
100
|
-
def compile(compiler, expression)
|
101
|
-
compiler.line(line_number)
|
102
|
-
compiler.body(self, expression)
|
103
|
-
rescue Exception => ex
|
104
|
-
raise Mirah::InternalCompilerError.wrap(ex, self)
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
class ScopedBody
|
109
|
-
def compile(compiler, expression)
|
110
|
-
compiler.line(line_number)
|
111
|
-
compiler.scoped_body(self, expression)
|
112
|
-
rescue Exception => ex
|
113
|
-
raise Mirah::InternalCompilerError.wrap(ex, self)
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
class Import
|
118
|
-
def compile(compiler, expression)
|
119
|
-
# TODO: what does it mean for import to be an expression?
|
120
|
-
compiler.import(short, long)
|
121
|
-
rescue Exception => ex
|
122
|
-
raise Mirah::InternalCompilerError.wrap(ex, self)
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
class Constant
|
127
|
-
def compile(compiler, expression)
|
128
|
-
if expression
|
129
|
-
compiler.line(line_number)
|
130
|
-
compiler.constant(self)
|
131
|
-
end
|
132
|
-
rescue Exception => ex
|
133
|
-
raise Mirah::InternalCompilerError.wrap(ex, self)
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
class Print
|
138
|
-
def compile(compiler, expression)
|
139
|
-
# TODO: what does it mean for printline to be an expression?
|
140
|
-
compiler.line(line_number)
|
141
|
-
compiler.print(self)
|
142
|
-
rescue Exception => ex
|
143
|
-
raise Mirah::InternalCompilerError.wrap(ex, self)
|
144
|
-
end
|
145
|
-
end
|
146
|
-
|
147
|
-
class Local
|
148
|
-
def compile(compiler, expression)
|
149
|
-
if expression
|
150
|
-
compiler.line(line_number)
|
151
|
-
if captured? && scope.has_binding?
|
152
|
-
compiler.captured_local(containing_scope, name, inferred_type)
|
153
|
-
else
|
154
|
-
compiler.local(containing_scope, name, inferred_type)
|
26
|
+
module Compiler
|
27
|
+
class ASTCompiler
|
28
|
+
def initialize(compiler_class, logging)
|
29
|
+
@compiler_class = compiler_class
|
30
|
+
@logging = logging
|
31
|
+
end
|
32
|
+
|
33
|
+
attr_accessor :compiler_class, :logging
|
34
|
+
|
35
|
+
def compile_asts(nodes)
|
36
|
+
results = []
|
37
|
+
puts "Compiling..." if logging
|
38
|
+
nodes.each do |ast|
|
39
|
+
puts " #{ast.position.file}" if logging
|
40
|
+
compile_ast(ast) do |filename, builder|
|
41
|
+
results << CompilerResult.new(filename, builder.class_name, builder.generate)
|
155
42
|
end
|
156
43
|
end
|
157
|
-
|
158
|
-
raise Mirah::InternalCompilerError.wrap(ex, self)
|
159
|
-
end
|
160
|
-
end
|
161
|
-
|
162
|
-
class LocalDeclaration
|
163
|
-
def compile(compiler, expression)
|
164
|
-
compiler.line(line_number)
|
165
|
-
if captured? && scope.has_binding?
|
166
|
-
compiler.captured_local_declare(containing_scope, name, type)
|
167
|
-
else
|
168
|
-
compiler.local_declare(containing_scope, name, type)
|
169
|
-
end
|
170
|
-
rescue Exception => ex
|
171
|
-
raise Mirah::InternalCompilerError.wrap(ex, self)
|
172
|
-
end
|
173
|
-
end
|
174
|
-
|
175
|
-
class LocalAssignment
|
176
|
-
def compile(compiler, expression)
|
177
|
-
compiler.line(line_number)
|
178
|
-
if captured? && scope.has_binding?
|
179
|
-
compiler.captured_local_assign(self, expression)
|
180
|
-
else
|
181
|
-
compiler.local_assign(containing_scope, name, inferred_type, expression, value)
|
182
|
-
end
|
183
|
-
rescue Exception => ex
|
184
|
-
raise Mirah::InternalCompilerError.wrap(ex, self)
|
185
|
-
end
|
186
|
-
end
|
187
|
-
|
188
|
-
class Script
|
189
|
-
def compile(compiler, expression)
|
190
|
-
# TODO: what does it mean for a script to be an expression? possible?
|
191
|
-
compiler.define_main(self)
|
192
|
-
rescue Exception => ex
|
193
|
-
raise Mirah::InternalCompilerError.wrap(ex, self)
|
194
|
-
end
|
195
|
-
end
|
196
|
-
|
197
|
-
class MethodDefinition
|
198
|
-
def compile(compiler, expression)
|
199
|
-
# TODO: what does it mean for a method to be an expression?
|
200
|
-
compiler.define_method(self)
|
201
|
-
rescue Exception => ex
|
202
|
-
raise Mirah::InternalCompilerError.wrap(ex, self)
|
203
|
-
end
|
204
|
-
end
|
205
|
-
|
206
|
-
class ConstructorDefinition
|
207
|
-
def compile(compiler, expression)
|
208
|
-
compiler.constructor(self)
|
209
|
-
rescue Exception => ex
|
210
|
-
raise Mirah::InternalCompilerError.wrap(ex, self)
|
211
|
-
end
|
212
|
-
end
|
213
|
-
|
214
|
-
class Arguments
|
215
|
-
def compile(compiler, expression)
|
216
|
-
# TODO: what does it mean for a method to be an expression?
|
217
|
-
args.each {|arg| compiler.declare_argument(arg.name, arg.inferred_type)} if args
|
218
|
-
rescue Exception => ex
|
219
|
-
raise Mirah::InternalCompilerError.wrap(ex, self)
|
220
|
-
end
|
221
|
-
end
|
222
|
-
|
223
|
-
class Noop
|
224
|
-
def compile(compiler, expression)
|
225
|
-
# TODO: what does it mean for a noop to be an expression
|
226
|
-
# nothing
|
227
|
-
rescue Exception => ex
|
228
|
-
raise Mirah::InternalCompilerError.wrap(ex, self)
|
229
|
-
end
|
230
|
-
end
|
231
|
-
|
232
|
-
class If
|
233
|
-
def compile(compiler, expression)
|
234
|
-
compiler.line(line_number)
|
235
|
-
compiler.branch(self, expression)
|
236
|
-
rescue Exception => ex
|
237
|
-
raise Mirah::InternalCompilerError.wrap(ex, self)
|
238
|
-
end
|
239
|
-
end
|
240
|
-
|
241
|
-
class Condition
|
242
|
-
def compile(compiler, expression)
|
243
|
-
# TODO: can a condition ever be an expression? I don't think it can...
|
244
|
-
compiler.line(line_number)
|
245
|
-
predicate.compile(compiler, expression)
|
246
|
-
rescue Exception => ex
|
247
|
-
raise Mirah::InternalCompilerError.wrap(ex, self)
|
248
|
-
end
|
249
|
-
end
|
250
|
-
|
251
|
-
class FunctionalCall
|
252
|
-
def compile(compiler, expression)
|
253
|
-
compiler.line(line_number)
|
254
|
-
compiler.self_call(self, expression)
|
255
|
-
rescue Exception => ex
|
256
|
-
raise Mirah::InternalCompilerError.wrap(ex, self)
|
257
|
-
end
|
258
|
-
end
|
259
|
-
|
260
|
-
class Call
|
261
|
-
def compile(compiler, expression)
|
262
|
-
compiler.line(line_number)
|
263
|
-
compiler.call(self, expression)
|
264
|
-
rescue Exception => ex
|
265
|
-
raise Mirah::InternalCompilerError.wrap(ex, self)
|
266
|
-
end
|
267
|
-
end
|
268
|
-
|
269
|
-
class Super
|
270
|
-
def compile(compiler, expression)
|
271
|
-
compiler.line(line_number)
|
272
|
-
compiler.super_call(self, expression)
|
273
|
-
rescue Exception => ex
|
274
|
-
raise Mirah::InternalCompilerError.wrap(ex, self)
|
275
|
-
end
|
276
|
-
end
|
277
|
-
|
278
|
-
class Loop
|
279
|
-
def compile(compiler, expression)
|
280
|
-
compiler.line(line_number)
|
281
|
-
compiler.loop(self, expression)
|
282
|
-
rescue Exception => ex
|
283
|
-
raise Mirah::InternalCompilerError.wrap(ex, self)
|
284
|
-
end
|
285
|
-
end
|
286
|
-
|
287
|
-
class ClassDefinition
|
288
|
-
def compile(compiler, expression)
|
289
|
-
compiler.define_class(self, expression)
|
290
|
-
rescue Exception => ex
|
291
|
-
raise Mirah::InternalCompilerError.wrap(ex, self)
|
292
|
-
end
|
293
|
-
end
|
294
|
-
|
295
|
-
class ClosureDefinition
|
296
|
-
def compile(compiler, expression)
|
297
|
-
compiler.define_closure(self, expression)
|
298
|
-
rescue Exception => ex
|
299
|
-
raise Mirah::InternalCompilerError.wrap(ex, self)
|
300
|
-
end
|
301
|
-
end
|
302
|
-
|
303
|
-
class FieldDeclaration
|
304
|
-
def compile(compiler, expression)
|
305
|
-
compiler.field_declare(name, inferred_type, annotations, static)
|
306
|
-
rescue Exception => ex
|
307
|
-
raise Mirah::InternalCompilerError.wrap(ex, self)
|
308
|
-
end
|
309
|
-
end
|
310
|
-
|
311
|
-
class FieldAssignment
|
312
|
-
def compile(compiler, expression)
|
313
|
-
compiler.line(line_number)
|
314
|
-
compiler.field_assign(name, inferred_type, expression, value, annotations, static)
|
315
|
-
rescue Exception => ex
|
316
|
-
raise Mirah::InternalCompilerError.wrap(ex, self)
|
317
|
-
end
|
318
|
-
end
|
319
|
-
|
320
|
-
class Field
|
321
|
-
def compile(compiler, expression)
|
322
|
-
compiler.line(line_number)
|
323
|
-
if expression
|
324
|
-
compiler.field(name, inferred_type, annotations, static)
|
325
|
-
end
|
326
|
-
rescue Exception => ex
|
327
|
-
raise Mirah::InternalCompilerError.wrap(ex, self)
|
44
|
+
results
|
328
45
|
end
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
class Return
|
336
|
-
def compile(compiler, expression)
|
337
|
-
compiler.line(line_number)
|
338
|
-
compiler.return(self)
|
339
|
-
rescue Exception => ex
|
340
|
-
raise Mirah::InternalCompilerError.wrap(ex, self)
|
341
|
-
end
|
342
|
-
end
|
343
|
-
|
344
|
-
class EmptyArray
|
345
|
-
def compile(compiler, expression)
|
346
|
-
if expression
|
347
|
-
compiler.line(line_number)
|
348
|
-
compiler.empty_array(component_type, size)
|
349
|
-
end
|
350
|
-
rescue Exception => ex
|
351
|
-
raise Mirah::InternalCompilerError.wrap(ex, self)
|
352
|
-
end
|
353
|
-
end
|
354
|
-
|
355
|
-
class Null
|
356
|
-
def compile(compiler, expression)
|
357
|
-
if expression
|
358
|
-
compiler.line(line_number)
|
359
|
-
compiler.null
|
360
|
-
end
|
361
|
-
rescue Exception => ex
|
362
|
-
raise Mirah::InternalCompilerError.wrap(ex, self)
|
363
|
-
end
|
364
|
-
end
|
365
|
-
|
366
|
-
class Break
|
367
|
-
def compile(compiler, expression)
|
368
|
-
compiler.line(line_number)
|
369
|
-
compiler.break(self)
|
370
|
-
rescue Exception => ex
|
371
|
-
raise Mirah::InternalCompilerError.wrap(ex, self)
|
372
|
-
end
|
373
|
-
end
|
374
|
-
|
375
|
-
class Next
|
376
|
-
def compile(compiler, expression)
|
377
|
-
compiler.line(line_number)
|
378
|
-
compiler.next(self)
|
379
|
-
rescue Exception => ex
|
380
|
-
raise Mirah::InternalCompilerError.wrap(ex, self)
|
381
|
-
end
|
382
|
-
end
|
383
|
-
|
384
|
-
class Redo
|
385
|
-
def compile(compiler, expression)
|
386
|
-
compiler.line(line_number)
|
387
|
-
compiler.redo(self)
|
388
|
-
rescue Exception => ex
|
389
|
-
raise Mirah::InternalCompilerError.wrap(ex, self)
|
390
|
-
end
|
391
|
-
end
|
392
|
-
|
393
|
-
class Raise
|
394
|
-
def compile(compiler, expression)
|
395
|
-
compiler.line(line_number)
|
396
|
-
compiler._raise(exception)
|
397
|
-
rescue Exception => ex
|
398
|
-
raise Mirah::InternalCompilerError.wrap(ex, self)
|
46
|
+
|
47
|
+
def compile_ast(ast, &block)
|
48
|
+
compiler = compiler_class.new
|
49
|
+
ast.compile(compiler, false)
|
50
|
+
compiler.generate(&block)
|
399
51
|
end
|
400
52
|
end
|
401
|
-
|
402
|
-
class
|
403
|
-
def
|
404
|
-
|
405
|
-
compiler.rescue(self, expression)
|
406
|
-
rescue Exception => ex
|
407
|
-
raise Mirah::InternalCompilerError.wrap(ex, self)
|
408
|
-
end
|
409
|
-
end
|
410
|
-
|
411
|
-
class Ensure
|
412
|
-
def compile(compiler, expression)
|
413
|
-
compiler.line(line_number)
|
414
|
-
compiler.ensure(self, expression)
|
415
|
-
rescue Exception => ex
|
416
|
-
raise Mirah::InternalCompilerError.wrap(ex, self)
|
417
|
-
end
|
418
|
-
end
|
419
|
-
|
420
|
-
class Self
|
421
|
-
def compile(compiler, expression)
|
422
|
-
if expression
|
423
|
-
compiler.line(line_number)
|
424
|
-
compiler.compile_self
|
425
|
-
end
|
426
|
-
rescue Exception => ex
|
427
|
-
raise Mirah::InternalCompilerError.wrap(ex, self)
|
428
|
-
end
|
429
|
-
end
|
430
|
-
|
431
|
-
class BindingReference
|
432
|
-
def compile(compiler, expression)
|
433
|
-
if expression
|
434
|
-
compiler.line(line_number)
|
435
|
-
compiler.binding_reference
|
436
|
-
end
|
437
|
-
rescue Exception => ex
|
438
|
-
raise Mirah::InternalCompilerError.wrap(ex, self)
|
53
|
+
|
54
|
+
class CompilerResult
|
55
|
+
def initialize(filename, classname, bytes)
|
56
|
+
@filename, @classname, @bytes = filename, classname, bytes
|
439
57
|
end
|
58
|
+
|
59
|
+
attr_accessor :filename, :classname, :bytes
|
440
60
|
end
|
441
61
|
end
|
442
|
-
end
|
62
|
+
end
|