From 05b3a71f95e8eadfb4359dbe829d6b7c7785c2e8 Mon Sep 17 00:00:00 2001 From: sutter Date: Fri, 19 Jan 2018 18:05:50 -0800 Subject: [PATCH] initial pass initial pass to fix the function init problem, involving a redesign of the code execution. Need to go back and clean and test. --- .gitignore | 3 ++ web/apogee/data/FunctionTable.js | 57 +++++++++++++++++++++------ web/apogee/data/JsonTable.js | 17 ++++++-- web/apogee/datacomponents/Codeable.js | 28 +++++-------- web/apogee/lib/codeCompiler.js | 10 +++-- 5 files changed, 78 insertions(+), 37 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..8fc67343 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +/web/node_modules/ +/web/apogeeapp/test-electron/node_modules/ +/web/apogeeapp/test-electron/npm-debug.log \ No newline at end of file diff --git a/web/apogee/data/FunctionTable.js b/web/apogee/data/FunctionTable.js index b736a163..51d5e0f2 100644 --- a/web/apogee/data/FunctionTable.js +++ b/web/apogee/data/FunctionTable.js @@ -28,21 +28,54 @@ apogee.base.mixin(apogee.FunctionTable,apogee.Codeable); // Codeable Methods //------------------------------ -apogee.FunctionTable.prototype.processMemberFunction = function(memberFunction) { - this.setData(memberFunction); -} +apogee.FunctionTable.prototype.processMemberFunction = function(memberGenerator) { + var instance = this; + + var packagerFunction = function() { + var src = {}; + var memberInitialized = false; + var memberFunction = null; + var issue = null; + + + var initMember = function() { + memberInitialized = true; + var impactorSuccess = instance.memberFunctionInitialize(); + if(impactorSuccess) { + memberFunction = memberGenerator(); + } + else { + if(instance.hasError()) { + issue = new Error("Error in dependency: " + instance.getFullName()); -apogee.FunctionTable.prototype.postInitializeAction = function() { - //pending check - we don't know if a function is pending until we - //actually call it. I didn't know how else to capture this in the - //calling code other than use an error. But this is not an error - if(this.hasError()) { - throw new Error("Error in dependency: " + this.getFullName()); + } + if(instance.getResultPending()) { + issue = apogee.Codeable.MEMBER_FUNCTION_PENDING; + } + else { + issue = new Error("Unknown problem in initializing: " + instance.getFullName()); + } + } + } + var wrapperMemberFunction = function(argList) { + if(!memberInitialized) { + initMember(); + } + + if(memberFunction) { + return memberFunction.apply(null,arguments); + } + else { + throw issue; + } + } + + return wrapperMemberFunction; } - if(this.getResultPending()) { - throw apogee.Codeable.MEMBER_FUNCTION_PENDING; - } + + var memberFunction = packagerFunction(); + this.setData(memberFunction); } //------------------------------ diff --git a/web/apogee/data/JsonTable.js b/web/apogee/data/JsonTable.js index 901323a4..0e4b919b 100644 --- a/web/apogee/data/JsonTable.js +++ b/web/apogee/data/JsonTable.js @@ -49,10 +49,21 @@ apogee.JsonTable.prototype.getArgList = function() { return []; } -apogee.JsonTable.prototype.processMemberFunction = function(memberFunction) { +apogee.JsonTable.prototype.processMemberFunction = function(memberGenerator) { - //the data is the output of the function - var data = memberFunction(); + //first initialize + var initialized = this.memberFunctionInitialize(); + + var data; + if(initialized) { + //the data is the output of the function + var memberFunction = memberGenerator(); + data = memberFunction(); + } + else { + //initialization issue = error or pending dependancy + data = undefined; + } //if the return value is a Promise, the data is asynch if(apogee.base.isPromise(data)) { diff --git a/web/apogee/datacomponents/Codeable.js b/web/apogee/datacomponents/Codeable.js index 82b00d1a..be22f590 100644 --- a/web/apogee/datacomponents/Codeable.js +++ b/web/apogee/datacomponents/Codeable.js @@ -25,7 +25,7 @@ apogee.Codeable.init = function(argList) { this.varInfo = null; this.dependencyInfo = null; this.memberFunctionInitializer = null; - this.memberFunction = null; + this.memberGenerator = null; this.codeErrors = []; this.clearCalcPending(); @@ -87,15 +87,14 @@ apogee.Codeable.setCodeInfo = function(codeInfo) { //set the code by exectuing generator try { //get the inputs to the generator - var instance = this; - var initFunction = function() { - return instance.memberFunctionInitialize(); - } var messenger = new apogee.action.Messenger(this); //get the generated fucntion - var generatedFunctions = codeInfo.generatorFunction(initFunction,messenger); - this.memberFunction = generatedFunctions.memberFunction; + var generatedFunctions = codeInfo.generatorFunction(messenger); + //------------------------------------------------------------- + //this is a standin for memeber generator before we fix the code compiler + this.memberGenerator = generatedFunctions.memberGenerator; + //------------------------------------------------------------- this.memberFunctionInitializer = generatedFunctions.initializer; this.codeErrors = []; @@ -111,7 +110,7 @@ apogee.Codeable.setCodeInfo = function(codeInfo) { if(this.codeErrors.length > 0) { //code not valid - this.memberFunction = null; + this.memberGenerator = null; this.memberFunctionInitializer = null; } this.codeSet = true; @@ -164,7 +163,7 @@ apogee.Codeable.clearCode = function() { this.varInfo = null; this.dependencyInfo = null; this.memberFunctionInitializer = null; - this.memberFunction = null; + this.memberGenerator = null; this.codeErrors = []; this.clearCalcPending(); @@ -202,7 +201,7 @@ apogee.Codeable.calculate = function() { return; } - if((!this.memberFunction)||(!this.memberFunctionInitializer)) { + if((!this.memberGenerator)||(!this.memberFunctionInitializer)) { var msg = "Function not found for member: " + this.getName(); var actionError = new apogee.ActionError(msg,"Codeable - Calculate",this); this.addError(actionError); @@ -211,7 +210,7 @@ apogee.Codeable.calculate = function() { } try { - this.processMemberFunction(this.memberFunction); + this.processMemberFunction(this.memberGenerator); } catch(error) { if(error == apogee.Codeable.MEMBER_FUNCTION_PENDING) { @@ -284,13 +283,6 @@ apogee.Codeable.memberFunctionInitialize = function() { this.addError(actionError); this.initReturnValue = false; } - finally { - //This lets us do something outside the catch block - mainly just to - //let some things throw the (cludgy) pending error. - if(this.postInitializeAction) { - this.postInitializeAction(); - } - } this.calcInProgress = false; this.functionInitialized = true; diff --git a/web/apogee/lib/codeCompiler.js b/web/apogee/lib/codeCompiler.js index b4be97a6..36b89179 100644 --- a/web/apogee/lib/codeCompiler.js +++ b/web/apogee/lib/codeCompiler.js @@ -127,7 +127,7 @@ apogee.codeCompiler.createGeneratorFunction = function(varInfo, combinedFunction combinedFunctionBody ); - var generatorFunction = new Function("__initFunction","apogeeMessenger",generatorBody); + var generatorFunction = new Function("apogeeMessenger",generatorBody); return generatorFunction; } @@ -151,7 +151,6 @@ apogee.codeCompiler.MEMBER_FUNCTION_FORMAT_TEXT = [ "//member function----------------", "function __memberFunction({1}) {", "//overhead code", -"if(!__initFunction()) return undefined;", "__memberFunctionDebugHook();", "", "//user code", @@ -163,7 +162,7 @@ apogee.codeCompiler.MEMBER_FUNCTION_FORMAT_TEXT = [ /** This line is added when getting the dependencies to account for some local * variables in the member function. * @private */ -apogee.codeCompiler.MEMBER_LOCALS_TEXT = "var __initFunction, apogeeMessenger, __memberFunction, __memberFunctionDebugHook;"; +apogee.codeCompiler.MEMBER_LOCALS_TEXT = "var apogeeMessenger, __memberFunction, __memberFunctionDebugHook;"; /** This is the format string to create the code body for the object function * Input indices: @@ -181,9 +180,12 @@ apogee.codeCompiler.GENERATOR_FUNCTION_FORMAT_TEXT = [ "{1}};", "", "//user code", +"function __memberGenerator() {", "{2}", +"return __memberFunction", +"}", "return {", -"'memberFunction': __memberFunction,", +"'memberGenerator': __memberGenerator,", "'initializer': __initializer", "};" ].join("\n");