Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
victorlei committed May 25, 2018
2 parents 4e0dcd9 + 245d9c8 commit 41faaba
Show file tree
Hide file tree
Showing 14 changed files with 183 additions and 181 deletions.
9 changes: 8 additions & 1 deletion HACKING.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
node.py resolve.py

class method
node.ident self.ident



=========
HACKING
=========
Expand All @@ -8,7 +15,7 @@ HACKING
| | | | |
| A. Base-one indexing | yes | yes | no |
+-----------------------------------------+-------+-------+-------+
| | | | |
| | | | |
| B. Columns-first data layout | yes | yes | no |
+-----------------------------------------+-------+-------+-------+
| C. Auto-expanding arrays | yes | no * | yes |
Expand Down
43 changes: 16 additions & 27 deletions INSTALL
Original file line number Diff line number Diff line change
@@ -1,29 +1,18 @@
smop -- matlab to python compiler

Installation with easy_install
==============================

This is the preferred option, because easy_install takes care of
everything -- finding the dowinload site, and installing the dependences
(numpy and networkx). If you don't have easy_install, this is the
perfect time to install it. It is a part of setuptools package located
at http://pypi.python.org/pypi/setuptools.

$ easy_install smop

Binary Windows installer
========================

Download it from github then run it, but you must make sure you have
installed the dependences -- numpy and networkx.

Installation from sources
=========================

$ tar zxvf smop.tar.gz
$ cd smop
$ python setup.py install [--user]

If you use the --user option, don't forget to put
your .local/bin into the search path (unix only).

Installation from sources with pip
==================================

This is the preferred option, because pip takes
care of everything -- finding the dowinload
site, installing the dependences (numpy and
networkx), etc. If you don't have pip, this
is the perfect time to install it.

$ pip install smop --user
$ tar zxvf smop.tar.gz
$ cd smop
$ pip install . --user

If you use the --user option, don't forget to
put your .local/bin into the search path (unix only).
9 changes: 8 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import os
from setuptools import setup

from smop.version import __version__ as __VERSION__
#from smop.version import __version__ as __VERSION__

try:
__VERSION__ = os.popen("git describe --tags").read().strip()
except OSError as e:
__VERSION__ = ""

open("smop/version.py","w").write("__version__='%s'" % __VERSION__)

setup(
author = 'Victor Leikehman',
Expand Down
18 changes: 16 additions & 2 deletions smop/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# for py3: make PYTHON=python3 CYTHON="cython -3" V=3.4
# for py3: make PYTHON=python3 CYTHON="cython -3" V=3

OCTAVE = /home/lei/octave-4.0.2
SCRIPTS = $(OCTAVE)/scripts/specfun
Expand All @@ -7,13 +7,27 @@ CYTHON = cython
PYTHON = python
XFILES = -x inputParser.m,dblquad.m,triplequad.m

COVERAGE = python3 -m coverage

CYTHON = cython
PYTHON = python$V
XFILES = -x inputParser.m,dblquad.m,triplequad.m

SRCSMOP = main.py parse.py backend.py resolve.py options.py
FLAGS =
MYFLAGS=

V = 2.7
#V = 2.7
V = 3

all:
<<<<<<< HEAD
make -B FLAGS= liboctave.py
=======
make -B FLAGS= liboctave.py
$(COVERAGE) run -p main.py solver.m
$(COVERAGE) combine
>>>>>>> 245d9c8989e304a637840d6bcbd87d8905a96101
foo:
make -B FLAGS=-C liboctave.py
make -B FLAGS=-N liboctave.py
Expand Down
6 changes: 1 addition & 5 deletions smop/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
# SMOP compiler -- Simple Matlab/Octave to Python compiler
# Copyright 2011-2014 Victor Leikehman

import version
import parse,resolve,backend,main
from version import __version__
# Copyright 2011-2018 Victor Leikehman
11 changes: 8 additions & 3 deletions smop/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@

import logging
logger = logging.getLogger(__name__)
import node,options
from node import extend,exceptions

from . import node
from . import options
from . node import extend,exceptions

indent = " "*4

Expand Down Expand Up @@ -364,7 +366,10 @@ def _backend(self,level=0):

@extend(node.string)
def _backend(self,level=0):
return "'%s'" % str(self.value).encode("string_escape")
try:
return "'%s'" % str(self.value).encode("string_escape")
except:
return "'%s'" % str(self.value)

@extend(node.sub)
def _backend(self,level=0):
Expand Down
13 changes: 8 additions & 5 deletions smop/lexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import re
import ply.lex as lex
from ply.lex import TOKEN
import options
from . import options


tokens = [
Expand Down Expand Up @@ -98,7 +98,10 @@ def unescape(s):
if s[0] == "'":
return s[1:-1].replace("''", "'")
else:
return s[1:-1].decode("string_escape")
try:
return s[1:-1].decode("string_escape")
except:
return s[1:-1]

@TOKEN(mos)
def t_afterkeyword_STRING(t):
Expand Down Expand Up @@ -339,11 +342,11 @@ def main():
while 1:
try:
line += raw_input("=>> ").decode("string_escape")
print len(line), [c for c in line]
print(len(line), [c for c in line])
except EOFError:
reload(sys.modules["lexer.py"])
lexer.input(line)
print list(tok for tok in lexer)
print(list(tok for tok in lexer))
line = ""


Expand All @@ -354,4 +357,4 @@ def main():
buf = open(sys.argv[1]).read()
lexer.input(buf)
for tok in lexer:
print tok
print(tok)
18 changes: 8 additions & 10 deletions smop/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,17 @@
import traceback
from os.path import basename, splitext

import lexer
import options
import parse
import resolve
import backend
import version

from . import options
from . import parse
from . import resolve
from . import backend
from . import version

def print_header(fp):
if options.no_header:
return
print("# Autogenerated with SMOP ",
version.__version__, file=fp)
print("# Running Python %s" % sys.version, file=fp)
print("# Generated with SMOP ", version.__version__, file=fp)
print("from libsmop import *", file=fp)
print("#", options.filename, file=fp)

Expand Down Expand Up @@ -59,7 +57,7 @@ def main():
continue
buf = open(options.filename).read()
buf = buf.replace("\r\n", "\n")
buf = buf.decode("ascii", errors="ignore")
# FIXME buf = buf.decode("ascii", errors="ignore")
stmt_list = parse.parse(buf if buf[-1] == '\n' else buf + '\n')

if not stmt_list:
Expand Down
10 changes: 6 additions & 4 deletions smop/node.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# SMOP compiler -- Simple Matlab/Octave to Python compiler
# Copyright 2011-2013 Victor Leikehman


from __future__ import print_function
from collections import namedtuple
from recipes import recordtype
import copy,sys,inspect
import options

from . recipes import recordtype
from . import options

# def preorder(u):
# if isinstance(u,traversable):
Expand Down Expand Up @@ -44,7 +46,7 @@ def wrapper(self,*args,**kwargs):
try:
return f(self,*args,**kwargs)
except:
print "%s.%s()" % (self.__class__.__name__, f.__name__)
print("%s.%s()" % (self.__class__.__name__, f.__name__))
raise
wrapper.__name__ = f.__name__
wrapper.__doc__ = f.__doc__
Expand Down
Loading

0 comments on commit 41faaba

Please sign in to comment.