From 203d5f13722d38ab6decabbfd0b4dd659bd48de9 Mon Sep 17 00:00:00 2001 From: Victor Lei Date: Tue, 22 Nov 2016 11:36:54 +0300 Subject: [PATCH] 0.32.2 --- NEWS.rst | 16 ++++++++++++++++ smop/libscripts/Makefile | 4 ++++ smop/main.py | 33 +++++++++++++++++++++++---------- smop/options.py | 10 +++++----- smop/parse.py | 21 ++++++++++----------- 5 files changed, 58 insertions(+), 26 deletions(-) diff --git a/NEWS.rst b/NEWS.rst index 7a7bf969..8212c1de 100644 --- a/NEWS.rst +++ b/NEWS.rst @@ -1,6 +1,22 @@ ============= Release notes ============= + + Version 0.33 is out + + New option -c --code + Quickly check how a particular statement + is translated. Option -c implies -o- . + + Renamed option -D to -d (--debug). + + New regression count: + + $ cd libscripts && make regresss + + Currently 14 regressions + + November 18, 2016 Version 0.31 is out diff --git a/smop/libscripts/Makefile b/smop/libscripts/Makefile index 3b49de5a..c1e26d0f 100644 --- a/smop/libscripts/Makefile +++ b/smop/libscripts/Makefile @@ -16,11 +16,15 @@ V = 2.7 all: pyfiles $(PYTHON) -m py_compile *.py +regress: + $(SMOP) $(FLAGS) $(MFILES) | grep Error | wc + .PHONY: all pyfiles clean pyfiles: $(SMOP) $(FLAGS) $(MFILES) + wall: $(PYFILES) $(CAT) *.py > libscripts.py diff --git a/smop/main.py b/smop/main.py index 3760ab04..125e8890 100644 --- a/smop/main.py +++ b/smop/main.py @@ -1,6 +1,7 @@ # SMOP -- Simple Matlab/Octave to Python compiler # Copyright 2011-2016 Victor Leikehman +import tempfile import fnmatch import tarfile import sys @@ -25,14 +26,26 @@ def print_header(fp): def main(): - if not options.filelist and not options.archive: - options.parser.print_help() - return - if not options.filelist and options.archive: - tar = tarfile.open(options.archive) - options.filelist = tar.getnames() - else: - tar = None + tar = None + if "M" in options.debug: + import pdb + pdb.set_trace() + if not options.filelist: + if options.archive: + tar = tarfile.open(options.archive) + options.filelist = tar.getnames() + elif options.code: + tmp = tempfile.NamedTemporaryFile(suffix=".m") + tmp.file.write(options.code) + tmp.file.flush() + options.filelist = [tmp.name] + if options.output: + print "Conflicting options -c and -o" + return + options.output = "-" + else: + options.parser.print_help() + return if options.output == "-": fp = sys.stdout elif options.output: @@ -54,7 +67,7 @@ def main(): options.filename) continue if basename(options.filename) in options.xfiles: - if options.verbose and "a3" in options.debug: + if options.verbose: print "\tExcluded: '%s'" % options.filename continue if tar: @@ -81,7 +94,7 @@ def main(): except: print 40*"=" - traceback.print_exc() + traceback.print_exc(file=sys.stdout) if __name__ == "__main__": main() diff --git a/smop/options.py b/smop/options.py index f40bc1c4..7a0ed991 100644 --- a/smop/options.py +++ b/smop/options.py @@ -28,6 +28,7 @@ formatter_class=argparse.RawTextHelpFormatter, ) +parser.add_argument("-c", "--code") parser.add_argument("-a", "--archive", metavar="archive.tar", @@ -92,12 +93,11 @@ type=str, help="""comma-separated list of files to ignore""") -parser.add_argument("-D", "--debug", type=str, +parser.add_argument("-d", "--debug", help="""Colon-separated codes. -a Main -b Lex -c Parse -1 After parsing +M Main +L Lex +P Parse """) parser.add_argument("-L", "--debug-lexer", diff --git a/smop/parse.py b/smop/parse.py index ba2ad50d..a7795d0c 100644 --- a/smop/parse.py +++ b/smop/parse.py @@ -838,25 +838,25 @@ def p_error(p): @exceptions def parse(buf): + if "P" in options.debug: + import pdb + pdb.set_trace() global new_lexer # used in main.main() new_lexer = lexer.new() p = parser.parse( buf, tracking=1, debug=options.debug_parser, lexer=new_lexer) - if "1" in options.debug: + if "P" in options.debug: for i, pi in enumerate(p): print i, pi.__class__.__name__, pi._backend() - if "p" in options.debug: - import pdb - pdb.set_trace() - - for i in range(len(p)): - if isinstance(p[i], node.func_stmt): - break - else: - return None # p[i] is a func decl +# for i in range(len(p)): +# if isinstance(p[i], node.func_stmt): +# break +# else: +# return None # p[i] is a func decl + return p # for j in range(i+1,len(p)): # if i < j and isinstance(p[j], node.func_stmt): # p.insert(j,node.return_stmt(ret=p[i].ret)) @@ -868,4 +868,3 @@ def parse(buf): # for i,pi in enumerate(p): # print i,pi.__class__.__name__,str(pi)[:50] - return p