Skip to content

Commit bdcf7f1

Browse files
author
whitequark
committedAug 8, 2015
ARTIQIRGenerator: add semantic locs to all other implicitly raised exceptions.
1 parent acd8d63 commit bdcf7f1

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed
 

Diff for: ‎artiq/compiler/testbench/inferencer.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def process_diagnostic(diag):
6666
buf = source.Buffer("".join(fileinput.input()).expandtabs(),
6767
os.path.basename(fileinput.filename()))
6868
parsed, comments = parse_buffer(buf, engine=engine)
69-
typed = ASTTypedRewriter(engine=engine, globals=prelude.globals()).visit(parsed)
69+
typed = ASTTypedRewriter(engine=engine, prelude=prelude.globals()).visit(parsed)
7070
Inferencer(engine=engine).visit(typed)
7171
if monomorphize:
7272
IntMonomorphizer(engine=engine).visit(typed)

Diff for: ‎artiq/compiler/transforms/artiq_ir_generator.py

+12-7
Original file line numberDiff line numberDiff line change
@@ -714,13 +714,13 @@ def _map_index(self, length, index, one_past_the_end=False, loc=None):
714714

715715
return mapped_index
716716

717-
def _make_check(self, cond, exn_gen):
717+
def _make_check(self, cond, exn_gen, loc=None):
718718
# cond: bool Value, condition
719719
# exn_gen: lambda()->exn Value, exception if condition not true
720720
cond_block = self.current_block
721721

722722
self.current_block = body_block = self.add_block()
723-
self.raise_exn(exn_gen())
723+
self.raise_exn(exn_gen(), loc=loc)
724724

725725
self.current_block = tail_block = self.add_block()
726726
cond_block.append(ir.BranchIf(cond, tail_block, body_block))
@@ -789,7 +789,8 @@ def visit_SubscriptT(self, node):
789789
self._make_check(
790790
self.append(ir.Compare(ast.NotEq(loc=None), step, ir.Constant(0, step.type))),
791791
lambda: self.alloc_exn(builtins.TValueError(),
792-
ir.Constant("step cannot be zero", builtins.TStr())))
792+
ir.Constant("step cannot be zero", builtins.TStr())),
793+
loc=node.slice.step.loc)
793794
else:
794795
step = ir.Constant(1, node.slice.type)
795796
counting_up = self.append(ir.Compare(ast.Gt(loc=None), step,
@@ -811,7 +812,8 @@ def visit_SubscriptT(self, node):
811812
lambda: self.alloc_exn(builtins.TValueError(),
812813
ir.Constant("slice size {0} is larger than iterable length {1}",
813814
builtins.TStr()),
814-
slice_size, length))
815+
slice_size, length),
816+
loc=node.slice.loc)
815817

816818
if self.current_assign is None:
817819
is_neg_size = self.append(ir.Compare(ast.Lt(loc=None),
@@ -992,20 +994,23 @@ def visit_CoerceT(self, node):
992994

993995
def visit_BinOpT(self, node):
994996
if builtins.is_numeric(node.type):
997+
lhs = self.visit(node.left)
995998
rhs = self.visit(node.right)
996999
if isinstance(node.op, (ast.LShift, ast.RShift)):
9971000
# Check for negative shift amount.
9981001
self._make_check(
9991002
self.append(ir.Compare(ast.GtE(loc=None), rhs, ir.Constant(0, rhs.type))),
10001003
lambda: self.alloc_exn(builtins.TValueError(),
1001-
ir.Constant("shift amount must be nonnegative", builtins.TStr())))
1004+
ir.Constant("shift amount must be nonnegative", builtins.TStr())),
1005+
loc=node.right.loc)
10021006
elif isinstance(node.op, (ast.Div, ast.FloorDiv)):
10031007
self._make_check(
10041008
self.append(ir.Compare(ast.NotEq(loc=None), rhs, ir.Constant(0, rhs.type))),
10051009
lambda: self.alloc_exn(builtins.TZeroDivisionError(),
1006-
ir.Constant("cannot divide by zero", builtins.TStr())))
1010+
ir.Constant("cannot divide by zero", builtins.TStr())),
1011+
loc=node.right.loc)
10071012

1008-
return self.append(ir.Arith(node.op, self.visit(node.left), rhs))
1013+
return self.append(ir.Arith(node.op, lhs, rhs))
10091014
elif isinstance(node.op, ast.Add): # list + list, tuple + tuple
10101015
lhs, rhs = self.visit(node.left), self.visit(node.right)
10111016
if types.is_tuple(node.left.type) and types.is_tuple(node.right.type):

0 commit comments

Comments
 (0)
Please sign in to comment.