From: Tim Vieira Date: Thu, 11 Jul 2013 18:43:46 +0000 (-0400) Subject: Merge branch 'master' of ssh://github.com/nwf/dyna X-Git-Url: https://hydra-www.ietfng.org/gitweb/?a=commitdiff_plain;h=6fc273aed95a1dfffa49c58ced03dd14fddff403;p=dyna2 Merge branch 'master' of ssh://github.com/nwf/dyna Conflicts: src/Dyna/Backend/Python/Backend.hs src/Dyna/Backend/Python/interpreter.py Had to make a small change to pretty printing of @nwf's new representation of true and false (they need to print as *lower case* true and false). --- 6fc273aed95a1dfffa49c58ced03dd14fddff403 diff --cc src/Dyna/Backend/Python/Backend.hs index 7d19c29,267568e..752f0db --- a/src/Dyna/Backend/Python/Backend.hs +++ b/src/Dyna/Backend/Python/Backend.hs @@@ -125,7 -127,7 +127,7 @@@ builtins (f,is,o) = case () o -> case is of [x,y] | isFree x && isGround y -> let -- call _ vs = "iter_cons" <> (parens $ sepBy comma $ mpv vs) <> colon -- for some reason on colon get put at the end of this line. ++ call _ vs = "iter_cons" <> (parens $ sepBy comma $ mpv vs) <> colon cdop = [OPIter x [y] "iter" DetNon (Just $ PDBS call)] cmod = [(x^.mv_var, nuniv)] in if isFree o @@@ -173,28 -176,31 +175,26 @@@ constants = g go ("split",_) = Just $ PDBS $ call "split" [] go ("float",_) = Just $ PDBS $ call "float" [] go ("int",_) = Just $ PDBS $ call "int" [] - go ("pycall",_) = Just $ PDBS $ call "pycall" [] - go ("range",_) = Just $ PDBS $ call "range" [] - go ("in",2) = Just $ PDBS $ call "in_list" [] - - go ("<=",2) = Just $ PDBS $ infixOp "<=" - go ("<",2) = Just $ PDBS $ infixOp "<" - go ("=",2) = Just $ PDBS $ call "equals" [] - go ("==",2) = Just $ PDBS $ call "equals" [] - go (">=",2) = Just $ PDBS $ infixOp ">=" - go (">",2) = Just $ PDBS $ infixOp ">" - go ("!=",2) = Just $ PDBS $ infixOp "!=" + go ("<=",2) = Just $ PDBS $ call "lte" [] + go ("<",2) = Just $ PDBS $ call "lt" [] + go ("=",2) = Just $ PDBS $ call "eq" [] + go ("==",2) = Just $ PDBS $ call "eq" [] + go (">=",2) = Just $ PDBS $ call "gte" [] + go (">",2) = Just $ PDBS $ call "gt" [] + go ("!=",2) = Just $ PDBS $ call "not_eq" [] - go ("and",2) = Just $ PDBS $ infixOp "and" - go ("or",2) = Just $ PDBS $ infixOp "or" + go ("|",2) = Just $ PDBS $ call "or_" [] + go ("&",2) = Just $ PDBS $ call "and_" [] + go ("!",1) = Just $ PDBS $ call "not_" [] - go ("true",0) = Just $ PDBS $ nullary "true" - go ("false",0) = Just $ PDBS $ nullary "false" - go ("null",0) = Just $ PDBS $ nullary "None" -- XXX + go ("null",0) = Just $ PDBS $ nullary "null" - go ("!",1) = Just $ PDBS $ call "not" [] - go ("not",1) = Just $ PDBS $ call "not" [] - - go ("eval",1) = Just $ PDBS $ call "None;exec " [] - go ("tuple",_) = Just $ PDBS $ call "" [] + --go ("eval",1) = Just $ PDBS $ call "None;exec " [] + --go ("tuple",_) = Just $ PDBS $ call "" [] + go ("in",2) = Just $ PDBS $ call "in_list" [] go ("nil",0) = Just $ PDBS $ call "build" ["nil/0"] go ("cons",2) = Just $ PDBS $ call "build" ["cons/2"] diff --cc src/Dyna/Backend/Python/stdlib.py index 1b740cd,81c62c9..516a83e --- a/src/Dyna/Backend/Python/stdlib.py +++ b/src/Dyna/Backend/Python/stdlib.py @@@ -1,45 -1,16 +1,42 @@@ import re -from term import Term, Cons, Nil +from term import Term, Cons, Nil, MapsTo from collections import Counter -from utils import pretty, pretty_print - - +from utils import pretty, pretty_print, true, false, null, isbool from math import log, exp, sqrt from random import random as _random -def uniform(a=0, b=1): - return _random() * (b - a) + a - def uniform(a=0, b=1): - return _random() * (b - a) + a - -def equals(x,y): +def or_(x, y): + if not (isbool(x) and isbool(y)): + raise TypeError('') + return todyna(x or y) + +def and_(x, y): + if not (isbool(x) and isbool(y)): + raise TypeError('') + return todyna(x and y) + +def not_(x): + if not isbool(x): + raise TypeError('') + if x: + return false + else: + return true + +def gt(x, y): + return todyna(x > y) + +def gte(x, y): + return todyna(x >= y) + +def lt(x, y): + return todyna(x < y) + +def lte(x, y): + return todyna(x <= y) + +def eq(x,y): """ My work around for discrepency in bool equality True==1 and False==0. @@@ -150,3 -105,3 +147,6 @@@ def in_list(x, a) def read_lines(filename): with file(filename) as f: return f.readlines() ++ ++def uniform(a=0, b=1): ++ return _random() * (b - a) + a diff --cc src/Dyna/Term/TTerm.hs index 32938e8,64f2355..a8a9e66 --- a/src/Dyna/Term/TTerm.hs +++ b/src/Dyna/Term/TTerm.hs @@@ -52,6 -53,7 +53,11 @@@ data TBase = TBool !Boo deriving (D.Data,D.Typeable,Eq,Ord,Show) instance PP.Pretty TBase where - pretty (TBool x) = PP.pretty x ++ --pretty (TBool x) = PP.pretty x ++ ++ pretty (TBool True) = "true" ++ pretty (TBool False) = "false" ++ pretty (TNumeric (Left x)) = PP.pretty x pretty (TNumeric (Right x)) = PP.pretty x pretty (TString s) = PP.text $ show s