back.pysim: handle out of bounds ArrayProxy indexes.

This commit is contained in:
whitequark 2018-12-21 12:32:08 +00:00
parent 7ae7683fed
commit 48d13e47ec
2 changed files with 25 additions and 2 deletions

View file

@ -193,7 +193,12 @@ class _RHSValueCompiler(AbstractValueTransformer):
shape = value.shape()
elems = list(map(self, value.elems))
index = self(value.index)
return lambda state: normalize(elems[index(state)](state), shape)
def eval(state):
index_value = index(state)
if index_value >= len(elems):
index_value = len(elems) - 1
return normalize(elems[index_value](state), shape)
return eval
class _LHSValueCompiler(AbstractValueTransformer):
@ -263,7 +268,10 @@ class _LHSValueCompiler(AbstractValueTransformer):
elems = list(map(self, value.elems))
index = self.rhs_compiler(value.index)
def eval(state, rhs):
elems[index(state)](state, rhs)
index_value = index(state)
if index_value >= len(elems):
index_value = len(elems) - 1
elems[index_value](state, rhs)
return eval