Skip to content

Commit

Permalink
Merge branch 'devel' into issues/#125-overflow-2
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianRappl authored Sep 5, 2024
2 parents 411a63d + 6ecbdc8 commit 9517a0f
Show file tree
Hide file tree
Showing 243 changed files with 15,984 additions and 16,107 deletions.
12 changes: 10 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ jobs:

- uses: actions/setup-dotnet@v3
with:
dotnet-version: '5.0.x'
dotnet-version: |
5.0.x
6.0.x
7.0.x
8.0.x
- name: Build
run: ./build.sh
Expand All @@ -29,7 +33,11 @@ jobs:

- uses: actions/setup-dotnet@v3
with:
dotnet-version: '5.0.x'
dotnet-version: |
5.0.x
6.0.x
7.0.x
8.0.x
- name: Build
run: |
Expand Down
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
# 3.0.0

- Improved GC allocations (#81)
- Added wrapping of `Task` in `Future` (#64)
- Added JSX syntax (#120)
- Added default `jsx` and `html` function (#120)
- Added events to `Engine` to handle uncaught errors (#121)

# 2.0.3

- Include checksum in chocolatey package

# 2.0.2

- Fixed vulnerability using outdated version of `System.Drawing.Common` for plugins
Expand Down
18 changes: 11 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,34 @@
![MAGES Logo](https://raw.githubusercontent.com/FlorianRappl/Mages/main/logo.png)
![MAGES Logo](./logo.png)

# MAGES

[![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)
[![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

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).
Among other applications, MAGES has been used in [Microsoft's PowerToys](https://github.com/microsoft/PowerToys).

### Current Status

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.
MAGES was just updated (v3.0.0) with object metadata, direct list support, and JSX syntax.

### Previous Status

**2023**:

MAGES was updated (v2.0.0) with support for complex numbers. Also, the build target and runtime has been updated to make use of modern possibilities.

**2018**:

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

MAGES itself does not have any dependencies, however, the tests are dependent on NUnit and the benchmarks use BenchmarkDotNet. Usually, MAGES should be installed via the NuGet package source. If this does not work for you, then clone the source and build MAGES yourself. Make sure that all unit tests pass.

The whole library was designed to be consumed from .NET 3.5 (or higher) applications. This means it is (amongst others) compatible with Unity / Mono 2.6. The NuGet package is available via [the official package feed](https://www.nuget.org/packages/MAGES).
The whole library was designed to be consumed from .NET Core 3.0 (or higher) / .NET 5.0 (or higher) applications. This means it is (amongst others) compatible with Unity 2021.2 or Mono 6.4. The NuGet package is available via [the official package feed](https://www.nuget.org/packages/MAGES).

### Get Me Started!

Expand Down
Binary file added assets/logo-128x128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/logo-256x256.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/logo-32x32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/logo-460x460.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/logo-64x64.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/logo-96x96.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 12 additions & 13 deletions build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ 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 buildDir = Directory("./src/Mages.Core/bin") + Directory(configuration) + Directory("netstandard2.1");
var replDir = Directory("./src/Mages.Repl/bin") + Directory(configuration) + Directory("net60");
var installerDir = Directory("./src/Mages.Repl.Installer/bin") + Directory(configuration) + Directory("net50");
var buildResultDir = Directory("./bin") + Directory(version);
var nugetRoot = buildResultDir + Directory("nuget");
var chocolateyRoot = buildResultDir + Directory("chocolatey");
Expand Down Expand Up @@ -71,7 +71,10 @@ Task("Restore-Packages")
.IsDependentOn("Clean")
.Does(() =>
{
NuGetRestore("./src/Mages.sln");
NuGetRestore("./src/Mages.sln", new NuGetRestoreSettings
{
DisableParallelProcessing = isRunningOnUnix && isRunningOnGitHubActions,
});
});

Task("Update-Assembly-Version")
Expand Down Expand Up @@ -123,7 +126,7 @@ Task("Copy-Files")
.IsDependentOn("Build")
.Does(() =>
{
var nugetBin = nugetRoot + Directory("lib") + Directory("netstandard2.0");
var nugetBin = nugetRoot + Directory("lib") + Directory("netstandard2.1");
CreateDirectory(nugetBin);
CreateDirectory(squirrelBin);
CreateDirectory(releaseDir);
Expand Down Expand Up @@ -204,10 +207,11 @@ Task("Create-Squirrel-Package")
});

Task("Create-Chocolatey-Package")
.IsDependentOn("Copy-Files")
.IsDependentOn("Create-Squirrel-Package")
.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 checksum = CalculateFileHash(releaseDir.Path.FullPath + "/MagesSetup.exe", HashAlgorithm.SHA256).ToHex();
var content = String.Format("$packageName = 'Mages'{1}$installerType = 'exe'{1}$url32 = 'https://github.com/FlorianRappl/Mages/releases/download/v{0}/MagesSetup.exe'{1}$silentArgs = ''{1}$checksum32 = '{2}'{1}{1}Install-ChocolateyPackage -PackageName \"$packageName\" -FileType \"$installerType\" -SilentArgs \"$silentArgs\" -Url \"$url32\" -Checksum \"$checksum32\" -ChecksumType \"sha256\"", version, Environment.NewLine, checksum);
var nuspec = chocolateyRoot + File("Mages.nuspec");
var toolsDirectory = chocolateyRoot + Directory("tools");
var scriptFile = toolsDirectory + File("chocolateyInstall.ps1");
Expand Down Expand Up @@ -267,7 +271,7 @@ Task("Publish-GitHub-Release")
TargetCommitish = isPublish ? "main" : "devel"
}).Result;
var target = nugetRoot + Directory("lib") + Directory("netstandard2.0");
var target = nugetRoot + Directory("lib") + Directory("netstandard2.1");
var libPath = target + File("Mages.Core.dll");
var releaseFiles = GetFiles(releaseDir.Path.FullPath + "/*");
Expand All @@ -280,11 +284,6 @@ Task("Publish-GitHub-Release")
{
var name = System.IO.Path.GetFileName(file.FullPath);
if (name.Equals("Setup.exe"))
{
name = "Mages.exe";
}
using (var fileStream = System.IO.File.OpenRead(file.FullPath))
{
newRelease.UploadAsset(release, new ReleaseAssetUpload(name, "application/x-msdownload", fileStream, null)).Wait();
Expand Down
14 changes: 11 additions & 3 deletions doc/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,14 @@ Works without any arguments.
x = rand() // any number between 0 and 1
```

### Generate Single Random Integer

Works with one argument.

```
x = randi(5) // any integer between 0 and 5
```

### Generate Random Vector

Works with one argument.
Expand All @@ -284,9 +292,9 @@ M = rand(3, 2) // a 3x2 matrix with numbers between 0 and 1
Works with one argument, which could be anything.

```
x = type(true) // "Boolean"
x = type([1, 2, 3]) // "Matrix"
x = type("foo") // "String"
x = type(true).name // "Boolean"
x = type([1, 2, 3]).name // "Matrix"
x = type("foo").name // "String"
```

### Checking Types
Expand Down
2 changes: 1 addition & 1 deletion doc/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ On starting the REPL we see the following:
\/ \/ \/ \/ \/
(c) Florian Rappl, 2024
Version 2.0.2
Version 2.0.3
Running on Microsoft Windows NT 6.2.9200.0
For help type 'help()'.
Expand Down
Binary file modified logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<Product>Mages</Product>
<Authors>Florian Rappl</Authors>
<Company>smapiot</Company>
<Version>2.0.2</Version>
<Version>3.0.0</Version>
<Copyright>Copyright (c) 2024, Florian Rappl</Copyright>
<PackageLicenseUrl>https://github.com/FlorianRappl/MAGES/blob/main/LICENSE</PackageLicenseUrl>
<PackageProjectUrl>https://github.com/FlorianRappl/MAGES/</PackageProjectUrl>
Expand Down
3 changes: 2 additions & 1 deletion src/Mages.Chocolatey.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
<authors>Florian Rappl</authors>
<owners>FlorianRappl</owners>
<licenseUrl>https://github.com/FlorianRappl/Mages/blob/main/LICENSE</licenseUrl>
<projectUrl>https://github.com/FlorianRappl/Mages</projectUrl>
<projectUrl>https://github.com/FlorianRappl/Mages/blob/main/README.md</projectUrl>
<iconUrl>https://raw.github.com/FlorianRappl/Mages/main/logo.png</iconUrl>
<releaseNotes>https://github.com/FlorianRappl/Mages/blob/main/CHANGELOG.md</releaseNotes>
<projectSourceUrl>https://github.com/FlorianRappl/Mages</projectSourceUrl>
<packageSourceUrl>https://github.com/FlorianRappl/Mages</packageSourceUrl>
<docsUrl>https://github.com/FlorianRappl/Mages/tree/main/doc</docsUrl>
<bugTrackerUrl>https://github.com/FlorianRappl/Mages/issues</bugTrackerUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
Expand Down
69 changes: 34 additions & 35 deletions src/Mages.Core.Performance/CachedBenchmarks.cs
Original file line number Diff line number Diff line change
@@ -1,45 +1,44 @@
namespace Mages.Core.Performance
namespace Mages.Core.Performance;

using BenchmarkDotNet.Attributes;
using System;
using System.Collections.Generic;

public class CachedBenchmarks
{
using BenchmarkDotNet.Attributes;
using System;
using System.Collections.Generic;
private static readonly String CallStandardFunctions = "sin(pi / 4) * cos(pi * 0.25) + exp(2) * log(3)";
private static readonly Engine MagesEngine = new();
private static readonly Dictionary<String, Func<Object>> FunctionCache = [];

public class CachedBenchmarks
[Benchmark]
public Double Mages_Uncached_CallStandardFunctions()
{
private static readonly String CallStandardFunctions = "sin(pi / 4) * cos(pi * 0.25) + exp(2) * log(3)";
private static readonly Engine MagesEngine = new Engine();
private static readonly Dictionary<String, Func<Object>> FunctionCache = new Dictionary<String, Func<Object>>();

[Benchmark]
public Double Mages_Uncached_CallStandardFunctions()
{
return MagesUncachedNumeric(CallStandardFunctions);
}
return MagesUncachedNumeric(CallStandardFunctions);
}

[Benchmark]
public Double Mages_Cached_CallStandardFunctions()
{
return MagesCachedNumeric(CallStandardFunctions);
}
[Benchmark]
public Double Mages_Cached_CallStandardFunctions()
{
return MagesCachedNumeric(CallStandardFunctions);
}

private Double MagesCachedNumeric(String sourceCode)
private Double MagesCachedNumeric(String sourceCode)
{
var func = default(Func<Object>);

if (!FunctionCache.TryGetValue(sourceCode, out func))
{
var func = default(Func<Object>);

if (!FunctionCache.TryGetValue(sourceCode, out func))
{
func = MagesEngine.Compile(sourceCode);
FunctionCache[sourceCode] = func;
}

var result = func.Invoke();
return (Double)result;
func = MagesEngine.Compile(sourceCode);
FunctionCache[sourceCode] = func;
}

var result = func.Invoke();
return (Double)result;
}

private Double MagesUncachedNumeric(String sourceCode)
{
var result = MagesEngine.Interpret(sourceCode);
return (Double)result;
}
private Double MagesUncachedNumeric(String sourceCode)
{
var result = MagesEngine.Interpret(sourceCode);
return (Double)result;
}
}
Loading

0 comments on commit 9517a0f

Please sign in to comment.