Example #1
0
File: object.py Project: dirk/stalk
 def call(self, parent, args):
     s = SL_Scope()
     s.set_parent(self.closure)
     s.set_local("this", parent)
     i = 0
     params = self._params()
     while i < len(params):
         s.set_local(params[i].get_value(), args[i])
         i += 1
     ret = self.block.send("call:with:", [SL_Array([]), s])
     return ret
Example #2
0
def _block_call_binary(method, args):
    # args[0] = SL_Array
    b_block = method.parent.get_value_block() # S_Block
    b_params = b_block.get_header()
    sent_params = args[0]
    if type(sent_params) != SL_Array:
        # TODO: Make this duck-check instead of type-check
        #return SL_Exception("Params must be an array")
        raise Exception("Params must be an array")
    sent_params_array = sent_params.get_value_array()#[SL_Object...]
    recv_params_array = b_params.get_nodes()#[S_Identifier...]
    if len(sent_params_array) != len(recv_params_array):
        raise Exception("Sent and receiving param lengths do not match")
    
    scope = SL_Scope()
    i = 0
    for s_i in recv_params_array:
        scope.set_local(s_i.get_value(), sent_params_array[i])
        i += 1
    b_closure = method.parent.get_closure()
    scope.set_parent(b_closure)
    
    b_list = b_block.get_list()
    return b_list.eval(scope)