Merge pull request #361 from thisandagain/bugfix/360

Fix hat blocks in horizontal grammar
This commit is contained in:
Andrew Sliwinski 2017-01-03 09:37:42 -05:00 committed by GitHub
commit bc60fa13ce

View file

@ -435,12 +435,24 @@ Runtime.prototype.startHats = function (requestedHatOpcode,
// Not the right hat. // Not the right hat.
return; return;
} }
// Match any requested fields. // Match any requested fields.
// For example: ensures that broadcasts match. // For example: ensures that broadcasts match.
// This needs to happen before the block is evaluated // This needs to happen before the block is evaluated
// (i.e., before the predicate can be run) because "broadcast and wait" // (i.e., before the predicate can be run) because "broadcast and wait"
// needs to have a precise collection of started threads. // needs to have a precise collection of started threads.
var hatFields = target.blocks.getFields(topBlockId); var hatFields = target.blocks.getFields(topBlockId);
// If no fields are present, check inputs (horizontal blocks)
if (Object.keys(hatFields).length === 0) {
var hatInputs = target.blocks.getInputs(topBlockId);
for (var input in hatInputs) {
var id = hatInputs[input].block;
var fields = target.blocks.getFields(id);
hatFields = Object.assign(fields, hatFields);
}
}
if (optMatchFields) { if (optMatchFields) {
for (var matchField in optMatchFields) { for (var matchField in optMatchFields) {
if (hatFields[matchField].value !== if (hatFields[matchField].value !==
@ -450,6 +462,7 @@ Runtime.prototype.startHats = function (requestedHatOpcode,
} }
} }
} }
// Look up metadata for the relevant hat. // Look up metadata for the relevant hat.
var hatMeta = instance._hats[requestedHatOpcode]; var hatMeta = instance._hats[requestedHatOpcode];
if (hatMeta.restartExistingThreads) { if (hatMeta.restartExistingThreads) {