Beispiel #1
0
 def testSettingNew(self):
     """
     Setting a non-existent variable should die.
     """
     new = {}
     env = E.pushFrame(self.env, new)
     self.assertRaises(NameError, E.set, env, "a", 3.14)
Beispiel #2
0
 def testDefinition(self):
     """
     Defining z should add it to the innermost frame.
     """
     new = {}
     env = E.pushFrame(self.env, new)
     E.define(env, "z", 4)
     self.assertEquals(new["z"], 4)
Beispiel #3
0
 def testDefinitionShadowing(self):
     """
     Defining x should change it in the innermost frame and not
     affect the binding of x in the outer frames.
     """
     new = {}
     env = E.pushFrame(self.env, new)
     E.define(env, "x", 5)
     self.assertEquals(self.init["x"], 1)
     self.assertEquals(new["x"], 5)
Beispiel #4
0
def special_let(interp, oform, env):
    "(let bindings &body)"
    form = oform.pyvalue
    bindings = form[1].pyvalue
    body = form[2:]
    d = {}
    for binding in bindings:
        name, value = binding.pyvalue
        d[name.name] = interp.evalForm(value, env)
    newEnv = E.pushFrame(env, d)
    r = None
    for code in body:
        r = interp.evalForm(code, newEnv)
    return r
Beispiel #5
0
 def callFunc(self, interp, args=None):
     #print "appending", self
     interp.frames.append(self)
     if args is not None:
         bindings = self.makeBindings(args.pyvalue)
     else:
         bindings = {}
     newEnv = E.pushFrame(self.env, bindings)
     r = None
     for form in self.body:
         self.curform = form
         r = interp.evalForm(form, newEnv)
     #print "popping", self
     interp.frames.pop()
     return r
Beispiel #6
0
 def testLookupInner(self):
     second = {"y": 2}
     env = E.pushFrame(self.env, second)
     self.assertEquals(E.lookup(env, "y"), 2)