From 8b871781996fa04a78ac5f1f5d35c8615300b659 Mon Sep 17 00:00:00 2001 From: Florian Rappl Date: Tue, 18 May 2021 21:57:50 +0200 Subject: [PATCH 01/27] Updated general info --- CHANGELOG.md | 8 ++++++++ LICENSE | 2 +- README.md | 22 ++++++++++++++++++++-- src/SharedAssemblyInfo.cs | 8 ++++---- 4 files changed, 33 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 77ebafa3..16ce69a9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ +# 2.0.0 + +- Added missing helpers and constants (#98) +- Added complex helpers (#97) +- Added complex numbers support (#96) +- Changed library target to .NET Standard 2 (#68) +- Changed application to run on .NET Core 3.1 (#68) + # 1.6.1 - Fixed `factorial` bug (#94) diff --git a/LICENSE b/LICENSE index 58e44a75..4a453d20 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2016-2018 Florian Rappl +Copyright (c) 2016-2021 Florian Rappl Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 5fcd68dc..301395f4 100644 --- a/README.md +++ b/README.md @@ -8,10 +8,16 @@ ## Mages: Another Generalized Expression Simplifier -MAGES is the official successor to YAMP. It is a very simple, yet powerful, expression parser and interpreter. You can use MAGES to include a sophisticated, easy to customize, and lightweight scripting engine to your application. +MAGES is the official successor to [YAMP](https://github.com/FlorianRappl/YAMP). It is a very simple, yet powerful, expression parser and interpreter. You can use MAGES to include a sophisticated, easy to customize, and lightweight scripting engine to your application. + +Among other applications, MAGES is used in [Microsoft's PowerToys](https://github.com/microsoft/PowerToys). ### Current Status +MAGES was just updated with support for complex numbers. Also, the build target and runtime has been updated to make use of modern possibilities. + +### Previous Status + The first stable version has been released. The current version 1.6.0 contains an improved REPL. The library contains everything to perform lightweight scripting operations in C#. A [CodeProject article](http://www.codeproject.com/Articles/1108939/MAGES-Ultimate-Scripting-for-NET) about the library (also containing some background and performance comparisons) is also available. ### Installation @@ -80,11 +86,23 @@ The rules of [semver](http://semver.org/) are our bread and butter. In short thi Hence: Do not expect any breaking changes within the same major version. +## Sponsors + +The following companies sponsored part of the development of MAGES. + +
+ + + +
+ +Thanks for all the support and trust in the project! + ## License The MIT License (MIT) -Copyright (c) 2016-2018 Florian Rappl +Copyright (c) 2016-2021 Florian Rappl Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: diff --git a/src/SharedAssemblyInfo.cs b/src/SharedAssemblyInfo.cs index 4ab1e2a0..f1d3d307 100644 --- a/src/SharedAssemblyInfo.cs +++ b/src/SharedAssemblyInfo.cs @@ -5,9 +5,9 @@ //------------------------------------------------------------------------------ using System.Reflection; -[assembly: AssemblyCompany("Polytrope")] +[assembly: AssemblyCompany("smapiot")] [assembly: AssemblyProduct("Mages")] -[assembly: AssemblyVersion("1.6.0")] -[assembly: AssemblyFileVersion("1.6.0")] -[assembly: AssemblyCopyright("Copyright (c) 2018, Florian Rappl")] +[assembly: AssemblyVersion("2.0.0")] +[assembly: AssemblyFileVersion("2.0.0")] +[assembly: AssemblyCopyright("Copyright (c) 2021, Florian Rappl")] From 8ce848616834d2cf5335c39d7a6883d544ef4ca3 Mon Sep 17 00:00:00 2001 From: Florian Rappl Date: Tue, 18 May 2021 22:03:35 +0200 Subject: [PATCH 02/27] Added GH stuff --- .github/CODE_OF_CONDUCT.md | 18 ++++++++++++++++++ .github/CONTRIBUTING.md | 19 +++++++++++++++++++ .github/FUNDING.yml | 3 +++ .github/PULL_REQUEST_TEMPLATE.md | 24 ++++++++++++++++++++++++ 4 files changed, 64 insertions(+) create mode 100644 .github/CODE_OF_CONDUCT.md create mode 100644 .github/CONTRIBUTING.md create mode 100644 .github/FUNDING.yml create mode 100644 .github/PULL_REQUEST_TEMPLATE.md diff --git a/.github/CODE_OF_CONDUCT.md b/.github/CODE_OF_CONDUCT.md new file mode 100644 index 00000000..23995348 --- /dev/null +++ b/.github/CODE_OF_CONDUCT.md @@ -0,0 +1,18 @@ +# Contributor Covenant Code of Conduct + +This project has adopted the code of conduct defined by the Contributor Covenant to clarify expected behavior in our community. + +In particular this means: + +> We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, religion, or nationality. + +Examples of unacceptable behavior by participants include: + +* The use of sexualized language or imagery +* Personal attacks +* Trolling or insulting/derogatory comments +* Public or private harassment +* Publishing other's private information, such as physical or electronic addresses, without explicit permission +* Other unethical or unprofessional conduct + +For the complete set of rules and more information on the topic see the [.NET Foundation Code of Conduct](https://dotnetfoundation.org/code-of-conduct). diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md new file mode 100644 index 00000000..bf896da2 --- /dev/null +++ b/.github/CONTRIBUTING.md @@ -0,0 +1,19 @@ +# Contributing + +## Project Scope + +The MAGES project ultimately tries to provide a minimalistic language for scripting .NET projects. + +## Code License + +This is an open source project falling under the [MIT License](../LICENSE). By using, distributing, or contributing to this project, you accept and agree that all code within the MAGES project and its libraries are licensed under MIT license. + +## Becoming a Contributor + +Until the project has enough contributors a [BDFL](https://en.wikipedia.org/wiki/Benevolent_dictator_for_life) model is followed. As such the sole key maintainer keeps the right to appoint GitHub members as regular project contributors. Nevertheless, usually appointing someone follows this process: + +1. An individual contributes actively via discussions (reporting bugs, giving feedback to existing or opening new issues) and / or pull requests +2. The individual is either directly asked, invited or asks for contributor rights on the project +3. The individual uses the contribution rights to sustain or increase the active contributions + +Every contributor has to sign the contributor's license agreement (CLA) to establish a legal trust between the project and its contributors. diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 00000000..4c831738 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,3 @@ +# These are supported funding model platforms + +github: FlorianRappl diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 00000000..f3f3c419 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,24 @@ +# Types of Changes + +## Prerequisites + +Please make sure you can check the following two boxes: + +- [ ] I have read the **CONTRIBUTING** document +- [ ] My code follows the code style of this project + +## Contribution Type + +What types of changes does your code introduce? Put an `x` in all the boxes that apply: + +- [ ] Bug fix (non-breaking change which fixes an issue, please reference the issue id) +- [ ] New feature (non-breaking change which adds functionality, make sure to open an associated issue first) +- [ ] Breaking change (fix or feature that would cause existing functionality to change) +- [ ] My change requires a change to the documentation +- [ ] I have updated the documentation accordingly +- [ ] I have added tests to cover my changes +- [ ] All new and existing tests passed + +## Description + +[Place a meaningful description here.] From 358aa12f1e507e4b10484e12f4a79e4c0979af36 Mon Sep 17 00:00:00 2001 From: Florian Rappl Date: Tue, 18 May 2021 23:55:46 +0200 Subject: [PATCH 03/27] Migrated to .NET standard 2.0 / .NET core 3.1 #68 --- src/Directory.Build.props | 12 + .../Mages.Core.Performance.csproj | 79 +---- .../Properties/AssemblyInfo.cs | 14 - src/Mages.Core.Tests/Mages.Core.Tests.csproj | 126 +------ src/Mages.Core.Tests/NumberTests.cs | 4 +- .../Properties/AssemblyInfo.cs | 14 - src/Mages.Core/AssemblyInfo.cs | 3 + src/Mages.Core/Mages.Core.csproj | 237 +------------- src/Mages.Core/Properties/AssemblyInfo.cs | 12 - src/Mages.Nuget.nuspec | 4 +- .../Mages.Plugins.Common.csproj | 59 +--- .../Properties/AssemblyInfo.cs | 15 - .../Mages.Plugins.Draw.csproj | 59 +--- .../Properties/AssemblyInfo.cs | 15 - .../Mages.Plugins.FileSystem.csproj | 61 +--- .../Properties/AssemblyInfo.cs | 15 - .../Mages.Plugins.LinearAlgebra.csproj | 73 +---- .../Properties/AssemblyInfo.cs | 15 - .../Mages.Plugins.Modules.csproj | 64 +--- .../Properties/AssemblyInfo.cs | 15 - .../Mages.Plugins.Plots.csproj | 67 +--- .../Properties/AssemblyInfo.cs | 15 - src/Mages.Plugins.Plots/packages.config | 4 - .../Mages.Plugins.Random.csproj | 72 +--- .../Properties/AssemblyInfo.cs | 15 - src/Mages.Plugins.Random/packages.config | 5 - .../Mages.Plugins.Transpilers.csproj | 69 +--- .../Properties/AssemblyInfo.cs | 36 -- src/Mages.Plugins.Transpilers/Transpiler.cs | 12 - .../TranspilersPlugin.cs | 2 - .../TreeWalkers/CPlusPlusTreeWalker.cs | 307 ------------------ .../TreeWalkers/CSharpTreeWalker.cs | 307 ------------------ src/Mages.Repl.Base/AssemblyInfo.cs | 3 + src/Mages.Repl.Base/Mages.Repl.Base.csproj | 139 +------- .../Properties/AssemblyInfo.cs | 12 - src/Mages.Repl.Base/packages.config | 5 - src/Mages.Repl.Tests/Mages.Repl.Tests.csproj | 97 +----- .../Properties/AssemblyInfo.cs | 15 - src/Mages.Repl/Mages.Repl.csproj | 85 +---- src/Mages.Repl/Properties/AssemblyInfo.cs | 12 - src/Mages.Repl/packages.config | 5 - src/Mages.Squirrel.nuspec | 2 +- src/Mages.sln | 51 +-- src/SharedAssemblyInfo.cs | 13 - 44 files changed, 175 insertions(+), 2071 deletions(-) create mode 100644 src/Directory.Build.props delete mode 100644 src/Mages.Core.Performance/Properties/AssemblyInfo.cs delete mode 100644 src/Mages.Core.Tests/Properties/AssemblyInfo.cs create mode 100644 src/Mages.Core/AssemblyInfo.cs delete mode 100644 src/Mages.Core/Properties/AssemblyInfo.cs delete mode 100644 src/Mages.Plugins.Common/Properties/AssemblyInfo.cs delete mode 100644 src/Mages.Plugins.Draw/Properties/AssemblyInfo.cs delete mode 100644 src/Mages.Plugins.FileSystem/Properties/AssemblyInfo.cs delete mode 100644 src/Mages.Plugins.LinearAlgebra/Properties/AssemblyInfo.cs delete mode 100644 src/Mages.Plugins.Modules/Properties/AssemblyInfo.cs delete mode 100644 src/Mages.Plugins.Plots/Properties/AssemblyInfo.cs delete mode 100644 src/Mages.Plugins.Plots/packages.config delete mode 100644 src/Mages.Plugins.Random/Properties/AssemblyInfo.cs delete mode 100644 src/Mages.Plugins.Random/packages.config delete mode 100644 src/Mages.Plugins.Transpilers/Properties/AssemblyInfo.cs delete mode 100644 src/Mages.Plugins.Transpilers/TreeWalkers/CPlusPlusTreeWalker.cs delete mode 100644 src/Mages.Plugins.Transpilers/TreeWalkers/CSharpTreeWalker.cs create mode 100644 src/Mages.Repl.Base/AssemblyInfo.cs delete mode 100644 src/Mages.Repl.Base/Properties/AssemblyInfo.cs delete mode 100644 src/Mages.Repl.Base/packages.config delete mode 100644 src/Mages.Repl.Tests/Properties/AssemblyInfo.cs delete mode 100644 src/Mages.Repl/Properties/AssemblyInfo.cs delete mode 100644 src/Mages.Repl/packages.config delete mode 100644 src/SharedAssemblyInfo.cs diff --git a/src/Directory.Build.props b/src/Directory.Build.props new file mode 100644 index 00000000..fe6000c1 --- /dev/null +++ b/src/Directory.Build.props @@ -0,0 +1,12 @@ + + + Mages + Florian Rappl + smapiot + 2.0.0 + Copyright (c) 2021, Florian Rappl + https://github.com/FlorianRappl/MAGES/blob/master/LICENSE + https://github.com/FlorianRappl/MAGES/ + https://github.com/FlorianRappl/MAGES/ + + diff --git a/src/Mages.Core.Performance/Mages.Core.Performance.csproj b/src/Mages.Core.Performance/Mages.Core.Performance.csproj index 291a529a..6733ad32 100644 --- a/src/Mages.Core.Performance/Mages.Core.Performance.csproj +++ b/src/Mages.Core.Performance/Mages.Core.Performance.csproj @@ -1,79 +1,18 @@ - - - + - Debug - AnyCPU - {15B324FD-3EE3-467A-BDDA-A6F571FEA4C8} + net472 Exe - Properties - Mages.Core.Performance Mages.Core.Performance - v4.0 - 512 - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - + Mages.Core.Performance + latest + - - ..\packages\BenchmarkDotNet.0.9.6\lib\net40\BenchmarkDotNet.dll - True - - - - - - - - - - - - - - ..\packages\YAMP.1.5.3.15660\lib\portable-net40+sl50+win+wpa81+wp80+MonoAndroid10+xamarinios10+MonoTouch10\YAMP.dll - - - - - - - - - - - + + - - {b0698a2a-bfe9-4568-9055-82302f325452} - Mages.Core - + + - - \ No newline at end of file diff --git a/src/Mages.Core.Performance/Properties/AssemblyInfo.cs b/src/Mages.Core.Performance/Properties/AssemblyInfo.cs deleted file mode 100644 index f9c10902..00000000 --- a/src/Mages.Core.Performance/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System.Reflection; -using System.Runtime.InteropServices; - -[assembly: AssemblyTitle("Mages.Core.Performance")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("Polytrope")] -[assembly: AssemblyProduct("Mages")] -[assembly: AssemblyCopyright("Copyright © 2016, Florian Rappl")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] -[assembly: ComVisible(false)] -[assembly: Guid("dcfd7765-c8b5-4afc-aede-a4588c1d450f")] -[assembly: AssemblyVersion("1.0.0.0")] \ No newline at end of file diff --git a/src/Mages.Core.Tests/Mages.Core.Tests.csproj b/src/Mages.Core.Tests/Mages.Core.Tests.csproj index f57280ec..8807365a 100644 --- a/src/Mages.Core.Tests/Mages.Core.Tests.csproj +++ b/src/Mages.Core.Tests/Mages.Core.Tests.csproj @@ -1,128 +1,38 @@ - - + - Debug - AnyCPU - {72E0C8E6-8853-4919-8280-F792B647031F} + netcoreapp3.1 + {77E50520-8C68-460A-B138-3FACEE76F170} Library Properties Mages.Core.Tests Mages.Core.Tests - v4.0 - 512 - {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - 10.0 - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages - False - UnitTest + + + x64 + - true full false - bin\Debug\ DEBUG;TRACE prompt 4 + pdbonly - true - bin\Release\ - TRACE - prompt - 4 + - - ..\packages\NUnit.3.2.0\lib\net40\nunit.framework.dll - - - - 3.5 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - {b0698a2a-bfe9-4568-9055-82302f325452} - Mages.Core - + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + - + - - - - - False - - - False - - - False - - - False - - - - - - - - \ No newline at end of file + \ No newline at end of file diff --git a/src/Mages.Core.Tests/NumberTests.cs b/src/Mages.Core.Tests/NumberTests.cs index b5726363..013e1896 100644 --- a/src/Mages.Core.Tests/NumberTests.cs +++ b/src/Mages.Core.Tests/NumberTests.cs @@ -205,7 +205,7 @@ public void NumberAfterAndBeforeSpace() Assert.AreEqual(TokenType.Number, result.Type); Assert.AreEqual(TokenType.Space, space2.Type); Assert.AreEqual(TokenType.End, end.Type); - Assert.AreEqual("120000", result.Payload); + Assert.AreEqual("120000.00000000001", result.Payload); } [Test] @@ -218,7 +218,7 @@ public void DigitsOnlyNumberWithOverflowForInt32() var end = comment.Next(scanner); Assert.AreEqual(TokenType.Number, result.Type); Assert.AreEqual(TokenType.End, end.Type); - Assert.AreEqual("0.212410080106903", result.Payload); + Assert.AreEqual("0.21241008010690302", result.Payload); } [Test] diff --git a/src/Mages.Core.Tests/Properties/AssemblyInfo.cs b/src/Mages.Core.Tests/Properties/AssemblyInfo.cs deleted file mode 100644 index 20bf24d9..00000000 --- a/src/Mages.Core.Tests/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System.Reflection; -using System.Runtime.InteropServices; - -[assembly: AssemblyTitle("Mages.Core.Tests")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("Polytrope")] -[assembly: AssemblyProduct("Mages")] -[assembly: AssemblyCopyright("Copyright © 2016, Florian Rappl")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] -[assembly: ComVisible(false)] -[assembly: Guid("d0a97e4c-4c43-499c-b5b0-e70170d8ddfb")] -[assembly: AssemblyVersion("1.0.0.0")] \ No newline at end of file diff --git a/src/Mages.Core/AssemblyInfo.cs b/src/Mages.Core/AssemblyInfo.cs new file mode 100644 index 00000000..c378d32a --- /dev/null +++ b/src/Mages.Core/AssemblyInfo.cs @@ -0,0 +1,3 @@ +using System.Runtime.CompilerServices; + +[assembly: InternalsVisibleTo("Mages.Core.Tests")] \ No newline at end of file diff --git a/src/Mages.Core/Mages.Core.csproj b/src/Mages.Core/Mages.Core.csproj index b53cef18..96d4b1b8 100644 --- a/src/Mages.Core/Mages.Core.csproj +++ b/src/Mages.Core/Mages.Core.csproj @@ -1,237 +1,8 @@ - - - + - Debug - AnyCPU - {B0698A2A-BFE9-4568-9055-82302F325452} - Library - Properties - Mages.Core + netstandard2.0 Mages.Core - v3.5 - 512 - - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - bin\Release\Mages.Core.xml + Mages.Core + A lightweight parser / interpreter for mathematical expressions. - - - - - - - - - - - Properties\SharedAssemblyInfo.cs - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/Mages.Core/Properties/AssemblyInfo.cs b/src/Mages.Core/Properties/AssemblyInfo.cs deleted file mode 100644 index 43efc683..00000000 --- a/src/Mages.Core/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -[assembly: AssemblyTitle("Mages.Core")] -[assembly: AssemblyDescription("A lightweight parser / interpreter for mathematical expressions.")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] -[assembly: ComVisible(false)] -[assembly: Guid("f75805c5-2ae8-49dc-b423-25a7060a3b2b")] -[assembly: InternalsVisibleTo("Mages.Core.Tests")] \ No newline at end of file diff --git a/src/Mages.Nuget.nuspec b/src/Mages.Nuget.nuspec index b05c5ccc..260c64d7 100644 --- a/src/Mages.Nuget.nuspec +++ b/src/Mages.Nuget.nuspec @@ -11,10 +11,10 @@ false MAGES is a very simple, yet powerful, expression parser and interpreter. For all changes see: https://github.com/FlorianRappl/Mages/blob/master/CHANGELOG.md. - Copyright 2016, Florian Rappl. + Copyright 2021, Florian Rappl. interpreter mages expression scripting language mathematics performance - + diff --git a/src/Mages.Plugins.Common/Mages.Plugins.Common.csproj b/src/Mages.Plugins.Common/Mages.Plugins.Common.csproj index 2e1b584d..07dcb3a7 100644 --- a/src/Mages.Plugins.Common/Mages.Plugins.Common.csproj +++ b/src/Mages.Plugins.Common/Mages.Plugins.Common.csproj @@ -1,60 +1,11 @@ - - - + - Debug - AnyCPU - {62F70CC4-CAC2-4477-8E72-39366D185B68} - Library - Properties - Mages.Plugins.Common + netstandard2.0 Mages.Plugins.Common - v4.5 - 512 + Mages.Plugins - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - - - - - - - - - - - - + - - {b0698a2a-bfe9-4568-9055-82302f325452} - Mages.Core - + - - \ No newline at end of file diff --git a/src/Mages.Plugins.Common/Properties/AssemblyInfo.cs b/src/Mages.Plugins.Common/Properties/AssemblyInfo.cs deleted file mode 100644 index 0df722b8..00000000 --- a/src/Mages.Plugins.Common/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System.Reflection; -using System.Runtime.InteropServices; - -[assembly: AssemblyTitle("Mages.Plugins.Common")] -[assembly: AssemblyDescription("Plugin infrastructure for Mages.")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("Polytrope")] -[assembly: AssemblyProduct("Mages")] -[assembly: AssemblyCopyright("Copyright © Florian Rappl 2016")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] -[assembly: ComVisible(false)] -[assembly: Guid("a77b09c4-22f7-4f07-829c-bae73ce45494")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/src/Mages.Plugins.Draw/Mages.Plugins.Draw.csproj b/src/Mages.Plugins.Draw/Mages.Plugins.Draw.csproj index c4a59e9e..8a863458 100644 --- a/src/Mages.Plugins.Draw/Mages.Plugins.Draw.csproj +++ b/src/Mages.Plugins.Draw/Mages.Plugins.Draw.csproj @@ -1,61 +1,14 @@ - - - + - Debug - AnyCPU - {D9A3AF85-2B7F-4240-BBB4-54A75A599EFC} - Library - Properties - Mages.Plugins.Draw + netstandard2.0 Mages.Plugins.Draw - v4.5 - 512 - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 + Mages.Plugins.Draw - - - - - - - - - - - - - + + - - {62f70cc4-cac2-4477-8e72-39366d185b68} - Mages.Plugins.Common - + - - \ No newline at end of file diff --git a/src/Mages.Plugins.Draw/Properties/AssemblyInfo.cs b/src/Mages.Plugins.Draw/Properties/AssemblyInfo.cs deleted file mode 100644 index 61960634..00000000 --- a/src/Mages.Plugins.Draw/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System.Reflection; -using System.Runtime.InteropServices; - -[assembly: AssemblyTitle("Mages.Plugins.Draw")] -[assembly: AssemblyDescription("Drawing plugin for Mages.")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("Polytrope")] -[assembly: AssemblyProduct("Mages")] -[assembly: AssemblyCopyright("Copyright © Florian Rappl 2016")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] -[assembly: ComVisible(false)] -[assembly: Guid("b881e93b-526b-413a-bb7d-b9204499b9e1")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/src/Mages.Plugins.FileSystem/Mages.Plugins.FileSystem.csproj b/src/Mages.Plugins.FileSystem/Mages.Plugins.FileSystem.csproj index 966d6a16..f35f5336 100644 --- a/src/Mages.Plugins.FileSystem/Mages.Plugins.FileSystem.csproj +++ b/src/Mages.Plugins.FileSystem/Mages.Plugins.FileSystem.csproj @@ -1,62 +1,11 @@ - - - + - Debug - AnyCPU - {DF8D8E0E-87BC-4B70-8560-14B2DE02C424} - Library - Properties - Mages.Plugins.FileSystem + netstandard2.0 Mages.Plugins.FileSystem - v4.5 - 512 - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 + Mages.Plugins.FileSystem + - - - - - - - - - - - - - - - - - - {62f70cc4-cac2-4477-8e72-39366d185b68} - Mages.Plugins.Common - + - - \ No newline at end of file diff --git a/src/Mages.Plugins.FileSystem/Properties/AssemblyInfo.cs b/src/Mages.Plugins.FileSystem/Properties/AssemblyInfo.cs deleted file mode 100644 index 6102d829..00000000 --- a/src/Mages.Plugins.FileSystem/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System.Reflection; -using System.Runtime.InteropServices; - -[assembly: AssemblyTitle("Mages.Plugins.FileSystem")] -[assembly: AssemblyDescription("File System plugin for Mages.")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("Polytrope")] -[assembly: AssemblyProduct("Mages")] -[assembly: AssemblyCopyright("Copyright © Florian Rappl 2016")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] -[assembly: ComVisible(false)] -[assembly: Guid("58a7d7d9-850c-4d76-9dca-d4d8f71a0914")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/src/Mages.Plugins.LinearAlgebra/Mages.Plugins.LinearAlgebra.csproj b/src/Mages.Plugins.LinearAlgebra/Mages.Plugins.LinearAlgebra.csproj index 16382f4d..5f9cd30b 100644 --- a/src/Mages.Plugins.LinearAlgebra/Mages.Plugins.LinearAlgebra.csproj +++ b/src/Mages.Plugins.LinearAlgebra/Mages.Plugins.LinearAlgebra.csproj @@ -1,74 +1,11 @@ - - - + - Debug - AnyCPU - {84965E3E-B7E6-49E7-ADF1-46A3CB7EBEA6} - Library - Properties - Mages.Plugins.LinearAlgebra + netstandard2.0 Mages.Plugins.LinearAlgebra - v4.5 - 512 - - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 + Mages.Plugins.LinearAlgebra + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - {62f70cc4-cac2-4477-8e72-39366d185b68} - Mages.Plugins.Common - + - - \ No newline at end of file diff --git a/src/Mages.Plugins.LinearAlgebra/Properties/AssemblyInfo.cs b/src/Mages.Plugins.LinearAlgebra/Properties/AssemblyInfo.cs deleted file mode 100644 index eff79d47..00000000 --- a/src/Mages.Plugins.LinearAlgebra/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System.Reflection; -using System.Runtime.InteropServices; - -[assembly: AssemblyTitle("Mages.Plugins.LinearAlgebra")] -[assembly: AssemblyDescription("Linear Algebra plugin for Mages.")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("Polytrope")] -[assembly: AssemblyProduct("Mages")] -[assembly: AssemblyCopyright("Copyright © Florian Rappl 2016")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] -[assembly: ComVisible(false)] -[assembly: Guid("84965e3e-b7e6-49e7-adf1-46a3cb7ebea6")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/src/Mages.Plugins.Modules/Mages.Plugins.Modules.csproj b/src/Mages.Plugins.Modules/Mages.Plugins.Modules.csproj index 00418757..aee83ee3 100644 --- a/src/Mages.Plugins.Modules/Mages.Plugins.Modules.csproj +++ b/src/Mages.Plugins.Modules/Mages.Plugins.Modules.csproj @@ -1,65 +1,11 @@ - - - + - Debug - AnyCPU - {16E1BAF8-6CE0-404F-85D8-E8841CC48ECA} - Library - Properties - Mages.Plugins.Modules + netstandard2.0 Mages.Plugins.Modules - v4.5 - 512 - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 + Mages.Plugins.Modules + - - - - - - - - - - - - - - - - - - - - - {b0698a2a-bfe9-4568-9055-82302f325452} - Mages.Core - + - - \ No newline at end of file diff --git a/src/Mages.Plugins.Modules/Properties/AssemblyInfo.cs b/src/Mages.Plugins.Modules/Properties/AssemblyInfo.cs deleted file mode 100644 index 0e17a27e..00000000 --- a/src/Mages.Plugins.Modules/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System.Reflection; -using System.Runtime.InteropServices; - -[assembly: AssemblyTitle("Mages.Plugins.Modules")] -[assembly: AssemblyDescription("Modules plugin for Mages.")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("Polytrope")] -[assembly: AssemblyProduct("Mages")] -[assembly: AssemblyCopyright("Copyright © Florian Rappl 2016")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] -[assembly: ComVisible(false)] -[assembly: Guid("16e1baf8-6ce0-404f-85d8-e8841cc48eca")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/src/Mages.Plugins.Plots/Mages.Plugins.Plots.csproj b/src/Mages.Plugins.Plots/Mages.Plugins.Plots.csproj index 68315be3..47321841 100644 --- a/src/Mages.Plugins.Plots/Mages.Plugins.Plots.csproj +++ b/src/Mages.Plugins.Plots/Mages.Plugins.Plots.csproj @@ -1,68 +1,15 @@ - - - + - Debug - AnyCPU - {152E57B3-2AC2-434C-9695-73BB91E9D772} - Library - Properties - Mages.Plugins.Plots + netstandard2.0 Mages.Plugins.Plots - v4.5 - 512 - - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 + Mages.Plugins.Plots + - - ..\packages\OxyPlot.Core.1.0.0-unstable2100\lib\net45\OxyPlot.dll - True - - - - - - - - - - - - - - - - + + - - {62f70cc4-cac2-4477-8e72-39366d185b68} - Mages.Plugins.Common - + - - \ No newline at end of file diff --git a/src/Mages.Plugins.Plots/Properties/AssemblyInfo.cs b/src/Mages.Plugins.Plots/Properties/AssemblyInfo.cs deleted file mode 100644 index 2e814046..00000000 --- a/src/Mages.Plugins.Plots/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System.Reflection; -using System.Runtime.InteropServices; - -[assembly: AssemblyTitle("Mages.Plugins.Plots")] -[assembly: AssemblyDescription("Drawing plugin for Mages.")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("Polytrope")] -[assembly: AssemblyProduct("Mages")] -[assembly: AssemblyCopyright("Copyright © Florian Rappl 2016")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] -[assembly: ComVisible(false)] -[assembly: Guid("152e57b3-2ac2-434c-9695-73bb91e9d772")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/src/Mages.Plugins.Plots/packages.config b/src/Mages.Plugins.Plots/packages.config deleted file mode 100644 index 03bce4fe..00000000 --- a/src/Mages.Plugins.Plots/packages.config +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/src/Mages.Plugins.Random/Mages.Plugins.Random.csproj b/src/Mages.Plugins.Random/Mages.Plugins.Random.csproj index f1e1bd8e..89f62b28 100644 --- a/src/Mages.Plugins.Random/Mages.Plugins.Random.csproj +++ b/src/Mages.Plugins.Random/Mages.Plugins.Random.csproj @@ -1,73 +1,15 @@ - - - + - Debug - AnyCPU - {75FC4F51-4BB7-4F30-A0CA-80D91A5BDD62} - Library - Properties - Mages.Plugins.Random + netstandard2.0 Mages.Plugins.Random - v4.5 - 512 - - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 + Mages.Plugins.Random + - - ..\packages\Thrower.2.2.2\lib\net45\PommaLabs.Thrower.dll - True - - - - - - - - - - - ..\packages\Troschuetz.Random.4.0.4\lib\net45\Troschuetz.Random.dll - True - - - - - - - - - + + - - {62f70cc4-cac2-4477-8e72-39366d185b68} - Mages.Plugins.Common - + - - \ No newline at end of file diff --git a/src/Mages.Plugins.Random/Properties/AssemblyInfo.cs b/src/Mages.Plugins.Random/Properties/AssemblyInfo.cs deleted file mode 100644 index a55da376..00000000 --- a/src/Mages.Plugins.Random/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System.Reflection; -using System.Runtime.InteropServices; - -[assembly: AssemblyTitle("Mages.Plugins.Random")] -[assembly: AssemblyDescription("Random number generators plugin for Mages.")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("Polytrope")] -[assembly: AssemblyProduct("Mages")] -[assembly: AssemblyCopyright("Copyright © Florian Rappl 2016")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] -[assembly: ComVisible(false)] -[assembly: Guid("75fc4f51-4bb7-4f30-a0ca-80d91a5bdd62")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/src/Mages.Plugins.Random/packages.config b/src/Mages.Plugins.Random/packages.config deleted file mode 100644 index d641b04e..00000000 --- a/src/Mages.Plugins.Random/packages.config +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/src/Mages.Plugins.Transpilers/Mages.Plugins.Transpilers.csproj b/src/Mages.Plugins.Transpilers/Mages.Plugins.Transpilers.csproj index 4d2192fb..d8f5d68c 100644 --- a/src/Mages.Plugins.Transpilers/Mages.Plugins.Transpilers.csproj +++ b/src/Mages.Plugins.Transpilers/Mages.Plugins.Transpilers.csproj @@ -1,70 +1,15 @@ - - - + - Debug - AnyCPU - {AAB88537-6F7D-40A6-81A0-7CE6731FE0CB} - Library - Properties - Mages.Plugins.Transpilers + netstandard2.0 Mages.Plugins.Transpilers - v4.5 - 512 - - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 + Mages.Plugins.Transpilers - - - - - - - - - - - - - - - - - + + - - {b0698a2a-bfe9-4568-9055-82302f325452} - Mages.Core - - - {62f70cc4-cac2-4477-8e72-39366d185b68} - Mages.Plugins.Common - + + - - \ No newline at end of file diff --git a/src/Mages.Plugins.Transpilers/Properties/AssemblyInfo.cs b/src/Mages.Plugins.Transpilers/Properties/AssemblyInfo.cs deleted file mode 100644 index 79406e2b..00000000 --- a/src/Mages.Plugins.Transpilers/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("Mages.Plugins.Transpilers")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("Mages.Plugins.Transpilers")] -[assembly: AssemblyCopyright("Copyright © 2017")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("aab88537-6f7d-40a6-81a0-7ce6731fe0cb")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/src/Mages.Plugins.Transpilers/Transpiler.cs b/src/Mages.Plugins.Transpilers/Transpiler.cs index 189f13c1..fa0fc1c5 100644 --- a/src/Mages.Plugins.Transpilers/Transpiler.cs +++ b/src/Mages.Plugins.Transpilers/Transpiler.cs @@ -19,18 +19,6 @@ public String Js(String content) return Transform(walker, content); } - public String Cs(String content) - { - var walker = new CSharpTreeWalker(); - return Transform(walker, content); - } - - public String Cpp(String content) - { - var walker = new CPlusPlusTreeWalker(); - return Transform(walker, content); - } - private String Transform(TranspilerTreeWalker walker, String content) { var parser = _engine.Parser; diff --git a/src/Mages.Plugins.Transpilers/TranspilersPlugin.cs b/src/Mages.Plugins.Transpilers/TranspilersPlugin.cs index a1dc92fa..983c5903 100644 --- a/src/Mages.Plugins.Transpilers/TranspilersPlugin.cs +++ b/src/Mages.Plugins.Transpilers/TranspilersPlugin.cs @@ -19,8 +19,6 @@ public TranspilersPlugin(Engine engine) _transpiler = new Dictionary { { "toJavaScript", Wrap(transpiler.Js) }, - { "toCsharp", Wrap(transpiler.Cs) }, - { "toCplusplus", Wrap(transpiler.Cpp) } }; } diff --git a/src/Mages.Plugins.Transpilers/TreeWalkers/CPlusPlusTreeWalker.cs b/src/Mages.Plugins.Transpilers/TreeWalkers/CPlusPlusTreeWalker.cs deleted file mode 100644 index de7efca2..00000000 --- a/src/Mages.Plugins.Transpilers/TreeWalkers/CPlusPlusTreeWalker.cs +++ /dev/null @@ -1,307 +0,0 @@ -namespace Mages.Plugins.Transpilers.TreeWalkers -{ - using System; - - public class CPlusPlusTreeWalker : TranspilerTreeWalker - { - protected override void InsertAdd(Action left, Action right) - { - throw new NotImplementedException(); - } - - protected override void InsertAnd(Action left, Action right) - { - throw new NotImplementedException(); - } - - protected override void InsertArguments(Int32 length, Action argument) - { - throw new NotImplementedException(); - } - - protected override void InsertAssignment(Action slot, Action value) - { - throw new NotImplementedException(); - } - - protected override void InsertAwait(Action payload) - { - throw new NotImplementedException(); - } - - protected override void InsertBlock(Action body) - { - throw new NotImplementedException(); - } - - protected override void InsertBreak() - { - throw new NotImplementedException(); - } - - protected override void InsertCall(Boolean isAssigned, Action function, Action arguments) - { - throw new NotImplementedException(); - } - - protected override void InsertCase(Action condition, Action body) - { - throw new NotImplementedException(); - } - - protected override void InsertCondition(Action condition, Action primary, Action secondary) - { - throw new NotImplementedException(); - } - - protected override void InsertConstant(Object value) - { - throw new NotImplementedException(); - } - - protected override void InsertContinue() - { - throw new NotImplementedException(); - } - - protected override void InsertDefVariable(String name) - { - throw new NotImplementedException(); - } - - protected override void InsertDelMember(Action obj, String name) - { - throw new NotImplementedException(); - } - - protected override void InsertDelVariable(String name) - { - throw new NotImplementedException(); - } - - protected override void InsertDiv(Action left, Action right) - { - throw new NotImplementedException(); - } - - protected override void InsertEq(Action left, Action right) - { - throw new NotImplementedException(); - } - - protected override void InsertFactorial(Action expression) - { - throw new NotImplementedException(); - } - - protected override void InsertFor(Action init, Action condition, Action post, Action body) - { - throw new NotImplementedException(); - } - - protected override void InsertFunction(Boolean isMethod, Action parameters, Action body) - { - throw new NotImplementedException(); - } - - protected override void InsertGeq(Action left, Action right) - { - throw new NotImplementedException(); - } - - protected override void InsertGetMember(Action obj, Action property) - { - throw new NotImplementedException(); - } - - protected override void InsertGetVariable(String name) - { - throw new NotImplementedException(); - } - - protected override void InsertGt(Action left, Action right) - { - throw new NotImplementedException(); - } - - protected override void InsertIdentifier(String name) - { - throw new NotImplementedException(); - } - - protected override void InsertIf(Action condition, Action primary, Action secondary) - { - throw new NotImplementedException(); - } - - protected override void InsertMod(Action left, Action right) - { - throw new NotImplementedException(); - } - - protected override void InsertPow(Action left, Action right) - { - throw new NotImplementedException(); - } - - protected override void InsertInterpolatedString(String formattedString, Int32 length, Action replacement) - { - throw new NotImplementedException(); - } - - protected override void InsertLeq(Action left, Action right) - { - throw new NotImplementedException(); - } - - protected override void InsertLookupType(Action expression) - { - throw new NotImplementedException(); - } - - protected override void InsertLt(Action left, Action right) - { - throw new NotImplementedException(); - } - - protected override void InsertMatch(Action reference, Action cases) - { - throw new NotImplementedException(); - } - - protected override void InsertMatrix(Int32 cols, Int32 rows, Action cell) - { - throw new NotImplementedException(); - } - - protected override void InsertMul(Action left, Action right) - { - throw new NotImplementedException(); - } - - protected override void InsertNegative(Action expression) - { - throw new NotImplementedException(); - } - - protected override void InsertNeq(Action left, Action right) - { - throw new NotImplementedException(); - } - - protected override void InsertNot(Action expression) - { - throw new NotImplementedException(); - } - - protected override void InsertObject(Int32 length, Action property) - { - throw new NotImplementedException(); - } - - protected override void InsertOptionalParameter(String name, Action defaultValue) - { - throw new NotImplementedException(); - } - - protected override void InsertOr(Action left, Action right) - { - throw new NotImplementedException(); - } - - protected override void InsertParameters(Int32 length, Action parameter) - { - throw new NotImplementedException(); - } - - protected override void InsertPipe(Action left, Action right) - { - throw new NotImplementedException(); - } - - protected override void InsertPositive(Action expression) - { - throw new NotImplementedException(); - } - - protected override void InsertPostDecrement(Action expression) - { - throw new NotImplementedException(); - } - - protected override void InsertPostIncrement(Action expression) - { - throw new NotImplementedException(); - } - - protected override void InsertPreDecrement(Action expression) - { - throw new NotImplementedException(); - } - - protected override void InsertPreIncrement(Action expression) - { - throw new NotImplementedException(); - } - - protected override void InsertProperty(Action name, Action value) - { - throw new NotImplementedException(); - } - - protected override void InsertRange(Action from, Action to, Action step) - { - throw new NotImplementedException(); - } - - protected override void InsertRequiredParameters(String name) - { - throw new NotImplementedException(); - } - - protected override void InsertReturn(Action payload) - { - throw new NotImplementedException(); - } - - protected override void InsertReverseDiv(Action left, Action right) - { - throw new NotImplementedException(); - } - - protected override void InsertSetMember(Action obj, Action property) - { - throw new NotImplementedException(); - } - - protected override void InsertSetVariable(String name) - { - throw new NotImplementedException(); - } - - protected override void InsertStatement(Action body) - { - throw new NotImplementedException(); - } - - protected override void InsertSub(Action left, Action right) - { - throw new NotImplementedException(); - } - - protected override void InsertTranspose(Action expression) - { - throw new NotImplementedException(); - } - - protected override void InsertWhile(Action condition, Action body) - { - throw new NotImplementedException(); - } - - protected override String Stringify() - { - throw new NotImplementedException(); - } - } -} diff --git a/src/Mages.Plugins.Transpilers/TreeWalkers/CSharpTreeWalker.cs b/src/Mages.Plugins.Transpilers/TreeWalkers/CSharpTreeWalker.cs deleted file mode 100644 index 99d78531..00000000 --- a/src/Mages.Plugins.Transpilers/TreeWalkers/CSharpTreeWalker.cs +++ /dev/null @@ -1,307 +0,0 @@ -namespace Mages.Plugins.Transpilers.TreeWalkers -{ - using System; - - public class CSharpTreeWalker : TranspilerTreeWalker - { - protected override void InsertAdd(Action left, Action right) - { - throw new NotImplementedException(); - } - - protected override void InsertAnd(Action left, Action right) - { - throw new NotImplementedException(); - } - - protected override void InsertArguments(Int32 length, Action argument) - { - throw new NotImplementedException(); - } - - protected override void InsertAssignment(Action slot, Action value) - { - throw new NotImplementedException(); - } - - protected override void InsertAwait(Action payload) - { - throw new NotImplementedException(); - } - - protected override void InsertBlock(Action body) - { - throw new NotImplementedException(); - } - - protected override void InsertBreak() - { - throw new NotImplementedException(); - } - - protected override void InsertCall(Boolean isAssigned, Action function, Action arguments) - { - throw new NotImplementedException(); - } - - protected override void InsertCase(Action condition, Action body) - { - throw new NotImplementedException(); - } - - protected override void InsertCondition(Action condition, Action primary, Action secondary) - { - throw new NotImplementedException(); - } - - protected override void InsertConstant(Object value) - { - throw new NotImplementedException(); - } - - protected override void InsertContinue() - { - throw new NotImplementedException(); - } - - protected override void InsertDefVariable(String name) - { - throw new NotImplementedException(); - } - - protected override void InsertDelMember(Action obj, String name) - { - throw new NotImplementedException(); - } - - protected override void InsertDelVariable(String name) - { - throw new NotImplementedException(); - } - - protected override void InsertDiv(Action left, Action right) - { - throw new NotImplementedException(); - } - - protected override void InsertEq(Action left, Action right) - { - throw new NotImplementedException(); - } - - protected override void InsertFactorial(Action expression) - { - throw new NotImplementedException(); - } - - protected override void InsertFor(Action init, Action condition, Action post, Action body) - { - throw new NotImplementedException(); - } - - protected override void InsertFunction(Boolean isMethod, Action parameters, Action body) - { - throw new NotImplementedException(); - } - - protected override void InsertGeq(Action left, Action right) - { - throw new NotImplementedException(); - } - - protected override void InsertGetMember(Action obj, Action property) - { - throw new NotImplementedException(); - } - - protected override void InsertGetVariable(String name) - { - throw new NotImplementedException(); - } - - protected override void InsertGt(Action left, Action right) - { - throw new NotImplementedException(); - } - - protected override void InsertIdentifier(String name) - { - throw new NotImplementedException(); - } - - protected override void InsertIf(Action condition, Action primary, Action secondary) - { - throw new NotImplementedException(); - } - - protected override void InsertMod(Action left, Action right) - { - throw new NotImplementedException(); - } - - protected override void InsertPow(Action left, Action right) - { - throw new NotImplementedException(); - } - - protected override void InsertInterpolatedString(String formattedString, Int32 length, Action replacement) - { - throw new NotImplementedException(); - } - - protected override void InsertLeq(Action left, Action right) - { - throw new NotImplementedException(); - } - - protected override void InsertLookupType(Action expression) - { - throw new NotImplementedException(); - } - - protected override void InsertLt(Action left, Action right) - { - throw new NotImplementedException(); - } - - protected override void InsertMatch(Action reference, Action cases) - { - throw new NotImplementedException(); - } - - protected override void InsertMatrix(Int32 cols, Int32 rows, Action cell) - { - throw new NotImplementedException(); - } - - protected override void InsertMul(Action left, Action right) - { - throw new NotImplementedException(); - } - - protected override void InsertNegative(Action expression) - { - throw new NotImplementedException(); - } - - protected override void InsertNeq(Action left, Action right) - { - throw new NotImplementedException(); - } - - protected override void InsertNot(Action expression) - { - throw new NotImplementedException(); - } - - protected override void InsertObject(Int32 length, Action property) - { - throw new NotImplementedException(); - } - - protected override void InsertOptionalParameter(String name, Action defaultValue) - { - throw new NotImplementedException(); - } - - protected override void InsertOr(Action left, Action right) - { - throw new NotImplementedException(); - } - - protected override void InsertParameters(Int32 length, Action parameter) - { - throw new NotImplementedException(); - } - - protected override void InsertPipe(Action left, Action right) - { - throw new NotImplementedException(); - } - - protected override void InsertPositive(Action expression) - { - throw new NotImplementedException(); - } - - protected override void InsertPostDecrement(Action expression) - { - throw new NotImplementedException(); - } - - protected override void InsertPostIncrement(Action expression) - { - throw new NotImplementedException(); - } - - protected override void InsertPreDecrement(Action expression) - { - throw new NotImplementedException(); - } - - protected override void InsertPreIncrement(Action expression) - { - throw new NotImplementedException(); - } - - protected override void InsertProperty(Action name, Action value) - { - throw new NotImplementedException(); - } - - protected override void InsertRange(Action from, Action to, Action step) - { - throw new NotImplementedException(); - } - - protected override void InsertRequiredParameters(String name) - { - throw new NotImplementedException(); - } - - protected override void InsertReturn(Action payload) - { - throw new NotImplementedException(); - } - - protected override void InsertReverseDiv(Action left, Action right) - { - throw new NotImplementedException(); - } - - protected override void InsertSetMember(Action obj, Action property) - { - throw new NotImplementedException(); - } - - protected override void InsertSetVariable(String name) - { - throw new NotImplementedException(); - } - - protected override void InsertStatement(Action body) - { - throw new NotImplementedException(); - } - - protected override void InsertSub(Action left, Action right) - { - throw new NotImplementedException(); - } - - protected override void InsertTranspose(Action expression) - { - throw new NotImplementedException(); - } - - protected override void InsertWhile(Action condition, Action body) - { - throw new NotImplementedException(); - } - - protected override String Stringify() - { - throw new NotImplementedException(); - } - } -} diff --git a/src/Mages.Repl.Base/AssemblyInfo.cs b/src/Mages.Repl.Base/AssemblyInfo.cs new file mode 100644 index 00000000..a793f4e4 --- /dev/null +++ b/src/Mages.Repl.Base/AssemblyInfo.cs @@ -0,0 +1,3 @@ +using System.Runtime.CompilerServices; + +[assembly: InternalsVisibleTo("Mages.Repl.Tests")] \ No newline at end of file diff --git a/src/Mages.Repl.Base/Mages.Repl.Base.csproj b/src/Mages.Repl.Base/Mages.Repl.Base.csproj index c71796e1..fd24f919 100644 --- a/src/Mages.Repl.Base/Mages.Repl.Base.csproj +++ b/src/Mages.Repl.Base/Mages.Repl.Base.csproj @@ -1,129 +1,24 @@ - - - + - Debug - AnyCPU - {18E9CD99-8F61-4E77-A59A-8EFDC588042E} - Library - Properties - Mages.Repl + netstandard2.0 Mages.Repl.Base - v4.5 - 512 - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 + Mages.Repl + - - ..\packages\Microsoft.Web.Xdt.2.1.1\lib\net40\Microsoft.Web.XmlTransform.dll - True - - - ..\packages\NuGet.Core.2.11.1\lib\net40-Client\NuGet.Core.dll - True - - - - - - - - - - - - - Properties\SharedAssemblyInfo.cs - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + - - {b0698a2a-bfe9-4568-9055-82302f325452} - Mages.Core - - - {62f70cc4-cac2-4477-8e72-39366d185b68} - Mages.Plugins.Common - - - {d9a3af85-2b7f-4240-bbb4-54a75a599efc} - Mages.Plugins.Draw - - - {df8d8e0e-87bc-4b70-8560-14b2de02c424} - Mages.Plugins.FileSystem - - - {84965e3e-b7e6-49e7-adf1-46a3cb7ebea6} - Mages.Plugins.LinearAlgebra - - - {16e1baf8-6ce0-404f-85d8-e8841cc48eca} - Mages.Plugins.Modules - - - {152e57b3-2ac2-434c-9695-73bb91e9d772} - Mages.Plugins.Plots - - - {75fc4f51-4bb7-4f30-a0ca-80d91a5bdd62} - Mages.Plugins.Random - - - {aab88537-6f7d-40a6-81a0-7ce6731fe0cb} - Mages.Plugins.Transpilers - + + - - - \ No newline at end of file + diff --git a/src/Mages.Repl.Base/Properties/AssemblyInfo.cs b/src/Mages.Repl.Base/Properties/AssemblyInfo.cs deleted file mode 100644 index 8079ea0d..00000000 --- a/src/Mages.Repl.Base/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -[assembly: AssemblyTitle("Mages.Repl.Base")] -[assembly: AssemblyDescription("REPL base library for MAGES.")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] -[assembly: ComVisible(false)] -[assembly: Guid("18e9cd99-8f61-4e77-a59a-8efdc588042e")] -[assembly: InternalsVisibleTo("Mages.Repl.Tests")] \ No newline at end of file diff --git a/src/Mages.Repl.Base/packages.config b/src/Mages.Repl.Base/packages.config deleted file mode 100644 index e920eeb9..00000000 --- a/src/Mages.Repl.Base/packages.config +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/src/Mages.Repl.Tests/Mages.Repl.Tests.csproj b/src/Mages.Repl.Tests/Mages.Repl.Tests.csproj index e6368b43..c129eec1 100644 --- a/src/Mages.Repl.Tests/Mages.Repl.Tests.csproj +++ b/src/Mages.Repl.Tests/Mages.Repl.Tests.csproj @@ -1,101 +1,40 @@ - - + - Debug - AnyCPU + netcoreapp3.1 {92BAD61F-F5B6-4E6D-A34A-939B994B2910} Library Properties Mages.Repl.Tests Mages.Repl.Tests - v4.5 - 512 - {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - 10.0 - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages - False - UnitTest + + + x64 + - true full false - bin\Debug\ DEBUG;TRACE prompt 4 + pdbonly - true - bin\Release\ - TRACE - prompt - 4 + - - ..\packages\NUnit.3.2.0\lib\net45\nunit.framework.dll - True - - - - - - - - - - - - - - - - - - - {b0698a2a-bfe9-4568-9055-82302f325452} - Mages.Core - - - {16e1baf8-6ce0-404f-85d8-e8841cc48eca} - Mages.Plugins.Modules - - - {18e9cd99-8f61-4e77-a59a-8efdc588042e} - Mages.Repl.Base - + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + - + + + - - - - - False - - - False - - - False - - - False - - - - - - - \ No newline at end of file diff --git a/src/Mages.Repl.Tests/Properties/AssemblyInfo.cs b/src/Mages.Repl.Tests/Properties/AssemblyInfo.cs deleted file mode 100644 index 54ba446e..00000000 --- a/src/Mages.Repl.Tests/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System.Reflection; -using System.Runtime.InteropServices; - -[assembly: AssemblyTitle("Mages.Repl.Tests")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("Polytrope")] -[assembly: AssemblyProduct("Mages")] -[assembly: AssemblyCopyright("Copyright © 2016, Florian Rappl")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] -[assembly: ComVisible(false)] -[assembly: Guid("92bad61f-f5b6-4e6d-a34a-939b994b2910")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/src/Mages.Repl/Mages.Repl.csproj b/src/Mages.Repl/Mages.Repl.csproj index ff838756..b1d7c6ce 100644 --- a/src/Mages.Repl/Mages.Repl.csproj +++ b/src/Mages.Repl/Mages.Repl.csproj @@ -1,92 +1,31 @@ - - - + - Debug - AnyCPU + netcoreapp3.1 {027A32F7-4411-4083-AA01-0550EEA0E5A3} Exe Properties Mages.Repl mages - v4.5 - 512 - + + + x64 + - true full false - bin\Debug\ DEBUG;TRACE prompt 4 - false - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - false - - - - - - ..\packages\CommandLineParser.2.0.275-beta\lib\net45\CommandLine.dll - True - - - ..\packages\Ninject.3.2.2.0\lib\net45-full\Ninject.dll - True - - - - - - - - - - - - Properties\SharedAssemblyInfo.cs - - - - - - - - - - - - - - - - + - - + + + + - - {18e9cd99-8f61-4e77-a59a-8efdc588042e} - Mages.Repl.Base - + - - \ No newline at end of file diff --git a/src/Mages.Repl/Properties/AssemblyInfo.cs b/src/Mages.Repl/Properties/AssemblyInfo.cs deleted file mode 100644 index 85a2f2d1..00000000 --- a/src/Mages.Repl/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,12 +0,0 @@ -using CommandLine.Text; -using System.Reflection; -using System.Runtime.InteropServices; - -[assembly: AssemblyTitle("Mages")] -[assembly: AssemblyDescription("Default Read-Evaluate-Print-Loop for the MAGES parser / interpreter.")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyLicense("The MIT License (MIT)")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] -[assembly: ComVisible(false)] -[assembly: Guid("c81b4efa-f050-4039-bc5c-1f928d9bf5d3")] \ No newline at end of file diff --git a/src/Mages.Repl/packages.config b/src/Mages.Repl/packages.config deleted file mode 100644 index 4b37a45c..00000000 --- a/src/Mages.Repl/packages.config +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/src/Mages.Squirrel.nuspec b/src/Mages.Squirrel.nuspec index 92a10502..2c464dc1 100644 --- a/src/Mages.Squirrel.nuspec +++ b/src/Mages.Squirrel.nuspec @@ -10,7 +10,7 @@ https://raw.github.com/FlorianRappl/Mages/master/logo.png false https://github.com/FlorianRappl/Mages/blob/master/CHANGELOG.md - Copyright 2016, Florian Rappl. + Copyright 2021, Florian Rappl. MAGES is a very simple, yet powerful, expression parser and interpreter. diff --git a/src/Mages.sln b/src/Mages.sln index f8c55efc..36ad1d1f 100644 --- a/src/Mages.sln +++ b/src/Mages.sln @@ -1,40 +1,40 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 14 -VisualStudioVersion = 14.0.25420.1 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.31313.79 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mages.Core", "Mages.Core\Mages.Core.csproj", "{B0698A2A-BFE9-4568-9055-82302F325452}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mages.Core", "Mages.Core\Mages.Core.csproj", "{B0698A2A-BFE9-4568-9055-82302F325452}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mages.Core.Tests", "Mages.Core.Tests\Mages.Core.Tests.csproj", "{72E0C8E6-8853-4919-8280-F792B647031F}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mages.Core.Tests", "Mages.Core.Tests\Mages.Core.Tests.csproj", "{77E50520-8C68-460A-B138-3FACEE76F170}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mages.Repl", "Mages.Repl\Mages.Repl.csproj", "{027A32F7-4411-4083-AA01-0550EEA0E5A3}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mages.Repl", "Mages.Repl\Mages.Repl.csproj", "{027A32F7-4411-4083-AA01-0550EEA0E5A3}" ProjectSection(ProjectDependencies) = postProject {18E9CD99-8F61-4E77-A59A-8EFDC588042E} = {18E9CD99-8F61-4E77-A59A-8EFDC588042E} EndProjectSection EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mages.Core.Performance", "Mages.Core.Performance\Mages.Core.Performance.csproj", "{15B324FD-3EE3-467A-BDDA-A6F571FEA4C8}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mages.Core.Performance", "Mages.Core.Performance\Mages.Core.Performance.csproj", "{15B324FD-3EE3-467A-BDDA-A6F571FEA4C8}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mages.Repl.Installer", "Mages.Repl.Installer\Mages.Repl.Installer.csproj", "{2239BDD1-07B4-44B0-A6DB-ED4C69B8797C}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mages.Plugins.LinearAlgebra", "Mages.Plugins.LinearAlgebra\Mages.Plugins.LinearAlgebra.csproj", "{84965E3E-B7E6-49E7-ADF1-46A3CB7EBEA6}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mages.Plugins.LinearAlgebra", "Mages.Plugins.LinearAlgebra\Mages.Plugins.LinearAlgebra.csproj", "{84965E3E-B7E6-49E7-ADF1-46A3CB7EBEA6}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mages.Plugins.FileSystem", "Mages.Plugins.FileSystem\Mages.Plugins.FileSystem.csproj", "{DF8D8E0E-87BC-4B70-8560-14B2DE02C424}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mages.Plugins.FileSystem", "Mages.Plugins.FileSystem\Mages.Plugins.FileSystem.csproj", "{DF8D8E0E-87BC-4B70-8560-14B2DE02C424}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mages.Plugins.Draw", "Mages.Plugins.Draw\Mages.Plugins.Draw.csproj", "{D9A3AF85-2B7F-4240-BBB4-54A75A599EFC}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mages.Plugins.Draw", "Mages.Plugins.Draw\Mages.Plugins.Draw.csproj", "{D9A3AF85-2B7F-4240-BBB4-54A75A599EFC}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mages.Plugins.Plots", "Mages.Plugins.Plots\Mages.Plugins.Plots.csproj", "{152E57B3-2AC2-434C-9695-73BB91E9D772}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mages.Plugins.Plots", "Mages.Plugins.Plots\Mages.Plugins.Plots.csproj", "{152E57B3-2AC2-434C-9695-73BB91E9D772}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mages.Plugins.Random", "Mages.Plugins.Random\Mages.Plugins.Random.csproj", "{75FC4F51-4BB7-4F30-A0CA-80D91A5BDD62}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mages.Plugins.Random", "Mages.Plugins.Random\Mages.Plugins.Random.csproj", "{75FC4F51-4BB7-4F30-A0CA-80D91A5BDD62}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mages.Plugins.Modules", "Mages.Plugins.Modules\Mages.Plugins.Modules.csproj", "{16E1BAF8-6CE0-404F-85D8-E8841CC48ECA}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mages.Plugins.Modules", "Mages.Plugins.Modules\Mages.Plugins.Modules.csproj", "{16E1BAF8-6CE0-404F-85D8-E8841CC48ECA}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mages.Plugins.Common", "Mages.Plugins.Common\Mages.Plugins.Common.csproj", "{62F70CC4-CAC2-4477-8E72-39366D185B68}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mages.Plugins.Common", "Mages.Plugins.Common\Mages.Plugins.Common.csproj", "{62F70CC4-CAC2-4477-8E72-39366D185B68}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mages.Repl.Tests", "Mages.Repl.Tests\Mages.Repl.Tests.csproj", "{92BAD61F-F5B6-4E6D-A34A-939B994B2910}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mages.Repl.Tests", "Mages.Repl.Tests\Mages.Repl.Tests.csproj", "{92BAD61F-F5B6-4E6D-A34A-939B994B2910}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mages.Repl.Base", "Mages.Repl.Base\Mages.Repl.Base.csproj", "{18E9CD99-8F61-4E77-A59A-8EFDC588042E}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mages.Repl.Base", "Mages.Repl.Base\Mages.Repl.Base.csproj", "{18E9CD99-8F61-4E77-A59A-8EFDC588042E}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mages.Plugins.Transpilers", "Mages.Plugins.Transpilers\Mages.Plugins.Transpilers.csproj", "{AAB88537-6F7D-40A6-81A0-7CE6731FE0CB}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mages.Plugins.Transpilers", "Mages.Plugins.Transpilers\Mages.Plugins.Transpilers.csproj", "{AAB88537-6F7D-40A6-81A0-7CE6731FE0CB}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -46,12 +46,12 @@ Global {B0698A2A-BFE9-4568-9055-82302F325452}.Debug|Any CPU.Build.0 = Debug|Any CPU {B0698A2A-BFE9-4568-9055-82302F325452}.Release|Any CPU.ActiveCfg = Release|Any CPU {B0698A2A-BFE9-4568-9055-82302F325452}.Release|Any CPU.Build.0 = Release|Any CPU - {72E0C8E6-8853-4919-8280-F792B647031F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {72E0C8E6-8853-4919-8280-F792B647031F}.Debug|Any CPU.Build.0 = Debug|Any CPU - {72E0C8E6-8853-4919-8280-F792B647031F}.Release|Any CPU.ActiveCfg = Release|Any CPU - {72E0C8E6-8853-4919-8280-F792B647031F}.Release|Any CPU.Build.0 = Release|Any CPU - {027A32F7-4411-4083-AA01-0550EEA0E5A3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {027A32F7-4411-4083-AA01-0550EEA0E5A3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {77E50520-8C68-460A-B138-3FACEE76F170}.Debug|Any CPU.ActiveCfg = Debug|x64 + {77E50520-8C68-460A-B138-3FACEE76F170}.Debug|Any CPU.Build.0 = Debug|x64 + {77E50520-8C68-460A-B138-3FACEE76F170}.Release|Any CPU.ActiveCfg = Release|Any CPU + {77E50520-8C68-460A-B138-3FACEE76F170}.Release|Any CPU.Build.0 = Release|Any CPU + {027A32F7-4411-4083-AA01-0550EEA0E5A3}.Debug|Any CPU.ActiveCfg = Debug|x64 + {027A32F7-4411-4083-AA01-0550EEA0E5A3}.Debug|Any CPU.Build.0 = Debug|x64 {027A32F7-4411-4083-AA01-0550EEA0E5A3}.Release|Any CPU.ActiveCfg = Release|Any CPU {027A32F7-4411-4083-AA01-0550EEA0E5A3}.Release|Any CPU.Build.0 = Release|Any CPU {15B324FD-3EE3-467A-BDDA-A6F571FEA4C8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU @@ -90,8 +90,8 @@ Global {62F70CC4-CAC2-4477-8E72-39366D185B68}.Debug|Any CPU.Build.0 = Debug|Any CPU {62F70CC4-CAC2-4477-8E72-39366D185B68}.Release|Any CPU.ActiveCfg = Release|Any CPU {62F70CC4-CAC2-4477-8E72-39366D185B68}.Release|Any CPU.Build.0 = Release|Any CPU - {92BAD61F-F5B6-4E6D-A34A-939B994B2910}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {92BAD61F-F5B6-4E6D-A34A-939B994B2910}.Debug|Any CPU.Build.0 = Debug|Any CPU + {92BAD61F-F5B6-4E6D-A34A-939B994B2910}.Debug|Any CPU.ActiveCfg = Debug|x64 + {92BAD61F-F5B6-4E6D-A34A-939B994B2910}.Debug|Any CPU.Build.0 = Debug|x64 {92BAD61F-F5B6-4E6D-A34A-939B994B2910}.Release|Any CPU.ActiveCfg = Release|Any CPU {92BAD61F-F5B6-4E6D-A34A-939B994B2910}.Release|Any CPU.Build.0 = Release|Any CPU {18E9CD99-8F61-4E77-A59A-8EFDC588042E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU @@ -106,4 +106,7 @@ Global GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {B90BCD75-8311-463A-9F55-263E7CC0609E} + EndGlobalSection EndGlobal diff --git a/src/SharedAssemblyInfo.cs b/src/SharedAssemblyInfo.cs deleted file mode 100644 index f1d3d307..00000000 --- a/src/SharedAssemblyInfo.cs +++ /dev/null @@ -1,13 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by Cake. -// -//------------------------------------------------------------------------------ -using System.Reflection; - -[assembly: AssemblyCompany("smapiot")] -[assembly: AssemblyProduct("Mages")] -[assembly: AssemblyVersion("2.0.0")] -[assembly: AssemblyFileVersion("2.0.0")] -[assembly: AssemblyCopyright("Copyright (c) 2021, Florian Rappl")] - From cdd623a4c9aea199ec12bc69fe6159be27847f10 Mon Sep 17 00:00:00 2001 From: Florian Rappl Date: Wed, 19 May 2021 11:17:42 +0200 Subject: [PATCH 04/27] CI/CD improvements --- .github/workflows/ci.yml | 34 + build.cake | 97 +- src/Mages.Core.Tests/Mages.Core.Tests.csproj | 2 + src/Mages.Core/Mages.Core.csproj | 1 + src/Mages.Core/Mages.Core.xml | 4920 +++++++++++++++++ src/Mages.Repl.Installer/Installer.cs | 7 + .../Mages.Repl.Installer.csproj | 112 +- src/Mages.Repl.Installer/Program.cs | 2 +- .../Properties/AssemblyInfo.cs | 13 - src/Mages.Repl.Installer/packages.config | 8 - src/Mages.Repl.Tests/Mages.Repl.Tests.csproj | 2 + src/Mages.Repl.Tests/packages.config | 4 - src/Mages.sln | 8 +- 13 files changed, 5032 insertions(+), 178 deletions(-) create mode 100644 .github/workflows/ci.yml create mode 100644 src/Mages.Core/Mages.Core.xml delete mode 100644 src/Mages.Repl.Installer/Properties/AssemblyInfo.cs delete mode 100644 src/Mages.Repl.Installer/packages.config delete mode 100644 src/Mages.Repl.Tests/packages.config diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..71edcaed --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,34 @@ +name: CI + +on: [push, pull_request] + +env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }} + CHOCOLATEY_API_KEY: ${{ secrets.CHOCOLATEY_API_KEY }} + +jobs: + linux: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Build + run: ./build.sh + + windows: + runs-on: windows-latest + + steps: + - uses: actions/checkout@v2 + + - name: Build + run: | + if ($env:GITHUB_REF -eq "refs/heads/main") { + .\build.ps1 -Target Publish + } elseif ($env:GITHUB_REF -eq "refs/heads/devel") { + .\build.ps1 -Target PrePublish + } else { + .\build.ps1 + } diff --git a/build.cake b/build.cake index dc1545f3..d4ca4084 100644 --- a/build.cake +++ b/build.cake @@ -4,8 +4,8 @@ - Update CHANGELOG.md - Run a normal build with Cake - - Push to devel and FF merge to master - - Switch to master + - Push to devel and FF merge to main + - Switch to main - Run a Publish build with Cake - Switch back to devel branch **************************************** */ @@ -17,22 +17,33 @@ using Octokit; var target = Argument("target", "Default"); var configuration = Argument("configuration", "Release"); -var isLocal = BuildSystem.IsLocalBuild; var isRunningOnUnix = IsRunningOnUnix(); var isRunningOnWindows = IsRunningOnWindows(); -var isRunningOnAppVeyor = AppVeyor.IsRunningOnAppVeyor; -var isPullRequest = AppVeyor.Environment.PullRequest.IsPullRequest; -var buildNumber = AppVeyor.Environment.Build.Number; var releaseNotes = ParseReleaseNotes("./CHANGELOG.md"); var version = releaseNotes.Version.ToString(); -var buildDir = Directory("./src/Mages.Core/bin") + Directory(configuration); -var installerDir = Directory("./src/Mages.Repl.Installer/bin") + Directory(configuration); +var buildDir = Directory("./src/Mages.Core/bin") + Directory(configuration) + Directory("netstandard2.0"); +var replDir = Directory("./src/Mages.Repl/bin") + Directory(configuration) + Directory("netcoreapp3.1"); +var installerDir = Directory("./src/Mages.Repl.Installer/bin") + Directory(configuration) + Directory("net45"); var buildResultDir = Directory("./bin") + Directory(version); var nugetRoot = buildResultDir + Directory("nuget"); var chocolateyRoot = buildResultDir + Directory("chocolatey"); var squirrelRoot = buildResultDir + Directory("squirrel"); var releaseDir = squirrelRoot + Directory("release"); +if (BuildSystem.GitHubActions.IsRunningOnGitHubActions) +{ + var buildNumber = BuildSystem.GitHubActions.Environment.Workflow.RunNumber; + + if (target == "Default") + { + version = $"{version}-ci-{buildNumber}"; + } + else if (target == "PrePublish") + { + version = $"{version}-alpha-{buildNumber}"; + } +} + // Initialization // ---------------------------------------- @@ -64,16 +75,7 @@ Task("Restore-Packages") Task("Update-Assembly-Version") .Does(() => { - var file = Directory("./src") + File("SharedAssemblyInfo.cs"); - - CreateAssemblyInfo(file, new AssemblyInfoSettings - { - Product = "Mages", - Version = version, - FileVersion = version, - Company = "Polytrope", - Copyright = String.Format("Copyright (c) {0}, Florian Rappl", DateTime.Now.Year) - }); + ReplaceRegexInFiles("./src/Directory.Build.props", "(?<=)(.+?)(?=)", version); }); Task("Build") @@ -81,44 +83,35 @@ Task("Build") .IsDependentOn("Update-Assembly-Version") .Does(() => { - if (isRunningOnWindows) + DotNetCoreBuild($"./src/Mages.sln", new DotNetCoreBuildSettings { - MSBuild("./src/Mages.sln", new MSBuildSettings() - .SetConfiguration(configuration) - .SetVerbosity(Verbosity.Minimal) - ); - } - else - { - XBuild("./src/Mages.sln", new XBuildSettings() - .SetConfiguration(configuration) - .SetVerbosity(Verbosity.Minimal) - ); - } + Configuration = configuration, + }); }); Task("Run-Unit-Tests") .IsDependentOn("Build") .Does(() => { - var settings = new NUnit3Settings + var settings = new DotNetCoreTestSettings { - Work = buildResultDir.Path.FullPath + Configuration = configuration, }; - if (isRunningOnAppVeyor) + if (isRunningOnGitHubActions) { - settings.Where = "cat != ExcludeFromAppVeyor"; + settings.Loggers.Add("GitHubActions"); } - NUnit3("./src/**/bin/" + configuration + "/*.Tests.dll", settings); + DotNetCoreTest($"./src/Mages.Core.Tests/", settings); + DotNetCoreTest($"./src/Mages.Repl.Tests/", settings); }); Task("Copy-Files") .IsDependentOn("Build") .Does(() => { - var nugetBin = nugetRoot + Directory("lib") + Directory("net35"); + var nugetBin = nugetRoot + Directory("lib") + Directory("netstandard2.0"); var squirrelBin = squirrelRoot + Directory("lib") + Directory("net45"); CreateDirectory(nugetBin); CreateDirectory(squirrelBin); @@ -127,6 +120,7 @@ Task("Copy-Files") buildDir + File("Mages.Core.dll"), buildDir + File("Mages.Core.xml") }, nugetBin); + CopyDirectory(replDir, squirrelBin); CopyDirectory(installerDir, squirrelBin); CopyFile("src/Mages.Nuget.nuspec", nugetRoot + File("Mages.nuspec")); CopyFile("src/Mages.Chocolatey.nuspec", chocolateyRoot + File("Mages.nuspec")); @@ -160,7 +154,6 @@ Task("Create-Nuget-Package") Task("Publish-Nuget-Package") .IsDependentOn("Create-Nuget-Package") - .WithCriteria(() => isLocal) .Does(() => { var apiKey = EnvironmentVariable("NUGET_API_KEY"); @@ -217,7 +210,6 @@ Task("Create-Squirrel-Package") Task("Create-Chocolatey-Package") .IsDependentOn("Copy-Files") - .WithCriteria(() => isLocal) .Does(() => { var content = String.Format("$packageName = 'Mages'{1}$installerType = 'exe'{1}$url32 = 'https://github.com/FlorianRappl/Mages/releases/download/v{0}/Mages.exe'{1}$silentArgs = ''{1}{1}Install-ChocolateyPackage \"$packageName\" \"$installerType\" \"$silentArgs\" \"$url32\"", version, Environment.NewLine); var nuspec = chocolateyRoot + File("Mages.nuspec"); @@ -236,7 +228,6 @@ Task("Create-Chocolatey-Package") Task("Publish-Chocolatey-Package") .IsDependentOn("Create-Chocolatey-Package") - .WithCriteria(() => isLocal) .Does(() => { var apiKey = EnvironmentVariable("CHOCOLATEY_API_KEY"); var fileName = "Mages." + version + ".nupkg"; @@ -256,7 +247,6 @@ Task("Publish-Chocolatey-Package") Task("Publish-GitHub-Release") .IsDependentOn("Create-Squirrel-Package") - .WithCriteria(() => isLocal) .Does(() => { var githubToken = EnvironmentVariable("GITHUB_API_TOKEN"); @@ -277,10 +267,10 @@ Task("Publish-GitHub-Release") Name = version, Body = String.Join(Environment.NewLine, releaseNotes.Notes), Prerelease = false, - TargetCommitish = "master" + TargetCommitish = "main" }).Result; - var target = nugetRoot + Directory("lib") + Directory("net35"); + var target = nugetRoot + Directory("lib") + Directory("netstandard2.0"); var libPath = target + File("Mages.Core.dll"); var releaseFiles = GetFiles(releaseDir.Path.FullPath + "/*"); @@ -305,13 +295,6 @@ Task("Publish-GitHub-Release") } }); -Task("Update-AppVeyor-Build-Number") - .WithCriteria(() => isRunningOnAppVeyor) - .Does(() => - { - AppVeyor.UpdateBuildVersion(version); - }); - // Targets // ---------------------------------------- @@ -322,16 +305,18 @@ Task("Package") .IsDependentOn("Create-Nuget-Package"); Task("Default") - .IsDependentOn("Package"); + .IsDependentOn("Package"); -Task("Publish") +Task("Publish-Packages") .IsDependentOn("Publish-Nuget-Package") .IsDependentOn("Publish-GitHub-Release") .IsDependentOn("Publish-Chocolatey-Package"); - -Task("AppVeyor") - .IsDependentOn("Run-Unit-Tests") - .IsDependentOn("Update-AppVeyor-Build-Number"); + +Task("Publish") + .IsDependentOn("Publish-Packages"); + +Task("PrePublish") + .IsDependentOn("Publish-Packages"); // Execution // ---------------------------------------- diff --git a/src/Mages.Core.Tests/Mages.Core.Tests.csproj b/src/Mages.Core.Tests/Mages.Core.Tests.csproj index 8807365a..f94b2be3 100644 --- a/src/Mages.Core.Tests/Mages.Core.Tests.csproj +++ b/src/Mages.Core.Tests/Mages.Core.Tests.csproj @@ -9,6 +9,7 @@ x64 + true @@ -24,6 +25,7 @@ + all diff --git a/src/Mages.Core/Mages.Core.csproj b/src/Mages.Core/Mages.Core.csproj index 96d4b1b8..90afba69 100644 --- a/src/Mages.Core/Mages.Core.csproj +++ b/src/Mages.Core/Mages.Core.csproj @@ -4,5 +4,6 @@ Mages.Core Mages.Core A lightweight parser / interpreter for mathematical expressions. + Mages.Core.xml \ No newline at end of file diff --git a/src/Mages.Core/Mages.Core.xml b/src/Mages.Core/Mages.Core.xml new file mode 100644 index 00000000..842e4ca1 --- /dev/null +++ b/src/Mages.Core/Mages.Core.xml @@ -0,0 +1,4920 @@ + + + + Mages.Core + + + + + Represents an abstract (compile-time) scope information. + + + + + Creates a new abstract scope. + + The parent scope to use, if any. + + + + Gets the parent scope. + + + + + The class for an argument expression. + + + + + Creates new arguments expression. + + + + + Gets the stored arguments. + + + + + Gets the number of arguments. + + + + + Accepts the visitor by showing him around. + + The visitor walking the tree. + + + + Validates the expression with the given context. + + The validator to report errors to. + + + + Represents an expression that can be assigned. + + + + + Creates a new assignable expression. + + + + + Gets if the expression is assignable. + + + + + Represents an assignment expression. + + + + + Creates a new assignment expression. + + + + + Gets the variable (value on the left side). + + + + + Gets the variable name, if any. + + + + + Gets the value on the right side. + + + + + Accepts the visitor by showing him around. + + The visitor walking the tree. + + + + Validates the expression with the given context. + + The validator to report errors to. + + + + Represents a future wrapper. + + + + + Creates a new await expression. + + + + + Gets the carried payload to be awaited. + + + + + Accepts the visitor by showing him around. + + The visitor walking the tree. + + + + Validates the expression with the given context. + + The validator to report errors to. + + + + Represents the shared core of all expressions. + + + + + Creates a new expression. + + + + + Gets the start position of the expression. + + + + + Gets the end position of the expression. + + + + + The base class for all binary expressions. + + + + + Creates a new binary expression. + + + + + Gets the value on the left side. + + + + + Gets the value on the right side. + + + + + Gets the associated operator string. + + + + + Accepts the visitor by showing him around. + + The visitor walking the tree. + + + + Validates the expression with the given context. + + The validator to report errors to. + + + + Represents a function call. + + + + + Creates a new function call expression. + + + + + Gets the associated function. + + + + + Gets the arguments to pass to the function. + + + + + Accepts the visitor by showing him around. + + The visitor walking the tree. + + + + Validates the expression with the given context. + + The validator to report errors to. + + + + Represents a computed expression (not-assignable). + + + + + Creates a new computing expression. + + + + + Gets if the expression is assignable. + + + + + Represents a conditional expression. + + + + + Creates a new conditional expression. + + + + + Gets the condition. + + + + + Gets the primary selected value. + + + + + Gets the alternative selected value. + + + + + Accepts the visitor by showing him around. + + The visitor walking the tree. + + + + Validates the expression with the given context. + + The validator to report errors to. + + + + Represents a constant (predefined value) expression. + + + + + Creates a new constant expression for the given value. + + + + + Gets the carried value. + + + + + Accepts the visitor by showing him around. + + The visitor walking the tree. + + + + Creates a new constant expression carrying the given object. + + The value to carry. + The range that is covered. + The constant expression. + + + + Validates the expression with the given context. + + The validator to report errors to. + + + + Represents a delete expression. + + + + + Creates a new delete statement with the given payload. + + The start position. + The payload to transport. + + + + Gets the stored payload. + + + + + Accepts the visitor by showing him around. + + The visitor walking the tree. + + + + Validates the expression with the given context. + + The validator to report errors to. + + + + Represents an empty expression (potentially invalid). + + + + + Creates a new empty expression. + + + + + Accepts the visitor by showing him around. + + The visitor walking the tree. + + + + Validates the expression with the given context. + + The validator to report errors to. + + + + Represents a function expression. + + + + + Creates a new function expression. + + + + + Gets the associated abstract scope. + + + + + Gets the defined parameters. + + + + + Gets the body to use. + + + + + Accepts the visitor by showing him around. + + The visitor walking the tree. + + + + Validates the expression with the given context. + + The validator to report errors to. + + + + Represents a generalized identifier, which is not a variable. + + + + + Creates a new identifier expression. + + + + + Gets the name of the identifier. + + + + + Accepts the visitor by showing him around. + + The visitor walking the tree. + + + + Validates the expression with the given context. + + The validator to report errors to. + + + + Represents an interpolated string expression. + + + + + Creates a new interpolated string expression. + + + + + Gets the formatting string. + + + + + Gets the associated replacements. + + + + + Accepts the visitor by showing him around. + + The visitor walking the tree. + + + + Validates the expression with the given context. + + The validator to report errors to. + + + + Represents an invalid expression. + + + + + Creates a new invalid expression. + + + + + Gets the payload covered by the container. + + + + + Gets the associated error code. + + + + + Accepts the visitor by showing him around. + + The visitor walking the tree. + + + + Validates the expression with the given context. + + The validator to report errors to. + + + + Represents a matrix expression. + + + + + Creates a new matrix expression. + + + + + Gets the initialized values. + + + + + Accepts the visitor by showing him around. + + The visitor walking the tree. + + + + Validates the expression with the given context. + + The validator to report errors to. + + + + Represents a member expression. + + + + + Creates a new member expression. + + + + + Gets the associated object expression. + + + + + Gets the associated member access. + + + + + Accepts the visitor by showing him around. + + The visitor walking the tree. + + + + Validates the expression with the given context. + + The validator to report errors to. + + + + Represents an object literal. + + + + + Creates a new object expression. + + + + + Gets the contained expressions. + + + + + Accepts the visitor by showing him around. + + The visitor walking the tree. + + + + Validates the expression with the given context. + + The validator to report errors to. + + + + Represents an expression containing function parameters. + + + + + Creates a new parameter expression. + + + + + Gets the contained expressions. + + + + + Gets the available parameter names. + + + + + Accepts the visitor by showing him around. + + The visitor walking the tree. + + + + Validates the expression with the given context. + + The validator to report errors to. + + + + Base class for all post unary expressions. + + + + + Creates a new post unary expression. + + + + + Gets the used value. + + + + + Gets the operator string. + + + + + Accepts the visitor by showing him around. + + The visitor walking the tree. + + + + Validates the expression with the given context. + + The validator to report errors to. + + + + Base class for all pre unary expressions. + + + + + Creates a new pre unary expression. + + + + + Gets the used value. + + + + + Gets the operator string. + + + + + Accepts the visitor by showing him around. + + The visitor walking the tree. + + + + Validates the expression with the given context. + + The validator to report errors to. + + + + Represents a property (name-value pair) of an object. + + + + + Creates a new property. + + + + + Gets the name of the property. + + + + + Gets the value of the property. + + + + + Accepts the visitor by showing him around. + + The visitor walking the tree. + + + + Validates the expression with the given context. + + The validator to report errors to. + + + + The range expression. + + + + + Creates a new range expression. + + + + + Gets the from expression. + + + + + Gets the to expression. + + + + + Gets the step expression. + + + + + Accepts the visitor by showing him around. + + The visitor walking the tree. + + + + Validates the expression with the given context. + + The validator to report errors to. + + + + Represents the access of a variable. + + + + + Creates a new variable expression. + + + + + Gets the name of the variable. + + + + + Gets the assigned abstract scope. + + + + + Accepts the visitor by showing him around. + + The visitor walking the tree. + + + + Validates the expression with the given context. + + The validator to report errors to. + + + + An abstract expression from the AST. + + + + + Gets if the expression can be used as a value container. + + + + + Represents the core parser interface. + + + + + Parses the next expression. + + The stream of tokens. + The parsed expression. + + + + Parses the next statement. + + The stream of tokens. + The parsed statement. + + + + Parse the next statements. + + The stream of tokens. + The parsed statements. + + + + An abstract statement from the AST. + + + + + Represents a syntax tree walker. + + + + + Visits the given statement. + + Variable statement. + + + + Visits the given statement. + + Block statement. + + + + Visits the given statement. + + Simple statement. + + + + Visits the given statement. + + Return statement. + + + + Visits the given statement. + + While statement. + + + + Visits the given statement. + + For statement. + + + + Visits the given statement. + + If statement. + + + + Visits the given statement. + + Match statement. + + + + Visits the given statement. + + Case statement. + + + + Visits the given statement. + + Continue statement. + + + + Visits the given statement. + + Break statement. + + + + Visits the given expression. + + Empty expression. + + + + Visits the given expression. + + Constant expression. + + + + Visits the given expression. + + Interpolated expression. + + + + Visits the given expression. + + Arguments expression. + + + + Visits the given expression. + + Assignment expression. + + + + Visits the given expression. + + Binary expression. + + + + Visits the given expression. + + Pre-unary expression. + + + + Visits the given expression. + + Post-unary expression. + + + + Visits the given expression. + + Range expression. + + + + Visits the given expression. + + Conditional expression. + + + + Visits the given expression. + + Call expression. + + + + Visits the given expression. + + Object expression. + + + + Visits the given expression. + + Property expression. + + + + Visits the given expression. + + Matrix expression. + + + + Visits the given expression. + + Function expression. + + + + Visits the given expression. + + Invalid expression. + + + + Visits the given expression. + + Identifier expression. + + + + Visits the given expression. + + Member expression. + + + + Visits the given expression. + + Parameter expression. + + + + Visits the given expression. + + Variable expression. + + + + Visits the given expression. + + Delete expression. + + + + Visits the given experssion. + + Await expression. + + + + Represents a part of the AST that can be validated. + + + + + Validates the expression with the given context. + + The validator to report errors to. + + + + Represents the validation context. + + + + + Gets if the current element is nested in a loop. + + + + + Adds an error to the validation context. + + The error to add. + + + + Represents a part of the AST that can be walked. + + + + + Accepts the visitor by showing him around. + + The visitor walking the tree. + + + + A set of useful extensions for parsing. + + + + + Parse the expression given in form of a string. + + The parser. + The code to parse. + The resulting expression. + + + + Parse the statement given in form of a string. + + The parser. + The code to parse. + The resulting statement. + + + + Parse the statements given in form of a string. + + The parser. + The code to parse. + The resulting statements. + + + + A collection of statement extensions. + + + + + Looks for missing symbols in the provided statement. + + The statement. + The found list of missing symbols. + + + + Looks for missing symbols in the provided statements. + + The statements. + The found list of missing symbols. + + + + Converts the given statements to a single block statement. + + The statements. + The single block statement containing all statements. + + + + Collects the missing symbols in the provided statement. + + The statement. + The list of missing symbols to populate. + + + + Transforms the statements to an array of operations. + + The statements. + The operations that can be run. + + + + Checks if the given statement is a simple statement containing + an empty expression. + + The statement. + True if the statement is empty, otherwise false. + + + + Checks if the given expression is an empty expression. + + The expression. + True if the expression is empty, otherwise false. + + + + Gets the list of possible completions at the given position. + + The statements. + The position to look for completions. + The existing global symbols. + The list of completions for the given position. + + + + Represents the shared core of all statements. + + + + + Creates a new statement. + + + + + Gets the start position of the statement. + + + + + Gets the end position of the statement. + + + + + Represents a block of statements. + + + + + Creates a new block statement. + + + + + Gets the contained statements. + + + + + Validates the expression with the given context. + + The validator to report errors to. + + + + Accepts the visitor by showing him around. + + The visitor walking the tree. + + + + Represents a breakable statement. + + + + + Creates a new breakable statement. + + The body to use. + The start position. + The end position. + + + + Gets the stored body. + + + + + Validates the expression with the given context. + + The validator to report errors to. + + + + Represents a break statement. + + + + + Creates a new break statement with the given payload. + + The payload. + The start position. + The end position. + + + + Accepts the visitor by showing him around. + + The visitor walking the tree. + + + + Validates the expression with the given context. + + The validator to report errors to. + + + + Represents an case statement. + + + + + Creates a new case statement. + + + + + Gets the stored condition. + + + + + Accepts the visitor by showing him around. + + The visitor walking the tree. + + + + Represents a continue statement. + + + + + Creates a new continue statement with the given payload. + + The payload. + The start position. + The end position. + + + + Accepts the visitor by showing him around. + + The visitor walking the tree. + + + + Validates the expression with the given context. + + The validator to report errors to. + + + + Represents a for statement. + + + + + Creates a new for statement. + + + + + Gets if the initialization variable is declared. + + + + + Gets the stored initialization. + + + + + Gets the stored condition. + + + + + Gets the stored after thought. + + + + + Accepts the visitor by showing him around. + + The visitor walking the tree. + + + + Represents an if statement. + + + + + Creates a new if statement. + + + + + Gets the stored condition. + + + + + Gets the primary statement. + + + + + Gets the secondary statement. + + + + + Accepts the visitor by showing him around. + + The visitor walking the tree. + + + + Validates the expression with the given context. + + The validator to report errors to. + + + + Represents an match statement. + + + + + Creates a new match statement. + + + + + Gets the stored reference. + + + + + Gets the associated cases. + + + + + Accepts the visitor by showing him around. + + The visitor walking the tree. + + + + Validates the expression with the given context. + + The validator to report errors to. + + + + Represents a return statement. + + + + + Creates a new return statement with the given payload. + + The payload to transport. + The start position. + The end position. + + + + Gets the stored payload. + + + + + Accepts the visitor by showing him around. + + The visitor walking the tree. + + + + Validates the expression with the given context. + + The validator to report errors to. + + + + Represents a simple statement containing an expression. + + + + + Creates a new simple statement. + + + + + Gets the contained expression. + + + + + Validates the expression with the given context. + + The validator to report errors to. + + + + Accepts the visitor by showing him around. + + The visitor walking the tree. + + + + Represents a "var ...;" statement. + + + + + Creates a new var statement. + + + + + Gets the associated assignment. + + + + + Validates the expression with the given context. + + The validator to report errors to. + + + + Accepts the visitor by showing him around. + + The visitor walking the tree. + + + + Represents a while statement. + + + + + Creates a new while statement. + + + + + Gets the stored condition. + + + + + Accepts the visitor by showing him around. + + The visitor walking the tree. + + + + A basic tree walker to focus on what's really important. + + + + + Visits a var statement - accepts the assignment. + + + + + Visits a block statement - accepts all childs. + + + + + Visits a simple statement - accepts the expression. + + + + + Visits a return statement - accepts the payload. + + + + + Visits a delete expression - accepts the payload. + + + + + Visits a while statement - accepts the condition and body. + + + + + Visits a for statement - accepts the initialization, condition, afterthought, and body. + + + + + Visits an if statement - accepts the condition and body. + + + + + Visits a match statement - accepts the condition and body. + + + + + Visits a case statement - accepts the condition and body. + + + + + Visits a continue statement. + + + + + Visits a break statement. + + + + + Visits an empty expression. + + + + + Visits a constant expression. + + + + + Visits an awaitable expression. + + + + + Visits an arguments expression - accepts all arguments. + + + + + Visits an assignment expression - accepts the variable and value. + + + + + Visits a binary expression - accepts the left and right value. + + + + + Visits an interpolated string - accepts the format and replacements. + + + + + Visits a pre-unary expression - accepts the value. + + + + + Visits a post-unary expression - accepts the value. + + + + + Visits a range expression - accepts the from, step. and to. + + + + + Visits a conditional expression - accepts the condition, primary, and secondary. + + + + + Visits a call expression - accepts the function and arguments. + + + + + Visits an object expression - accepts all values. + + + + + Visits a property expression - accepts the name and value. + + + + + Visits a matrix expression - accepts all values. + + + + + Visits a function expression - accepts the parameters and body. + + + + + Visits an invalid expression. + + + + + Visits an identifier expression. + + + + + Visits a member expression - accepts the object and member. + + + + + Visits a parameter expression - accepts all parameters. + + + + + Visits a variable expression. + + + + + Represents the walker to get code completion information. + + + + + Creates a new completition tree walker for the given position. + + + + + Gets the list of autocomplete suggestions. + + + + + Finds the suggestions for the given list of statements. + + The statements to use. + + + + Visits a block statement - accepts all childs. + + + + + Visits a var statement - accepts the assignment. + + + + + Visits a simple statement - accepts the expression. + + + + + Visits an empty expression. + + + + + Visits an invalid expression. + + + + + Visits an assignment expression - accepts the variable and value. + + + + + Visits a function expression - accepts the parameters and body. + + + + + Visits a parameter expression - accepts all parameters. + + + + + Visits a property expression - accepts the name and value. + + + + + Visits a variable expression. + + + + + Visits a member expression. + + + + + Represents the walker to create operations. + + + + + Creates a new operation tree walker. + + The list of operations to populate. + + + + Represents the walker to serialize the AST. + + + + + Creates a new serialization tree walker. + + The destination to write to. + + + + Represents the walker to gather symbol information. + + + + + Creates a new symbol tree walker. + + + + + Creates a new symbol tree walker with a missing symbols collector. + + The target for missing symbols. + + + + Creates a new symbol tree walker with a new general and missing symbols collector. + + The target for general symbol information. + The target for missing symbols. + + + + Gets the found potentially missing symbols. + + + + + Gets the found resolved symbols. + + + + + Finds all references of the given symbol. + + The variable to get references for. + The list of all references of the variable. + + + + Visits the assignment expression. + + + + + Visits the function expression. + + + + + Visits the variable expression. + + + + + Represents the walker to validate the AST. + + + + + Creates a new validation tree walker with the list of errors + to populate. + + The list to populate. + + + + Represents the configuration DTO. + + + + + Gets or sets the parser to use. + + + + + Gets or sets the scope to use. + + + + + Gets or sets of a global 'this' referencing the scope should be created. + + + + + Gets or sets if the eval function is disallowed. + + + + + Gets or sets if the engine itself is exposed. + + + + + Represents the central engine for any kind of evaluation. + + + + + Creates a new engine with the specified configuration. Otherwise a + default configuration is used. + + The configuration to use. + + + + Gets the used parser instance. + + + + + Gets the used global scope. + + + + + Gets the used global function layer. + + + + + Gets the version of the engine. + + + + + Gets the currently loaded plugins. + + + + + Adds the given plugin to the list of plugins. + + The plugin to add. + + + + Removes the plugin from the list of plugins. + + The plugin to remove. + + + + Compiles the given source and returns a function to execute later. + + The source to compile. + The function to invoke later. + + + + Interprets the given source and returns the result, if any. + + The source to interpret. + The result if available, otherwise null. + + + + A collection of useful extensions for the engine. + + + + + Adds or replaces a function with the given name to the function layer. + + The engine. + The name of the function to add or replace. + The function to be integrated. + + + + Adds or replaces a function represented as a general delegate by wrapping + it as a function with the given name. + + The engine. + The name of the function to add or replace. + The function to be wrapped. + + + + Adds or replaces a function represented as a reflected method info by + wrapping it as a function with the given name. + + The engine. + The name of the function to add or replace. + The function to be wrapped. + The optional target object of the method. + + + + Adds or replaces an object represented as the MAGES primitive. This is + either directly the given value or a wrapper around it. + + The engine. + The name of the constant to add or replace. + The value to interact with. + + + + Exposes all static methods and the type's constructors in the object + that can be freely placed. + + The type to expose. + The engine. + + + + Exposes all static methods and the type's constructors in the object + that can be freely placed. + + The engine. + The type to expose. + + + + Exposes all types in the assembly that satisfy the optional condition + in an object that can be freely placed. + + The engine. + The library containing the types to expose. + The optional inclusion checker. + + + + Exposes all types in an object that can be freely placed. Here no + default name is given. + + The engine. + The types to include. + + + + Finds the missing symbols (if any) in the given source. + + The engine. + The source code to inspect. + The variable expressions pointing to the missing symbols. + + + + Interprets the given source and returns the result in form of a future. + + The engine. + The source to interpret. + The result in form of a future. Any callbacks will be aggregated here. + + + + Adds a plugin from the given type. This requires that the type represents a + static class that ends with "Plugin". Meta-data is given in form of public + static string fields, while static properties and methods are considered + content. + + The engine. + The type to represent as a plugin. + The plugin if any. + + + + Adds all plugins found in the given assembly. + + The engine. + The assembly to investigate. + The list with all added plugins. + + + + Gets the currently stored global symbols. + + The engine containing the global symbols. + The enumeration over all global symbols. + + + + Gets the currently stored global items, i.e., key-value pairs. + + The engine containing the global scope. + The dictionary with all global items. + + + + Looks up for completion at the given index in the provided source. + + The engine. + The source code to use as basis. + The index where the cursor is. + The enumeration over potential completion symbols. + + + + A list of possible parsing error codes. + + + + + See description. + + + + + See description. + + + + + See description. + + + + + See description. + + + + + See description. + + + + + See description. + + + + + See description. + + + + + See description. + + + + + See description. + + + + + See description. + + + + + See description. + + + + + See description. + + + + + See description. + + + + + See description. + + + + + See description. + + + + + See description. + + + + + See description. + + + + + See description. + + + + + See description. + + + + + See description. + + + + + See description. + + + + + See description. + + + + + See description. + + + + + See description. + + + + + See description. + + + + + See description. + + + + + See description. + + + + + See description. + + + + + See description. + + + + + See description. + + + + + See description. + + + + + See description. + + + + + See description. + + + + + See description. + + + + + See description. + + + + + See description. + + + + + See description. + + + + + See description. + + + + + See description. + + + + + See description. + + + + + Defines the function delegate. + + The arguments to pass in. + The result of the evaluation. + + + + A set of useful extensions for functions. + + + + + Calls the function with the given arguments. + + The function. + The arguments to supply. + The result of calling the function. + + + + Calls the function with the given arguments. + + The anticipated result type. + The function. + The arguments to supply. + The result or the type's default value. + + + + Gets the names of the parameters of the function. + + The function to inspect. + The array with parameter names. + + + + Determines the placement of objects in the global scope. + + + + + Placed with the given name. + + The name to use. + + + + Placed with the default name. + + + + + The children of the object are placed in the scope. + + + + + Represents a range of characters within the source code. + + + + + Gets the start position of the token. + + + + + Gets the end position of the token. + + + + + Contains all the reserved keywords. + + + + + The true keyword. + + + + + The false keyword. + + + + + The pi constant. + + + + + The var keyword. + + + + + The return keyword. + + + + + The let keyword. + + + + + The const keyword. + + + + + The for keyword. + + + + + The while keyword. + + + + + The do keyword. + + + + + The module keyword. + + + + + The if keyword. + + + + + The else keyword. + + + + + The break keyword. + + + + + The continue keyword. + + + + + The yield keyword. + + + + + The match keyword. + + + + + The async keyword. + + + + + The await keyword. + + + + + The class keyword. + + + + + The static keyword. + + + + + The new keyword. + + + + + The delete keyword. + + + + + Gets the globally available statement keywords. + + + + + Gets the within-loop available statement keywords. + + + + + Gets the available expression keywords. + + + + + Tries to get the constant's value. + + The name of the constant. + The value of the constant. + True if the constant could be resolved, otherwise false. + + + + Checks if the given identifier is actually a keyword. + + The identifier to check. + True if the identifier is a keyword, otherwise false. + + + + Represents the definition of a function parameter. + + + + + Creates a new parameter definition. + + + + + Gets the name of the parameter. + + + + + Gets if the parameter is required. + + + + + Gets the hash code. + + + + + Checks for equality to the other object. + + + + + Checks for equality to the other parameter definition. + + + + + A class to encapsulate data of a parse error. + + + + + Creates a new parse error object with these properties. + + The code of the error. + The text range of the error. + + + + Gets the start position of the error. + + + + + Gets the end position of the error. + + + + + Gets the code of the error. + + + + + Represents the exception that is thrown on trying + to interpret invalid code. + + + + + Creates a new parse exception. + + The error that occured. + + + + Gets the detected parse error. + + + + + Defines the plugin essentials. + + + + + Creates a new plugin. + + + + + Gets the name of the plugin. + + + + + Gets the plugin's meta data. + + + + + Gets the plugin's content. + + + + + A global accessible container for engine-independent services. + + + + + Registers the specified service in the container. + + The type of service to set. + The service to register. + The optional lifetime controlling instance. + + + + Unregisters the specified service from the container. + + The type of service to remove. + The service to remove. + True if the service was removed, otherwise false. + + + + Unregisters the specified service from the container. + + The type of service to remove. + The removed services, if any. + + + + Tries to get the specified service from the container. + + The type of service to get. + The optional default instance. + The service or a default instance. + + + + Tries to get the specified services from the container. + + The type of service to get. + The services. + + + + A set of useful extension methods for type conversions. + + + + + Returns the type of the given value. + + The value to get the type of. + The MAGES type string. + + + + Converts the given value to the specified type. + + The type to convert. + The destination type. + The converted value. + + + + Returns the boolean representation of the given value. + + The value to convert. + The boolean representation of the value. + + + + Returns the boolean representation of the given numeric value. + + The value to convert. + The boolean representation of the value. + + + + Returns the boolean representation of the given string value. + + The value to convert. + The boolean representation of the value. + + + + Returns the boolean representation of the given matrix value. + + The matrix to convert. + The boolean representation of the value. + + + + Returns the boolean representation of the given object value. + + The obj to convert. + The boolean representation of the value. + + + + Returns the object representation of the given value. + + The value to convert. + The object representation of the value. + + + + Returns the number representation of the given value. + + The value to convert. + The number representation of the value. + + + + Returns the number representation of the given boolean value. + + The value to convert. + The number representation of the value. + + + + Returns the number representation of the given string value. + + The value to convert. + The number representation of the value. + + + + Returns the number representation of the given matrix value. + + The matrix to convert. + The number representation of the value. + + + + Returns the matrix representation of the given number value. + + The value to convert. + The matrix representation of the value. + + + + Returns the matrix representation of the given boolean value. + + The value to convert. + The matrix representation of the value. + + + + Returns the matrix representation of the given numeric values. + + The value to convert. + The matrix representation of the value. + + + + Returns the matrix representation of the given numeric values. + + The value to convert. + The matrix representation of the value. + + + + Returns the vector representation of the given matrix value. + + The matrix to convert. + The matrix representation of the value. + + + + Returns the list representation of the given matrix value. + + The matrix to convert. + The list representation of the value. + + + + Tries to get the index supplied from the given object. + + The object to convert. + The retrieved index. + True if the index could be retrieved, otherwise false. + + + + Represents the interface to handle name selections. + + + + + Selects a name for the given member. + + The already registered names. + The member to give a MAGES name. + The selected name. + + + + Contains the event data for changes observed in a dictionary. + + + + + Creates a new event data container. + + + + + Gets the key that changed. + + + + + Gets the previously assigned value, if any. + + + + + Gets the currently assigned value, if any. + + + + + The collection of all attached properties. + + + + + Registers the provided attached property. + + The type of the object to extend. + The name of the property to attach. + The getter function to register. + + + + Unregisters the provided attached property. + + The type of the object to extend. + The name of the property to detach. + + + + Tries to find the value for the attached property. + + The object context. + The name of the property to retrieve. + The potentially attached property value. + True if the attached property could be found, otherwise false. + + + + Provide helpers to enable currying. + + + + + Checks if the provided args deliver at least one argument. + Otherwise returns null. + + The function to return or capture. + The args to check and potentially capture. + A curried function or null. + + + + Checks if the provided args deliver at least two arguments. + Otherwise returns null. + + The function to return or capture. + The args to check and potentially capture. + A curried function or null. + + + + Checks if the provided args deliver at least three arguments. + Otherwise returns null. + + The function to return or capture. + The args to check and potentially capture. + A curried function or null. + + + + Checks if the provided args deliver at least count argument(s). + Otherwise returns null. + + The required number of arguments. + The function to return or capture. + The args to check and potentially capture. + A curried function or null. + + + + Creates a function that shuffles the arguments of a given function + according to the current arguments. + + The arguments to create the shuffle function. + The created shuffle function. + + + + Helpers to check for argument types. + + + + + Checks if the first value of the given arguments is of type T. + + The type T to check for. + The arguments to check. + The callback to invoke if fulfilled. + The result of the callback or null. + + + + Checks if the first two values of the given arguments are of type + T1 and T2. + + The type of the first value. + The type of the second value. + The arguments to check. + The callback to invoke if fulfilled. + The result of the callback or null. + + + + Checks if the first three values of the given arguments are of type + T1, T2, and T3. + + The type of the first value. + The type of the second value. + The type of the third value. + The arguments to check. + The callback to invoke if fulfilled. + The result of the callback or null. + + + + Checks if the first four values of the given arguments are of type + T1, T2, T3, and T4. + + The type of the first value. + The type of the second value. + The type of the third value. + The type of the fourth value. + The arguments to check. + The callback to invoke if fulfilled. + The result of the callback or null. + + + + Checks if the first three values of the given arguments are of type + T1, anything, and T3. + + The type of the first value. + The type of the third value. + The arguments to check. + The callback to invoke if fulfilled. + The result of the callback or null. + + + + Checks if the provided args are all non-null. Performs the conversion and invokes + the result if successful. + + The type after the conversion. + The arguments to check. + The converter to use. + The result function to use. + The result or null if the check was not successful. + + + + Defines a procedure to set values. + + The index arguments. + The value to set. + + + + The collection of all standard functions. + + + + + Exposes the + operator as a function. + + + + + Exposes the - operator as a function. + + + + + Exposes the * operator as a function. + + + + + Exposes the / operator as a function. + + + + + Exposes the \ operator as a function. + + + + + Exposes the ^ operator as a function. + + + + + Exposes the % operator as a function. + + + + + Exposes the && operator as a function. + + + + + Exposes the || operator as a function. + + + + + Exposes the == operator as a function. + + + + + Exposes the != operator as a function. + + + + + Exposes the > operator as a function. + + + + + Exposes the >= operator as a function. + + + + + Exposes the < operator as a function. + + + + + Exposes the <= operator as a function. + + + + + Exposes the | operator as a function. + + + + + Exposes the ~ operator as a function. + + + + + Exposes the + operator as a function. + + + + + Exposes the - operator as a function. + + + + + Exposes the ! operator as a function. + + + + + Exposes the ' operator as a function. + + + + + Wraps the Math.Abs function. + + + + + Exposes the & operator as a function. + + + + + Wraps the Math.Sqrt function. + + + + + Wraps the Math.Sign function. + + + + + Contains the gamma function. + + + + + Wraps the Math.Ceiling function. + + + + + Wraps the Math.Floor function. + + + + + Wraps the Math.Round function. + + + + + Wraps the Math.Exp function. + + + + + Wraps the Math.Log function. + + + + + Wraps the Math.Sin function. + + + + + Wraps the Math.Cos function. + + + + + Wraps the Math.Tan function. + + + + + Contains the cot function. + + + + + Contains the sec function. + + + + + Contains the csc function. + + + + + Wraps the Math.Sinh function. + + + + + Wraps the Math.Cosh function. + + + + + Wraps the Math.Tanh function. + + + + + Contains the coth function. + + + + + Contains the sech function. + + + + + Contains the csch function. + + + + + Wraps the Math.Asin function. + + + + + Wraps the Math.Acos function. + + + + + Wraps the Math.Atan function. + + + + + Contains the arccot function. + + + + + Contains the asec function. + + + + + Contains the acsc function. + + + + + Contains the arsinh function. + + + + + Contains the arcosh function. + + + + + Contains the artanh function. + + + + + Contains the arcoth function. + + + + + Contains the asech function. + + + + + Contains the acsch function. + + + + + Contains the random function. + + + + + Contains the throw function. + + + + + Contains the catch function. + + + + + Contains the length function. + + + + + Contains the sum function. + + + + + Wraps the Math.Min function. + + + + + Wraps the Math.Max function. + + + + + Wraps the Enumerable.OrderBy function. + + + + + Wraps the Enumerable.Reverse function. + + + + + Wraps the Double.IsNaN function. + + + + + Contains the is integer function. + + + + + Contains the is prime function. + + + + + Wraps the Double.IsInfinity function. + + + + + Contains the any function. + + + + + Contains the all function. + + + + + Contains the is function. + + + + + Contains the as function. + + + + + Contains the list function. + + + + + Contains the keys function. + + + + + Contains the map function. + + + + + Contains the reduce function. + + + + + Contains the where function. + + + + + Contains the zip function. + + + + + Contains the concat function. + + + + + Contains the intersection function. + + + + + Contains the union function. + + + + + Contains the except function. + + + + + Wraps the String.Format function. + + + + + Contains the hasKey function. + + + + + Contains the getValue function. + + + + + Contains the shuffle function. + + + + + Contains the regex function. + + + + + Contains the clip function. + + + + + Contains the clamp function. + + + + + Contains the lerp function. + + + + + The collection of all standard operators. + + + + + Contains the add operator. + + + + + Contains the and operator. + + + + + Contains the left division operator. + + + + + Contains the modulo operator. + + + + + Contains the multiplication operator. + + + + + Contains the or operator. + + + + + Contains the power operator. + + + + + Contains the right division operator. + + + + + Contains the subtraction operator. + + + + + Contains the equality operator. + + + + + Contains the not equals operator. + + + + + Contains the greater or equals operator. + + + + + Contains the greater than operator. + + + + + Contains the less or equals operator. + + + + + Contains the less than operator. + + + + + Contains the pipe operator. + + + + + Contains the factorial function. + + + + + Contains the transpose operator. + + + + + Contains the negation operator. + + + + + Contains the positive operator. + + + + + Contains the negative operator. + + + + + Wraps the Math.Abs function. + + + + + Contains the type operator. + + + + + The collection of all type function creators. + + + + + Registers the provided getter function. + + The type of the object to extend. + The getter function to register. + + + + Unregisters the type function for the given type. + + The type of object to unconfigure. + + + + Tries to find the named getter. + + The object context. + The potentially found getter function. + True if the getter could be found, otherwise false. + + + + The collection of all type function creators. + + + + + Registers the provided setter procedure. + + The type of the object to extend. + The setter function to register. + + + + Unregisters the type function for the given type. + + The type of object to unconfigure. + + + + Tries to find the named setter. + + The object context. + The potentially found setter procedure. + True if the setter could be found, otherwise false. + + + + Represents an awaitable object definition. + + + + + Creates a new future object. + + + + + Gets if the result is already present. + + + + + Gets the result, if any. + + + + + Gets the error message, if any. + + + + + Sets the result in case of success. + + The concrete result, if any. + + + + Sets the error message in case of failure. + + The specific error message. + + + + Sets the callback to notify once finished. This function + is immediately called if the result is already determined. + + The callback action. + + + + Represents the observable dictionary from MAGES. + + + + + Fired once an element is added, removed, or updated. + + + + + Creates a new observable dictionary with a standard container. + + + + + Creates a new observable dictionary with the given container. + + + + + Gets the used container. + + + + + Gets or sets the value at key. + + + + + Gets the number of items stored in the container. + + + + + Adds the given key, value pair to the container. + + + + + Resets the container. + + + + + Removes the given key from the container. + + + + + Tries to get the value at the given key. + + + + + Called after something changed. + + The name of the changed entry. + The entry's previous value. + The entry's new value. + + + + Helpers to stringify objects used by MAGES. + + + + + Contains the stringify function. + + + + + Contains the JSON function. + + + + + Converts the number to a string. + + + + + Converts the boolean to a string. + + + + + Converts the string for output. + + + + + Converts the matrix to a string. + + + + + Converts the object to a string. + + + + + Converts the function to a string. + + + + + Outputs the string for an undefined (null?) value. + + + + + + Converts the undetermined value to a string. + + + + + Converts the given MAGES object to a JSON string. + + The object to represent. + The JSON representation. + + + + Converts the given string object to a JSON string. + + The string to represent. + The JSON representation. + + + + Converts the given matrix to a JSON string. + + The matrix to represent. + The JSON representation. + + + + Represents the object wrapper from MAGES. + + + + + Creates a new wrapped instance object. + + The object to wrap. + + + + Creates a new wrapped static object. + + The type to wrap. + + + + Creates a wrapper object for the given value. + + The value to inspect. + The wrapper or null dependent on the value. + + + + Gets the wrapped object if instance bound. + + + + + Gets the type that is wrapped (instance or static). + + + + + Gets or sets the value of the underlying object or + the extension object. + + The name of the property. + The value of the property. + + + + Gets the number of properties of the underlying + object and the extension object. + + + + + Gets all the keys from the extension object. + + + + + Gets all the values from the extension object. + + + + + Sets the provided value at the provided property. + + The name of the property. + The value to use. + + + + Resets the extension object. + + + + + Checks if the underlying object or the extension + object contains the given key. + + The item to check for. + True if the key is used, otherwise false. + + + + Checks if the underlying object or the extension + object contains the given key. + + The key to check for. + True if the key is used, otherwise false. + + + + Gets the enumerator over the elements of the extension. + + The extension's enumerator. + + + + Removes the item from the extension. + + The key of the item to be removed. + True if it could be removed, otherwise false. + + + + Tries to get the value from the given key. + + The name of the property. + The resulting value. + True if the value could be retrieved, otherwise false. + + + + A set of special characters. + + + + + The end of file Character -1. + + + + + The tilde Character (~). + + + + + The pipe Character (|). + + + + + The null Character. + + + + + The ampersand Character (&). + + + + + The number sign Character (#). + + + + + The dollar sign Character ($). + + + + + The semicolon sign (;). + + + + + The asterisk Character (*). + + + + + The equals sign (=). + + + + + The comma Character (,). + + + + + The full stop (.). + + + + + The circumflex accent (^) Character. + + + + + The commercial at (@) Character. + + + + + The opening angle bracket (LESS-THAN-SIGN). + + + + + The closing angle bracket (GREATER-THAN-SIGN). + + + + + The single quote / quotation mark ('). + + + + + The (double) quotation mark ("). + + + + + The (curved) quotation mark (`). + + + + + The question mark (?). + + + + + The tab Character. + + + + + The line feed Character. + + + + + The carriage return Character. + + + + + The form feed Character. + + + + + The space Character. + + + + + The slash (solidus, /) Character. + + + + + The backslash (reverse-solidus, \) Character. + + + + + The colon (:) Character. + + + + + The exlamation mark (!) Character. + + + + + The dash (hypen minus, -) Character. + + + + + The plus sign (+). + + + + + The low line (_) Character. + + + + + The percent (%) Character. + + + + + Opening a round bracket (. + + + + + Closing a round bracket ). + + + + + Opening an array bracket [. + + + + + Closing an array bracket ]. + + + + + Opening a scope bracket {. + + + + + Closing a scope bracket }. + + + + + The number 0. + + + + + The number 1. + + + + + The letter E. + + + + + The letter I. + + + + + The letter a. + + + + + The letter b. + + + + + The letter e. + + + + + The letter f. + + + + + The letter i. + + + + + The letter n. + + + + + The letter r. + + + + + The letter t. + + + + + The letter u. + + + + + The letter v. + + + + + The letter x. + + + + + Represents the source code scanner. + + + + + Gets the current character code. + + + + + Gets the current position in the source code. + + + + + Tries to move to the next position. + + True if the next character exists, otherwise false. + + + + Tries to move to the previous position. + + True if the previous character exists, otherwise false. + + + + Gets the position at the given index. + + The linear index in the source. + The corresponding text position. + + + + Specification helpers and extension methods. + + + + + Converts a given character from the hex representation (0-9A-Fa-f) to an integer. + + The character to convert. + The integer value or undefined behavior if invalid. + + + + Determines if the given character is in the given range. + + The character to examine. + The lower bound of the range. + The upper bound of the range. + The result of the test. + + + + Determines if the given character is a uppercase character (A-Z). + + The character to examine. + The result of the test. + + + + Determines if the given character is a lowercase character (a-z). + + The character to examine. + The result of the test. + + + + Determines if the given character is a hexadecimal (0-9a-fA-F). + + The character to examine. + The result of the test. + + + + Gets if the character is actually a (A-Z,a-z) letter. + + The character to examine. + The result of the test. + + + + Gets if the character is actually a name character. + + The character to examine. + The result of the test. + + + + Determines if the given character is a valid character for starting an identifier. + + The character to examine. + The result of the test. + + + + Determines if the given character is a white-space character. + + The character to examine. + The result of the test. + + + + Determines if the given character is a digit (0-9). + + The character to examine. + The result of the test. + + + + A pool for recycled resources. + + + + + Either creates a fresh stringbuilder or gets a (cleaned) used one. + + A stringbuilder to use. + + + + Returns the given stringbuilder to the pool and gets the current + string content. + + The stringbuilder to recycle. + The string that is contained in the stringbuilder. + + + + A number of useful string extensions. + + + + + Transforms the string to a token iterator. + + The string. + The created token iterator. + + + + Gets a scanner to walk through the provided source. + + The string. + The created scanner. + + + + Checks if the source could be considered completed. This is not to + indicate that the source is error free, but at least all open brackets + have their partner. + + The string. + True if the source is completed, otherwise false. + + + + Represents a position within a text source. + + + + + Creates a new text position. + + The row number. + The column number. + The character index. + + + + Gets the row in the source code. + + + + + Gets the column in the source code. + + + + + Gets the index (absolute position) in the source code. + + + + + Compares the index of the left text position against the index of the right text position. + + + + + Compares the index of the left text position against the index of the right text position. + + + + + Compares the index of the left text position against the index of the right text position. + + + + + Compares the index of the left text position against the index of the right text position. + + + + + Compares the index of the left text position against the index of the right text position. + + + + + Compares the index of the left text position against the index of the right text position. + + + + + Checks the types for equality. + + + + + Returns the index of the text position. + + + + + Checks the types for equality. + + + + + Represents a token found by the tokenizer. + + + + + Gets the type of the token. + + + + + Gets the payload of the token. + + + + + Represents the tokenizer performing the lexical analysis. + + + + + Gets the next token from the scanner. + + The token. + + + + The available token types. + + + + + Unknown token type. + + + + + Keyword token. + + + + + Identifier token. + + + + + Number token. + + + + + Interpolated string token. + + + + + String token. + + + + + Round bracket open. + + + + + Round bracket close. + + + + + Square bracket open. + + + + + Square bracket close. + + + + + Curly bracket open. + + + + + Curly bracket close. + + + + + Comma symbol. + + + + + Colon symbol. + + + + + Dot symbol. + + + + + Power operator. + + + + + Right divide operator. + + + + + Left divide operator. + + + + + Multiply operator. + + + + + Modulo operator. + + + + + Factorial operator. + + + + + Add operator. + + + + + Subtract operator. + + + + + Increment operator. + + + + + Decrement operator. + + + + + Or operator. + + + + + And operator. + + + + + Equal operator. + + + + + Not equal operator. + + + + + Less operator. + + + + + Less or equal operator. + + + + + Greater or equal operator. + + + + + Greater operator. + + + + + Negate operator. + + + + + Condition operator. + + + + + Transpose operator. + + + + + Assignment operator. + + + + + Lambda operator. + + + + + Type operator. + + + + + Pipe operator. + + + + + Semicolon symbol. + + + + + EOF. + + + + + Any kind of space symbol. + + + + + Preprocessor token. + + + + + Comment token. + + + + + Assembles the MAGES runtime memory model. + + + + + Creates a new execution context. + + The operations to use. + The global scope to use. + + + + Gets the current position of the execution context. + + + + + Gets the position of the last operation. + + + + + Gets the currently used scope of the execution context. + + + + + Executes the operations. + + + + + Pushes the value onto the stack. + + The value to push. + + + + Pops a value from the stack. + + The last value from the stack. + + + + Extension methods for IExecutionContext instances. + + + + + Stops the execution of the given context. + + The context to stop. + + + + Pauses the execution of the given context. + + The context to pause. + + + + Represents the model of the MAGES VM. + + + + + Gets or sets the position of the previous operation. + + + + + Gets the position of the last operation. + + + + + Gets the currently used execution scope. + + + + + Pushes a new value on the stack. + + The value to push on the stack. + + + + Pops a value from the stack. + + The value that came from the stack. + + + + Represents the core interface of an interpreted operation. + + + + + Invokes the operation from the execution context. + + The current context. + + + + A set of handy helpers for operations. + + + + + Serializes the given operations to a string of instructions. + + The operations to serialize. + The string with the instructions. + + + + Checks if the parameters |Object[]| is less / equal than i by + popping one value from the stack and pushing back two values. + + + + + Assigns the argument at index i by popping two values + from the scope and pushing one value back. + + + + + Populates the local scope with one of the arguments. + + + + + Pops one element from the stack. + + + + + Pops three elements from the stack and pushes one. + + + + + Pushes a constant value on the stack. + + + + + Contains a const operation pushing null on the stack. + + + + + Pops one element from the stack and pushes one element. + + + + + Peeks the top element from the stack. + + + + + Pops one value and tries to remove the key from the object. + Pushes the result on the stack. + + + + + Tries to remove the named variable from the scope and pushes the result + on the stack. + + + + + Takes two elements from the stack and pushes one. + + + + + Takes two elements from the stack and pushes the result. + + + + + Pushes the loaded value on the stack. + + + + + Pops one element from the stack and pushes one element. + + + + + Peeks the top element from the stack. + + + + + Pops three elements from the stack and pushes on element. + + + + + Changes the currently executing position. + + + + + Pushes one new element on the stack. + + + + + Pushes one new element on the stack. + + + + + Pops two elements from the stack and pushes three new element on the stack. + + + + + Pushes one new element on the stack. + + + + + Pops one element from the stack. + + + + + Pops one element from the stack. + + + + + Stops the execution without changing the stack. + + + + + Pops three elements from the stack and pushes one. + + + + + Pops two elements from the stack and pushes one. + + + + + Pops at least two elements from the stack and pushes one. + + + + + Pops three elements from the stack and pushes one. + + + + + Peeks the top element from the stack. + + + + diff --git a/src/Mages.Repl.Installer/Installer.cs b/src/Mages.Repl.Installer/Installer.cs index acab80dc..7739a3c1 100644 --- a/src/Mages.Repl.Installer/Installer.cs +++ b/src/Mages.Repl.Installer/Installer.cs @@ -1,6 +1,7 @@ namespace Mages.Repl.Installer { using System; + using System.Diagnostics; using System.IO; using System.Linq; using System.Security; @@ -54,6 +55,12 @@ public static void RemoveShortcut() } } + public static void Run() + { + var directory = GetInstallDirectory(); + Process.Start(Path.Combine(directory, "mages.exe")); + } + public static String GetInstallDirectory() { return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Mages"); diff --git a/src/Mages.Repl.Installer/Mages.Repl.Installer.csproj b/src/Mages.Repl.Installer/Mages.Repl.Installer.csproj index b0a5eae9..0e2581ab 100644 --- a/src/Mages.Repl.Installer/Mages.Repl.Installer.csproj +++ b/src/Mages.Repl.Installer/Mages.Repl.Installer.csproj @@ -1,19 +1,21 @@ - - - + - Debug - AnyCPU + net45 {2239BDD1-07B4-44B0-A6DB-ED4C69B8797C} Exe Properties Mages.Repl.Installer mages.installer + + v4.5 - 512 - true + + + app.manifest + + AnyCPU true @@ -24,6 +26,7 @@ prompt 4 + AnyCPU pdbonly @@ -33,77 +36,16 @@ prompt 4 - - app.manifest - - - - ..\packages\CommandLineParser.2.0.275-beta\lib\net45\CommandLine.dll - True - - - ..\packages\DeltaCompressionDotNet.1.0.0\lib\net45\DeltaCompressionDotNet.dll - True - - - ..\packages\DeltaCompressionDotNet.1.0.0\lib\net45\DeltaCompressionDotNet.MsDelta.dll - True - - - ..\packages\DeltaCompressionDotNet.1.0.0\lib\net45\DeltaCompressionDotNet.PatchApi.dll - True - - - ..\packages\squirrel.windows.1.4.0\lib\Net45\ICSharpCode.SharpZipLib.dll - True - - - ..\packages\Mono.Cecil.0.9.6.1\lib\net45\Mono.Cecil.dll - True - - - ..\packages\Mono.Cecil.0.9.6.1\lib\net45\Mono.Cecil.Mdb.dll - True - - - ..\packages\Mono.Cecil.0.9.6.1\lib\net45\Mono.Cecil.Pdb.dll - True - - - ..\packages\Mono.Cecil.0.9.6.1\lib\net45\Mono.Cecil.Rocks.dll - True - - - ..\packages\squirrel.windows.1.4.0\lib\Net45\NuGet.Squirrel.dll - True - - - ..\packages\Splat.1.6.2\lib\Net45\Splat.dll - True - - - ..\packages\squirrel.windows.1.4.0\lib\Net45\Squirrel.dll - True - - - - - - - - - - + - - Properties\SharedAssemblyInfo.cs - - - - - - + + + + + + + {F935DC20-1CF0-11D0-ADB9-00C04FD58A0B} @@ -115,23 +57,9 @@ True + - - - - - {027a32f7-4411-4083-aa01-0550eea0e5a3} - Mages.Repl - - - - \ No newline at end of file + diff --git a/src/Mages.Repl.Installer/Program.cs b/src/Mages.Repl.Installer/Program.cs index eb660bad..d399df18 100644 --- a/src/Mages.Repl.Installer/Program.cs +++ b/src/Mages.Repl.Installer/Program.cs @@ -42,7 +42,7 @@ private static void Run(Options options) } else { - Mages.Repl.Program.Run(); + Actions.Run(); } } } diff --git a/src/Mages.Repl.Installer/Properties/AssemblyInfo.cs b/src/Mages.Repl.Installer/Properties/AssemblyInfo.cs deleted file mode 100644 index 16f97582..00000000 --- a/src/Mages.Repl.Installer/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,13 +0,0 @@ -using CommandLine.Text; -using System.Reflection; -using System.Runtime.InteropServices; - -[assembly: AssemblyTitle("Mages.Repl.Installer")] -[assembly: AssemblyDescription("Default Read-Evaluate-Print-Loop for the MAGES parser / interpreter.")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyLicense("The MIT License (MIT)")] -[assembly: AssemblyMetadata("SquirrelAwareVersion", "1")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] -[assembly: ComVisible(false)] -[assembly: Guid("2239bdd1-07b4-44b0-a6db-ed4c69b8797c")] diff --git a/src/Mages.Repl.Installer/packages.config b/src/Mages.Repl.Installer/packages.config deleted file mode 100644 index ef2d5cbc..00000000 --- a/src/Mages.Repl.Installer/packages.config +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/src/Mages.Repl.Tests/Mages.Repl.Tests.csproj b/src/Mages.Repl.Tests/Mages.Repl.Tests.csproj index c129eec1..0551b197 100644 --- a/src/Mages.Repl.Tests/Mages.Repl.Tests.csproj +++ b/src/Mages.Repl.Tests/Mages.Repl.Tests.csproj @@ -9,6 +9,7 @@ x64 + true @@ -24,6 +25,7 @@ + all diff --git a/src/Mages.Repl.Tests/packages.config b/src/Mages.Repl.Tests/packages.config deleted file mode 100644 index df67fa01..00000000 --- a/src/Mages.Repl.Tests/packages.config +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/src/Mages.sln b/src/Mages.sln index 36ad1d1f..91f3466c 100644 --- a/src/Mages.sln +++ b/src/Mages.sln @@ -48,12 +48,12 @@ Global {B0698A2A-BFE9-4568-9055-82302F325452}.Release|Any CPU.Build.0 = Release|Any CPU {77E50520-8C68-460A-B138-3FACEE76F170}.Debug|Any CPU.ActiveCfg = Debug|x64 {77E50520-8C68-460A-B138-3FACEE76F170}.Debug|Any CPU.Build.0 = Debug|x64 - {77E50520-8C68-460A-B138-3FACEE76F170}.Release|Any CPU.ActiveCfg = Release|Any CPU - {77E50520-8C68-460A-B138-3FACEE76F170}.Release|Any CPU.Build.0 = Release|Any CPU + {77E50520-8C68-460A-B138-3FACEE76F170}.Release|Any CPU.ActiveCfg = Release|x64 + {77E50520-8C68-460A-B138-3FACEE76F170}.Release|Any CPU.Build.0 = Release|x64 {027A32F7-4411-4083-AA01-0550EEA0E5A3}.Debug|Any CPU.ActiveCfg = Debug|x64 {027A32F7-4411-4083-AA01-0550EEA0E5A3}.Debug|Any CPU.Build.0 = Debug|x64 - {027A32F7-4411-4083-AA01-0550EEA0E5A3}.Release|Any CPU.ActiveCfg = Release|Any CPU - {027A32F7-4411-4083-AA01-0550EEA0E5A3}.Release|Any CPU.Build.0 = Release|Any CPU + {027A32F7-4411-4083-AA01-0550EEA0E5A3}.Release|Any CPU.ActiveCfg = Release|x64 + {027A32F7-4411-4083-AA01-0550EEA0E5A3}.Release|Any CPU.Build.0 = Release|x64 {15B324FD-3EE3-467A-BDDA-A6F571FEA4C8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {15B324FD-3EE3-467A-BDDA-A6F571FEA4C8}.Debug|Any CPU.Build.0 = Debug|Any CPU {15B324FD-3EE3-467A-BDDA-A6F571FEA4C8}.Release|Any CPU.ActiveCfg = Release|Any CPU From d3ec0ab2c79f21c73908c17012783c4cf188e9f5 Mon Sep 17 00:00:00 2001 From: Florian Rappl Date: Wed, 19 May 2021 11:21:27 +0200 Subject: [PATCH 05/27] CI/CD improvements --- README.md | 6 +++--- tools/packages.config | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 301395f4..62b9b3bc 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,9 @@ # MAGES -[![AppVeyor CI](https://img.shields.io/appveyor/ci/FlorianRappl/Mages/master.svg?style=flat-square)](https://ci.appveyor.com/project/FlorianRappl/Mages) -[![Nuget count](https://img.shields.io/nuget/v/MAGES.svg?style=flat-square)](https://www.nuget.org/packages/Mages/) -[![Issues open](https://img.shields.io/github/issues/FlorianRappl/MAGES.svg?style=flat-square)](https://github.com/FlorianRappl/Mages/issues) +[![GitHub CI](https://github.com/FlorianRappl/Mages/actions/workflows/ci.yml/badge.svg)](https://github.com/FlorianRappl/Mages/actions/workflows/ci.yml) +[![NuGet](https://img.shields.io/nuget/v/MAGES.svg?style=flat-square)](https://www.nuget.org/packages/Mages/) +[![Issues](https://img.shields.io/github/issues/FlorianRappl/MAGES.svg?style=flat-square)](https://github.com/FlorianRappl/Mages/issues) ## Mages: Another Generalized Expression Simplifier diff --git a/tools/packages.config b/tools/packages.config index a7c5c312..7c61bc07 100644 --- a/tools/packages.config +++ b/tools/packages.config @@ -1,7 +1,7 @@ - - - + + + \ No newline at end of file From 8136896f62db4b7c235dc305dd924650d0d3d206 Mon Sep 17 00:00:00 2001 From: Florian Rappl Date: Wed, 19 May 2021 11:28:30 +0200 Subject: [PATCH 06/27] Adjusted cake --- build.ps1 | 38 +++++++++++++++++++++++++------------- build.sh | 2 +- 2 files changed, 26 insertions(+), 14 deletions(-) mode change 100644 => 100755 build.sh diff --git a/build.ps1 b/build.ps1 index 8c4f5d9e..ba4e06ac 100644 --- a/build.ps1 +++ b/build.ps1 @@ -14,27 +14,29 @@ Param( ) $PSScriptRoot = split-path -parent $MyInvocation.MyCommand.Definition; +$UseDryRun = ""; +$UseMono = ""; $TOOLS_DIR = Join-Path $PSScriptRoot "tools" $NUGET_EXE = Join-Path $TOOLS_DIR "nuget.exe" +$NUGET_OLD_EXE = Join-Path $TOOLS_DIR "nuget_old.exe" $CAKE_EXE = Join-Path $TOOLS_DIR "Cake/Cake.exe" $NUGET_URL = "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe" +$NUGET_OLD_URL = "https://dist.nuget.org/win-x86-commandline/v3.5.0/nuget.exe" # Should we use experimental build of Roslyn? $UseExperimental = ""; -if($Experimental.IsPresent) { - $UseExperimental = "-experimental" +if ($Experimental.IsPresent) { + $UseExperimental = "--experimental" } # Is this a dry run? -$UseDryRun = ""; -if($WhatIf.IsPresent) { - $UseDryRun = "-dryrun" +if ($WhatIf.IsPresent) { + $UseDryRun = "--dryrun" } # Should we use mono? -$UseMono = ""; -if($Mono.IsPresent) { - $UseMono = "-mono" +if ($Mono.IsPresent) { + $UseMono = "--mono" } # Try download NuGet.exe if do not exist. @@ -42,13 +44,23 @@ if (!(Test-Path $NUGET_EXE)) { (New-Object System.Net.WebClient).DownloadFile($NUGET_URL, $NUGET_EXE) } -# Make sure NuGet exists where we expect it. +# Try download NuGet.exe if do not exist. +if (!(Test-Path $NUGET_OLD_URL)) { + (New-Object System.Net.WebClient).DownloadFile($NUGET_OLD_URL, $NUGET_OLD_EXE) +} + +# Make sure NuGet (latest) exists where we expect it. if (!(Test-Path $NUGET_EXE)) { - Throw "Could not find NuGet.exe" + Throw "Could not find nuget.exe" +} + +# Make sure NuGet (v3.5.0) exists where we expect it. +if (!(Test-Path $NUGET_OLD_EXE)) { + Throw "Could not find nuget_old.exe" } # Restore tools from NuGet? -if(-Not $SkipToolPackageRestore.IsPresent) +if (-Not $SkipToolPackageRestore.IsPresent) { Push-Location Set-Location $TOOLS_DIR @@ -65,5 +77,5 @@ if (!(Test-Path $CAKE_EXE)) { } # Start Cake -Invoke-Expression "$CAKE_EXE `"$Script`" -target=`"$Target`" -configuration=`"$Configuration`" -verbosity=`"$Verbosity`" $UseMono $UseDryRun $UseExperimental $ScriptArgs" -exit $LASTEXITCODE \ No newline at end of file +Invoke-Expression "$CAKE_EXE `"$Script`" --target=`"$Target`" --configuration=`"$Configuration`" --verbosity=`"$Verbosity`" $UseMono $UseDryRun $UseExperimental $ScriptArgs" +exit $LASTEXITCODE diff --git a/build.sh b/build.sh old mode 100644 new mode 100755 index 06610a3f..6e5e05fd --- a/build.sh +++ b/build.sh @@ -78,5 +78,5 @@ fi if $SHOW_VERSION; then exec mono $CAKE_EXE -version else - exec mono $CAKE_EXE $SCRIPT -verbosity=$VERBOSITY -configuration=$CONFIGURATION -target=$TARGET $DRYRUN "${SCRIPT_ARGUMENTS[@]}" + exec mono $CAKE_EXE $SCRIPT --verbosity=$VERBOSITY --configuration=$CONFIGURATION --target=$TARGET $DRYRUN "${SCRIPT_ARGUMENTS[@]}" fi \ No newline at end of file From b65335435aa3344e2956a04d6d24216a60324c55 Mon Sep 17 00:00:00 2001 From: Florian Rappl Date: Wed, 19 May 2021 11:36:13 +0200 Subject: [PATCH 07/27] CI/CD fixes --- build.cake | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/build.cake b/build.cake index d4ca4084..aafe444f 100644 --- a/build.cake +++ b/build.cake @@ -21,6 +21,7 @@ var isRunningOnUnix = IsRunningOnUnix(); var isRunningOnWindows = IsRunningOnWindows(); var releaseNotes = ParseReleaseNotes("./CHANGELOG.md"); var version = releaseNotes.Version.ToString(); +var isRunningOnGitHubActions = BuildSystem.GitHubActions.IsRunningOnGitHubActions; var buildDir = Directory("./src/Mages.Core/bin") + Directory(configuration) + Directory("netstandard2.0"); var replDir = Directory("./src/Mages.Repl/bin") + Directory(configuration) + Directory("netcoreapp3.1"); var installerDir = Directory("./src/Mages.Repl.Installer/bin") + Directory(configuration) + Directory("net45"); @@ -30,7 +31,7 @@ var chocolateyRoot = buildResultDir + Directory("chocolatey"); var squirrelRoot = buildResultDir + Directory("squirrel"); var releaseDir = squirrelRoot + Directory("release"); -if (BuildSystem.GitHubActions.IsRunningOnGitHubActions) +if (isRunningOnGitHubActions) { var buildNumber = BuildSystem.GitHubActions.Environment.Workflow.RunNumber; @@ -133,8 +134,7 @@ Task("Create-Nuget-Package") .IsDependentOn("Copy-Files") .Does(() => { - var nugetExe = GetFiles("./tools/**/nuget.exe").FirstOrDefault() - ?? (isRunningOnAppVeyor ? GetFiles("C:\\Tools\\NuGet3\\nuget.exe").FirstOrDefault() : null); + var nugetExe = GetFiles("./tools/**/nuget.exe").FirstOrDefault(); if (nugetExe == null) { @@ -177,8 +177,7 @@ Task("Create-Squirrel-Package") .IsDependentOn("Copy-Files") .WithCriteria(() => isRunningOnWindows) .Does(() => { - var nugetExe = GetFiles("./tools/**/nuget.exe").FirstOrDefault() - ?? (isRunningOnAppVeyor ? GetFiles("C:\\Tools\\NuGet3\\nuget.exe").FirstOrDefault() : null); + var nugetExe = GetFiles("./tools/**/nuget.exe").FirstOrDefault(); if (nugetExe == null) { From 76639f08bef2ca0b3a80f3a1be04597859d34274 Mon Sep 17 00:00:00 2001 From: Florian Rappl Date: Wed, 19 May 2021 12:59:45 +0200 Subject: [PATCH 08/27] CI/CD fixes --- build.sh | 2 +- src/Mages.Repl.Installer/Installer.cs | 19 ++++++++++++++----- .../Mages.Repl.Installer.csproj | 12 ------------ 3 files changed, 15 insertions(+), 18 deletions(-) diff --git a/build.sh b/build.sh index 6e5e05fd..931fca07 100755 --- a/build.sh +++ b/build.sh @@ -12,7 +12,7 @@ CAKE_EXE=$TOOLS_DIR/Cake/Cake.exe # Define default arguments. SCRIPT="build.cake" -TARGET="Travis" +TARGET="Default" CONFIGURATION="Release" VERBOSITY="verbose" DRYRUN= diff --git a/src/Mages.Repl.Installer/Installer.cs b/src/Mages.Repl.Installer/Installer.cs index 7739a3c1..88557945 100644 --- a/src/Mages.Repl.Installer/Installer.cs +++ b/src/Mages.Repl.Installer/Installer.cs @@ -37,11 +37,20 @@ public static void CreateShortcut() } var shortcutLocation = Path.Combine(startMenuFolderPath, "Mages.lnk"); - var shell = new IWshRuntimeLibrary.WshShell(); - var shortcut = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(shortcutLocation); - shortcut.TargetPath = "cmd.exe"; - shortcut.Arguments = "/k " + Path.Combine(GetInstallDirectory(), "mages.cmd"); - shortcut.Save(); + + try + { + var progId = "IWshRuntimeLibrary.WshShell"; + var type = Type.GetTypeFromProgID(progId); + dynamic shell = Activator.CreateInstance(type); + var shortcut = shell.CreateShortcut(shortcutLocation); + shortcut.TargetPath = "cmd.exe"; + shortcut.Arguments = "/k " + Path.Combine(GetInstallDirectory(), "mages.cmd"); + shortcut.Save(); + } + catch + { + } } public static void RemoveShortcut() diff --git a/src/Mages.Repl.Installer/Mages.Repl.Installer.csproj b/src/Mages.Repl.Installer/Mages.Repl.Installer.csproj index 0e2581ab..950630ee 100644 --- a/src/Mages.Repl.Installer/Mages.Repl.Installer.csproj +++ b/src/Mages.Repl.Installer/Mages.Repl.Installer.csproj @@ -45,18 +45,6 @@ - - - - {F935DC20-1CF0-11D0-ADB9-00C04FD58A0B} - 1 - 0 - 0 - tlbimp - False - True - - From de6920a345f67977460a134d5843624a888a1c84 Mon Sep 17 00:00:00 2001 From: Florian Rappl Date: Wed, 19 May 2021 13:40:07 +0200 Subject: [PATCH 09/27] Improved codebase --- src/Mages.Core/Mages.Core.csproj | 2 +- src/Mages.Core/Mages.Core.xml | 4920 ----------------- .../Runtime/Functions/ComplexFunctions.cs | 32 + src/Mages.Core/Runtime/Functions/Global.cs | 4 +- src/Mages.Core/Runtime/Stringify.cs | 13 + 5 files changed, 49 insertions(+), 4922 deletions(-) delete mode 100644 src/Mages.Core/Mages.Core.xml create mode 100644 src/Mages.Core/Runtime/Functions/ComplexFunctions.cs diff --git a/src/Mages.Core/Mages.Core.csproj b/src/Mages.Core/Mages.Core.csproj index 90afba69..841ef06b 100644 --- a/src/Mages.Core/Mages.Core.csproj +++ b/src/Mages.Core/Mages.Core.csproj @@ -4,6 +4,6 @@ Mages.Core Mages.Core A lightweight parser / interpreter for mathematical expressions. - Mages.Core.xml + bin\$(Configuration)\$(TargetFramework)\Mages.Core.xml \ No newline at end of file diff --git a/src/Mages.Core/Mages.Core.xml b/src/Mages.Core/Mages.Core.xml deleted file mode 100644 index 842e4ca1..00000000 --- a/src/Mages.Core/Mages.Core.xml +++ /dev/null @@ -1,4920 +0,0 @@ - - - - Mages.Core - - - - - Represents an abstract (compile-time) scope information. - - - - - Creates a new abstract scope. - - The parent scope to use, if any. - - - - Gets the parent scope. - - - - - The class for an argument expression. - - - - - Creates new arguments expression. - - - - - Gets the stored arguments. - - - - - Gets the number of arguments. - - - - - Accepts the visitor by showing him around. - - The visitor walking the tree. - - - - Validates the expression with the given context. - - The validator to report errors to. - - - - Represents an expression that can be assigned. - - - - - Creates a new assignable expression. - - - - - Gets if the expression is assignable. - - - - - Represents an assignment expression. - - - - - Creates a new assignment expression. - - - - - Gets the variable (value on the left side). - - - - - Gets the variable name, if any. - - - - - Gets the value on the right side. - - - - - Accepts the visitor by showing him around. - - The visitor walking the tree. - - - - Validates the expression with the given context. - - The validator to report errors to. - - - - Represents a future wrapper. - - - - - Creates a new await expression. - - - - - Gets the carried payload to be awaited. - - - - - Accepts the visitor by showing him around. - - The visitor walking the tree. - - - - Validates the expression with the given context. - - The validator to report errors to. - - - - Represents the shared core of all expressions. - - - - - Creates a new expression. - - - - - Gets the start position of the expression. - - - - - Gets the end position of the expression. - - - - - The base class for all binary expressions. - - - - - Creates a new binary expression. - - - - - Gets the value on the left side. - - - - - Gets the value on the right side. - - - - - Gets the associated operator string. - - - - - Accepts the visitor by showing him around. - - The visitor walking the tree. - - - - Validates the expression with the given context. - - The validator to report errors to. - - - - Represents a function call. - - - - - Creates a new function call expression. - - - - - Gets the associated function. - - - - - Gets the arguments to pass to the function. - - - - - Accepts the visitor by showing him around. - - The visitor walking the tree. - - - - Validates the expression with the given context. - - The validator to report errors to. - - - - Represents a computed expression (not-assignable). - - - - - Creates a new computing expression. - - - - - Gets if the expression is assignable. - - - - - Represents a conditional expression. - - - - - Creates a new conditional expression. - - - - - Gets the condition. - - - - - Gets the primary selected value. - - - - - Gets the alternative selected value. - - - - - Accepts the visitor by showing him around. - - The visitor walking the tree. - - - - Validates the expression with the given context. - - The validator to report errors to. - - - - Represents a constant (predefined value) expression. - - - - - Creates a new constant expression for the given value. - - - - - Gets the carried value. - - - - - Accepts the visitor by showing him around. - - The visitor walking the tree. - - - - Creates a new constant expression carrying the given object. - - The value to carry. - The range that is covered. - The constant expression. - - - - Validates the expression with the given context. - - The validator to report errors to. - - - - Represents a delete expression. - - - - - Creates a new delete statement with the given payload. - - The start position. - The payload to transport. - - - - Gets the stored payload. - - - - - Accepts the visitor by showing him around. - - The visitor walking the tree. - - - - Validates the expression with the given context. - - The validator to report errors to. - - - - Represents an empty expression (potentially invalid). - - - - - Creates a new empty expression. - - - - - Accepts the visitor by showing him around. - - The visitor walking the tree. - - - - Validates the expression with the given context. - - The validator to report errors to. - - - - Represents a function expression. - - - - - Creates a new function expression. - - - - - Gets the associated abstract scope. - - - - - Gets the defined parameters. - - - - - Gets the body to use. - - - - - Accepts the visitor by showing him around. - - The visitor walking the tree. - - - - Validates the expression with the given context. - - The validator to report errors to. - - - - Represents a generalized identifier, which is not a variable. - - - - - Creates a new identifier expression. - - - - - Gets the name of the identifier. - - - - - Accepts the visitor by showing him around. - - The visitor walking the tree. - - - - Validates the expression with the given context. - - The validator to report errors to. - - - - Represents an interpolated string expression. - - - - - Creates a new interpolated string expression. - - - - - Gets the formatting string. - - - - - Gets the associated replacements. - - - - - Accepts the visitor by showing him around. - - The visitor walking the tree. - - - - Validates the expression with the given context. - - The validator to report errors to. - - - - Represents an invalid expression. - - - - - Creates a new invalid expression. - - - - - Gets the payload covered by the container. - - - - - Gets the associated error code. - - - - - Accepts the visitor by showing him around. - - The visitor walking the tree. - - - - Validates the expression with the given context. - - The validator to report errors to. - - - - Represents a matrix expression. - - - - - Creates a new matrix expression. - - - - - Gets the initialized values. - - - - - Accepts the visitor by showing him around. - - The visitor walking the tree. - - - - Validates the expression with the given context. - - The validator to report errors to. - - - - Represents a member expression. - - - - - Creates a new member expression. - - - - - Gets the associated object expression. - - - - - Gets the associated member access. - - - - - Accepts the visitor by showing him around. - - The visitor walking the tree. - - - - Validates the expression with the given context. - - The validator to report errors to. - - - - Represents an object literal. - - - - - Creates a new object expression. - - - - - Gets the contained expressions. - - - - - Accepts the visitor by showing him around. - - The visitor walking the tree. - - - - Validates the expression with the given context. - - The validator to report errors to. - - - - Represents an expression containing function parameters. - - - - - Creates a new parameter expression. - - - - - Gets the contained expressions. - - - - - Gets the available parameter names. - - - - - Accepts the visitor by showing him around. - - The visitor walking the tree. - - - - Validates the expression with the given context. - - The validator to report errors to. - - - - Base class for all post unary expressions. - - - - - Creates a new post unary expression. - - - - - Gets the used value. - - - - - Gets the operator string. - - - - - Accepts the visitor by showing him around. - - The visitor walking the tree. - - - - Validates the expression with the given context. - - The validator to report errors to. - - - - Base class for all pre unary expressions. - - - - - Creates a new pre unary expression. - - - - - Gets the used value. - - - - - Gets the operator string. - - - - - Accepts the visitor by showing him around. - - The visitor walking the tree. - - - - Validates the expression with the given context. - - The validator to report errors to. - - - - Represents a property (name-value pair) of an object. - - - - - Creates a new property. - - - - - Gets the name of the property. - - - - - Gets the value of the property. - - - - - Accepts the visitor by showing him around. - - The visitor walking the tree. - - - - Validates the expression with the given context. - - The validator to report errors to. - - - - The range expression. - - - - - Creates a new range expression. - - - - - Gets the from expression. - - - - - Gets the to expression. - - - - - Gets the step expression. - - - - - Accepts the visitor by showing him around. - - The visitor walking the tree. - - - - Validates the expression with the given context. - - The validator to report errors to. - - - - Represents the access of a variable. - - - - - Creates a new variable expression. - - - - - Gets the name of the variable. - - - - - Gets the assigned abstract scope. - - - - - Accepts the visitor by showing him around. - - The visitor walking the tree. - - - - Validates the expression with the given context. - - The validator to report errors to. - - - - An abstract expression from the AST. - - - - - Gets if the expression can be used as a value container. - - - - - Represents the core parser interface. - - - - - Parses the next expression. - - The stream of tokens. - The parsed expression. - - - - Parses the next statement. - - The stream of tokens. - The parsed statement. - - - - Parse the next statements. - - The stream of tokens. - The parsed statements. - - - - An abstract statement from the AST. - - - - - Represents a syntax tree walker. - - - - - Visits the given statement. - - Variable statement. - - - - Visits the given statement. - - Block statement. - - - - Visits the given statement. - - Simple statement. - - - - Visits the given statement. - - Return statement. - - - - Visits the given statement. - - While statement. - - - - Visits the given statement. - - For statement. - - - - Visits the given statement. - - If statement. - - - - Visits the given statement. - - Match statement. - - - - Visits the given statement. - - Case statement. - - - - Visits the given statement. - - Continue statement. - - - - Visits the given statement. - - Break statement. - - - - Visits the given expression. - - Empty expression. - - - - Visits the given expression. - - Constant expression. - - - - Visits the given expression. - - Interpolated expression. - - - - Visits the given expression. - - Arguments expression. - - - - Visits the given expression. - - Assignment expression. - - - - Visits the given expression. - - Binary expression. - - - - Visits the given expression. - - Pre-unary expression. - - - - Visits the given expression. - - Post-unary expression. - - - - Visits the given expression. - - Range expression. - - - - Visits the given expression. - - Conditional expression. - - - - Visits the given expression. - - Call expression. - - - - Visits the given expression. - - Object expression. - - - - Visits the given expression. - - Property expression. - - - - Visits the given expression. - - Matrix expression. - - - - Visits the given expression. - - Function expression. - - - - Visits the given expression. - - Invalid expression. - - - - Visits the given expression. - - Identifier expression. - - - - Visits the given expression. - - Member expression. - - - - Visits the given expression. - - Parameter expression. - - - - Visits the given expression. - - Variable expression. - - - - Visits the given expression. - - Delete expression. - - - - Visits the given experssion. - - Await expression. - - - - Represents a part of the AST that can be validated. - - - - - Validates the expression with the given context. - - The validator to report errors to. - - - - Represents the validation context. - - - - - Gets if the current element is nested in a loop. - - - - - Adds an error to the validation context. - - The error to add. - - - - Represents a part of the AST that can be walked. - - - - - Accepts the visitor by showing him around. - - The visitor walking the tree. - - - - A set of useful extensions for parsing. - - - - - Parse the expression given in form of a string. - - The parser. - The code to parse. - The resulting expression. - - - - Parse the statement given in form of a string. - - The parser. - The code to parse. - The resulting statement. - - - - Parse the statements given in form of a string. - - The parser. - The code to parse. - The resulting statements. - - - - A collection of statement extensions. - - - - - Looks for missing symbols in the provided statement. - - The statement. - The found list of missing symbols. - - - - Looks for missing symbols in the provided statements. - - The statements. - The found list of missing symbols. - - - - Converts the given statements to a single block statement. - - The statements. - The single block statement containing all statements. - - - - Collects the missing symbols in the provided statement. - - The statement. - The list of missing symbols to populate. - - - - Transforms the statements to an array of operations. - - The statements. - The operations that can be run. - - - - Checks if the given statement is a simple statement containing - an empty expression. - - The statement. - True if the statement is empty, otherwise false. - - - - Checks if the given expression is an empty expression. - - The expression. - True if the expression is empty, otherwise false. - - - - Gets the list of possible completions at the given position. - - The statements. - The position to look for completions. - The existing global symbols. - The list of completions for the given position. - - - - Represents the shared core of all statements. - - - - - Creates a new statement. - - - - - Gets the start position of the statement. - - - - - Gets the end position of the statement. - - - - - Represents a block of statements. - - - - - Creates a new block statement. - - - - - Gets the contained statements. - - - - - Validates the expression with the given context. - - The validator to report errors to. - - - - Accepts the visitor by showing him around. - - The visitor walking the tree. - - - - Represents a breakable statement. - - - - - Creates a new breakable statement. - - The body to use. - The start position. - The end position. - - - - Gets the stored body. - - - - - Validates the expression with the given context. - - The validator to report errors to. - - - - Represents a break statement. - - - - - Creates a new break statement with the given payload. - - The payload. - The start position. - The end position. - - - - Accepts the visitor by showing him around. - - The visitor walking the tree. - - - - Validates the expression with the given context. - - The validator to report errors to. - - - - Represents an case statement. - - - - - Creates a new case statement. - - - - - Gets the stored condition. - - - - - Accepts the visitor by showing him around. - - The visitor walking the tree. - - - - Represents a continue statement. - - - - - Creates a new continue statement with the given payload. - - The payload. - The start position. - The end position. - - - - Accepts the visitor by showing him around. - - The visitor walking the tree. - - - - Validates the expression with the given context. - - The validator to report errors to. - - - - Represents a for statement. - - - - - Creates a new for statement. - - - - - Gets if the initialization variable is declared. - - - - - Gets the stored initialization. - - - - - Gets the stored condition. - - - - - Gets the stored after thought. - - - - - Accepts the visitor by showing him around. - - The visitor walking the tree. - - - - Represents an if statement. - - - - - Creates a new if statement. - - - - - Gets the stored condition. - - - - - Gets the primary statement. - - - - - Gets the secondary statement. - - - - - Accepts the visitor by showing him around. - - The visitor walking the tree. - - - - Validates the expression with the given context. - - The validator to report errors to. - - - - Represents an match statement. - - - - - Creates a new match statement. - - - - - Gets the stored reference. - - - - - Gets the associated cases. - - - - - Accepts the visitor by showing him around. - - The visitor walking the tree. - - - - Validates the expression with the given context. - - The validator to report errors to. - - - - Represents a return statement. - - - - - Creates a new return statement with the given payload. - - The payload to transport. - The start position. - The end position. - - - - Gets the stored payload. - - - - - Accepts the visitor by showing him around. - - The visitor walking the tree. - - - - Validates the expression with the given context. - - The validator to report errors to. - - - - Represents a simple statement containing an expression. - - - - - Creates a new simple statement. - - - - - Gets the contained expression. - - - - - Validates the expression with the given context. - - The validator to report errors to. - - - - Accepts the visitor by showing him around. - - The visitor walking the tree. - - - - Represents a "var ...;" statement. - - - - - Creates a new var statement. - - - - - Gets the associated assignment. - - - - - Validates the expression with the given context. - - The validator to report errors to. - - - - Accepts the visitor by showing him around. - - The visitor walking the tree. - - - - Represents a while statement. - - - - - Creates a new while statement. - - - - - Gets the stored condition. - - - - - Accepts the visitor by showing him around. - - The visitor walking the tree. - - - - A basic tree walker to focus on what's really important. - - - - - Visits a var statement - accepts the assignment. - - - - - Visits a block statement - accepts all childs. - - - - - Visits a simple statement - accepts the expression. - - - - - Visits a return statement - accepts the payload. - - - - - Visits a delete expression - accepts the payload. - - - - - Visits a while statement - accepts the condition and body. - - - - - Visits a for statement - accepts the initialization, condition, afterthought, and body. - - - - - Visits an if statement - accepts the condition and body. - - - - - Visits a match statement - accepts the condition and body. - - - - - Visits a case statement - accepts the condition and body. - - - - - Visits a continue statement. - - - - - Visits a break statement. - - - - - Visits an empty expression. - - - - - Visits a constant expression. - - - - - Visits an awaitable expression. - - - - - Visits an arguments expression - accepts all arguments. - - - - - Visits an assignment expression - accepts the variable and value. - - - - - Visits a binary expression - accepts the left and right value. - - - - - Visits an interpolated string - accepts the format and replacements. - - - - - Visits a pre-unary expression - accepts the value. - - - - - Visits a post-unary expression - accepts the value. - - - - - Visits a range expression - accepts the from, step. and to. - - - - - Visits a conditional expression - accepts the condition, primary, and secondary. - - - - - Visits a call expression - accepts the function and arguments. - - - - - Visits an object expression - accepts all values. - - - - - Visits a property expression - accepts the name and value. - - - - - Visits a matrix expression - accepts all values. - - - - - Visits a function expression - accepts the parameters and body. - - - - - Visits an invalid expression. - - - - - Visits an identifier expression. - - - - - Visits a member expression - accepts the object and member. - - - - - Visits a parameter expression - accepts all parameters. - - - - - Visits a variable expression. - - - - - Represents the walker to get code completion information. - - - - - Creates a new completition tree walker for the given position. - - - - - Gets the list of autocomplete suggestions. - - - - - Finds the suggestions for the given list of statements. - - The statements to use. - - - - Visits a block statement - accepts all childs. - - - - - Visits a var statement - accepts the assignment. - - - - - Visits a simple statement - accepts the expression. - - - - - Visits an empty expression. - - - - - Visits an invalid expression. - - - - - Visits an assignment expression - accepts the variable and value. - - - - - Visits a function expression - accepts the parameters and body. - - - - - Visits a parameter expression - accepts all parameters. - - - - - Visits a property expression - accepts the name and value. - - - - - Visits a variable expression. - - - - - Visits a member expression. - - - - - Represents the walker to create operations. - - - - - Creates a new operation tree walker. - - The list of operations to populate. - - - - Represents the walker to serialize the AST. - - - - - Creates a new serialization tree walker. - - The destination to write to. - - - - Represents the walker to gather symbol information. - - - - - Creates a new symbol tree walker. - - - - - Creates a new symbol tree walker with a missing symbols collector. - - The target for missing symbols. - - - - Creates a new symbol tree walker with a new general and missing symbols collector. - - The target for general symbol information. - The target for missing symbols. - - - - Gets the found potentially missing symbols. - - - - - Gets the found resolved symbols. - - - - - Finds all references of the given symbol. - - The variable to get references for. - The list of all references of the variable. - - - - Visits the assignment expression. - - - - - Visits the function expression. - - - - - Visits the variable expression. - - - - - Represents the walker to validate the AST. - - - - - Creates a new validation tree walker with the list of errors - to populate. - - The list to populate. - - - - Represents the configuration DTO. - - - - - Gets or sets the parser to use. - - - - - Gets or sets the scope to use. - - - - - Gets or sets of a global 'this' referencing the scope should be created. - - - - - Gets or sets if the eval function is disallowed. - - - - - Gets or sets if the engine itself is exposed. - - - - - Represents the central engine for any kind of evaluation. - - - - - Creates a new engine with the specified configuration. Otherwise a - default configuration is used. - - The configuration to use. - - - - Gets the used parser instance. - - - - - Gets the used global scope. - - - - - Gets the used global function layer. - - - - - Gets the version of the engine. - - - - - Gets the currently loaded plugins. - - - - - Adds the given plugin to the list of plugins. - - The plugin to add. - - - - Removes the plugin from the list of plugins. - - The plugin to remove. - - - - Compiles the given source and returns a function to execute later. - - The source to compile. - The function to invoke later. - - - - Interprets the given source and returns the result, if any. - - The source to interpret. - The result if available, otherwise null. - - - - A collection of useful extensions for the engine. - - - - - Adds or replaces a function with the given name to the function layer. - - The engine. - The name of the function to add or replace. - The function to be integrated. - - - - Adds or replaces a function represented as a general delegate by wrapping - it as a function with the given name. - - The engine. - The name of the function to add or replace. - The function to be wrapped. - - - - Adds or replaces a function represented as a reflected method info by - wrapping it as a function with the given name. - - The engine. - The name of the function to add or replace. - The function to be wrapped. - The optional target object of the method. - - - - Adds or replaces an object represented as the MAGES primitive. This is - either directly the given value or a wrapper around it. - - The engine. - The name of the constant to add or replace. - The value to interact with. - - - - Exposes all static methods and the type's constructors in the object - that can be freely placed. - - The type to expose. - The engine. - - - - Exposes all static methods and the type's constructors in the object - that can be freely placed. - - The engine. - The type to expose. - - - - Exposes all types in the assembly that satisfy the optional condition - in an object that can be freely placed. - - The engine. - The library containing the types to expose. - The optional inclusion checker. - - - - Exposes all types in an object that can be freely placed. Here no - default name is given. - - The engine. - The types to include. - - - - Finds the missing symbols (if any) in the given source. - - The engine. - The source code to inspect. - The variable expressions pointing to the missing symbols. - - - - Interprets the given source and returns the result in form of a future. - - The engine. - The source to interpret. - The result in form of a future. Any callbacks will be aggregated here. - - - - Adds a plugin from the given type. This requires that the type represents a - static class that ends with "Plugin". Meta-data is given in form of public - static string fields, while static properties and methods are considered - content. - - The engine. - The type to represent as a plugin. - The plugin if any. - - - - Adds all plugins found in the given assembly. - - The engine. - The assembly to investigate. - The list with all added plugins. - - - - Gets the currently stored global symbols. - - The engine containing the global symbols. - The enumeration over all global symbols. - - - - Gets the currently stored global items, i.e., key-value pairs. - - The engine containing the global scope. - The dictionary with all global items. - - - - Looks up for completion at the given index in the provided source. - - The engine. - The source code to use as basis. - The index where the cursor is. - The enumeration over potential completion symbols. - - - - A list of possible parsing error codes. - - - - - See description. - - - - - See description. - - - - - See description. - - - - - See description. - - - - - See description. - - - - - See description. - - - - - See description. - - - - - See description. - - - - - See description. - - - - - See description. - - - - - See description. - - - - - See description. - - - - - See description. - - - - - See description. - - - - - See description. - - - - - See description. - - - - - See description. - - - - - See description. - - - - - See description. - - - - - See description. - - - - - See description. - - - - - See description. - - - - - See description. - - - - - See description. - - - - - See description. - - - - - See description. - - - - - See description. - - - - - See description. - - - - - See description. - - - - - See description. - - - - - See description. - - - - - See description. - - - - - See description. - - - - - See description. - - - - - See description. - - - - - See description. - - - - - See description. - - - - - See description. - - - - - See description. - - - - - See description. - - - - - Defines the function delegate. - - The arguments to pass in. - The result of the evaluation. - - - - A set of useful extensions for functions. - - - - - Calls the function with the given arguments. - - The function. - The arguments to supply. - The result of calling the function. - - - - Calls the function with the given arguments. - - The anticipated result type. - The function. - The arguments to supply. - The result or the type's default value. - - - - Gets the names of the parameters of the function. - - The function to inspect. - The array with parameter names. - - - - Determines the placement of objects in the global scope. - - - - - Placed with the given name. - - The name to use. - - - - Placed with the default name. - - - - - The children of the object are placed in the scope. - - - - - Represents a range of characters within the source code. - - - - - Gets the start position of the token. - - - - - Gets the end position of the token. - - - - - Contains all the reserved keywords. - - - - - The true keyword. - - - - - The false keyword. - - - - - The pi constant. - - - - - The var keyword. - - - - - The return keyword. - - - - - The let keyword. - - - - - The const keyword. - - - - - The for keyword. - - - - - The while keyword. - - - - - The do keyword. - - - - - The module keyword. - - - - - The if keyword. - - - - - The else keyword. - - - - - The break keyword. - - - - - The continue keyword. - - - - - The yield keyword. - - - - - The match keyword. - - - - - The async keyword. - - - - - The await keyword. - - - - - The class keyword. - - - - - The static keyword. - - - - - The new keyword. - - - - - The delete keyword. - - - - - Gets the globally available statement keywords. - - - - - Gets the within-loop available statement keywords. - - - - - Gets the available expression keywords. - - - - - Tries to get the constant's value. - - The name of the constant. - The value of the constant. - True if the constant could be resolved, otherwise false. - - - - Checks if the given identifier is actually a keyword. - - The identifier to check. - True if the identifier is a keyword, otherwise false. - - - - Represents the definition of a function parameter. - - - - - Creates a new parameter definition. - - - - - Gets the name of the parameter. - - - - - Gets if the parameter is required. - - - - - Gets the hash code. - - - - - Checks for equality to the other object. - - - - - Checks for equality to the other parameter definition. - - - - - A class to encapsulate data of a parse error. - - - - - Creates a new parse error object with these properties. - - The code of the error. - The text range of the error. - - - - Gets the start position of the error. - - - - - Gets the end position of the error. - - - - - Gets the code of the error. - - - - - Represents the exception that is thrown on trying - to interpret invalid code. - - - - - Creates a new parse exception. - - The error that occured. - - - - Gets the detected parse error. - - - - - Defines the plugin essentials. - - - - - Creates a new plugin. - - - - - Gets the name of the plugin. - - - - - Gets the plugin's meta data. - - - - - Gets the plugin's content. - - - - - A global accessible container for engine-independent services. - - - - - Registers the specified service in the container. - - The type of service to set. - The service to register. - The optional lifetime controlling instance. - - - - Unregisters the specified service from the container. - - The type of service to remove. - The service to remove. - True if the service was removed, otherwise false. - - - - Unregisters the specified service from the container. - - The type of service to remove. - The removed services, if any. - - - - Tries to get the specified service from the container. - - The type of service to get. - The optional default instance. - The service or a default instance. - - - - Tries to get the specified services from the container. - - The type of service to get. - The services. - - - - A set of useful extension methods for type conversions. - - - - - Returns the type of the given value. - - The value to get the type of. - The MAGES type string. - - - - Converts the given value to the specified type. - - The type to convert. - The destination type. - The converted value. - - - - Returns the boolean representation of the given value. - - The value to convert. - The boolean representation of the value. - - - - Returns the boolean representation of the given numeric value. - - The value to convert. - The boolean representation of the value. - - - - Returns the boolean representation of the given string value. - - The value to convert. - The boolean representation of the value. - - - - Returns the boolean representation of the given matrix value. - - The matrix to convert. - The boolean representation of the value. - - - - Returns the boolean representation of the given object value. - - The obj to convert. - The boolean representation of the value. - - - - Returns the object representation of the given value. - - The value to convert. - The object representation of the value. - - - - Returns the number representation of the given value. - - The value to convert. - The number representation of the value. - - - - Returns the number representation of the given boolean value. - - The value to convert. - The number representation of the value. - - - - Returns the number representation of the given string value. - - The value to convert. - The number representation of the value. - - - - Returns the number representation of the given matrix value. - - The matrix to convert. - The number representation of the value. - - - - Returns the matrix representation of the given number value. - - The value to convert. - The matrix representation of the value. - - - - Returns the matrix representation of the given boolean value. - - The value to convert. - The matrix representation of the value. - - - - Returns the matrix representation of the given numeric values. - - The value to convert. - The matrix representation of the value. - - - - Returns the matrix representation of the given numeric values. - - The value to convert. - The matrix representation of the value. - - - - Returns the vector representation of the given matrix value. - - The matrix to convert. - The matrix representation of the value. - - - - Returns the list representation of the given matrix value. - - The matrix to convert. - The list representation of the value. - - - - Tries to get the index supplied from the given object. - - The object to convert. - The retrieved index. - True if the index could be retrieved, otherwise false. - - - - Represents the interface to handle name selections. - - - - - Selects a name for the given member. - - The already registered names. - The member to give a MAGES name. - The selected name. - - - - Contains the event data for changes observed in a dictionary. - - - - - Creates a new event data container. - - - - - Gets the key that changed. - - - - - Gets the previously assigned value, if any. - - - - - Gets the currently assigned value, if any. - - - - - The collection of all attached properties. - - - - - Registers the provided attached property. - - The type of the object to extend. - The name of the property to attach. - The getter function to register. - - - - Unregisters the provided attached property. - - The type of the object to extend. - The name of the property to detach. - - - - Tries to find the value for the attached property. - - The object context. - The name of the property to retrieve. - The potentially attached property value. - True if the attached property could be found, otherwise false. - - - - Provide helpers to enable currying. - - - - - Checks if the provided args deliver at least one argument. - Otherwise returns null. - - The function to return or capture. - The args to check and potentially capture. - A curried function or null. - - - - Checks if the provided args deliver at least two arguments. - Otherwise returns null. - - The function to return or capture. - The args to check and potentially capture. - A curried function or null. - - - - Checks if the provided args deliver at least three arguments. - Otherwise returns null. - - The function to return or capture. - The args to check and potentially capture. - A curried function or null. - - - - Checks if the provided args deliver at least count argument(s). - Otherwise returns null. - - The required number of arguments. - The function to return or capture. - The args to check and potentially capture. - A curried function or null. - - - - Creates a function that shuffles the arguments of a given function - according to the current arguments. - - The arguments to create the shuffle function. - The created shuffle function. - - - - Helpers to check for argument types. - - - - - Checks if the first value of the given arguments is of type T. - - The type T to check for. - The arguments to check. - The callback to invoke if fulfilled. - The result of the callback or null. - - - - Checks if the first two values of the given arguments are of type - T1 and T2. - - The type of the first value. - The type of the second value. - The arguments to check. - The callback to invoke if fulfilled. - The result of the callback or null. - - - - Checks if the first three values of the given arguments are of type - T1, T2, and T3. - - The type of the first value. - The type of the second value. - The type of the third value. - The arguments to check. - The callback to invoke if fulfilled. - The result of the callback or null. - - - - Checks if the first four values of the given arguments are of type - T1, T2, T3, and T4. - - The type of the first value. - The type of the second value. - The type of the third value. - The type of the fourth value. - The arguments to check. - The callback to invoke if fulfilled. - The result of the callback or null. - - - - Checks if the first three values of the given arguments are of type - T1, anything, and T3. - - The type of the first value. - The type of the third value. - The arguments to check. - The callback to invoke if fulfilled. - The result of the callback or null. - - - - Checks if the provided args are all non-null. Performs the conversion and invokes - the result if successful. - - The type after the conversion. - The arguments to check. - The converter to use. - The result function to use. - The result or null if the check was not successful. - - - - Defines a procedure to set values. - - The index arguments. - The value to set. - - - - The collection of all standard functions. - - - - - Exposes the + operator as a function. - - - - - Exposes the - operator as a function. - - - - - Exposes the * operator as a function. - - - - - Exposes the / operator as a function. - - - - - Exposes the \ operator as a function. - - - - - Exposes the ^ operator as a function. - - - - - Exposes the % operator as a function. - - - - - Exposes the && operator as a function. - - - - - Exposes the || operator as a function. - - - - - Exposes the == operator as a function. - - - - - Exposes the != operator as a function. - - - - - Exposes the > operator as a function. - - - - - Exposes the >= operator as a function. - - - - - Exposes the < operator as a function. - - - - - Exposes the <= operator as a function. - - - - - Exposes the | operator as a function. - - - - - Exposes the ~ operator as a function. - - - - - Exposes the + operator as a function. - - - - - Exposes the - operator as a function. - - - - - Exposes the ! operator as a function. - - - - - Exposes the ' operator as a function. - - - - - Wraps the Math.Abs function. - - - - - Exposes the & operator as a function. - - - - - Wraps the Math.Sqrt function. - - - - - Wraps the Math.Sign function. - - - - - Contains the gamma function. - - - - - Wraps the Math.Ceiling function. - - - - - Wraps the Math.Floor function. - - - - - Wraps the Math.Round function. - - - - - Wraps the Math.Exp function. - - - - - Wraps the Math.Log function. - - - - - Wraps the Math.Sin function. - - - - - Wraps the Math.Cos function. - - - - - Wraps the Math.Tan function. - - - - - Contains the cot function. - - - - - Contains the sec function. - - - - - Contains the csc function. - - - - - Wraps the Math.Sinh function. - - - - - Wraps the Math.Cosh function. - - - - - Wraps the Math.Tanh function. - - - - - Contains the coth function. - - - - - Contains the sech function. - - - - - Contains the csch function. - - - - - Wraps the Math.Asin function. - - - - - Wraps the Math.Acos function. - - - - - Wraps the Math.Atan function. - - - - - Contains the arccot function. - - - - - Contains the asec function. - - - - - Contains the acsc function. - - - - - Contains the arsinh function. - - - - - Contains the arcosh function. - - - - - Contains the artanh function. - - - - - Contains the arcoth function. - - - - - Contains the asech function. - - - - - Contains the acsch function. - - - - - Contains the random function. - - - - - Contains the throw function. - - - - - Contains the catch function. - - - - - Contains the length function. - - - - - Contains the sum function. - - - - - Wraps the Math.Min function. - - - - - Wraps the Math.Max function. - - - - - Wraps the Enumerable.OrderBy function. - - - - - Wraps the Enumerable.Reverse function. - - - - - Wraps the Double.IsNaN function. - - - - - Contains the is integer function. - - - - - Contains the is prime function. - - - - - Wraps the Double.IsInfinity function. - - - - - Contains the any function. - - - - - Contains the all function. - - - - - Contains the is function. - - - - - Contains the as function. - - - - - Contains the list function. - - - - - Contains the keys function. - - - - - Contains the map function. - - - - - Contains the reduce function. - - - - - Contains the where function. - - - - - Contains the zip function. - - - - - Contains the concat function. - - - - - Contains the intersection function. - - - - - Contains the union function. - - - - - Contains the except function. - - - - - Wraps the String.Format function. - - - - - Contains the hasKey function. - - - - - Contains the getValue function. - - - - - Contains the shuffle function. - - - - - Contains the regex function. - - - - - Contains the clip function. - - - - - Contains the clamp function. - - - - - Contains the lerp function. - - - - - The collection of all standard operators. - - - - - Contains the add operator. - - - - - Contains the and operator. - - - - - Contains the left division operator. - - - - - Contains the modulo operator. - - - - - Contains the multiplication operator. - - - - - Contains the or operator. - - - - - Contains the power operator. - - - - - Contains the right division operator. - - - - - Contains the subtraction operator. - - - - - Contains the equality operator. - - - - - Contains the not equals operator. - - - - - Contains the greater or equals operator. - - - - - Contains the greater than operator. - - - - - Contains the less or equals operator. - - - - - Contains the less than operator. - - - - - Contains the pipe operator. - - - - - Contains the factorial function. - - - - - Contains the transpose operator. - - - - - Contains the negation operator. - - - - - Contains the positive operator. - - - - - Contains the negative operator. - - - - - Wraps the Math.Abs function. - - - - - Contains the type operator. - - - - - The collection of all type function creators. - - - - - Registers the provided getter function. - - The type of the object to extend. - The getter function to register. - - - - Unregisters the type function for the given type. - - The type of object to unconfigure. - - - - Tries to find the named getter. - - The object context. - The potentially found getter function. - True if the getter could be found, otherwise false. - - - - The collection of all type function creators. - - - - - Registers the provided setter procedure. - - The type of the object to extend. - The setter function to register. - - - - Unregisters the type function for the given type. - - The type of object to unconfigure. - - - - Tries to find the named setter. - - The object context. - The potentially found setter procedure. - True if the setter could be found, otherwise false. - - - - Represents an awaitable object definition. - - - - - Creates a new future object. - - - - - Gets if the result is already present. - - - - - Gets the result, if any. - - - - - Gets the error message, if any. - - - - - Sets the result in case of success. - - The concrete result, if any. - - - - Sets the error message in case of failure. - - The specific error message. - - - - Sets the callback to notify once finished. This function - is immediately called if the result is already determined. - - The callback action. - - - - Represents the observable dictionary from MAGES. - - - - - Fired once an element is added, removed, or updated. - - - - - Creates a new observable dictionary with a standard container. - - - - - Creates a new observable dictionary with the given container. - - - - - Gets the used container. - - - - - Gets or sets the value at key. - - - - - Gets the number of items stored in the container. - - - - - Adds the given key, value pair to the container. - - - - - Resets the container. - - - - - Removes the given key from the container. - - - - - Tries to get the value at the given key. - - - - - Called after something changed. - - The name of the changed entry. - The entry's previous value. - The entry's new value. - - - - Helpers to stringify objects used by MAGES. - - - - - Contains the stringify function. - - - - - Contains the JSON function. - - - - - Converts the number to a string. - - - - - Converts the boolean to a string. - - - - - Converts the string for output. - - - - - Converts the matrix to a string. - - - - - Converts the object to a string. - - - - - Converts the function to a string. - - - - - Outputs the string for an undefined (null?) value. - - - - - - Converts the undetermined value to a string. - - - - - Converts the given MAGES object to a JSON string. - - The object to represent. - The JSON representation. - - - - Converts the given string object to a JSON string. - - The string to represent. - The JSON representation. - - - - Converts the given matrix to a JSON string. - - The matrix to represent. - The JSON representation. - - - - Represents the object wrapper from MAGES. - - - - - Creates a new wrapped instance object. - - The object to wrap. - - - - Creates a new wrapped static object. - - The type to wrap. - - - - Creates a wrapper object for the given value. - - The value to inspect. - The wrapper or null dependent on the value. - - - - Gets the wrapped object if instance bound. - - - - - Gets the type that is wrapped (instance or static). - - - - - Gets or sets the value of the underlying object or - the extension object. - - The name of the property. - The value of the property. - - - - Gets the number of properties of the underlying - object and the extension object. - - - - - Gets all the keys from the extension object. - - - - - Gets all the values from the extension object. - - - - - Sets the provided value at the provided property. - - The name of the property. - The value to use. - - - - Resets the extension object. - - - - - Checks if the underlying object or the extension - object contains the given key. - - The item to check for. - True if the key is used, otherwise false. - - - - Checks if the underlying object or the extension - object contains the given key. - - The key to check for. - True if the key is used, otherwise false. - - - - Gets the enumerator over the elements of the extension. - - The extension's enumerator. - - - - Removes the item from the extension. - - The key of the item to be removed. - True if it could be removed, otherwise false. - - - - Tries to get the value from the given key. - - The name of the property. - The resulting value. - True if the value could be retrieved, otherwise false. - - - - A set of special characters. - - - - - The end of file Character -1. - - - - - The tilde Character (~). - - - - - The pipe Character (|). - - - - - The null Character. - - - - - The ampersand Character (&). - - - - - The number sign Character (#). - - - - - The dollar sign Character ($). - - - - - The semicolon sign (;). - - - - - The asterisk Character (*). - - - - - The equals sign (=). - - - - - The comma Character (,). - - - - - The full stop (.). - - - - - The circumflex accent (^) Character. - - - - - The commercial at (@) Character. - - - - - The opening angle bracket (LESS-THAN-SIGN). - - - - - The closing angle bracket (GREATER-THAN-SIGN). - - - - - The single quote / quotation mark ('). - - - - - The (double) quotation mark ("). - - - - - The (curved) quotation mark (`). - - - - - The question mark (?). - - - - - The tab Character. - - - - - The line feed Character. - - - - - The carriage return Character. - - - - - The form feed Character. - - - - - The space Character. - - - - - The slash (solidus, /) Character. - - - - - The backslash (reverse-solidus, \) Character. - - - - - The colon (:) Character. - - - - - The exlamation mark (!) Character. - - - - - The dash (hypen minus, -) Character. - - - - - The plus sign (+). - - - - - The low line (_) Character. - - - - - The percent (%) Character. - - - - - Opening a round bracket (. - - - - - Closing a round bracket ). - - - - - Opening an array bracket [. - - - - - Closing an array bracket ]. - - - - - Opening a scope bracket {. - - - - - Closing a scope bracket }. - - - - - The number 0. - - - - - The number 1. - - - - - The letter E. - - - - - The letter I. - - - - - The letter a. - - - - - The letter b. - - - - - The letter e. - - - - - The letter f. - - - - - The letter i. - - - - - The letter n. - - - - - The letter r. - - - - - The letter t. - - - - - The letter u. - - - - - The letter v. - - - - - The letter x. - - - - - Represents the source code scanner. - - - - - Gets the current character code. - - - - - Gets the current position in the source code. - - - - - Tries to move to the next position. - - True if the next character exists, otherwise false. - - - - Tries to move to the previous position. - - True if the previous character exists, otherwise false. - - - - Gets the position at the given index. - - The linear index in the source. - The corresponding text position. - - - - Specification helpers and extension methods. - - - - - Converts a given character from the hex representation (0-9A-Fa-f) to an integer. - - The character to convert. - The integer value or undefined behavior if invalid. - - - - Determines if the given character is in the given range. - - The character to examine. - The lower bound of the range. - The upper bound of the range. - The result of the test. - - - - Determines if the given character is a uppercase character (A-Z). - - The character to examine. - The result of the test. - - - - Determines if the given character is a lowercase character (a-z). - - The character to examine. - The result of the test. - - - - Determines if the given character is a hexadecimal (0-9a-fA-F). - - The character to examine. - The result of the test. - - - - Gets if the character is actually a (A-Z,a-z) letter. - - The character to examine. - The result of the test. - - - - Gets if the character is actually a name character. - - The character to examine. - The result of the test. - - - - Determines if the given character is a valid character for starting an identifier. - - The character to examine. - The result of the test. - - - - Determines if the given character is a white-space character. - - The character to examine. - The result of the test. - - - - Determines if the given character is a digit (0-9). - - The character to examine. - The result of the test. - - - - A pool for recycled resources. - - - - - Either creates a fresh stringbuilder or gets a (cleaned) used one. - - A stringbuilder to use. - - - - Returns the given stringbuilder to the pool and gets the current - string content. - - The stringbuilder to recycle. - The string that is contained in the stringbuilder. - - - - A number of useful string extensions. - - - - - Transforms the string to a token iterator. - - The string. - The created token iterator. - - - - Gets a scanner to walk through the provided source. - - The string. - The created scanner. - - - - Checks if the source could be considered completed. This is not to - indicate that the source is error free, but at least all open brackets - have their partner. - - The string. - True if the source is completed, otherwise false. - - - - Represents a position within a text source. - - - - - Creates a new text position. - - The row number. - The column number. - The character index. - - - - Gets the row in the source code. - - - - - Gets the column in the source code. - - - - - Gets the index (absolute position) in the source code. - - - - - Compares the index of the left text position against the index of the right text position. - - - - - Compares the index of the left text position against the index of the right text position. - - - - - Compares the index of the left text position against the index of the right text position. - - - - - Compares the index of the left text position against the index of the right text position. - - - - - Compares the index of the left text position against the index of the right text position. - - - - - Compares the index of the left text position against the index of the right text position. - - - - - Checks the types for equality. - - - - - Returns the index of the text position. - - - - - Checks the types for equality. - - - - - Represents a token found by the tokenizer. - - - - - Gets the type of the token. - - - - - Gets the payload of the token. - - - - - Represents the tokenizer performing the lexical analysis. - - - - - Gets the next token from the scanner. - - The token. - - - - The available token types. - - - - - Unknown token type. - - - - - Keyword token. - - - - - Identifier token. - - - - - Number token. - - - - - Interpolated string token. - - - - - String token. - - - - - Round bracket open. - - - - - Round bracket close. - - - - - Square bracket open. - - - - - Square bracket close. - - - - - Curly bracket open. - - - - - Curly bracket close. - - - - - Comma symbol. - - - - - Colon symbol. - - - - - Dot symbol. - - - - - Power operator. - - - - - Right divide operator. - - - - - Left divide operator. - - - - - Multiply operator. - - - - - Modulo operator. - - - - - Factorial operator. - - - - - Add operator. - - - - - Subtract operator. - - - - - Increment operator. - - - - - Decrement operator. - - - - - Or operator. - - - - - And operator. - - - - - Equal operator. - - - - - Not equal operator. - - - - - Less operator. - - - - - Less or equal operator. - - - - - Greater or equal operator. - - - - - Greater operator. - - - - - Negate operator. - - - - - Condition operator. - - - - - Transpose operator. - - - - - Assignment operator. - - - - - Lambda operator. - - - - - Type operator. - - - - - Pipe operator. - - - - - Semicolon symbol. - - - - - EOF. - - - - - Any kind of space symbol. - - - - - Preprocessor token. - - - - - Comment token. - - - - - Assembles the MAGES runtime memory model. - - - - - Creates a new execution context. - - The operations to use. - The global scope to use. - - - - Gets the current position of the execution context. - - - - - Gets the position of the last operation. - - - - - Gets the currently used scope of the execution context. - - - - - Executes the operations. - - - - - Pushes the value onto the stack. - - The value to push. - - - - Pops a value from the stack. - - The last value from the stack. - - - - Extension methods for IExecutionContext instances. - - - - - Stops the execution of the given context. - - The context to stop. - - - - Pauses the execution of the given context. - - The context to pause. - - - - Represents the model of the MAGES VM. - - - - - Gets or sets the position of the previous operation. - - - - - Gets the position of the last operation. - - - - - Gets the currently used execution scope. - - - - - Pushes a new value on the stack. - - The value to push on the stack. - - - - Pops a value from the stack. - - The value that came from the stack. - - - - Represents the core interface of an interpreted operation. - - - - - Invokes the operation from the execution context. - - The current context. - - - - A set of handy helpers for operations. - - - - - Serializes the given operations to a string of instructions. - - The operations to serialize. - The string with the instructions. - - - - Checks if the parameters |Object[]| is less / equal than i by - popping one value from the stack and pushing back two values. - - - - - Assigns the argument at index i by popping two values - from the scope and pushing one value back. - - - - - Populates the local scope with one of the arguments. - - - - - Pops one element from the stack. - - - - - Pops three elements from the stack and pushes one. - - - - - Pushes a constant value on the stack. - - - - - Contains a const operation pushing null on the stack. - - - - - Pops one element from the stack and pushes one element. - - - - - Peeks the top element from the stack. - - - - - Pops one value and tries to remove the key from the object. - Pushes the result on the stack. - - - - - Tries to remove the named variable from the scope and pushes the result - on the stack. - - - - - Takes two elements from the stack and pushes one. - - - - - Takes two elements from the stack and pushes the result. - - - - - Pushes the loaded value on the stack. - - - - - Pops one element from the stack and pushes one element. - - - - - Peeks the top element from the stack. - - - - - Pops three elements from the stack and pushes on element. - - - - - Changes the currently executing position. - - - - - Pushes one new element on the stack. - - - - - Pushes one new element on the stack. - - - - - Pops two elements from the stack and pushes three new element on the stack. - - - - - Pushes one new element on the stack. - - - - - Pops one element from the stack. - - - - - Pops one element from the stack. - - - - - Stops the execution without changing the stack. - - - - - Pops three elements from the stack and pushes one. - - - - - Pops two elements from the stack and pushes one. - - - - - Pops at least two elements from the stack and pushes one. - - - - - Pops three elements from the stack and pushes one. - - - - - Peeks the top element from the stack. - - - - diff --git a/src/Mages.Core/Runtime/Functions/ComplexFunctions.cs b/src/Mages.Core/Runtime/Functions/ComplexFunctions.cs new file mode 100644 index 00000000..872734c3 --- /dev/null +++ b/src/Mages.Core/Runtime/Functions/ComplexFunctions.cs @@ -0,0 +1,32 @@ +namespace Mages.Core.Runtime.Functions +{ + using System; + using System.Numerics; + + /// + /// The collection of all standard complex functions. + /// + public static class ComplexFunctions + { + /// + /// Exposes the complex constructor function. + /// + public static readonly Function Cmplx = new Function(args => + { + return Curry.MinTwo(Cmplx, args) ?? + If.Is(args, (x, y) => new Complex(x, y)) ?? + Complex.Zero; + }); + + /// + /// Exposes the complex conjugate function. + /// + public static readonly Function Conj = new Function(args => + { + return Curry.MinOne(Conj, args) ?? + If.Is(args, x => new Complex(x, 0)) ?? + If.Is(args, x => new Complex(x.Real, -x.Imaginary)) ?? + Double.NaN; + }); + } +} diff --git a/src/Mages.Core/Runtime/Functions/Global.cs b/src/Mages.Core/Runtime/Functions/Global.cs index c8ee906c..f0f6d7da 100644 --- a/src/Mages.Core/Runtime/Functions/Global.cs +++ b/src/Mages.Core/Runtime/Functions/Global.cs @@ -95,7 +95,9 @@ static class Global { "clip", StandardFunctions.Clip }, { "regex", StandardFunctions.Regex }, { "lerp", StandardFunctions.Lerp }, - { "clamp", StandardFunctions.Clamp } + { "clamp", StandardFunctions.Clamp }, + { "cmplx", ComplexFunctions.Cmplx }, + { "conj", ComplexFunctions.Conj }, }; } } diff --git a/src/Mages.Core/Runtime/Stringify.cs b/src/Mages.Core/Runtime/Stringify.cs index 5e70742a..831555d5 100644 --- a/src/Mages.Core/Runtime/Stringify.cs +++ b/src/Mages.Core/Runtime/Stringify.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; using System.Globalization; + using System.Numerics; /// /// Helpers to stringify objects used by MAGES. @@ -19,6 +20,14 @@ public static class Stringify /// public static readonly Function Json = new Function(args => AsJson(args.Length > 0 ? args[0] : null)); + /// + /// Converts the number to a string. + /// + public static String This(Complex value) + { + return $"cmplx{value.ToString(CultureInfo.InvariantCulture)}"; + } + /// /// Converts the number to a string. /// @@ -133,6 +142,10 @@ public static String This(Object value) { return This((Boolean)value); } + else if (value is Complex) + { + return This((Complex)value); + } return "(unknown)"; } From 9966d149ec0f4a0541736de99790e5c3030f6a8a Mon Sep 17 00:00:00 2001 From: Florian Rappl Date: Wed, 19 May 2021 13:43:03 +0200 Subject: [PATCH 10/27] Fixed build setup --- build.cake | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/build.cake b/build.cake index aafe444f..b6850656 100644 --- a/build.cake +++ b/build.cake @@ -88,6 +88,16 @@ Task("Build") { Configuration = configuration, }); + + DotNetCoreBuild($"./src/Mages.Repl/Mages.Repl.csproj", new DotNetCoreBuildSettings + { + Configuration = configuration, + }); + + DotNetCoreBuild($"./src/Mages.Repl.Installer/Mages.Repl.Installer.csproj", new DotNetCoreBuildSettings + { + Configuration = configuration, + }); }); Task("Run-Unit-Tests") From 8fdaa63e1621d4f892a1c0522d68d46f1a8a3343 Mon Sep 17 00:00:00 2001 From: Florian Rappl Date: Wed, 19 May 2021 13:56:15 +0200 Subject: [PATCH 11/27] Improved structure --- .github/workflows/ci.yml | 2 +- build.cake | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 71edcaed..63a3347d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,8 +3,8 @@ name: CI on: [push, pull_request] env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }} + GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} CHOCOLATEY_API_KEY: ${{ secrets.CHOCOLATEY_API_KEY }} jobs: diff --git a/build.cake b/build.cake index b6850656..31db522d 100644 --- a/build.cake +++ b/build.cake @@ -219,6 +219,7 @@ Task("Create-Squirrel-Package") Task("Create-Chocolatey-Package") .IsDependentOn("Copy-Files") + .WithCriteria(() => isRunningOnWindows) .Does(() => { var content = String.Format("$packageName = 'Mages'{1}$installerType = 'exe'{1}$url32 = 'https://github.com/FlorianRappl/Mages/releases/download/v{0}/Mages.exe'{1}$silentArgs = ''{1}{1}Install-ChocolateyPackage \"$packageName\" \"$installerType\" \"$silentArgs\" \"$url32\"", version, Environment.NewLine); var nuspec = chocolateyRoot + File("Mages.nuspec"); @@ -237,6 +238,7 @@ Task("Create-Chocolatey-Package") Task("Publish-Chocolatey-Package") .IsDependentOn("Create-Chocolatey-Package") + .WithCriteria(() => isRunningOnWindows) .Does(() => { var apiKey = EnvironmentVariable("CHOCOLATEY_API_KEY"); var fileName = "Mages." + version + ".nupkg"; @@ -255,7 +257,7 @@ Task("Publish-Chocolatey-Package") }); Task("Publish-GitHub-Release") - .IsDependentOn("Create-Squirrel-Package") + .IsDependentOn("Publish-Packages") .Does(() => { var githubToken = EnvironmentVariable("GITHUB_API_TOKEN"); @@ -318,11 +320,10 @@ Task("Default") Task("Publish-Packages") .IsDependentOn("Publish-Nuget-Package") - .IsDependentOn("Publish-GitHub-Release") .IsDependentOn("Publish-Chocolatey-Package"); Task("Publish") - .IsDependentOn("Publish-Packages"); + .IsDependentOn("Publish-GitHub-Release"); Task("PrePublish") .IsDependentOn("Publish-Packages"); From e0ce2245caabef612d33b6bfc8ca2c4663bc071b Mon Sep 17 00:00:00 2001 From: Florian Rappl Date: Wed, 19 May 2021 14:32:36 +0200 Subject: [PATCH 12/27] Added missing helpers --- src/Mages.Core/Runtime/Constants.cs | 78 +++++++++++++++++++ .../Runtime/Functions/ComplexFunctions.cs | 22 ++++++ .../Runtime/Functions/StandardFunctions.cs | 24 ++++++ .../Runtime/{Functions => }/Global.cs | 25 +++++- src/Mages.Core/Runtime/GlobalScope.cs | 1 - src/Mages.Core/Runtime/Mathx.cs | 74 +++++------------- 6 files changed, 166 insertions(+), 58 deletions(-) create mode 100644 src/Mages.Core/Runtime/Constants.cs rename src/Mages.Core/Runtime/{Functions => }/Global.cs (84%) diff --git a/src/Mages.Core/Runtime/Constants.cs b/src/Mages.Core/Runtime/Constants.cs new file mode 100644 index 00000000..b6af8190 --- /dev/null +++ b/src/Mages.Core/Runtime/Constants.cs @@ -0,0 +1,78 @@ +namespace Mages.Core.Runtime +{ + using System; + using System.Numerics; + + /// + /// A set of known / famous / useful constants. + /// + public static class Constants + { + /// + /// Euler's constant. + /// The number e is an important mathematical constant, approximately equal to + /// 2.71828, that is the base of the natural logarithm. + /// + public static Double E = Math.E; + + /// + /// Imaginary unit. + /// + public static Complex I = Complex.ImaginaryOne; + + /// + /// Imaginary unit (alt). + /// + public static Complex J = Complex.ImaginaryOne; + + /// + /// The Feigenbaum constant alpha is the ratio between the width of a tine and the + /// width of one of its two subtines (except the tine closest to the fold). + /// + public static Double Alpha = 2.50290787509589282228390287321821578; + + /// + /// Catalan's constant G, which occasionally appears in estimates in combinatorics, + /// is defined by G = beta(2), where beta is the Dirichlet beta function. + /// + public static Double Catalan = 0.915965594177219015054604; + + /// + /// The Feigenbaum constant delta is the limiting ratio of each bifurcation interval + /// to the next between every period doubling, of a one-parameter map. + /// + public static Double Delta = 4.66920160910299067185320382046620161; + + /// + /// The Euler–Mascheroni constant (also called Euler's constant) is a mathematical + /// constant recurring in analysis and number theory. + /// + public static Double Gamma1 = 0.57721566490153286060651209008240243; + + /// + /// Gauss's constant, denoted by G, is defined as the reciprocal of the + /// arithmetic-geometric mean of 1 and the square root of 2. + /// + public static Double Gauss = 0.8346268416740731862814297; + + /// + /// The omega constant is the value of W(1) where W is Lambert's W function. The name is derived + /// from the alternate name for Lambert's W function, the omega function. + /// + public static Double Omega = 0.5671432904097838729999686622; + + /// + /// The golden ratio: two quantities are in the golden ratio if the ratio of the sum of the + /// quantities to the larger quantity is equal to the ratio of the larger quantity to the + /// smaller one. + /// + public static Double Phi = 1.61803398874989484820458683436563811; + + /// + /// A degree (in full, a degree of arc, arc degree, or arcdegree), usually denoted by ° (the degree symbol), + /// is a measurement of plane angle, representing 1⁄360 of a full rotation; one degree is equivalent to + /// π/180 radians. + /// + public static Double Deg = Math.PI / 180.0; + } +} diff --git a/src/Mages.Core/Runtime/Functions/ComplexFunctions.cs b/src/Mages.Core/Runtime/Functions/ComplexFunctions.cs index 872734c3..c8daa082 100644 --- a/src/Mages.Core/Runtime/Functions/ComplexFunctions.cs +++ b/src/Mages.Core/Runtime/Functions/ComplexFunctions.cs @@ -28,5 +28,27 @@ public static class ComplexFunctions If.Is(args, x => new Complex(x.Real, -x.Imaginary)) ?? Double.NaN; }); + + /// + /// Exposes the complex real function. + /// + public static readonly Function Real = new Function(args => + { + return Curry.MinOne(Real, args) ?? + If.Is(args, x => x) ?? + If.Is(args, x => x.Real) ?? + Double.NaN; + }); + + /// + /// Exposes the complex imag function. + /// + public static readonly Function Imag = new Function(args => + { + return Curry.MinOne(Imag, args) ?? + If.Is(args, _ => 0.0) ?? + If.Is(args, x => x.Imaginary) ?? + Double.NaN; + }); } } diff --git a/src/Mages.Core/Runtime/Functions/StandardFunctions.cs b/src/Mages.Core/Runtime/Functions/StandardFunctions.cs index 566e0c59..cc410306 100644 --- a/src/Mages.Core/Runtime/Functions/StandardFunctions.cs +++ b/src/Mages.Core/Runtime/Functions/StandardFunctions.cs @@ -313,6 +313,30 @@ public static class StandardFunctions Math.Log(args[0].ToNumber()); }); + /// + /// Wraps the Math.Log2 function. + /// + public static readonly Function Log2 = new Function(args => + { + return Curry.MinOne(Log2, args) ?? + If.Is(args, x => Mathx.Log2(x)) ?? + If.Is(args, x => x.ForEach(Mathx.Log2)) ?? + If.Is>(args, o => o.Map(Log2)) ?? + Math.Log(args[0].ToNumber()); + }); + + /// + /// Wraps the Math.Log10 function. + /// + public static readonly Function Log10 = new Function(args => + { + return Curry.MinOne(Log10, args) ?? + If.Is(args, x => Math.Log10(x)) ?? + If.Is(args, x => x.ForEach(Math.Log10)) ?? + If.Is>(args, o => o.Map(Log10)) ?? + Math.Log(args[0].ToNumber()); + }); + /// /// Wraps the Math.Sin function. /// diff --git a/src/Mages.Core/Runtime/Functions/Global.cs b/src/Mages.Core/Runtime/Global.cs similarity index 84% rename from src/Mages.Core/Runtime/Functions/Global.cs rename to src/Mages.Core/Runtime/Global.cs index f0f6d7da..bf80d2de 100644 --- a/src/Mages.Core/Runtime/Functions/Global.cs +++ b/src/Mages.Core/Runtime/Global.cs @@ -1,5 +1,6 @@ -namespace Mages.Core.Runtime.Functions +namespace Mages.Core.Runtime { + using Mages.Core.Runtime.Functions; using System; using System.Collections.Generic; @@ -7,6 +8,7 @@ static class Global { public static readonly IDictionary Mapping = new Dictionary { + // Functions { "abs", StandardFunctions.Abs }, { "not", StandardFunctions.Not }, { "type", StandardFunctions.Type }, @@ -32,6 +34,8 @@ static class Global { "exp", StandardFunctions.Exp }, { "floor", StandardFunctions.Floor }, { "round", StandardFunctions.Round }, + { "log2", StandardFunctions.Log2 }, + { "log10", StandardFunctions.Log10 }, { "log", StandardFunctions.Log }, { "sign", StandardFunctions.Sign }, { "gamma", StandardFunctions.Gamma }, @@ -98,6 +102,25 @@ static class Global { "clamp", StandardFunctions.Clamp }, { "cmplx", ComplexFunctions.Cmplx }, { "conj", ComplexFunctions.Conj }, + { "real", ComplexFunctions.Real }, + { "imag", ComplexFunctions.Imag }, + + // Constants + { "e", Constants.E }, + { "i", Constants.I }, + { "j", Constants.J }, + { "I", Constants.I }, + { "J", Constants.J }, + { "exp0", 1.0 }, + { "exp1", Constants.E }, + { "alpha", Constants.Alpha }, + { "delta", Constants.Delta }, + { "gamma1", Constants.Gamma1}, + { "gauss", Constants.Gauss }, + { "omega", Constants.Omega }, + { "catalan", Constants.Catalan }, + { "phi", Constants.Phi }, + { "deg", Constants.Deg }, }; } } diff --git a/src/Mages.Core/Runtime/GlobalScope.cs b/src/Mages.Core/Runtime/GlobalScope.cs index ec20835b..895ce2d2 100644 --- a/src/Mages.Core/Runtime/GlobalScope.cs +++ b/src/Mages.Core/Runtime/GlobalScope.cs @@ -1,6 +1,5 @@ namespace Mages.Core.Runtime { - using Mages.Core.Runtime.Functions; using System; using System.Collections.Generic; diff --git a/src/Mages.Core/Runtime/Mathx.cs b/src/Mages.Core/Runtime/Mathx.cs index a9e41585..c3aa75d7 100644 --- a/src/Mages.Core/Runtime/Mathx.cs +++ b/src/Mages.Core/Runtime/Mathx.cs @@ -44,10 +44,7 @@ static class Mathx -261082718496449122051.0 / 13530.0 }; - public static Double Sign(Double value) - { - return (Double)Math.Sign(value); - } + public static Double Sign(Double value) => (Double)Math.Sign(value); public static Double Factorial(Double value) { @@ -82,30 +79,15 @@ public static Double Gamma(Double x) return Math.Exp(LogGamma(x)); } - public static Double Asinh(Double value) - { - return Math.Log(value + Math.Sqrt(value * value + 1.0)); - } + public static Double Asinh(Double value) => Math.Log(value + Math.Sqrt(value * value + 1.0)); - public static Double Acosh(Double value) - { - return Math.Log(value + Math.Sqrt(value * value - 1.0)); - } + public static Double Acosh(Double value) => Math.Log(value + Math.Sqrt(value * value - 1.0)); - public static Double Atanh(Double value) - { - return 0.5 * Math.Log((1.0 + value) / (1.0 - value)); - } + public static Double Atanh(Double value) => 0.5 * Math.Log((1.0 + value) / (1.0 - value)); - public static Double Cot(Double value) - { - return Math.Cos(value) / Math.Sin(value); - } + public static Double Cot(Double value) => Math.Cos(value) / Math.Sin(value); - public static Double Acot(Double value) - { - return Math.Atan(1.0 / value); - } + public static Double Acot(Double value) => Math.Atan(1.0 / value); public static Double Coth(Double value) { @@ -114,25 +96,13 @@ public static Double Coth(Double value) return (a + b) / (a - b); } - public static Double Acoth(Double value) - { - return 0.5 * Math.Log((1.0 + value) / (value - 1.0)); - } + public static Double Acoth(Double value) => 0.5 * Math.Log((1.0 + value) / (value - 1.0)); - public static Double Sec(Double value) - { - return 1.0 / Math.Cos(value); - } + public static Double Sec(Double value) => 1.0 / Math.Cos(value); - public static Double Asec(Double value) - { - return Math.Acos(1.0 / value); - } + public static Double Asec(Double value) => Math.Acos(1.0 / value); - public static Double Sech(Double value) - { - return 2.0 / (Math.Exp(value) + Math.Exp(-value)); - } + public static Double Sech(Double value) => 2.0 / (Math.Exp(value) + Math.Exp(-value)); public static Double Asech(Double value) { @@ -140,25 +110,15 @@ public static Double Asech(Double value) return Math.Log(vi + Math.Sqrt(vi + 1.0) * Math.Sqrt(vi - 1.0)); } - public static Double Csc(Double value) - { - return 1.0 / Math.Sin(value); - } + public static Double Csc(Double value) => 1.0 / Math.Sin(value); - public static Double Acsc(Double value) - { - return Math.Asin(1.0 / value); - } + public static Double Acsc(Double value) => Math.Asin(1.0 / value); - public static Double Csch(Double value) - { - return 2.0 / (Math.Exp(value) - Math.Exp(-value)); - } + public static Double Csch(Double value) => 2.0 / (Math.Exp(value) - Math.Exp(-value)); - public static Double Acsch(Double value) - { - return Math.Log(1.0 / value + Math.Sqrt(1.0 / (value * value) + 1.0)); - } + public static Double Acsch(Double value) => Math.Log(1.0 / value + Math.Sqrt(1.0 / (value * value) + 1.0)); + + public static Double Log2(Double value) => Math.Log(value, 2.0); private static Double LogGamma(Double x) { @@ -201,7 +161,9 @@ private static Double StirlingLogGamma(Double x) f += BernoulliNumbers[i] / (2 * i) / (2 * i - 1) / xp; if (f == f_old) + { break; + } xp *= xsqu; } From 25d723e92fc24d50803f3ee287c69b32632d3b2a Mon Sep 17 00:00:00 2001 From: Florian Rappl Date: Thu, 20 May 2021 01:53:18 +0200 Subject: [PATCH 13/27] Converted functions to allow cmplx --- src/Mages.Core/Ast/AbstractScope.cs | 5 +- src/Mages.Core/Ast/AbstractScopeStack.cs | 5 +- .../Ast/Expressions/ArgumentsExpression.cs | 10 +- .../Ast/Expressions/AssignableExpression.cs | 5 +- .../Ast/Expressions/AssignmentExpression.cs | 10 +- .../Ast/Expressions/AwaitExpression.cs | 5 +- .../Ast/Expressions/BaseExpression.cs | 10 +- .../Ast/Expressions/BinaryExpression.cs | 15 +- .../Ast/Expressions/CallExpression.cs | 10 +- .../Ast/Expressions/ComputingExpression.cs | 5 +- .../Ast/Expressions/ConditionalExpression.cs | 15 +- .../Ast/Expressions/ConstantExpression.cs | 5 +- .../Ast/Expressions/DeleteExpression.cs | 5 +- .../Ast/Expressions/FunctionExpression.cs | 15 +- .../Ast/Expressions/IdentifierExpression.cs | 5 +- .../Ast/Expressions/InterpolatedExpression.cs | 10 +- .../Ast/Expressions/InvalidExpression.cs | 10 +- .../Ast/Expressions/MatrixExpression.cs | 5 +- .../Ast/Expressions/MemberExpression.cs | 10 +- .../Ast/Expressions/ObjectExpression.cs | 5 +- .../Ast/Expressions/ParameterExpression.cs | 5 +- .../Ast/Expressions/PostUnaryExpression.cs | 10 +- .../Ast/Expressions/PreUnaryExpression.cs | 10 +- .../Ast/Expressions/PropertyExpression.cs | 10 +- .../Ast/Expressions/RangeExpression.cs | 15 +- .../Ast/Expressions/VariableExpression.cs | 10 +- .../Ast/Statements/BaseStatement.cs | 10 +- .../Ast/Statements/BlockStatement.cs | 5 +- .../Ast/Statements/BreakableStatement.cs | 5 +- .../Ast/Statements/CaseStatement.cs | 5 +- src/Mages.Core/Ast/Statements/ForStatement.cs | 20 +- src/Mages.Core/Ast/Statements/IfStatement.cs | 15 +- .../Ast/Statements/MatchStatement.cs | 10 +- .../Ast/Statements/ReturnStatement.cs | 5 +- .../Ast/Statements/SimpleStatement.cs | 5 +- src/Mages.Core/Ast/Statements/VarStatement.cs | 5 +- .../Ast/Statements/WhileStatement.cs | 5 +- .../Ast/Walkers/CompletionTreeWalker.cs | 5 +- .../Ast/Walkers/OperationTreeWalker.cs | 5 +- .../Ast/Walkers/SymbolTreeWalker.cs | 10 +- .../Ast/Walkers/ValidationTreeWalker.cs | 5 +- src/Mages.Core/Engine.cs | 20 +- src/Mages.Core/Mages.Core.csproj | 1 + src/Mages.Core/ParameterDefinition.cs | 10 +- src/Mages.Core/ParseError.cs | 15 +- src/Mages.Core/Plugin.cs | 10 +- src/Mages.Core/Runtime/BaseScope.cs | 25 +- src/Mages.Core/Runtime/BinaryOperators.cs | 11 +- .../Runtime/Converters/ArrayConverters.cs | 9 + .../Runtime/Converters/ConverterExtensions.cs | 175 +++++------ .../Runtime/Converters/StandardConverters.cs | 15 + .../Runtime/Converters/TypeConverter.cs | 15 +- .../Runtime/Functions/ComplexFunctions.cs | 44 ++- src/Mages.Core/Runtime/Functions/If.cs | 33 +-- .../Runtime/Functions/StandardFunctions.cs | 73 +++++ src/Mages.Core/Runtime/Future.cs | 10 +- src/Mages.Core/Runtime/GammaHelpers.cs | 272 ++++++++++++++++++ src/Mages.Core/Runtime/JsonSerializer.cs | 30 +- src/Mages.Core/Runtime/LocalFunction.cs | 10 +- src/Mages.Core/Runtime/Mathx.cs | 153 +++++----- src/Mages.Core/Runtime/Matrix.cs | 153 ++++++---- .../Runtime/ObservableDictionary.cs | 25 +- src/Mages.Core/Runtime/Stringify.cs | 82 ++---- src/Mages.Core/Runtime/UnaryOperators.cs | 104 +++---- src/Mages.Core/Runtime/WrapperObject.cs | 30 +- src/Mages.Core/Source/BaseScanner.cs | 5 +- src/Mages.Core/Source/StringScanner.cs | 5 +- src/Mages.Core/TextPosition.cs | 15 +- src/Mages.Core/Tokens/CharacterToken.cs | 20 +- src/Mages.Core/Tokens/CommentToken.cs | 20 +- src/Mages.Core/Tokens/EndToken.cs | 20 +- src/Mages.Core/Tokens/IdentToken.cs | 20 +- src/Mages.Core/Tokens/InterpolatedToken.cs | 30 +- src/Mages.Core/Tokens/NumberToken.cs | 30 +- src/Mages.Core/Tokens/NumberTokenizer.cs | 5 +- src/Mages.Core/Tokens/OperatorToken.cs | 20 +- src/Mages.Core/Tokens/PreprocessorToken.cs | 20 +- src/Mages.Core/Tokens/StringToken.cs | 25 +- .../Tokens/TextPositionExtensions.cs | 10 +- src/Mages.Core/Vm/ExecutionContext.cs | 10 +- 80 files changed, 922 insertions(+), 998 deletions(-) create mode 100644 src/Mages.Core/Runtime/GammaHelpers.cs diff --git a/src/Mages.Core/Ast/AbstractScope.cs b/src/Mages.Core/Ast/AbstractScope.cs index e7da80ac..eea9613e 100644 --- a/src/Mages.Core/Ast/AbstractScope.cs +++ b/src/Mages.Core/Ast/AbstractScope.cs @@ -29,10 +29,7 @@ public AbstractScope(AbstractScope parent) /// /// Gets the parent scope. /// - public AbstractScope Parent - { - get { return _parent; } - } + public AbstractScope Parent => _parent; #endregion } diff --git a/src/Mages.Core/Ast/AbstractScopeStack.cs b/src/Mages.Core/Ast/AbstractScopeStack.cs index 775c79c0..74b4abcc 100644 --- a/src/Mages.Core/Ast/AbstractScopeStack.cs +++ b/src/Mages.Core/Ast/AbstractScopeStack.cs @@ -12,10 +12,7 @@ public AbstractScopeStack(AbstractScope root) _scopes.Push(root); } - public AbstractScope Current - { - get { return _scopes.Peek(); } - } + public AbstractScope Current => _scopes.Peek(); public void PushNew() { diff --git a/src/Mages.Core/Ast/Expressions/ArgumentsExpression.cs b/src/Mages.Core/Ast/Expressions/ArgumentsExpression.cs index bcb6985c..b8539d60 100644 --- a/src/Mages.Core/Ast/Expressions/ArgumentsExpression.cs +++ b/src/Mages.Core/Ast/Expressions/ArgumentsExpression.cs @@ -31,18 +31,12 @@ public ArgumentsExpression(IExpression[] arguments, TextPosition start, TextPosi /// /// Gets the stored arguments. /// - public IExpression[] Arguments - { - get { return _arguments; } - } + public IExpression[] Arguments => _arguments; /// /// Gets the number of arguments. /// - public Int32 Count - { - get { return _arguments.Length; } - } + public Int32 Count => _arguments.Length; #endregion diff --git a/src/Mages.Core/Ast/Expressions/AssignableExpression.cs b/src/Mages.Core/Ast/Expressions/AssignableExpression.cs index 842e50e1..c956ff87 100644 --- a/src/Mages.Core/Ast/Expressions/AssignableExpression.cs +++ b/src/Mages.Core/Ast/Expressions/AssignableExpression.cs @@ -24,10 +24,7 @@ public AssignableExpression(TextPosition start, TextPosition end) /// /// Gets if the expression is assignable. /// - public Boolean IsAssignable - { - get { return true; } - } + public Boolean IsAssignable => true; #endregion } diff --git a/src/Mages.Core/Ast/Expressions/AssignmentExpression.cs b/src/Mages.Core/Ast/Expressions/AssignmentExpression.cs index 9726e718..6d614052 100644 --- a/src/Mages.Core/Ast/Expressions/AssignmentExpression.cs +++ b/src/Mages.Core/Ast/Expressions/AssignmentExpression.cs @@ -33,10 +33,7 @@ public AssignmentExpression(IExpression variable, IExpression value) /// /// Gets the variable (value on the left side). /// - public IExpression Variable - { - get { return _variable; } - } + public IExpression Variable => _variable; /// /// Gets the variable name, if any. @@ -59,10 +56,7 @@ public String VariableName /// /// Gets the value on the right side. /// - public IExpression Value - { - get { return _value; } - } + public IExpression Value => _value; #endregion diff --git a/src/Mages.Core/Ast/Expressions/AwaitExpression.cs b/src/Mages.Core/Ast/Expressions/AwaitExpression.cs index 62484b3c..6f6f194b 100644 --- a/src/Mages.Core/Ast/Expressions/AwaitExpression.cs +++ b/src/Mages.Core/Ast/Expressions/AwaitExpression.cs @@ -29,10 +29,7 @@ public AwaitExpression(TextPosition start, IExpression payload) /// /// Gets the carried payload to be awaited. /// - public IExpression Payload - { - get { return _payload; } - } + public IExpression Payload => _payload; #endregion diff --git a/src/Mages.Core/Ast/Expressions/BaseExpression.cs b/src/Mages.Core/Ast/Expressions/BaseExpression.cs index 5adee8b5..e69d3c1d 100644 --- a/src/Mages.Core/Ast/Expressions/BaseExpression.cs +++ b/src/Mages.Core/Ast/Expressions/BaseExpression.cs @@ -30,18 +30,12 @@ public BaseExpression(TextPosition start, TextPosition end) /// /// Gets the start position of the expression. /// - public TextPosition Start - { - get { return _start; } - } + public TextPosition Start => _start; /// /// Gets the end position of the expression. /// - public TextPosition End - { - get { return _end; } - } + public TextPosition End => _end; #endregion } diff --git a/src/Mages.Core/Ast/Expressions/BinaryExpression.cs b/src/Mages.Core/Ast/Expressions/BinaryExpression.cs index 7e849894..c0e0f8cb 100644 --- a/src/Mages.Core/Ast/Expressions/BinaryExpression.cs +++ b/src/Mages.Core/Ast/Expressions/BinaryExpression.cs @@ -35,26 +35,17 @@ public BinaryExpression(IExpression left, IExpression right, String op) /// /// Gets the value on the left side. /// - public IExpression LValue - { - get { return _left; } - } + public IExpression LValue => _left; /// /// Gets the value on the right side. /// - public IExpression RValue - { - get { return _right; } - } + public IExpression RValue => _right; /// /// Gets the associated operator string. /// - public String Operator - { - get { return _operator; } - } + public String Operator => _operator; #endregion diff --git a/src/Mages.Core/Ast/Expressions/CallExpression.cs b/src/Mages.Core/Ast/Expressions/CallExpression.cs index a90be0c7..aa541ba9 100644 --- a/src/Mages.Core/Ast/Expressions/CallExpression.cs +++ b/src/Mages.Core/Ast/Expressions/CallExpression.cs @@ -31,18 +31,12 @@ public CallExpression(IExpression function, ArgumentsExpression arguments) /// /// Gets the associated function. /// - public IExpression Function - { - get { return _function; } - } + public IExpression Function => _function; /// /// Gets the arguments to pass to the function. /// - public ArgumentsExpression Arguments - { - get { return _arguments; } - } + public ArgumentsExpression Arguments => _arguments; #endregion diff --git a/src/Mages.Core/Ast/Expressions/ComputingExpression.cs b/src/Mages.Core/Ast/Expressions/ComputingExpression.cs index f11dfdd3..a3b72239 100644 --- a/src/Mages.Core/Ast/Expressions/ComputingExpression.cs +++ b/src/Mages.Core/Ast/Expressions/ComputingExpression.cs @@ -24,10 +24,7 @@ public ComputingExpression(TextPosition start, TextPosition end) /// /// Gets if the expression is assignable. /// - public Boolean IsAssignable - { - get { return false; } - } + public Boolean IsAssignable => false; #endregion } diff --git a/src/Mages.Core/Ast/Expressions/ConditionalExpression.cs b/src/Mages.Core/Ast/Expressions/ConditionalExpression.cs index ea573577..a63cadd3 100644 --- a/src/Mages.Core/Ast/Expressions/ConditionalExpression.cs +++ b/src/Mages.Core/Ast/Expressions/ConditionalExpression.cs @@ -33,26 +33,17 @@ public ConditionalExpression(IExpression condition, IExpression primary, IExpres /// /// Gets the condition. /// - public IExpression Condition - { - get { return _condition; } - } + public IExpression Condition => _condition; /// /// Gets the primary selected value. /// - public IExpression Primary - { - get { return _primary; } - } + public IExpression Primary => _primary; /// /// Gets the alternative selected value. /// - public IExpression Secondary - { - get { return _secondary; } - } + public IExpression Secondary => _secondary; #endregion diff --git a/src/Mages.Core/Ast/Expressions/ConstantExpression.cs b/src/Mages.Core/Ast/Expressions/ConstantExpression.cs index 249f98e7..480fa7ba 100644 --- a/src/Mages.Core/Ast/Expressions/ConstantExpression.cs +++ b/src/Mages.Core/Ast/Expressions/ConstantExpression.cs @@ -33,10 +33,7 @@ public ConstantExpression(Object value, TextPosition start, TextPosition end) /// /// Gets the carried value. /// - public Object Value - { - get { return _value; } - } + public Object Value => _value; #endregion diff --git a/src/Mages.Core/Ast/Expressions/DeleteExpression.cs b/src/Mages.Core/Ast/Expressions/DeleteExpression.cs index 7b123bdb..e86b58c1 100644 --- a/src/Mages.Core/Ast/Expressions/DeleteExpression.cs +++ b/src/Mages.Core/Ast/Expressions/DeleteExpression.cs @@ -31,10 +31,7 @@ public DeleteExpression(TextPosition start, IExpression payload) /// /// Gets the stored payload. /// - public IExpression Payload - { - get { return _payload; } - } + public IExpression Payload => _payload; #endregion diff --git a/src/Mages.Core/Ast/Expressions/FunctionExpression.cs b/src/Mages.Core/Ast/Expressions/FunctionExpression.cs index 2a00bb24..d1cec419 100644 --- a/src/Mages.Core/Ast/Expressions/FunctionExpression.cs +++ b/src/Mages.Core/Ast/Expressions/FunctionExpression.cs @@ -33,26 +33,17 @@ public FunctionExpression(AbstractScope scope, ParameterExpression parameters, I /// /// Gets the associated abstract scope. /// - public AbstractScope Scope - { - get { return _scope; } - } + public AbstractScope Scope => _scope; /// /// Gets the defined parameters. /// - public ParameterExpression Parameters - { - get { return _parameters; } - } + public ParameterExpression Parameters => _parameters; /// /// Gets the body to use. /// - public IStatement Body - { - get { return _body; } - } + public IStatement Body => _body; #endregion diff --git a/src/Mages.Core/Ast/Expressions/IdentifierExpression.cs b/src/Mages.Core/Ast/Expressions/IdentifierExpression.cs index 5df89846..ba165f74 100644 --- a/src/Mages.Core/Ast/Expressions/IdentifierExpression.cs +++ b/src/Mages.Core/Ast/Expressions/IdentifierExpression.cs @@ -31,10 +31,7 @@ public IdentifierExpression(String name, TextPosition start, TextPosition end) /// /// Gets the name of the identifier. /// - public String Name - { - get { return _name; } - } + public String Name => _name; #endregion diff --git a/src/Mages.Core/Ast/Expressions/InterpolatedExpression.cs b/src/Mages.Core/Ast/Expressions/InterpolatedExpression.cs index ebf32116..df651f45 100644 --- a/src/Mages.Core/Ast/Expressions/InterpolatedExpression.cs +++ b/src/Mages.Core/Ast/Expressions/InterpolatedExpression.cs @@ -33,18 +33,12 @@ public InterpolatedExpression(ConstantExpression format, IExpression[] replaceme /// /// Gets the formatting string. /// - public ConstantExpression Format - { - get { return _format; } - } + public ConstantExpression Format => _format; /// /// Gets the associated replacements. /// - public IExpression[] Replacements - { - get { return _replacements; } - } + public IExpression[] Replacements => _replacements; #endregion diff --git a/src/Mages.Core/Ast/Expressions/InvalidExpression.cs b/src/Mages.Core/Ast/Expressions/InvalidExpression.cs index 1ccb08d6..a96595af 100644 --- a/src/Mages.Core/Ast/Expressions/InvalidExpression.cs +++ b/src/Mages.Core/Ast/Expressions/InvalidExpression.cs @@ -31,18 +31,12 @@ public InvalidExpression(ErrorCode error, ITextRange payload) /// /// Gets the payload covered by the container. /// - public ITextRange Payload - { - get { return _payload; } - } + public ITextRange Payload => _payload; /// /// Gets the associated error code. /// - public ErrorCode Error - { - get { return _error; } - } + public ErrorCode Error => _error; #endregion diff --git a/src/Mages.Core/Ast/Expressions/MatrixExpression.cs b/src/Mages.Core/Ast/Expressions/MatrixExpression.cs index 59fe46b0..639122fc 100644 --- a/src/Mages.Core/Ast/Expressions/MatrixExpression.cs +++ b/src/Mages.Core/Ast/Expressions/MatrixExpression.cs @@ -29,10 +29,7 @@ public MatrixExpression(IExpression[][] values, TextPosition start, TextPosition /// /// Gets the initialized values. /// - public IExpression[][] Values - { - get { return _values; } - } + public IExpression[][] Values => _values; #endregion diff --git a/src/Mages.Core/Ast/Expressions/MemberExpression.cs b/src/Mages.Core/Ast/Expressions/MemberExpression.cs index e7c177a1..67e36801 100644 --- a/src/Mages.Core/Ast/Expressions/MemberExpression.cs +++ b/src/Mages.Core/Ast/Expressions/MemberExpression.cs @@ -31,18 +31,12 @@ public MemberExpression(IExpression obj, IExpression member) /// /// Gets the associated object expression. /// - public IExpression Object - { - get { return _obj; } - } + public IExpression Object => _obj; /// /// Gets the associated member access. /// - public IExpression Member - { - get { return _member; } - } + public IExpression Member => _member; #endregion diff --git a/src/Mages.Core/Ast/Expressions/ObjectExpression.cs b/src/Mages.Core/Ast/Expressions/ObjectExpression.cs index 93aefd6e..2d44a537 100644 --- a/src/Mages.Core/Ast/Expressions/ObjectExpression.cs +++ b/src/Mages.Core/Ast/Expressions/ObjectExpression.cs @@ -29,10 +29,7 @@ public ObjectExpression(IExpression[] values, TextPosition start, TextPosition e /// /// Gets the contained expressions. /// - public IExpression[] Values - { - get { return _values; } - } + public IExpression[] Values => _values; #endregion diff --git a/src/Mages.Core/Ast/Expressions/ParameterExpression.cs b/src/Mages.Core/Ast/Expressions/ParameterExpression.cs index 06236f01..25caf01b 100644 --- a/src/Mages.Core/Ast/Expressions/ParameterExpression.cs +++ b/src/Mages.Core/Ast/Expressions/ParameterExpression.cs @@ -30,10 +30,7 @@ public ParameterExpression(IExpression[] parameters, TextPosition start, TextPos /// /// Gets the contained expressions. /// - public IExpression[] Parameters - { - get { return _parameters; } - } + public IExpression[] Parameters => _parameters; /// /// Gets the available parameter names. diff --git a/src/Mages.Core/Ast/Expressions/PostUnaryExpression.cs b/src/Mages.Core/Ast/Expressions/PostUnaryExpression.cs index 875b1e73..db3488c1 100644 --- a/src/Mages.Core/Ast/Expressions/PostUnaryExpression.cs +++ b/src/Mages.Core/Ast/Expressions/PostUnaryExpression.cs @@ -33,18 +33,12 @@ public PostUnaryExpression(IExpression value, TextPosition end, String op) /// /// Gets the used value. /// - public IExpression Value - { - get { return _value; } - } + public IExpression Value => _value; /// /// Gets the operator string. /// - public String Operator - { - get { return _operator; } - } + public String Operator => _operator; #endregion diff --git a/src/Mages.Core/Ast/Expressions/PreUnaryExpression.cs b/src/Mages.Core/Ast/Expressions/PreUnaryExpression.cs index ada093a4..49b54b39 100644 --- a/src/Mages.Core/Ast/Expressions/PreUnaryExpression.cs +++ b/src/Mages.Core/Ast/Expressions/PreUnaryExpression.cs @@ -33,18 +33,12 @@ public PreUnaryExpression(TextPosition start, IExpression value, String op) /// /// Gets the used value. /// - public IExpression Value - { - get { return _value; } - } + public IExpression Value => _value; /// /// Gets the operator string. /// - public String Operator - { - get { return _operator; } - } + public String Operator => _operator; #endregion diff --git a/src/Mages.Core/Ast/Expressions/PropertyExpression.cs b/src/Mages.Core/Ast/Expressions/PropertyExpression.cs index 3afe4c16..045b059a 100644 --- a/src/Mages.Core/Ast/Expressions/PropertyExpression.cs +++ b/src/Mages.Core/Ast/Expressions/PropertyExpression.cs @@ -31,18 +31,12 @@ public PropertyExpression(IExpression name, IExpression value) /// /// Gets the name of the property. /// - public IExpression Name - { - get { return _name; } - } + public IExpression Name => _name; /// /// Gets the value of the property. /// - public IExpression Value - { - get { return _value; } - } + public IExpression Value => _value; #endregion diff --git a/src/Mages.Core/Ast/Expressions/RangeExpression.cs b/src/Mages.Core/Ast/Expressions/RangeExpression.cs index 36d46c08..b557a7e9 100644 --- a/src/Mages.Core/Ast/Expressions/RangeExpression.cs +++ b/src/Mages.Core/Ast/Expressions/RangeExpression.cs @@ -33,26 +33,17 @@ public RangeExpression(IExpression from, IExpression step, IExpression to) /// /// Gets the from expression. /// - public IExpression From - { - get { return _from; } - } + public IExpression From => _from; /// /// Gets the to expression. /// - public IExpression To - { - get { return _to; } - } + public IExpression To => _to; /// /// Gets the step expression. /// - public IExpression Step - { - get { return _step; } - } + public IExpression Step => _step; #endregion diff --git a/src/Mages.Core/Ast/Expressions/VariableExpression.cs b/src/Mages.Core/Ast/Expressions/VariableExpression.cs index 6b61026e..e070955f 100644 --- a/src/Mages.Core/Ast/Expressions/VariableExpression.cs +++ b/src/Mages.Core/Ast/Expressions/VariableExpression.cs @@ -33,18 +33,12 @@ public VariableExpression(String name, AbstractScope scope, TextPosition start, /// /// Gets the name of the variable. /// - public String Name - { - get { return _name; } - } + public String Name => _name; /// /// Gets the assigned abstract scope. /// - public AbstractScope Scope - { - get { return _scope; } - } + public AbstractScope Scope => _scope; #endregion diff --git a/src/Mages.Core/Ast/Statements/BaseStatement.cs b/src/Mages.Core/Ast/Statements/BaseStatement.cs index a1dd5ae5..f0b1b37a 100644 --- a/src/Mages.Core/Ast/Statements/BaseStatement.cs +++ b/src/Mages.Core/Ast/Statements/BaseStatement.cs @@ -30,18 +30,12 @@ public BaseStatement(TextPosition start, TextPosition end) /// /// Gets the start position of the statement. /// - public TextPosition Start - { - get { return _start; } - } + public TextPosition Start => _start; /// /// Gets the end position of the statement. /// - public TextPosition End - { - get { return _end; } - } + public TextPosition End => _end; #endregion } diff --git a/src/Mages.Core/Ast/Statements/BlockStatement.cs b/src/Mages.Core/Ast/Statements/BlockStatement.cs index d349221d..736c97ca 100644 --- a/src/Mages.Core/Ast/Statements/BlockStatement.cs +++ b/src/Mages.Core/Ast/Statements/BlockStatement.cs @@ -31,10 +31,7 @@ public BlockStatement(IStatement[] statements, TextPosition start, TextPosition /// /// Gets the contained statements. /// - public IEnumerable Statements - { - get { return _statements; } - } + public IEnumerable Statements => _statements; #endregion diff --git a/src/Mages.Core/Ast/Statements/BreakableStatement.cs b/src/Mages.Core/Ast/Statements/BreakableStatement.cs index a4ce6250..68deb3c0 100644 --- a/src/Mages.Core/Ast/Statements/BreakableStatement.cs +++ b/src/Mages.Core/Ast/Statements/BreakableStatement.cs @@ -32,10 +32,7 @@ public BreakableStatement(IStatement body, TextPosition start, TextPosition end) /// /// Gets the stored body. /// - public IStatement Body - { - get { return _body; } - } + public IStatement Body => _body; #endregion diff --git a/src/Mages.Core/Ast/Statements/CaseStatement.cs b/src/Mages.Core/Ast/Statements/CaseStatement.cs index a7323201..b1fd113b 100644 --- a/src/Mages.Core/Ast/Statements/CaseStatement.cs +++ b/src/Mages.Core/Ast/Statements/CaseStatement.cs @@ -29,10 +29,7 @@ public CaseStatement(IExpression condition, IStatement body) /// /// Gets the stored condition. /// - public IExpression Condition - { - get { return _condition; } - } + public IExpression Condition => _condition; #endregion diff --git a/src/Mages.Core/Ast/Statements/ForStatement.cs b/src/Mages.Core/Ast/Statements/ForStatement.cs index d7143b1a..3386f8e5 100644 --- a/src/Mages.Core/Ast/Statements/ForStatement.cs +++ b/src/Mages.Core/Ast/Statements/ForStatement.cs @@ -37,34 +37,22 @@ public ForStatement(Boolean declared, IExpression initialization, IExpression co /// /// Gets if the initialization variable is declared. /// - public Boolean IsDeclared - { - get { return _declared; } - } + public Boolean IsDeclared => _declared; /// /// Gets the stored initialization. /// - public IExpression Initialization - { - get { return _initialization; } - } + public IExpression Initialization => _initialization; /// /// Gets the stored condition. /// - public IExpression Condition - { - get { return _condition; } - } + public IExpression Condition => _condition; /// /// Gets the stored after thought. /// - public IExpression AfterThought - { - get { return _afterthought; } - } + public IExpression AfterThought => _afterthought; #endregion diff --git a/src/Mages.Core/Ast/Statements/IfStatement.cs b/src/Mages.Core/Ast/Statements/IfStatement.cs index d5d9f1e6..d7b661dd 100644 --- a/src/Mages.Core/Ast/Statements/IfStatement.cs +++ b/src/Mages.Core/Ast/Statements/IfStatement.cs @@ -33,26 +33,17 @@ public IfStatement(IExpression condition, IStatement primary, IStatement seconda /// /// Gets the stored condition. /// - public IExpression Condition - { - get { return _condition; } - } + public IExpression Condition => _condition; /// /// Gets the primary statement. /// - public IStatement Primary - { - get { return _primary; } - } + public IStatement Primary => _primary; /// /// Gets the secondary statement. /// - public IStatement Secondary - { - get { return _secondary; } - } + public IStatement Secondary => _secondary; #endregion diff --git a/src/Mages.Core/Ast/Statements/MatchStatement.cs b/src/Mages.Core/Ast/Statements/MatchStatement.cs index 5172d7ae..ff09e02c 100644 --- a/src/Mages.Core/Ast/Statements/MatchStatement.cs +++ b/src/Mages.Core/Ast/Statements/MatchStatement.cs @@ -31,18 +31,12 @@ public MatchStatement(IExpression reference, IStatement cases, TextPosition star /// /// Gets the stored reference. /// - public IExpression Reference - { - get { return _reference; } - } + public IExpression Reference => _reference; /// /// Gets the associated cases. /// - public IStatement Cases - { - get { return _cases; } - } + public IStatement Cases => _cases; #endregion diff --git a/src/Mages.Core/Ast/Statements/ReturnStatement.cs b/src/Mages.Core/Ast/Statements/ReturnStatement.cs index c0cb2973..0fb9e46d 100644 --- a/src/Mages.Core/Ast/Statements/ReturnStatement.cs +++ b/src/Mages.Core/Ast/Statements/ReturnStatement.cs @@ -34,10 +34,7 @@ public ReturnStatement(IExpression expression, TextPosition start, TextPosition /// /// Gets the stored payload. /// - public IExpression Expression - { - get { return _expression; } - } + public IExpression Expression => _expression; #endregion diff --git a/src/Mages.Core/Ast/Statements/SimpleStatement.cs b/src/Mages.Core/Ast/Statements/SimpleStatement.cs index edd2d09d..76fbaf82 100644 --- a/src/Mages.Core/Ast/Statements/SimpleStatement.cs +++ b/src/Mages.Core/Ast/Statements/SimpleStatement.cs @@ -29,10 +29,7 @@ public SimpleStatement(IExpression expression, TextPosition end) /// /// Gets the contained expression. /// - public IExpression Expression - { - get { return _expression; } - } + public IExpression Expression => _expression; #endregion diff --git a/src/Mages.Core/Ast/Statements/VarStatement.cs b/src/Mages.Core/Ast/Statements/VarStatement.cs index e37312e0..0e27ddab 100644 --- a/src/Mages.Core/Ast/Statements/VarStatement.cs +++ b/src/Mages.Core/Ast/Statements/VarStatement.cs @@ -31,10 +31,7 @@ public VarStatement(IExpression assignment, TextPosition start, TextPosition end /// /// Gets the associated assignment. /// - public IExpression Assignment - { - get { return _assignment; } - } + public IExpression Assignment => _assignment; #endregion diff --git a/src/Mages.Core/Ast/Statements/WhileStatement.cs b/src/Mages.Core/Ast/Statements/WhileStatement.cs index 6d407d07..c76bb377 100644 --- a/src/Mages.Core/Ast/Statements/WhileStatement.cs +++ b/src/Mages.Core/Ast/Statements/WhileStatement.cs @@ -29,10 +29,7 @@ public WhileStatement(IExpression condition, IStatement body, TextPosition start /// /// Gets the stored condition. /// - public IExpression Condition - { - get { return _condition; } - } + public IExpression Condition => _condition; #endregion diff --git a/src/Mages.Core/Ast/Walkers/CompletionTreeWalker.cs b/src/Mages.Core/Ast/Walkers/CompletionTreeWalker.cs index a3c2a051..10288da7 100644 --- a/src/Mages.Core/Ast/Walkers/CompletionTreeWalker.cs +++ b/src/Mages.Core/Ast/Walkers/CompletionTreeWalker.cs @@ -44,10 +44,7 @@ public CompletionTreeWalker(TextPosition position, IDictionary s /// /// Gets the list of autocomplete suggestions. /// - public IEnumerable Suggestions - { - get { return _completion.Where(m => !String.IsNullOrEmpty(m)).OrderBy(m => m, StringComparer.Ordinal); } - } + public IEnumerable Suggestions => _completion.Where(m => !String.IsNullOrEmpty(m)).OrderBy(m => m, StringComparer.Ordinal); #endregion diff --git a/src/Mages.Core/Ast/Walkers/OperationTreeWalker.cs b/src/Mages.Core/Ast/Walkers/OperationTreeWalker.cs index c9c15a3c..1b7dbb93 100644 --- a/src/Mages.Core/Ast/Walkers/OperationTreeWalker.cs +++ b/src/Mages.Core/Ast/Walkers/OperationTreeWalker.cs @@ -83,10 +83,7 @@ public OperationTreeWalker(List operations) #region Properties - Boolean IValidationContext.IsInLoop - { - get { return _loops.Count > 0 && _loops.Peek().Break != 0; } - } + Boolean IValidationContext.IsInLoop => _loops.Count > 0 && _loops.Peek().Break != 0; #endregion diff --git a/src/Mages.Core/Ast/Walkers/SymbolTreeWalker.cs b/src/Mages.Core/Ast/Walkers/SymbolTreeWalker.cs index 23f9ca43..9aafb7b9 100644 --- a/src/Mages.Core/Ast/Walkers/SymbolTreeWalker.cs +++ b/src/Mages.Core/Ast/Walkers/SymbolTreeWalker.cs @@ -56,18 +56,12 @@ public SymbolTreeWalker(IDictionary /// /// Gets the found potentially missing symbols. /// - public IEnumerable Missing - { - get { return _missing; } - } + public IEnumerable Missing => _missing; /// /// Gets the found resolved symbols. /// - public IEnumerable Symbols - { - get { return _collector.Keys; } - } + public IEnumerable Symbols => _collector.Keys; #endregion diff --git a/src/Mages.Core/Ast/Walkers/ValidationTreeWalker.cs b/src/Mages.Core/Ast/Walkers/ValidationTreeWalker.cs index d6e262bb..f3cdc843 100644 --- a/src/Mages.Core/Ast/Walkers/ValidationTreeWalker.cs +++ b/src/Mages.Core/Ast/Walkers/ValidationTreeWalker.cs @@ -34,10 +34,7 @@ public ValidationTreeWalker(List errors) #region Properties - Boolean IValidationContext.IsInLoop - { - get { return _loops.Count != 0 && _loops.Peek() != null; } - } + Boolean IValidationContext.IsInLoop => _loops.Count != 0 && _loops.Peek() != null; #endregion diff --git a/src/Mages.Core/Engine.cs b/src/Mages.Core/Engine.cs index c20f7418..2a1fc860 100644 --- a/src/Mages.Core/Engine.cs +++ b/src/Mages.Core/Engine.cs @@ -43,26 +43,17 @@ public Engine(Configuration configuration = null) /// /// Gets the used parser instance. /// - public IParser Parser - { - get { return _parser; } - } + public IParser Parser => _parser; /// /// Gets the used global scope. /// - public IDictionary Scope - { - get { return _scope; } - } + public IDictionary Scope => _scope; /// /// Gets the used global function layer. /// - public IDictionary Globals - { - get { return _scope.Parent; } - } + public IDictionary Globals => _scope.Parent; /// /// Gets the version of the engine. @@ -79,10 +70,7 @@ public String Version /// /// Gets the currently loaded plugins. /// - public IEnumerable Plugins - { - get { return _plugins; } - } + public IEnumerable Plugins => _plugins; #endregion diff --git a/src/Mages.Core/Mages.Core.csproj b/src/Mages.Core/Mages.Core.csproj index 841ef06b..246bfbe5 100644 --- a/src/Mages.Core/Mages.Core.csproj +++ b/src/Mages.Core/Mages.Core.csproj @@ -5,5 +5,6 @@ Mages.Core A lightweight parser / interpreter for mathematical expressions. bin\$(Configuration)\$(TargetFramework)\Mages.Core.xml + latest \ No newline at end of file diff --git a/src/Mages.Core/ParameterDefinition.cs b/src/Mages.Core/ParameterDefinition.cs index 2094f786..c2008775 100644 --- a/src/Mages.Core/ParameterDefinition.cs +++ b/src/Mages.Core/ParameterDefinition.cs @@ -22,18 +22,12 @@ public ParameterDefinition(String name, Boolean required) /// /// Gets the name of the parameter. /// - public String Name - { - get { return _name; } - } + public String Name => _name; /// /// Gets if the parameter is required. /// - public Boolean IsRequired - { - get { return _required; } - } + public Boolean IsRequired => _required; /// /// Gets the hash code. diff --git a/src/Mages.Core/ParseError.cs b/src/Mages.Core/ParseError.cs index 90e6e872..158c0720 100644 --- a/src/Mages.Core/ParseError.cs +++ b/src/Mages.Core/ParseError.cs @@ -32,26 +32,17 @@ public ParseError(ErrorCode code, ITextRange range) /// /// Gets the start position of the error. /// - public TextPosition Start - { - get { return _range.Start; } - } + public TextPosition Start => _range.Start; /// /// Gets the end position of the error. /// - public TextPosition End - { - get { return _range.End; } - } + public TextPosition End => _range.End; /// /// Gets the code of the error. /// - public ErrorCode Code - { - get { return _code; } - } + public ErrorCode Code => _code; #endregion } diff --git a/src/Mages.Core/Plugin.cs b/src/Mages.Core/Plugin.cs index 7bb37f1b..07b5b1c4 100644 --- a/src/Mages.Core/Plugin.cs +++ b/src/Mages.Core/Plugin.cs @@ -46,18 +46,12 @@ public String Name /// /// Gets the plugin's meta data. /// - public IEnumerable> MetaData - { - get { return _metaData; } - } + public IEnumerable> MetaData => _metaData; /// /// Gets the plugin's content. /// - public IEnumerable> Content - { - get { return _content; } - } + public IEnumerable> Content => _content; #endregion } diff --git a/src/Mages.Core/Runtime/BaseScope.cs b/src/Mages.Core/Runtime/BaseScope.cs index 9339656c..433144d2 100644 --- a/src/Mages.Core/Runtime/BaseScope.cs +++ b/src/Mages.Core/Runtime/BaseScope.cs @@ -15,10 +15,7 @@ public BaseScope(IDictionary scope, IDictionary _parent = parent; } - public IDictionary Parent - { - get { return _parent; } - } + public IDictionary Parent => _parent; public Object this[String key] { @@ -26,25 +23,13 @@ public Object this[String key] set { SetValue(key, value); } } - public Int32 Count - { - get { return _scope.Count; } - } + public Int32 Count => _scope.Count; - public Boolean IsReadOnly - { - get { return false; } - } + public Boolean IsReadOnly => false; - public ICollection Keys - { - get { return _scope.Keys; } - } + public ICollection Keys => _scope.Keys; - public ICollection Values - { - get { return _scope.Values; } - } + public ICollection Values => _scope.Values; public void Add(KeyValuePair item) { diff --git a/src/Mages.Core/Runtime/BinaryOperators.cs b/src/Mages.Core/Runtime/BinaryOperators.cs index 19a77a6c..a56505cd 100644 --- a/src/Mages.Core/Runtime/BinaryOperators.cs +++ b/src/Mages.Core/Runtime/BinaryOperators.cs @@ -3,12 +3,14 @@ using Mages.Core.Runtime.Converters; using Mages.Core.Runtime.Functions; using System; + using System.Numerics; static class BinaryOperators { #region Converter Fields private static readonly Func AsNumber = m => m.ToNumber(); + private static readonly Func AsComplex = m => m.ToComplex(); #endregion @@ -16,6 +18,8 @@ static class BinaryOperators private static readonly Func AddNumbers = (y, x) => x + y; private static readonly Func AddMatrices = (y, x) => x.Add(y); + private static readonly Func AddCNumbers = (y, x) => x + y; + private static readonly Func AddCMatrices = (y, x) => x.Add(y); private static readonly Func AddStrings = (y, x) => String.Concat(x, y); private static readonly Func AddAnyStr = (y, x) => String.Concat(x, Stringify.This(y)); private static readonly Func AddStrAny = (y, x) => String.Concat(Stringify.This(x), y); @@ -160,6 +164,8 @@ public static Object Add(Object[] args) { return If.Is(args, AddNumbers) ?? If.Is(args, AddMatrices) ?? + If.Is(args, AddCNumbers) ?? + If.Is(args, AddCMatrices) ?? If.Is(args, AddStrings) ?? If.Is(args, AddAnyStr) ?? If.Is(args, AddStrAny) ?? @@ -297,10 +303,7 @@ public static Object Leq(Object[] args) (args[1].ToNumber() <= args[0].ToNumber()); } - public static Object Pipe(Object[] args) - { - return If.Is(args, InvokeFunction); - } + public static Object Pipe(Object[] args) => If.Is(args, InvokeFunction); #endregion } diff --git a/src/Mages.Core/Runtime/Converters/ArrayConverters.cs b/src/Mages.Core/Runtime/Converters/ArrayConverters.cs index b17931c3..05cd1b7f 100644 --- a/src/Mages.Core/Runtime/Converters/ArrayConverters.cs +++ b/src/Mages.Core/Runtime/Converters/ArrayConverters.cs @@ -3,6 +3,7 @@ using System; using System.Collections; using System.Collections.Generic; + using System.Numerics; static class ArrayConverters { @@ -24,6 +25,14 @@ public static Func Get(Type from, Type to, Func return ConvertArray(to, converter, values, values.Length); }; } + else if (typeof(Complex[,]).IsAssignableFrom(from)) + { + return mat => + { + var values = (Complex[,])mat; + return ConvertArray(to, converter, values, values.Length); + }; + } else if (typeof(String).IsAssignableFrom(from)) { return str => diff --git a/src/Mages.Core/Runtime/Converters/ConverterExtensions.cs b/src/Mages.Core/Runtime/Converters/ConverterExtensions.cs index 6af54603..3cfa1864 100644 --- a/src/Mages.Core/Runtime/Converters/ConverterExtensions.cs +++ b/src/Mages.Core/Runtime/Converters/ConverterExtensions.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Globalization; using System.Linq; + using System.Numerics; /// /// A set of useful extension methods for type conversions. @@ -15,16 +16,17 @@ public static class ConverterExtensions /// /// The value to get the type of. /// The MAGES type string. - public static String ToType(this Object value) + public static String ToType(this Object value) => value switch { - if (value is Double) return "Number"; - if (value is String) return "String"; - if (value is Boolean) return "Boolean"; - if (value is Double[,]) return "Matrix"; - if (value is Function) return "Function"; - if (value is IDictionary) return "Object"; - return "Undefined"; - } + Double _ => "Number", + Complex _ => "Complex", + String _ => "String", + Boolean _ => "Boolean", + Double[,] or Complex[,] _ =>"Matrix", + Function _ => "Function", + IDictionary _ => "Object", + _ => "Undefined", + }; /// /// Converts the given value to the specified type. @@ -32,21 +34,17 @@ public static String ToType(this Object value) /// The type to convert. /// The destination type. /// The converted value. - public static Object To(this Object value, String type) + public static Object To(this Object value, String type) => type switch { - switch (type) - { - case "Number": return value.ToNumber(); - case "String": return Stringify.This(value); - case "Boolean": return value.ToBoolean(); - case "Matrix": return value.ToNumber().ToMatrix(); - case "Function": return value as Function; - case "Object": return value as IDictionary; - case "Undefined": return null; - } - - return null; - } + "Number" => value.ToNumber(), + "String" => Stringify.This(value), + "Boolean" => value.ToBoolean(), + "Matrix" => value.ToNumber().ToMatrix(), + "Function" => value as Function, + "Object" => value as IDictionary, + "Undefined" => null, + _ => null, + }; /// /// Returns the boolean representation of the given value. @@ -55,30 +53,27 @@ public static Object To(this Object value, String type) /// The boolean representation of the value. public static Boolean ToBoolean(this Object value) { - if (value is Boolean) + if (value is Boolean bval) { - return (Boolean)value; + return bval; } else if (value != null) { var nval = value as Double?; - var sval = value as String; - var mval = value as Double[,]; - var oval = value as IDictionary; if (nval.HasValue) { return nval.Value.ToBoolean(); } - else if (sval != null) + else if (value is String sval) { return sval.ToBoolean(); } - else if (mval != null) + else if (value is Double[,] mval) { return mval.ToBoolean(); } - else if (oval != null) + else if (value is IDictionary oval) { return oval.ToBoolean(); } @@ -94,40 +89,28 @@ public static Boolean ToBoolean(this Object value) /// /// The value to convert. /// The boolean representation of the value. - public static Boolean ToBoolean(this Double value) - { - return value != 0.0;; - } + public static Boolean ToBoolean(this Double value) => value != 0.0; /// /// Returns the boolean representation of the given string value. /// /// The value to convert. /// The boolean representation of the value. - public static Boolean ToBoolean(this String value) - { - return value.Length > 0; - } + public static Boolean ToBoolean(this String value) => value.Length > 0; /// /// Returns the boolean representation of the given matrix value. /// /// The matrix to convert. /// The boolean representation of the value. - public static Boolean ToBoolean(this Double[,] matrix) - { - return matrix.AnyTrue(); - } + public static Boolean ToBoolean(this Double[,] matrix) => matrix.AnyTrue(); /// /// Returns the boolean representation of the given object value. /// /// The obj to convert. /// The boolean representation of the value. - public static Boolean ToBoolean(this IDictionary obj) - { - return obj.Count > 0; - } + public static Boolean ToBoolean(this IDictionary obj) => obj.Count > 0; /// /// Returns the object representation of the given value. @@ -136,13 +119,12 @@ public static Boolean ToBoolean(this IDictionary obj) /// The object representation of the value. public static IDictionary ToObject(this Object value) { - if (value is IDictionary) + if (value is IDictionary dict) { - return (IDictionary)value; + return dict; } - else if (value is Double[,]) + else if (value is Double[,] matrix) { - var matrix = (Double[,])value; var result = new Dictionary(); var rows = matrix.GetRows(); var columns = matrix.GetColumns(); @@ -177,25 +159,23 @@ public static IDictionary ToObject(this Object value) /// The number representation of the value. public static Double ToNumber(this Object value) { - if (value is Double) + if (value is Double dval) { - return (Double)value; + return dval; } else if (value != null) { var bval = value as Boolean?; - var sval = value as String; - var mval = value as Double[,]; if (bval.HasValue) { return bval.Value.ToNumber(); } - else if (sval != null) + else if (value is String sval) { return sval.ToNumber(); } - else if (mval != null) + else if (value is Double[,] mval) { return mval.ToNumber(); } @@ -205,15 +185,34 @@ public static Double ToNumber(this Object value) } /// - /// Returns the number representation of the given boolean value. + /// Returns the complex representation of the given value. /// /// The value to convert. - /// The number representation of the value. - public static Double ToNumber(this Boolean value) + /// The complex representation of the value. + public static Complex ToComplex(this Object value) { - return value ? 1.0 : 0.0; + if (value is Complex c) + { + return c; + } + + return value.ToNumber(); } + /// + /// Returns the number representation of the given boolean value. + /// + /// The value to convert. + /// The number representation of the value. + public static Double ToNumber(this Boolean value) => value ? 1.0 : 0.0; + + /// + /// Returns the complex representation of the given boolean value. + /// + /// The value to convert. + /// The complex representation of the value. + public static Complex ToComplex(this Boolean value) => value ? Complex.One : Complex.Zero; + /// /// Returns the number representation of the given string value. /// @@ -221,9 +220,7 @@ public static Double ToNumber(this Boolean value) /// The number representation of the value. public static Double ToNumber(this String value) { - var result = default(Double); - - if (!Double.TryParse(value, NumberStyles.Any, CultureInfo.InvariantCulture, out result)) + if (!Double.TryParse(value, NumberStyles.Any, CultureInfo.InvariantCulture, out var result)) { return Double.NaN; } @@ -246,32 +243,48 @@ public static Double ToNumber(this Double[,] matrix) return Double.NaN; } + /// + /// Returns the number representation of the given matrix value. + /// + /// The matrix to convert. + /// The number representation of the value. + public static Complex ToNumber(this Complex[,] matrix) + { + if (matrix.GetRows() == 1 && matrix.GetColumns() == 1) + { + return matrix[0, 0]; + } + + return Double.NaN; + } + /// /// Returns the matrix representation of the given number value. /// /// The value to convert. /// The matrix representation of the value. - public static Double[,] ToMatrix(this Double value) - { - return new Double[1, 1] { { value } }; - } + public static Double[,] ToMatrix(this Double value) => new Double[1, 1] { { value } }; + + /// + /// Returns the matrix representation of the given number value. + /// + /// The value to convert. + /// The matrix representation of the value. + public static Complex[,] ToMatrix(this Complex value) => new Complex[1, 1] { { value } }; /// /// Returns the matrix representation of the given boolean value. /// /// The value to convert. /// The matrix representation of the value. - public static Double[,] ToMatrix(this Boolean value) - { - return new Double[1, 1] { { value.ToNumber() } }; - } + public static Double[,] ToMatrix(this Boolean value) => new Double[1, 1] { { value.ToNumber() } }; /// /// Returns the matrix representation of the given numeric values. /// /// The value to convert. /// The matrix representation of the value. - public static Double[,] ToMatrix(this IEnumerable value) + public static T[,] ToMatrix(this IEnumerable value) { var source = value.ToList(); return source.ToMatrix(); @@ -282,10 +295,10 @@ public static Double ToNumber(this Double[,] matrix) /// /// The value to convert. /// The matrix representation of the value. - public static Double[,] ToMatrix(this List value) + public static T[,] ToMatrix(this List value) { var length = value.Count; - var matrix = new Double[1, length]; + var matrix = new T[1, length]; for (var i = 0; i < length; i++) { @@ -300,11 +313,11 @@ public static Double ToNumber(this Double[,] matrix) /// /// The matrix to convert. /// The matrix representation of the value. - public static Double[] ToVector(this Double[,] matrix) + public static T[] ToVector(this T[,] matrix) { var rows = matrix.GetLength(0); var cols = matrix.GetLength(1); - var vec = new Double[rows * cols]; + var vec = new T[rows * cols]; var k = 0; for (var i = 0; i < rows; i++) @@ -323,11 +336,11 @@ public static Double[] ToVector(this Double[,] matrix) /// /// The matrix to convert. /// The list representation of the value. - public static List ToList(this Double[,] matrix) + public static List ToList(this T[,] matrix) { var rows = matrix.GetRows(); var cols = matrix.GetColumns(); - var list = new List(rows * cols); + var list = new List(rows * cols); for (var i = 0; i < rows; i++) { @@ -348,9 +361,9 @@ public static List ToList(this Double[,] matrix) /// True if the index could be retrieved, otherwise false. public static Boolean TryGetIndex(this Object obj, out Int32 value) { - if (obj is Double && ((Double)obj).IsInteger()) + if (obj is Double val && val.IsInteger()) { - value = (Int32)(Double)obj; + value = (Int32)val; return true; } else diff --git a/src/Mages.Core/Runtime/Converters/StandardConverters.cs b/src/Mages.Core/Runtime/Converters/StandardConverters.cs index 1a6b8ed8..c9b8311a 100644 --- a/src/Mages.Core/Runtime/Converters/StandardConverters.cs +++ b/src/Mages.Core/Runtime/Converters/StandardConverters.cs @@ -2,12 +2,14 @@ { using System; using System.Collections.Generic; + using System.Numerics; static class StandardConverters { public static readonly List List = new List { TypeConverter.Create(x => (Single)x), + TypeConverter.Create(x => new Complex(x, 0.0)), TypeConverter.Create(x => (Decimal)x), TypeConverter.Create(x => (Byte)Math.Max(0, Math.Min(255, x))), TypeConverter.Create(x => (Int16)x), @@ -21,10 +23,12 @@ static class StandardConverters TypeConverter.Create(x => x.ToMatrix()), TypeConverter.Create(x => x.ToNumber()), + TypeConverter.Create(x => new Complex(x.ToNumber(), 0.0)), TypeConverter.Create(x => x.ToBoolean()), TypeConverter.Create(x => x.Length > 0 ? x[0] : Char.MinValue), TypeConverter.Create(x => x.ToNumber()), + TypeConverter.Create(x => new Complex(x.ToNumber(), 0.0)), TypeConverter.Create(x => Stringify.This(x)), TypeConverter.Create(x => x.ToMatrix()), @@ -46,6 +50,17 @@ static class StandardConverters TypeConverter.Create(x => (Double)x), TypeConverter.Create(x => (Double)x), TypeConverter.Create(x => (Double)x), + + TypeConverter.Create(x => new Complex((Double)x, 0.0)), + TypeConverter.Create(x => new Complex((Double)x, 0.0)), + TypeConverter.Create(x => new Complex((Double)x, 0.0)), + TypeConverter.Create(x => new Complex((Double)x, 0.0)), + TypeConverter.Create(x => new Complex((Double)x, 0.0)), + TypeConverter.Create(x => new Complex((Double)x, 0.0)), + TypeConverter.Create(x => new Complex((Double)x, 0.0)), + TypeConverter.Create(x => new Complex((Double)x, 0.0)), + TypeConverter.Create(x => new Complex((Double)x, 0.0)), + TypeConverter.Create(x => x.ToString()), TypeConverter.Create(x => x.ToMatrix()), TypeConverter.Create, Double[,]>(x => x.ToMatrix()), diff --git a/src/Mages.Core/Runtime/Converters/TypeConverter.cs b/src/Mages.Core/Runtime/Converters/TypeConverter.cs index 02641733..1225f4c6 100644 --- a/src/Mages.Core/Runtime/Converters/TypeConverter.cs +++ b/src/Mages.Core/Runtime/Converters/TypeConverter.cs @@ -20,19 +20,10 @@ public static TypeConverter Create(Func converter) return new TypeConverter(typeof(TFrom), typeof(TTo), x => converter((TFrom)x)); } - public Type From - { - get { return _from; } - } + public Type From => _from; - public Type To - { - get { return _to; } - } + public Type To => _to; - public Func Converter - { - get { return _converter; } - } + public Func Converter => _converter; } } diff --git a/src/Mages.Core/Runtime/Functions/ComplexFunctions.cs b/src/Mages.Core/Runtime/Functions/ComplexFunctions.cs index c8daa082..d1abb985 100644 --- a/src/Mages.Core/Runtime/Functions/ComplexFunctions.cs +++ b/src/Mages.Core/Runtime/Functions/ComplexFunctions.cs @@ -11,44 +11,40 @@ public static class ComplexFunctions /// /// Exposes the complex constructor function. /// - public static readonly Function Cmplx = new Function(args => - { - return Curry.MinTwo(Cmplx, args) ?? - If.Is(args, (x, y) => new Complex(x, y)) ?? - Complex.Zero; - }); + public static readonly Function Cmplx = new Function(args => + Curry.MinTwo(Cmplx, args) ?? + If.Is(args, (x, y) => new Complex(x, y)) ?? + Complex.Zero + ); /// /// Exposes the complex conjugate function. /// public static readonly Function Conj = new Function(args => - { - return Curry.MinOne(Conj, args) ?? - If.Is(args, x => new Complex(x, 0)) ?? - If.Is(args, x => new Complex(x.Real, -x.Imaginary)) ?? - Double.NaN; - }); + Curry.MinOne(Conj, args) ?? + If.Is(args, x => new Complex(x, 0)) ?? + If.Is(args, x => new Complex(x.Real, -x.Imaginary)) ?? + Double.NaN + ); /// /// Exposes the complex real function. /// public static readonly Function Real = new Function(args => - { - return Curry.MinOne(Real, args) ?? - If.Is(args, x => x) ?? - If.Is(args, x => x.Real) ?? - Double.NaN; - }); + Curry.MinOne(Real, args) ?? + If.Is(args, x => x) ?? + If.Is(args, x => x.Real) ?? + Double.NaN + ); /// /// Exposes the complex imag function. /// public static readonly Function Imag = new Function(args => - { - return Curry.MinOne(Imag, args) ?? - If.Is(args, _ => 0.0) ?? - If.Is(args, x => x.Imaginary) ?? - Double.NaN; - }); + Curry.MinOne(Imag, args) ?? + If.Is(args, _ => 0.0) ?? + If.Is(args, x => x.Imaginary) ?? + Double.NaN + ); } } diff --git a/src/Mages.Core/Runtime/Functions/If.cs b/src/Mages.Core/Runtime/Functions/If.cs index e5119ab1..a8dd06cb 100644 --- a/src/Mages.Core/Runtime/Functions/If.cs +++ b/src/Mages.Core/Runtime/Functions/If.cs @@ -14,10 +14,8 @@ public static class If /// The arguments to check. /// The callback to invoke if fulfilled. /// The result of the callback or null. - public static Object Is(Object[] args, Func f) - { - return args[0] is T ? f((T)args[0]) : null; - } + public static Object Is(Object[] args, Func f) => + args[0] is T ? f((T)args[0]) : null; /// /// Checks if the first two values of the given arguments are of type @@ -28,10 +26,8 @@ public static Object Is(Object[] args, Func f) /// The arguments to check. /// The callback to invoke if fulfilled. /// The result of the callback or null. - public static Object Is(Object[] args, Func f) - { - return args[0] is T1 && args[1] is T2 ? f((T1)args[0], (T2)args[1]) : null; - } + public static Object Is(Object[] args, Func f) => + args[0] is T1 && args[1] is T2 ? f((T1)args[0], (T2)args[1]) : null; /// /// Checks if the first three values of the given arguments are of type @@ -43,10 +39,8 @@ public static Object Is(Object[] args, Func f) /// The arguments to check. /// The callback to invoke if fulfilled. /// The result of the callback or null. - public static Object Is(Object[] args, Func f) - { - return args[0] is T1 && args[1] is T2 && args[2] is T3 ? f((T1)args[0], (T2)args[1], (T3)args[2]) : null; - } + public static Object Is(Object[] args, Func f) => + args[0] is T1 && args[1] is T2 && args[2] is T3 ? f((T1)args[0], (T2)args[1], (T3)args[2]) : null; /// /// Checks if the first four values of the given arguments are of type @@ -59,11 +53,8 @@ public static Object Is(Object[] args, Func f) /// The arguments to check. /// The callback to invoke if fulfilled. /// The result of the callback or null. - public static Object Is(Object[] args, Func f) - { - return args[0] is T1 && args[1] is T2 && args[2] is T3 && args[3] is T4 ? - f((T1)args[0], (T2)args[1], (T3)args[2], (T4)args[3]) : null; - } + public static Object Is(Object[] args, Func f) => + args[0] is T1 && args[1] is T2 && args[2] is T3 && args[3] is T4 ? f((T1)args[0], (T2)args[1], (T3)args[2], (T4)args[3]) : null; /// /// Checks if the first three values of the given arguments are of type @@ -74,10 +65,8 @@ public static Object Is(Object[] args, FuncThe arguments to check. /// The callback to invoke if fulfilled. /// The result of the callback or null. - public static Object IsAnyT2(Object[] args, Func f) - { - return args[0] is T1 && args[2] is T3 ? f((T1)args[0], args[1], (T3)args[2]) : null; - } + public static Object IsAnyT2(Object[] args, Func f) => + args[0] is T1 && args[2] is T3 ? f((T1)args[0], args[1], (T3)args[2]) : null; /// /// Checks if the provided args are all non-null. Performs the conversion and invokes @@ -90,7 +79,7 @@ public static Object IsAnyT2(Object[] args, Func /// The result or null if the check was not successful. public static Object IsNotNull(Object[] args, Func converter, Func result) { - if (args[0] != null && args[1] != null) + if (args[0] is not null && args[1] is not null) { var left = converter.Invoke(args[0]); var right = converter.Invoke(args[1]); diff --git a/src/Mages.Core/Runtime/Functions/StandardFunctions.cs b/src/Mages.Core/Runtime/Functions/StandardFunctions.cs index cc410306..598270ba 100644 --- a/src/Mages.Core/Runtime/Functions/StandardFunctions.cs +++ b/src/Mages.Core/Runtime/Functions/StandardFunctions.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Linq; + using System.Numerics; /// /// The collection of all standard functions. @@ -225,6 +226,8 @@ public static class StandardFunctions return Curry.MinOne(Sqrt, args) ?? If.Is(args, x => Math.Sqrt(x)) ?? If.Is(args, x => x.ForEach(Math.Sqrt)) ?? + If.Is(args, x => Complex.Sqrt(x)) ?? + If.Is(args, x => x.ForEach(Complex.Sqrt)) ?? If.Is>(args, o => o.Map(Sqrt)) ?? Math.Sqrt(args[0].ToNumber()); }); @@ -237,6 +240,8 @@ public static class StandardFunctions return Curry.MinOne(Sign, args) ?? If.Is(args, x => Mathx.Sign(x)) ?? If.Is(args, x => x.ForEach(Mathx.Sign)) ?? + If.Is(args, x => Mathx.Sign(x)) ?? + If.Is(args, x => x.ForEach(Mathx.Sign)) ?? If.Is>(args, o => o.Map(Sign)) ?? Mathx.Sign(args[0].ToNumber()); }); @@ -249,6 +254,8 @@ public static class StandardFunctions return Curry.MinOne(Gamma, args) ?? If.Is(args, x => Mathx.Gamma(x)) ?? If.Is(args, x => x.ForEach(Mathx.Gamma)) ?? + If.Is(args, x => Mathx.Gamma(x)) ?? + If.Is(args, x => x.ForEach(Mathx.Gamma)) ?? If.Is>(args, o => o.Map(Gamma)) ?? Mathx.Gamma(args[0].ToNumber()); }); @@ -261,6 +268,8 @@ public static class StandardFunctions return Curry.MinOne(Ceil, args) ?? If.Is(args, x => Math.Ceiling(x)) ?? If.Is(args, x => x.ForEach(Math.Ceiling)) ?? + If.Is(args, x => Mathx.Ceiling(x)) ?? + If.Is(args, x => x.ForEach(Mathx.Ceiling)) ?? If.Is>(args, o => o.Map(Ceil)) ?? Math.Ceiling(args[0].ToNumber()); }); @@ -273,6 +282,8 @@ public static class StandardFunctions return Curry.MinOne(Floor, args) ?? If.Is(args, x => Math.Floor(x)) ?? If.Is(args, x => x.ForEach(Math.Floor)) ?? + If.Is(args, x => Mathx.Floor(x)) ?? + If.Is(args, x => x.ForEach(Mathx.Floor)) ?? If.Is>(args, o => o.Map(Floor)) ?? Math.Floor(args[0].ToNumber()); }); @@ -285,6 +296,8 @@ public static class StandardFunctions return Curry.MinOne(Round, args) ?? If.Is(args, x => Math.Round(x)) ?? If.Is(args, x => x.ForEach(Math.Round)) ?? + If.Is(args, x => Mathx.Round(x)) ?? + If.Is(args, x => x.ForEach(Mathx.Round)) ?? If.Is>(args, o => o.Map(Round)) ?? Math.Round(args[0].ToNumber()); }); @@ -297,6 +310,8 @@ public static class StandardFunctions return Curry.MinOne(Exp, args) ?? If.Is(args, x => Math.Exp(x)) ?? If.Is(args, x => x.ForEach(Math.Exp)) ?? + If.Is(args, x => Complex.Exp(x)) ?? + If.Is(args, x => x.ForEach(Complex.Exp)) ?? If.Is>(args, o => o.Map(Exp)) ?? Math.Exp(args[0].ToNumber()); }); @@ -309,6 +324,8 @@ public static class StandardFunctions return Curry.MinOne(Log, args) ?? If.Is(args, x => Math.Log(x)) ?? If.Is(args, x => x.ForEach(Math.Log)) ?? + If.Is(args, x => Complex.Log(x)) ?? + If.Is(args, x => x.ForEach(Complex.Log)) ?? If.Is>(args, o => o.Map(Log)) ?? Math.Log(args[0].ToNumber()); }); @@ -321,6 +338,8 @@ public static class StandardFunctions return Curry.MinOne(Log2, args) ?? If.Is(args, x => Mathx.Log2(x)) ?? If.Is(args, x => x.ForEach(Mathx.Log2)) ?? + If.Is(args, x => Mathx.Log2(x)) ?? + If.Is(args, x => x.ForEach(Mathx.Log2)) ?? If.Is>(args, o => o.Map(Log2)) ?? Math.Log(args[0].ToNumber()); }); @@ -333,6 +352,8 @@ public static class StandardFunctions return Curry.MinOne(Log10, args) ?? If.Is(args, x => Math.Log10(x)) ?? If.Is(args, x => x.ForEach(Math.Log10)) ?? + If.Is(args, x => Complex.Log10(x)) ?? + If.Is(args, x => x.ForEach(Complex.Log10)) ?? If.Is>(args, o => o.Map(Log10)) ?? Math.Log(args[0].ToNumber()); }); @@ -345,6 +366,8 @@ public static class StandardFunctions return Curry.MinOne(Sin, args) ?? If.Is(args, x => Math.Sin(x)) ?? If.Is(args, x => x.ForEach(Math.Sin)) ?? + If.Is(args, x => Complex.Sin(x)) ?? + If.Is(args, x => x.ForEach(Complex.Sin)) ?? If.Is>(args, o => o.Map(Sin)) ?? Math.Sin(args[0].ToNumber()); }); @@ -357,6 +380,8 @@ public static class StandardFunctions return Curry.MinOne(Cos, args) ?? If.Is(args, x => Math.Cos(x)) ?? If.Is(args, x => x.ForEach(Math.Cos)) ?? + If.Is(args, x => Complex.Cos(x)) ?? + If.Is(args, x => x.ForEach(Complex.Cos)) ?? If.Is>(args, o => o.Map(Cos)) ?? Math.Cos(args[0].ToNumber()); }); @@ -369,6 +394,8 @@ public static class StandardFunctions return Curry.MinOne(Tan, args) ?? If.Is(args, x => Math.Tan(x)) ?? If.Is(args, x => x.ForEach(Math.Tan)) ?? + If.Is(args, x => Complex.Tan(x)) ?? + If.Is(args, x => x.ForEach(Complex.Tan)) ?? If.Is>(args, o => o.Map(Tan)) ?? Math.Tan(args[0].ToNumber()); }); @@ -381,6 +408,8 @@ public static class StandardFunctions return Curry.MinOne(Cot, args) ?? If.Is(args, x => Mathx.Cot(x)) ?? If.Is(args, x => x.ForEach(Mathx.Cot)) ?? + If.Is(args, x => Mathx.Cot(x)) ?? + If.Is(args, x => x.ForEach(Mathx.Cot)) ?? If.Is>(args, o => o.Map(Cot)) ?? Mathx.Cot(args[0].ToNumber()); }); @@ -393,6 +422,8 @@ public static class StandardFunctions return Curry.MinOne(Sec, args) ?? If.Is(args, x => Mathx.Sec(x)) ?? If.Is(args, x => x.ForEach(Mathx.Sec)) ?? + If.Is(args, x => Mathx.Sec(x)) ?? + If.Is(args, x => x.ForEach(Mathx.Sec)) ?? If.Is>(args, o => o.Map(Sec)) ?? Mathx.Sec(args[0].ToNumber()); }); @@ -405,6 +436,8 @@ public static class StandardFunctions return Curry.MinOne(Csc, args) ?? If.Is(args, x => Mathx.Csc(x)) ?? If.Is(args, x => x.ForEach(Mathx.Csc)) ?? + If.Is(args, x => Mathx.Csc(x)) ?? + If.Is(args, x => x.ForEach(Mathx.Csc)) ?? If.Is>(args, o => o.Map(Csc)) ?? Mathx.Csc(args[0].ToNumber()); }); @@ -417,6 +450,8 @@ public static class StandardFunctions return Curry.MinOne(Sinh, args) ?? If.Is(args, x => Math.Sinh(x)) ?? If.Is(args, x => x.ForEach(Math.Sinh)) ?? + If.Is(args, x => Complex.Sinh(x)) ?? + If.Is(args, x => x.ForEach(Complex.Sinh)) ?? If.Is>(args, o => o.Map(Sinh)) ?? Math.Sinh(args[0].ToNumber()); }); @@ -429,6 +464,8 @@ public static class StandardFunctions return Curry.MinOne(Cosh, args) ?? If.Is(args, x => Math.Cosh(x)) ?? If.Is(args, x => x.ForEach(Math.Cosh)) ?? + If.Is(args, x => Complex.Cosh(x)) ?? + If.Is(args, x => x.ForEach(Complex.Cosh)) ?? If.Is>(args, o => o.Map(Cosh)) ?? Math.Cosh(args[0].ToNumber()); }); @@ -441,6 +478,8 @@ public static class StandardFunctions return Curry.MinOne(Tanh, args) ?? If.Is(args, x => Math.Tanh(x)) ?? If.Is(args, x => x.ForEach(Math.Tanh)) ?? + If.Is(args, x => Complex.Tanh(x)) ?? + If.Is(args, x => x.ForEach(Complex.Tanh)) ?? If.Is>(args, o => o.Map(Tanh)) ?? Math.Tanh(args[0].ToNumber()); }); @@ -453,6 +492,8 @@ public static class StandardFunctions return Curry.MinOne(Coth, args) ?? If.Is(args, x => Mathx.Coth(x)) ?? If.Is(args, x => x.ForEach(Mathx.Coth)) ?? + If.Is(args, x => Mathx.Coth(x)) ?? + If.Is(args, x => x.ForEach(Mathx.Coth)) ?? If.Is>(args, o => o.Map(Coth)) ?? Mathx.Coth(args[0].ToNumber()); }); @@ -465,6 +506,8 @@ public static class StandardFunctions return Curry.MinOne(Sech, args) ?? If.Is(args, x => Mathx.Sech(x)) ?? If.Is(args, x => x.ForEach(Mathx.Sech)) ?? + If.Is(args, x => Mathx.Sech(x)) ?? + If.Is(args, x => x.ForEach(Mathx.Sech)) ?? If.Is>(args, o => o.Map(Sech)) ?? Mathx.Sech(args[0].ToNumber()); }); @@ -477,6 +520,8 @@ public static class StandardFunctions return Curry.MinOne(Csch, args) ?? If.Is(args, x => Mathx.Csch(x)) ?? If.Is(args, x => x.ForEach(Mathx.Csch)) ?? + If.Is(args, x => Mathx.Csch(x)) ?? + If.Is(args, x => x.ForEach(Mathx.Csch)) ?? If.Is>(args, o => o.Map(Csch)) ?? Mathx.Csch(args[0].ToNumber()); }); @@ -489,6 +534,8 @@ public static class StandardFunctions return Curry.MinOne(ArcSin, args) ?? If.Is(args, x => Math.Asin(x)) ?? If.Is(args, x => x.ForEach(Math.Asin)) ?? + If.Is(args, x => Complex.Asin(x)) ?? + If.Is(args, x => x.ForEach(Complex.Asin)) ?? If.Is>(args, o => o.Map(ArcSin)) ?? Math.Asin(args[0].ToNumber()); }); @@ -501,6 +548,8 @@ public static class StandardFunctions return Curry.MinOne(ArcCos, args) ?? If.Is(args, x => Math.Acos(x)) ?? If.Is(args, x => x.ForEach(Math.Acos)) ?? + If.Is(args, x => Complex.Acos(x)) ?? + If.Is(args, x => x.ForEach(Complex.Acos)) ?? If.Is>(args, o => o.Map(ArcCos)) ?? Math.Acos(args[0].ToNumber()); }); @@ -513,6 +562,8 @@ public static class StandardFunctions return Curry.MinOne(ArcTan, args) ?? If.Is(args, x => Math.Atan(x)) ?? If.Is(args, x => x.ForEach(Math.Atan)) ?? + If.Is(args, x => Complex.Atan(x)) ?? + If.Is(args, x => x.ForEach(Complex.Atan)) ?? If.Is>(args, o => o.Map(ArcTan)) ?? Math.Atan(args[0].ToNumber()); }); @@ -525,6 +576,8 @@ public static class StandardFunctions return Curry.MinOne(ArcCot, args) ?? If.Is(args, x => Mathx.Acot(x)) ?? If.Is(args, x => x.ForEach(Mathx.Acot)) ?? + If.Is(args, x => Mathx.Acot(x)) ?? + If.Is(args, x => x.ForEach(Mathx.Acot)) ?? If.Is>(args, o => o.Map(ArcCot)) ?? Mathx.Acot(args[0].ToNumber()); }); @@ -537,6 +590,8 @@ public static class StandardFunctions return Curry.MinOne(ArcSec, args) ?? If.Is(args, x => Mathx.Asec(x)) ?? If.Is(args, x => x.ForEach(Mathx.Asec)) ?? + If.Is(args, x => Mathx.Asec(x)) ?? + If.Is(args, x => x.ForEach(Mathx.Asec)) ?? If.Is>(args, o => o.Map(ArcSec)) ?? Mathx.Asec(args[0].ToNumber()); }); @@ -549,6 +604,8 @@ public static class StandardFunctions return Curry.MinOne(ArcCsc, args) ?? If.Is(args, x => Mathx.Acsc(x)) ?? If.Is(args, x => x.ForEach(Mathx.Acsc)) ?? + If.Is(args, x => Mathx.Acsc(x)) ?? + If.Is(args, x => x.ForEach(Mathx.Acsc)) ?? If.Is>(args, o => o.Map(ArcCsc)) ?? Mathx.Acsc(args[0].ToNumber()); }); @@ -561,6 +618,8 @@ public static class StandardFunctions return Curry.MinOne(ArSinh, args) ?? If.Is(args, x => Mathx.Asinh(x)) ?? If.Is(args, x => x.ForEach(Mathx.Asinh)) ?? + If.Is(args, x => Mathx.Asinh(x)) ?? + If.Is(args, x => x.ForEach(Mathx.Asinh)) ?? If.Is>(args, o => o.Map(ArSinh)) ?? Mathx.Asinh(args[0].ToNumber()); }); @@ -573,6 +632,8 @@ public static class StandardFunctions return Curry.MinOne(ArCosh, args) ?? If.Is(args, x => Mathx.Acosh(x)) ?? If.Is(args, x => x.ForEach(Mathx.Acosh)) ?? + If.Is(args, x => Mathx.Acosh(x)) ?? + If.Is(args, x => x.ForEach(Mathx.Acosh)) ?? If.Is>(args, o => o.Map(ArCosh)) ?? Mathx.Acosh(args[0].ToNumber()); }); @@ -585,6 +646,8 @@ public static class StandardFunctions return Curry.MinOne(ArTanh, args) ?? If.Is(args, x => Mathx.Atanh(x)) ?? If.Is(args, x => x.ForEach(Mathx.Atanh)) ?? + If.Is(args, x => Mathx.Atanh(x)) ?? + If.Is(args, x => x.ForEach(Mathx.Atanh)) ?? If.Is>(args, o => o.Map(ArTanh)) ?? Mathx.Atanh(args[0].ToNumber()); }); @@ -597,6 +660,8 @@ public static class StandardFunctions return Curry.MinOne(ArCoth, args) ?? If.Is(args, x => Mathx.Acoth(x)) ?? If.Is(args, x => x.ForEach(Mathx.Acoth)) ?? + If.Is(args, x => Mathx.Acoth(x)) ?? + If.Is(args, x => x.ForEach(Mathx.Acoth)) ?? If.Is>(args, o => o.Map(ArCoth)) ?? Mathx.Acoth(args[0].ToNumber()); }); @@ -609,6 +674,8 @@ public static class StandardFunctions return Curry.MinOne(ArSech, args) ?? If.Is(args, x => Mathx.Asech(x)) ?? If.Is(args, x => x.ForEach(Mathx.Asech)) ?? + If.Is(args, x => Mathx.Asech(x)) ?? + If.Is(args, x => x.ForEach(Mathx.Asech)) ?? If.Is>(args, o => o.Map(ArSech)) ?? Mathx.Asech(args[0].ToNumber()); }); @@ -621,6 +688,8 @@ public static class StandardFunctions return Curry.MinOne(ArCsch, args) ?? If.Is(args, x => Mathx.Acsch(x)) ?? If.Is(args, x => x.ForEach(Mathx.Acsch)) ?? + If.Is(args, x => Mathx.Acsch(x)) ?? + If.Is(args, x => x.ForEach(Mathx.Acsch)) ?? If.Is>(args, o => o.Map(ArCsch)) ?? Mathx.Acsch(args[0].ToNumber()); }); @@ -672,6 +741,7 @@ public static class StandardFunctions { return Curry.MinOne(Sum, args) ?? If.Is(args, x => x.Reduce((a, b) => a + b)) ?? + If.Is(args, x => x.Reduce((a, b) => a + b)) ?? If.Is>(args, obj => obj.Sum(m => m.Value.ToNumber())) ?? args.Select(m => m.ToNumber()).Sum(); }); @@ -683,6 +753,7 @@ public static class StandardFunctions { return Curry.MinOne(Min, args) ?? If.Is(args, x => x.Reduce(Math.Min)) ?? + If.Is(args, x => x.Reduce(Mathx.Min)) ?? If.Is>(args, obj => obj.Min(m => m.Value.ToNumber())) ?? args.Select(m => m.ToNumber()).Min(); }); @@ -694,6 +765,7 @@ public static class StandardFunctions { return Curry.MinOne(Max, args) ?? If.Is(args, x => x.Reduce(Math.Max)) ?? + If.Is(args, x => x.Reduce(Mathx.Max)) ?? If.Is>(args, obj => obj.Max(m => m.Value.ToNumber())) ?? args.Select(m => m.ToNumber()).Max(); }); @@ -715,6 +787,7 @@ public static class StandardFunctions { return Curry.MinOne(Reverse, args) ?? If.Is(args, x => x.ToVector().Reverse().ToMatrix()) ?? + If.Is(args, x => x.ToVector().Reverse().ToMatrix()) ?? If.Is(args, x => new String(x.Reverse().ToArray())) ?? args.Reverse().ToArray(); }); diff --git a/src/Mages.Core/Runtime/Future.cs b/src/Mages.Core/Runtime/Future.cs index 4f2f8c82..12c18150 100644 --- a/src/Mages.Core/Runtime/Future.cs +++ b/src/Mages.Core/Runtime/Future.cs @@ -34,18 +34,12 @@ public Boolean IsCompleted /// /// Gets the result, if any. /// - public Object Result - { - get { return this.GetProperty("result"); } - } + public Object Result => this.GetProperty("result"); /// /// Gets the error message, if any. /// - public String Error - { - get { return this.GetProperty("error") as String; } - } + public String Error => this.GetProperty("error") as String; /// /// Sets the result in case of success. diff --git a/src/Mages.Core/Runtime/GammaHelpers.cs b/src/Mages.Core/Runtime/GammaHelpers.cs new file mode 100644 index 00000000..a772b1d9 --- /dev/null +++ b/src/Mages.Core/Runtime/GammaHelpers.cs @@ -0,0 +1,272 @@ +namespace Mages.Core.Runtime +{ + using System; + using System.Numerics; + + /// + /// This class contains the linear gamma function as well as complex ones + /// and logarithmic ones. + /// + public static class GammaHelpers + { + #region Linear + + /// + /// Computes the real (linear) gamma function. + /// + /// The argument. + /// The evaluated value. + public static Double LinearGamma(Double x) + { + if (x <= 0.0) + { + if (x == Math.Ceiling(x)) + { + return Double.PositiveInfinity; + } + + return Math.PI / LinearGamma(-x) / (-x) / Math.Sin(x * Math.PI); + } + + return Math.Exp(LogGamma(x)); + } + + /// + /// Computes the complex (linear) gamma function. + /// + /// The complex argument. + /// The evaluated value. + public static Complex LinearGamma(Complex z) + { + if (z.Real < 0.5) + { + return Math.PI / LinearGamma(1.0 - z) / Complex.Sin(Math.PI * z); + } + + return Complex.Exp(LogGamma(z)); + } + + #endregion + + #region Log + + /// + /// Computes the real (log) gamma function. + /// + /// The argument. + /// The evaluated value. + public static Double LogGamma(Double x) + { + if (x <= 0.0) + { + return Double.PositiveInfinity; + } + else if (x > 16.0) + { + return LogGamma_Stirling(x); + } + + return LanczosLogGamma(x); + } + + /// + /// Computes the complex (log) gamma function. + /// + /// The complex argument. + /// The evaluated value. + public static Complex LogGamma(Complex z) + { + if (z.Real < 0.0) + { + return new Complex(Double.PositiveInfinity, 0.0); + } + + if (Complex.Abs(z) > 15.0) + { + return LogGamma_Stirling(z); + } + + return LanczosLogGamma(z); + } + + #endregion + + #region Beta + + /// + /// Computes the real beta function, Gamma(a) * Gamma(b) / Gamma(a+b). + /// + /// The first parameter. + /// The second parameter. + /// The evaluated value. + public static Double Beta(Double a, Double b) => Math.Exp(LogGamma(a) + LogGamma(b) - LogGamma(a + b)); + + /// + /// Computes the complex beta function, Gamma(a) * Gamma(b) / Gamma(a+b). + /// + /// The first complex parameter. + /// The second complex parameter. + /// The evaluated value. + public static Complex Beta(Complex a, Complex b) => Complex.Exp(LogGamma(a) + LogGamma(b) - LogGamma(a + b)); + + #endregion + + #region Psi + + /// + /// Computes the real psi, usually called the digamma function, which is defined as the logarithmic derivative of the gamma function. + /// + /// The real argument. + /// The value. + public static Double Psi(Double x) + { + if (x <= 0.0) + { + if (x == Math.Ceiling(x)) + { + return Double.NaN; + } + + return Psi(1.0 - x) - Math.PI / Math.Tan(Math.PI * x); + } + else if (x > 16.0) + { + return Psi_Stirling(x); + } + + return LanczosPsi(x); + } + + #endregion + + #region Helpers + + private static Double LogGamma_Stirling(Double x) + { + var f = (x - 0.5) * Math.Log(x) - x + Math.Log(2.0 * Math.PI) / 2.0; + var xsqu = x * x; + var xp = x; + + for (int i = 1; i < 10; i++) + { + var f_old = f; + f += Mathx.BernoulliNumbers[i] / (2 * i) / (2 * i - 1) / xp; + + if (f == f_old) + { + return (f); + } + + xp *= xsqu; + } + + throw new Exception("gamma not converged"); + } + + private static Complex LogGamma_Stirling(Complex z) + { + if (z.Imaginary < 0.0) + { + return Complex.Conjugate(LogGamma_Stirling(Complex.Conjugate(z))); + } + + var f = (z - 0.5) * Complex.Log(z) - z + Math.Log(2.0 * Math.PI) / 2.0; + var reduce = f.Imaginary / (2.0 * Math.PI); + reduce = f.Imaginary - (int)(reduce) * 2.0 * Math.PI; + f = new Complex(f.Real, reduce); + + var zsqu = z * z; + var zp = new Complex(z.Real, z.Imaginary); + + for (var i = 1; i < 10; i++) + { + var f_old = new Complex(f.Real, f.Imaginary); + f += Mathx.BernoulliNumbers[i] / (2 * i) / (2 * i - 1) / zp; + + if (f == f_old) + { + return (f); + } + + zp *= zsqu; + } + + throw new Exception("gamma not converged"); + } + + private static double LanczosLogGamma(double x) + { + var sum = Mathx.LanczosD[0]; + + for (var i = 1; i < Mathx.LanczosD.Length; i++) + { + sum += Mathx.LanczosD[i] / (x + i); + } + + sum = 2.0 / Math.Sqrt(Math.PI) * sum / x; + var xshift = x + 0.5; + var t = xshift * Math.Log(xshift + Mathx.LanczosR) - x; + + return t + Math.Log(sum); + } + + private static Complex LanczosLogGamma(Complex z) + { + var sum = new Complex(Mathx.LanczosD[0], 0.0); + + for (int i = 1; i < Mathx.LanczosD.Length; i++) + { + sum += Mathx.LanczosD[i] / (z + i); + } + + sum = (2.0 / Math.Sqrt(Math.PI)) * (sum / z); + var zshift = z + 0.5; + var t = zshift * Complex.Log(zshift + Mathx.LanczosR) - z; + + return t + Complex.Log(sum); + } + + private static double LanczosPsi(double x) + { + var s0 = Mathx.LanczosD[0]; + var s1 = 0.0; + + for (int i = 1; i < Mathx.LanczosD.Length; i++) + { + var xi = x + i; + var st = Mathx.LanczosD[i] / xi; + s0 += st; + s1 += st / xi; + } + + var xx = x + Mathx.LanczosR + 0.5; + var t = Math.Log(xx) - Mathx.LanczosR / xx - 1.0 / x; + + return (t - s1 / s0); + } + + private static Double Psi_Stirling(Double x) + { + var f = Math.Log(x) - 1.0 / (2.0 * x); + var xsqu = x * x; + var xp = xsqu; + + for (int i = 1; i < 10; i++) + { + var f_old = f; + f -= Mathx.BernoulliNumbers[i] / (2 * i) / xp; + + if (f == f_old) + { + return (f); + } + + xp *= xsqu; + } + + throw new Exception("gamma not converged"); + } + + #endregion + } +} diff --git a/src/Mages.Core/Runtime/JsonSerializer.cs b/src/Mages.Core/Runtime/JsonSerializer.cs index ed726496..6de235aa 100644 --- a/src/Mages.Core/Runtime/JsonSerializer.cs +++ b/src/Mages.Core/Runtime/JsonSerializer.cs @@ -2,6 +2,7 @@ { using System; using System.Collections.Generic; + using System.Numerics; using System.Text; sealed class JsonSerializer @@ -54,32 +55,41 @@ private void SerializeTo(Object value, StringBuilder buffer, Int32 level) { buffer.Append(Stringify.AsJson("[Function]")); } - else if (value is IDictionary) + else if (value is IDictionary o) { if (!_seen.Contains(value.Unwrap())) { - SerializeTo((IDictionary)value, buffer, level); + SerializeTo(o, buffer, level); } else { buffer.Append(Stringify.AsJson("[Recursion]")); } } - else if (value is Double[,]) + else if (value is Double[,] m) { - buffer.Append(Stringify.AsJson((Double[,])value)); + buffer.Append(Stringify.AsJson(m)); } - else if (value is String) + else if (value is String s) { - buffer.Append(Stringify.AsJson((String)value)); + buffer.Append(Stringify.AsJson(s)); } - else if (value is Double) + else if (value is Double d) { - buffer.Append(Stringify.This((Double)value)); + buffer.Append(Stringify.This(d)); } - else if (value is Boolean) + else if (value is Boolean b) { - buffer.Append(Stringify.This((Boolean)value)); + buffer.Append(Stringify.This(b)); + } + else if (value is Complex c) + { + SerializeTo(new Dictionary + { + { "type", "cmplx" }, + { "real", c.Real }, + { "imag", c.Imaginary }, + }, buffer, level); } else { diff --git a/src/Mages.Core/Runtime/LocalFunction.cs b/src/Mages.Core/Runtime/LocalFunction.cs index 1604f99c..23a11e57 100644 --- a/src/Mages.Core/Runtime/LocalFunction.cs +++ b/src/Mages.Core/Runtime/LocalFunction.cs @@ -26,15 +26,9 @@ public LocalFunction(Object self, IDictionary parentScope, Param _pointer = new Function(Invoke); } - public ParameterDefinition[] Parameters - { - get { return _parameters; } - } + public ParameterDefinition[] Parameters => _parameters; - public Function Pointer - { - get { return _pointer; } - } + public Function Pointer => _pointer; private Object Invoke(Object[] arguments) { diff --git a/src/Mages.Core/Runtime/Mathx.cs b/src/Mages.Core/Runtime/Mathx.cs index c3aa75d7..8b37bb5d 100644 --- a/src/Mages.Core/Runtime/Mathx.cs +++ b/src/Mages.Core/Runtime/Mathx.cs @@ -1,10 +1,11 @@ namespace Mages.Core.Runtime { using System; + using System.Numerics; static class Mathx { - private static readonly Double[] LanczosD = new[] + public static readonly Double[] LanczosD = new[] { 2.48574089138753565546e-5, 1.05142378581721974210, @@ -19,7 +20,7 @@ static class Mathx -2.71994908488607703910e-9 }; - private static readonly Double[] BernoulliNumbers = new[] + public static readonly Double[] BernoulliNumbers = new[] { 1.0, 1.0 / 6.0, @@ -44,51 +45,77 @@ static class Mathx -261082718496449122051.0 / 13530.0 }; - public static Double Sign(Double value) => (Double)Math.Sign(value); + public const Double LanczosR = 10.900511; - public static Double Factorial(Double value) - { - var result = (Double)Math.Sign(value); - var n = (Int32)Math.Floor(result * value); + public static Complex Min(Complex a, Complex b) => Complex.Abs(a) > Complex.Abs(b) ? b : a; - if (n == 0) - { - return 1.0; - } + public static Complex Max(Complex a, Complex b) => Complex.Abs(a) > Complex.Abs(b) ? a : b; - while (n > 0) - { - result *= n--; - } + public static Complex Ceiling(Complex value) => new Complex(Math.Ceiling(value.Real), Math.Ceiling(value.Imaginary)); + + public static Complex Floor(Complex value) => new Complex(Math.Floor(value.Real), Math.Floor(value.Imaginary)); + + public static Complex Round(Complex value) => new Complex(Math.Round(value.Real), Math.Round(value.Imaginary)); - return result; + public static Double Sign(Double value) => (Double)Math.Sign(value); + + public static Complex Sign(Complex value) + { + var arg = Math.Atan2(value.Imaginary, value.Real); + return new Complex(Math.Cos(arg), Math.Sin(arg)); } - public static Double Gamma(Double x) + public static Complex Factorial(Complex value) => new Complex(Factorial(value.Real), Factorial(value.Imaginary)); + + public static Double Factorial(Double value) { - if (x <= 0.0) + if (value.IsInteger() && Math.Abs(value) < 1e5) { - if (x == Math.Ceiling(x)) + var result = (Double)Math.Sign(value); + var n = (Int32)Math.Floor(result * value); + + if (n == 0) { - return Double.PositiveInfinity; + return 1.0; } - return Math.PI / (Gamma(-x) * (-x) * Math.Sin(x * Math.PI)); - } + while (n > 0) + { + result *= n--; + } - return Math.Exp(LogGamma(x)); + return result; + } + else + { + return Gamma(value + 1.0); + } } + public static Double Gamma(Double x) => GammaHelpers.LinearGamma(x); + + public static Complex Gamma(Complex x) => GammaHelpers.LinearGamma(x); + public static Double Asinh(Double value) => Math.Log(value + Math.Sqrt(value * value + 1.0)); + public static Complex Asinh(Complex value) => Complex.Log(value + Complex.Sqrt(value * value + 1.0)); + public static Double Acosh(Double value) => Math.Log(value + Math.Sqrt(value * value - 1.0)); + public static Complex Acosh(Complex value) => Complex.Log(value + Complex.Sqrt(value * value - 1.0)); + public static Double Atanh(Double value) => 0.5 * Math.Log((1.0 + value) / (1.0 - value)); + public static Complex Atanh(Complex value) => 0.5 * Complex.Log((1.0 + value) / (1.0 - value)); + public static Double Cot(Double value) => Math.Cos(value) / Math.Sin(value); + public static Complex Cot(Complex value) => Complex.Cos(value) / Complex.Sin(value); + public static Double Acot(Double value) => Math.Atan(1.0 / value); + public static Complex Acot(Complex value) => Complex.Atan(1.0 / value); + public static Double Coth(Double value) { var a = Math.Exp(+value); @@ -96,79 +123,59 @@ public static Double Coth(Double value) return (a + b) / (a - b); } + public static Complex Coth(Complex value) + { + var a = Complex.Exp(value); + var b = Complex.Exp(-value); + return (a + b) / (a - b); + } + public static Double Acoth(Double value) => 0.5 * Math.Log((1.0 + value) / (value - 1.0)); + public static Complex Acoth(Complex value) => 0.5 * Complex.Log((1.0 + value) / (value - 1.0)); + public static Double Sec(Double value) => 1.0 / Math.Cos(value); + public static Complex Sec(Complex value) => 1.0 / Complex.Cos(value); + public static Double Asec(Double value) => Math.Acos(1.0 / value); + public static Complex Asec(Complex value) => Complex.Acos(1.0 / value); + public static Double Sech(Double value) => 2.0 / (Math.Exp(value) + Math.Exp(-value)); + public static Complex Sech(Complex value) => 2.0 / (Complex.Exp(value) + Complex.Exp(-value)); + public static Double Asech(Double value) { var vi = 1.0 / value; return Math.Log(vi + Math.Sqrt(vi + 1.0) * Math.Sqrt(vi - 1.0)); } - public static Double Csc(Double value) => 1.0 / Math.Sin(value); - - public static Double Acsc(Double value) => Math.Asin(1.0 / value); - - public static Double Csch(Double value) => 2.0 / (Math.Exp(value) - Math.Exp(-value)); - - public static Double Acsch(Double value) => Math.Log(1.0 / value + Math.Sqrt(1.0 / (value * value) + 1.0)); - - public static Double Log2(Double value) => Math.Log(value, 2.0); - - private static Double LogGamma(Double x) + public static Complex Asech(Complex value) { - if (x <= 0.0) - { - return double.PositiveInfinity; - } - else if (x > 16.0) - { - return StirlingLogGamma(x); - } - - return LanczosLogGamma(x); + var vi = 1.0 / value; + return Complex.Log(vi + Complex.Sqrt(vi + 1.0) * Complex.Sqrt(vi - 1.0)); } - private static Double LanczosLogGamma(Double x) - { - var sum = LanczosD[0]; + public static Double Csc(Double value) => 1.0 / Math.Sin(value); - for (var i = 1; i < LanczosD.Length; i++) - { - sum += LanczosD[i] / (x + i); - } + public static Complex Csc(Complex value) => 1.0 / Complex.Sin(value); - sum = 2.0 / Math.Sqrt(Math.PI) * sum / x; - var xshift = x + 0.5; - var t = xshift * Math.Log(xshift + 10.900511) - x; - return t + Math.Log(sum); - } + public static Double Acsc(Double value) => Math.Asin(1.0 / value); - private static Double StirlingLogGamma(Double x) - { - var f = (x - 0.5) * Math.Log(x) - x + Math.Log(2.0 * Math.PI) / 2.0; - var xsqu = x * x; - var xp = x; + public static Complex Acsc(Complex value) => Complex.Asin(1.0 / value); - for (var i = 1; i < 10; i++) - { - var f_old = f; - f += BernoulliNumbers[i] / (2 * i) / (2 * i - 1) / xp; + public static Double Csch(Double value) => 2.0 / (Math.Exp(value) - Math.Exp(-value)); - if (f == f_old) - { - break; - } + public static Complex Csch(Complex value) => 2.0 / (Complex.Exp(value) - Complex.Exp(-value)); - xp *= xsqu; - } + public static Double Acsch(Double value) => Math.Log(1.0 / value + Math.Sqrt(1.0 / (value * value) + 1.0)); - return f; - } + public static Complex Acsch(Complex value) => Complex.Log(1.0 / value + Complex.Sqrt(1.0 / (value * value) + 1.0)); + + public static Double Log2(Double value) => Math.Log(value, 2.0); + + public static Complex Log2(Complex value) => Complex.Log(value, 2.0); } } diff --git a/src/Mages.Core/Runtime/Matrix.cs b/src/Mages.Core/Runtime/Matrix.cs index 631cf69e..d4f8cc63 100644 --- a/src/Mages.Core/Runtime/Matrix.cs +++ b/src/Mages.Core/Runtime/Matrix.cs @@ -3,25 +3,26 @@ using Mages.Core.Runtime.Converters; using System; using System.Collections.Generic; + using System.Numerics; static class Matrix { - public static Int32 GetRows(this Double[,] matrix) + public static Int32 GetRows(this T[,] matrix) { return matrix.GetLength(0); } - public static Int32 GetColumns(this Double[,] matrix) + public static Int32 GetColumns(this T[,] matrix) { return matrix.GetLength(1); } - public static Int32 GetCount(this Double[,] matrix) + public static Int32 GetCount(this T[,] matrix) { return matrix.GetLength(0) * matrix.GetLength(1); } - public static Object GetKeys(this Double[,] matrix) + public static Object GetKeys(this T[,] matrix) { var result = new Dictionary(); var length = matrix.Length; @@ -34,7 +35,7 @@ public static Object GetKeys(this Double[,] matrix) return result; } - public static Boolean TryGetIndices(this Double[,] matrix, Object[] arguments, out Int32 row, out Int32 col) + public static Boolean TryGetIndices(this T[,] matrix, Object[] arguments, out Int32 row, out Int32 col) { var rows = matrix.GetRows(); var cols = matrix.GetColumns(); @@ -54,12 +55,9 @@ public static Boolean TryGetIndices(this Double[,] matrix, Object[] arguments, o return row >= 0 && col >= 0 && row < rows && col < cols; } - public static Object Getter(this Double[,] matrix, Object[] arguments) + public static Object Getter(this T[,] matrix, Object[] arguments) { - var i = 0; - var j = 0; - - if (matrix.TryGetIndices(arguments, out i, out j)) + if (matrix.TryGetIndices(arguments, out var i, out var j)) { return matrix[i, j]; } @@ -69,10 +67,7 @@ public static Object Getter(this Double[,] matrix, Object[] arguments) public static void Setter(this Double[,] matrix, Object[] arguments, Object value) { - var i = 0; - var j = 0; - - if (matrix.TryGetIndices(arguments, out i, out j)) + if (matrix.TryGetIndices(arguments, out var i, out var j)) { matrix[i, j] = value.ToNumber(); } @@ -88,14 +83,33 @@ public static Double Abs(Double[,] matrix) { for (var j = 0; j < cols; j++) { - sum += matrix[i ,j] * matrix[i, j]; + var n = matrix[i, j]; + sum += n * n; } } return Math.Sqrt(sum); } - public static Boolean Fits(this Double[,] a, Double[,] b) + public static Double Abs(Complex[,] matrix) + { + var sum = 0.0; + var rows = matrix.GetRows(); + var cols = matrix.GetColumns(); + + for (var i = 0; i < rows; i++) + { + for (var j = 0; j < cols; j++) + { + var c = matrix[i, j]; + sum += c.Real * c.Real + c.Imaginary * c.Imaginary; + } + } + + return Math.Sqrt(sum); + } + + public static Boolean Fits(this T[,] a, T[,] b) { var rowsA = a.GetRows(); var rowsB = b.GetRows(); @@ -127,6 +141,28 @@ public static Boolean Fits(this Double[,] a, Double[,] b) return null; } + public static Complex[,] Add(this Complex[,] a, Complex[,] b) + { + if (a.Fits(b)) + { + var rows = a.GetRows(); + var cols = a.GetColumns(); + var result = new Complex[rows, cols]; + + for (var i = 0; i < rows; i++) + { + for (var j = 0; j < cols; j++) + { + result[i, j] = a[i, j] + b[i, j]; + } + } + + return result; + } + + return null; + } + public static Double[,] Subtract(this Double[,] a, Double[,] b) { if (a.Fits(b)) @@ -202,11 +238,11 @@ public static Boolean Fits(this Double[,] a, Double[,] b) return a.Multiply(1.0 / b); } - public static Double[,] Transpose(this Double[,] matrix) + public static T[,] Transpose(this T[,] matrix) { var rows = matrix.GetRows(); var cols = matrix.GetColumns(); - var result = new Double[cols, rows]; + var result = new T[cols, rows]; for (var i = 0; i < rows; i++) { @@ -219,17 +255,16 @@ public static Boolean Fits(this Double[,] a, Double[,] b) return result; } - public static Boolean IsSquare(this Double[,] matrix) + public static Boolean IsSquare(this T[,] matrix) { return matrix.GetColumns() == matrix.GetRows(); } - public static Double[,] Fill(this Double[,] matrix, Double value) + public static T[,] Fill(this T[,] matrix, T value) { var rows = matrix.GetRows(); var cols = matrix.GetColumns(); - var result = new Double[rows, cols]; - var length = Math.Min(rows, cols); + var result = new T[rows, cols]; for (var i = 0; i < rows; i++) { @@ -314,7 +349,7 @@ public static Boolean IsSquare(this Double[,] matrix) return result; } - public static Double GetValue(this Double[,] matrix, Int32 row, Int32 col) + public static T GetValue(this T[,] matrix, Int32 row, Int32 col) { var rows = matrix.GetRows(); var cols = matrix.GetColumns(); @@ -324,10 +359,10 @@ public static Double GetValue(this Double[,] matrix, Int32 row, Int32 col) return matrix[row, col]; } - return 0.0; + return default; } - public static void SetValue(this Double[,] matrix, Int32 row, Int32 col, Double value) + public static void SetValue(this T[,] matrix, Int32 row, Int32 col, T value) { var rows = matrix.GetRows(); var cols = matrix.GetColumns(); @@ -338,11 +373,11 @@ public static void SetValue(this Double[,] matrix, Int32 row, Int32 col, Double } } - public static Double[,] ForEach(this Double[,] matrix, Func apply) + public static T[,] ForEach(this T[,] matrix, Func apply) { var rows = matrix.GetRows(); var cols = matrix.GetColumns(); - var result = new Double[rows, cols]; + var result = new T[rows, cols]; for (var i = 0; i < rows; i++) { @@ -355,7 +390,7 @@ public static void SetValue(this Double[,] matrix, Int32 row, Int32 col, Double return result; } - public static Object Reduce(this Double[,] matrix, Func reducer) + public static Object Reduce(this T[,] matrix, Func reducer) { var rows = matrix.GetRows(); var cols = matrix.GetColumns(); @@ -388,7 +423,7 @@ public static Object Reduce(this Double[,] matrix, Func } else { - var result = new Double[rows, 1]; + var result = new T[rows, 1]; for (var i = 0; i < rows; i++) { @@ -406,10 +441,7 @@ public static Object Reduce(this Double[,] matrix, Func } } - public static Double[,] And(this Double[,] a, Double b) - { - return a.And(a.Fill(b)); - } + public static Double[,] And(this Double[,] a, Double b) => a.And(a.Fill(b)); public static Double[,] And(this Double[,] a, Double[,] b) { @@ -433,10 +465,7 @@ public static Object Reduce(this Double[,] matrix, Func return null; } - public static Double[,] IsGreaterThan(this Double[,] a, Double b) - { - return a.IsGreaterThan(a.Fill(b)); - } + public static Double[,] IsGreaterThan(this Double[,] a, Double b) => a.IsGreaterThan(a.Fill(b)); public static Double[,] IsGreaterThan(this Double[,] a, Double[,] b) { @@ -460,10 +489,7 @@ public static Object Reduce(this Double[,] matrix, Func return null; } - public static Double[,] IsGreaterOrEqual(this Double[,] a, Double b) - { - return a.IsGreaterOrEqual(a.Fill(b)); - } + public static Double[,] IsGreaterOrEqual(this Double[,] a, Double b) => a.IsGreaterOrEqual(a.Fill(b)); public static Double[,] IsGreaterOrEqual(this Double[,] a, Double[,] b) { @@ -487,10 +513,7 @@ public static Object Reduce(this Double[,] matrix, Func return null; } - public static Double[,] AreNotEqual(this Double[,] a, Double b) - { - return a.AreNotEqual(a.Fill(b)); - } + public static Double[,] AreNotEqual(this Double[,] a, Double b) => a.AreNotEqual(a.Fill(b)); public static Object Map(this Double[,] matrix, Function f) { @@ -586,10 +609,7 @@ public static Object Reduce(this Double[,] matrix, Function f, Object start) return null; } - public static Double[,] IsLessThan(this Double[,] a, Double b) - { - return a.IsLessThan(a.Fill(b)); - } + public static Double[,] IsLessThan(this Double[,] a, Double b) => a.IsLessThan(a.Fill(b)); public static Double[,] IsLessThan(this Double[,] a, Double[,] b) { @@ -613,10 +633,7 @@ public static Object Reduce(this Double[,] matrix, Function f, Object start) return null; } - public static Double[,] IsLessOrEqual(this Double[,] a, Double b) - { - return a.IsLessOrEqual(a.Fill(b)); - } + public static Double[,] IsLessOrEqual(this Double[,] a, Double b) => a.IsLessOrEqual(a.Fill(b)); public static Double[,] IsLessOrEqual(this Double[,] a, Double[,] b) { @@ -640,10 +657,7 @@ public static Object Reduce(this Double[,] matrix, Function f, Object start) return null; } - public static Double[,] AreEqual(this Double[,] a, Double b) - { - return a.AreEqual(a.Fill(b)); - } + public static Double[,] AreEqual(this Double[,] a, Double b) => a.AreEqual(a.Fill(b)); public static Double[,] AreEqual(this Double[,] a, Double[,] b) { @@ -667,11 +681,32 @@ public static Object Reduce(this Double[,] matrix, Function f, Object start) return null; } - public static Double[,] Or(this Double[,] a, Double b) + public static Double[,] AreEqual(this Complex[,] a, Complex b) => a.AreEqual(a.Fill(b)); + + public static Double[,] AreEqual(this Complex[,] a, Complex[,] b) { - return a.Or(a.Fill(b)); + if (a.Fits(b)) + { + var rows = a.GetRows(); + var cols = a.GetColumns(); + var result = new Double[rows, cols]; + + for (var i = 0; i < rows; i++) + { + for (var j = 0; j < cols; j++) + { + result[i, j] = (a[i, j] == b[i, j]).ToNumber(); + } + } + + return result; + } + + return null; } + public static Double[,] Or(this Double[,] a, Double b) => a.Or(a.Fill(b)); + public static Double[,] Or(this Double[,] a, Double[,] b) { if (a.Fits(b)) diff --git a/src/Mages.Core/Runtime/ObservableDictionary.cs b/src/Mages.Core/Runtime/ObservableDictionary.cs index 0c5e6dd4..f8290015 100644 --- a/src/Mages.Core/Runtime/ObservableDictionary.cs +++ b/src/Mages.Core/Runtime/ObservableDictionary.cs @@ -50,10 +50,7 @@ public ObservableDictionary(IDictionary container) /// /// Gets the used container. /// - public IDictionary Container - { - get { return _container; } - } + public IDictionary Container => _container; #endregion @@ -77,25 +74,13 @@ public Object this[String key] /// /// Gets the number of items stored in the container. /// - public Int32 Count - { - get { return _container.Count; } - } + public Int32 Count => _container.Count; - Boolean ICollection>.IsReadOnly - { - get { return _container.IsReadOnly; } - } + Boolean ICollection>.IsReadOnly => _container.IsReadOnly; - ICollection IDictionary.Keys - { - get { return _container.Keys; } - } + ICollection IDictionary.Keys => _container.Keys; - ICollection IDictionary.Values - { - get { return _container.Values; } - } + ICollection IDictionary.Values => _container.Values; void ICollection>.Add(KeyValuePair item) { diff --git a/src/Mages.Core/Runtime/Stringify.cs b/src/Mages.Core/Runtime/Stringify.cs index 831555d5..93d98c8e 100644 --- a/src/Mages.Core/Runtime/Stringify.cs +++ b/src/Mages.Core/Runtime/Stringify.cs @@ -23,34 +23,22 @@ public static class Stringify /// /// Converts the number to a string. /// - public static String This(Complex value) - { - return $"cmplx{value.ToString(CultureInfo.InvariantCulture)}"; - } + public static String This(Complex value) => $"cmplx{value.ToString(CultureInfo.InvariantCulture)}"; /// /// Converts the number to a string. /// - public static String This(Double value) - { - return value.ToString(CultureInfo.InvariantCulture); - } + public static String This(Double value) => value.ToString(CultureInfo.InvariantCulture); /// /// Converts the boolean to a string. /// - public static String This(Boolean value) - { - return value ? Keywords.True : Keywords.False; - } + public static String This(Boolean value) => value ? Keywords.True : Keywords.False; /// /// Converts the string for output. /// - public static String This(String value) - { - return value.ToString(CultureInfo.InvariantCulture); - } + public static String This(String value) => value.ToString(CultureInfo.InvariantCulture); /// /// Converts the matrix to a string. @@ -87,68 +75,34 @@ public static String This(Double[,] value) /// /// Converts the object to a string. /// - public static String This(IDictionary value) - { - return "[Object]"; - } + public static String This(IDictionary value) => "[Object]"; /// /// Converts the function to a string. /// - public static String This(Function value) - { - return "[Function]"; - } + public static String This(Function value) => "[Function]"; /// /// Outputs the string for an undefined (null?) value. /// /// - public static String Undefined() - { - return System.String.Empty; - } + public static String Undefined() => System.String.Empty; /// /// Converts the undetermined value to a string. /// - public static String This(Object value) + public static String This(Object value)=> value switch { - if (value == null) - { - return Undefined(); - } - else if (value is Function) - { - return This((Function)value); - } - else if (value is IDictionary) - { - return This((IDictionary)value); - } - else if (value is Double[,]) - { - return This((Double[,])value); - } - else if (value is String) - { - return This((String)value); - } - else if (value is Double) - { - return This((Double)value); - } - else if (value is Boolean) - { - return This((Boolean)value); - } - else if (value is Complex) - { - return This((Complex)value); - } - - return "(unknown)"; - } + null => Undefined(), + Function f => This(f), + IDictionary o => This(o), + Double[,] m => This(m), + String s => This(s), + Double d => This(d), + Boolean b => This(b), + Complex c => This(c), + _ => "(unknown)" + }; /// /// Converts the given MAGES object to a JSON string. diff --git a/src/Mages.Core/Runtime/UnaryOperators.cs b/src/Mages.Core/Runtime/UnaryOperators.cs index af186f9b..55ad1545 100644 --- a/src/Mages.Core/Runtime/UnaryOperators.cs +++ b/src/Mages.Core/Runtime/UnaryOperators.cs @@ -3,21 +3,26 @@ using Mages.Core.Runtime.Converters; using Mages.Core.Runtime.Functions; using System; + using System.Numerics; static class UnaryOperators { #region Not Fields + private static readonly Func NotComplex = x => x == Complex.Zero; private static readonly Func NotNumber = x => x == 0.0; private static readonly Func NotMatrix = x => x.AreEqual(0.0); + private static readonly Func NotCMatrix = x => x.AreEqual(0.0); private static readonly Func NotAny = x => !x.ToBoolean(); #endregion #region Positive Fields - private static readonly Func PositiveNumber = m => +m; + private static readonly Func PositiveNumber = m => m; + private static readonly Func PositiveComplex = m => m; private static readonly Func PositiveMatrix = m => m; + private static readonly Func PositiveCMatrix = m => m; private static readonly Func PositiveAny = m => +m.ToNumber(); #endregion @@ -25,7 +30,9 @@ static class UnaryOperators #region Negative Fields private static readonly Func NegativeNumber = m => -m; + private static readonly Func NegativeComplex = m => -m; private static readonly Func NegativeMatrix = m => m.ForEach(x => -x); + private static readonly Func NegativeCMatrix = m => m.ForEach(x => -x); private static readonly Func NegativeAny = m => -m.ToNumber(); #endregion @@ -33,7 +40,9 @@ static class UnaryOperators #region Factorial Fields private static readonly Func FactorialNumber = x => Mathx.Factorial(x); + private static readonly Func FactorialComplex = x => Mathx.Factorial(x); private static readonly Func FactorialMatrix = x => x.ForEach(y => Mathx.Factorial(y)); + private static readonly Func FactorialCMatrix = x => x.ForEach(y => Mathx.Factorial(y)); private static readonly Func FactorialAny = x => Mathx.Factorial(x.ToNumber()); #endregion @@ -41,60 +50,57 @@ static class UnaryOperators #region Other Fields private static readonly Func TransposeMatrix = x => x.Transpose(); + private static readonly Func TransposeCMatrix = x => x.Transpose(); private static readonly Func AbsMatrix = x => Matrix.Abs(x); + private static readonly Func AbsCMatrix = x => Matrix.Abs(x); #endregion #region Functions - public static Object Not(Object[] args) - { - return If.Is(args, NotNumber) ?? - If.Is(args, NotMatrix) ?? - If.Is(args, NotAny) ?? - true; - } - - public static Object Positive(Object[] args) - { - return If.Is(args, PositiveNumber) ?? - If.Is(args, PositiveMatrix) ?? - If.Is(args, PositiveAny) ?? - Double.NaN; - } - - public static Object Negative(Object[] args) - { - return If.Is(args, NegativeNumber) ?? - If.Is(args, NegativeMatrix) ?? - If.Is(args, NegativeAny) ?? - Double.NaN; - } - - public static Object Factorial(Object[] args) - { - return If.Is(args, FactorialNumber) ?? - If.Is(args, FactorialMatrix) ?? - If.Is(args, FactorialAny) ?? - Double.NaN; - } - - public static Object Transpose(Object[] args) - { - return If.Is(args, TransposeMatrix) ?? - args[0].ToNumber().ToMatrix(); - } - - public static Object Abs(Object[] args) - { - return If.Is(args, AbsMatrix) ?? - Math.Abs(args[0].ToNumber()); - } - - public static Object Type(Object[] args) - { - return args[0].ToType(); - } + public static Object Not(Object[] args) => + If.Is(args, NotNumber) ?? + If.Is(args, NotComplex) ?? + If.Is(args, NotMatrix) ?? + If.Is(args, NotCMatrix) ?? + If.Is(args, NotAny) ?? + true; + + public static Object Positive(Object[] args) => + If.Is(args, PositiveNumber) ?? + If.Is(args, PositiveComplex) ?? + If.Is(args, PositiveMatrix) ?? + If.Is(args, PositiveCMatrix) ?? + If.Is(args, PositiveAny) ?? + Double.NaN; + + public static Object Negative(Object[] args) => + If.Is(args, NegativeNumber) ?? + If.Is(args, NegativeComplex) ?? + If.Is(args, NegativeMatrix) ?? + If.Is(args, NegativeCMatrix) ?? + If.Is(args, NegativeAny) ?? + Double.NaN; + + public static Object Factorial(Object[] args) => + If.Is(args, FactorialNumber) ?? + If.Is(args, FactorialComplex) ?? + If.Is(args, FactorialMatrix) ?? + If.Is(args, FactorialCMatrix) ?? + If.Is(args, FactorialAny) ?? + Double.NaN; + + public static Object Transpose(Object[] args) => + If.Is(args, TransposeMatrix) ?? + If.Is(args, TransposeCMatrix) ?? + args[0].ToNumber().ToMatrix(); + + public static Object Abs(Object[] args) => + If.Is(args, AbsMatrix) ?? + If.Is(args, AbsCMatrix) ?? + Math.Abs(args[0].ToNumber()); + + public static Object Type(Object[] args) => args[0].ToType(); #endregion } diff --git a/src/Mages.Core/Runtime/WrapperObject.cs b/src/Mages.Core/Runtime/WrapperObject.cs index 8c328691..a8f2a236 100644 --- a/src/Mages.Core/Runtime/WrapperObject.cs +++ b/src/Mages.Core/Runtime/WrapperObject.cs @@ -75,18 +75,12 @@ public static WrapperObject CreateFor(Object value) /// /// Gets the wrapped object if instance bound. /// - public Object Content - { - get { return _content; } - } + public Object Content => _content; /// /// Gets the type that is wrapped (instance or static). /// - public Type Type - { - get { return _type; } - } + public Type Type => _type; #endregion @@ -113,31 +107,19 @@ public Object this[String key] /// Gets the number of properties of the underlying /// object and the extension object. /// - public Int32 Count - { - get { return _extends.Count + _proxies.Count; } - } + public Int32 Count => _extends.Count + _proxies.Count; - Boolean ICollection>.IsReadOnly - { - get { return false; } - } + Boolean ICollection>.IsReadOnly => false; /// /// Gets all the keys from the extension object. /// - public ICollection Keys - { - get { return _extends.Keys; } - } + public ICollection Keys => _extends.Keys; /// /// Gets all the values from the extension object. /// - public ICollection Values - { - get { return _extends.Values; } - } + public ICollection Values => _extends.Values; void ICollection>.Add(KeyValuePair item) { diff --git a/src/Mages.Core/Source/BaseScanner.cs b/src/Mages.Core/Source/BaseScanner.cs index f9dde7a0..8bf677f8 100644 --- a/src/Mages.Core/Source/BaseScanner.cs +++ b/src/Mages.Core/Source/BaseScanner.cs @@ -30,10 +30,7 @@ public BaseScanner() #region Properties - public TextPosition Position - { - get { return new TextPosition(_row, _column, _position); } - } + public TextPosition Position => new TextPosition(_row, _column, _position); #endregion diff --git a/src/Mages.Core/Source/StringScanner.cs b/src/Mages.Core/Source/StringScanner.cs index f4767860..e5b44098 100644 --- a/src/Mages.Core/Source/StringScanner.cs +++ b/src/Mages.Core/Source/StringScanner.cs @@ -29,10 +29,7 @@ public StringScanner(String source) #region Properties - public Int32 Current - { - get { return _current; } - } + public Int32 Current => _current; #endregion diff --git a/src/Mages.Core/TextPosition.cs b/src/Mages.Core/TextPosition.cs index 0c1781df..037f421d 100644 --- a/src/Mages.Core/TextPosition.cs +++ b/src/Mages.Core/TextPosition.cs @@ -37,26 +37,17 @@ public TextPosition(Int32 row, Int32 column, Int32 index) /// /// Gets the row in the source code. /// - public Int32 Row - { - get { return _row; } - } + public Int32 Row => _row; /// /// Gets the column in the source code. /// - public Int32 Column - { - get { return _column; } - } + public Int32 Column => _column; /// /// Gets the index (absolute position) in the source code. /// - public Int32 Index - { - get { return _index; } - } + public Int32 Index => _index; #endregion diff --git a/src/Mages.Core/Tokens/CharacterToken.cs b/src/Mages.Core/Tokens/CharacterToken.cs index 0278dcf0..751dfd31 100644 --- a/src/Mages.Core/Tokens/CharacterToken.cs +++ b/src/Mages.Core/Tokens/CharacterToken.cs @@ -15,24 +15,12 @@ public CharacterToken(TokenType type, Int32 character, TextPosition position) _position = position; } - public TokenType Type - { - get { return _type; } - } + public TokenType Type => _type; - public String Payload - { - get { return Char.ConvertFromUtf32(_character); } - } + public String Payload => Char.ConvertFromUtf32(_character); - public TextPosition Start - { - get { return _position; } - } + public TextPosition Start => _position; - public TextPosition End - { - get { return _position; } - } + public TextPosition End => _position; } } diff --git a/src/Mages.Core/Tokens/CommentToken.cs b/src/Mages.Core/Tokens/CommentToken.cs index 9694e729..76eb0fb7 100644 --- a/src/Mages.Core/Tokens/CommentToken.cs +++ b/src/Mages.Core/Tokens/CommentToken.cs @@ -15,24 +15,12 @@ public CommentToken(String comment, TextPosition start, TextPosition end) _end = end; } - public TokenType Type - { - get { return TokenType.Comment; } - } + public TokenType Type => TokenType.Comment; - public String Payload - { - get { return _comment; } - } + public String Payload => _comment; - public TextPosition Start - { - get { return _start; } - } + public TextPosition Start => _start; - public TextPosition End - { - get { return _end; } - } + public TextPosition End => _end; } } diff --git a/src/Mages.Core/Tokens/EndToken.cs b/src/Mages.Core/Tokens/EndToken.cs index 7be1a099..d906350b 100644 --- a/src/Mages.Core/Tokens/EndToken.cs +++ b/src/Mages.Core/Tokens/EndToken.cs @@ -11,24 +11,12 @@ public EndToken(TextPosition position) _position = position; } - public TokenType Type - { - get { return TokenType.End; } - } + public TokenType Type => TokenType.End; - public String Payload - { - get { return String.Empty; } - } + public String Payload => String.Empty; - public TextPosition Start - { - get { return _position; } - } + public TextPosition Start => _position; - public TextPosition End - { - get { return _position; } - } + public TextPosition End => _position; } } diff --git a/src/Mages.Core/Tokens/IdentToken.cs b/src/Mages.Core/Tokens/IdentToken.cs index 9479966e..926ad2f5 100644 --- a/src/Mages.Core/Tokens/IdentToken.cs +++ b/src/Mages.Core/Tokens/IdentToken.cs @@ -17,24 +17,12 @@ public IdentToken(TokenType type, String identifier, TextPosition start, TextPos _end = end; } - public TokenType Type - { - get { return _type; } - } + public TokenType Type => _type; - public String Payload - { - get { return _identifier; } - } + public String Payload => _identifier; - public TextPosition Start - { - get { return _start; } - } + public TextPosition Start => _start; - public TextPosition End - { - get { return _end; } - } + public TextPosition End => _end; } } diff --git a/src/Mages.Core/Tokens/InterpolatedToken.cs b/src/Mages.Core/Tokens/InterpolatedToken.cs index d47ba69a..807d11ac 100644 --- a/src/Mages.Core/Tokens/InterpolatedToken.cs +++ b/src/Mages.Core/Tokens/InterpolatedToken.cs @@ -23,39 +23,21 @@ public InterpolatedToken(String content, List> parts, IEnumerable

_parts.Count; public IEnumerable this[Int32 index] { get { return _parts[index]; } } - public IEnumerable Errors - { - get { return _errors; } - } + public IEnumerable Errors => _errors; - public TokenType Type - { - get { return TokenType.InterpolatedString; } - } + public TokenType Type => TokenType.InterpolatedString; - public String Payload - { - get { return _content; } - } + public String Payload => _content; - public TextPosition Start - { - get { return _start; } - } + public TextPosition Start => _start; - public TextPosition End - { - get { return _end; } - } + public TextPosition End => _end; } } diff --git a/src/Mages.Core/Tokens/NumberToken.cs b/src/Mages.Core/Tokens/NumberToken.cs index 13f99a14..1ee72254 100644 --- a/src/Mages.Core/Tokens/NumberToken.cs +++ b/src/Mages.Core/Tokens/NumberToken.cs @@ -22,34 +22,16 @@ public NumberToken(Double value, IEnumerable errors, TextPosition st _errors = errors ?? NoErrors; } - public IEnumerable Errors - { - get { return _errors; } - } + public IEnumerable Errors => _errors; - public Double Value - { - get { return _value; } - } + public Double Value => _value; - public TokenType Type - { - get { return TokenType.Number; } - } + public TokenType Type => TokenType.Number; - public String Payload - { - get { return _value.ToString(NumberFormatInfo.InvariantInfo); } - } + public String Payload => _value.ToString(NumberFormatInfo.InvariantInfo); - public TextPosition Start - { - get { return _start; } - } + public TextPosition Start => _start; - public TextPosition End - { - get { return _end; } - } + public TextPosition End => _end; } } diff --git a/src/Mages.Core/Tokens/NumberTokenizer.cs b/src/Mages.Core/Tokens/NumberTokenizer.cs index d55df016..5192357c 100644 --- a/src/Mages.Core/Tokens/NumberTokenizer.cs +++ b/src/Mages.Core/Tokens/NumberTokenizer.cs @@ -60,10 +60,7 @@ public NumberState(IScanner scanner) _powers = 0; } - public Double Number - { - get { return _value * Math.Pow(10.0, -_digits) * Math.Pow(10.0, _powers); } - } + public Double Number => _value * Math.Pow(10.0, -_digits) * Math.Pow(10.0, _powers); public IToken Zero() { diff --git a/src/Mages.Core/Tokens/OperatorToken.cs b/src/Mages.Core/Tokens/OperatorToken.cs index 6e024268..285fcb21 100644 --- a/src/Mages.Core/Tokens/OperatorToken.cs +++ b/src/Mages.Core/Tokens/OperatorToken.cs @@ -22,24 +22,12 @@ public OperatorToken(TokenType type, String payload, TextPosition start, TextPos _end = end; } - public TokenType Type - { - get { return _type; } - } + public TokenType Type => _type; - public String Payload - { - get { return _payload; } - } + public String Payload => _payload; - public TextPosition Start - { - get { return _start; } - } + public TextPosition Start => _start; - public TextPosition End - { - get { return _end; } - } + public TextPosition End => _end; } } diff --git a/src/Mages.Core/Tokens/PreprocessorToken.cs b/src/Mages.Core/Tokens/PreprocessorToken.cs index 3a85cdf6..ac5851ad 100644 --- a/src/Mages.Core/Tokens/PreprocessorToken.cs +++ b/src/Mages.Core/Tokens/PreprocessorToken.cs @@ -16,20 +16,11 @@ public PreprocessorToken(String payload, TextPosition start, TextPosition end) _end = end; } - public TokenType Type - { - get { return TokenType.Preprocessor; } - } + public TokenType Type => TokenType.Preprocessor; - public TextPosition End - { - get { return _end; } - } + public TextPosition End => _end; - public TextPosition Start - { - get { return _start; } - } + public TextPosition Start => _start; public String Command { @@ -51,9 +42,6 @@ public String Command } } - public String Payload - { - get { return _payload; } - } + public String Payload => _payload; } } \ No newline at end of file diff --git a/src/Mages.Core/Tokens/StringToken.cs b/src/Mages.Core/Tokens/StringToken.cs index a485c783..460064a9 100644 --- a/src/Mages.Core/Tokens/StringToken.cs +++ b/src/Mages.Core/Tokens/StringToken.cs @@ -21,29 +21,14 @@ public StringToken(String content, IEnumerable errors, TextPosition _errors = errors ?? NoErrors; } - public IEnumerable Errors - { - get { return _errors; } - } + public IEnumerable Errors => _errors; - public TokenType Type - { - get { return TokenType.String; } - } + public TokenType Type => TokenType.String; - public String Payload - { - get { return _content; } - } + public String Payload => _content; - public TextPosition Start - { - get { return _start; } - } + public TextPosition Start => _start; - public TextPosition End - { - get { return _end; } - } + public TextPosition End => _end; } } diff --git a/src/Mages.Core/Tokens/TextPositionExtensions.cs b/src/Mages.Core/Tokens/TextPositionExtensions.cs index d145f1e2..76f0d9dd 100644 --- a/src/Mages.Core/Tokens/TextPositionExtensions.cs +++ b/src/Mages.Core/Tokens/TextPositionExtensions.cs @@ -30,15 +30,9 @@ public TextRange(TextPosition start, TextPosition end) _end = end; } - public TextPosition Start - { - get { return _start; } - } + public TextPosition Start => _start; - public TextPosition End - { - get { return _end; } - } + public TextPosition End => _end; } } } diff --git a/src/Mages.Core/Vm/ExecutionContext.cs b/src/Mages.Core/Vm/ExecutionContext.cs index 1d66f869..58df2612 100644 --- a/src/Mages.Core/Vm/ExecutionContext.cs +++ b/src/Mages.Core/Vm/ExecutionContext.cs @@ -39,18 +39,12 @@ public Int32 Position ///

/// Gets the position of the last operation. /// - public Int32 End - { - get { return _operations.Length - 1; } - } + public Int32 End => _operations.Length - 1; /// /// Gets the currently used scope of the execution context. /// - public IDictionary Scope - { - get { return _scope; } - } + public IDictionary Scope => _scope; /// /// Executes the operations. From 3eb8efb83c3758a9a21618b6693bdd0a45d4b92a Mon Sep 17 00:00:00 2001 From: Florian Rappl Date: Thu, 20 May 2021 14:14:21 +0200 Subject: [PATCH 14/27] Finished complex implementation --- .../Ast/Walkers/OperationTreeWalker.cs | 2 + src/Mages.Core/Runtime/BinaryOperators.cs | 76 ++++- .../Runtime/Converters/ConverterExtensions.cs | 114 ++++--- src/Mages.Core/Runtime/Functions/If.cs | 15 + src/Mages.Core/Runtime/Logic.cs | 40 +++ src/Mages.Core/Runtime/Mathx.cs | 15 +- src/Mages.Core/Runtime/Matrix.cs | 284 +++++++++++++++++- src/Mages.Core/Runtime/Stringify.cs | 5 +- src/Mages.Core/Runtime/UnaryOperators.cs | 13 + .../Vm/Operations/InitMatOperation.cs | 5 +- .../Vm/Operations/NewMatOperation.cs | 2 +- .../Vm/Operations/SetMatOperation.cs | 42 +++ 12 files changed, 537 insertions(+), 76 deletions(-) create mode 100644 src/Mages.Core/Vm/Operations/SetMatOperation.cs diff --git a/src/Mages.Core/Ast/Walkers/OperationTreeWalker.cs b/src/Mages.Core/Ast/Walkers/OperationTreeWalker.cs index 1b7dbb93..fa543c69 100644 --- a/src/Mages.Core/Ast/Walkers/OperationTreeWalker.cs +++ b/src/Mages.Core/Ast/Walkers/OperationTreeWalker.cs @@ -403,6 +403,8 @@ void ITreeWalker.Visit(MatrixExpression expression) _operations.Add(new InitMatOperation(row, col)); } } + + _operations.Add(new SetMatOperation()); } void ITreeWalker.Visit(FunctionExpression expression) diff --git a/src/Mages.Core/Runtime/BinaryOperators.cs b/src/Mages.Core/Runtime/BinaryOperators.cs index a56505cd..117b973b 100644 --- a/src/Mages.Core/Runtime/BinaryOperators.cs +++ b/src/Mages.Core/Runtime/BinaryOperators.cs @@ -11,6 +11,8 @@ static class BinaryOperators private static readonly Func AsNumber = m => m.ToNumber(); private static readonly Func AsComplex = m => m.ToComplex(); + private static readonly Func CastNumber = m => new Complex(m, 0.0); + private static readonly Func CastMatrix = m => m.ForEach(CastNumber); #endregion @@ -30,6 +32,8 @@ static class BinaryOperators private static readonly Func SubNumbers = (y, x) => x - y; private static readonly Func SubMatrices = (y, x) => x.Subtract(y); + private static readonly Func SubCNumbers = (y, x) => x - y; + private static readonly Func SubCMatrices = (y, x) => x.Subtract(y); #endregion @@ -39,6 +43,10 @@ static class BinaryOperators private static readonly Func MulMatrices = (y, x) => x.Multiply(y); private static readonly Func MulNumMat = (y, x) => x.Multiply(y); private static readonly Func MulMatNum = (y, x) => y.Multiply(x); + private static readonly Func MulCNumbers = (y, x) => x * y; + private static readonly Func MulCMatrices = (y, x) => x.Multiply(y); + private static readonly Func MulCNumMat = (y, x) => x.Multiply(y); + private static readonly Func MulCMatNum = (y, x) => y.Multiply(x); #endregion @@ -46,6 +54,8 @@ static class BinaryOperators private static readonly Func RDivNumbers = (y, x) => x / y; private static readonly Func RDivNumMat = (y, x) => x.Divide(y); + private static readonly Func RDivCNumbers = (y, x) => x / y; + private static readonly Func RDivCNumMat = (y, x) => x.Divide(y); #endregion @@ -53,6 +63,8 @@ static class BinaryOperators private static readonly Func LDivNumbers = (y, x) => y / x; private static readonly Func LDivMatNum = (y, x) => y.Divide(x); + private static readonly Func LDivCNumbers = (y, x) => y / x; + private static readonly Func LDivCMatNum = (y, x) => y.Divide(x); #endregion @@ -62,12 +74,17 @@ static class BinaryOperators private static readonly Func PowMatrices = (y, x) => x.Pow(y); private static readonly Func PowMatNum = (y, x) => x.Pow(y); private static readonly Func PowNumMat = (y, x) => x.Pow(y); + private static readonly Func PowCNumbers = (y, x) => Complex.Pow(x, y); + private static readonly Func PowCMatrices = (y, x) => x.Pow(y); + private static readonly Func PowCMatNum = (y, x) => x.Pow(y); + private static readonly Func PowCNumMat = (y, x) => x.Pow(y); #endregion #region Other Fields private static readonly Func ModNumbers = (y, x) => x % y; + private static readonly Func ModCNumbers = (y, x) => Mathx.Mod(y, x); private static readonly Func InvokeFunction = (f, arg) => f.Invoke(new[] { arg }); #endregion @@ -99,8 +116,10 @@ static class BinaryOperators #region Eq Fields private static readonly Func EqNumbers = (y, x) => x == y; + private static readonly Func EqCNumbers = (y, x) => x == y; private static readonly Func EqBooleans = (y, x) => x == y; private static readonly Func EqMatrices = (y, x) => x.AreEqual(y); + private static readonly Func EqCMatrices = (y, x) => x.AreEqual(y); private static readonly Func EqMatNum = (y, x) => y.AreEqual(x); private static readonly Func EqNumMat = (y, x) => x.AreEqual(y); private static readonly Func EqMatBool = (y, x) => y.AreEqual(x.ToNumber()); @@ -112,8 +131,10 @@ static class BinaryOperators #region Neq Fields private static readonly Func NeqNumbers = (y, x) => x != y; + private static readonly Func NeqCNumbers = (y, x) => x != y; private static readonly Func NeqBooleans = (y, x) => x != y; private static readonly Func NeqMatrices = (y, x) => x.AreNotEqual(y); + private static readonly Func NeqCMatrices = (y, x) => x.AreNotEqual(y); private static readonly Func NeqMatNum = (y, x) => y.AreNotEqual(x); private static readonly Func NeqNumMat = (y, x) => x.AreNotEqual(y); private static readonly Func NeqMatBool = (y, x) => y.AreNotEqual(x.ToNumber()); @@ -128,6 +149,10 @@ static class BinaryOperators private static readonly Func GtMatrices = Matrix.IsLessThan; private static readonly Func GtMatNum = Matrix.IsLessThan; private static readonly Func GtNumMat = (y, x) => x.IsGreaterThan(y); + private static readonly Func GtCNumbers = (y, x) => Mathx.IsGreaterThan(x, y); + private static readonly Func GtCMatrices = Matrix.IsLessThan; + private static readonly Func GtCMatNum = Matrix.IsLessThan; + private static readonly Func GtCNumMat = (y, x) => x.IsGreaterThan(y); #endregion @@ -137,6 +162,10 @@ static class BinaryOperators private static readonly Func GeqMatrices = Matrix.IsLessOrEqual; private static readonly Func GeqMatNum = Matrix.IsLessOrEqual; private static readonly Func GeqNumMat = (y, x) => x.IsGreaterOrEqual(y); + private static readonly Func GeqCNumbers = (y, x) => !Mathx.IsGreaterThan(y, x); + private static readonly Func GeqCMatrices = Matrix.IsLessOrEqual; + private static readonly Func GeqCMatNum = Matrix.IsLessOrEqual; + private static readonly Func GeqCNumMat = (y, x) => x.IsGreaterOrEqual(y); #endregion @@ -146,6 +175,10 @@ static class BinaryOperators private static readonly Func LtMatrices = Matrix.IsGreaterThan; private static readonly Func LtMatNum = Matrix.IsGreaterThan; private static readonly Func LtNumMat = (y, x) => x.IsLessThan(y); + private static readonly Func LtCNumbers = (y, x) => Mathx.IsLessThan(x, y); + private static readonly Func LtCMatrices = Matrix.IsGreaterThan; + private static readonly Func LtCMatNum = Matrix.IsGreaterThan; + private static readonly Func LtCNumMat = (y, x) => x.IsLessThan(y); #endregion @@ -155,6 +188,10 @@ static class BinaryOperators private static readonly Func LeqMatrices = Matrix.IsGreaterOrEqual; private static readonly Func LeqMatNum = Matrix.IsGreaterOrEqual; private static readonly Func LeqNumMat = (y, x) => x.IsLessOrEqual(y); + private static readonly Func LeqCNumbers = (y, x) => !Mathx.IsLessThan(y, x); + private static readonly Func LeqCMatrices = Matrix.IsGreaterOrEqual; + private static readonly Func LeqCMatNum = Matrix.IsGreaterOrEqual; + private static readonly Func LeqCNumMat = (y, x) => x.IsLessOrEqual(y); #endregion @@ -164,8 +201,8 @@ public static Object Add(Object[] args) { return If.Is(args, AddNumbers) ?? If.Is(args, AddMatrices) ?? - If.Is(args, AddCNumbers) ?? - If.Is(args, AddCMatrices) ?? + If.IsEither(args, CastNumber, CastNumber, AddCNumbers) ?? + If.IsEither(args, CastMatrix, CastMatrix, AddCMatrices) ?? If.Is(args, AddStrings) ?? If.Is(args, AddAnyStr) ?? If.Is(args, AddStrAny) ?? @@ -176,6 +213,8 @@ public static Object Sub(Object[] args) { return If.Is(args, SubNumbers) ?? If.Is(args, SubMatrices) ?? + If.IsEither(args, CastNumber, CastNumber, SubCNumbers) ?? + If.IsEither(args, CastMatrix, CastMatrix, SubCMatrices) ?? If.IsNotNull(args, AsNumber, SubNumbers); } @@ -185,6 +224,10 @@ public static Object Mul(Object[] args) If.Is(args, MulMatrices) ?? If.Is(args, MulNumMat) ?? If.Is(args, MulMatNum) ?? + If.IsEither(args, CastNumber, CastNumber, MulCNumbers) ?? + If.IsEither(args, CastMatrix, CastMatrix, MulCMatrices) ?? + If.IsEither(args, CastNumber, CastMatrix, MulCNumMat) ?? + If.IsEither(args, CastMatrix, CastNumber, MulCMatNum) ?? If.IsNotNull(args, AsNumber, MulNumbers); } @@ -192,6 +235,8 @@ public static Object RDiv(Object[] args) { return If.Is(args, RDivNumbers) ?? If.Is(args, RDivNumMat) ?? + If.IsEither(args, CastNumber, CastNumber, RDivCNumbers) ?? + If.IsEither(args, CastNumber, CastMatrix, RDivCNumMat) ?? If.IsNotNull(args, AsNumber, RDivNumbers); } @@ -199,6 +244,8 @@ public static Object LDiv(Object[] args) { return If.Is(args, LDivNumbers) ?? If.Is(args, LDivMatNum) ?? + If.IsEither(args, CastNumber, CastNumber, LDivCNumbers) ?? + If.IsEither(args, CastMatrix, CastNumber, LDivCMatNum) ?? If.IsNotNull(args, AsNumber, LDivNumbers); } @@ -208,12 +255,17 @@ public static Object Pow(Object[] args) If.Is(args, PowMatrices) ?? If.Is(args, PowMatNum) ?? If.Is(args, PowNumMat) ?? + If.IsEither(args, CastNumber, CastNumber, PowCNumbers) ?? + If.IsEither(args, CastMatrix, CastMatrix, PowCMatrices) ?? + If.IsEither(args, CastMatrix, CastNumber, PowCMatNum) ?? + If.IsEither(args, CastNumber, CastMatrix, PowCNumMat) ?? If.IsNotNull(args, AsNumber, PowNumbers); } public static Object Mod(Object[] args) { return If.Is(args, ModNumbers) ?? + If.IsEither(args, CastNumber, CastNumber, ModCNumbers) ?? If.IsNotNull(args, AsNumber, ModNumbers); } @@ -251,6 +303,8 @@ public static Object Eq(Object[] args) If.Is(args, EqMatBool) ?? If.Is(args, EqBoolMat) ?? If.Is(args, EqStrings) ?? + If.IsEither(args, CastNumber, CastNumber, EqCNumbers) ?? + If.IsEither(args, CastMatrix, CastMatrix, EqCMatrices) ?? Object.ReferenceEquals(args[1], args[0]); } @@ -264,6 +318,8 @@ public static Object Neq(Object[] args) If.Is(args, NeqMatBool) ?? If.Is(args, NeqBoolMat) ?? If.Is(args, NeqStrings) ?? + If.IsEither(args, CastNumber, CastNumber, NeqCNumbers) ?? + If.IsEither(args, CastMatrix, CastMatrix, NeqCMatrices) ?? !Object.ReferenceEquals(args[1], args[0]); } @@ -273,6 +329,10 @@ public static Object Gt(Object[] args) If.Is(args, GtMatrices) ?? If.Is(args, GtMatNum) ?? If.Is(args, GtNumMat) ?? + If.IsEither(args, CastNumber, CastNumber, GtCNumbers) ?? + If.IsEither(args, CastMatrix, CastMatrix, GtCMatrices) ?? + If.IsEither(args, CastMatrix, CastNumber, GtCMatNum) ?? + If.IsEither(args, CastNumber, CastMatrix, GtCNumMat) ?? (args[1].ToNumber() > args[0].ToNumber()); } @@ -282,6 +342,10 @@ public static Object Geq(Object[] args) If.Is(args, GeqMatrices) ?? If.Is(args, GeqMatNum) ?? If.Is(args, GeqNumMat) ?? + If.IsEither(args, CastNumber, CastNumber, GeqCNumbers) ?? + If.IsEither(args, CastMatrix, CastMatrix, GeqCMatrices) ?? + If.IsEither(args, CastMatrix, CastNumber, GeqCMatNum) ?? + If.IsEither(args, CastNumber, CastMatrix, GeqCNumMat) ?? (args[1].ToNumber() >= args[0].ToNumber()); } @@ -291,6 +355,10 @@ public static Object Lt(Object[] args) If.Is(args, LtMatrices) ?? If.Is(args, LtMatNum) ?? If.Is(args, LtNumMat) ?? + If.IsEither(args, CastNumber, CastNumber, LtCNumbers) ?? + If.IsEither(args, CastMatrix, CastMatrix, LtCMatrices) ?? + If.IsEither(args, CastMatrix, CastNumber, LtCMatNum) ?? + If.IsEither(args, CastNumber, CastMatrix, LtCNumMat) ?? (args[1].ToNumber() < args[0].ToNumber()); } @@ -300,6 +368,10 @@ public static Object Leq(Object[] args) If.Is(args, LeqMatrices) ?? If.Is(args, LeqMatNum) ?? If.Is(args, LeqNumMat) ?? + If.IsEither(args, CastNumber, CastNumber, LeqCNumbers) ?? + If.IsEither(args, CastMatrix, CastMatrix, LeqCMatrices) ?? + If.IsEither(args, CastMatrix, CastNumber, LeqCMatNum) ?? + If.IsEither(args, CastNumber, CastMatrix, LeqCNumMat) ?? (args[1].ToNumber() <= args[0].ToNumber()); } diff --git a/src/Mages.Core/Runtime/Converters/ConverterExtensions.cs b/src/Mages.Core/Runtime/Converters/ConverterExtensions.cs index 3cfa1864..59919dcd 100644 --- a/src/Mages.Core/Runtime/Converters/ConverterExtensions.cs +++ b/src/Mages.Core/Runtime/Converters/ConverterExtensions.cs @@ -51,38 +51,18 @@ public static class ConverterExtensions /// /// The value to convert. /// The boolean representation of the value. - public static Boolean ToBoolean(this Object value) + public static Boolean ToBoolean(this Object value) => value switch { - if (value is Boolean bval) - { - return bval; - } - else if (value != null) - { - var nval = value as Double?; - - if (nval.HasValue) - { - return nval.Value.ToBoolean(); - } - else if (value is String sval) - { - return sval.ToBoolean(); - } - else if (value is Double[,] mval) - { - return mval.ToBoolean(); - } - else if (value is IDictionary oval) - { - return oval.ToBoolean(); - } - - return true; - } - - return false; - } + null => false, + Boolean bval => bval, + Double nval => nval.ToBoolean(), + Complex cval => cval.ToBoolean(), + String sval => sval.ToBoolean(), + Double[,] mval => mval.ToBoolean(), + Complex[,] cmval => cmval.ToBoolean(), + IDictionary oval => oval.ToBoolean(), + _ => true + }; /// /// Returns the boolean representation of the given numeric value. @@ -91,6 +71,13 @@ public static Boolean ToBoolean(this Object value) /// The boolean representation of the value. public static Boolean ToBoolean(this Double value) => value != 0.0; + /// + /// Returns the boolean representation of the given complex value. + /// + /// The value to convert. + /// The boolean representation of the value. + public static Boolean ToBoolean(this Complex value) => value != Complex.Zero; + /// /// Returns the boolean representation of the given string value. /// @@ -105,6 +92,13 @@ public static Boolean ToBoolean(this Object value) /// The boolean representation of the value. public static Boolean ToBoolean(this Double[,] matrix) => matrix.AnyTrue(); + /// + /// Returns the boolean representation of the given complex matrix value. + /// + /// The matrix to convert. + /// The boolean representation of the value. + public static Boolean ToBoolean(this Complex[,] matrix) => matrix.AnyTrue(); + /// /// Returns the boolean representation of the given object value. /// @@ -139,6 +133,22 @@ public static IDictionary ToObject(this Object value) return result; } + else if (value is Complex[,] cmatrix) + { + var result = new Dictionary(); + var rows = cmatrix.GetRows(); + var columns = cmatrix.GetColumns(); + + for (int i = 0, k = 0; i < rows; i++) + { + for (var j = 0; j < columns; j++, k++) + { + result[k.ToString()] = cmatrix[i, j]; + } + } + + return result; + } else { var result = new Dictionary(); @@ -157,32 +167,16 @@ public static IDictionary ToObject(this Object value) /// /// The value to convert. /// The number representation of the value. - public static Double ToNumber(this Object value) + public static Double ToNumber(this Object value) => value switch { - if (value is Double dval) - { - return dval; - } - else if (value != null) - { - var bval = value as Boolean?; - - if (bval.HasValue) - { - return bval.Value.ToNumber(); - } - else if (value is String sval) - { - return sval.ToNumber(); - } - else if (value is Double[,] mval) - { - return mval.ToNumber(); - } - } - - return Double.NaN; - } + null => double.NaN, + Double dval => dval, + Boolean bval => bval.ToNumber(), + String sval => sval.ToNumber(), + Double[,] mval => mval.ToNumber(), + Complex[,] cmval => cmval.ToNumber(), + _ => Double.NaN + }; /// /// Returns the complex representation of the given value. @@ -244,15 +238,15 @@ public static Double ToNumber(this Double[,] matrix) } /// - /// Returns the number representation of the given matrix value. + /// Returns the number representation of the given complex matrix value. /// - /// The matrix to convert. + /// The complex matrix to convert. /// The number representation of the value. - public static Complex ToNumber(this Complex[,] matrix) + public static Double ToNumber(this Complex[,] matrix) { if (matrix.GetRows() == 1 && matrix.GetColumns() == 1) { - return matrix[0, 0]; + return Complex.Abs(matrix[0, 0]); } return Double.NaN; diff --git a/src/Mages.Core/Runtime/Functions/If.cs b/src/Mages.Core/Runtime/Functions/If.cs index a8dd06cb..db1b391e 100644 --- a/src/Mages.Core/Runtime/Functions/If.cs +++ b/src/Mages.Core/Runtime/Functions/If.cs @@ -68,6 +68,21 @@ public static Object Is(Object[] args, Func(Object[] args, Func f) => args[0] is T1 && args[2] is T3 ? f((T1)args[0], args[1], (T3)args[2]) : null; + /// + /// Checks if the first argument is either T1 or T2 and the second argument is either T1 or T2. + /// + /// The type of the first value. + /// The type of the second value. + /// The type of the third value. + /// The type of the fourth value. + /// The arguments to check. + /// The converter for the first part. + /// The converter for the second part. + /// The callback to invoke if fulfilled. + /// The result of the callback or null. + public static Object IsEither(Object[] args, Func conv1, Func conv2, Func f) => + args[0] is T1 or T2 && args[1] is T3 or T4 ? f(args[0] is T1 t0 ? conv1(t0) : (T2)args[0], args[1] is T3 t1 ? conv2(t1) : (T4)args[1]) : null; + /// /// Checks if the provided args are all non-null. Performs the conversion and invokes /// the result if successful. diff --git a/src/Mages.Core/Runtime/Logic.cs b/src/Mages.Core/Runtime/Logic.cs index 13aafbdf..2b2b0213 100644 --- a/src/Mages.Core/Runtime/Logic.cs +++ b/src/Mages.Core/Runtime/Logic.cs @@ -2,6 +2,7 @@ { using Mages.Core.Runtime.Converters; using System; + using System.Numerics; static class Logic { @@ -20,6 +21,11 @@ public static Boolean IsInteger(this Double value) return Math.Truncate(value) == value; } + public static Boolean IsInteger(this Complex value) + { + return value.Imaginary == 0.0 && value.Real.IsInteger(); + } + public static Boolean AnyTrue(this Double[,] matrix) { var rows = matrix.GetRows(); @@ -37,6 +43,23 @@ public static Boolean AnyTrue(this Double[,] matrix) return res; } + public static Boolean AnyTrue(this Complex[,] matrix) + { + var rows = matrix.GetRows(); + var cols = matrix.GetColumns(); + var res = false; + + for (var i = 0; i < rows; i++) + { + for (var j = 0; !res && j < cols; j++) + { + res = matrix[i, j].ToBoolean(); + } + } + + return res; + } + public static Boolean AllTrue(this Double[,] matrix) { var rows = matrix.GetRows(); @@ -53,5 +76,22 @@ public static Boolean AllTrue(this Double[,] matrix) return res; } + + public static Boolean AllTrue(this Complex[,] matrix) + { + var rows = matrix.GetRows(); + var cols = matrix.GetColumns(); + var res = true; + + for (var i = 0; i < rows; i++) + { + for (var j = 0; res && j < cols; j++) + { + res = matrix[i, j].ToBoolean(); + } + } + + return res; + } } } diff --git a/src/Mages.Core/Runtime/Mathx.cs b/src/Mages.Core/Runtime/Mathx.cs index 8b37bb5d..2c5f086c 100644 --- a/src/Mages.Core/Runtime/Mathx.cs +++ b/src/Mages.Core/Runtime/Mathx.cs @@ -47,9 +47,13 @@ static class Mathx public const Double LanczosR = 10.900511; - public static Complex Min(Complex a, Complex b) => Complex.Abs(a) > Complex.Abs(b) ? b : a; + public static Boolean IsGreaterThan(Complex a, Complex b) => Complex.Abs(a) > Complex.Abs(b); - public static Complex Max(Complex a, Complex b) => Complex.Abs(a) > Complex.Abs(b) ? a : b; + public static Boolean IsLessThan(Complex a, Complex b) => Complex.Abs(a) < Complex.Abs(b); + + public static Complex Min(Complex a, Complex b) => IsGreaterThan(a, b) ? b : a; + + public static Complex Max(Complex a, Complex b) => IsGreaterThan(a, b) ? a : b; public static Complex Ceiling(Complex value) => new Complex(Math.Ceiling(value.Real), Math.Ceiling(value.Imaginary)); @@ -65,6 +69,13 @@ public static Complex Sign(Complex value) return new Complex(Math.Cos(arg), Math.Sin(arg)); } + public static Complex Mod(Complex a, Complex b) + { + var x = a / b; + var z = new Complex(Math.Floor(x.Real), Math.Floor(x.Imaginary)) * b; + return a - z; + } + public static Complex Factorial(Complex value) => new Complex(Factorial(value.Real), Factorial(value.Imaginary)); public static Double Factorial(Double value) diff --git a/src/Mages.Core/Runtime/Matrix.cs b/src/Mages.Core/Runtime/Matrix.cs index d4f8cc63..1d49997c 100644 --- a/src/Mages.Core/Runtime/Matrix.cs +++ b/src/Mages.Core/Runtime/Matrix.cs @@ -185,6 +185,28 @@ public static Boolean Fits(this T[,] a, T[,] b) return null; } + public static Complex[,] Subtract(this Complex[,] a, Complex[,] b) + { + if (a.Fits(b)) + { + var rows = a.GetRows(); + var cols = a.GetColumns(); + var result = new Complex[rows, cols]; + + for (var i = 0; i < rows; i++) + { + for (var j = 0; j < cols; j++) + { + result[i, j] = a[i, j] - b[i, j]; + } + } + + return result; + } + + return null; + } + public static Double[,] Multiply(this Double[,] a, Double[,] b) { var rows = a.GetRows(); @@ -216,6 +238,37 @@ public static Boolean Fits(this T[,] a, T[,] b) return null; } + public static Complex[,] Multiply(this Complex[,] a, Complex[,] b) + { + var rows = a.GetRows(); + var cols = b.GetColumns(); + var length = a.GetColumns(); + + if (length == b.GetRows()) + { + var result = new Complex[rows, cols]; + + for (var i = 0; i < rows; i++) + { + for (var j = 0; j < cols; j++) + { + var value = Complex.Zero; + + for (var k = 0; k < length; k++) + { + value += a[i, k] * b[k, j]; + } + + result[i, j] = value; + } + } + + return result; + } + + return null; + } + public static Double[,] Multiply(this Double[,] a, Double b) { var rows = a.GetRows(); @@ -233,11 +286,33 @@ public static Boolean Fits(this T[,] a, T[,] b) return result; } + public static Complex[,] Multiply(this Complex[,] a, Complex b) + { + var rows = a.GetRows(); + var cols = a.GetColumns(); + var result = new Complex[rows, cols]; + + for (var i = 0; i < rows; i++) + { + for (var j = 0; j < cols; j++) + { + result[i, j] = a[i, j] * b; + } + } + + return result; + } + public static Double[,] Divide(this Double[,] a, Double b) { return a.Multiply(1.0 / b); } + public static Complex[,] Divide(this Complex[,] a, Complex b) + { + return a.Multiply(1.0 / b); + } + public static T[,] Transpose(this T[,] matrix) { var rows = matrix.GetRows(); @@ -277,16 +352,16 @@ public static Boolean IsSquare(this T[,] matrix) return result; } - public static Double[,] Identity(this Double[,] matrix) + public static T[,] Identity(this T[,] matrix, T element) { var rows = matrix.GetRows(); var cols = matrix.GetColumns(); - var result = new Double[rows, cols]; + var result = new T[rows, cols]; var length = Math.Min(rows, cols); for (var i = 0; i < length; i++) { - result[i, i] = 1.0; + result[i, i] = element; } return result; @@ -314,12 +389,52 @@ public static Boolean IsSquare(this T[,] matrix) return null; } + public static Complex[,] Pow(this Complex[,] a, Complex[,] b) + { + if (a.Fits(b)) + { + var rows = a.GetRows(); + var cols = a.GetColumns(); + var result = new Complex[rows, cols]; + + for (var i = 0; i < rows; i++) + { + for (var j = 0; j < cols; j++) + { + result[i, j] = Complex.Pow(a[i, j], b[i, j]); + } + } + + return result; + } + + return null; + } + public static Double[,] Pow(this Double[,] matrix, Double value) { if (value.IsInteger() && matrix.IsSquare()) { var n = (Int32)value; - var result = matrix.Identity(); + var result = matrix.Identity(1.0); + + while (n-- > 0) + { + result = result.Multiply(matrix); + } + + return result; + } + + return null; + } + + public static Complex[,] Pow(this Complex[,] matrix, Complex value) + { + if (value.IsInteger() && matrix.IsSquare()) + { + var n = (Int32)value.Real; + var result = matrix.Identity(Complex.One); while (n-- > 0) { @@ -349,6 +464,23 @@ public static Boolean IsSquare(this T[,] matrix) return result; } + public static Complex[,] Pow(this Complex value, Complex[,] matrix) + { + var result = matrix.Fill(value); + var rows = matrix.GetRows(); + var cols = matrix.GetColumns(); + + for (var i = 0; i < rows; i++) + { + for (var j = 0; j < cols; j++) + { + result[i, j] = Complex.Pow(result[i, j], matrix[i, j]); + } + } + + return result; + } + public static T GetValue(this T[,] matrix, Int32 row, Int32 col) { var rows = matrix.GetRows(); @@ -373,11 +505,31 @@ public static void SetValue(this T[,] matrix, Int32 row, Int32 col, T value) } } - public static T[,] ForEach(this T[,] matrix, Func apply) + public static Int32 CountAll(this T[,] matrix, Func apply) { var rows = matrix.GetRows(); var cols = matrix.GetColumns(); - var result = new T[rows, cols]; + var result = 0; + + for (var i = 0; i < rows; i++) + { + for (var j = 0; j < cols; j++) + { + if (apply(matrix[i, j])) + { + result++; + } + } + } + + return result; + } + + public static T2[,] ForEach(this T1[,] matrix, Func apply) + { + var rows = matrix.GetRows(); + var cols = matrix.GetColumns(); + var result = new T2[rows, cols]; for (var i = 0; i < rows; i++) { @@ -489,6 +641,30 @@ public static Object Reduce(this T[,] matrix, Func reducer) return null; } + public static Double[,] IsGreaterThan(this Complex[,] a, Complex b) => a.IsGreaterThan(a.Fill(b)); + + public static Double[,] IsGreaterThan(this Complex[,] a, Complex[,] b) + { + if (a.Fits(b)) + { + var rows = a.GetRows(); + var cols = a.GetColumns(); + var result = new Double[rows, cols]; + + for (var i = 0; i < rows; i++) + { + for (var j = 0; j < cols; j++) + { + result[i, j] = Mathx.IsGreaterThan(a[i, j], b[i, j]).ToNumber(); + } + } + + return result; + } + + return null; + } + public static Double[,] IsGreaterOrEqual(this Double[,] a, Double b) => a.IsGreaterOrEqual(a.Fill(b)); public static Double[,] IsGreaterOrEqual(this Double[,] a, Double[,] b) @@ -513,8 +689,34 @@ public static Object Reduce(this T[,] matrix, Func reducer) return null; } + public static Double[,] IsGreaterOrEqual(this Complex[,] a, Complex b) => a.IsGreaterOrEqual(a.Fill(b)); + + public static Double[,] IsGreaterOrEqual(this Complex[,] a, Complex[,] b) + { + if (a.Fits(b)) + { + var rows = a.GetRows(); + var cols = a.GetColumns(); + var result = new Double[rows, cols]; + + for (var i = 0; i < rows; i++) + { + for (var j = 0; j < cols; j++) + { + result[i, j] = (!Mathx.IsGreaterThan(b[i, j], a[i, j])).ToNumber(); + } + } + + return result; + } + + return null; + } + public static Double[,] AreNotEqual(this Double[,] a, Double b) => a.AreNotEqual(a.Fill(b)); + public static Double[,] AreNotEqual(this Complex[,] a, Complex b) => a.AreNotEqual(a.Fill(b)); + public static Object Map(this Double[,] matrix, Function f) { var result = new Dictionary(); @@ -609,6 +811,28 @@ public static Object Reduce(this Double[,] matrix, Function f, Object start) return null; } + public static Double[,] AreNotEqual(this Complex[,] a, Complex[,] b) + { + if (a.Fits(b)) + { + var rows = a.GetRows(); + var cols = a.GetColumns(); + var result = new Double[rows, cols]; + + for (var i = 0; i < rows; i++) + { + for (var j = 0; j < cols; j++) + { + result[i, j] = (a[i, j] != b[i, j]).ToNumber(); + } + } + + return result; + } + + return null; + } + public static Double[,] IsLessThan(this Double[,] a, Double b) => a.IsLessThan(a.Fill(b)); public static Double[,] IsLessThan(this Double[,] a, Double[,] b) @@ -633,6 +857,30 @@ public static Object Reduce(this Double[,] matrix, Function f, Object start) return null; } + public static Double[,] IsLessThan(this Complex[,] a, Complex b) => a.IsLessThan(a.Fill(b)); + + public static Double[,] IsLessThan(this Complex[,] a, Complex[,] b) + { + if (a.Fits(b)) + { + var rows = a.GetRows(); + var cols = a.GetColumns(); + var result = new Double[rows, cols]; + + for (var i = 0; i < rows; i++) + { + for (var j = 0; j < cols; j++) + { + result[i, j] = Mathx.IsGreaterThan(b[i, j], a[i, j]).ToNumber(); + } + } + + return result; + } + + return null; + } + public static Double[,] IsLessOrEqual(this Double[,] a, Double b) => a.IsLessOrEqual(a.Fill(b)); public static Double[,] IsLessOrEqual(this Double[,] a, Double[,] b) @@ -657,6 +905,30 @@ public static Object Reduce(this Double[,] matrix, Function f, Object start) return null; } + public static Double[,] IsLessOrEqual(this Complex[,] a, Complex b) => a.IsLessOrEqual(a.Fill(b)); + + public static Double[,] IsLessOrEqual(this Complex[,] a, Complex[,] b) + { + if (a.Fits(b)) + { + var rows = a.GetRows(); + var cols = a.GetColumns(); + var result = new Double[rows, cols]; + + for (var i = 0; i < rows; i++) + { + for (var j = 0; j < cols; j++) + { + result[i, j] = (!Mathx.IsGreaterThan(a[i, j], b[i, j])).ToNumber(); + } + } + + return result; + } + + return null; + } + public static Double[,] AreEqual(this Double[,] a, Double b) => a.AreEqual(a.Fill(b)); public static Double[,] AreEqual(this Double[,] a, Double[,] b) diff --git a/src/Mages.Core/Runtime/Stringify.cs b/src/Mages.Core/Runtime/Stringify.cs index 93d98c8e..b71ab5ea 100644 --- a/src/Mages.Core/Runtime/Stringify.cs +++ b/src/Mages.Core/Runtime/Stringify.cs @@ -43,7 +43,7 @@ public static class Stringify /// /// Converts the matrix to a string. /// - public static String This(Double[,] value) + public static String This(T[,] value) { var sb = StringBuilderPool.Pull(); var rows = value.GetLength(0); @@ -64,7 +64,7 @@ public static String This(Double[,] value) sb.Append(','); } - sb.Append(value[i, j].ToString(CultureInfo.InvariantCulture)); + sb.Append(This(value[i, j])); } } @@ -101,6 +101,7 @@ public static String This(Double[,] value) Double d => This(d), Boolean b => This(b), Complex c => This(c), + Complex[,] m => This(m), _ => "(unknown)" }; diff --git a/src/Mages.Core/Runtime/UnaryOperators.cs b/src/Mages.Core/Runtime/UnaryOperators.cs index 55ad1545..4c03e5ae 100644 --- a/src/Mages.Core/Runtime/UnaryOperators.cs +++ b/src/Mages.Core/Runtime/UnaryOperators.cs @@ -49,8 +49,17 @@ static class UnaryOperators #region Other Fields + private static readonly Func NumberToMatrix = x => x.ToMatrix(); + private static readonly Func CNumberToMatrix = x => x.ToMatrix(); private static readonly Func TransposeMatrix = x => x.Transpose(); private static readonly Func TransposeCMatrix = x => x.Transpose(); + + #endregion + + #region Abs + + private static readonly Func AbsNumber = x => Math.Abs(x); + private static readonly Func AbsCNumber = x => Complex.Abs(x); private static readonly Func AbsMatrix = x => Matrix.Abs(x); private static readonly Func AbsCMatrix = x => Matrix.Abs(x); @@ -93,9 +102,13 @@ public static Object Factorial(Object[] args) => public static Object Transpose(Object[] args) => If.Is(args, TransposeMatrix) ?? If.Is(args, TransposeCMatrix) ?? + If.Is(args, NumberToMatrix) ?? + If.Is(args, CNumberToMatrix) ?? args[0].ToNumber().ToMatrix(); public static Object Abs(Object[] args) => + If.Is(args, AbsNumber) ?? + If.Is(args, AbsCNumber) ?? If.Is(args, AbsMatrix) ?? If.Is(args, AbsCMatrix) ?? Math.Abs(args[0].ToNumber()); diff --git a/src/Mages.Core/Vm/Operations/InitMatOperation.cs b/src/Mages.Core/Vm/Operations/InitMatOperation.cs index 0ad8c4f5..95e308c2 100644 --- a/src/Mages.Core/Vm/Operations/InitMatOperation.cs +++ b/src/Mages.Core/Vm/Operations/InitMatOperation.cs @@ -1,7 +1,6 @@ namespace Mages.Core.Vm.Operations { using Mages.Core.Runtime; - using Mages.Core.Runtime.Converters; using System; /// @@ -20,8 +19,8 @@ public InitMatOperation(Int32 row, Int32 col) public void Invoke(IExecutionContext context) { - var value = context.Pop().ToNumber(); - var matrix = (Double[,])context.Pop(); + var value = context.Pop(); + var matrix = (Object[,])context.Pop(); matrix.SetValue(_row, _col, value); context.Push(matrix); } diff --git a/src/Mages.Core/Vm/Operations/NewMatOperation.cs b/src/Mages.Core/Vm/Operations/NewMatOperation.cs index 648006ab..181df628 100644 --- a/src/Mages.Core/Vm/Operations/NewMatOperation.cs +++ b/src/Mages.Core/Vm/Operations/NewMatOperation.cs @@ -18,7 +18,7 @@ public NewMatOperation(Int32 rows, Int32 cols) public void Invoke(IExecutionContext context) { - context.Push(new Double[_rows, _cols]); + context.Push(new Object[_rows, _cols]); } public override String ToString() diff --git a/src/Mages.Core/Vm/Operations/SetMatOperation.cs b/src/Mages.Core/Vm/Operations/SetMatOperation.cs new file mode 100644 index 00000000..9008285f --- /dev/null +++ b/src/Mages.Core/Vm/Operations/SetMatOperation.cs @@ -0,0 +1,42 @@ +namespace Mages.Core.Vm.Operations +{ + using Mages.Core.Runtime; + using Mages.Core.Runtime.Converters; + using System; + using System.Numerics; + + /// + /// Converts the generic matrix to a specific matrix. + /// + sealed class SetMatOperation : IOperation + { + public SetMatOperation() + { + } + + public void Invoke(IExecutionContext context) + { + var matrix = (Object[,])context.Pop(); + var rows = matrix.GetRows(); + var cols = matrix.GetColumns(); + var count = matrix.CountAll(m => m is Complex); + var isComplex = count > 0; + + if (isComplex) + { + var result = matrix.ForEach(z => z.ToComplex()); + context.Push(result); + } + else + { + var result = matrix.ForEach(z => z.ToNumber()); + context.Push(result); + } + } + + public override String ToString() + { + return String.Concat("setmat"); + } + } +} From 0398677a1c01e5207de8f0ad2801f48ce812f1d6 Mon Sep 17 00:00:00 2001 From: Florian Rappl Date: Thu, 20 May 2021 14:37:11 +0200 Subject: [PATCH 15/27] Improved docs --- CHANGELOG.md | 1 + README.md | 2 +- build.cake | 6 ++-- doc/functions.md | 4 +++ doc/introduction.md | 4 +-- doc/types.md | 10 ++++++ .../Runtime/Converters/ConverterExtensions.cs | 35 +++++++++++++------ 7 files changed, 46 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 16ce69a9..8b253f03 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ # 2.0.0 +- Migrated to use GitHub actions - Added missing helpers and constants (#98) - Added complex helpers (#97) - Added complex numbers support (#96) diff --git a/README.md b/README.md index 62b9b3bc..395125e7 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ Among other applications, MAGES is used in [Microsoft's PowerToys](https://githu ### Current Status -MAGES was just updated with support for complex numbers. Also, the build target and runtime has been updated to make use of modern possibilities. +MAGES was just updated (v2.0.0) with support for complex numbers. Also, the build target and runtime has been updated to make use of modern possibilities. ### Previous Status diff --git a/build.cake b/build.cake index 31db522d..ffbc5d75 100644 --- a/build.cake +++ b/build.cake @@ -277,8 +277,8 @@ Task("Publish-GitHub-Release") { Name = version, Body = String.Join(Environment.NewLine, releaseNotes.Notes), - Prerelease = false, - TargetCommitish = "main" + Prerelease = target != "Publish", + TargetCommitish = target == "Publish" ? "main" : "devel" }).Result; var target = nugetRoot + Directory("lib") + Directory("netstandard2.0"); @@ -326,7 +326,7 @@ Task("Publish") .IsDependentOn("Publish-GitHub-Release"); Task("PrePublish") - .IsDependentOn("Publish-Packages"); + .IsDependentOn("Publish-GitHub-Release"); // Execution // ---------------------------------------- diff --git a/doc/functions.md b/doc/functions.md index f68356c5..40096717 100644 --- a/doc/functions.md +++ b/doc/functions.md @@ -90,6 +90,8 @@ x = exp(1) // 2.72... M = exp([-1, 0]) // [0.36..., 1] ``` +The values `exp(0)` and `exp(1)` have been also conserved in constants (`exp0` and `exp1`). For `exp(1)` also `e` was taken as a global constant. + ### Logarithmic Function Works with numbers and matrices (applied to each value). @@ -99,6 +101,8 @@ x = log(1) // 0 M = log([0.5, 2]) // [-0.69..., 0.69...] ``` +Also cases for other basis such as `log2` or `log10` exist. + ## Comparison Functions ### Minimum of Values diff --git a/doc/introduction.md b/doc/introduction.md index 6b22b69b..d3c28efa 100644 --- a/doc/introduction.md +++ b/doc/introduction.md @@ -99,8 +99,8 @@ On starting the REPL we see the following: \____|__ /\____|__ /\______ /_______ /_______ / \/ \/ \/ \/ \/ - (c) Florian Rappl, 2016 - Version 0.4.5995 + (c) Florian Rappl, 2021 + Version 2.0.0 Running on Microsoft Windows NT 6.2.9200.0 For help type 'help()'. diff --git a/doc/types.md b/doc/types.md index 0a8d4402..b7003f85 100644 --- a/doc/types.md +++ b/doc/types.md @@ -6,6 +6,8 @@ MAGES maps every .NET data type to one of its data types: * Boolean (`System.Boolean`) * String (`System.String`) * Matrix (`System.Double[,]`) +* Complex (`System.Numerics.Complex`) +* Complex Matrix (`System.Numerics.Complex[,]`) * Object (`System.Collections.Generic.IDictionary`) * Function (`Mages.Core.Function`, essentially a `Delegate` mapping `Object[]` to `Object`) * Nothing (`null`) @@ -18,6 +20,7 @@ The following table yields the essential type mapping. | MAGES | .NET | |--------- | --------------------------- | +| Complex | Complex | | Number | Double | | | Single | | | Decimal | @@ -31,6 +34,7 @@ The following table yields the essential type mapping. | Boolean | Boolean | | String | String | | | Char | +| CMatrix | Complex[,] | | Matrix | Double[,] | | | Double[] | | | List | @@ -85,12 +89,18 @@ The following tables yield information on casting possibilities. | Number | Boolean | `y = any(x)` | | | String | `y = stringify(x)` | | | Matrix | `y = x'` | +| Complex | Boolean | `y = any(x)` | +| | String | `y = stringify(x)` | +| | Matrix | `y = x'` | | Boolean | Number | `y = +x` | | | String | `y = stringify(x)` | | | Matrix | `y = x'` | | String | Number | `y = +x` | | | Boolean | `y = any(x)` | | | Matrix | `y = x'` | +| CMatrix | Number | (nothing) | +| | Boolean | `y = any(x)` | +| | String | `y = stringify(x)` | | Matrix | Number | (nothing) | | | Boolean | `y = any(x)` | | | String | `y = stringify(x)` | diff --git a/src/Mages.Core/Runtime/Converters/ConverterExtensions.cs b/src/Mages.Core/Runtime/Converters/ConverterExtensions.cs index 59919dcd..1422d7e0 100644 --- a/src/Mages.Core/Runtime/Converters/ConverterExtensions.cs +++ b/src/Mages.Core/Runtime/Converters/ConverterExtensions.cs @@ -22,7 +22,8 @@ public static class ConverterExtensions Complex _ => "Complex", String _ => "String", Boolean _ => "Boolean", - Double[,] or Complex[,] _ =>"Matrix", + Double[,] _ => "Matrix", + Complex[,] _ => "CMatrix", Function _ => "Function", IDictionary _ => "Object", _ => "Undefined", @@ -37,9 +38,11 @@ public static class ConverterExtensions public static Object To(this Object value, String type) => type switch { "Number" => value.ToNumber(), + "Complex" => value.ToComplex(), "String" => Stringify.This(value), "Boolean" => value.ToBoolean(), "Matrix" => value.ToNumber().ToMatrix(), + "CMatrix" => value.ToComplex().ToMatrix(), "Function" => value as Function, "Object" => value as IDictionary, "Undefined" => null, @@ -169,7 +172,7 @@ public static IDictionary ToObject(this Object value) /// The number representation of the value. public static Double ToNumber(this Object value) => value switch { - null => double.NaN, + null => Double.NaN, Double dval => dval, Boolean bval => bval.ToNumber(), String sval => sval.ToNumber(), @@ -183,15 +186,12 @@ public static IDictionary ToObject(this Object value) /// /// The value to convert. /// The complex representation of the value. - public static Complex ToComplex(this Object value) + public static Complex ToComplex(this Object value) => value switch { - if (value is Complex c) - { - return c; - } - - return value.ToNumber(); - } + Complex c => c, + Complex[,] m => m.ToComplex(), + _ => value.ToNumber() + }; /// /// Returns the number representation of the given boolean value. @@ -207,6 +207,21 @@ public static Complex ToComplex(this Object value) /// The complex representation of the value. public static Complex ToComplex(this Boolean value) => value ? Complex.One : Complex.Zero; + /// + /// Returns the complex representation of the given complex matrix value. + /// + /// The complex matrix to convert. + /// The complex representation of the value. + public static Complex ToComplex(this Complex[,] matrix) + { + if (matrix.GetRows() == 1 && matrix.GetColumns() == 1) + { + return matrix[0, 0]; + } + + return Double.NaN; + } + /// /// Returns the number representation of the given string value. /// From c2f31cd81c7646b198e3b6fca86484e807a5f872 Mon Sep 17 00:00:00 2001 From: Florian Rappl Date: Thu, 20 May 2021 14:56:27 +0200 Subject: [PATCH 16/27] Fixed cake file --- build.cake | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/build.cake b/build.cake index ffbc5d75..1d7e6345 100644 --- a/build.cake +++ b/build.cake @@ -30,6 +30,7 @@ var nugetRoot = buildResultDir + Directory("nuget"); var chocolateyRoot = buildResultDir + Directory("chocolatey"); var squirrelRoot = buildResultDir + Directory("squirrel"); var releaseDir = squirrelRoot + Directory("release"); +var isPublish = target == "Publish"; if (isRunningOnGitHubActions) { @@ -277,8 +278,8 @@ Task("Publish-GitHub-Release") { Name = version, Body = String.Join(Environment.NewLine, releaseNotes.Notes), - Prerelease = target != "Publish", - TargetCommitish = target == "Publish" ? "main" : "devel" + Prerelease = !isPublish, + TargetCommitish = isPublish ? "main" : "devel" }).Result; var target = nugetRoot + Directory("lib") + Directory("netstandard2.0"); From ea027492a748bf4db375c939e61f0688faab6502 Mon Sep 17 00:00:00 2001 From: Florian Rappl Date: Thu, 20 May 2021 16:43:10 +0200 Subject: [PATCH 17/27] Improved Cake structure --- build.cake | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/build.cake b/build.cake index 1d7e6345..31e18ce0 100644 --- a/build.cake +++ b/build.cake @@ -15,22 +15,14 @@ #addin "Cake.Squirrel" using Octokit; +var isRunningOnGitHubActions = BuildSystem.GitHubActions.IsRunningOnGitHubActions; var target = Argument("target", "Default"); +var isPublish = target == "Publish"; var configuration = Argument("configuration", "Release"); var isRunningOnUnix = IsRunningOnUnix(); var isRunningOnWindows = IsRunningOnWindows(); var releaseNotes = ParseReleaseNotes("./CHANGELOG.md"); var version = releaseNotes.Version.ToString(); -var isRunningOnGitHubActions = BuildSystem.GitHubActions.IsRunningOnGitHubActions; -var buildDir = Directory("./src/Mages.Core/bin") + Directory(configuration) + Directory("netstandard2.0"); -var replDir = Directory("./src/Mages.Repl/bin") + Directory(configuration) + Directory("netcoreapp3.1"); -var installerDir = Directory("./src/Mages.Repl.Installer/bin") + Directory(configuration) + Directory("net45"); -var buildResultDir = Directory("./bin") + Directory(version); -var nugetRoot = buildResultDir + Directory("nuget"); -var chocolateyRoot = buildResultDir + Directory("chocolatey"); -var squirrelRoot = buildResultDir + Directory("squirrel"); -var releaseDir = squirrelRoot + Directory("release"); -var isPublish = target == "Publish"; if (isRunningOnGitHubActions) { @@ -46,6 +38,15 @@ if (isRunningOnGitHubActions) } } +var buildDir = Directory("./src/Mages.Core/bin") + Directory(configuration) + Directory("netstandard2.0"); +var replDir = Directory("./src/Mages.Repl/bin") + Directory(configuration) + Directory("netcoreapp3.1"); +var installerDir = Directory("./src/Mages.Repl.Installer/bin") + Directory(configuration) + Directory("net45"); +var buildResultDir = Directory("./bin") + Directory(version); +var nugetRoot = buildResultDir + Directory("nuget"); +var chocolateyRoot = buildResultDir + Directory("chocolatey"); +var squirrelRoot = buildResultDir + Directory("squirrel"); +var releaseDir = squirrelRoot + Directory("release"); + // Initialization // ---------------------------------------- From 9cf0a7a1dd39a73d4bd44666e88a12957bae89c0 Mon Sep 17 00:00:00 2001 From: Florian Rappl Date: Thu, 20 May 2021 17:07:16 +0200 Subject: [PATCH 18/27] Improved build deps --- build.cake | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/build.cake b/build.cake index 31e18ce0..9a23c1d9 100644 --- a/build.cake +++ b/build.cake @@ -321,16 +321,19 @@ Task("Default") .IsDependentOn("Package"); Task("Publish-Packages") + .IsDependentOn("Default") .IsDependentOn("Publish-Nuget-Package") .IsDependentOn("Publish-Chocolatey-Package"); Task("Publish") + .IsDependentOn("Publish-Packages") .IsDependentOn("Publish-GitHub-Release"); Task("PrePublish") + .IsDependentOn("Publish-Packages") .IsDependentOn("Publish-GitHub-Release"); // Execution // ---------------------------------------- -RunTarget(target); \ No newline at end of file +RunTarget(target); From f0fde2b710ca61e222bc2b31584c6dbe1e6d4f29 Mon Sep 17 00:00:00 2001 From: Florian Rappl Date: Fri, 21 May 2021 02:06:47 +0200 Subject: [PATCH 19/27] Changed range operator #76 --- CHANGELOG.md | 1 + doc/contributing.md | 6 +-- doc/first-steps.md | 4 +- doc/introduction.md | 2 +- doc/language.md | 10 ++--- doc/syntax.md | 4 +- src/Mages.Core.Tests/AuxiliariesTests.cs | 4 +- .../ComposedExpressionTests.cs | 14 +++--- src/Mages.Core.Tests/FunctionTests.cs | 7 +++ src/Mages.Core.Tests/OperationTests.cs | 14 +++--- src/Mages.Core.Tests/YampTests.cs | 4 +- src/Mages.Core/Ast/ExpressionParser.cs | 32 +++++++------- src/Mages.Core/Source/StringScanner.cs | 44 ++++++++++++------- src/Mages.Core/TextPosition.cs | 10 +++++ src/Mages.Core/Tokens/CharacterToken.cs | 5 +++ src/Mages.Core/Tokens/CommentToken.cs | 5 +++ src/Mages.Core/Tokens/EndToken.cs | 5 +++ src/Mages.Core/Tokens/IdentToken.cs | 5 +++ src/Mages.Core/Tokens/InterpolatedToken.cs | 5 +++ src/Mages.Core/Tokens/NumberToken.cs | 5 +++ src/Mages.Core/Tokens/NumberTokenizer.cs | 13 +++++- src/Mages.Core/Tokens/OperatorToken.cs | 5 +++ src/Mages.Core/Tokens/StringToken.cs | 5 +++ src/Mages.Core/Tokens/TokenType.cs | 4 ++ src/Mages.Repl.Base/Functions/Helpers.cs | 13 ++++++ .../Functions/ReplFunctions.cs | 6 +++ 26 files changed, 167 insertions(+), 65 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8b253f03..2e553fff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - Added missing helpers and constants (#98) - Added complex helpers (#97) - Added complex numbers support (#96) +- Changed the range operator from `:` to `..` (#76) - Changed library target to .NET Standard 2 (#68) - Changed application to run on .NET Core 3.1 (#68) diff --git a/doc/contributing.md b/doc/contributing.md index 5ecd021b..1c2e27b2 100644 --- a/doc/contributing.md +++ b/doc/contributing.md @@ -6,11 +6,11 @@ The following guide should help you getting on track: 1. If no issue already exists for the work you'll be doing, create one to document the problem(s) being solved and self-assign the issue. 2. Otherwise, please let us know that you are working on the problem. Regular status updates (e.g., "still in progress", "no time anymore", "practically done", "pull request issued") are highly welcome. A possible code-complete date helps us placing the issue in the overall roadmap. -2. Create a new branch! Please don't work in the `master` branch directly. It is reserved for stable versions, i.e., releases. We recommend naming the branch to match the issue being addressed (`feature-#777` or `issue-777`), but we accept all names except `master` and `devel`. +2. Create a new branch! Please don't work in the `main` branch directly. It is reserved for stable versions, i.e., releases. We recommend naming the branch to match the issue being addressed (`feature-#777` or `issue-777`), but we accept all names except `main` and `devel`. 3. Add failing tests for the change you want to make. Tests are crucial and should cover the code involved in the issue. 4. Fix stuff. Always go from edge case to edge case. 5. All tests should pass now. Also your new implementation should not break existing tests. 6. Update the documentation to reflect any potential changes. -7. Push to your fork or push your issue-specific branch to the main repository, then submit a pull request against `devel`. Never create a PR against the `master` branch! +7. Push to your fork or push your issue-specific branch to the main repository, then submit a pull request against `devel`. Never create a PR against the `main` branch! -TL;DR: There are two fixed branches, `master` and `devel`, which should not be touched directly. `master` contains the current stable version, i.e., the last released version, `devel` contains the working version, which is the branch aggregating all feature branches. \ No newline at end of file +TL;DR: There are two fixed branches, `main` and `devel`, which should not be touched directly. `main` contains the current stable version, i.e., the last released version, `devel` contains the working version, which is the branch aggregating all feature branches. diff --git a/doc/first-steps.md b/doc/first-steps.md index 81e8bf08..cbce64bc 100644 --- a/doc/first-steps.md +++ b/doc/first-steps.md @@ -61,9 +61,11 @@ Console.WriteLine(engine.Scope["IsSevenPrime"]); // true MAGES tries to narrow every .NET data type to one of its data types: * Number (`System.Double`) +* Complex (`System.Numerics.Complex`) * Boolean (`System.Boolean`) * String (`System.String`) * Matrix (`System.Double[,]`) +* CMatrix (`System.Numerics.Complex[,]`) * Object (`System.Collections.Generic.IDictionary`) * Function (`Mages.Core.Function`, essentially a `Delegate` mapping `Object[]` to `Object`) * Undefined (`null`) @@ -221,4 +223,4 @@ engine.SetStatic(typeof(MyMath)).Scattered(); var result = engine.Interpret("arccot(cot(1))"); // 1 ``` -Using `Scattered` the object is decomposed and inserted into the global API layer. \ No newline at end of file +Using `Scattered` the object is decomposed and inserted into the global API layer. diff --git a/doc/introduction.md b/doc/introduction.md index d3c28efa..6e57db6e 100644 --- a/doc/introduction.md +++ b/doc/introduction.md @@ -141,4 +141,4 @@ Help on the available functions can be retrieved via the `help()` function. MAGES is certainly not the only tool available to cover our scripting needs, but depending on our requirements it may be the ideal choice. MAGES is simple, lightweight, focused, and highly performant. It still offers a nice API layer that makes it possible to come up with sophisticated editor support and state-of-the-art tooling. -The other documents provide more insights and specific topics, e.g., the [language and its features](language.md) itself or an overview over the [integrated functions](functions.md). \ No newline at end of file +The other documents provide more insights and specific topics, e.g., the [language and its features](language.md) itself or an overview over the [integrated functions](functions.md). diff --git a/doc/language.md b/doc/language.md index 890e6601..12f8b54d 100644 --- a/doc/language.md +++ b/doc/language.md @@ -175,11 +175,11 @@ Ranges come in two versions. There is an implicit and an explicit range. The for The operator to invoke the range literal is the colon `:`. It can be used with two such colons (explicit: denoting start, step, end) or just one (implicit: separating start and end). Start and end are both given inclusive. ```C -1:1:5 // Creates a 1x5 matrix [1,2,3,4,5] -1:2:5 // Creates a 1x3 matrix [1,3,5] -1:-1:-1 // Creates a 1x3 matrix [1,0,-1] -1:4 // Creates a 1x4 matrix [1,2,3,4] -1:-1 // Creates a 1x3 matrix [1,0,-1] +1..1..5 // Creates a 1x5 matrix [1,2,3,4,5] +1..2..5 // Creates a 1x3 matrix [1,3,5] +1..-1..-1 // Creates a 1x3 matrix [1,0,-1] +1..4 // Creates a 1x4 matrix [1,2,3,4] +1..-1 // Creates a 1x3 matrix [1,0,-1] ``` By default this creates a row vector, however, one can always transpose the result, e.g., `(1:3)'`. diff --git a/doc/syntax.md b/doc/syntax.md index 229f6326..e272196b 100644 --- a/doc/syntax.md +++ b/doc/syntax.md @@ -131,10 +131,12 @@ call ::= expr space* arguments Besides a couple of unary and binary operators, two tertiary operators are also included. We have: ``` -range ::= expr space* ':' (space* expr space* ':')? space* expr +range ::= expr space* '..' (space* expr space* '..')? space* expr condition ::= expr space* '?' space* expr space* ':' space* expr ``` +Conditions take precedence over ranges. + ## Operators A special kind of binary operator is the member operator, which is used in conjunction with objects: diff --git a/src/Mages.Core.Tests/AuxiliariesTests.cs b/src/Mages.Core.Tests/AuxiliariesTests.cs index 5b009af3..3ea37153 100644 --- a/src/Mages.Core.Tests/AuxiliariesTests.cs +++ b/src/Mages.Core.Tests/AuxiliariesTests.cs @@ -323,7 +323,7 @@ public void ExceptBetweenTwoObjectsWithDifferentValue() [Test] public void KeysOfMatrixYieldNumbers() { - var result = "keys(1:5)".Eval(); + var result = "keys(1..5)".Eval(); var array = result as IDictionary; Assert.IsNotNull(array); Assert.AreEqual(5, array.Count); @@ -370,7 +370,7 @@ public void AllOfObjectWithSomeFalseIsFalse() [Test] public void AllOfMatrixWithNoZerosIsTrue() { - var result = "all(1:10)".Eval(); + var result = "all(1..10)".Eval(); Assert.AreEqual(true, result); } } diff --git a/src/Mages.Core.Tests/ComposedExpressionTests.cs b/src/Mages.Core.Tests/ComposedExpressionTests.cs index 27cf78f7..1ac1d578 100644 --- a/src/Mages.Core.Tests/ComposedExpressionTests.cs +++ b/src/Mages.Core.Tests/ComposedExpressionTests.cs @@ -161,20 +161,16 @@ public void FunctionCallWithThreeArguments() } [Test] - public void ConditionWithRangeShouldYieldRange() + public void ConditionWithRangeShouldYieldCondition() { - var result = "c ? a : 2:3:1".ToExpression(); + var result = "c ? a : 2..3..1".ToExpression(); - Assert.IsInstanceOf(result); - - var range = (RangeExpression)result; - var condition = (ConditionalExpression)range.From; + Assert.IsInstanceOf(result); + var condition = (ConditionalExpression)result; Assert.IsInstanceOf(condition.Condition); Assert.IsInstanceOf(condition.Primary); - Assert.IsInstanceOf(condition.Secondary); - Assert.IsInstanceOf(range.Step); - Assert.IsInstanceOf(range.To); + Assert.IsInstanceOf(condition.Secondary); } [Test] diff --git a/src/Mages.Core.Tests/FunctionTests.cs b/src/Mages.Core.Tests/FunctionTests.cs index 93274481..10c62b27 100644 --- a/src/Mages.Core.Tests/FunctionTests.cs +++ b/src/Mages.Core.Tests/FunctionTests.cs @@ -152,6 +152,13 @@ public void CallObjectWithValidNameYieldsValue() Assert.AreEqual(29.0, result); } + [Test] + public void CallWithConditionAndRangeYieldsValue() + { + var result = "false ? 2..3 : 3..4".Eval(); + Assert.IsNotNull(result); + } + [Test] public void CallObjectWithUnknownNameYieldsNothing() { diff --git a/src/Mages.Core.Tests/OperationTests.cs b/src/Mages.Core.Tests/OperationTests.cs index ba29476a..b3f91ad2 100644 --- a/src/Mages.Core.Tests/OperationTests.cs +++ b/src/Mages.Core.Tests/OperationTests.cs @@ -485,7 +485,7 @@ public void AllWithOneAndZeroMatrixIsFalse() [Test] public void RangeWithValidToAndFromAutoStep() { - var result = "1:3".Eval() as Double[,]; + var result = "1..3".Eval() as Double[,]; Assert.IsNotNull(result); Assert.AreEqual(3, result.Length); Assert.AreEqual(1.0, result[0, 0]); @@ -496,7 +496,7 @@ public void RangeWithValidToAndFromAutoStep() [Test] public void RangeWithInvalidToAndValidFromAutoStep() { - var result = "1:\"3k\"".Eval() as Double[,]; + var result = "1..\"3k\"".Eval() as Double[,]; Assert.IsNotNull(result); Assert.AreEqual(0, result.Length); } @@ -504,7 +504,7 @@ public void RangeWithInvalidToAndValidFromAutoStep() [Test] public void RangeWithValidToAndInvalidFromAutoStep() { - var result = "\"3k\":1".Eval() as Double[,]; + var result = "\"3k\"..1".Eval() as Double[,]; Assert.IsNotNull(result); Assert.AreEqual(0, result.Length); } @@ -512,7 +512,7 @@ public void RangeWithValidToAndInvalidFromAutoStep() [Test] public void RangeWithValidToAndFromAndStep() { - var result = "1:2:3".Eval() as Double[,]; + var result = "1..2..3".Eval() as Double[,]; Assert.IsNotNull(result); Assert.AreEqual(2, result.Length); Assert.AreEqual(1.0, result[0, 0]); @@ -522,7 +522,7 @@ public void RangeWithValidToAndFromAndStep() [Test] public void RangeWithValidToAndInvalidFromAndValidStep() { - var result = "\"foo\":2:3".Eval() as Double[,]; + var result = "\"foo\"..2..3".Eval() as Double[,]; Assert.IsNotNull(result); Assert.AreEqual(0, result.Length); } @@ -530,7 +530,7 @@ public void RangeWithValidToAndInvalidFromAndValidStep() [Test] public void RangeWithValidToAndFromAndInvalidStep() { - var result = "1:\"foo\":3".Eval() as Double[,]; + var result = "1..\"foo\"..3".Eval() as Double[,]; Assert.IsNotNull(result); Assert.AreEqual(0, result.Length); } @@ -538,7 +538,7 @@ public void RangeWithValidToAndFromAndInvalidStep() [Test] public void RangeWithInvalidToAndValidFromAndValidStep() { - var result = "1:2:\"foo\"".Eval() as Double[,]; + var result = "1..2..\"foo\"".Eval() as Double[,]; Assert.IsNotNull(result); Assert.AreEqual(0, result.Length); } diff --git a/src/Mages.Core.Tests/YampTests.cs b/src/Mages.Core.Tests/YampTests.cs index 74b8dca8..72e73093 100644 --- a/src/Mages.Core.Tests/YampTests.cs +++ b/src/Mages.Core.Tests/YampTests.cs @@ -317,7 +317,7 @@ public void MultiplyVectors() [Test] public void RangeWithExplicitDelta() { - Test("abs(1:1:3)", Math.Sqrt(1 + 4 + 9)); + Test("abs(1..1..3)", Math.Sqrt(1 + 4 + 9)); } [Test] @@ -359,7 +359,7 @@ public void SineOfMatrix() [Test] public void LengthOfRange() { - Test("length(-pi/4:0.1:pi/4)", 16.0); + Test("length(-pi/4..0.1..pi/4)", 16.0); } [Test] diff --git a/src/Mages.Core/Ast/ExpressionParser.cs b/src/Mages.Core/Ast/ExpressionParser.cs index 4835efb8..e7b75951 100644 --- a/src/Mages.Core/Ast/ExpressionParser.cs +++ b/src/Mages.Core/Ast/ExpressionParser.cs @@ -424,7 +424,7 @@ private IExpression ParseAssignment(IEnumerator tokens) if (token.Type != TokenType.Comma) { - var x = ParseRange(tokens); + var x = ParseConditional(tokens); var mode = tokens.Current.Type; if (mode == TokenType.Assignment) @@ -444,14 +444,14 @@ private IExpression ParseAssignment(IEnumerator tokens) return new InvalidExpression(ErrorCode.ExpressionExpected, token); } - private IExpression ParseRange(IEnumerator tokens) + private IExpression ParseConditional(IEnumerator tokens) { - var x = ParseConditional(tokens); + var x = ParseRange(tokens); - if (tokens.Current.Type == TokenType.Colon) + if (tokens.Current.Type == TokenType.Condition) { - var z = ParseConditional(tokens.NextNonIgnorable()); - var y = z; + var y = ParseConditional(tokens.NextNonIgnorable()); + var z = default(IExpression); if (tokens.Current.Type == TokenType.Colon) { @@ -459,34 +459,34 @@ private IExpression ParseRange(IEnumerator tokens) } else { - y = new EmptyExpression(z.Start); + z = ParseInvalid(ErrorCode.BranchMissing, tokens); } - return new RangeExpression(x, y, z); + return new ConditionalExpression(x, y, z); } return x; } - private IExpression ParseConditional(IEnumerator tokens) + private IExpression ParseRange(IEnumerator tokens) { var x = ParsePipe(tokens); - if (tokens.Current.Type == TokenType.Condition) + if (tokens.Current.Type == TokenType.DotDot) { - var y = ParseConditional(tokens.NextNonIgnorable()); - var z = default(IExpression); + var z = ParsePipe(tokens.NextNonIgnorable()); + var y = z; - if (tokens.Current.Type == TokenType.Colon) + if (tokens.Current.Type == TokenType.DotDot) { - z = ParseConditional(tokens.NextNonIgnorable()); + z = ParsePipe(tokens.NextNonIgnorable()); } else { - z = ParseInvalid(ErrorCode.BranchMissing, tokens); + y = new EmptyExpression(z.Start); } - return new ConditionalExpression(x, y, z); + return new RangeExpression(x, y, z); } return x; diff --git a/src/Mages.Core/Source/StringScanner.cs b/src/Mages.Core/Source/StringScanner.cs index e5b44098..a4bca3aa 100644 --- a/src/Mages.Core/Source/StringScanner.cs +++ b/src/Mages.Core/Source/StringScanner.cs @@ -10,9 +10,12 @@ sealed class StringScanner : BaseScanner, IScanner private readonly StringReader _source; private Int32 _current; - private Int32 _previous; + private Int32 _p0; + private Int32 _p1; + private Int32 _p2; + private Int32 _p3; private Boolean _skip; - private Boolean _swap; + private Int32 _pIndex; #endregion @@ -21,7 +24,11 @@ sealed class StringScanner : BaseScanner, IScanner public StringScanner(String source) { _source = new StringReader(source); - _previous = CharacterTable.NullPtr; + _pIndex = 0; + _p0 = CharacterTable.NullPtr; + _p1 = CharacterTable.NullPtr; + _p2 = CharacterTable.NullPtr; + _p3 = CharacterTable.NullPtr; _current = CharacterTable.NullPtr; } @@ -29,7 +36,15 @@ public StringScanner(String source) #region Properties - public Int32 Current => _current; + public Int32 Current => _pIndex switch + { + 0 => _current, + 1 => _p0, + 2 => _p1, + 3 => _p2, + 4 => _p3, + _ => CharacterTable.NullPtr, + }; #endregion @@ -63,17 +78,17 @@ protected override void Cleanup() private void Retreat() { - if (!_swap) + if (_pIndex < 4) { - Swap(); + _pIndex++; } } private void Advance() { - if (_swap) + if (_pIndex > 0) { - Swap(); + _pIndex--; } else if (_current != CharacterTable.End) { @@ -86,7 +101,10 @@ private void Advance() NextColumn(); } - _previous = _current; + _p3 = _p2; + _p2 = _p1; + _p1 = _p0; + _p0 = _current; _current = Read(); } } @@ -113,14 +131,6 @@ private Int32 Read() return current; } - private void Swap() - { - var tmp = _current; - _current = _previous; - _previous = tmp; - _swap = !_swap; - } - #endregion } } diff --git a/src/Mages.Core/TextPosition.cs b/src/Mages.Core/TextPosition.cs index 037f421d..89effb83 100644 --- a/src/Mages.Core/TextPosition.cs +++ b/src/Mages.Core/TextPosition.cs @@ -131,5 +131,15 @@ public Boolean Equals(TextPosition other) } #endregion + + #region ToString + + /// + public override String ToString() + { + return $"{_index}:{_row},{_column}"; + } + + #endregion } } diff --git a/src/Mages.Core/Tokens/CharacterToken.cs b/src/Mages.Core/Tokens/CharacterToken.cs index 751dfd31..10fa3583 100644 --- a/src/Mages.Core/Tokens/CharacterToken.cs +++ b/src/Mages.Core/Tokens/CharacterToken.cs @@ -22,5 +22,10 @@ public CharacterToken(TokenType type, Int32 character, TextPosition position) public TextPosition Start => _position; public TextPosition End => _position; + + public override String ToString() + { + return $"Character / {_position} / '{Char.ConvertFromUtf32(_character)}'#{_character}"; + } } } diff --git a/src/Mages.Core/Tokens/CommentToken.cs b/src/Mages.Core/Tokens/CommentToken.cs index 76eb0fb7..82426513 100644 --- a/src/Mages.Core/Tokens/CommentToken.cs +++ b/src/Mages.Core/Tokens/CommentToken.cs @@ -22,5 +22,10 @@ public CommentToken(String comment, TextPosition start, TextPosition end) public TextPosition Start => _start; public TextPosition End => _end; + + public override String ToString() + { + return $"Comment / {_start} -- {_end} / '{_comment}'"; + } } } diff --git a/src/Mages.Core/Tokens/EndToken.cs b/src/Mages.Core/Tokens/EndToken.cs index d906350b..9ab9d468 100644 --- a/src/Mages.Core/Tokens/EndToken.cs +++ b/src/Mages.Core/Tokens/EndToken.cs @@ -18,5 +18,10 @@ public EndToken(TextPosition position) public TextPosition Start => _position; public TextPosition End => _position; + + public override String ToString() + { + return $"EOF / {_position}"; + } } } diff --git a/src/Mages.Core/Tokens/IdentToken.cs b/src/Mages.Core/Tokens/IdentToken.cs index 926ad2f5..82964340 100644 --- a/src/Mages.Core/Tokens/IdentToken.cs +++ b/src/Mages.Core/Tokens/IdentToken.cs @@ -24,5 +24,10 @@ public IdentToken(TokenType type, String identifier, TextPosition start, TextPos public TextPosition Start => _start; public TextPosition End => _end; + + public override String ToString() + { + return $"Identifier / {_start} -- {_end} / '{_identifier}'"; + } } } diff --git a/src/Mages.Core/Tokens/InterpolatedToken.cs b/src/Mages.Core/Tokens/InterpolatedToken.cs index 807d11ac..72db3d62 100644 --- a/src/Mages.Core/Tokens/InterpolatedToken.cs +++ b/src/Mages.Core/Tokens/InterpolatedToken.cs @@ -39,5 +39,10 @@ public IEnumerable this[Int32 index] public TextPosition Start => _start; public TextPosition End => _end; + + public override String ToString() + { + return $"InterpolatedString / {_start} -- {_end} / '{_content}'"; + } } } diff --git a/src/Mages.Core/Tokens/NumberToken.cs b/src/Mages.Core/Tokens/NumberToken.cs index 1ee72254..bcaacd1e 100644 --- a/src/Mages.Core/Tokens/NumberToken.cs +++ b/src/Mages.Core/Tokens/NumberToken.cs @@ -33,5 +33,10 @@ public NumberToken(Double value, IEnumerable errors, TextPosition st public TextPosition Start => _start; public TextPosition End => _end; + + public override String ToString() + { + return $"Number / {_start} -- {_end} / '{_value}'"; + } } } diff --git a/src/Mages.Core/Tokens/NumberTokenizer.cs b/src/Mages.Core/Tokens/NumberTokenizer.cs index 5192357c..b41baa2e 100644 --- a/src/Mages.Core/Tokens/NumberTokenizer.cs +++ b/src/Mages.Core/Tokens/NumberTokenizer.cs @@ -95,6 +95,10 @@ public IToken Dot() { return Decimal(); } + else if (_scanner.Current == CharacterTable.FullStop) + { + return new OperatorToken(TokenType.DotDot, "..", _start); + } _scanner.MoveBack(); } @@ -116,6 +120,12 @@ public IToken Digit() if (_scanner.Current == CharacterTable.FullStop && _scanner.MoveNext()) { + if (_scanner.Current == CharacterTable.FullStop) + { + _scanner.MoveBack(); + return Final(); + } + return Decimal(); } else if (_scanner.Current == CharacterTable.SmallE || _scanner.Current == CharacterTable.BigE) @@ -181,7 +191,8 @@ private IToken Decimal() { if (IsDotOperator(_scanner.Current)) { - _scanner.MoveBack(); + //TODO: Right now disabled as we don't consume / handle dot operators in the general tokenizer + //_scanner.MoveBack(); return Final(); } diff --git a/src/Mages.Core/Tokens/OperatorToken.cs b/src/Mages.Core/Tokens/OperatorToken.cs index 285fcb21..fd021891 100644 --- a/src/Mages.Core/Tokens/OperatorToken.cs +++ b/src/Mages.Core/Tokens/OperatorToken.cs @@ -29,5 +29,10 @@ public OperatorToken(TokenType type, String payload, TextPosition start, TextPos public TextPosition Start => _start; public TextPosition End => _end; + + public override String ToString() + { + return $"Operator / {_start} -- {_end} / '{_payload}'"; + } } } diff --git a/src/Mages.Core/Tokens/StringToken.cs b/src/Mages.Core/Tokens/StringToken.cs index 460064a9..ab8a85aa 100644 --- a/src/Mages.Core/Tokens/StringToken.cs +++ b/src/Mages.Core/Tokens/StringToken.cs @@ -30,5 +30,10 @@ public StringToken(String content, IEnumerable errors, TextPosition public TextPosition Start => _start; public TextPosition End => _end; + + public override String ToString() + { + return $"String / {_start} -- {_end} / '{_content}'"; + } } } diff --git a/src/Mages.Core/Tokens/TokenType.cs b/src/Mages.Core/Tokens/TokenType.cs index 300fb6bf..044bd386 100644 --- a/src/Mages.Core/Tokens/TokenType.cs +++ b/src/Mages.Core/Tokens/TokenType.cs @@ -166,6 +166,10 @@ public enum TokenType /// Pipe = 39, /// + /// The dot dot operator (range). + /// + DotDot = 40, + /// /// Semicolon symbol. /// SemiColon = 0x40, diff --git a/src/Mages.Repl.Base/Functions/Helpers.cs b/src/Mages.Repl.Base/Functions/Helpers.cs index 11f56d87..6b82ce6a 100644 --- a/src/Mages.Repl.Base/Functions/Helpers.cs +++ b/src/Mages.Repl.Base/Functions/Helpers.cs @@ -49,5 +49,18 @@ public static String ShowAst(Engine engine, String source) statements.ToBlock().Accept(walker); return sb.ToString(0, sb.Length - Environment.NewLine.Length); } + + public static String ShowTokens(Engine engine, String source) + { + var tokens = source.ToTokenStream(); + var list = new List(); + + while (tokens.MoveNext()) + { + list.Add($"{tokens.Current}"); + } + + return String.Join(Environment.NewLine, list); + } } } diff --git a/src/Mages.Repl.Base/Functions/ReplFunctions.cs b/src/Mages.Repl.Base/Functions/ReplFunctions.cs index 1c600f54..5406928a 100644 --- a/src/Mages.Repl.Base/Functions/ReplFunctions.cs +++ b/src/Mages.Repl.Base/Functions/ReplFunctions.cs @@ -36,6 +36,12 @@ public static void Integrate(Engine engine, IInteractivity interactivity) return Curry.MinOne(id, args) ?? If.Is(args, source => Helpers.ShowAst(engine, source)); })); + engine.SetFunction("tokens", new Function(args => + { + var id = engine.Globals["tokens"] as Function; + return Curry.MinOne(id, args) ?? + If.Is(args, source => Helpers.ShowTokens(engine, source)); + })); engine.SetConstant("process", new ProcessObject()); engine.SetConstant("measure", new Function(args => { From 9095cc788d7697c37e446e213aae4e04a8f01853 Mon Sep 17 00:00:00 2001 From: Florian Rappl Date: Fri, 21 May 2021 02:56:54 +0200 Subject: [PATCH 20/27] Changed types to be reflected as objects --- CHANGELOG.md | 1 + src/Mages.Core.Tests/FunctionTests.cs | 14 ++--- src/Mages.Core.Tests/OperationTests.cs | 33 ++++++++--- .../Runtime/Converters/ConverterExtensions.cs | 21 +++---- .../Runtime/Converters/TypeCategories.cs | 3 + .../Runtime/Functions/StandardFunctions.cs | 2 +- src/Mages.Core/Runtime/Helpers.cs | 6 +- src/Mages.Core/Runtime/Matrix.cs | 15 +---- src/Mages.Core/Runtime/Types/MagesBoolean.cs | 22 +++++++ src/Mages.Core/Runtime/Types/MagesCMatrix.cs | 22 +++++++ src/Mages.Core/Runtime/Types/MagesComplex.cs | 22 +++++++ src/Mages.Core/Runtime/Types/MagesFunction.cs | 21 +++++++ src/Mages.Core/Runtime/Types/MagesMatrix.cs | 22 +++++++ src/Mages.Core/Runtime/Types/MagesNumber.cs | 22 +++++++ src/Mages.Core/Runtime/Types/MagesObject.cs | 22 +++++++ src/Mages.Core/Runtime/Types/MagesString.cs | 21 +++++++ .../Runtime/Types/MagesUndefined.cs | 20 +++++++ src/Mages.Core/Runtime/WrapperObject.cs | 57 +++++-------------- .../Functions/HelpFunctions.cs | 29 +++++++--- 19 files changed, 280 insertions(+), 95 deletions(-) create mode 100644 src/Mages.Core/Runtime/Types/MagesBoolean.cs create mode 100644 src/Mages.Core/Runtime/Types/MagesCMatrix.cs create mode 100644 src/Mages.Core/Runtime/Types/MagesComplex.cs create mode 100644 src/Mages.Core/Runtime/Types/MagesFunction.cs create mode 100644 src/Mages.Core/Runtime/Types/MagesMatrix.cs create mode 100644 src/Mages.Core/Runtime/Types/MagesNumber.cs create mode 100644 src/Mages.Core/Runtime/Types/MagesObject.cs create mode 100644 src/Mages.Core/Runtime/Types/MagesString.cs create mode 100644 src/Mages.Core/Runtime/Types/MagesUndefined.cs diff --git a/CHANGELOG.md b/CHANGELOG.md index 2e553fff..de0b537e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ - Changed the range operator from `:` to `..` (#76) - Changed library target to .NET Standard 2 (#68) - Changed application to run on .NET Core 3.1 (#68) +- Changed types to be reflected as objects (#60) # 1.6.1 diff --git a/src/Mages.Core.Tests/FunctionTests.cs b/src/Mages.Core.Tests/FunctionTests.cs index 10c62b27..fe3a3258 100644 --- a/src/Mages.Core.Tests/FunctionTests.cs +++ b/src/Mages.Core.Tests/FunctionTests.cs @@ -326,49 +326,49 @@ public void ListWithOneEntryAddNewEntryWithIndexSetAccessor() [Test] public void TypeOfNothingIsUndefined() { - var result = "type(null)".Eval(); + var result = "type(null).name".Eval(); Assert.AreEqual("Undefined", result); } [Test] public void TypeOfMatrixIsMatrix() { - var result = "type([])".Eval(); + var result = "type([]).name".Eval(); Assert.AreEqual("Matrix", result); } [Test] public void TypeOfDictionaryIsObject() { - var result = "type(new {})".Eval(); + var result = "type(new {}).name".Eval(); Assert.AreEqual("Object", result); } [Test] public void TypeOfStringIsString() { - var result = "type(\"\")".Eval(); + var result = "type(\"\").name".Eval(); Assert.AreEqual("String", result); } [Test] public void TypeOfBooleanIsBoolean() { - var result = "type(true)".Eval(); + var result = "type(true).name".Eval(); Assert.AreEqual("Boolean", result); } [Test] public void TypeOfDoubleIsNumber() { - var result = "type(2.3)".Eval(); + var result = "type(2.3).name".Eval(); Assert.AreEqual("Number", result); } [Test] public void TypeOfDelegateIsFunction() { - var result = "type(() => {})".Eval(); + var result = "type(() => {}).name".Eval(); Assert.AreEqual("Function", result); } diff --git a/src/Mages.Core.Tests/OperationTests.cs b/src/Mages.Core.Tests/OperationTests.cs index b3f91ad2..3f543bd0 100644 --- a/src/Mages.Core.Tests/OperationTests.cs +++ b/src/Mages.Core.Tests/OperationTests.cs @@ -795,21 +795,28 @@ public void SomethingAintNothingIsFalse() [Test] public void TypeOperatorOnNullYieldsUndefined() { - var result = "&null".Eval(); + var result = "(&null).name".Eval(); Assert.AreEqual("Undefined", result); } [Test] - public void TypeOperatorOnResultOfTypeOperatorYieldsString() + public void TypeOperatorOnResultOfTypeOperatorYieldsObject() { - var result = "& &null".Eval(); + var result = "(& &null).name".Eval(); + Assert.AreEqual("Object", result); + } + + [Test] + public void TypeOperatorOnResultOfTypeOperatorNameYieldsString() + { + var result = "(& (&null).name).name".Eval(); Assert.AreEqual("String", result); } [Test] public void TypeOperatorOnMatrixYieldsMatrix() { - var result = "&[1, 2, 3]".Eval(); + var result = "(&[1, 2, 3]).name".Eval(); Assert.AreEqual("Matrix", result); } @@ -839,7 +846,7 @@ public void PipeOperatorAfterMinusOnCurriedMultiplyYieldsResult() [Test] public void PipeOperatorIsLowerPrecendenceThanEquals() { - var result = "3 == 4 | type".Eval(); + var result = "(3 == 4 | type).name".Eval(); Assert.IsInstanceOf(result); Assert.AreEqual("Boolean", result); } @@ -847,7 +854,7 @@ public void PipeOperatorIsLowerPrecendenceThanEquals() [Test] public void PipeOperatorIsLowerPrecendenceThanOr() { - var result = "1 || 0 | type".Eval(); + var result = "(1 || 0 | type).name".Eval(); Assert.IsInstanceOf(result); Assert.AreEqual("Boolean", result); } @@ -855,19 +862,27 @@ public void PipeOperatorIsLowerPrecendenceThanOr() [Test] public void PipeOperatorOnTypeYieldsResult() { - var result = "2 | type".Eval(); + var result = "(2 | type).name".Eval(); Assert.IsInstanceOf(result); Assert.AreEqual("Number", result); } [Test] - public void PipeOperatorOnTypeOfTypeYieldsString() + public void PipeOperatorOnTypeOfTypeNameYieldsString() { - var result = "2 | type | type".Eval(); + var result = "((2 | type).name | type).name".Eval(); Assert.IsInstanceOf(result); Assert.AreEqual("String", result); } + [Test] + public void PipeOperatorOnTypeOfTypeYieldsObject() + { + var result = "(2 | type | type).name".Eval(); + Assert.IsInstanceOf(result); + Assert.AreEqual("Object", result); + } + [Test] public void InvalidAssignmentAddWithNumberYieldsError() { diff --git a/src/Mages.Core/Runtime/Converters/ConverterExtensions.cs b/src/Mages.Core/Runtime/Converters/ConverterExtensions.cs index 1422d7e0..f14f3b52 100644 --- a/src/Mages.Core/Runtime/Converters/ConverterExtensions.cs +++ b/src/Mages.Core/Runtime/Converters/ConverterExtensions.cs @@ -1,5 +1,6 @@ namespace Mages.Core.Runtime.Converters { + using Mages.Core.Runtime.Types; using System; using System.Collections.Generic; using System.Globalization; @@ -16,17 +17,17 @@ public static class ConverterExtensions /// /// The value to get the type of. /// The MAGES type string. - public static String ToType(this Object value) => value switch + public static IDictionary ToType(this Object value) => value switch { - Double _ => "Number", - Complex _ => "Complex", - String _ => "String", - Boolean _ => "Boolean", - Double[,] _ => "Matrix", - Complex[,] _ => "CMatrix", - Function _ => "Function", - IDictionary _ => "Object", - _ => "Undefined", + Double _ => MagesNumber.Type, + Complex _ => MagesComplex.Type, + String _ => MagesString.Type, + Boolean _ => MagesBoolean.Type, + Double[,] _ => MagesMatrix.Type, + Complex[,] _ => MagesCMatrix.Type, + Function _ => MagesFunction.Type, + IDictionary _ => MagesObject.Type, + _ => MagesUndefined.Type, }; /// diff --git a/src/Mages.Core/Runtime/Converters/TypeCategories.cs b/src/Mages.Core/Runtime/Converters/TypeCategories.cs index d31de892..9b4e561d 100644 --- a/src/Mages.Core/Runtime/Converters/TypeCategories.cs +++ b/src/Mages.Core/Runtime/Converters/TypeCategories.cs @@ -2,15 +2,18 @@ { using System; using System.Collections.Generic; + using System.Numerics; static class TypeCategories { public static readonly Dictionary> Mapping = new Dictionary> { { typeof(Double), new List { typeof(Double), typeof(Single), typeof(Decimal), typeof(Byte), typeof(UInt16), typeof(UInt32), typeof(UInt64), typeof(Int16), typeof(Int32), typeof(Int64) } }, + { typeof(Complex), new List { typeof(Complex) } }, { typeof(Boolean), new List { typeof(Boolean) } }, { typeof(String), new List { typeof(String), typeof(Char) } }, { typeof(Double[,]), new List { typeof(Double[,]), typeof(Double[]), typeof(List) } }, + { typeof(Complex[,]), new List { typeof(Complex[,]), typeof(Complex[]), typeof(List) } }, { typeof(Function), new List { typeof(Function), typeof(Delegate) } }, { typeof(IDictionary), new List { typeof(IDictionary), typeof(Object) } } }; diff --git a/src/Mages.Core/Runtime/Functions/StandardFunctions.cs b/src/Mages.Core/Runtime/Functions/StandardFunctions.cs index 598270ba..0019d0fa 100644 --- a/src/Mages.Core/Runtime/Functions/StandardFunctions.cs +++ b/src/Mages.Core/Runtime/Functions/StandardFunctions.cs @@ -866,7 +866,7 @@ public static class StandardFunctions public static readonly Function Is = new Function(args => { return Curry.MinTwo(Is, args) ?? - If.Is(args, type => type == args[1].ToType()) ?? + If.Is(args, type => type == args[1].ToType()["name"].ToString()) ?? If.Is>(args, type => type.Satisfies(args[1])); }); diff --git a/src/Mages.Core/Runtime/Helpers.cs b/src/Mages.Core/Runtime/Helpers.cs index 626e154b..a574568e 100644 --- a/src/Mages.Core/Runtime/Helpers.cs +++ b/src/Mages.Core/Runtime/Helpers.cs @@ -124,14 +124,12 @@ public static Boolean Satisfies(this IDictionary constraints, Ob { foreach (var constraint in constraints) { - var val = default(Object); - - if (obj.TryGetValue(constraint.Key, out val)) + if (obj.TryGetValue(constraint.Key, out var val)) { var simple = constraint.Value as String; var extended = constraint.Value as IDictionary; - if ((simple == null || val.ToType() == simple) && + if ((simple == null || val.ToType()["name"].ToString() == simple) && (extended == null || extended.Satisfies(val))) { continue; diff --git a/src/Mages.Core/Runtime/Matrix.cs b/src/Mages.Core/Runtime/Matrix.cs index 1d49997c..0a55b69c 100644 --- a/src/Mages.Core/Runtime/Matrix.cs +++ b/src/Mages.Core/Runtime/Matrix.cs @@ -7,20 +7,11 @@ static class Matrix { - public static Int32 GetRows(this T[,] matrix) - { - return matrix.GetLength(0); - } + public static Int32 GetRows(this T[,] matrix) => matrix.GetLength(0); - public static Int32 GetColumns(this T[,] matrix) - { - return matrix.GetLength(1); - } + public static Int32 GetColumns(this T[,] matrix) => matrix.GetLength(1); - public static Int32 GetCount(this T[,] matrix) - { - return matrix.GetLength(0) * matrix.GetLength(1); - } + public static Int32 GetCount(this T[,] matrix) => matrix.GetLength(0) * matrix.GetLength(1); public static Object GetKeys(this T[,] matrix) { diff --git a/src/Mages.Core/Runtime/Types/MagesBoolean.cs b/src/Mages.Core/Runtime/Types/MagesBoolean.cs new file mode 100644 index 00000000..39483279 --- /dev/null +++ b/src/Mages.Core/Runtime/Types/MagesBoolean.cs @@ -0,0 +1,22 @@ +namespace Mages.Core.Runtime.Types +{ + using Mages.Core.Runtime.Converters; + using Mages.Core.Runtime.Functions; + using System; + using System.Collections.Generic; + + static class MagesBoolean + { + private static readonly Function Create = new Function(args => + { + return Curry.MinOne(Create, args) ?? + args[0].ToBoolean(); + }); + + public static readonly IDictionary Type = new Dictionary + { + { "name", "Boolean" }, + { "create", Create }, + }; + } +} diff --git a/src/Mages.Core/Runtime/Types/MagesCMatrix.cs b/src/Mages.Core/Runtime/Types/MagesCMatrix.cs new file mode 100644 index 00000000..aec41e0f --- /dev/null +++ b/src/Mages.Core/Runtime/Types/MagesCMatrix.cs @@ -0,0 +1,22 @@ +namespace Mages.Core.Runtime.Types +{ + using Mages.Core.Runtime.Converters; + using Mages.Core.Runtime.Functions; + using System; + using System.Collections.Generic; + + static class MagesCMatrix + { + private static readonly Function Create = new Function(args => + { + return Curry.MinOne(Create, args) ?? + args[0].ToComplex().ToMatrix(); + }); + + public static readonly IDictionary Type = new Dictionary + { + { "name", "CMatrix" }, + { "create", Create }, + }; + } +} diff --git a/src/Mages.Core/Runtime/Types/MagesComplex.cs b/src/Mages.Core/Runtime/Types/MagesComplex.cs new file mode 100644 index 00000000..08e06b69 --- /dev/null +++ b/src/Mages.Core/Runtime/Types/MagesComplex.cs @@ -0,0 +1,22 @@ +namespace Mages.Core.Runtime.Types +{ + using Mages.Core.Runtime.Converters; + using Mages.Core.Runtime.Functions; + using System; + using System.Collections.Generic; + + static class MagesComplex + { + private static readonly Function Create = new Function(args => + { + return Curry.MinOne(Create, args) ?? + args[0].ToComplex(); + }); + + public static readonly IDictionary Type = new Dictionary + { + { "name", "Complex" }, + { "create", Create }, + }; + } +} diff --git a/src/Mages.Core/Runtime/Types/MagesFunction.cs b/src/Mages.Core/Runtime/Types/MagesFunction.cs new file mode 100644 index 00000000..98efa68d --- /dev/null +++ b/src/Mages.Core/Runtime/Types/MagesFunction.cs @@ -0,0 +1,21 @@ +namespace Mages.Core.Runtime.Types +{ + using Mages.Core.Runtime.Functions; + using System; + using System.Collections.Generic; + + static class MagesFunction + { + private static readonly Function Create = new Function(args => + { + return Curry.MinOne(Create, args) ?? + (args[0] as Function); + }); + + public static readonly IDictionary Type = new Dictionary + { + { "name", "Function" }, + { "create", Create }, + }; + } +} diff --git a/src/Mages.Core/Runtime/Types/MagesMatrix.cs b/src/Mages.Core/Runtime/Types/MagesMatrix.cs new file mode 100644 index 00000000..13f4f9ab --- /dev/null +++ b/src/Mages.Core/Runtime/Types/MagesMatrix.cs @@ -0,0 +1,22 @@ +namespace Mages.Core.Runtime.Types +{ + using Mages.Core.Runtime.Converters; + using Mages.Core.Runtime.Functions; + using System; + using System.Collections.Generic; + + static class MagesMatrix + { + private static readonly Function Create = new Function(args => + { + return Curry.MinOne(Create, args) ?? + args[0].ToNumber().ToMatrix(); + }); + + public static readonly IDictionary Type = new Dictionary + { + { "name", "Matrix" }, + { "create", Create }, + }; + } +} diff --git a/src/Mages.Core/Runtime/Types/MagesNumber.cs b/src/Mages.Core/Runtime/Types/MagesNumber.cs new file mode 100644 index 00000000..c367cbf2 --- /dev/null +++ b/src/Mages.Core/Runtime/Types/MagesNumber.cs @@ -0,0 +1,22 @@ +namespace Mages.Core.Runtime.Types +{ + using Mages.Core.Runtime.Converters; + using Mages.Core.Runtime.Functions; + using System; + using System.Collections.Generic; + + static class MagesNumber + { + private static readonly Function Create = new Function(args => + { + return Curry.MinOne(Create, args) ?? + args[0].ToNumber(); + }); + + public static readonly IDictionary Type = new Dictionary + { + { "name", "Number" }, + { "create", Create }, + }; + } +} diff --git a/src/Mages.Core/Runtime/Types/MagesObject.cs b/src/Mages.Core/Runtime/Types/MagesObject.cs new file mode 100644 index 00000000..53d8895d --- /dev/null +++ b/src/Mages.Core/Runtime/Types/MagesObject.cs @@ -0,0 +1,22 @@ +namespace Mages.Core.Runtime.Types +{ + using Mages.Core.Runtime.Converters; + using Mages.Core.Runtime.Functions; + using System; + using System.Collections.Generic; + + static class MagesObject + { + private static readonly Function Create = new Function(args => + { + return Curry.MinOne(Create, args) ?? + args[0].ToObject(); + }); + + public static readonly IDictionary Type = new Dictionary + { + { "name", "Object" }, + { "create", Create }, + }; + } +} diff --git a/src/Mages.Core/Runtime/Types/MagesString.cs b/src/Mages.Core/Runtime/Types/MagesString.cs new file mode 100644 index 00000000..da0b251a --- /dev/null +++ b/src/Mages.Core/Runtime/Types/MagesString.cs @@ -0,0 +1,21 @@ +namespace Mages.Core.Runtime.Types +{ + using Mages.Core.Runtime.Functions; + using System; + using System.Collections.Generic; + + static class MagesString + { + private static readonly Function Create = new Function(args => + { + return Curry.MinOne(Create, args) ?? + Stringify.This(args[0]); + }); + + public static readonly IDictionary Type = new Dictionary + { + { "name", "String" }, + { "create", Create }, + }; + } +} diff --git a/src/Mages.Core/Runtime/Types/MagesUndefined.cs b/src/Mages.Core/Runtime/Types/MagesUndefined.cs new file mode 100644 index 00000000..ab029256 --- /dev/null +++ b/src/Mages.Core/Runtime/Types/MagesUndefined.cs @@ -0,0 +1,20 @@ +namespace Mages.Core.Runtime.Types +{ + using Mages.Core.Runtime.Functions; + using System; + using System.Collections.Generic; + + static class MagesUndefined + { + private static readonly Function Create = new Function(args => + { + return Curry.MinOne(Create, args) ?? null; + }); + + public static readonly IDictionary Type = new Dictionary + { + { "name", "Undefined" }, + { "create", Create }, + }; + } +} diff --git a/src/Mages.Core/Runtime/WrapperObject.cs b/src/Mages.Core/Runtime/WrapperObject.cs index a8f2a236..71563ef4 100644 --- a/src/Mages.Core/Runtime/WrapperObject.cs +++ b/src/Mages.Core/Runtime/WrapperObject.cs @@ -96,8 +96,7 @@ public Object this[String key] { get { - var result = default(Object); - TryGetValue(key, out result); + TryGetValue(key, out var result); return result; } set { TrySetValue(key, value); } @@ -121,28 +120,19 @@ public Object this[String key] /// public ICollection Values => _extends.Values; - void ICollection>.Add(KeyValuePair item) - { - Add(item.Key, item.Value); - } + void ICollection>.Add(KeyValuePair item) => Add(item.Key, item.Value); /// /// Sets the provided value at the provided property. /// /// The name of the property. /// The value to use. - public void Add(String key, Object value) - { - TrySetValue(key, value); - } + public void Add(String key, Object value) => TrySetValue(key, value); /// /// Resets the extension object. /// - public void Clear() - { - _extends.Clear(); - } + public void Clear() => _extends.Clear(); /// /// Checks if the underlying object or the extension @@ -150,10 +140,7 @@ public void Clear() /// /// The item to check for. /// True if the key is used, otherwise false. - public Boolean Contains(KeyValuePair item) - { - return ContainsKey(item.Key); - } + public Boolean Contains(KeyValuePair item) => ContainsKey(item.Key); /// /// Checks if the underlying object or the extension @@ -161,10 +148,7 @@ public Boolean Contains(KeyValuePair item) /// /// The key to check for. /// True if the key is used, otherwise false. - public Boolean ContainsKey(String key) - { - return _proxies.ContainsKey(key) || _extends.ContainsKey(key); - } + public Boolean ContainsKey(String key) => _proxies.ContainsKey(key) || _extends.ContainsKey(key); void ICollection>.CopyTo(KeyValuePair[] array, Int32 arrayIndex) { @@ -174,25 +158,17 @@ void ICollection>.CopyTo(KeyValuePair /// The extension's enumerator. - public IEnumerator> GetEnumerator() - { - return _extends.Concat(_proxies.Select(m => new KeyValuePair(m.Key, m.Value.Value))).GetEnumerator(); - } + public IEnumerator> GetEnumerator() => + _extends.Concat(_proxies.Select(m => new KeyValuePair(m.Key, m.Value.Value))).GetEnumerator(); - Boolean ICollection>.Remove(KeyValuePair item) - { - return Remove(item.Key); - } + Boolean ICollection>.Remove(KeyValuePair item) => Remove(item.Key); /// /// Removes the item from the extension. /// /// The key of the item to be removed. /// True if it could be removed, otherwise false. - public Boolean Remove(String key) - { - return _extends.Remove(key); - } + public Boolean Remove(String key) => _extends.Remove(key); /// /// Tries to get the value from the given key. @@ -202,9 +178,7 @@ public Boolean Remove(String key) /// True if the value could be retrieved, otherwise false. public Boolean TryGetValue(String key, out Object value) { - var proxy = default(BaseProxy); - - if (_proxies.TryGetValue(key, out proxy)) + if (_proxies.TryGetValue(key, out var proxy)) { value = proxy.Value; return true; @@ -219,9 +193,7 @@ public Boolean TryGetValue(String key, out Object value) private void TrySetValue(String key, Object value) { - var proxy = default(BaseProxy); - - if (_proxies.TryGetValue(key, out proxy)) + if (_proxies.TryGetValue(key, out var proxy)) { proxy.Value = value; } @@ -231,10 +203,7 @@ private void TrySetValue(String key, Object value) } } - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); #endregion } diff --git a/src/Mages.Repl.Base/Functions/HelpFunctions.cs b/src/Mages.Repl.Base/Functions/HelpFunctions.cs index 3c80c545..75cf8068 100644 --- a/src/Mages.Repl.Base/Functions/HelpFunctions.cs +++ b/src/Mages.Repl.Base/Functions/HelpFunctions.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.Linq; + using System.Numerics; using System.Text; sealed class HelpFunctions @@ -60,8 +61,9 @@ private String Info(String topic, Object value) { var sb = new StringBuilder(); var type = value.ToType(); + var typeName = $"{type["name"]}"; sb.AppendFormat("Type of '{0}': ", topic); - sb.AppendLine(type); + sb.AppendLine(typeName); sb.Append("Number value: "); sb.Append(Stringify.This(value.ToNumber())); sb.AppendLine(); @@ -71,25 +73,36 @@ private String Info(String topic, Object value) sb.Append("String value: "); sb.Append(Stringify.This(value)); - switch (type) + switch (typeName) { case "Number": - break; + case "Complex": case "String": - break; case "Boolean": + case "Function": + case "Undefined": break; - case "Matrix": + case "CMatrix": + sb.AppendLine(); + sb.Append("Columns: "); + sb.Append(((Complex[,])value).GetLength(1)); + sb.AppendLine(); + sb.Append("Rows: "); + sb.Append(((Complex[,])value).GetLength(0)); break; - case "Function": + case "Matrix": + sb.AppendLine(); + sb.Append("Columns: "); + sb.Append(((Double[,])value).GetLength(1)); + sb.AppendLine(); + sb.Append("Rows: "); + sb.Append(((Double[,])value).GetLength(0)); break; case "Object": sb.AppendLine(); sb.Append("Keys: "); sb.Append(String.Join(", ", ((IDictionary)value).Select(m => m.Key))); break; - case "Undefined": - break; } return sb.ToString(); From 131dde67b79f8ef82a39a3ac3670a836d0c1b032 Mon Sep 17 00:00:00 2001 From: Florian Rappl Date: Mon, 31 May 2021 14:18:53 +0200 Subject: [PATCH 21/27] Consistent overload for matrices --- src/Mages.Core/Ast/ExpressionParser.cs | 3 +- .../Runtime/Functions/ComplexFunctions.cs | 6 +++ src/Mages.Core/Runtime/Helpers.cs | 44 +++++++------------ 3 files changed, 23 insertions(+), 30 deletions(-) diff --git a/src/Mages.Core/Ast/ExpressionParser.cs b/src/Mages.Core/Ast/ExpressionParser.cs index e7b75951..37d2ed34 100644 --- a/src/Mages.Core/Ast/ExpressionParser.cs +++ b/src/Mages.Core/Ast/ExpressionParser.cs @@ -682,9 +682,8 @@ private IExpression ParsePrimary(IEnumerator tokens) { var current = tokens.Current; var mode = current.Type; - var creator = default(Func); - if (ExpressionCreators.PostUnary.TryGetValue(mode, out creator)) + if (ExpressionCreators.PostUnary.TryGetValue(mode, out var creator)) { tokens.NextNonIgnorable(); left = creator.Invoke(left, current.End); diff --git a/src/Mages.Core/Runtime/Functions/ComplexFunctions.cs b/src/Mages.Core/Runtime/Functions/ComplexFunctions.cs index d1abb985..6e9423f1 100644 --- a/src/Mages.Core/Runtime/Functions/ComplexFunctions.cs +++ b/src/Mages.Core/Runtime/Functions/ComplexFunctions.cs @@ -24,6 +24,8 @@ public static class ComplexFunctions Curry.MinOne(Conj, args) ?? If.Is(args, x => new Complex(x, 0)) ?? If.Is(args, x => new Complex(x.Real, -x.Imaginary)) ?? + If.Is(args, x => x.ForEach(m => new Complex(m, 0))) ?? + If.Is(args, x => x.ForEach(m => new Complex(m.Real, -m.Imaginary))) ?? Double.NaN ); @@ -34,6 +36,8 @@ public static class ComplexFunctions Curry.MinOne(Real, args) ?? If.Is(args, x => x) ?? If.Is(args, x => x.Real) ?? + If.Is(args, x => x) ?? + If.Is(args, x => x.ForEach(m => m.Real)) ?? Double.NaN ); @@ -44,6 +48,8 @@ public static class ComplexFunctions Curry.MinOne(Imag, args) ?? If.Is(args, _ => 0.0) ?? If.Is(args, x => x.Imaginary) ?? + If.Is(args, x => x.ForEach(_ => 0.0)) ?? + If.Is(args, x => x.ForEach(m => m.Imaginary)) ?? Double.NaN ); } diff --git a/src/Mages.Core/Runtime/Helpers.cs b/src/Mages.Core/Runtime/Helpers.cs index a574568e..e88419e2 100644 --- a/src/Mages.Core/Runtime/Helpers.cs +++ b/src/Mages.Core/Runtime/Helpers.cs @@ -14,9 +14,7 @@ static class Helpers public static Object Getter(this String str, Object[] arguments) { - var index = 0; - - if (arguments.Length > 0 && arguments[0].TryGetIndex(out index) && index >= 0 && index < str.Length) + if (arguments.Length > 0 && arguments[0].TryGetIndex(out var index) && index >= 0 && index < str.Length) { return new String(str[index], 1); } @@ -51,8 +49,7 @@ public static void SetProperty(this IDictionary obj, String name public static Object GetProperty(this IDictionary obj, String name) { - var value = default(Object); - obj.TryGetValue(name, out value); + obj.TryGetValue(name, out var value); return value; } @@ -78,8 +75,10 @@ public static String Clamp(this String value, Int32 min, Int32 max) { return value.Substring(0, max); } - - return value; + else + { + return value; + } } public static String Clip(this String value, Int32 from, Int32 to) @@ -100,14 +99,13 @@ public static String Clip(this String value, Int32 from, Int32 to) { return value.Substring(from, value.Length - from); } - - return value; + else + { + return value; + } } - public static Double Clamp(this Double value, Double min, Double max) - { - return Math.Max(Math.Min(value, max), min); - } + public static Double Clamp(this Double value, Double min, Double max) => Math.Max(Math.Min(value, max), min); public static Double Lerp(this Double value, Double min, Double max) { @@ -259,13 +257,11 @@ public static void ContinueWith(this Future promise, Future future) { promise.SetCallback((result, error) => { - var nestedPromise = result as Future; - - if (nestedPromise != null) + if (result is Future nestedPromise) { nestedPromise.ContinueWith(future); } - else if (error != null) + else if (error is not null) { future.SetError(error); } @@ -288,10 +284,7 @@ public static IDictionary ToArrayObject(this Object[] arguments) return obj; } - public static WrapperObject Expose(this Type type) - { - return WrapperObject.CreateFor(type); - } + public static WrapperObject Expose(this Type type) => WrapperObject.CreateFor(type); public static String FindName(this IEnumerable names, MemberInfo member) { @@ -320,10 +313,7 @@ public static String Where(this String str, Function f) return new String(result, 0, length); } - public static Function WrapFunction(this Delegate func) - { - return WrapFunction(func.Method, func.Target); - } + public static Function WrapFunction(this Delegate func) => WrapFunction(func.Method, func.Target); public static IDictionary WrapArray(this Array array) { @@ -380,9 +370,7 @@ public static Object WrapObject(this Object value) public static Object Unwrap(this Object value) { - var wrapped = value as WrapperObject; - - if (wrapped != null) + if (value is WrapperObject wrapped) { return wrapped.Content ?? wrapped.Type; } From 748a62bed62f97f9791b49af5290ba86c853f74e Mon Sep 17 00:00:00 2001 From: Florian Rappl Date: Tue, 1 Jun 2021 22:01:37 +0200 Subject: [PATCH 22/27] Added support for double->complex edge case in sqrt #99 --- .../Runtime/Functions/StandardFunctions.cs | 4 ++-- src/Mages.Core/Runtime/Logic.cs | 19 ++++++++++++++++++ src/Mages.Core/Runtime/Mathx.cs | 20 +++++++++++++++++++ 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/src/Mages.Core/Runtime/Functions/StandardFunctions.cs b/src/Mages.Core/Runtime/Functions/StandardFunctions.cs index 0019d0fa..52fda999 100644 --- a/src/Mages.Core/Runtime/Functions/StandardFunctions.cs +++ b/src/Mages.Core/Runtime/Functions/StandardFunctions.cs @@ -224,8 +224,8 @@ public static class StandardFunctions public static readonly Function Sqrt = new Function(args => { return Curry.MinOne(Sqrt, args) ?? - If.Is(args, x => Math.Sqrt(x)) ?? - If.Is(args, x => x.ForEach(Math.Sqrt)) ?? + If.Is(args, x => Mathx.Sqrt(x)) ?? + If.Is(args, x => Mathx.Sqrt(x)) ?? If.Is(args, x => Complex.Sqrt(x)) ?? If.Is(args, x => x.ForEach(Complex.Sqrt)) ?? If.Is>(args, o => o.Map(Sqrt)) ?? diff --git a/src/Mages.Core/Runtime/Logic.cs b/src/Mages.Core/Runtime/Logic.cs index 2b2b0213..c62101fb 100644 --- a/src/Mages.Core/Runtime/Logic.cs +++ b/src/Mages.Core/Runtime/Logic.cs @@ -93,5 +93,24 @@ public static Boolean AllTrue(this Complex[,] matrix) return res; } + + public static Boolean HasAny(this Double[,] matrix, Predicate check) + { + var rows = matrix.GetRows(); + var cols = matrix.GetColumns(); + + for (var i = 0; i < rows; i++) + { + for (var j = 0; j < cols; j++) + { + if (check(matrix[i, j])) + { + return true; + } + } + } + + return false; + } } } diff --git a/src/Mages.Core/Runtime/Mathx.cs b/src/Mages.Core/Runtime/Mathx.cs index 2c5f086c..f36abc81 100644 --- a/src/Mages.Core/Runtime/Mathx.cs +++ b/src/Mages.Core/Runtime/Mathx.cs @@ -63,6 +63,26 @@ static class Mathx public static Double Sign(Double value) => (Double)Math.Sign(value); + public static Object Sqrt(Double x) + { + if (x >= 0) + { + return Math.Sqrt(x); + } + + return Complex.Sqrt(x); + } + + public static Object Sqrt(Double[,] x) + { + if (x.HasAny(x => x < 0.0)) + { + return x.ForEach(m => Complex.Sqrt(m)); + } + + return x.ForEach(Math.Sqrt); + } + public static Complex Sign(Complex value) { var arg = Math.Atan2(value.Imaginary, value.Real); From dde53cfebe3be9a0a3c246d1297e326b3e97e6ae Mon Sep 17 00:00:00 2001 From: Florian Rappl Date: Tue, 1 Jun 2021 23:27:02 +0200 Subject: [PATCH 23/27] Extended logs to support negative edge cases #100 --- .../Runtime/Functions/StandardFunctions.cs | 10 ++-- src/Mages.Core/Runtime/Mathx.cs | 60 ++++++++++++++++++- 2 files changed, 64 insertions(+), 6 deletions(-) diff --git a/src/Mages.Core/Runtime/Functions/StandardFunctions.cs b/src/Mages.Core/Runtime/Functions/StandardFunctions.cs index 52fda999..50fa98aa 100644 --- a/src/Mages.Core/Runtime/Functions/StandardFunctions.cs +++ b/src/Mages.Core/Runtime/Functions/StandardFunctions.cs @@ -322,8 +322,8 @@ public static class StandardFunctions public static readonly Function Log = new Function(args => { return Curry.MinOne(Log, args) ?? - If.Is(args, x => Math.Log(x)) ?? - If.Is(args, x => x.ForEach(Math.Log)) ?? + If.Is(args, x => Mathx.Log(x)) ?? + If.Is(args, x => Mathx.Log(x)) ?? If.Is(args, x => Complex.Log(x)) ?? If.Is(args, x => x.ForEach(Complex.Log)) ?? If.Is>(args, o => o.Map(Log)) ?? @@ -337,7 +337,7 @@ public static class StandardFunctions { return Curry.MinOne(Log2, args) ?? If.Is(args, x => Mathx.Log2(x)) ?? - If.Is(args, x => x.ForEach(Mathx.Log2)) ?? + If.Is(args, x => Mathx.Log2(x)) ?? If.Is(args, x => Mathx.Log2(x)) ?? If.Is(args, x => x.ForEach(Mathx.Log2)) ?? If.Is>(args, o => o.Map(Log2)) ?? @@ -350,8 +350,8 @@ public static class StandardFunctions public static readonly Function Log10 = new Function(args => { return Curry.MinOne(Log10, args) ?? - If.Is(args, x => Math.Log10(x)) ?? - If.Is(args, x => x.ForEach(Math.Log10)) ?? + If.Is(args, x => Mathx.Log10(x)) ?? + If.Is(args, x => Mathx.Log10(x)) ?? If.Is(args, x => Complex.Log10(x)) ?? If.Is(args, x => x.ForEach(Complex.Log10)) ?? If.Is>(args, o => o.Map(Log10)) ?? diff --git a/src/Mages.Core/Runtime/Mathx.cs b/src/Mages.Core/Runtime/Mathx.cs index f36abc81..1cba41f0 100644 --- a/src/Mages.Core/Runtime/Mathx.cs +++ b/src/Mages.Core/Runtime/Mathx.cs @@ -205,8 +205,66 @@ public static Complex Asech(Complex value) public static Complex Acsch(Complex value) => Complex.Log(1.0 / value + Complex.Sqrt(1.0 / (value * value) + 1.0)); - public static Double Log2(Double value) => Math.Log(value, 2.0); + public static Object Log(Double value) + { + if (value >= 0.0) + { + return Math.Log(value); + } + + return Complex.Log(value); + } + + public static Object Log(Double[,] value) + { + if (value.HasAny(m => m < 0.0)) + { + return value.ForEach(m => Complex.Log(m)); + } + + return value.ForEach(Math.Log); + } + + public static Object Log2(Double value) + { + if (value >= 0.0) + { + return Math.Log(value, 2.0); + } + + return Complex.Log(value, 2.0); + } + + public static Object Log2(Double[,] value) + { + if (value.HasAny(m => m < 0.0)) + { + return value.ForEach(m => Complex.Log(m, 2.0)); + } + + return value.ForEach(m => Math.Log(m, 2.0)); + } public static Complex Log2(Complex value) => Complex.Log(value, 2.0); + + public static Object Log10(Double value) + { + if (value >= 0.0) + { + return Math.Log10(value); + } + + return Complex.Log10(value); + } + + public static Object Log10(Double[,] value) + { + if (value.HasAny(m => m < 0.0)) + { + return value.ForEach(m => Complex.Log10(m)); + } + + return value.ForEach(Math.Log10); + } } } From 9c0a41840f0717daa716a0a4090ef16619ad1b2a Mon Sep 17 00:00:00 2001 From: Florian Rappl Date: Tue, 1 Jun 2021 23:41:58 +0200 Subject: [PATCH 24/27] Fixed fallback scenarios --- src/Mages.Core/Runtime/Functions/StandardFunctions.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Mages.Core/Runtime/Functions/StandardFunctions.cs b/src/Mages.Core/Runtime/Functions/StandardFunctions.cs index 50fa98aa..121c1de7 100644 --- a/src/Mages.Core/Runtime/Functions/StandardFunctions.cs +++ b/src/Mages.Core/Runtime/Functions/StandardFunctions.cs @@ -229,7 +229,7 @@ public static class StandardFunctions If.Is(args, x => Complex.Sqrt(x)) ?? If.Is(args, x => x.ForEach(Complex.Sqrt)) ?? If.Is>(args, o => o.Map(Sqrt)) ?? - Math.Sqrt(args[0].ToNumber()); + Mathx.Sqrt(args[0].ToNumber()); }); /// @@ -327,7 +327,7 @@ public static class StandardFunctions If.Is(args, x => Complex.Log(x)) ?? If.Is(args, x => x.ForEach(Complex.Log)) ?? If.Is>(args, o => o.Map(Log)) ?? - Math.Log(args[0].ToNumber()); + Mathx.Log(args[0].ToNumber()); }); /// @@ -341,7 +341,7 @@ public static class StandardFunctions If.Is(args, x => Mathx.Log2(x)) ?? If.Is(args, x => x.ForEach(Mathx.Log2)) ?? If.Is>(args, o => o.Map(Log2)) ?? - Math.Log(args[0].ToNumber()); + Mathx.Log2(args[0].ToNumber()); }); /// @@ -355,7 +355,7 @@ public static class StandardFunctions If.Is(args, x => Complex.Log10(x)) ?? If.Is(args, x => x.ForEach(Complex.Log10)) ?? If.Is>(args, o => o.Map(Log10)) ?? - Math.Log(args[0].ToNumber()); + Mathx.Log10(args[0].ToNumber()); }); /// From a2870c82b1d175ddf7312db8fd3eb0f536aee759 Mon Sep 17 00:00:00 2001 From: Florian Rappl Date: Wed, 2 Jun 2021 01:24:27 +0200 Subject: [PATCH 25/27] Implemented complex cont. #102 --- .../Runtime/Functions/StandardFunctions.cs | 22 +-- src/Mages.Core/Runtime/Mathx.cs | 168 +++++++++++++++++- 2 files changed, 174 insertions(+), 16 deletions(-) diff --git a/src/Mages.Core/Runtime/Functions/StandardFunctions.cs b/src/Mages.Core/Runtime/Functions/StandardFunctions.cs index 121c1de7..597b4892 100644 --- a/src/Mages.Core/Runtime/Functions/StandardFunctions.cs +++ b/src/Mages.Core/Runtime/Functions/StandardFunctions.cs @@ -532,12 +532,12 @@ public static class StandardFunctions public static readonly Function ArcSin = new Function(args => { return Curry.MinOne(ArcSin, args) ?? - If.Is(args, x => Math.Asin(x)) ?? - If.Is(args, x => x.ForEach(Math.Asin)) ?? + If.Is(args, x => Mathx.Asin(x)) ?? + If.Is(args, x => Mathx.Asin(x)) ?? If.Is(args, x => Complex.Asin(x)) ?? If.Is(args, x => x.ForEach(Complex.Asin)) ?? If.Is>(args, o => o.Map(ArcSin)) ?? - Math.Asin(args[0].ToNumber()); + Mathx.Asin(args[0].ToNumber()); }); /// @@ -546,12 +546,12 @@ public static class StandardFunctions public static readonly Function ArcCos = new Function(args => { return Curry.MinOne(ArcCos, args) ?? - If.Is(args, x => Math.Acos(x)) ?? - If.Is(args, x => x.ForEach(Math.Acos)) ?? + If.Is(args, x => Mathx.Acos(x)) ?? + If.Is(args, x => Mathx.Acos(x)) ?? If.Is(args, x => Complex.Acos(x)) ?? If.Is(args, x => x.ForEach(Complex.Acos)) ?? If.Is>(args, o => o.Map(ArcCos)) ?? - Math.Acos(args[0].ToNumber()); + Mathx.Acos(args[0].ToNumber()); }); /// @@ -589,7 +589,7 @@ public static class StandardFunctions { return Curry.MinOne(ArcSec, args) ?? If.Is(args, x => Mathx.Asec(x)) ?? - If.Is(args, x => x.ForEach(Mathx.Asec)) ?? + If.Is(args, x => Mathx.Asec(x)) ?? If.Is(args, x => Mathx.Asec(x)) ?? If.Is(args, x => x.ForEach(Mathx.Asec)) ?? If.Is>(args, o => o.Map(ArcSec)) ?? @@ -603,7 +603,7 @@ public static class StandardFunctions { return Curry.MinOne(ArcCsc, args) ?? If.Is(args, x => Mathx.Acsc(x)) ?? - If.Is(args, x => x.ForEach(Mathx.Acsc)) ?? + If.Is(args, x => Mathx.Acsc(x)) ?? If.Is(args, x => Mathx.Acsc(x)) ?? If.Is(args, x => x.ForEach(Mathx.Acsc)) ?? If.Is>(args, o => o.Map(ArcCsc)) ?? @@ -631,7 +631,7 @@ public static class StandardFunctions { return Curry.MinOne(ArCosh, args) ?? If.Is(args, x => Mathx.Acosh(x)) ?? - If.Is(args, x => x.ForEach(Mathx.Acosh)) ?? + If.Is(args, x => Mathx.Acosh(x)) ?? If.Is(args, x => Mathx.Acosh(x)) ?? If.Is(args, x => x.ForEach(Mathx.Acosh)) ?? If.Is>(args, o => o.Map(ArCosh)) ?? @@ -645,7 +645,7 @@ public static class StandardFunctions { return Curry.MinOne(ArTanh, args) ?? If.Is(args, x => Mathx.Atanh(x)) ?? - If.Is(args, x => x.ForEach(Mathx.Atanh)) ?? + If.Is(args, x => Mathx.Atanh(x)) ?? If.Is(args, x => Mathx.Atanh(x)) ?? If.Is(args, x => x.ForEach(Mathx.Atanh)) ?? If.Is>(args, o => o.Map(ArTanh)) ?? @@ -659,7 +659,7 @@ public static class StandardFunctions { return Curry.MinOne(ArCoth, args) ?? If.Is(args, x => Mathx.Acoth(x)) ?? - If.Is(args, x => x.ForEach(Mathx.Acoth)) ?? + If.Is(args, x => Mathx.Acoth(x)) ?? If.Is(args, x => Mathx.Acoth(x)) ?? If.Is(args, x => x.ForEach(Mathx.Acoth)) ?? If.Is>(args, o => o.Map(ArCoth)) ?? diff --git a/src/Mages.Core/Runtime/Mathx.cs b/src/Mages.Core/Runtime/Mathx.cs index 1cba41f0..a8584293 100644 --- a/src/Mages.Core/Runtime/Mathx.cs +++ b/src/Mages.Core/Runtime/Mathx.cs @@ -131,11 +131,55 @@ public static Double Factorial(Double value) public static Complex Asinh(Complex value) => Complex.Log(value + Complex.Sqrt(value * value + 1.0)); - public static Double Acosh(Double value) => Math.Log(value + Math.Sqrt(value * value - 1.0)); + private static Double AcoshReal(Double value) => Math.Log(value + Math.Sqrt(value * value - 1.0)); + + private static Complex AcoshCmplx(Double value) => Acosh(new Complex(value, 0)); + + public static Object Acosh(Double value) + { + if (value >= 1.0) + { + return AcoshReal(value); + } + + return AcoshCmplx(value); + } + + public static Object Acosh(Double[,] value) + { + if (value.HasAny(x => x < 1.0)) + { + return value.ForEach(AcoshCmplx); + } + + return value.ForEach(AcoshReal); + } public static Complex Acosh(Complex value) => Complex.Log(value + Complex.Sqrt(value * value - 1.0)); - public static Double Atanh(Double value) => 0.5 * Math.Log((1.0 + value) / (1.0 - value)); + private static Double AtanhReal(Double value) => 0.5 * Math.Log((1.0 + value) / (1.0 - value)); + + private static Complex AtanhCmplx(Double value) => Atanh(new Complex(value, 0)); + + public static Object Atanh(Double value) + { + if (value >= -1.0 && value <= 1.0) + { + return AtanhReal(value); + } + + return AtanhCmplx(value); + } + + public static Object Atanh(Double[,] value) + { + if (value.HasAny(x => x < -1.0 || x > 1.0)) + { + return value.ForEach(AtanhCmplx); + } + + return value.ForEach(AtanhReal); + } public static Complex Atanh(Complex value) => 0.5 * Complex.Log((1.0 + value) / (1.0 - value)); @@ -161,7 +205,29 @@ public static Complex Coth(Complex value) return (a + b) / (a - b); } - public static Double Acoth(Double value) => 0.5 * Math.Log((1.0 + value) / (value - 1.0)); + private static Double AcothReal(Double value) => 0.5 * Math.Log((1.0 + value) / (value - 1.0)); + + private static Complex AcothCmplx(Double value) => Acoth(new Complex(value, 0.0)); + + public static Object Acoth(Double value) + { + if (value <= -1.0 || value >= 1.0) + { + return AcothReal(value); + } + + return AcothCmplx(value); + } + + public static Object Acoth(Double[,] value) + { + if (value.HasAny(x => x > -1.0 && x < 1.0)) + { + return value.ForEach(AcothCmplx); + } + + return value.ForEach(AcothReal); + } public static Complex Acoth(Complex value) => 0.5 * Complex.Log((1.0 + value) / (value - 1.0)); @@ -169,7 +235,77 @@ public static Complex Coth(Complex value) public static Complex Sec(Complex value) => 1.0 / Complex.Cos(value); - public static Double Asec(Double value) => Math.Acos(1.0 / value); + private static Double AsecReal(Double value) => Math.Acos(1.0 / value); + + private static Complex AsecCmplx(Double value) => Asec(new Complex(value, 0.0)); + + public static Object Asec(Double value) + { + if (value >= 1.0) + { + return AsecReal(value); + } + + return AsecCmplx(value); + } + + public static Object Asec(Double[,] value) + { + if (value.HasAny(x => x < 1.0)) + { + return value.ForEach(AsecCmplx); + } + + return value.ForEach(AsecReal); + } + + private static Double AsinReal(Double value) => Math.Asin(value); + + private static Complex AsinCmplx(Double value) => Complex.Asin(new Complex(value, 0.0)); + + public static Object Asin(Double value) + { + if (value >= -1.0 && value <= 1.0) + { + return AsinReal(value); + } + + return AsinCmplx(value); + } + + public static Object Asin(Double[,] value) + { + if (value.HasAny(x => x < -1.0 || x > 1.0)) + { + return value.ForEach(AsinCmplx); + } + + return value.ForEach(AsinReal); + } + + private static Double AcosReal(Double value) => Math.Acos(value); + + private static Complex AcosCmplx(Double value) => Complex.Acos(new Complex(value, 0.0)); + + public static Object Acos(Double value) + { + if (value >= -1.0 && value <= 1.0) + { + return AcosReal(value); + } + + return AcosCmplx(value); + } + + public static Object Acos(Double[,] value) + { + if (value.HasAny(x => x < -1.0 || x > 1.0)) + { + return value.ForEach(AcosCmplx); + } + + return value.ForEach(AcosReal); + } public static Complex Asec(Complex value) => Complex.Acos(1.0 / value); @@ -193,7 +329,29 @@ public static Complex Asech(Complex value) public static Complex Csc(Complex value) => 1.0 / Complex.Sin(value); - public static Double Acsc(Double value) => Math.Asin(1.0 / value); + private static Double AcscReal(Double value) => Math.Asin(1.0 / value); + + private static Complex AcscCmplx(Double value) => Acsc(new Complex(value, 0.0)); + + public static Object Acsc(Double value) + { + if (value <= -1.0 || value >= 1.0) + { + return AcscReal(value); + } + + return AcscCmplx(value); + } + + public static Object Acsc(Double[,] value) + { + if (value.HasAny(x => x > -1.0 && x < 1.0)) + { + return value.ForEach(AcscCmplx); + } + + return value.ForEach(AcscReal); + } public static Complex Acsc(Complex value) => Complex.Asin(1.0 / value); From 6a1d5810acda0036bb8bb2b98913646299aeaa1f Mon Sep 17 00:00:00 2001 From: Florian Rappl Date: Thu, 3 Jun 2021 10:55:47 +0200 Subject: [PATCH 26/27] Fixed reversed complex mod operation #103 --- src/Mages.Core/Runtime/BinaryOperators.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Mages.Core/Runtime/BinaryOperators.cs b/src/Mages.Core/Runtime/BinaryOperators.cs index 117b973b..c21f574c 100644 --- a/src/Mages.Core/Runtime/BinaryOperators.cs +++ b/src/Mages.Core/Runtime/BinaryOperators.cs @@ -84,7 +84,7 @@ static class BinaryOperators #region Other Fields private static readonly Func ModNumbers = (y, x) => x % y; - private static readonly Func ModCNumbers = (y, x) => Mathx.Mod(y, x); + private static readonly Func ModCNumbers = (y, x) => Mathx.Mod(x, y); private static readonly Func InvokeFunction = (f, arg) => f.Invoke(new[] { arg }); #endregion From c7c1e92c973487333234f68fd27a6526d13f06f7 Mon Sep 17 00:00:00 2001 From: Florian Rappl Date: Mon, 7 Jun 2021 13:14:51 +0200 Subject: [PATCH 27/27] Improved documentation --- doc/functions.md | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/doc/functions.md b/doc/functions.md index 40096717..7ba077cb 100644 --- a/doc/functions.md +++ b/doc/functions.md @@ -128,11 +128,13 @@ M = max([0.5, 2, -1, 10, -0.5]) // 10 Works with numbers and matrices (applied to each value). Equivalent to the less-than operator (`<`). If two matrices are supplied the dimensions must match. ``` -x = lt(2, 3) // 1 -M = lt(2, [1, 2, 3]) // [0, 0, 1] -M = lt([1, 2, 3], [2, 0, 3]) // [1, 0, 0] +x = lt(3, 2) // 1 +M = lt(2, [1, 2, 3]) // [1, 0, 0] +M = lt([1, 2, 3], [2, 0, 3]) // [0, 1, 0] ``` +**Remark**: Keep in mind that the first argument for the function represents the RHS of the operator. This allows currying such as `let lessThan2 = lt(2)` to be working as expected. + ### Equals Works with numbers and matrices (applied to each value). Equivalent to the equals operator (`==`). If two matrices are supplied the dimensions must match. @@ -148,11 +150,13 @@ M = eq([1, 2, 3], [2, 0, 3]) // [0, 0, 1] Works with numbers and matrices (applied to each value). Equivalent to the greater-than operator (`>`). If two matrices are supplied the dimensions must match. ``` -x = gt(2, 3) // 0 -M = gt(2, [1, 2, 3]) // [1, 0, 0] -M = gt([1, 2, 3], [2, 0, 3]) // [0, 1, 0] +x = gt(3, 2) // 0 +M = gt(2, [1, 2, 3]) // [0, 0, 1] +M = gt([1, 2, 3], [2, 0, 3]) // [1, 0, 0] ``` +**Remark**: Keep in mind that the first argument for the function represents the RHS of the operator. This allows currying such as `let greaterThan2 = gt(2)` to be working as expected. + ## Trigonometric Functions ### Sine