def test_type_context(self): ctx_1 = AST.Type_Context.get_empty_context() ctx_1.add(AST.Id_Val("i"), 10) ctx_1.add(AST.Id_Val("j"), 20) ctx_1.add(AST.Id_Val("k"), 30) ctx_2 = AST.Type_Context.get_empty_context() ctx_2.add(AST.Id_Val("a"), 100, {"val": True}) ctx_2.add(AST.Id_Val("b"), 200) ctx_2.add(AST.Id_Val("c"), 300) self.assertEqual(ctx_1.lookup(AST.Id_Val("k")), 30) self.assertEqual(ctx_2.lookup(AST.Id_Val("b")), 200) # look up something that doesn't exist in the context scope try: ctx_1.lookup(AST.Id_Val("ds")) except exceptions.Context_Lookup_Error as e: # flush out the error message so that it doesn't print at the end sys.stdout.flush() # look up outer scope of top-level context, result in None self.assertEqual(ctx_2.get_outer_context_var_id(), None)
def var_expr(s): return AST.Id_Val(s[0].getstr())