From: Nathaniel Wesley Filardo Date: Sat, 15 Jun 2013 00:24:06 +0000 (-0400) Subject: Take a stab at fixing up = vs == X-Git-Url: https://hydra-www.ietfng.org/gitweb/?a=commitdiff_plain;h=0e383b2dc4b0c247307e2c311e06f9f25631a85a;p=dyna2 Take a stab at fixing up = vs == Adds examples/equalities.dyna to selftests. --- diff --git a/examples/equalities.dyna b/examples/equalities.dyna new file mode 100644 index 0000000..102ae8a --- /dev/null +++ b/examples/equalities.dyna @@ -0,0 +1,17 @@ +% Given two items with different names and equal values... +a += 0. +b += 0. + +% == +by_evl_refl := a == a. % True +by_evl_cross := a == b. % True + +% = +by_syn_refl := a = a. % &a is the same as &a +by_syn_cross := a = b. % ... but not the same as &b. + +% is +by_is_0a := 0 is a. % That's right, a evaluates to 0. +by_is_ab := a is b. % b does not evaluate to &a, so this is + % a unification failure and the head + % remains null (not false). diff --git a/examples/expected/equalities.py.out b/examples/expected/equalities.py.out new file mode 100644 index 0000000..637d9c7 --- /dev/null +++ b/examples/expected/equalities.py.out @@ -0,0 +1,35 @@ + +Charts +============ +a/0 +================= +a := 0 + +b/0 +================= +b := 0 + +by_evl_cross/0 +================= +by_evl_cross := true + +by_evl_refl/0 +================= +by_evl_refl := true + +by_is_0a/0 +================= +by_is_0a := true + +by_is_ab/0 +================= + + +by_syn_cross/0 +================= +by_syn_cross := false + +by_syn_refl/0 +================= +by_syn_refl := true + diff --git a/src/Dyna/Backend/Python/Backend.hs b/src/Dyna/Backend/Python/Backend.hs index 4d08cd2..d40d6d6 100644 --- a/src/Dyna/Backend/Python/Backend.hs +++ b/src/Dyna/Backend/Python/Backend.hs @@ -147,8 +147,7 @@ constants = go go ("<=",2) = Just $ PDBS $ infixOp "<=" go ("<",2) = Just $ PDBS $ infixOp "<" - go ("=",2) = Just $ PDBS $ infixOp "=" - -- XXX "==" means something else in Dyna + go ("=",2) = Just $ PDBS $ infixOp "==" go ("==",2) = Just $ PDBS $ infixOp "==" go (">=",2) = Just $ PDBS $ infixOp ">=" go (">",2) = Just $ PDBS $ infixOp ">" diff --git a/src/Dyna/Backend/Python/Selftest.hs b/src/Dyna/Backend/Python/Selftest.hs index 7e13bdd..99db414 100644 --- a/src/Dyna/Backend/Python/Selftest.hs +++ b/src/Dyna/Backend/Python/Selftest.hs @@ -75,7 +75,7 @@ mkExample name = -- will be broken. ;) test_End_To_End :: [Test] test_End_To_End = map mkExample - [ "simple", "fib-limit", "dijkstra", "papa2", "matrixops" ] + [ "simple", "equalities", "fib-limit", "dijkstra", "papa2", "matrixops" ] test_REPL :: [Test] test_REPL = map (\n -> testProgramRuns n ("./test/repl/"++n) []) diff --git a/src/Dyna/Term/SurfaceSyntax.hs b/src/Dyna/Term/SurfaceSyntax.hs index 77ce614..a0c45d2 100644 --- a/src/Dyna/Term/SurfaceSyntax.hs +++ b/src/Dyna/Term/SurfaceSyntax.hs @@ -62,6 +62,7 @@ defOperSpec = M.fromList , ("<=" ,[(4,PFIn AssocNone ) ]) , ("<" ,[(4,PFIn AssocNone ) ]) , ("=" ,[(4,PFIn AssocNone ) ]) + , ("==" ,[(4,PFIn AssocNone ) ]) , (">=" ,[(4,PFIn AssocNone ) ]) , (">" ,[(4,PFIn AssocNone ) ]) , ("!=" ,[(4,PFIn AssocNone ) ]) @@ -165,7 +166,8 @@ disposTab_dyna t = DisposTab s a -- There are, however, even in this case a few terms we would prefer to -- behave structurally by default. dt = M.fromList [ - (("pair" ,2),(SDQuote,[ADEval,ADEval])) + (("=" ,2),(SDEval ,[ADQuote,ADQuote])) + , (("pair" ,2),(SDQuote,[ADEval ,ADEval ])) , (("true" ,0),(SDQuote,[])) , (("false",0),(SDQuote,[])) ]