little compilation experiment

totally under construction and unusable for now
upd4.2
Jens Mönig 2018-02-12 17:23:35 +01:00
rodzic c7f3a0cd4d
commit 1574e01a2d
3 zmienionych plików z 52 dodań i 4 usunięć

Wyświetl plik

@ -3950,6 +3950,7 @@ Translation Updates:
180212
------
* Threads: Allow JS-functions for invoke()
* Threads, Objects: Small compilation experiment
=== v4.1.2 features ===

Wyświetl plik

@ -83,7 +83,7 @@ BlockEditorMorph, BlockDialogMorph, PrototypeHatBlockMorph, localize,
TableMorph, TableFrameMorph, normalizeCanvas, BooleanSlotMorph, HandleMorph,
AlignmentMorph*/
modules.objects = '2018-January-25';
modules.objects = '2018-February-12';
var SpriteMorph;
var StageMorph;
@ -1079,6 +1079,12 @@ SpriteMorph.prototype.initBlocks = function () {
spec: '%txtfun of %s',
defaults: [null, "Abelson & Sussman"]
},
reportCompiled: { // only in dev mode - experimental
dev: true,
type: 'reporter',
category: 'operators',
spec: 'compiled %repRing'
},
/*
reportScript: {
@ -2143,6 +2149,7 @@ SpriteMorph.prototype.blockTemplates = function (category) {
blocks.push('-');
blocks.push(block('reportTypeOf'));
blocks.push(block('reportTextFunction'));
blocks.push(block('reportCompiled'));
}
/////////////////////////////////

Wyświetl plik

@ -696,7 +696,9 @@ Process.prototype.evaluateContext = function () {
};
Process.prototype.evaluateBlock = function (block, argCount) {
var selector = block.selector;
var rcvr, inputs,
selector = block.selector;
// check for special forms
if (selector === 'reportOr' ||
selector === 'reportAnd' ||
@ -705,8 +707,8 @@ Process.prototype.evaluateBlock = function (block, argCount) {
}
// first evaluate all inputs, then apply the primitive
var rcvr = this.context.receiver || this.receiver,
inputs = this.context.inputs;
rcvr = this.context.receiver || this.receiver;
inputs = this.context.inputs;
if (argCount > inputs.length) {
this.evaluateNextInput(block);
@ -733,6 +735,44 @@ Process.prototype.evaluateBlock = function (block, argCount) {
}
};
// Process: Compile simple, side-effect free Reporters
// with only implicit formal parameters (empty input slots)
// ** highly experimental and heavily under construction **
Process.prototype.reportCompiled = function (context) {
this.assertType(context, 'reporter');
return this.compile(context.expression);
};
Process.prototype.compile = function (block) {
// private - totally under construction and unusable at this time
var selector = block.selector,
rcvr = this.context.receiver || this.receiver,
args = [],
func = this[selector] ||
(this.context.receiver || this.receiver)[selector];
/*
function f(a, b, c) {return a * b + c};
function ff(f, p1) {return f.apply(null, [3, 4, p1]); }
function fff(x) {return ff.apply(null, [f, x]); }
*/
block.inputs().forEach(function (inp) {
if (inp.isEmptySlot && inp.isEmptySlot()) {
// add to formal parameters
} else if (inp instanceof ArgMorph) {
// literal - evaluate inline
args.push(inp.evaluate());
} else if (inp instanceof BlockMorph) {
// recurse
} else {
// raise error about unsupported slot
}
});
return function () {return func.apply(rcvr, args); };
};
// Process: Special Forms Blocks Primitives
Process.prototype.reportOr = function (block) {