Skip to content

Commit

Permalink
"infinity" is now available.
Browse files Browse the repository at this point in the history
  • Loading branch information
Alessandrito123 committed Nov 24, 2024
1 parent 19774bb commit 842d40f
Show file tree
Hide file tree
Showing 7 changed files with 418 additions and 219 deletions.
64 changes: 55 additions & 9 deletions src/blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,9 @@ SyntaxElementMorph.prototype.labelParts = {
menu: {
'1' : 1,
last : ['last'],
any : ['any']
any : ['any'],
'~' : null,
parent : ['parent']
}
},
'%la': {
Expand Down Expand Up @@ -691,6 +693,18 @@ SyntaxElementMorph.prototype.labelParts = {
confetti: ['confetti']
}
},
'%env': {
type: 'input',
tags: 'read-only static',
menu: {
script: ['script'],
caller: ['caller'],
continuation: ['continuation'],
'~' : null,
inputs : ['inputs'],
object : ['object']
}
},
'%snd': {
type: 'input',
tags: 'read-only',
Expand Down Expand Up @@ -5103,7 +5117,11 @@ BlockMorph.prototype.backupRender = function (ctx) {
this.drawEdges(ctx);
}; // draw location pin icon if applicable
if (this.hasLocationPin()) {
this.drawMethodIcon(ctx);};};
this.drawMethodIcon(ctx);};
// draw infinity / chain link icon if applicable
if (this.isRuleHat()) {
this.drawRuleIcon(ctx);
};};

BlockMorph.prototype.drawMethodIcon = function (ctx) {
var ext = this.methodIconExtent(), w = ext.x, h = ext.y,
Expand All @@ -5128,7 +5146,32 @@ r = w / 2, x = this.edge + this.labelPadding, y = (((this
ctx.closePath();
ctx.fill();};

BlockMorph.prototype.hasLocationPin = function () {return (this.isCustomBlock && !this.isGlobal) || this.isLocalVarTemplate;};
BlockMorph.prototype.drawRuleIcon = function (ctx) {
var h = this.hatHeight * 4/5,
l = Math.max(h / 4, 1),
r = h / 2,
x = (this.hatWidth - h * 7/4) * 11/20,
y = h / 2,
isNormal =
this.color === SpriteMorph.prototype.blockColorFor(this.category);
ctx.lineWidth = l;
// ctx.strokeStyle = color.toString();
ctx.strokeStyle = isNormal ? this.cachedClrBright : this.cachedClrDark;
// left arc
ctx.beginPath();
ctx.arc(x + r, y + r, r - l / 2, radians(60), radians(360), false);
ctx.stroke();
// right arc
ctx.beginPath();
ctx.arc(x + r * 3 - l, y + r, r - l / 2, radians(-120), radians(180), false);
ctx.stroke();
};

BlockMorph.prototype.hasLocationPin = function () {return (((this
).isCustomBlock && !(this.isGlobal)) || this.isLocalVarTemplate);};

(BlockMorph.prototype.isRuleHat
) = function () {return false;};

// BlockMorph highlighting

Expand Down Expand Up @@ -6294,6 +6337,9 @@ if (asABool(isPrototypeLike)) {this.category = 'custom'; this.setSpec(localize('
HatBlockMorph.prototype.blockSequence = function () {if (this.selector === 'receiveCondition') {return (
this);} else {var result = HatBlockMorph.uber.blockSequence.call(this); result.shift(); return result;};};

HatBlockMorph.prototype.isRuleHat = function () {
return (this.selector === 'receiveCondition');};

// HatBlockMorph drawing:

HatBlockMorph.prototype.outlinePath = function (ctx, inset) {
Expand Down Expand Up @@ -10512,12 +10558,12 @@ droppedMorph) {if (droppedMorph.selector === (
// TemplateSlotMorph drawing:

TemplateSlotMorph.prototype.backupRender = function (ctx) {if (this.parent instanceof Morph) {
this.color = this.parent.color.copy();}; BlockMorph.prototype.backupRender.call(this, ctx);};
TemplateSlotMorph.prototype.outlinePath = ReporterBlockMorph.prototype.outlinePathOval;
TemplateSlotMorph.prototype.drawEdges = ReporterBlockMorph.prototype.drawEdgesOval;
TemplateSlotMorph.prototype.hasLocationPin = function () {return false;};
TemplateSlotMorph.prototype.cSlots = (() => []); (TemplateSlotMorph
).prototype.clearSlots = TemplateSlotMorph.prototype.cSlots;
this.color = this.parent.color.copy();}; BlockMorph.prototype.backupRender.call(this, ctx);
}; TemplateSlotMorph.prototype.outlinePath = ReporterBlockMorph.prototype.outlinePathOval;
TemplateSlotMorph.prototype.cSlots = function () {return [];}; (TemplateSlotMorph.prototype
).drawEdges = ReporterBlockMorph.prototype.drawEdgesOval; (TemplateSlotMorph.prototype.isRuleHat
) = function () {return false;}; TemplateSlotMorph.prototype.hasLocationPin = function () {
return false;}; TemplateSlotMorph.prototype.clearSlots = TemplateSlotMorph.prototype.cSlots;

// TemplateSlotMorph single-stepping

Expand Down
24 changes: 10 additions & 14 deletions src/byob.js
Original file line number Diff line number Diff line change
Expand Up @@ -1449,20 +1449,16 @@ CustomDefinitorBlockMorph.prototype.isCustomBlock = true;
function CustomDefinitorBlockMorph(definition,
isProto) {this.init(definition, isProto);};

CustomDefinitorBlockMorph.prototype.init = function (definition, isProto) {
this.definition = definition;
this.semanticSpec = '';
this.isGlobal = definition ? definition.isGlobal : false;
this.isPrototype = isProto || false;
CustomDefinitorBlockMorph.uber.init.call(this);
if (isProto) {this.isTemplate = true;};
this.category = definition.category;
this.selector = 'evaluateCustomBlock';
this.variables = null;
this.storedTranslations = null;
this.initializeVariables();
if (definition) {this.refresh();};
};
CustomDefinitorBlockMorph.prototype.init = function (definition,
isProto) {this.definition = definition; this.isGlobal = ((definition
) ? definition.isGlobal : false); this.semanticSpec = ''; (this
).isPrototype = (isProto || false); (CustomDefinitorBlockMorph.uber
).init.call(this); if (isProto) {this.isTemplate = true;}; (this
).category = definition.category; this.selector = 'evaluateCustomBlock';
this.variables = null; this.storedTranslations = null; (this
).initializeVariables(); if (definition) {this.refresh();};};

CustomDefinitorBlockMorph.prototype.isRuleHat = function () {return true;};

CustomDefinitorBlockMorph.prototype.reactToTemplateCopy = CustomCommandBlockMorph.prototype.reactToTemplateCopy;

Expand Down
8 changes: 4 additions & 4 deletions src/compilers.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
var JSCompiler;

// JSCompiler /////////////////////////////////////////////////////////////////

/*
Expand Down Expand Up @@ -186,7 +184,9 @@ JSCompiler.prototype.compileExpression = function (block) {
return this.compileSequence(inputs[0].evaluate());
case 'reportBoolean':
case 'reportNewList':
return this.compileInput(inputs[0]);
return this.compileInput(inputs[0]);
case 'reportEnvironment':
return 'func';
default:
target = this.process[selector] ? this.process
: (this.source.receiver || this.process.receiver);
Expand Down Expand Up @@ -376,4 +376,4 @@ return ((contains(['number', 'Boolean'], (new Process).reportTypeOf(reportBasicT
} else if (blocks.selector === 'evaluateCustomBlock') {return reportBasicToJS(blocks.definition.body.toBlock()) + '.apply\(this, \[' + blocks.inputs().map(value => reportBasicToJS(value)) + '\]\);';
} else if (blocks.selector === 'reportGetVar') {return blocks.blockSpec;} else {return '';};} else {return '';};};
function reportToJS (input) {if (input instanceof List) {return new List(input.asArray().map(miniInput => reportToJS(miniInput)));}
else if (input instanceof Context) {return reportBasicToJS(input);} else {return reportBasicToJS(new Context());};};
else if (input instanceof Context) {return reportBasicToJS(input);} else {return reportBasicToJS(new Context);};};
67 changes: 67 additions & 0 deletions src/lists.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,73 @@ element) : Process.prototype.reportIsIdentical(
list[i], element)) {result.push(i + 1);
}; i++;}; return new List(result);};

// List key-value accessing (experimental in v8.1):

List.prototype.lookup = function (key, ifNone = '') {
// look up the value of a given key, return optional ifNone value,
// which can also be a niladic callback, or an empty string
var rec, parent;
if (parseFloat(key) === +key) { // treat as numerical index
return this.at(key);
}
rec = this.itemsArray().find(elem => elem instanceof List &&
elem.length() > 0 &&
snapEquals(elem.at(1), key));
if (rec) {
return rec.length() > 2 ? rec.cdr() : rec.at(2);
}
if (snapEquals(key, '...')) {
if (typeof ifNone === 'function') {
return ifNone();
}
return ifNone;
}
parent = this.lookup('...');
if (parent instanceof List) {
return parent.lookup(key, ifNone);
} else if (isSnapObject(parent)) {
Process.prototype.assertAlive(parent);
return parent.variables.getVar(key);
}
return typeof ifNone === 'function' ? ifNone() : ifNone;
};

List.prototype.bind = function (key, value) {
if (parseFloat(key) === +key) { // treat as numerical index
return this.put(value, key);
}
if (key instanceof List) {
return; // cannot use lists as key because of hyperization
}
this.add(new List([key, value]), this.forget(key) + 1);
};

List.prototype.forget = function (key) {
// remove all records indicated by the key
// and return the index of the first match, if any
var idx = 0,
match = this.length(),
query = rec =>
snapEquals(rec, key) || (
rec instanceof List &&
rec.length() === 2 &&
snapEquals(rec.at(1), key)
);

if (parseFloat(key) === +key) { // treat as numerical index
this.remove(key);
return key;
}
while (idx > -1) {
idx = this.itemsArray().findIndex(query);
if (idx > -1) {
match = Math.min(match, idx);
this.remove(idx + 1);
}
}
return match;
};

// List table (2D) accessing (for table morph widget):

List.prototype.isTable = function () {return (this.enableTables && ((this.length(
Expand Down
26 changes: 23 additions & 3 deletions src/morphic.js
Original file line number Diff line number Diff line change
Expand Up @@ -11251,7 +11251,8 @@ SymbolMorph.prototype.names = [
'trash',
'trashFull',
'cube',
'cubeSolid'
'cubeSolid',
'infinity'
];

// SymbolMorph instance creation:
Expand Down Expand Up @@ -11612,8 +11613,9 @@ SymbolMorph.prototype.renderShape = function (ctx, aColor) {
case 'cubeSolid':
this.renderSymbolCubeSolid(ctx, aColor);
break;
default:
throw new Error('unknown symbol name: "' + this.name + '"');
case 'infinity':
this.renderSymbolInfinity(ctx, aColor);
break;
};
};

Expand Down Expand Up @@ -11654,6 +11656,8 @@ SymbolMorph.prototype.symbolWidth = function () {
case 'keyboard':
case 'keyboardFilled':
return size * 8/5;
case 'infinity':
return size * 7/4;
case 'loop':
return size * 2;
default:
Expand Down Expand Up @@ -13712,6 +13716,22 @@ SymbolMorph.prototype.renderSymbolCubeSolid = function (ctx, color) {
ctx.fill();
};

SymbolMorph.prototype.renderSymbolInfinity = function (ctx, color) {
var h = this.size,
l = Math.max(h / 4, 1),
r = h / 2;
ctx.lineWidth = l;
ctx.strokeStyle = color.toString();
// left arc
ctx.beginPath();
ctx.arc(r, r, r - l / 2, (Math.PI / 3), (2 * Math.PI), false);
ctx.stroke();
// right arc
ctx.beginPath();
ctx.arc(r * 3 - l, r, r - l / 2, -(Math.PI * 2/3), Math.PI, false);
ctx.stroke();
};

(function () {
var bright = new Color(240, 240, 240),
dark = new Color(20, 20, 20),
Expand Down
43 changes: 21 additions & 22 deletions src/objects.js
Original file line number Diff line number Diff line change
Expand Up @@ -815,7 +815,7 @@ SpriteMorph.prototype.initBlocks = function () {
receiveCondition: {
type: 'hat',
category: 'events',
spec: 'when %b'
spec: 'when %b triggers'
},
getLastMessage: {
type: 'reporter',
Expand Down Expand Up @@ -1069,25 +1069,11 @@ SpriteMorph.prototype.initBlocks = function () {
spec: '%block of %r',
defaults: [['definition']]
},
reportThisContext: {
type: 'reporter',
category: 'control',
spec: 'this script'
},
reportThisCaller: {
reportEnvironment: {
type: 'reporter',
category: 'control',
spec: 'this caller'
},
reportThisContinuation: {
type: 'reporter',
category: 'control',
spec: 'this continuation'
},
reportThisInputs: {
type: 'reporter',
category: 'control',
spec: 'this inputs'
spec: 'this %env',
defaults: [['script']]
},

// Debugging
Expand Down Expand Up @@ -2458,6 +2444,22 @@ SpriteMorph.prototype.initBlockMigrations = function () {
selector: 'reportVariadicIsIdentical',
variadic: true
},
reportThisContext: {
selector: 'reportEnvironment',
inputs: [['script']]
},
reportThisCaller: {
selector: 'reportEnvironment',
inputs: [['caller']]
},
reportThisContinuation: {
selector: 'reportEnvironment',
inputs: [['continuation']]
},
reportThisInputs: {
selector: 'reportEnvironment',
inputs: [['inputs']]
},
reportStringSize: {
selector: 'reportTextAttribute',
inputs: [['length']],
Expand Down Expand Up @@ -3291,10 +3293,7 @@ category = 'other', all = false) {var blocks = [], myself = this, varNames, inhe
blocks.push(block('doCallCC'));
blocks.push(block('reportCallCC'));
blocks.push('-');
blocks.push(block('reportThisContext'));
blocks.push(block('reportThisContinuation'));
blocks.push(block('reportThisCaller'));
blocks.push(block('reportThisInputs'));
blocks.push(block('reportEnvironment'));
blocks.push('-');
blocks.push(this.subCategoryText('Scenes'));
blocks.push('-');
Expand Down
Loading

0 comments on commit 842d40f

Please sign in to comment.