Class: Atomy::Code::StringLiteral

Inherits:
Object
  • Object
show all
Defined in:
lib/atomy/code/string_literal.rb

Constant Summary collapse

ESCAPES =
{
  "n" => "\n", "s" => "\s", "r" => "\r", "t" => "\t", "v" => "\v",
  "f" => "\f", "b" => "\b", "a" => "\a", "e" => "\e", "\\" => "\\"
}

Instance Method Summary collapse

Constructor Details

#initialize(value, raw = false) ⇒ StringLiteral

Returns a new instance of StringLiteral.



9
10
11
12
# File 'lib/atomy/code/string_literal.rb', line 9

def initialize(value, raw = false)
  @value = value
  @raw = raw
end

Instance Method Details

#bytecode(gen, mod) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'lib/atomy/code/string_literal.rb', line 14

def bytecode(gen, mod)
  if @raw
    gen.push_literal(@value)
  else
    gen.push_literal(process_escapes(@value))
  end

  gen.string_dup
end