enabled variables access for experimental JS-compiler

upd4.2
Jens Mönig 2018-03-20 14:48:42 +01:00
rodzic d87146497c
commit 1a0c9fe6b8
2 zmienionych plików z 23 dodań i 28 usunięć

Wyświetl plik

@ -4054,4 +4054,5 @@ in development:
180320 180320
------ ------
* Threads: refactored experimental JS-Compiler * Threads: refactored experimental JS-compiler
* Threads: enabled variables access for experimental JS-compiler

Wyświetl plik

@ -4230,8 +4230,7 @@ JSCompiler.prototype.toString = function () {
}; };
JSCompiler.prototype.compileFunction = function (aContext) { JSCompiler.prototype.compileFunction = function (aContext) {
var func, var block = aContext.expression,
block = aContext.expression,
parameters = aContext.inputs, parameters = aContext.inputs,
parms = [], parms = [],
hasEmptySlots = false, hasEmptySlots = false,
@ -4239,36 +4238,28 @@ JSCompiler.prototype.compileFunction = function (aContext) {
this.source = aContext; this.source = aContext;
// scan for unbound variables and empty input slots // scan for empty input slots
block.allChildren().forEach(function (morph) { hasEmptySlots = !isNil(detect(
if (morph.selector === 'reportGetVar' && block.allChildren(),
!contains(parameters, morph.blockSpec) function (morph) {return morph.isEmptySlot && morph.isEmptySlot(); }
) { ));
throw new Error(
'compiling does not yet support\n' +
'variables that are not\nformal parameters'
);
} else if (morph.isEmptySlot && morph.isEmptySlot()) {
hasEmptySlots = true;
}
});
// translate formal parameters into gensyms // translate formal parameters into gensyms
this.gensyms = {}; this.gensyms = {};
if (parameters.length) { if (parameters.length) {
// test for conflicts // test for conflicts
if (hasEmptySlots) { if (hasEmptySlots) {
throw new Error( throw new Error(
'compiling does not yet support\n' + 'compiling does not yet support\n' +
'mixing explicit formal parameters\n' + 'mixing explicit formal parameters\n' +
'with empty input slots' 'with empty input slots'
); );
} }
// map explicit formal parameters // map explicit formal parameters
parameters.forEach(function (pName, idx) { parameters.forEach(function (pName, idx) {
var pn = 'p' + idx; var pn = 'p' + idx;
parms.push(pn); parms.push(pn);
myself.gensyms[pName] = pn; myself.gensyms[pName] = pn;
}); });
} else if (hasEmptySlots) { } else if (hasEmptySlots) {
// allow for a single implicit formal parameter // allow for a single implicit formal parameter
@ -4276,12 +4267,10 @@ JSCompiler.prototype.compileFunction = function (aContext) {
} }
// compile using gensyms // compile using gensyms
func = Function.apply( return Function.apply(
null, null,
parms.concat(['return ' + this.compileExpression(block)]) parms.concat(['return ' + this.compileExpression(block)])
); );
this.gensyms = {};
return func;
}; };
JSCompiler.prototype.compileExpression = function (block) { JSCompiler.prototype.compileExpression = function (block) {
@ -4366,11 +4355,16 @@ JSCompiler.prototype.compileInput = function (inp) {
} }
} else if (inp instanceof BlockMorph) { } else if (inp instanceof BlockMorph) {
if (inp.selector === 'reportGetVar') { if (inp.selector === 'reportGetVar') {
// un-quoted gensym: if (contains(this.source.inputs, inp.blockSpec)) {
return this.gensyms[inp.blockSpec]; // un-quoted gensym:
} else { return this.gensyms[inp.blockSpec];
return this.compileExpression(inp); }
// redirect var query to process
return 'arguments[arguments.length - 1].getVarNamed("' +
inp.blockSpec +
'")';
} }
return this.compileExpression(inp);
} else { } else {
throw new Error( throw new Error(
'compiling does not yet support\n' + 'compiling does not yet support\n' +