Skip to content

Commit

Permalink
ezr² v0.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Uralstech committed Aug 7, 2024
1 parent dc43304 commit 64d5ede
Show file tree
Hide file tree
Showing 28 changed files with 277 additions and 254 deletions.
14 changes: 14 additions & 0 deletions Changelog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
CHANGELOG - What's new?

See the GitHub releases for more detailed info:
https://github.com/Uralstech/ezrSquared/releases

* ezr² RE - v0.2.0 [07-08-24]
* [BREAKING CHANGE] SharpTypeWrapperAttribute will now require the type to have one SharpMethodWrapper wrapped constructor to create objects.
* [BREAKING CHANGE] EzrSharpSourceExecutableWrapper now inherits directly from EzrObject and implements some overrides.
* Static wrapped methods in SharpTypeWrapper wrapped types should work now.
* SharpMethodWrapperAttribute now also supports constructors.
* Updated error messages returned by SharpFieldWrapperAttribute's validation methods.
* Updated all declarations of DynamicallyAccessedMembers attributes to be more specific.
* Added some missing built-ins in EzrBuiltinsUtility.
* Fixed formatting, removed unused imports.
* Updated documentation.

* ezr² RE - v0.1.2 [06-08-24]
* Updated build dependencies.
* Updated documentation and website.
Expand Down
2 changes: 1 addition & 1 deletion src/EzrSquared.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<Title>ezr² Portable Library</Title>
<Description>The ezr² programming language, as a portable class library! This can be used to integrate ezr² as an embedded scripting language in your apps, websites and more!</Description>

<Version>0.1.2</Version>
<Version>0.2.0</Version>

<Authors>Udayshankar Ravikumar</Authors>
<Company>URAV ADVANCED LEARNING SYSTEMS PRIVATE LIMITED</Company>
Expand Down
25 changes: 14 additions & 11 deletions src/Runtime/Types/CSharpWrappers/Builtins/EzrBuiltinsUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,29 +45,32 @@ public static void AddBuiltinFunctions(Context context)
public static void AddBuiltinTypes(Context context)
{
EzrSharpSourceTypeWrapper runtimeError = new(typeof(EzrRuntimeError), context, Position.None, Position.None);
context.Set(null, runtimeError.SharpTypeName, ReferencePool.Get(runtimeError, AccessMod.Constant));

EzrSharpSourceTypeWrapper assertionError = new(typeof(EzrAssertionError), context, Position.None, Position.None);
EzrSharpSourceTypeWrapper illegalOperationError = new(typeof(EzrIllegalOperationError), context, Position.None, Position.None);
EzrSharpSourceTypeWrapper undefinedValueError = new(typeof(EzrUndefinedValueError), context, Position.None, Position.None);
EzrSharpSourceTypeWrapper privateValueAccessError = new(typeof(EzrPrivateMemberOperationError), context, Position.None, Position.None);
EzrSharpSourceTypeWrapper mathError = new(typeof(EzrMathError), context, Position.None, Position.None);
EzrSharpSourceTypeWrapper valueOutOfRangeError = new(typeof(EzrValueOutOfRangeError), context, Position.None, Position.None);
EzrSharpSourceTypeWrapper unexpectedTypeError = new(typeof(EzrUnexpectedTypeError), context, Position.None, Position.None);
EzrSharpSourceTypeWrapper keyNotFoundError = new(typeof(EzrKeyNotFoundError), context, Position.None, Position.None);
EzrSharpSourceTypeWrapper mathError = new(typeof(EzrMathError), context, Position.None, Position.None);
EzrSharpSourceTypeWrapper missingRequiredArgumentError = new(typeof(EzrMissingRequiredArgumentError), context, Position.None, Position.None);
EzrSharpSourceTypeWrapper privateMemberOperationError = new(typeof(EzrPrivateMemberOperationError), context, Position.None, Position.None);
EzrSharpSourceTypeWrapper undefinedValueError = new(typeof(EzrUndefinedValueError), context, Position.None, Position.None);
EzrSharpSourceTypeWrapper unexpectedArgumentError = new(typeof(EzrUnexpectedArgumentError), context, Position.None, Position.None);
EzrSharpSourceTypeWrapper unexpectedTypeError = new(typeof(EzrUnexpectedTypeError), context, Position.None, Position.None);
EzrSharpSourceTypeWrapper unsupportedWrappingError = new(typeof(EzrUnsupportedWrappingError), context, Position.None, Position.None);
EzrSharpSourceTypeWrapper valueOutOfRangeError = new(typeof(EzrValueOutOfRangeError), context, Position.None, Position.None);
EzrSharpSourceTypeWrapper wrapperExecutionError = new(typeof(EzrWrapperExecutionError), context, Position.None, Position.None);

context.Set(null, runtimeError.SharpTypeName, ReferencePool.Get(runtimeError, AccessMod.Constant));
context.Set(null, assertionError.SharpTypeName, ReferencePool.Get(assertionError, AccessMod.Constant));
context.Set(null, illegalOperationError.SharpTypeName, ReferencePool.Get(illegalOperationError, AccessMod.Constant));
context.Set(null, undefinedValueError.SharpTypeName, ReferencePool.Get(undefinedValueError, AccessMod.Constant));
context.Set(null, privateValueAccessError.SharpTypeName, ReferencePool.Get(privateValueAccessError, AccessMod.Constant));
context.Set(null, mathError.SharpTypeName, ReferencePool.Get(mathError, AccessMod.Constant));
context.Set(null, valueOutOfRangeError.SharpTypeName, ReferencePool.Get(valueOutOfRangeError, AccessMod.Constant));
context.Set(null, unexpectedTypeError.SharpTypeName, ReferencePool.Get(unexpectedTypeError, AccessMod.Constant));
context.Set(null, keyNotFoundError.SharpTypeName, ReferencePool.Get(keyNotFoundError, AccessMod.Constant));
context.Set(null, mathError.SharpTypeName, ReferencePool.Get(mathError, AccessMod.Constant));
context.Set(null, missingRequiredArgumentError.SharpTypeName, ReferencePool.Get(missingRequiredArgumentError, AccessMod.Constant));
context.Set(null, privateMemberOperationError.SharpTypeName, ReferencePool.Get(privateMemberOperationError, AccessMod.Constant));
context.Set(null, undefinedValueError.SharpTypeName, ReferencePool.Get(undefinedValueError, AccessMod.Constant));
context.Set(null, unexpectedArgumentError.SharpTypeName, ReferencePool.Get(unexpectedArgumentError, AccessMod.Constant));
context.Set(null, unexpectedTypeError.SharpTypeName, ReferencePool.Get(unexpectedTypeError, AccessMod.Constant));
context.Set(null, unsupportedWrappingError.SharpTypeName, ReferencePool.Get(unsupportedWrappingError, AccessMod.Constant));
context.Set(null, valueOutOfRangeError.SharpTypeName, ReferencePool.Get(valueOutOfRangeError, AccessMod.Constant));
context.Set(null, wrapperExecutionError.SharpTypeName, ReferencePool.Get(wrapperExecutionError, AccessMod.Constant));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class EzrSharpCompatibilityObjectInstance : EzrSharpCompatibilityWrapper

public EzrSharpCompatibilityObjectInstance(object instance,

Check warning on line 23 in src/Runtime/Types/CSharpWrappers/CompatWrappers/EzrSharpCompatibilityObjectInstance.cs

View workflow job for this annotation

GitHub Actions / publish-docs

Missing XML comment for publicly visible type or member 'EzrSharpCompatibilityObjectInstance.EzrSharpCompatibilityObjectInstance(object, Type, RuntimeResult, Context, Position, Position)'

[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.PublicProperties)]
Type instanceType,

RuntimeResult result, Context parentContext, Position startPosition, Position endPosition) : base(parentContext, startPosition, endPosition)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,25 @@ public class EzrSharpCompatibilityType : EzrSharpCompatibilityWrapper
/// <inheritdoc/>
public override string Tag { get; protected internal set; } = "ezrSquared.CSharpType";

[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]
public readonly Type SharpType;
[DynamicallyAccessedMembers(
DynamicallyAccessedMemberTypes.PublicFields
| DynamicallyAccessedMemberTypes.PublicMethods
| DynamicallyAccessedMemberTypes.PublicProperties
| DynamicallyAccessedMemberTypes.PublicConstructors
| DynamicallyAccessedMemberTypes.NonPublicConstructors
)] public readonly Type SharpType;

Check warning on line 26 in src/Runtime/Types/CSharpWrappers/CompatWrappers/EzrSharpCompatibilityType.cs

View workflow job for this annotation

GitHub Actions / publish-docs

Missing XML comment for publicly visible type or member 'EzrSharpCompatibilityType.SharpType'

public readonly string SharpTypeName;

Check warning on line 28 in src/Runtime/Types/CSharpWrappers/CompatWrappers/EzrSharpCompatibilityType.cs

View workflow job for this annotation

GitHub Actions / publish-docs

Missing XML comment for publicly visible type or member 'EzrSharpCompatibilityType.SharpTypeName'

public EzrSharpCompatibilityType(

Check warning on line 30 in src/Runtime/Types/CSharpWrappers/CompatWrappers/EzrSharpCompatibilityType.cs

View workflow job for this annotation

GitHub Actions / publish-docs

Missing XML comment for publicly visible type or member 'EzrSharpCompatibilityType.EzrSharpCompatibilityType(Type, RuntimeResult, Context, Position, Position)'
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]
Type type,

[DynamicallyAccessedMembers(
DynamicallyAccessedMemberTypes.PublicFields
| DynamicallyAccessedMemberTypes.PublicMethods
| DynamicallyAccessedMemberTypes.PublicProperties
| DynamicallyAccessedMemberTypes.PublicConstructors
| DynamicallyAccessedMemberTypes.NonPublicConstructors
)]Type type,

RuntimeResult result, Context parentContext, Position startPosition, Position endPosition) : base(parentContext, startPosition, endPosition)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ namespace EzrSquared.Runtime.Types.CSharpWrappers.CompatWrappers.ObjectMembers.E

public class EzrSharpCompatibilityConstructor : EzrSharpCompatibilityExecutable
{
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.PublicProperties)]
public readonly Type ConstructingType;
public readonly string ConstructingTypeName;
public readonly ConstructorInfo SharpConstructor;

public EzrSharpCompatibilityConstructor(ConstructorInfo sharpConstructor,

[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.PublicProperties)]
Type constructType,

Context context, Position startPosition, Position endPosition) : base(sharpConstructor, null, context, startPosition, endPosition)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
using EzrSquared.Runtime.Types.Core.Errors;
using EzrSquared.Runtime.Types.CSharpWrappers.CompatWrappers;
using EzrSquared.Util;
using System;
using System.Collections.Generic;

namespace EzrSquared.Runtime.Types.CSharpWrappers.SourceWrappers;

public abstract class EzrSharpSourceExecutableWrapper : EzrSharpCompatibilityWrapper
public abstract class EzrSharpSourceExecutableWrapper : EzrObject
{
/// <inheritdoc/>
public override string TypeName { get; protected internal set; } = "csharp source executable wrapper";
Expand Down Expand Up @@ -115,4 +114,30 @@ protected internal Dictionary<string, Reference> CheckAndPopulateArguments(Refer

return argumentReferences;
}

/// <inheritdoc/>
public override void ComparisonEqual(IEzrObject other, RuntimeResult result)
{
bool equal = StrictEquals(other, result);
if (result.ShouldReturn)
return;

result.Success(NewBooleanConstant(equal));
}

/// <inheritdoc/>
public override void ComparisonNotEqual(IEzrObject other, RuntimeResult result)
{
bool equal = StrictEquals(other, result);
if (result.ShouldReturn)
return;

result.Success(NewBooleanConstant(!equal));
}

/// <inheritdoc/>
public override bool EvaluateBoolean(RuntimeResult result)
{
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,27 @@ public class EzrSharpSourceTypeWrapper : EzrSharpSourceExecutableWrapper
/// <inheritdoc/>
public override string Tag { get; protected internal set; } = "ezrSquared.CSharpSourceTypeWrapper";

[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]
public readonly Type SharpType;
[DynamicallyAccessedMembers(
DynamicallyAccessedMemberTypes.PublicMethods
| DynamicallyAccessedMemberTypes.PublicFields
| DynamicallyAccessedMemberTypes.PublicProperties
| DynamicallyAccessedMemberTypes.PublicConstructors
| DynamicallyAccessedMemberTypes.NonPublicConstructors
)] public readonly Type SharpType;

public readonly string SharpTypeName;

public readonly EzrSharpSourceWrappableMethod Constructor;
public readonly ConstructorInfo Constructor;

public EzrSharpSourceTypeWrapper(

[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]
Type type,
[DynamicallyAccessedMembers(
DynamicallyAccessedMemberTypes.PublicMethods
| DynamicallyAccessedMemberTypes.PublicFields
| DynamicallyAccessedMemberTypes.PublicProperties
| DynamicallyAccessedMemberTypes.PublicConstructors
| DynamicallyAccessedMemberTypes.NonPublicConstructors
)] Type type,

Context parentContext, Position startPosition, Position endPosition) : base(parentContext, startPosition, endPosition)
{
Expand All @@ -44,46 +54,44 @@ public EzrSharpSourceTypeWrapper(
SharpTypeName = typeAttribute.Name;
Tag = $"{Tag}.{SharpTypeName}.{Utils.GetNextUniqueId()}";

// Get constructor info.
MethodInfo constructor = SharpType.GetMethod(typeAttribute.Constructor, BindingFlags.Static | BindingFlags.Public | BindingFlags.IgnoreReturn)
?? throw new NullReferenceException($"Could not find constructor method \"{typeAttribute.Constructor}\" in type \"{type.Name}\"!");
Exception? typeAttributeException = SharpTypeWrapperAttribute.ValidateMethodParameters(SharpType,
out (ConstructorInfo Info, SharpMethodWrapperAttribute Attribute)? constructor);

// Get constructor attribute.
SharpMethodWrapperAttribute constructorAttribute = constructor.GetCustomAttribute<SharpMethodWrapperAttribute>(true)
?? throw new ArgumentException($"No \"{nameof(SharpMethodWrapperAttribute)}\" attribute found in constructor method \"{constructor.Name}\"!", nameof(type));
if (typeAttributeException is not null)
throw typeAttributeException;

Exception? parameterException = SharpMethodWrapperAttribute.ValidateMethodParameters(constructor);
Exception? parameterException = SharpMethodWrapperAttribute.ValidateMethodParameters(constructor!.Value.Info);
if (parameterException is not null)
throw parameterException;

// Get constructor parameters.
int requiredParameters = constructorAttribute.RequiredParameters.Length;
Parameters = new (string Name, bool IsRequired)[constructorAttribute.RequiredParameters.Length + constructorAttribute.OptionalParameters.Length];
int requiredParameters = constructor.Value.Attribute.RequiredParameters.Length;
Parameters = new (string Name, bool IsRequired)[constructor.Value.Attribute.RequiredParameters.Length + constructor.Value.Attribute.OptionalParameters.Length];

// Required parameters.
for (int j = 0; j < requiredParameters; j++)
Parameters[j] = new(constructorAttribute.RequiredParameters[j], true);
Parameters[j] = new(constructor.Value.Attribute.RequiredParameters[j], true);

// Optional parameters.
for (int j = 0; j < constructorAttribute.OptionalParameters.Length; j++)
Parameters[j + requiredParameters] = new(constructorAttribute.OptionalParameters[j], false);
for (int j = 0; j < constructor.Value.Attribute.OptionalParameters.Length; j++)
Parameters[j + requiredParameters] = new(constructor.Value.Attribute.OptionalParameters[j], false);

// Set variables.
HasKeywordArguments = constructorAttribute.HasKeywordArguments;
Constructor = (EzrSharpSourceWrappableMethod)constructor.CreateDelegate(typeof(EzrSharpSourceWrappableMethod));
HasKeywordArguments = constructor.Value.Attribute.HasKeywordArguments;
Constructor = constructor.Value.Info;

// Get static methods to wrap.
MethodInfo[] staticMethods = SharpType.GetMethods(BindingFlags.Static);
MethodInfo[] staticMethods = SharpType.GetMethods(BindingFlags.Public | BindingFlags.Static);
for (int i = 0; i < staticMethods.Length; i++)
{
MethodInfo method = staticMethods[i];

// Check if abstract or same as constructor.
if (method.IsAbstract || method.Name == constructor.Name)
// Check if abstract.
if (method.IsAbstract)
continue;

// Check if method can be wrapped.
SharpMethodWrapperAttribute? methodAttribute = constructor.GetCustomAttribute<SharpMethodWrapperAttribute>(true);
SharpMethodWrapperAttribute? methodAttribute = method.GetCustomAttribute<SharpMethodWrapperAttribute>(false);
if (methodAttribute is null)
continue;

Expand Down Expand Up @@ -125,17 +133,24 @@ public override void Execute(Reference[] arguments, Interpreter interpreter, Run
if (result.ShouldReturn)
return;

Constructor.Invoke(new SharpMethodParameters
(
argumentReferences,
_executionContext,
_creationContext,
Context,
StartPosition,
EndPosition,
interpreter,
result
));
IEzrObject newObject = (IEzrObject)Constructor.Invoke(
[
new SharpMethodParameters
(
argumentReferences,
_executionContext,
_creationContext,
Context,
StartPosition,
EndPosition,
interpreter,
result
)
]
);

if (!result.ShouldReturn)
result.Success(ReferencePool.Get(newObject, AccessMod.PrivateConstant));
}

/// <inheritdoc/>
Expand Down
12 changes: 2 additions & 10 deletions src/Runtime/Types/Core/RuntimeErrors/EzrAssertionError.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace EzrSquared.Runtime.Types.Core.Errors;
/// <param name="context">The context in which the error occurred.</param>
/// <param name="startPosition">The starting position of the error.</param>
/// <param name="endPosition">The ending position of the error.</param>
[SharpTypeWrapper("assertion_error", nameof(WrapperConstructor))]
[SharpTypeWrapper("assertion_error")]
public class EzrAssertionError(Context context, Position startPosition, Position endPosition) : EzrRuntimeError("Assertion failed", "The assertion conditions were not met!", context, startPosition, endPosition)
{
/// <inheritdoc/>
Expand All @@ -22,13 +22,5 @@ public class EzrAssertionError(Context context, Position startPosition, Position
/// </summary>
/// <param name="arguments">The constructor arguments.</param>
[SharpMethodWrapper()]
public static new void WrapperConstructor(SharpMethodParameters arguments)
{
arguments.Result.Success(ReferencePool.Get(
new EzrAssertionError(
arguments.ExecutionContext,
arguments.StartPosition,
arguments.EndPosition),
AccessMod.PrivateConstant));
}
public EzrAssertionError(SharpMethodParameters arguments) : this(arguments.ExecutionContext, arguments.StartPosition, arguments.EndPosition) { }
}
Loading

0 comments on commit 64d5ede

Please sign in to comment.