Sha256: fc6ac0204e148e98a00fb0d6cc2ac09abe30dec04bcac35b36d56474a8e451a7

Contents?: true

Size: 1.9 KB

Versions: 11

Compression:

Stored size: 1.9 KB

Contents

#
# Stages for compiling Fancy to Rubinius bytecode.
#

class Fancy
  class Compiler

    # FancyAST -> Rubinius Symbolic bytecode
    class FancyGenerator < Rubinius::Compiler::Stage
      stage :fancy_bytecode
      next_stage Rubinius::Compiler::Encoder

      attr_accessor :variable_scope

      def initialize(compiler, last)
        super
        @variable_scope = nil
        compiler.generator = self
      end

      def run
        @output = Rubinius::Generator.new
        @input.variable_scope = @variable_scope
        @input.bytecode @output
        @output.close
        run_next
      end

      def input(root_ast)
        @input = root_ast
      end
    end

    # Fancy string -> AST
    class FancyCodeParser < Rubinius::Compiler::Stage
      stage :fancy_code
      next_stage FancyGenerator

      def initialize(compiler, last)
        super
        compiler.parser = self
      end

      def root(root)
        @root = root
      end

      def print
        @print = true
      end

      def input(code, filename="(eval)", line=1)
        @input = code
        @filename = filename
        @line = line
      end

      def run
        ast = Parser.parse_string(@input, @line, @filename)
        @output = @root.new ast
        @output.file = @filename
        run_next
      end
    end

    # Fancy file -> AST
    class FancyFileParser < Rubinius::Compiler::Stage
      stage :fancy_file
      next_stage FancyGenerator

      def initialize(compiler, last)
        super
        compiler.parser = self
      end

      def root(root)
        @root = root
      end

      def print
        @print = true
      end

      def input(filename, line=1)
        @filename = filename
        @line = line
      end

      def run
        ast = Parser.parse_file(@filename, @line)
        # p ast if @print
        @output = @root.new ast
        @output.file = @filename
        run_next
      end
    end

  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
fancy-0.10.0 boot/rbx-compiler/compiler/stages.rb
fancy-0.9.0 boot/rbx-compiler/compiler/stages.rb
fancy-0.8.0 boot/rbx-compiler/compiler/stages.rb
fancy-0.7.0 boot/rbx-compiler/compiler/stages.rb
fancy-0.6.0 boot/rbx-compiler/compiler/stages.rb
fancy-0.5.0 boot/rbx-compiler/compiler/stages.rb
fancy-0.4.0 boot/rbx-compiler/compiler/stages.rb
fancy-0.3.3 boot/rbx-compiler/compiler/stages.rb
fancy-0.3.2 boot/rbx-compiler/compiler/stages.rb
fancy-0.3.1 boot/rbx-compiler/compiler/stages.rb
fancy-0.3.0 boot/rbx-compiler/compiler/stages.rb