Class: Assembler::SymbolTable

Inherits:
Object
  • Object
show all
Defined in:
lib/hackasm/assembler/symbol_table.rb

Constant Summary collapse

DEFAULT_SYMBOL_TABLE =
{
  "SP" => 0,
  "LCL" => 1,
  "ARG" => 2,
  "THIS" => 3,
  "THAT" => 4,
  "SCREEN" => 16384,
  "KBD" => 24576,
}.merge(("0".."15").map { |i| ["R" + i, i.to_i] }.to_h).freeze

Instance Method Summary collapse

Constructor Details

#initialize(expressions) ⇒ SymbolTable

Returns a new instance of SymbolTable.



13
14
15
# File 'lib/hackasm/assembler/symbol_table.rb', line 13

def initialize(expressions)
  @expressions = expressions
end

Instance Method Details

#to_hObject



17
18
19
20
21
22
23
# File 'lib/hackasm/assembler/symbol_table.rb', line 17

def to_h
  DEFAULT_SYMBOL_TABLE.merge(
    label_symbols
  ).merge(
    variable_symbols
  )
end