Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: m-labs/artiq
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 4978f8b3d775
Choose a base ref
...
head repository: m-labs/artiq
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: f510d3aa4996
Choose a head ref
  • 2 commits
  • 2 files changed
  • 1 contributor

Commits on Sep 26, 2014

  1. Copy the full SHA
    d101126 View commit details
  2. Copy the full SHA
    f510d3a View commit details
Showing with 68 additions and 8 deletions.
  1. +12 −6 artiq/py2llvm/ast_body.py
  2. +56 −2 test/full_stack.py
18 changes: 12 additions & 6 deletions artiq/py2llvm/ast_body.py
Original file line number Diff line number Diff line change
@@ -43,7 +43,7 @@ def __init__(self, env, ns, builder=None):
self.ns = ns
self.builder = builder
self._break_stack = []
self._eid_stack = []
self._active_exception_stack = []
self._exception_level_stack = [0]

# builder can be None for visit_expression
@@ -294,15 +294,21 @@ def _visit_stmt_Pass(self, node):
pass

def _visit_stmt_Raise(self, node):
if node.exc is None:
eid = self._eid_stack[-1]
if self._active_exception_stack:
finally_block, propagate, propagate_eid = self._active_exception_stack[-1]
self.builder.store(lc.Constant.int(lc.Type.int(1), 1), propagate)
if node.exc is not None:
eid = lc.Constant.int(lc.Type.int(), node.exc.args[0].n)
self.builder.store(eid, propagate_eid)
self.builder.branch(finally_block)
else:
eid = lc.Constant.int(lc.Type.int(), node.exc.args[0].n)
self.env.build_raise(self.builder, eid)
self.env.build_raise(self.builder, eid)

def _handle_exception(self, function, finally_block, propagate, propagate_eid, handlers):
eid = self.env.build_getid(self.builder)
self._eid_stack.append(eid)
self._active_exception_stack.append(
(finally_block, propagate, propagate_eid))
self.builder.store(lc.Constant.int(lc.Type.int(1), 1), propagate)
self.builder.store(eid, propagate_eid)

@@ -336,7 +342,7 @@ def _handle_exception(self, function, finally_block, propagate, propagate_eid, h
self.builder.position_at_end(cont_exc_block)
self.builder.branch(finally_block)

self._eid_stack.pop()
self._active_exception_stack.pop()

def _visit_stmt_Try(self, node):
function = self.builder.basic_block.function
58 changes: 56 additions & 2 deletions test/full_stack.py
Original file line number Diff line number Diff line change
@@ -52,7 +52,7 @@ def pulse(self, f, duration):
self.print_off(int(now()))


class _PulseTest(AutoContext):
class _Pulses(AutoContext):
def build(self):
for name in "a", "b", "c", "d":
pl = _PulseLogger(self, name=name)
@@ -70,6 +70,52 @@ def run(self):
self.d.pulse(400+i, 20*us)


class _MyException(Exception):
pass


class _Exceptions(AutoContext):
parameters = "trace"

@kernel
def run(self):
for i in range(10):
self.trace.append(i)
if i == 4:
try:
self.trace.append(10)
try:
self.trace.append(11)
break
except:
pass
else:
self.trace.append(12)
try:
self.trace.append(13)
except:
pass
except _MyException:
self.trace.append(14)

for i in range(4):
try:
self.trace.append(100)
if i == 1:
raise _MyException
elif i == 2:
raise IndexError
except (TypeError, IndexError):
self.trace.append(101)
raise
except:
self.trace.append(102)
else:
self.trace.append(103)
finally:
self.trace.append(104)


class SimCompareCase(unittest.TestCase):
def test_primes(self):
l_device, l_host = [], []
@@ -80,7 +126,15 @@ def test_primes(self):
def test_pulses(self):
# TODO: compare results on host and device
# (this requires better unit management in the compiler)
_run_on_device(_PulseTest)
_run_on_device(_Pulses)

def test_exceptions(self):
t_device, t_host = [], []
with self.assertRaises(IndexError):
_run_on_device(_Exceptions, trace=t_device)
with self.assertRaises(IndexError):
_run_on_host(_Exceptions, trace=t_host)
self.assertEqual(t_device, t_host)


class _RTIOLoopback(AutoContext):