예제 #1
0
def run_string(string):
    tokens = OysterScanner(string).tokenize()
    statements = OysterParser().parse(tokens)
    instructions = [
        Instruction(Instruction.CODE, statement)
        for statement in statements.items
    ]
    instructions.reverse()
    env = populate_globals(Env(None, None))
    stack = [StackFrame(instructions, env)]
    cur = None
    while stack:
        cur = eval(stack, cur)

    print "Result is", cur.__str__()
예제 #2
0
 def setUp(self):
     self.lexical_environment = Env(None, None)
     self.calling_environment = Env(None, None)
     self.local = Env(self.lexical_environment,
                      self.calling_environment)
예제 #3
0
class EnvironmentTests(TestCase):
    def setUp(self):
        self.lexical_environment = Env(None, None)
        self.calling_environment = Env(None, None)
        self.local = Env(self.lexical_environment,
                         self.calling_environment)

    def test_local_set(self):
        self.local.set("a", 5)
        self.assertEqual(self.local.this_environment["a"], 5)

    def test_local_lookup(self):
        self.local.set("a", 5)
        self.assertEqual(self.local.lookup("a"), 5)

    def test_leaked_lookup(self):
        self.calling_environment.set("a", 6)
        self.local.leak("a")

        self.assertEqual(self.local.lookup("a"), 6)

    def test_leaked_set(self):
        self.calling_environment.set("a", 6)
        self.local.leak("a")
        self.local.set("a", 10)

        self.assertEqual(self.calling_environment.this_environment["a"], 10)

    def test_lexical_environment_lookup(self):
        self.lexical_environment.set("a", 15)
        self.assertEqual(self.local.lookup("a"), 15)

    def test_alter_set(self):
        self.local.alter("a")
        self.local.set("a", 20)

        self.assertEqual(self.local.lookup("a"), 20)
        self.assertEqual(self.lexical_environment.this_environment["a"], 20)

    def test_default_lookup(self):
        self.calling_environment.set("a", 6)
        self.lexical_environment.set("a", 12)

        self.assertEqual(self.local.lookup("a"), 12)
예제 #4
0
파일: test_case.py 프로젝트: diiq/oyoy
 def setUp(self):
     self.env = populate_globals(Env(None, None))
예제 #5
0
 def setUp(self):
     self.lexical_environment = Env(None, None)
     self.calling_environment = Env(None, None)
     self.local = Env(self.lexical_environment, self.calling_environment)
예제 #6
0
class EnvironmentTests(TestCase):
    def setUp(self):
        self.lexical_environment = Env(None, None)
        self.calling_environment = Env(None, None)
        self.local = Env(self.lexical_environment, self.calling_environment)

    def test_local_set(self):
        self.local.set("a", 5)
        self.assertEqual(self.local.this_environment["a"], 5)

    def test_local_lookup(self):
        self.local.set("a", 5)
        self.assertEqual(self.local.lookup("a"), 5)

    def test_leaked_lookup(self):
        self.calling_environment.set("a", 6)
        self.local.leak("a")

        self.assertEqual(self.local.lookup("a"), 6)

    def test_leaked_set(self):
        self.calling_environment.set("a", 6)
        self.local.leak("a")
        self.local.set("a", 10)

        self.assertEqual(self.calling_environment.this_environment["a"], 10)

    def test_lexical_environment_lookup(self):
        self.lexical_environment.set("a", 15)
        self.assertEqual(self.local.lookup("a"), 15)

    def test_alter_set(self):
        self.local.alter("a")
        self.local.set("a", 20)

        self.assertEqual(self.local.lookup("a"), 20)
        self.assertEqual(self.lexical_environment.this_environment["a"], 20)

    def test_default_lookup(self):
        self.calling_environment.set("a", 6)
        self.lexical_environment.set("a", 12)

        self.assertEqual(self.local.lookup("a"), 12)