From 1ae7724a1590c697a637a3a8de1da5f2c2c8666b Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Mon, 29 Sep 2014 18:09:48 +0800 Subject: [PATCH] transforms/interleave: support try statements --- artiq/transforms/interleave.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/artiq/transforms/interleave.py b/artiq/transforms/interleave.py index b98f7ea99..d421d902a 100644 --- a/artiq/transforms/interleave.py +++ b/artiq/transforms/interleave.py @@ -17,6 +17,15 @@ def _get_duration(stmt): return 0 else: return -1 + elif isinstance(stmt, ast.Try): + if (all(_get_duration(s) == 0 for s in stmt.body) + and all(_get_duration(s) == 0 for s in stmt.orelse) + and all(_get_duration(s) == 0 for s in stmt.finalbody) + and all(_get_duration(s) == 0 for s in handler.body + for handler in stmt.handlers)): + return 0 + else: + return -1 elif isinstance(stmt, ast.Call) and isinstance(stmt.func, ast.Name): name = stmt.func.id if name == "delay": @@ -89,6 +98,12 @@ def _interleave_stmts(stmts): if isinstance(stmt, (ast.For, ast.While, ast.If)): _interleave_stmts(stmt.body) _interleave_stmts(stmt.orelse) + elif isinstance(stmt, ast.Try): + _interleave_stmts(stmt.body) + _interleave_stmts(stmt.orelse) + _interleave_stmts(stmt.finalbody) + for handler in stmt.handlers: + _interleave_stmts(handler.body) elif isinstance(stmt, ast.With): btype = stmt.items[0].context_expr.id if btype == "sequential":