From: Tim Vieira Date: Mon, 8 Jul 2013 19:10:41 +0000 (-0400) Subject: Small tweaks. X-Git-Url: https://hydra-www.ietfng.org/gitweb/?a=commitdiff_plain;h=c96da6615abe0d0311c9ccf9b9b18a731fe255e6;p=dyna2 Small tweaks. added `range` to stdlib tiny tweak (nonfunctional) to doctest. small improvement to bool (runtime) type checking. --- diff --git a/src/Dyna/Backend/Python/Backend.hs b/src/Dyna/Backend/Python/Backend.hs index 79c8d79..d6423eb 100644 --- a/src/Dyna/Backend/Python/Backend.hs +++ b/src/Dyna/Backend/Python/Backend.hs @@ -176,6 +176,8 @@ constants = go 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 "<=" diff --git a/src/Dyna/Backend/Python/dyna_doctest.py b/src/Dyna/Backend/Python/dyna_doctest.py index d3cd5ad..244df58 100644 --- a/src/Dyna/Backend/Python/dyna_doctest.py +++ b/src/Dyna/Backend/Python/dyna_doctest.py @@ -18,7 +18,7 @@ def extract(code): for i, line in enumerate(block.split('\n')): if (line.startswith('|') or i == 0) and reading: if line.startswith('|'): - line = line[1:] + line = ' ' + line[1:] cmd.append(line) else: reading = False diff --git a/src/Dyna/Backend/Python/interpreter.py b/src/Dyna/Backend/Python/interpreter.py index b4b54d8..a3e9bb9 100644 --- a/src/Dyna/Backend/Python/interpreter.py +++ b/src/Dyna/Backend/Python/interpreter.py @@ -628,14 +628,11 @@ def peel(fn, item): functor/arity, `fn`. Returns the arguments of term as a tuple of intern idxs and constants (possibly an empty tuple). """ - - if fn == "true/0" : -# assert item is True - assert bool(item) + if fn == "true/0": + assert item is true return - if fn == "false/0" : -# assert item is False - assert not bool(item) + if fn == "false/0": + assert item is false return assert isinstance(item, Term) assert item.fn == fn diff --git a/src/Dyna/Backend/Python/repl.py b/src/Dyna/Backend/Python/repl.py index a9299ea..6133c45 100644 --- a/src/Dyna/Backend/Python/repl.py +++ b/src/Dyna/Backend/Python/repl.py @@ -133,14 +133,14 @@ class REPL(cmd.Cmd, object): # """ # ip() -# def do_debug(self, line): -# """ -# Development tool. Used for view Dyna's intermediate representations. -# """ -# import debug -# with file(dotdynadir / 'repl-debug-line.dyna', 'wb') as f: -# f.write(line) -# debug.main(f.name) + def do_debug(self, line): + """ + Development tool. Used for view Dyna's intermediate representations. + """ + import debug + with file(dotdynadir / 'repl-debug-line.dyna', 'wb') as f: + f.write(line) + debug.main(f.name) # def do_run(self, filename): # """ diff --git a/src/Dyna/Backend/Python/stdlib.py b/src/Dyna/Backend/Python/stdlib.py index 8e47293..5e8e922 100644 --- a/src/Dyna/Backend/Python/stdlib.py +++ b/src/Dyna/Backend/Python/stdlib.py @@ -11,6 +11,11 @@ except ImportError: # XXX: should probably issue a warning def uniform(a=0, b=1): return _random() * (b - a) + a + +_range = range +def range(*x): + return todyna(_range(*x)) + def split(s, delim='\s+'): return todynalist(re.split(delim, s)) diff --git a/test/app/ptb.dynadoc b/test/app/ptb.dynadoc index 0ee4322..30cd48c 100644 --- a/test/app/ptb.dynadoc +++ b/test/app/ptb.dynadoc @@ -107,7 +107,7 @@ > % a strange way to get back sentences as lists | sentence(S, I) = | T is b(tree(S)), -| I in pycall("range", 0, numwords(T)), +| I in range(0, numwords(T)), | word(I, T). | | slen(S) max= _ is sentence(S, I), I. diff --git a/test/repl/load.dynadoc b/test/repl/load.dynadoc index dce812a..e25ba41 100644 --- a/test/repl/load.dynadoc +++ b/test/repl/load.dynadoc @@ -1,7 +1,4 @@ -> :- dispos &cons(&,&). -| :- dispos &nil. -| -| % binary rules +> % binary rules | rewrite(X, Y, Z) := | rules_tsv(Linenum, Cost, X, R), | [Y, Z] is split(R, "\\s+"), @@ -17,7 +14,7 @@ | phrase(S,X,I,K) += phrase(S,Y,I,J) + phrase(S,Z,J,K) + rewrite(X,Y,Z). | phrase(S,W,I,I+1) += W is token(S,I), 0. | -| sentence_length(S) max= token(S,I), I+1. +| sentence_length(S) max= _ is token(S,I), I+1. | goal(S) += phrase(S, "ROOT", 0, sentence_length(S)).