def test_failed_lookup(self): a = expr.Symbol("a") def cont(_, amb): pass with self.assertRaises(SymbolNotFoundError): self.env.lookup(a, cont, lambda: None)
def test_lookup(self): a = expr.Symbol("a") b = expr.Constant(10) new_env = self.env.extend({a: b}) c = None def cont(v, amb): nonlocal c c = v new_env.lookup( a, cont, lambda: None)() # we have to bounce the result to evaluate cont. self.assertEqual(b, c, "lookup should find a = 10")
def __init__(self, input: StringIO, output: StringIO, error: StringIO): self.input = input self.output = output self.error = error self.tokeniser = reader.Tokeniser(input) self.reader = reader.Reader(self.tokeniser, error) operators = { "+": expr.Addition(), # int -> int -> int "-": expr.Subtraction(), # int -> int -> int "*": expr.Multiplication(), # int -> int -> int "/": expr.Division(), # int -> int -> int "%": expr.Modulus(), # int -> int -> int "**": expr.Exponentiation(), # int -> int -> int "==": expr.Equality(), # t -> t -> bool "<": expr.LT(), # t -> t -> bool ">": expr.GT(), # t -> t -> bool "<=": expr.LE(), # t -> t -> bool ">=": expr.GE(), # t -> t -> bool "!=": expr.NE(), # t -> t -> bool "and": expr.And(), # bool -> bool -> bool "or": expr.Or(), # bool -> bool -> bool "not": expr.Not(), # bool -> bool "xor": expr.Xor(), # bool -> bool -> bool "@": expr.Cons(), # t -> list(t) -> list(t) "@@": expr.Append(), # list(t) -> list(t) -> list(t) "back": expr.Back(), # _ "then": expr.Then(), # t -> t -> t "head": expr.Head(), # list(t) -> t "tail": expr.Tail(), # list(t) -> list(t) "length": expr.Length(), # list(t) -> int "print": expr.Print(self.output), # t -> t "here": expr.CallCC(), # ((t -> _) -> t) -> a ? "exit": expr.Exit(), # _ "spawn": expr.Spawn(), # bool "error": expr.Error(lambda val, amb: lambda: self.repl( ambivalence.Amb(lambda: None))) # _ } self.env = environment.Environment().extend( {expr.Symbol(k): v for k, v in operators.items()}) globalenv = expr.Symbol("globalenv") self.env.non_eval_context_define(globalenv, expr.EnvironmentWrapper(self.env)) self.type_env = TypeEnvironment().extend() for k, v in operators.items(): if v.static_type(): self.type_env[expr.Symbol(k)] = v.type() self.type_env[globalenv] = EnvironmentType(self.type_env)
def setUp(self): self.a = expr.Symbol("a") self.b = expr.Symbol("b") self.c = expr.Symbol("c") self.list = expr.LinkedList.list([self.a, self.b, self.c]) self.null = expr.Null()
def setUp(self): self.a = expr.Symbol("a") self.b = expr.Symbol("b") self.b2 = expr.Symbol("b")