Permalink
Browse files

implemented '!=' operator

  • Loading branch information...
cantora committed Oct 10, 2012
1 parent 23d69cf commit 8232fac5d3f56b65cd8e394987a20b198ba1a920
Showing with 11 additions and 4 deletions.
  1. +1 −1 makefile
  2. +10 −3 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 %dict0.py %dict1.py %eq1.py %is0.py %list0.py %list1.py %list2.py %list3.py %list4.py %list5.py %list6.py %list7.py %neq0.py, $(wildcard ./p1tests/grader_tests/*.py) )
+P1TESTS = $(filter-out %dict0.py %dict1.py %eq1.py %is0.py %list0.py %list1.py %list2.py %list3.py %list4.py %list5.py %list6.py %list7.py, $(wildcard ./p1tests/grader_tests/*.py) )
.PHONY: pkg
pkg: hw.zip
View
@@ -79,15 +79,15 @@ def visit_IfExp(self, node):
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):
- raise BadAss("expected compare to use equality context: %s" % dump(node) )
+ elif not isinstance(node.ops[0], ast.Eq) and not isinstance(node.ops[0], ast.NotEq):
+ 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() )
- return let_env(
+ result = let_env(
InjectFromBool(make_cmp(l_name, comp_name)),
(
l_name,
@@ -99,6 +99,13 @@ def visit_Compare(self, node):
)
)
+ if isinstance(node.ops[0], ast.NotEq):
+ return InjectFromBool(ast.UnaryOp(
+ op = ast.Not(),
+ operand = IsTrue(result)
+ ))
+
+ return result
def visit_Call(self, node):
if node.func.id != "input":

0 comments on commit 8232fac

Please sign in to comment.