Class: Halunke::Runtime::HObject

Inherits:
Object
  • Object
show all
Defined in:
lib/halunke/runtime/hobject.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(runtime_class, dict, source_code_position:) ⇒ HObject

Returns a new instance of HObject.



10
11
12
13
14
15
16
17
18
19
# File 'lib/halunke/runtime/hobject.rb', line 10

def initialize(runtime_class, dict, source_code_position:)
  @runtime_class = runtime_class
  @dict = {}
  @source_code_position = source_code_position
  dict.each_pair do |hkey, value|
    key = hkey.ruby_value
    raise HUnknownAttribute.new("Unknown attribute '#{key}' for #{@runtime_class.name}", source_code_position) unless @runtime_class.allowed_attribute? key
    @dict[key] = value
  end
end

Instance Attribute Details

#dictObject (readonly)

Returns the value of attribute dict.



6
7
8
# File 'lib/halunke/runtime/hobject.rb', line 6

def dict
  @dict
end

#runtime_classObject (readonly)

Returns the value of attribute runtime_class.



7
8
9
# File 'lib/halunke/runtime/hobject.rb', line 7

def runtime_class
  @runtime_class
end

#source_code_positionObject (readonly)

Returns the value of attribute source_code_position.



8
9
10
# File 'lib/halunke/runtime/hobject.rb', line 8

def source_code_position
  @source_code_position
end

Instance Method Details

#inspect(context) ⇒ Object



32
33
34
# File 'lib/halunke/runtime/hobject.rb', line 32

def inspect(context)
  receive_message(context, "inspect", []).ruby_value
end

#receive_message(context, message_name, message_value, source_code_position: NullSourceCodePosition.new) ⇒ Object



21
22
23
24
25
26
27
28
29
30
# File 'lib/halunke/runtime/hobject.rb', line 21

def receive_message(context, message_name, message_value, source_code_position: NullSourceCodePosition.new)
  if message_name == "@ else"
    @dict.fetch(message_value[0].ruby_value, message_value[1])
  else
    m = @runtime_class.lookup(message_name)
    m.receive_message(context, "call", [HArray.create_instance([self].concat(message_value))])
  end
rescue KeyError
  raise HUnknownMessage.new(self.inspect(context), message_name, @runtime_class.instance_methods.keys, source_code_position)
end