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,
  "BLOCKISEQ" => CallData::CALL_BLOCKISEQ,
  "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(filepath) ⇒ Assembler

Returns a new instance of Assembler.



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

def initialize(filepath)
  @filepath = filepath
end

Instance Attribute Details

#filepathObject (readonly)

Returns the value of attribute filepath.



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

def filepath
  @filepath
end

Class Method Details

.assemble(filepath) ⇒ Object



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

def self.assemble(filepath)
  new(filepath).assemble
end

Instance Method Details

#assembleObject



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

def assemble
  iseq = InstructionSequence.new("<main>", "<compiled>", 1, :top)
  assemble_iseq(iseq, File.readlines(filepath, chomp: true))

  iseq.compile!
  iseq
end