made addition reporter variadic

snap8
Jens Mönig 2022-02-28 09:24:12 +01:00
rodzic 9016a1639e
commit 3c74ecb847
7 zmienionych plików z 92 dodań i 24 usunięć

Wyświetl plik

@ -3,12 +3,16 @@
## in development:
* **New Features:**
* variadic infix reporters
* **Notable Changes:**
* **Notable Fixes:**
* **Documentation Updates:**
* **Translation Updates:**
### 2022-02-276
### 2022-02-28
* blocks, objects, threads, store: made addition reporter variadic
### 2022-02-27
* variadic infix branch
### 2022-02-26

Wyświetl plik

@ -16,9 +16,9 @@
<script src="src/morphic.js?version=2022-01-28"></script>
<script src="src/symbols.js?version=2021-03-03"></script>
<script src="src/widgets.js?version=2021-17-09"></script>
<script src="src/blocks.js?version=2022-02-25"></script>
<script src="src/threads.js?version=2022-02-26"></script>
<script src="src/objects.js?version=2022-02-22"></script>
<script src="src/blocks.js?version=2022-02-28"></script>
<script src="src/threads.js?version=2022-02-28"></script>
<script src="src/objects.js?version=2022-02-28"></script>
<script src="src/scenes.js?version=2021-11-24"></script>
<script src="src/gui.js?version=2022-02-27"></script>
<script src="src/paint.js?version=2021-07-05"></script>
@ -30,7 +30,7 @@
<script src="src/maps.js?version=2021-06-15"></script>
<script src="src/extensions.js?version=2022-02-08"></script>
<script src="src/xml.js?version=2021-07-05"></script>
<script src="src/store.js?version=2022-01-02"></script>
<script src="src/store.js?version=2022-02-28"></script>
<script src="src/locale.js?version=2022-02-22"></script>
<script src="src/cloud.js?version=2021-02-04"></script>
<script src="src/api.js?version=2022-01-03"></script>

Wyświetl plik

@ -161,7 +161,7 @@ CostumeIconMorph, SoundIconMorph, SVG_Costume*/
// Global stuff ////////////////////////////////////////////////////////
modules.blocks = '2022-February-25';
modules.blocks = '2022-February-28';
var SyntaxElementMorph;
var BlockMorph;
@ -1014,6 +1014,8 @@ SyntaxElementMorph.prototype.labelParts = {
type: 'multi'
slots: a slot spec string
label: (optional)
infix: (optional) // +++
collapse: (optional) alternative label to "Input list"
tags: 'widget' // doesn't count as "empty" slot implicit parameter
min: (optional) number of minimum inputs) or zero
max: (optional) number of maximum inputs) or zero
@ -1094,6 +1096,13 @@ SyntaxElementMorph.prototype.labelParts = {
slots: '%s',
defaults: 1,
tags: 'static widget'
},
'%sum': { // +++
type: 'multi',
slots: '%n',
min: 2,
infix: '+',
collapse: 'sum'
}
};
@ -1250,8 +1259,10 @@ SyntaxElementMorph.prototype.replaceInput = function (oldArg, newArg) {
oldArg.inputs().forEach(inp => // preserve nested reporters
oldArg.replaceInput(inp, new InputSlotMorph())
);
if (this.dynamicInputLabels && newArg instanceof ReporterBlockMorph) {
replacement = new ArgLabelMorph(newArg);
// if (this.dynamicInputLabels && newArg instanceof ReporterBlockMorph) {
if ((this.dynamicInputLabels || oldArg.collapse) &&
newArg instanceof ReporterBlockMorph) {
replacement = new ArgLabelMorph(newArg, oldArg.collapse); // +++
}
}
replacement.parent = this;
@ -1732,7 +1743,10 @@ SyntaxElementMorph.prototype.labelPart = function (spec) {
info.slots,
info.label,
info.min || 0,
spec
spec,
null, null, null, null, null,
info.infix, // +++
info.collapse // +++
);
part.maxInputs = info.max;
for (i = 0; i < info.defaults || 0; i += 1) {
@ -4000,7 +4014,7 @@ BlockMorph.prototype.copyWithInputs = function (inputs) {
(dta.length === 1) || (cpy.blockSpec === '\xa0' && dta.length > 1))
) {
cpy.setSpec(dta[0]);
return cpy.reify(dta.slice(1))
return cpy.reify(dta.slice(1));
}
// restore input slots
@ -12260,7 +12274,9 @@ function MultiArgMorph(
labelColor,
shadowColor,
shadowOffset,
isTransparent
isTransparent,
infix, // +++
collapse // +++
) {
this.init(
slotSpec,
@ -12271,7 +12287,9 @@ function MultiArgMorph(
labelColor,
shadowColor,
shadowOffset,
isTransparent
isTransparent,
infix,
collapse
);
}
@ -12284,7 +12302,9 @@ MultiArgMorph.prototype.init = function (
labelColor,
shadowColor,
shadowOffset,
isTransparent
isTransparent,
infix,
collapse
) {
var label,
arrows = new FrameMorph(),
@ -12294,6 +12314,8 @@ MultiArgMorph.prototype.init = function (
this.slotSpec = slotSpec || '%s';
this.labelText = localize(labelTxt || '');
this.infix = infix || ''; // +++
this.collapse = collapse || ''; // +++
this.minInputs = min || 0;
this.maxInputs = null;
this.elementSpec = eSpec || null;
@ -12542,8 +12564,10 @@ MultiArgMorph.prototype.insertNewInputBefore = function (anInput, contents) {
// MultiArgMorph arity control:
MultiArgMorph.prototype.addInput = function (contents) {
var i, name,
newPart = this.labelPart(this.slotSpec),
var newPart = this.labelPart(this.slotSpec),
i, name, idx;
this.addInfix(); // +++
idx = this.children.length - 1;
if (contents) {
newPart.setContents(contents);
@ -12582,6 +12606,14 @@ MultiArgMorph.prototype.addInput = function (contents) {
return newPart;
};
MultiArgMorph.prototype.addInfix = function () {
var infix;
if (this.infix === '' || !this.inputs().length) {return; }
infix = this.labelPart(this.infix);
infix.parent = this;
this.children.splice(this.children.length - 1, 0, infix);
};
MultiArgMorph.prototype.removeInput = function () {
var oldPart, scripts;
if (this.children.length > 1) {
@ -12595,6 +12627,11 @@ MultiArgMorph.prototype.removeInput = function () {
}
}
}
if (this.infix !== '') { // +++
if (this.children.length > 1) {
this.removeChild(this.children[this.children.length - 2]);
}
}
this.fixLayout();
};

Wyświetl plik

@ -87,7 +87,7 @@ BlockVisibilityDialogMorph, CostumeIconMorph, SoundIconMorph*/
/*jshint esversion: 6*/
modules.objects = '2022-February-22';
modules.objects = '2022-February-28';
var SpriteMorph;
var StageMorph;
@ -1104,6 +1104,12 @@ SpriteMorph.prototype.initBlocks = function () {
category: 'operators',
spec: '%n + %n'
},
reportVariadicSum: { // +++ under construction
// +++ dev: true,
type: 'reporter',
category: 'operators',
spec: '%sum'
},
reportDifference: {
type: 'reporter',
category: 'operators',
@ -1681,6 +1687,10 @@ SpriteMorph.prototype.initBlockMigrations = function () {
doSend: {
selector: 'doBroadcast',
expand: 1
},
reportSum: { // +++
selector: 'reportVariadicSum',
variadic: true
}
};
};
@ -2663,7 +2673,8 @@ SpriteMorph.prototype.blockTemplates = function (
blocks.push(block('reifyPredicate'));
blocks.push('#');
blocks.push('-');
blocks.push(block('reportSum'));
// blocks.push(block('reportSum'));
blocks.push(block('reportVariadicSum'));
blocks.push(block('reportDifference'));
blocks.push(block('reportProduct'));
blocks.push(block('reportQuotient'));
@ -2708,6 +2719,7 @@ SpriteMorph.prototype.blockTemplates = function (
blocks.push('-');
blocks.push(block('reportTypeOf'));
blocks.push(block('reportTextFunction'));
blocks.push(block('reportVariadicSum')); // +++
}
} else if (category === 'variables') {
@ -9088,7 +9100,8 @@ StageMorph.prototype.blockTemplates = function (
blocks.push(block('reifyPredicate'));
blocks.push('#');
blocks.push('-');
blocks.push(block('reportSum'));
// +++ blocks.push(block('reportSum'));
blocks.push(block('reportVariadicSum'));
blocks.push(block('reportDifference'));
blocks.push(block('reportProduct'));
blocks.push(block('reportQuotient'));
@ -9134,6 +9147,7 @@ StageMorph.prototype.blockTemplates = function (
blocks.push('-');
blocks.push(block('reportTypeOf'));
blocks.push(block('reportTextFunction'));
blocks.push(block('reportVariadicSum')); // +++
}
}

Wyświetl plik

@ -63,7 +63,7 @@ Project*/
// Global stuff ////////////////////////////////////////////////////////
modules.store = '2022-January-02';
modules.store = '2022-February-28';
// XML_Serializer ///////////////////////////////////////////////////////
/*
@ -1189,7 +1189,8 @@ SnapSerializer.prototype.loadComment = function (model) {
SnapSerializer.prototype.loadBlock = function (model, isReporter, object) {
// private
var block, info, inputs, isGlobal, receiver, migration,
migrationOffset = 0;
migrationOffset = 0,
migratoToVariadic = false; // +++
if (model.tag === 'block') {
if (Object.prototype.hasOwnProperty.call(
@ -1206,6 +1207,7 @@ SnapSerializer.prototype.loadBlock = function (model, isReporter, object) {
];
if (migration) {
migrationOffset = migration.offset || 0;
migratoToVariadic = migration.variadic; // +++
}
}
} else if (model.tag === 'custom-block') {
@ -1265,7 +1267,14 @@ SnapSerializer.prototype.loadBlock = function (model, isReporter, object) {
} else if (child.tag === 'receiver') {
nop(); // ignore
} else {
this.loadInput(child, inputs[i + migrationOffset], block, object);
if (migratoToVariadic) { // +++
// assume all formerly single inputs are now part of the first
// one which is variadic and already expanded to hold them
// example: migrate old infix addition to new variadic infix sum
this.loadInput(child, inputs[0].inputs()[i], inputs[0], object); // +++
} else {
this.loadInput(child, inputs[i + migrationOffset], block, object); // +++
}
}
});
block.cachedInputs = null;

Wyświetl plik

@ -64,7 +64,7 @@ SnapExtensions, AlignmentMorph, TextMorph, Cloud, HatBlockMorph*/
/*jshint esversion: 6*/
modules.threads = '2022-February-26';
modules.threads = '2022-February-28';
var ThreadManager;
var Process;
@ -4010,6 +4010,10 @@ Process.prototype.isMatrix = function (data) {
// Process math primtives - arithmetic
Process.prototype.reportVariadicSum = function (list) { // +++
return this.reportListAggregation(list, 'reportSum');
};
Process.prototype.reportSum = function (a, b) {
return this.hyperDyadic(this.reportBasicSum, a, b);
};

2
sw.js
Wyświetl plik

@ -1,4 +1,4 @@
var snapVersion = '7.2.6-dev',
var snapVersion = '7.3.0-dev',
cacheName = 'snap-pwa',
filesToCache = [
'snap.html',