mirror of https://github.com/exaloop/codon
Fix domination within deeply nested blocks (#485)
Co-authored-by: Ibrahim Numanagić <ibrahimpasa@gmail.com>pull/470/head
parent
bee2c2f402
commit
1e6382c564
|
@ -126,11 +126,16 @@ SimplifyContext::Item SimplifyContext::findDominatingBinding(const std::string &
|
|||
// We went outside the function scope. Break.
|
||||
if (!isOutside && (*i)->getBaseName() != getBaseName())
|
||||
break;
|
||||
bool completeDomination =
|
||||
(*i)->scope.size() <= scope.blocks.size() &&
|
||||
(*i)->scope.back() == scope.blocks[(*i)->scope.size() - 1];
|
||||
if (!completeDomination && prefix < int(scope.blocks.size()) && prefix != p) {
|
||||
break;
|
||||
}
|
||||
prefix = p;
|
||||
lastGood = i;
|
||||
// The binding completely dominates the current scope. Break.
|
||||
if ((*i)->scope.size() <= scope.blocks.size() &&
|
||||
(*i)->scope.back() == scope.blocks[(*i)->scope.size() - 1])
|
||||
if (completeDomination)
|
||||
break;
|
||||
}
|
||||
seqassert(lastGood != it->second.end(), "corrupted scoping ({})", name);
|
||||
|
|
|
@ -1998,3 +1998,35 @@ print(Tuple[-5, int].__class__.__name__)
|
|||
#: Tuple
|
||||
print(Tuple[5, int, str].__class__.__name__)
|
||||
#: Tuple[int,str,int,str,int,str,int,str,int,str]
|
||||
|
||||
|
||||
#%% domination_nested,barebones
|
||||
def correlate(a, b, mode = 'valid'):
|
||||
if mode == 'valid':
|
||||
if isinstance(a, List):
|
||||
xret = '1'
|
||||
else:
|
||||
xret = '2'
|
||||
for i in a:
|
||||
for j in b:
|
||||
xret += 'z'
|
||||
elif mode == 'same':
|
||||
if isinstance(a, List):
|
||||
xret = '3'
|
||||
else:
|
||||
xret = '4'
|
||||
for i in a:
|
||||
for j in b:
|
||||
xret += 'z'
|
||||
elif mode == 'full':
|
||||
if isinstance(a, List):
|
||||
xret = '5'
|
||||
else:
|
||||
xret = '6'
|
||||
for i in a:
|
||||
for j in b:
|
||||
xret += 'z'
|
||||
else:
|
||||
raise ValueError(f"mode must be one of 'valid', 'same', or 'full' (got {repr(mode)})")
|
||||
return xret
|
||||
print(correlate([1], [2], 'full')) # 5z
|
||||
|
|
Loading…
Reference in New Issue