Skip to content

Commit

Permalink
Wrapper unification part 3.
Browse files Browse the repository at this point in the history
  • Loading branch information
Uralstech committed Dec 20, 2024
1 parent c2b908a commit f932e44
Show file tree
Hide file tree
Showing 38 changed files with 288 additions and 304 deletions.
8 changes: 4 additions & 4 deletions src/Executor/CodeExecutor.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using EzrSquared.Runtime;
using EzrSquared.Runtime.Types.CSharpWrappers.Builtins;
using EzrSquared.Runtime.Types.CSharpWrappers.CompatWrappers;
using EzrSquared.Runtime.Types.Builtins;
using EzrSquared.Runtime.Types.Wrappers;
using EzrSquared.Syntax;
using EzrSquared.Syntax.Errors;
using System;
Expand Down Expand Up @@ -86,8 +86,8 @@ public static void AddToContext(Reference reference, string name)
/// </exception>
/// <param name="wrapper">The wrapped object to add.</param>
/// <param name="accessibilityModifiers">The accessibility modifiers for the reference. Defaults to <see cref="AccessMod.Constant"/>.</param>
/// <typeparam name="TMemberInfo">See <see cref="EzrSharpCompatibilityWrapper{TMemberInfo}"/>.</typeparam>
public static void AddToContext<TMemberInfo>(EzrSharpCompatibilityWrapper<TMemberInfo> wrapper, AccessMod accessibilityModifiers = AccessMod.Constant)
/// <typeparam name="TMemberInfo">See <see cref="EzrWrapper{TMemberInfo}"/>.</typeparam>
public static void AddToContext<TMemberInfo>(EzrWrapper<TMemberInfo> wrapper, AccessMod accessibilityModifiers = AccessMod.Constant)
where TMemberInfo : MemberInfo
{
if (RuntimeContext is null)
Expand Down
6 changes: 3 additions & 3 deletions src/GlobalSuppressions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
[assembly: SuppressMessage("Style", "IDE0078:Use pattern matching", Justification = "Recommended fix breaks code.", Scope = "member", Target = "~M:EzrSquared.Runtime.Types.Core.Text.EzrCharacterList.Multiplication(EzrSquared.Runtime.Types.IEzrObject,EzrSquared.Runtime.RuntimeResult)")]
[assembly: SuppressMessage("Style", "IDE0078:Use pattern matching", Justification = "Recommended fix breaks code.", Scope = "member", Target = "~M:EzrSquared.Runtime.Types.Collections.EzrList.Multiplication(EzrSquared.Runtime.Types.IEzrObject,EzrSquared.Runtime.RuntimeResult)")]
[assembly: SuppressMessage("Style", "IDE0078:Use pattern matching", Justification = "Recommended fix breaks code.", Scope = "member", Target = "~M:EzrSquared.Runtime.Types.Core.Text.EzrString.Multiplication(EzrSquared.Runtime.Types.IEzrObject,EzrSquared.Runtime.RuntimeResult)")]
[assembly: SuppressMessage("Style", "IDE0078:Use pattern matching", Justification = "Recommended fix breaks code.", Scope = "member", Target = "~M:EzrSquared.Runtime.Types.CSharpWrappers.CompatWrappers.EzrSharpCompatibilityWrapper`1.EzrObjectToCSharp(EzrSquared.Runtime.Types.IEzrObject,System.Type,EzrSquared.Runtime.RuntimeResult)~System.Object")]
[assembly: SuppressMessage("Style", "IDE0046:Convert to conditional expression", Justification = "Too many ternary operators.", Scope = "member", Target = "~M:EzrSquared.Runtime.Types.CSharpWrappers.CompatWrappers.Attributes.WrappedMemberAttribute.ValidateMethod(System.Reflection.MethodBase,System.Boolean)~System.Boolean")]
[assembly: SuppressMessage("Style", "IDE0046:Convert to conditional expression", Justification = "Too many ternary operators.", Scope = "member", Target = "~M:EzrSquared.Runtime.Types.CSharpWrappers.CompatWrappers.Attributes.WrappedMemberAttribute.ValidateType(System.Type,System.Boolean)~System.Boolean")]
[assembly: SuppressMessage("Style", "IDE0078:Use pattern matching", Justification = "Recommended fix breaks code.", Scope = "member", Target = "~M:EzrSquared.Runtime.Types.Wrappers.EzrWrapper`1.EzrObjectToCSharp(EzrSquared.Runtime.Types.IEzrObject,System.Type,EzrSquared.Runtime.RuntimeResult)~System.Object")]
[assembly: SuppressMessage("Style", "IDE0046:Convert to conditional expression", Justification = "Too many ternary operators.", Scope = "member", Target = "~M:EzrSquared.Runtime.Types.Wrappers.WrapMemberAttribute.ValidateMethod(System.Reflection.MethodBase,System.Boolean)~System.Boolean")]
[assembly: SuppressMessage("Style", "IDE0046:Convert to conditional expression", Justification = "Too many ternary operators.", Scope = "member", Target = "~M:EzrSquared.Runtime.Types.Wrappers.WrapMemberAttribute.ValidateType(System.Type,System.Boolean)~System.Boolean")]
12 changes: 6 additions & 6 deletions src/Runtime/Collections/RuntimeEzrObjectDictionary.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using EzrSquared.Runtime.Types;
using EzrSquared.Runtime.Types.Collections;
using EzrSquared.Runtime.Types.Core.Errors;
using EzrSquared.Runtime.Types.CSharpWrappers.CompatWrappers.Attributes;
using EzrSquared.Runtime.Types.CSharpWrappers.CompatWrappers.ObjectMembers.Executables.Attributes;
using EzrSquared.Runtime.Types.Wrappers;
using EzrSquared.Runtime.Types.Wrappers.Members.Methods;
using System.Collections;
using System.Collections.Generic;

Expand All @@ -21,7 +21,7 @@ public class RuntimeEzrObjectDictionary : IMutable<RuntimeEzrObjectDictionary>,
/// <summary>
/// The number of <see cref="IEzrObject"/>s in the <see cref="RuntimeEzrObjectDictionary"/>.
/// </summary>
[WrappedMember("length")]
[WrapMember("length")]
public int Count => _items.Count;

/// <summary>
Expand Down Expand Up @@ -117,7 +117,7 @@ public bool Remove(IEzrObject key, RuntimeResult result)
/// </remarks>
/// <param name="key">The key (hash) to be removed.</param>
/// <returns><see langword="true"/> if the operation was successful, <see langword="false"/> if not.</returns>
[WrappedMember("remove_by_hash")]
[WrapMember("remove_by_hash")]
public bool RemoveHash(int key)
{
if (_items.TryGetValue(key, out KeyValuePair<IEzrObject, Reference> pair))
Expand Down Expand Up @@ -192,8 +192,8 @@ public Reference Get(IEzrObject key, RuntimeResult result)
/// <param name="key">The key to be checked.</param>
/// <param name="result">The <see cref="RuntimeResult"/> object for returning errors.</param>
/// <returns><see langword="true"/> if the key was found, <see langword="false"/> if any error occured or the key was not found.</returns>
[WrappedMember]
public bool HasKey(IEzrObject key, [Runtime(Feature.ResultRef)] RuntimeResult result)
[WrapMember]
public bool HasKey(IEzrObject key, [FeatureParameter(Feature.ResultRef)] RuntimeResult result)
{
int hash = key.ComputeHashCode(result);
return !result.ShouldReturn && _items.ContainsKey(hash);
Expand Down
4 changes: 2 additions & 2 deletions src/Runtime/Interpreter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
using EzrSquared.Runtime.Types.Core.Errors;
using EzrSquared.Runtime.Types.Core.Numerics;
using EzrSquared.Runtime.Types.Core.Text;
using EzrSquared.Runtime.Types.CSharpWrappers.CompatWrappers;
using EzrSquared.Runtime.Types.Executables;
using EzrSquared.Runtime.Types.Wrappers;
using System;
using System.Collections.Generic;
using System.Numerics;
Expand Down Expand Up @@ -1174,7 +1174,7 @@ private void VisitTryNode(TryNode node, Context executionContext, Context callin
return;

IEzrObject targetObject = RuntimeResult.Reference.Object;
if (targetObject is not EzrSharpCompatibilityType target || !typeof(IEzrRuntimeError).IsAssignableFrom(target.SharpMember))
if (targetObject is not EzrTypeWrapper target || !typeof(IEzrRuntimeError).IsAssignableFrom(target.SharpMember))
{
RuntimeResult.Failure(new EzrUnexpectedTypeError($"Expected error type, but got object of type \"{targetObject.TypeName}\"!", executionContext, errorType.StartPosition, errorType.EndPosition));
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@
using EzrSquared.Runtime.Types.Core.Errors;
using EzrSquared.Runtime.Types.Core.Numerics;
using EzrSquared.Runtime.Types.Core.Text;
using EzrSquared.Runtime.Types.CSharpWrappers.CompatWrappers;
using EzrSquared.Runtime.Types.CSharpWrappers.CompatWrappers.Attributes;
using EzrSquared.Runtime.Types.CSharpWrappers.CompatWrappers.ObjectMembers.Executables.Attributes;
using EzrSquared.Runtime.Types.Wrappers;
using EzrSquared.Runtime.Types.Wrappers.Members.Methods;
using System;
using System.Collections.Generic;
using System.Text;

namespace EzrSquared.Runtime.Types.CSharpWrappers.Builtins;
namespace EzrSquared.Runtime.Types.Builtins;

/// <summary>
/// All built-in functions in ezr².
Expand Down Expand Up @@ -53,15 +52,14 @@ public static class EzrBuiltinFunctions
/// </item>
/// </list>
/// </remarks>
/// <param name="arguments">The method arguments.</param>
[WrappedMember]
[WrapMember]
public static void Show(
[Expose(true)] string lineEnd,
[Expose(true)] string separator,
[Runtime(Feature.PositionalArguments)] ExtraPositionalArguments messages,
[Runtime(Feature.CallerRef)] IEzrObject wrapper,
[Runtime(Feature.ResultRef)] RuntimeResult result,
[Runtime(Feature.ExecutionRef)] Context executionContext)
[Parameter(true)] string lineEnd,
[Parameter(true)] string separator,
[FeatureParameter(Feature.PositionalArguments)] ExtraPositionalArguments messages,
[FeatureParameter(Feature.CallerRef)] IEzrObject wrapper,
[FeatureParameter(Feature.ResultRef)] RuntimeResult result,
[FeatureParameter(Feature.ExecutionRef)] Context executionContext)
{
if (messages.Count == 0)
{
Expand Down Expand Up @@ -112,9 +110,8 @@ public static void Show(
/// </item>
/// </list>
/// </remarks>
/// <param name="arguments">The method arguments.</param>
[WrappedMember]
public static void ThrowError(IEzrRuntimeError error, [Runtime(Feature.ResultRef)] RuntimeResult result)
[WrapMember]
public static void ThrowError(IEzrRuntimeError error, [FeatureParameter(Feature.ResultRef)] RuntimeResult result)
{
result.Failure(error);
}
Expand All @@ -134,9 +131,8 @@ public static void ThrowError(IEzrRuntimeError error, [Runtime(Feature.ResultRef
/// ezr² return type:
/// <see cref="EzrString"/>
/// </remarks>
/// <param name="arguments">The method arguments.</param>
[WrappedMember]
public static string Get([Expose(true)] IEzrObject? message, [Runtime(Feature.ResultRef)] RuntimeResult result)
[WrapMember]
public static string Get([Parameter(true)] IEzrObject? message, [FeatureParameter(Feature.ResultRef)] RuntimeResult result)
{
if (message is not null)
{
Expand All @@ -157,8 +153,7 @@ public static string Get([Expose(true)] IEzrObject? message, [Runtime(Feature.Re
/// ezr² return type:
/// <see cref="EzrNothing"/>
/// </remarks>
/// <param name="arguments">The method arguments.</param>
[WrappedMember]
[WrapMember]
public static void Clear()
{
Console.Clear();
Expand All @@ -182,12 +177,11 @@ public static void Clear()
/// ezr² errors:
/// <see cref="EzrAssertionError"/> if the condition is not met.
/// </remarks>
/// <param name="arguments">The method arguments.</param>
[WrappedMember]
[WrapMember]
public static void Assert(IEzrObject condition,
[Runtime(Feature.CallerRef)] IEzrObject wrapper,
[Runtime(Feature.ResultRef)] RuntimeResult result,
[Runtime(Feature.ExecutionRef)] Context executionContext)
[FeatureParameter(Feature.CallerRef)] IEzrObject wrapper,
[FeatureParameter(Feature.ResultRef)] RuntimeResult result,
[FeatureParameter(Feature.ExecutionRef)] Context executionContext)
{
bool conditionResult = condition.EvaluateBoolean(result);
if (!result.ShouldReturn && !conditionResult)
Expand All @@ -209,9 +203,8 @@ public static void Assert(IEzrObject condition,
/// ezr² return type:
/// <see cref="EzrInteger"/>
/// </remarks>
/// <param name="arguments">The method arguments.</param>
[WrappedMember]
public static int Hash(IEzrObject toHash, [Runtime(Feature.ResultRef)] RuntimeResult result)
[WrapMember]
public static int Hash(IEzrObject toHash, [FeatureParameter(Feature.ResultRef)] RuntimeResult result)
{
return toHash.ComputeHashCode(result);
}
Expand All @@ -231,8 +224,7 @@ public static int Hash(IEzrObject toHash, [Runtime(Feature.ResultRef)] RuntimeRe
/// ezr² return type:
/// <see cref="EzrString"/>
/// </remarks>
/// <param name="arguments">The method arguments.</param>
[WrappedMember]
[WrapMember]
public static string TypeOf(IEzrObject toCheck)
{
return toCheck.Tag;
Expand All @@ -253,8 +245,7 @@ public static string TypeOf(IEzrObject toCheck)
/// ezr² return type:
/// <see cref="EzrString"/>
/// </remarks>
/// <param name="arguments">The method arguments.</param>
[WrappedMember]
[WrapMember]
public static string TypeNameOf(IEzrObject toCheck)
{
return toCheck.TypeName;
Expand All @@ -275,8 +266,7 @@ public static string TypeNameOf(IEzrObject toCheck)
/// ezr² return type:
/// <see cref="EzrString"/>
/// </remarks>
/// <param name="arguments">The method arguments.</param>
[WrappedMember]
[WrapMember]
public static int TypeHashOf(IEzrObject toCheck)
{
return toCheck.HashTag;
Expand All @@ -300,9 +290,8 @@ public static int TypeHashOf(IEzrObject toCheck)
/// ezr² errors:
/// <see cref="EzrUnexpectedTypeError"/> if "to_copy" is not of the expected type.
/// </remarks>
/// <param name="arguments">The method arguments.</param>
[WrappedMember]
public static IEzrObject Copy(IEzrMutableObject toCopy, [Runtime(Feature.ResultRef)] RuntimeResult result)
[WrapMember]
public static IEzrObject Copy(IEzrMutableObject toCopy, [FeatureParameter(Feature.ResultRef)] RuntimeResult result)
{
return (IEzrObject?)toCopy.DeepCopy(result) ?? EzrConstants.Nothing;
}
Expand All @@ -322,13 +311,12 @@ public static IEzrObject Copy(IEzrMutableObject toCopy, [Runtime(Feature.ResultR
/// ezr² return type:
/// <see cref="IEzrObject"/>
/// </remarks>
/// <param name="arguments">The method arguments.</param>
[WrappedMember]
public static EzrSharpCompatibilityObjectInstance GetRaw(IEzrObject toGet,
[Runtime(Feature.CallerRef)] IEzrObject wrapper,
[Runtime(Feature.ExecutionRef)] Context executionContext)
[WrapMember]
public static EzrObjectWrapper GetRaw(IEzrObject toGet,
[FeatureParameter(Feature.CallerRef)] IEzrObject wrapper,
[FeatureParameter(Feature.ExecutionRef)] Context executionContext)
{
return new EzrSharpCompatibilityObjectInstance(toGet, toGet.GetType(), executionContext, wrapper.StartPosition, wrapper.EndPosition);
return new EzrObjectWrapper(toGet, toGet.GetType(), executionContext, wrapper.StartPosition, wrapper.EndPosition);
}

/// <summary>
Expand All @@ -346,12 +334,11 @@ public static EzrSharpCompatibilityObjectInstance GetRaw(IEzrObject toGet,
/// ezr² return type:
/// <see cref="EzrDictionary"/>
/// </remarks>
/// <param name="arguments">The method arguments.</param>
[WrappedMember]
[WrapMember]
public static IEzrObject GetContext(IEzrObject toGet,
[Runtime(Feature.CallerRef)] IEzrObject wrapper,
[Runtime(Feature.ResultRef)] RuntimeResult result,
[Runtime(Feature.ExecutionRef)] Context executionContext)
[FeatureParameter(Feature.CallerRef)] IEzrObject wrapper,
[FeatureParameter(Feature.ResultRef)] RuntimeResult result,
[FeatureParameter(Feature.ExecutionRef)] Context executionContext)
{
RuntimeEzrObjectDictionary context = new();
foreach (KeyValuePair<string, Reference> pair in toGet.Context)
Expand Down
Loading

0 comments on commit f932e44

Please sign in to comment.