]> hydra-www.ietfng.org Git - dyna2/commitdiff
Merge branch 'master' of ssh://github.com/nwf/dyna
authorTim Vieira <tim.f.vieira@gmail.com>
Thu, 11 Jul 2013 18:43:46 +0000 (14:43 -0400)
committerTim Vieira <tim.f.vieira@gmail.com>
Thu, 11 Jul 2013 18:43:46 +0000 (14:43 -0400)
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).

1  2 
src/Dyna/Backend/Python/Backend.hs
src/Dyna/Backend/Python/Selftest.hs
src/Dyna/Backend/Python/interpreter.py
src/Dyna/Backend/Python/stdlib.py
src/Dyna/Term/TTerm.hs

index 7d19c29cbacfe2f987d1a448b83e258fd819f6e3,267568e5f77bbcfb195727902fccf717fb46e625..752f0db44fe3f53503312a4805d1342c370cb429
@@@ -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"]
  
Simple merge
index 1b740cd1b7b02ba90657bd74f09b4acb3e794b0a,81c62c9a0fba61b0554284c49b376a745f225106..516a83e3ac35dc30280101df7ee5a16c8116ab2a
@@@ -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
index 32938e8496137daf9bca7cda0832867b9c06ffa5,64f2355cc013fb61bcafd5163adf4f72c2d3495b..a8a9e66ba9ce5ad05a8c829dccfdb528416e735b
@@@ -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