phylanx
phylanx copied to clipboard
No support for pass, break, and continue statements in Python frontend
pass
@Phylanx()
def f():
pass
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
<ipython-input-45-0e04c4b83d2a> in <module>()
----> 1 @Phylanx()
2 def f():
3 pass
C:/Repos/phylanx/cmake-build-debug/python/build/lib.win-amd64-3.6\phylanx\ast\transformation.py in __init__(self, f)
562 ast.increment_lineno(tree, actual_lineno)
563 assert len(tree.body) == 1
--> 564 self.transformation = self.targets[target](tree, kwargs)
565 self.__src__ = self.transformation.__src__
566 if self.debug:
C:/Repos/phylanx/cmake-build-debug/python/build/lib.win-amd64-3.6\phylanx\ast\transformation.py in __init__(self, tree, kwargs)
54 for arg in tree.body[0].args.args:
55 self.defs[arg.arg] = 1
---> 56 self.__src__ = self.recompile(tree)
57
58 def _Num(self, a, allowreturn=False):
C:/Repos/phylanx/cmake-build-debug/python/build/lib.win-amd64-3.6\phylanx\ast\transformation.py in recompile(self, a, allowreturn)
463 return self.nodes[nm](self, a, allowreturn)
464 else:
--> 465 return self.nodes[nm](self, a)
466 except NotImplementedError:
467 raise Exception('unsupported AST node type: %s' % nm)
C:/Repos/phylanx/cmake-build-debug/python/build/lib.win-amd64-3.6\phylanx\ast\transformation.py in _Module(self, a, allowreturn)
283 def _Module(self, a, allowreturn=False):
284 args = [arg for arg in ast.iter_child_nodes(a)]
--> 285 return self.recompile(args[0])
286
287 def _Return(self, a, allowreturn=False):
C:/Repos/phylanx/cmake-build-debug/python/build/lib.win-amd64-3.6\phylanx\ast\transformation.py in recompile(self, a, allowreturn)
463 return self.nodes[nm](self, a, allowreturn)
464 else:
--> 465 return self.nodes[nm](self, a)
466 except NotImplementedError:
467 raise Exception('unsupported AST node type: %s' % nm)
C:/Repos/phylanx/cmake-build-debug/python/build/lib.win-amd64-3.6\phylanx\ast\transformation.py in _FunctionDef(self, a, allowreturn)
208 s += ", "
209 if len(args) == 2:
--> 210 s += self.recompile(args[1], True).strip(' ')
211 else:
212 s += '%s(' % full_node_name(a, 'block')
C:/Repos/phylanx/cmake-build-debug/python/build/lib.win-amd64-3.6\phylanx\ast\transformation.py in recompile(self, a, allowreturn)
461 try:
462 if allowreturn:
--> 463 return self.nodes[nm](self, a, allowreturn)
464 else:
465 return self.nodes[nm](self, a)
KeyError: 'Pass'
continue
@Phylanx()
def f():
for i in range(0):
continue
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
<ipython-input-50-c15faa2d0925> in <module>()
----> 1 @Phylanx()
2 def f():
3 for i in range(0):
4 continue
C:/Repos/phylanx/cmake-build-debug/python/build/lib.win-amd64-3.6\phylanx\ast\transformation.py in __init__(self, f)
562 ast.increment_lineno(tree, actual_lineno)
563 assert len(tree.body) == 1
--> 564 self.transformation = self.targets[target](tree, kwargs)
565 self.__src__ = self.transformation.__src__
566 if self.debug:
C:/Repos/phylanx/cmake-build-debug/python/build/lib.win-amd64-3.6\phylanx\ast\transformation.py in __init__(self, tree, kwargs)
54 for arg in tree.body[0].args.args:
55 self.defs[arg.arg] = 1
---> 56 self.__src__ = self.recompile(tree)
57
58 def _Num(self, a, allowreturn=False):
C:/Repos/phylanx/cmake-build-debug/python/build/lib.win-amd64-3.6\phylanx\ast\transformation.py in recompile(self, a, allowreturn)
463 return self.nodes[nm](self, a, allowreturn)
464 else:
--> 465 return self.nodes[nm](self, a)
466 except NotImplementedError:
467 raise Exception('unsupported AST node type: %s' % nm)
C:/Repos/phylanx/cmake-build-debug/python/build/lib.win-amd64-3.6\phylanx\ast\transformation.py in _Module(self, a, allowreturn)
283 def _Module(self, a, allowreturn=False):
284 args = [arg for arg in ast.iter_child_nodes(a)]
--> 285 return self.recompile(args[0])
286
287 def _Return(self, a, allowreturn=False):
C:/Repos/phylanx/cmake-build-debug/python/build/lib.win-amd64-3.6\phylanx\ast\transformation.py in recompile(self, a, allowreturn)
463 return self.nodes[nm](self, a, allowreturn)
464 else:
--> 465 return self.nodes[nm](self, a)
466 except NotImplementedError:
467 raise Exception('unsupported AST node type: %s' % nm)
C:/Repos/phylanx/cmake-build-debug/python/build/lib.win-amd64-3.6\phylanx\ast\transformation.py in _FunctionDef(self, a, allowreturn)
208 s += ", "
209 if len(args) == 2:
--> 210 s += self.recompile(args[1], True).strip(' ')
211 else:
212 s += '%s(' % full_node_name(a, 'block')
C:/Repos/phylanx/cmake-build-debug/python/build/lib.win-amd64-3.6\phylanx\ast\transformation.py in recompile(self, a, allowreturn)
461 try:
462 if allowreturn:
--> 463 return self.nodes[nm](self, a, allowreturn)
464 else:
465 return self.nodes[nm](self, a)
C:/Repos/phylanx/cmake-build-debug/python/build/lib.win-amd64-3.6\phylanx\ast\transformation.py in _For(self, a, allowreturn)
449 if blocki > 2:
450 ret += ", "
--> 451 ret += self.recompile(blockn)
452 blocki += 1
453 if isinstance(a.iter, ast.List):
C:/Repos/phylanx/cmake-build-debug/python/build/lib.win-amd64-3.6\phylanx\ast\transformation.py in recompile(self, a, allowreturn)
463 return self.nodes[nm](self, a, allowreturn)
464 else:
--> 465 return self.nodes[nm](self, a)
466 except NotImplementedError:
467 raise Exception('unsupported AST node type: %s' % nm)
KeyError: 'Continue'
break
@Phylanx()
def f():
for i in range(0):
break
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
<ipython-input-51-799a9fc3d3d3> in <module>()
----> 1 @Phylanx()
2 def f():
3 for i in range(0):
4 break
C:/Repos/phylanx/cmake-build-debug/python/build/lib.win-amd64-3.6\phylanx\ast\transformation.py in __init__(self, f)
562 ast.increment_lineno(tree, actual_lineno)
563 assert len(tree.body) == 1
--> 564 self.transformation = self.targets[target](tree, kwargs)
565 self.__src__ = self.transformation.__src__
566 if self.debug:
C:/Repos/phylanx/cmake-build-debug/python/build/lib.win-amd64-3.6\phylanx\ast\transformation.py in __init__(self, tree, kwargs)
54 for arg in tree.body[0].args.args:
55 self.defs[arg.arg] = 1
---> 56 self.__src__ = self.recompile(tree)
57
58 def _Num(self, a, allowreturn=False):
C:/Repos/phylanx/cmake-build-debug/python/build/lib.win-amd64-3.6\phylanx\ast\transformation.py in recompile(self, a, allowreturn)
463 return self.nodes[nm](self, a, allowreturn)
464 else:
--> 465 return self.nodes[nm](self, a)
466 except NotImplementedError:
467 raise Exception('unsupported AST node type: %s' % nm)
C:/Repos/phylanx/cmake-build-debug/python/build/lib.win-amd64-3.6\phylanx\ast\transformation.py in _Module(self, a, allowreturn)
283 def _Module(self, a, allowreturn=False):
284 args = [arg for arg in ast.iter_child_nodes(a)]
--> 285 return self.recompile(args[0])
286
287 def _Return(self, a, allowreturn=False):
C:/Repos/phylanx/cmake-build-debug/python/build/lib.win-amd64-3.6\phylanx\ast\transformation.py in recompile(self, a, allowreturn)
463 return self.nodes[nm](self, a, allowreturn)
464 else:
--> 465 return self.nodes[nm](self, a)
466 except NotImplementedError:
467 raise Exception('unsupported AST node type: %s' % nm)
C:/Repos/phylanx/cmake-build-debug/python/build/lib.win-amd64-3.6\phylanx\ast\transformation.py in _FunctionDef(self, a, allowreturn)
208 s += ", "
209 if len(args) == 2:
--> 210 s += self.recompile(args[1], True).strip(' ')
211 else:
212 s += '%s(' % full_node_name(a, 'block')
C:/Repos/phylanx/cmake-build-debug/python/build/lib.win-amd64-3.6\phylanx\ast\transformation.py in recompile(self, a, allowreturn)
461 try:
462 if allowreturn:
--> 463 return self.nodes[nm](self, a, allowreturn)
464 else:
465 return self.nodes[nm](self, a)
C:/Repos/phylanx/cmake-build-debug/python/build/lib.win-amd64-3.6\phylanx\ast\transformation.py in _For(self, a, allowreturn)
449 if blocki > 2:
450 ret += ", "
--> 451 ret += self.recompile(blockn)
452 blocki += 1
453 if isinstance(a.iter, ast.List):
C:/Repos/phylanx/cmake-build-debug/python/build/lib.win-amd64-3.6\phylanx\ast\transformation.py in recompile(self, a, allowreturn)
463 return self.nodes[nm](self, a, allowreturn)
464 else:
--> 465 return self.nodes[nm](self, a)
466 except NotImplementedError:
467 raise Exception('unsupported AST node type: %s' % nm)
KeyError: 'Break'
The Python pass construct could be translated to a simple nil (or nothing).
The continue construct will require code transformations as we will not be able to implement something resembling goto in PhySL. For instance:
for cond:
if foo:
continue
bar
will have to be transformed to
for cond:
if not foo:
bar
For the break construct we will have to implement a protocol on how PhySL for() should interact with its body. One way of solving this could be to combine some code transformations with the convention that the next iteration of a loop will be executed only if the body of this loop 'returns' nothing, nil, or false. Returning true would stop the iteration.