Skip to content

Commit 0a6a4f7

Browse files
committed
completing py2/py3 integration
1 parent bce6626 commit 0a6a4f7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1107
-1521
lines changed

src/matlab2cpp/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,9 @@
3030
3131
3232
The simplest way to use the library is to use the quick translation functions.
33-
They are available through the `mc.qfunctions` module and mirrors the
33+
They are available through the `matlab2cpp.qfunctions` module and mirrors the
3434
functionality offered by the `m2cpp` function.
3535
"""
36-
__version__ = "2.0"
37-
3836
try:
3937
import argcomplete
4038
except ImportError:
@@ -43,6 +41,8 @@
4341
from .parser import create_parser
4442
from .qfunctions import *
4543

44+
__version__ = "2.0"
45+
4646

4747
def m2cpp(args=None):
4848
"""

src/matlab2cpp/collection.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ def __init__(self, name="", cur=0, line=0, code="", **kws):
217217
Children:
218218
`Program+`
219219
220-
All keyword arguments are passed to `mc.Node.__init__`.
220+
All keyword arguments are passed to `matlab2cpp.Node.__init__`.
221221
"""
222222
assert "parent" not in kws
223223
self.parent = self
@@ -234,7 +234,7 @@ def __init__(self, parent, name, **kws):
234234
Children:
235235
`Includes Funcs Inlines Structs Headers Log`
236236
237-
All keyword arguments are passed to `mc.Node.__init__`.
237+
All keyword arguments are passed to `matlab2cpp.Node.__init__`.
238238
"""
239239
self._program = self
240240
Node.__init__(self, parent, name=name, **kws)
Lines changed: 2 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,2 @@
1-
from . import tree, datatypes, backends, reserved
2-
3-
4-
def configure(root, suggest=True, **kws):
5-
"""
6-
configure backend
7-
8-
See also:
9-
:py:func:`matlab2cpp.Builder.configure <Builder.configure>`
10-
"""
11-
if isinstance(root, tree.Builder):
12-
root = root.project
13-
14-
loop(root, suggest)
15-
loop(root, suggest)
16-
17-
def loop(root, suggest):
18-
19-
nodes = root.flatten(False, True, True)
20-
21-
while True:
22-
23-
# loop and configure
24-
for node in nodes:
25-
26-
# reserved stuff
27-
if node.cls + "_" + node.name in reserved.__dict__:
28-
rule = reserved.__dict__[node.cls+"_"+node.name]
29-
if isinstance(rule, str):
30-
node.type = rule
31-
else:
32-
rule(node)
33-
34-
# Datatype stuff
35-
if node.prop["type"] != "TYPE":
36-
pass
37-
38-
elif node.cls in datatypes.__dict__:
39-
datatype = datatypes.__dict__[node.cls]
40-
if isinstance(datatype, str):
41-
node.type = datatype
42-
else:
43-
datatype(node)
44-
45-
# Backend stuff
46-
if node.backend != "unknown":
47-
pass
48-
49-
elif node.cls in backends.__dict__:
50-
backend = backends.__dict__[node.cls]
51-
if isinstance(backend, str):
52-
node.backend = backend
53-
else:
54-
backend(node)
55-
56-
# determine if done
57-
if suggest:
58-
59-
complete = True
60-
61-
for program in root.project:
62-
63-
suggests = program.suggest
64-
program.stypes = suggests
65-
program.ftypes = suggests
66-
complete = complete and not any([any(v) for v in suggests.values()])
67-
68-
if complete:
69-
break
70-
71-
else:
72-
break
73-
74-
# delete log, if any (create on translate)
75-
for program in root.project:
76-
program[-1].children = []
1+
from .frontend import configure, loop
2+
from . import datatypes, backends, reserved

src/matlab2cpp/configure/armadillo.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import matlab2cpp.rules.armadillo as arma
1+
from ..rules import armadillo as arma
2+
23

34
def vec(node):
45
if len(node) != 1:
@@ -12,7 +13,7 @@ def vec(node):
1213
else:
1314
return
1415

15-
16+
1617
arg, dim = arma.configure_arg(node[0], 0)
1718

1819
if dim == 0:
@@ -31,8 +32,8 @@ def rowvec(node):
3132
return
3233
else:
3334
node_ = node[0]
34-
35-
35+
36+
3637
arg, dim = arma.configure_arg(node_, 0)
3738

3839
if dim == 0:
@@ -43,7 +44,7 @@ def mat(node):
4344
if len(node) == 1:
4445

4546
arg, dim = arma.configure_arg(node[0], 0)
46-
47+
4748
# scalar begets scalar
4849
if dim == 0:
4950
node.dim = 0

src/matlab2cpp/configure/backends.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def Matrix(node):
9393
def Fvar(node):
9494
"""
9595
Example:
96-
>>> print(mc.qtree("a.b = 4.4; c = [a.b]", core=True, suggest=True)) #doctest: +NORMALIZE_WHITESPACE
96+
>>> print(matlab2cpp.qtree("a.b = 4.4; c = [a.b]", core=True, suggest=True)) #doctest: +NORMALIZE_WHITESPACE
9797
1 1Block code_block TYPE
9898
1 1| Assign double double
9999
1 1| | Fvar struct double a

src/matlab2cpp/configure/datatypes.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11

22
from .funcs import funcs
3-
from . import armadillo, backends
4-
from .configure import configure
3+
from . import armadillo, backends, frontend
54

65
Counter = "structs"
76

87
def Var(node):
98
"""
109
Example:
11-
>>> print(mc.qcpp("a.b = 4; c = a"))
10+
>>> print(matlab2cpp.qcpp("a.b = 4; c = a"))
1211
#include <armadillo>
1312
using namespace arma ;
1413
<BLANKLINE>
@@ -167,7 +166,7 @@ def Assign(node):
167166
return
168167
node.type = node[1].type
169168
# node[0].declare.suggest = node[1].type
170-
169+
171170

172171
def Vector(node):
173172

@@ -212,11 +211,11 @@ def Vector(node):
212211
node.dim = 2
213212

214213
# mix of scalars and rowvecs
215-
elif dims == {0,2}:
214+
elif dims == {0, 2}:
216215
node.dim = 2
217216

218217
# mix of matrices and colvecs
219-
elif dims in ({3}, {1,3}):
218+
elif dims in ({3}, {1, 3}):
220219
node.dim = 3
221220

222221
def Matrix(node):
@@ -305,6 +304,8 @@ def Minus(node):
305304

306305
def Mul(node):
307306
opr(node)
307+
if "TYPE" in (n.type for n in node):
308+
return
308309
mem = max([n.mem for n in node])
309310
if node[0].dim == 2 and node[1].dim == 1:
310311
node.type = (0, mem)
@@ -406,7 +407,7 @@ def Lambda(node):
406407
node_.type = type
407408
node_.declare.type = type
408409

409-
configure(lfunc)
410+
frontend.configure(lfunc)
410411
# declare list in lambda function
411412
if ldeclares["_retval"].type != "TYPE":
412413
declares[node.name[1:]].type = "func_lambda"

src/matlab2cpp/configure/funcs.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ def funcs(node):
77
# lambda scope
88
if "_" + node.name in node.program[1]:
99
func = node.program[1]["_" + node.name]
10-
10+
1111
# local scope
1212
elif node in node.program[1]:
1313
func = node.program[1][node]
@@ -76,4 +76,4 @@ def funcs(node):
7676
params[i].suggest = node[i].type
7777

7878
return True
79-
79+

0 commit comments

Comments
 (0)