Skip to content

Commit

Permalink
Start on new compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
rkh committed Jan 23, 2011
1 parent 8cd7b2e commit aecf25c
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
Empty file added lib/reak/new_compiler/ast.rb
Empty file.
16 changes: 16 additions & 0 deletions 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
45 changes: 45 additions & 0 deletions 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.