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,19 +4238,11 @@ 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 = {};
@ -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') {
if (contains(this.source.inputs, inp.blockSpec)) {
// un-quoted gensym: // un-quoted gensym:
return this.gensyms[inp.blockSpec]; return this.gensyms[inp.blockSpec];
} else {
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' +