From 9932f6ba2f7ed44f17fa3434e7d314812b42dc81 Mon Sep 17 00:00:00 2001 From: jmoenig Date: Thu, 9 Dec 2021 12:43:19 +0100 Subject: [PATCH] never push untested last minute changes that might break everything --- HISTORY.md | 3 ++ snap.html | 4 +-- src/blocks.js | 95 ++++++++++++++++++++++++++++++++------------------ src/threads.js | 4 +-- 4 files changed, 68 insertions(+), 38 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index e6707a29..00827355 100755 --- a/HISTORY.md +++ b/HISTORY.md @@ -69,6 +69,9 @@ * Chinese, thanks, Simon! * Brazilian Portuguese, thank you, Cassiano D'Andrea! +### 2021-12-09 +* blocks, threads: never push untested last minute changes that might break everything + ### 2021-12-08 * blocks: refactored syntax trees * rc1 diff --git a/snap.html b/snap.html index e452d55e..96b8e753 100755 --- a/snap.html +++ b/snap.html @@ -16,8 +16,8 @@ - - + + diff --git a/src/blocks.js b/src/blocks.js index b73ccb7d..1e540be6 100644 --- a/src/blocks.js +++ b/src/blocks.js @@ -160,7 +160,7 @@ CustomCommandBlockMorph, ToggleButtonMorph, DialMorph, SnapExtensions*/ // Global stuff //////////////////////////////////////////////////////// -modules.blocks = '2021-December-08'; +modules.blocks = '2021-December-09'; var SyntaxElementMorph; var BlockMorph; @@ -1279,30 +1279,63 @@ SyntaxElementMorph.prototype.replaceInput = function (oldArg, newArg) { }; SyntaxElementMorph.prototype.revertToDefaultInput = function (arg, noValues) { + var deflt = this.revertToEmptyInput(arg), + inp = this.inputs().indexOf(deflt), + def; + if (noValues || inp < 0) { + return deflt; + } + if (this instanceof BlockMorph) { + if (this.isCustomBlock) { + def = this.isGlobal ? this.definition + : this.scriptTarget().getMethod(this.blockSpec); + if (!noValues && + (deflt instanceof InputSlotMorph || + deflt instanceof BooleanSlotMorph) + ) { + deflt.setContents( + def.defaultValueOfInputIdx(inp) + ); + } + } + } + if (deflt instanceof MultiArgMorph && !inp) { + // first - and only - input is variadic + deflt.setContents(this.defaults); + deflt.defaults = this.defaults; + } else if (!isNil(this.defaults[inp])) { + deflt.setContents(this.defaults[inp]); + if (deflt instanceof MultiArgMorph) { + deflt.defaults = this.defaults[inp]; + } + } + return deflt; +}; + +SyntaxElementMorph.prototype.revertToEmptyInput = function (arg) { var idx = this.parts().indexOf(arg), inp = this.inputs().indexOf(arg), deflt = new InputSlotMorph(), - def; + rcvr, def; if (idx !== -1) { if (this instanceof BlockMorph) { deflt = this.labelPart(this.parseSpec(this.blockSpec)[idx]); if (this.isCustomBlock) { - def = this.isGlobal ? this.definition - : this.scriptTarget().getMethod(this.blockSpec); - if (deflt instanceof InputSlotMorph) { + if (this.isGlobal) { + def = this.definition; + } else { + rcvr = this.scriptTarget(true); + if (rcvr) { + def = rcvr.getMethod(this.blockSpec); + } + } + if (def && deflt instanceof InputSlotMorph) { deflt.setChoices.apply( deflt, def.inputOptionsOfIdx(inp) ); } - if (deflt instanceof InputSlotMorph || - (deflt instanceof BooleanSlotMorph) - ) { - deflt.setContents( - def.defaultValueOfInputIdx(inp) - ); - } } } else if (this instanceof MultiArgMorph) { deflt = this.labelPart(this.slotSpec); @@ -1310,21 +1343,6 @@ SyntaxElementMorph.prototype.revertToDefaultInput = function (arg, noValues) { deflt = this.emptySlot(); } } - // set default value - if (!noValues) { - if (inp !== -1) { - if (deflt instanceof MultiArgMorph && !inp) { - // first - and only - input is variadic - deflt.setContents(this.defaults); - deflt.defaults = this.defaults; - } else if (!isNil(this.defaults[inp])) { - deflt.setContents(this.defaults[inp]); - if (deflt instanceof MultiArgMorph) { - deflt.defaults = this.defaults[inp]; - } - } - } - } if (deflt.icon || deflt instanceof BooleanSlotMorph) { deflt.fixLayout(); } @@ -2625,7 +2643,7 @@ BlockMorph.prototype.init = function () { this.cachedInputs = null; }; -BlockMorph.prototype.scriptTarget = function () { +BlockMorph.prototype.scriptTarget = function (noError) { // answer the sprite or stage that this block acts on, // if the user clicks on it. // NOTE: since scripts can be shared by more than a single sprite @@ -2650,6 +2668,7 @@ BlockMorph.prototype.scriptTarget = function () { return dlg.target.currentSprite; } } + if (noError) {return null; } throw new Error('script target cannot be found for orphaned block'); }; @@ -3749,10 +3768,13 @@ BlockMorph.prototype.syntaxTree = function (parameterNames) { return; } parts.add(inp.components()); - expr.revertToDefaultInput(inp, true); + expr.revertToEmptyInput(inp); } else if (inp.isEmptySlot()) { parts.add(); } else if (inp instanceof MultiArgMorph) { + if (!inp.inputs().length) { + parts.add(); + } inp.inputs().forEach((slot, i) => { var entry; if (slot instanceof BlockMorph) { @@ -3768,15 +3790,18 @@ BlockMorph.prototype.syntaxTree = function (parameterNames) { parts.add(entry instanceof BlockMorph ? entry.components() : entry); } - inp.revertToDefaultInput(slot, true); + inp.revertToEmptyInput(slot); }); } else if (inp instanceof ArgLabelMorph) { parts.add(inp.argMorph().components()); - expr.revertToDefaultInput(inp, true).collapseAll(); + expr.revertToEmptyInput(inp).collapseAll(); } else { val = inp.evaluate(); + if (inp instanceof ColorSlotMorph) { + val = val.toString(); + } parts.add(val instanceof BlockMorph ? val.components() : val); - expr.revertToDefaultInput(inp, true); + expr.revertToEmptyInput(inp, true); } }); parts.at(1).updateEmptySlots(); @@ -3804,14 +3829,14 @@ BlockMorph.prototype.copyWithInputs = function (inputs) { // restore input slots slots.forEach(slt => { if (slt instanceof BlockMorph) { - dflt = cpy.revertToDefaultInput(slt); + dflt = cpy.revertToEmptyInput(slt); if (dflt instanceof MultiArgMorph) { dflt.collapseAll(); } } else if (slt instanceof MultiArgMorph) { slt.inputs().forEach(entry => { if (entry instanceof BlockMorph) { - slt.revertToDefaultInput(entry); + slt.revertToEmptyInput(entry); } }); } @@ -3858,6 +3883,8 @@ BlockMorph.prototype.copyWithInputs = function (inputs) { } else { if (inp instanceof List && inp.length() === 0) { nop(); // ignore, i.e. leave slot as is + } else if (slot instanceof ColorSlotMorph) { + slot.setColor(Color.fromString(inp)); } else if (slot instanceof InputSlotMorph || slot instanceof TemplateSlotMorph || slot instanceof BooleanSlotMorph) { diff --git a/src/threads.js b/src/threads.js index adcba17c..dcc3b53d 100644 --- a/src/threads.js +++ b/src/threads.js @@ -64,7 +64,7 @@ SnapExtensions, AlignmentMorph, TextMorph, Cloud, HatBlockMorph*/ /*jshint esversion: 6*/ -modules.threads = '2021-December-07'; +modules.threads = '2021-December-09'; var ThreadManager; var Process; @@ -5463,7 +5463,7 @@ Process.prototype.reportBasicBlockAttribute = function (attribute, block) { case 'definition': if (expr.isCustomBlock) { if (expr.isGlobal) { - return expr.definition.body; + return expr.definition.body || new Context(); } return this.blockReceiver().getMethod(expr.semanticSpec).body || new Context();