From ac0baf94ed40ae20ed0087f5f431258a33ea3285 Mon Sep 17 00:00:00 2001 From: Ozzie Gooen Date: Fri, 31 Jul 2020 21:11:24 +0100 Subject: [PATCH] Fix for functions --- .../expressionTree/ExpressionTreeEvaluator.re | 2 +- src/distPlus/expressionTree/Functions.re | 4 ++- src/distPlus/expressionTree/MathJsParser.re | 3 +++ src/distPlus/renderers/DistPlusRenderer.re | 26 +++++++++++-------- 4 files changed, 22 insertions(+), 13 deletions(-) diff --git a/src/distPlus/expressionTree/ExpressionTreeEvaluator.re b/src/distPlus/expressionTree/ExpressionTreeEvaluator.re index 27570b59..a09d76d1 100644 --- a/src/distPlus/expressionTree/ExpressionTreeEvaluator.re +++ b/src/distPlus/expressionTree/ExpressionTreeEvaluator.re @@ -335,7 +335,7 @@ let toLeaf = FloatFromDist.operationToLeaf(evaluationParams, distToFloatOp, t) | `Normalize(t) => Normalize.operationToLeaf(evaluationParams, t) | `Render(t) => Render.operationToLeaf(evaluationParams, t) - | `Function(t) => Ok(`Function(t)) + | `Function(_) => Error("Function must be called with params") | `Symbol(r) => ExpressionTypes.ExpressionTree.Environment.get(evaluationParams.environment, r) |> E.O.toResult("Undeclared variable " ++ r) | `FunctionCall(name, args) => callableFunction(evaluationParams, name, args) diff --git a/src/distPlus/expressionTree/Functions.re b/src/distPlus/expressionTree/Functions.re index f32c570c..13941ad3 100644 --- a/src/distPlus/expressionTree/Functions.re +++ b/src/distPlus/expressionTree/Functions.re @@ -79,7 +79,8 @@ let fnn = evaluationParams: ExpressionTypes.ExpressionTree.evaluationParams, name, args: array(node), - ) => + ) =>{ + Js.log3("HERE", name, args); switch ( name, ExpressionTypes.ExpressionTree.Environment.get( @@ -120,3 +121,4 @@ let fnn = | ("to", _) => to_(args) | _ => Error("Function not found") }; + } diff --git a/src/distPlus/expressionTree/MathJsParser.re b/src/distPlus/expressionTree/MathJsParser.re index 52fb90b2..c5465ffc 100644 --- a/src/distPlus/expressionTree/MathJsParser.re +++ b/src/distPlus/expressionTree/MathJsParser.re @@ -1,3 +1,4 @@ +[%%debugger.chrome] module MathJsonToMathJsAdt = { type arg = | Symbol(string) @@ -355,6 +356,7 @@ let fromString2 = str => { Inside of this function, MathAdtToDistDst is called whenever a distribution function is encountered. */ let mathJsToJson = str |> pointwiseToRightLogShift |> Mathjs.parseMath; + Js.log2("HI", mathJsToJson); let mathJsParse = E.R.bind(mathJsToJson, r => { switch (MathJsonToMathJsAdt.run(r)) { @@ -364,6 +366,7 @@ let fromString2 = str => { }); let value = E.R.bind(mathJsParse, MathAdtToDistDst.run); + Js.log3("HI", mathJsParse, value); value; }; diff --git a/src/distPlus/renderers/DistPlusRenderer.re b/src/distPlus/renderers/DistPlusRenderer.re index 7c39e17c..927e6a64 100644 --- a/src/distPlus/renderers/DistPlusRenderer.re +++ b/src/distPlus/renderers/DistPlusRenderer.re @@ -35,7 +35,7 @@ module Inputs = { type inputs = { distPlusIngredients: ingredients, samplingInputs: SamplingInputs.t, - environment: ExpressionTypes.ExpressionTree.environment + environment: ExpressionTypes.ExpressionTree.environment, }; let empty: SamplingInputs.t = { @@ -67,16 +67,14 @@ module Internals = { }; let addVariable = - ( - {samplingInputs, guesstimatorString, environment}: inputs, - str, - node, - ) + ({samplingInputs, guesstimatorString, environment}: inputs, str, node) : inputs => { samplingInputs, guesstimatorString, environment: - ExpressionTypes.ExpressionTree.Environment.update(environment, str, _ => Some(node)) + ExpressionTypes.ExpressionTree.Environment.update(environment, str, _ => + Some(node) + ), }; let distPlusRenderInputsToInputs = (inputs: Inputs.inputs): inputs => { @@ -110,14 +108,15 @@ module Internals = { let runProgram = (inputs: inputs, p: ExpressionTypes.Program.program) => { let ins = ref(inputs); p - |> E.A.fmap(statement => + |> E.A.fmap(statement => { + Js.log2("Running ling", statement); switch (statement) { | `Assignment(name, node) => ins := addVariable(ins^, name, node); None; | `Expression(node) => Some(runNode(ins^, node)) - } - ) + }; + }) |> E.A.O.concatSomes |> E.A.R.firstErrorOrOpen; }; @@ -125,7 +124,12 @@ module Internals = { let inputsToShape = (inputs: inputs) => { MathJsParser.fromString(inputs.guesstimatorString) |> E.R.bind(_, g => runProgram(inputs, g)) - |> E.R.bind(_, r => E.A.last(r) |> E.O.toResult("No rendered lines") |> E.R.fmap(Shape.T.normalize)); + |> E.R.bind(_, r => + E.A.last(r) + |> E.O.toResult("No rendered lines") + |> (e => {Js.log2("EE", e); e}) + |> E.R.fmap(Shape.T.normalize) + ); }; let outputToDistPlus = (inputs: Inputs.inputs, shape: DistTypes.shape) => {