Permalink
Browse files

Start getting jvm compiler to work

  • Loading branch information...
1 parent bbb3423 commit df1f9db4cd657d209cb034cd3fcde7c52dd439b5 @ribrdb ribrdb committed Jul 19, 2011
View
@@ -13,7 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-def fib(a:int):int
+def fib(a:int)
if a < 2
a
else
Binary file not shown.
View
@@ -61,7 +61,7 @@ def self.print_error(message, position)
puts message
return
end
- puts "#{position.file}:#{position.start_line}: #{message}"
- puts position.underline
+ puts "#{position.filename}:#{position.start_line}: #{message}"
+ #puts position.underline
end
end
View
@@ -13,50 +13,50 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-require 'mirah/compiler/call'
-require 'mirah/compiler/class'
-require 'mirah/compiler/flow'
-require 'mirah/compiler/literal'
-require 'mirah/compiler/local'
-require 'mirah/compiler/method'
-require 'mirah/compiler/structure'
-require 'mirah/compiler/type'
-
module Mirah
module Compiler
class ASTCompiler
def initialize(compiler_class, logging)
@compiler_class = compiler_class
@logging = logging
end
-
- attr_accessor :compiler_class, :logging
-
+
+ attr_accessor :compiler_class, :compiler, :logging
+
def compile_asts(nodes, scoper)
results = []
puts "Compiling..." if logging
nodes.each do |ast|
- puts " #{ast.position.file}" if logging
+ puts " #{ast.position.filename}" if logging
compile_ast(ast, scoper) do |filename, builder|
results << CompilerResult.new(filename, builder.class_name, builder.generate)
end
end
results
end
-
+
def compile_ast(ast, scoper, &block)
- compiler = compiler_class.new(scoper)
- ast.compile(compiler, false)
+ @compiler = compiler_class.new(scoper)
+ compiler.visit(ast, nil)
compiler.generate(&block)
end
end
-
+
class CompilerResult
def initialize(filename, classname, bytes)
@filename, @classname, @bytes = filename, classname, bytes
end
-
+
attr_accessor :filename, :classname, :bytes
end
end
-end
+end
+
+require 'mirah/compiler/call'
+require 'mirah/compiler/class'
+require 'mirah/compiler/flow'
+require 'mirah/compiler/literal'
+require 'mirah/compiler/local'
+require 'mirah/compiler/method'
+require 'mirah/compiler/structure'
+require 'mirah/compiler/type'
@@ -1,45 +0,0 @@
-# Copyright (c) 2010 The Mirah project authors. All Rights Reserved.
-# All contributing project authors may be found in the NOTICE file.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-module Mirah
- module AST
- class FunctionalCall
- def compile(compiler, expression)
- compiler.line(line_number)
- compiler.self_call(self, expression)
- rescue Exception => ex
- raise Mirah::InternalCompilerError.wrap(ex, self)
- end
- end
-
- class Call
- def compile(compiler, expression)
- compiler.line(line_number)
- compiler.call(self, expression)
- rescue Exception => ex
- raise Mirah::InternalCompilerError.wrap(ex, self)
- end
- end
-
- class Super
- def compile(compiler, expression)
- compiler.line(line_number)
- compiler.super_call(self, expression)
- rescue Exception => ex
- raise Mirah::InternalCompilerError.wrap(ex, self)
- end
- end
- end
-end
@@ -1,81 +0,0 @@
-# Copyright (c) 2010 The Mirah project authors. All Rights Reserved.
-# All contributing project authors may be found in the NOTICE file.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-module Mirah
- module AST
- class ClassDefinition
- def compile(compiler, expression)
- compiler.define_class(self, expression)
- rescue Exception => ex
- raise Mirah::InternalCompilerError.wrap(ex, self)
- end
- end
-
- class ClosureDefinition
- def compile(compiler, expression)
- compiler.define_closure(self, expression)
- rescue Exception => ex
- raise Mirah::InternalCompilerError.wrap(ex, self)
- end
- end
-
- class AccessLevel
- def compile(compiler, expression); end
- end
-
- class FieldDeclaration
- def compile(compiler, expression)
- compiler.field_declare(name, inferred_type, annotations, static)
- rescue Exception => ex
- raise Mirah::InternalCompilerError.wrap(ex, self)
- end
- end
-
- class FieldAssignment
- def compile(compiler, expression)
- compiler.line(line_number)
- compiler.field_assign(name, inferred_type, expression, value, annotations, static)
- rescue Exception => ex
- raise Mirah::InternalCompilerError.wrap(ex, self)
- end
- end
-
- class Field
- def compile(compiler, expression)
- compiler.line(line_number)
- if expression
- compiler.field(name, inferred_type, annotations, static)
- end
- rescue Exception => ex
- raise Mirah::InternalCompilerError.wrap(ex, self)
- end
- end
-
- class Include
- def compile(compiler, expression); end
- end
-
- class Constant
- def compile(compiler, expression)
- if expression
- compiler.line(line_number)
- compiler.constant(self)
- end
- rescue Exception => ex
- raise Mirah::InternalCompilerError.wrap(ex, self)
- end
- end
- end
-end
@@ -1,109 +0,0 @@
-# Copyright (c) 2010 The Mirah project authors. All Rights Reserved.
-# All contributing project authors may be found in the NOTICE file.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-module Mirah
- module AST
- class If
- def compile(compiler, expression)
- compiler.line(line_number)
- compiler.branch(self, expression)
- rescue Exception => ex
- raise Mirah::InternalCompilerError.wrap(ex, self)
- end
- end
-
- class Condition
- def compile(compiler, expression)
- # TODO: can a condition ever be an expression? I don't think it can...
- compiler.line(line_number)
- predicate.compile(compiler, expression)
- rescue Exception => ex
- raise Mirah::InternalCompilerError.wrap(ex, self)
- end
- end
-
- class Loop
- def compile(compiler, expression)
- compiler.line(line_number)
- compiler.loop(self, expression)
- rescue Exception => ex
- raise Mirah::InternalCompilerError.wrap(ex, self)
- end
- end
-
- class Return
- def compile(compiler, expression)
- compiler.line(line_number)
- compiler.return(self)
- rescue Exception => ex
- raise Mirah::InternalCompilerError.wrap(ex, self)
- end
- end
-
- class Break
- def compile(compiler, expression)
- compiler.line(line_number)
- compiler.break(self)
- rescue Exception => ex
- raise Mirah::InternalCompilerError.wrap(ex, self)
- end
- end
-
- class Next
- def compile(compiler, expression)
- compiler.line(line_number)
- compiler.next(self)
- rescue Exception => ex
- raise Mirah::InternalCompilerError.wrap(ex, self)
- end
- end
-
- class Redo
- def compile(compiler, expression)
- compiler.line(line_number)
- compiler.redo(self)
- rescue Exception => ex
- raise Mirah::InternalCompilerError.wrap(ex, self)
- end
- end
-
- class Raise
- def compile(compiler, expression)
- compiler.line(line_number)
- compiler._raise(exception)
- rescue Exception => ex
- raise Mirah::InternalCompilerError.wrap(ex, self)
- end
- end
-
- class Rescue
- def compile(compiler, expression)
- compiler.line(line_number)
- compiler.rescue(self, expression)
- rescue Exception => ex
- raise Mirah::InternalCompilerError.wrap(ex, self)
- end
- end
-
- class Ensure
- def compile(compiler, expression)
- compiler.line(line_number)
- compiler.ensure(self, expression)
- rescue Exception => ex
- raise Mirah::InternalCompilerError.wrap(ex, self)
- end
- end
- end
-end
Oops, something went wrong. Retry.

0 comments on commit df1f9db

Please sign in to comment.