Sha256: e3e964d2093bc5ada3d85bddb78af6999e18cefeed52d9fde4ffe83379121b89

Contents?: true

Size: 1.05 KB

Versions: 7

Compression:

Stored size: 1.05 KB

Contents

class Fancy
  class AST

    class ClassDef < Rubinius::AST::Class
      def initialize(line, name, parent, body)
        body = AST::ExpressionList.new(line) unless body

        if name.kind_of?(Fancy::AST::Identifier)
          name = name.name
        end

        super(line, name, parent, body)

        if body.empty?
          body.unshift_expression Rubinius::AST::NilLiteral.new(line)
        end
      end

      def bytecode(g)
        docstring = body.body.shift_docstring
        if docstring
          setdoc = MessageSend.new(line,
                                   Identifier.new(line, "Fancy::Documentation"),
                                   Identifier.new(line, "for:append:"),
                                   MessageArgs.new(line,
                                                   Rubinius::AST::Self.new(line),
                                                   docstring))
          # Replace first string expression to set documentation.
          body.body.expressions.unshift setdoc
        end
        super(g)
      end

    end

  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
fancy-0.10.0 boot/rbx-compiler/compiler/ast/class_def.rb
fancy-0.9.0 boot/rbx-compiler/compiler/ast/class_def.rb
fancy-0.8.0 boot/rbx-compiler/compiler/ast/class_def.rb
fancy-0.7.0 boot/rbx-compiler/compiler/ast/class_def.rb
fancy-0.6.0 boot/rbx-compiler/compiler/ast/class_def.rb
fancy-0.5.0 boot/rbx-compiler/compiler/ast/class_def.rb
fancy-0.4.0 boot/rbx-compiler/compiler/ast/class_def.rb