Class: SyntaxTree::YARV::Assembler

Inherits:
Object
  • Object
show all
Defined in:
lib/syntax_tree/yarv/assembler.rb

Defined Under Namespace

Classes: ObjectVisitor

Constant Summary collapse

CALLDATA_FLAGS =
{
  "ARGS_SPLAT" => CallData::CALL_ARGS_SPLAT,
  "ARGS_BLOCKARG" => CallData::CALL_ARGS_BLOCKARG,
  "FCALL" => CallData::CALL_FCALL,
  "VCALL" => CallData::CALL_VCALL,
  "ARGS_SIMPLE" => CallData::CALL_ARGS_SIMPLE,
  "KWARG" => CallData::CALL_KWARG,
  "KW_SPLAT" => CallData::CALL_KW_SPLAT,
  "TAILCALL" => CallData::CALL_TAILCALL,
  "SUPER" => CallData::CALL_SUPER,
  "ZSUPER" => CallData::CALL_ZSUPER,
  "OPT_SEND" => CallData::CALL_OPT_SEND,
  "KW_SPLAT_MUT" => CallData::CALL_KW_SPLAT_MUT
}.freeze
DEFINED_TYPES =
[
  nil,
  "nil",
  "instance-variable",
  "local-variable",
  "global-variable",
  "class variable",
  "constant",
  "method",
  "yield",
  "super",
  "self",
  "true",
  "false",
  "assignment",
  "expression",
  "ref",
  "func",
  "constant-from"
].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(lines) ⇒ Assembler

Returns a new instance of Assembler.



66
67
68
# File 'lib/syntax_tree/yarv/assembler.rb', line 66

def initialize(lines)
  @lines = lines
end

Instance Attribute Details

#linesObject (readonly)

Returns the value of attribute lines.



64
65
66
# File 'lib/syntax_tree/yarv/assembler.rb', line 64

def lines
  @lines
end

Class Method Details

.assemble(source) ⇒ Object



78
79
80
# File 'lib/syntax_tree/yarv/assembler.rb', line 78

def self.assemble(source)
  new(source.lines(chomp: true)).assemble
end

.assemble_file(filepath) ⇒ Object



82
83
84
# File 'lib/syntax_tree/yarv/assembler.rb', line 82

def self.assemble_file(filepath)
  new(File.readlines(filepath, chomp: true)).assemble
end

Instance Method Details

#assembleObject



70
71
72
73
74
75
76
# File 'lib/syntax_tree/yarv/assembler.rb', line 70

def assemble
  iseq = InstructionSequence.new("<main>", "<compiled>", 1, :top)
  assemble_iseq(iseq, lines)

  iseq.compile!
  iseq
end