Skip to content
Browse files

Start on new compiler

  • Loading branch information...
1 parent 8cd7b2e commit aecf25c7a28394985c1624fa926e9914e9fcd2c8 @rkh committed Jan 23, 2011
Showing with 61 additions and 0 deletions.
  1. 0 lib/reak/new_compiler/ast.rb
  2. +16 −0 lib/reak/new_compiler/compiler.rb
  3. +45 −0 lib/reak/new_compiler/stages.rb
View
0 lib/reak/new_compiler/ast.rb
No changes.
View
16 lib/reak/new_compiler/compiler.rb
@@ -0,0 +1,16 @@
+module Reak
+ class Compiler < Rubinius::Compiler
+ def self.compiled_name(file)
+ file + (file.suffix?(".st") ? "c" : ".compiled.stc")
+ end
+
+ def initialize(from, to)
+ super map_stage(from), map_stage(to)
+ end
+
+ def map_stage(stage)
+ mapped = :"reak_#{stage}"
+ Stages.include?(mapped) ? mapped : stage
+ end
+ end
+end
View
45 lib/reak/new_compiler/stages.rb
@@ -0,0 +1,45 @@
+module Reak
+ module Compiler
+ class Parser < Rubinius::Compiler::Parser
+ def initialize(compiler, last)
+ super
+ @processor = Reak::Parser
+ end
+
+ def create
+ # TODO: we totally ignore @transforms
+ @parser = @processor.new(@file, @line)
+ @parser
+ end
+ end
+
+ class FileParser < Parser
+ stage :reak_file
+ next_stage Generator
+
+ def input(file, line = 1)
+ @file = file
+ @line = line
+ end
+
+ def parse
+ create.parse_file
+ end
+ end
+
+ class StringParser < Parser
+ stage :reak_string
+ next_stage Generator
+
+ def input(string, name = "(eval)", line = 1)
+ @input = string
+ @file = name
+ @line = line
+ end
+
+ def parse
+ create.parse_string(@input)
+ end
+ end
+ end
+end

0 comments on commit aecf25c

Please sign in to comment.
Something went wrong with that request. Please try again.