# Path: src/som/interpreter/ast/frame.py
# class Frame(object):
# 
#     _immutable_fields_ = ['_receiver', '_arguments[*]', '_args_for_inner[*]',
#                           '_temps', '_temps_for_inner', '_on_stack']
#     _virtualizable_    = ['_temps[*]']
# 
#     def __init__(self, receiver, arguments, arg_mapping, num_local_temps,
#                  num_context_temps):
#         make_sure_not_resized(arguments)
#         make_sure_not_resized(arg_mapping)
#         self = jit.hint(self, access_directly=True, fresh_virtualizable=True)
#         self._receiver        = receiver
#         self._arguments       = arguments
#         self._on_stack        = _FrameOnStackMarker()
#         if num_local_temps == 0:
#             self._temps       = _EMPTY_LIST
#         else:
#             self._temps       = [nilObject] * num_local_temps
# 
#         self._args_for_inner  = self._collect_shared_args(arg_mapping)
#         if num_context_temps == 0:
#             self._temps_for_inner = _EMPTY_LIST
#         else:
#             self._temps_for_inner = [nilObject] * num_context_temps
# 
#     @jit.unroll_safe
#     def _collect_shared_args(self, arg_mapping):
#         if len(arg_mapping) == 0:
#             return _EMPTY_LIST
#         return [self._arguments[i] for i in arg_mapping]
# 
#     def get_context_values(self):
#         return self._receiver, self._args_for_inner, self._temps_for_inner, self._on_stack
# 
#     def get_argument(self, index):
#         jit.promote(index)
#         return self._arguments[index]
# 
#     def set_argument(self, index, value):
#         self._arguments[index] = value
# 
#     def get_temp(self, index):
#         jit.promote(index)
#         temps = self._temps
#         assert 0 <= index < len(temps)
#         assert temps is not None
#         return temps[index]
# 
#     def set_temp(self, index, value):
#         jit.promote(index)
#         temps = self._temps
#         assert temps is not None
#         assert 0 <= index < len(temps)
#         temps[index] = value
# 
#     def get_shared_temp(self, index):
#         jit.promote(index)
#         temps = self._temps_for_inner
#         assert 0 <= index < len(temps)
#         assert temps is not None
#         return temps[index]
# 
#     def set_shared_temp(self, index, value):
#         jit.promote(index)
#         temps = self._temps_for_inner
#         assert temps is not None
#         assert 0 <= index < len(temps)
#         temps[index] = value
# 
#     def get_self(self):
#         return self._receiver
# 
#     def get_on_stack_marker(self):
#         return self._on_stack
# 
#     def __str__(self):
#         return "Frame(%s, %s, %s)" % (self._receiver, self._arguments,
#                                       self._temps)


from rlib import jit
from rlib.debug import make_sure_not_resized
from rtruffle.node import Node
from .frame import Frame
    # two different jit drivers are involved (in our case, the primitive
    # driver, and this one).

    # the next line says that calls involving this jitdriver should always be
    # inlined once (which means that things like Integer>>< will be inlined
    # into a while loop again, when enabling this driver).
    should_unroll_one_iteration = lambda self: True)


class Invokable(Node):

    _immutable_fields_ = ['_expr_or_sequence?', '_universe', '_arg_mapping[*]',
                          '_num_local_temps', '_num_context_temps']
    _child_nodes_      = ['_expr_or_sequence']

    def __init__(self, source_section, expr_or_sequence,
                 arg_mapping, number_of_local_temps, number_of_context_temps,
                 universe):
        Node.__init__(self, source_section)
        self._expr_or_sequence  = self.adopt_child(expr_or_sequence)
        self._universe          = universe
        assert isinstance(arg_mapping, list)
        self._arg_mapping = arg_mapping
        self._num_local_temps   = number_of_local_temps
        self._num_context_temps = number_of_context_temps

    def invoke(self, receiver, arguments):
        assert arguments is not None
        make_sure_not_resized(arguments)


# Path: src/som/interpreter/ast/frame.py
# class Frame(object):
# 
#     _immutable_fields_ = ['_receiver', '_arguments[*]', '_args_for_inner[*]',
#                           '_temps', '_temps_for_inner', '_on_stack']
#     _virtualizable_    = ['_temps[*]']
# 
#     def __init__(self, receiver, arguments, arg_mapping, num_local_temps,
#                  num_context_temps):
#         make_sure_not_resized(arguments)
#         make_sure_not_resized(arg_mapping)
#         self = jit.hint(self, access_directly=True, fresh_virtualizable=True)
#         self._receiver        = receiver
#         self._arguments       = arguments
#         self._on_stack        = _FrameOnStackMarker()
#         if num_local_temps == 0:
#             self._temps       = _EMPTY_LIST
#         else:
#             self._temps       = [nilObject] * num_local_temps
# 
#         self._args_for_inner  = self._collect_shared_args(arg_mapping)
#         if num_context_temps == 0:
#             self._temps_for_inner = _EMPTY_LIST
#         else:
#             self._temps_for_inner = [nilObject] * num_context_temps
# 
#     @jit.unroll_safe
#     def _collect_shared_args(self, arg_mapping):
#         if len(arg_mapping) == 0:
#             return _EMPTY_LIST
#         return [self._arguments[i] for i in arg_mapping]
# 
#     def get_context_values(self):
#         return self._receiver, self._args_for_inner, self._temps_for_inner, self._on_stack
# 
#     def get_argument(self, index):
#         jit.promote(index)
#         return self._arguments[index]
# 
#     def set_argument(self, index, value):
#         self._arguments[index] = value
# 
#     def get_temp(self, index):
#         jit.promote(index)
#         temps = self._temps
#         assert 0 <= index < len(temps)
#         assert temps is not None
#         return temps[index]
# 
#     def set_temp(self, index, value):
#         jit.promote(index)
#         temps = self._temps
#         assert temps is not None
#         assert 0 <= index < len(temps)
#         temps[index] = value
# 
#     def get_shared_temp(self, index):
#         jit.promote(index)
#         temps = self._temps_for_inner
#         assert 0 <= index < len(temps)
#         assert temps is not None
#         return temps[index]
# 
#     def set_shared_temp(self, index, value):
#         jit.promote(index)
#         temps = self._temps_for_inner
#         assert temps is not None
#         assert 0 <= index < len(temps)
#         temps[index] = value
# 
#     def get_self(self):
#         return self._receiver
# 
#     def get_on_stack_marker(self):
#         return self._on_stack
# 
#     def __str__(self):
#         return "Frame(%s, %s, %s)" % (self._receiver, self._arguments,
#                                       self._temps)


# Path: src/som/interpreter/ast/invokable.py
from rlib import jit
from rlib.debug import make_sure_not_resized
from rtruffle.node import Node
from .frame import Frame

    # two different jit drivers are involved (in our case, the primitive
    # driver, and this one).

    # the next line says that calls involving this jitdriver should always be
    # inlined once (which means that things like Integer>>< will be inlined
    # into a while loop again, when enabling this driver).
    should_unroll_one_iteration = lambda self: True)


class Invokable(Node):

    _immutable_fields_ = ['_expr_or_sequence?', '_universe', '_arg_mapping[*]',
                          '_num_local_temps', '_num_context_temps']
    _child_nodes_      = ['_expr_or_sequence']

    def __init__(self, source_section, expr_or_sequence,
                 arg_mapping, number_of_local_temps, number_of_context_temps,
                 universe):
        Node.__init__(self, source_section)
        self._expr_or_sequence  = self.adopt_child(expr_or_sequence)
        self._universe          = universe
        assert isinstance(arg_mapping, list)
        self._arg_mapping = arg_mapping
        self._num_local_temps   = number_of_local_temps
        self._num_context_temps = number_of_context_temps

    def invoke(self, receiver, arguments):
        assert arguments is not None
        make_sure_not_resized(arguments)


        frame = Frame(receiver, arguments, self._arg_mapping,