Permalink
Browse files

implemented 'is' compare operator

  • Loading branch information...
cantora committed Oct 10, 2012
1 parent 0727da2 commit ceee19e50ac43314896f453ccbbfb4f680cc55e1
Showing with 36 additions and 2 deletions.
  1. +1 −1 makefile
  2. +35 −1 pyc_ir.py
View
@@ -5,7 +5,7 @@ P0TESTS = $(wildcard ./p0tests/grader_tests/*.py) #\
#$(filter-out %stack_test.py, $(wildcard ./p0tests/mytests/*.py) ) \
#$(wildcard ./p0tests/student_tests/*.py)
-P1TESTS = $(filter-out %eq1.py %is0.py , $(wildcard ./p1tests/grader_tests/*.py) )
+P1TESTS = $(wildcard ./p1tests/grader_tests/*.py)
.PHONY: pkg
pkg: hw.zip
View
@@ -76,17 +76,51 @@ def visit_IfExp(self, node):
orelse = pyc_vis.visit(self, node.orelse)
)
+ def visit_Compare_Is(self, node, l_name, comp_name):
+
+ class IsPolySwitch(PolySwitch):
+
+ def no_match(self, name_typ_list):
+ return false_node()
+
+ def int_int(self, l, r):
+ return simple_compare(ProjectToInt(l), ProjectToInt(r))
+
+ def bool_bool(self, l, r):
+ return simple_compare(ProjectToBool(l), ProjectToBool(r))
+
+ def big_big(self, l, r):
+ return simple_compare(ProjectToBig(l), ProjectToBig(r))
+ #end IsPolySwitch
+
+ return let_env(
+ InjectFromBool(polyswitch(IsPolySwitch(), l_name, comp_name)) ,
+ (
+ l_name,
+ pyc_vis.visit(self, node.left)
+ ),
+ (
+ comp_name,
+ pyc_vis.visit(self, node.comparators[0])
+ )
+ )
+
def visit_Compare(self, node):
if len(node.ops) != 1:
raise BadAss("expected 1 compare op: %s" % dump(node) )
- elif not isinstance(node.ops[0], ast.Eq) and not isinstance(node.ops[0], ast.NotEq):
+ elif not isinstance(node.ops[0], ast.Eq) \
+ and not isinstance(node.ops[0], ast.NotEq) \
+ and not isinstance(node.ops[0], ast.Is):
raise BadAss("unexpected compare context: %s" % dump(node) )
elif len(node.comparators) != 1:
raise BadAss("expected 1 comparator: %s" % dump(node) )
l_name = var_ref(self.gen_name())
comp_name = var_ref(self.gen_name() )
+ if isinstance(node.ops[0], ast.Is):
+ return self.visit_Compare_Is(node, l_name, comp_name)
+
result = let_env(
InjectFromBool(make_cmp(l_name, comp_name)),
(

0 comments on commit ceee19e

Please sign in to comment.