Class: Fable::CallStack::Element

Inherits:
Object
  • Object
show all
Defined in:
lib/fable/call_stack.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, pointer, options = {in_expression_evaluation: false}) ⇒ Element

Returns a new instance of Element.



233
234
235
236
237
238
239
240
# File 'lib/fable/call_stack.rb', line 233

def initialize(type, pointer, options = {in_expression_evaluation: false})
  self.current_pointer = pointer.dup
  self.in_expression_evaluation = options[:in_expression_evaluation]
  self.temporary_variables = {}
  self.function_start_in_output_stream = 0
  self.evaluation_stack_height_when_pushed = 0
  self.type = type
end

Instance Attribute Details

#current_pointerObject

Returns the value of attribute current_pointer.



218
219
220
# File 'lib/fable/call_stack.rb', line 218

def current_pointer
  @current_pointer
end

#evaluation_stack_height_when_pushedObject

When this callstack element is actually a function evaluation called from the game, we need to keep track of when it was called so that we know whether there was any return value



226
227
228
# File 'lib/fable/call_stack.rb', line 226

def evaluation_stack_height_when_pushed
  @evaluation_stack_height_when_pushed
end

#function_start_in_output_streamObject

When functions are called, we trim whitespace from the start & end of what they generate, so we make sure we know where the function’s start/end are



231
232
233
# File 'lib/fable/call_stack.rb', line 231

def function_start_in_output_stream
  @function_start_in_output_stream
end

#in_expression_evaluationObject Also known as: in_expression_evaluation?

Returns the value of attribute in_expression_evaluation.



218
219
220
# File 'lib/fable/call_stack.rb', line 218

def in_expression_evaluation
  @in_expression_evaluation
end

#temporary_variablesObject

Returns the value of attribute temporary_variables.



218
219
220
# File 'lib/fable/call_stack.rb', line 218

def temporary_variables
  @temporary_variables
end

#typeObject

Returns the value of attribute type.



218
219
220
# File 'lib/fable/call_stack.rb', line 218

def type
  @type
end

Instance Method Details

#copyObject



242
243
244
245
246
247
248
# File 'lib/fable/call_stack.rb', line 242

def copy
  copied_element = self.class.new(type, current_pointer, in_expression_evaluation: in_expression_evaluation)
  copied_element.temporary_variables = Serializer.convert_to_runtime_objects_hash(Serializer.convert_hash_of_runtime_objects(temporary_variables))
  copied_element.evaluation_stack_height_when_pushed = evaluation_stack_height_when_pushed
  copied_element.function_start_in_output_stream = function_start_in_output_stream
  copied_element
end