Skip to content

Commit

Permalink
bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
victorlei committed Aug 18, 2016
1 parent 1cf07b9 commit a379717
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 41 deletions.
50 changes: 16 additions & 34 deletions smop/Makefile
Original file line number Diff line number Diff line change
@@ -1,59 +1,41 @@

# 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) $^

%.so: %.c
gcc -Wno-cpp -I /usr/include/python$V -O2 -shared -o $@ $^

%.py: %.m
#smop $(FLAGS) -o $@ $^
$(PYTHON) main.py -o $@ $^
$(PYTHON) $@

Expand Down
12 changes: 8 additions & 4 deletions smop/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"||": "or",
"&&": "and",
"^" : "**",
"**": "**",
".^": "**",
"./": "/",
".*": "*",
Expand Down Expand Up @@ -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())
Expand Down
3 changes: 2 additions & 1 deletion smop/lexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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"\~|\!"
Expand Down
2 changes: 1 addition & 1 deletion smop/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 6 additions & 1 deletion smop/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit a379717

Please sign in to comment.