Skip to content

Commit 1189aeb

Browse files
committed
Merge branch 'release/1.0.0'
2 parents 6f7a572 + d8bbc11 commit 1189aeb

File tree

6 files changed

+56
-5
lines changed

6 files changed

+56
-5
lines changed

Formula.Parser.Tests/CompilerTests.fs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,5 +461,27 @@ type CompilerTests () =
461461
| Success (ast, userState, endPos) ->
462462
let value = (compileFormula ast).Invoke(MapVariableProvider.Empty, DefaultFunctionProvider.Instance)
463463
Assert.AreEqual(None, value);
464+
| Failure (msg, error, userState) ->
465+
Assert.Fail(msg)
466+
467+
[<TestMethod>]
468+
member this.TestCompileBug51Variable () =
469+
let result = parseFormulaString "MyVar + MyVar + MyVar + MyVar + MyVar + MyVar + MyVar + MyVar + MyVar + MyVar + MyVar + MyVar + MyVar + MyVar + MyVar + MyVar + MyVar + MyVar + MyVar + MyVar"
470+
match result with
471+
| Success (ast, userState, endPos) ->
472+
let value = (compileFormula ast).Invoke(varMap, DefaultFunctionProvider.Instance)
473+
let expected = Some(Helpers.castToDouble(varMap.Lookup "MyVar").Value * 20.0)
474+
Assert.AreEqual(expected, value);
475+
| Failure (msg, error, userState) ->
476+
Assert.Fail(msg)
477+
478+
[<TestMethod>]
479+
member this.TestCompileBug51Constant () =
480+
let result = parseFormulaString "1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 17 + 18 + 19 + 20"
481+
match result with
482+
| Success (ast, userState, endPos) ->
483+
let value = (compileFormula ast).Invoke(MapVariableProvider.Empty, DefaultFunctionProvider.Instance)
484+
let expected = Some(210.0)
485+
Assert.AreEqual(expected, value);
464486
| Failure (msg, error, userState) ->
465487
Assert.Fail(msg)

Formula.Parser.Tests/InterpreterTests.fs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,5 +462,27 @@ type InterpreterTests () =
462462
| Success (ast, userState, endPos) ->
463463
let value = interpretFormula ast MapVariableProvider.Empty DefaultFunctionProvider.Instance
464464
Assert.AreEqual(None, value);
465+
| Failure (msg, error, userState) ->
466+
Assert.Fail(msg)
467+
468+
[<TestMethod>]
469+
member this.TestInterpretBug51Variable () =
470+
let result = parseFormulaString "MyVar + MyVar + MyVar + MyVar + MyVar + MyVar + MyVar + MyVar + MyVar + MyVar + MyVar + MyVar + MyVar + MyVar + MyVar + MyVar + MyVar + MyVar + MyVar + MyVar"
471+
match result with
472+
| Success (ast, userState, endPos) ->
473+
let value = interpretFormula ast varMap DefaultFunctionProvider.Instance
474+
let expected = Some(Helpers.castToDouble(varMap.Lookup "MyVar").Value * 20.0)
475+
Assert.AreEqual(expected, value);
476+
| Failure (msg, error, userState) ->
477+
Assert.Fail(msg)
478+
479+
[<TestMethod>]
480+
member this.TestInterpretBug51Constant () =
481+
let result = parseFormulaString "1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 17 + 18 + 19 + 20"
482+
match result with
483+
| Success (ast, userState, endPos) ->
484+
let value = interpretFormula ast MapVariableProvider.Empty DefaultFunctionProvider.Instance
485+
let expected = Some(210.0)
486+
Assert.AreEqual(expected, value);
465487
| Failure (msg, error, userState) ->
466488
Assert.Fail(msg)

Formula.Parser/AssemblyInfo.fs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ module AssemblyInfo
99
open System.Reflection
1010
open System.Runtime.InteropServices
1111

12-
[<assembly: AssemblyFileVersionAttribute("0.13.0.0")>]
13-
[<assembly: AssemblyInformationalVersionAttribute("0.13.0")>]
12+
[<assembly: AssemblyFileVersionAttribute("1.0.0.0")>]
13+
[<assembly: AssemblyInformationalVersionAttribute("1.0.0")>]
1414
[<assembly: AssemblyProductAttribute("Formula.Parser")>]
1515
[<assembly: AssemblyTitleAttribute("Formula.Parser")>]
16-
[<assembly: AssemblyVersionAttribute("0.13.0.0")>]
16+
[<assembly: AssemblyVersionAttribute("1.0.0.0")>]
1717
[<assembly: AssemblyDescriptionAttribute("A simple extensible formula language for .NET")>]
1818
[<assembly: AssemblyCopyrightAttribute("Richard Smith")>]
1919
do ()

Formula.Parser/Compiler.fs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,10 @@ module Compiler =
167167
let compileBranch cond a b =
168168
let valueCond = castToBoolExpression(compileInternal cond)
169169
Expression.Condition(valueCond, (compileInternal a), (compileInternal b)) :> Expression
170+
171+
let compileIntermediate (ex: Expression) =
172+
let inter = Expression.Lambda(ex, variableProvider, functionProvider).Compile()
173+
Expression.Invoke(Expression.Constant(inter), variableProvider, functionProvider) :> Expression
170174

171175
match ast.Item with
172176
| Constant c ->
@@ -176,7 +180,7 @@ module Compiler =
176180
| Negation n ->
177181
compileNegation n
178182
| Arithmetic (a, op, b) ->
179-
compileArithmetic a op.Item b
183+
compileIntermediate (compileArithmetic a op.Item b)
180184
| Inversion i ->
181185
compileInversion i
182186
| Comparison (a, op, b) ->

Formula.Parser/Formula.Parser.fsproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<PropertyGroup>
44
<TargetFramework>netstandard2.0</TargetFramework>
55
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
6-
<Version>0.13.0</Version>
6+
<Version>1.0.0</Version>
77
<Authors>Richard Smith</Authors>
88
<Copyright>Richard Smith</Copyright>
99
<RepositoryUrl>https://github.com/rsmithsa/formula</RepositoryUrl>

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ A simple extensible formula language for .NET
3030

3131
## Version History
3232

33+
### 1.0.0
34+
- Bug fix for large expressions
35+
3336
### 0.13.0
3437
- Constant folder supports folding functions with constant arguments
3538
- Function implementations can declare they are deterministic

0 commit comments

Comments
 (0)