diff --git a/smop/Makefile b/smop/Makefile index 5c857340..3b21d3ed 100644 --- a/smop/Makefile +++ b/smop/Makefile @@ -1,51 +1,34 @@ - # for py3: make PYTHON=python3 CYTHON="cython -3" V=3.4 -VPATH = $(SCRIPTS)/strings $(SCRIPTS)/specfun OCTAVE = /home/lei/octave-4.0.2 SCRIPTS = $(OCTAVE)/scripts CYTHON = cython PYTHON = python -XFILES = -x inputParser.m,quadgk.m,quadl.m,triplequad.m,dblquad.m,reallog.m,nthroot.m,factorial.m +#XFILES = -x inputParser.m,quadgk.m,quadl.m,triplequad.m,dblquad.m,uiputfile.m,uigetfile.m,qmr.m,installed_packages.m,stft.m,legend.m,__plt_get_axis_arg__.m,rotate.m,print.m,__ghostscript__.m,__gnuplot_print__.m,set.m,edit.m,what.m,usejava.m,javachk.m,__go_draw_axes__.m,interp3.m,interp2.m,interpn.m,randi.m,interp1.m,spdiags.m,importdata.m,stemleaf.m FLAGS = -V = 2.7 -ALL = \*.m - -factorial.py: factorial.m - $(PYTHON) main.py -v $^ $(FLAGS) -all: mybench.py - $(PYTHON) -c "import mybench ; mybench.mybench()" - -#octave.py: primes.m interp2.m meshgrid.m repmat.m -# $(PYTHON) main.py --callgraph $(FLAGS) $^ -r core -o $@ -# dot -Tpdf -o G.pdf G.dot -#test_primes: octave.py -# $(PYTHON) -c "import octave ; octave.primes(1000)" +V = 2.7 -octave.py: - find $(SCRIPTS)/general $(SCRIPTS)/specfun -name \*.m | xargs python main.py -o $@ $(FLAGS) $(XFILES) +all: + make -B FLAGS= liboctave.py | wc + make -B FLAGS=-C liboctave.py | wc + make -B FLAGS=-N liboctave.py | wc + make -B FLAGS=-T liboctave.py | wc + make -B FLAGS=-CN liboctave.py | wc + make -B FLAGS=-TN liboctave.py | wc + make -B FLAGS=-CT liboctave.py | wc + make -B FLAGS=-CTN liboctave.py | wc +liboctave.py: + find $(SCRIPTS) -name \*.m | xargs $(PYTHON) main.py -o $@ $(FLAGS) $(XFILES) $^ + #$(PYTHON) $@ clean: rm -f a.* *.pyc solver.so solver.py octave.so -solver.py: solver.m #r8_random.m octave.py - $(PYTHON) main.py $^ -o $@ - -check: solver.py - $(PYTHON) test_core.py - $(PYTHON) test_matlabarray.py - $(PYTHON) test_sparsearray.py - $(PYTHON) test_lexer.py - $(PYTHON) test_solver.py -# $(PYTHON) test_primes.py - -#$(PYTHON) main.py $(FLAGS) -r core solver.m r8_random.m -o solver.py && python go.py -#test: -# find $(SCRIPTS) -name $(ALL) | xargs python main.py $(FLAGS) - +regress: + make | sort -u | wc %.c: %.py $(CYTHON) $^ @@ -53,7 +36,6 @@ check: solver.py gcc -Wno-cpp -I /usr/include/python$V -O2 -shared -o $@ $^ %.py: %.m - #smop $(FLAGS) -o $@ $^ $(PYTHON) main.py -o $@ $^ $(PYTHON) $@ diff --git a/smop/backend.py b/smop/backend.py index 25c4883d..13f5c9aa 100644 --- a/smop/backend.py +++ b/smop/backend.py @@ -26,6 +26,7 @@ "||": "or", "&&": "and", "^" : "**", + "**": "**", ".^": "**", "./": "/", ".*": "*", @@ -125,15 +126,18 @@ def _backend(self,level=0): @extend(node.expr) def _backend(self,level=0): - if self.op in ("!","not"): # ??? - return "not %s" % self.args[0]._backend() - if self.op in ("&","and"): + if self.op in ("!","~"): + return "logical_not(%s)" % self.args[0]._backend() + + if self.op == "&": return "logical_and(%s)" % self.args._backend() + if self.op == "&&": return "%s and %s" % (self.args[0]._backend(), self.args[1]._backend()) - if self.op in ("|","or"): + if self.op == "|": return "logical_or(%s)" % self.args._backend() + if self.op == "||": return "%s or %s" % (self.args[0]._backend(), self.args[1]._backend()) diff --git a/smop/lexer.py b/smop/lexer.py index 5e068267..f3675ddb 100644 --- a/smop/lexer.py +++ b/smop/lexer.py @@ -20,7 +20,7 @@ class IllegalCharacterError(Exception): "MINUS","MINUSMINUS","MINUSEQ","MUL","MULEQ","NE", "NEG", "NUMBER", "OR","OREQ", "OROR", "PLUS", "PLUSEQ","PLUSPLUS", "RBRACE", "RBRACKET", "RPAREN", "SEMI", "STRING", - "TRANSPOSE", "ERROR_STMT", "COMMENT", "END_FUNCTION", ] + "TRANSPOSE", "ERROR_STMT", "COMMENT", "END_FUNCTION","POW", ] reserved = { "break" : "BREAK", @@ -73,6 +73,7 @@ def new(): t_MINUSEQ = r"\-=" t_MINUSMINUS = r"\--" t_MUL = r"\*" + t_POW = r"\*\*" t_MULEQ = r"\*=" t_NE = r"(~=)|(!=)" t_NEG = r"\~|\!" diff --git a/smop/main.py b/smop/main.py index be0e8033..5ff22d27 100644 --- a/smop/main.py +++ b/smop/main.py @@ -59,7 +59,7 @@ def main(): s = backend.backend(stmt_list) print >> fp, s except Exception as e: - print e + print "\tFailed: ",options.filename if options.strict: raise diff --git a/smop/parse.py b/smop/parse.py index 5fb64389..ed5ada9a 100644 --- a/smop/parse.py +++ b/smop/parse.py @@ -52,7 +52,7 @@ class syntax_error(error): ("left", "MUL","DIV","DOTMUL","DOTDIV","BACKSLASH"), ("right","UMINUS","NEG"), ("right","TRANSPOSE"), - ("right","EXP", "DOTEXP"), + ("right","EXP", "DOTEXP", "POW"), ("nonassoc","LPAREN","RPAREN","RBRACE","LBRACE"), ("left", "FIELD","DOT","PLUSPLUS","MINUSMINUS"), ) @@ -323,6 +323,7 @@ def p_expr2(p): | expr DOTMUL expr | expr DOTMULEQ expr | expr EQEQ expr + | expr POW expr | expr EXP expr | expr EXPEQ expr | expr GE expr @@ -831,6 +832,10 @@ def p_while_stmt(p): @exceptions def p_error(p): + if p.type == "COMMENT": + #print "Discarded comment", p.value + parser.errok() + return raise syntax_error(p) parser = yacc.yacc(start="top")