Esempio n. 1
0
def test_clone_not_deep():
    a1 = W_NormalObject()
    b1 = W_NormalObject()
    a1.setvalue('b', b1)
    a2 = a1.clone()
    b2 = a2.getvalue('b')
    assert b1 is b2
Esempio n. 2
0
def test_clone():
    w1 = W_NormalObject()
    w1.setvalue('abc', W_Integer(6))
    w2 = w1.clone()
    assert w2.getvalue('abc').value == 6
    w2.setvalue('abc', W_Integer(99))
    assert w2.getvalue('abc').value == 99
    assert w1.getvalue('abc').value == 6       # still the old value
Esempio n. 3
0
def test_normalobject():
    w1 = W_NormalObject()
    # 'setvalue' and 'getvalue' write and read the attributes by name.
    w1.setvalue('abc', W_Integer(6))
    w2 = w1.getvalue('abc')
    assert isinstance(w2, W_Integer)
    assert w2.value == 6
    # a missing attribute...
    assert w1.getvalue('bcd') is None
Esempio n. 4
0
 def eval_ObjectDefinition(self, ast, context):
     parent_names = ast.parentnames
     parent_values = map(lambda a: self.eval(a, context), ast.parentdefinitions)
     parents = dict(zip(parent_names, parent_values))
     parents['__parent__'] = context
     obj = W_NormalObject(parents)
     obj.parents = parent_names
     self.eval(ast.block, obj)
     context.setvalue(ast.name, obj)
     return obj
Esempio n. 5
0
 def eval_MethodCall(self, ast, context):
     receiver = self.eval(ast.receiver, context)
     if ast.methodname == 'self':
         subject = receiver.getparents()[0]
     else:
         subject = receiver.getvalue(ast.methodname)
     if(subject.callable()):
         block = subject.getvalue('block')
         arg_names = subject.getvalue('arguments')
         arg_values = map(lambda a: self.eval(a, context), ast.arguments)
         method_context = W_NormalObject(dict(zip(arg_names, arg_values)))
         method_context.setvalue('__parent__', receiver)
         return self.eval(block,method_context)
     else:
         return subject
Esempio n. 6
0
 def op_method_call(self, arg):
     args = []
     for i in xrange(arg):
         args.insert(0,self.stack.pop())
     method = self.stack.pop()
     receiver = self.stack.pop()
     if isinstance(method, W_Method):
         code = method.block
         context = W_NormalObject()
         i = 0
         for a in args:
             context.setvalue(code.symbols[i], a)
             i += 1
         context.setvalue('self', receiver)
         context.setvalue('__parent__', receiver)
         res = self.eval(code, context, self.interpreter)
     else:
         res = method
     self.stack.append(res)
Esempio n. 7
0
def test_getvalue_from_parent():
    o = W_NormalObject({'foo': W_Integer(42)})
    bar = W_NormalObject({'__parent__': o})
    assert bar.getvalue('__parent__') is o
    assert bar.getvalue('foo').value == 42