diff options
| author | jmoenig <jens@moenig.org> | 2014-11-21 16:55:25 +0100 |
|---|---|---|
| committer | jmoenig <jens@moenig.org> | 2014-11-21 16:55:25 +0100 |
| commit | 9e91a93ac029056adae89e7b8e07558b47f9634f (patch) | |
| tree | ee0f93561552e794927f885ccb28177777db1ebd /blocks.js | |
| parent | f2d0c2eba5d6b012fc3fb1167c82b64b2f8ed447 (diff) | |
| download | snap-byow-9e91a93ac029056adae89e7b8e07558b47f9634f.tar.gz snap-byow-9e91a93ac029056adae89e7b8e07558b47f9634f.zip | |
Fix "stop this block"’s lexical awareness
“stop this block” when used inside a custom block definition now always
returns out of the lexically enclosing script (the definition), even if
it is used inside other nested, C-shaped custom blocks in the
definition code. Previously it only stopped the nearest encompassing
“for” block, now it always stops the block whose definition it is in.
I don’t expect this fix to break any existing projects.
Diffstat (limited to 'blocks.js')
| -rw-r--r-- | blocks.js | 40 |
1 files changed, 25 insertions, 15 deletions
@@ -155,7 +155,7 @@ DialogBoxMorph, BlockInputFragmentMorph, PrototypeHatBlockMorph, Costume*/ // Global stuff //////////////////////////////////////////////////////// -modules.blocks = '2014-November-17'; +modules.blocks = '2014-November-21'; var SyntaxElementMorph; @@ -395,7 +395,9 @@ SyntaxElementMorph.prototype.allInputs = function () { SyntaxElementMorph.prototype.allEmptySlots = function () { // answer empty input slots of all children excluding myself, - // but omit those in nested rings (lambdas) and JS-Function primitives + // but omit those in nested rings (lambdas) and JS-Function primitives. + // Used by the evaluator when binding implicit formal parameters + // to empty input slots var empty = []; if (!(this instanceof RingMorph) && (this.selector !== 'reportJSFunction')) { @@ -410,19 +412,24 @@ SyntaxElementMorph.prototype.allEmptySlots = function () { return empty; }; -SyntaxElementMorph.prototype.allReportBlocks = function () { - // answer report blocks of all children including myself, - // but omit those in nested rings (lambdas) - if (this.selector === 'doReport') {return [this]; } - var reports = []; - if (!(this instanceof RingMorph)) { - this.children.forEach(function (morph) { - if (morph.allReportBlocks) { - reports = reports.concat(morph.allReportBlocks()); - } - }); +SyntaxElementMorph.prototype.tagExitBlocks = function (stopTag, isCommand) { + // tag 'report' and 'stop this block' blocks of all children including + // myself, with either a stopTag (for "stop" blocks) or an indicator of + // being inside a command block definition, but omit those in nested + // rings (lambdas. Used by the evaluator when entering a procedure + if (this.selector === 'doReport') { + this.partOfCustomCommand = isCommand; + } else if (this.selector === 'doStopThis') { + this.exitTag = stopTag; + } else { + if (!(this instanceof RingMorph)) { + this.children.forEach(function (morph) { + if (morph.tagExitBlocks) { + morph.tagExitBlocks(stopTag, isCommand); + } + }); + } } - return reports; }; SyntaxElementMorph.prototype.replaceInput = function (oldArg, newArg) { @@ -3186,9 +3193,10 @@ BlockMorph.prototype.snap = function () { bottomBlock() - answer the bottom block of my stack blockSequence() - answer an array of blocks starting with myself - and the following "lexical awareness" indicator: + and the following "lexical awareness" indicators: partOfCustomCommand - temporary bool set by the evaluator + exitTag - temporary string or number set by the evaluator */ // CommandBlockMorph inherits from BlockMorph: @@ -3206,6 +3214,8 @@ function CommandBlockMorph() { CommandBlockMorph.prototype.init = function () { CommandBlockMorph.uber.init.call(this); this.setExtent(new Point(200, 100)); + this.partOfCustomCommand = false; + this.exitTag = null; }; // CommandBlockMorph enumerating: |
