Skip to content

Commit

Permalink
ezr² RE v0.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Uralstech committed Sep 27, 2024
1 parent 188c69f commit 53e454f
Show file tree
Hide file tree
Showing 17 changed files with 135 additions and 177 deletions.
4 changes: 4 additions & 0 deletions Changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ CHANGELOG - What's new?
See the GitHub releases for more detailed info:
https://github.com/Uralstech/ezrSquared/releases

* ezr² RE - v0.4.0 [27-09-24]
* Text objects (strings, characters, character lists), now implement a common interface `IEzrString`.
* Runtime errors now implement a common interface `IEzrRuntimeError`.

* ezr² RE - v0.3.1 [14-08-24]
* Updated shell with new version.

Expand Down
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ More information, documentation and the reference manual for ezr² is available
## What's the 'ezrSquared-re' branch?
ezr² is being rewritten from the ground up! Expect more features, better performance and better code documentation!

## Update!
The development status of ezr² is now available on [***the ezr² project***](https://github.com/users/Uralstech/projects/3) and [***my blog***](https://uralstech.github.io/).

## Contributing
ezr² is an open source project and welcomes contributions from anyone who wants to improve it.

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.3.1</Version>
<Version>0.4.0</Version>

<Authors>Udayshankar Ravikumar</Authors>
<Company>URAV ADVANCED LEARNING SYSTEMS PRIVATE LIMITED</Company>
Expand Down
7 changes: 3 additions & 4 deletions src/Runtime/Collections/RuntimeEzrObjectDictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@ public class RuntimeEzrObjectDictionary : IMutable<RuntimeEzrObjectDictionary>
/// <summary>
/// The collection of <see cref="IEzrObject"/>s stored in the <see cref="RuntimeEzrObjectDictionary"/>, in the format Dictionary&lt;hashOfKey, KeyValuePair&lt;key, valueReference&gt;&gt;.
/// </summary>
private readonly Dictionary<int, KeyValuePair<IEzrObject, Reference>> _items;
private readonly IDictionary<int, KeyValuePair<IEzrObject, Reference>> _items;

/// <summary>
/// Creates a new <see cref="RuntimeEzrObjectDictionary"/>.
/// </summary>
public RuntimeEzrObjectDictionary()
{
_items = [];
_items = new Dictionary<int, KeyValuePair<IEzrObject, Reference>>();
}

/// <summary>
/// Creates a new <see cref="RuntimeEzrObjectDictionary"/> from an existing <see cref="Dictionary{TKey, TValue}"/>.
/// </summary>
public RuntimeEzrObjectDictionary(Dictionary<int, KeyValuePair<IEzrObject, Reference>> items)
public RuntimeEzrObjectDictionary(IDictionary<int, KeyValuePair<IEzrObject, Reference>> items)
{
_items = items;
}
Expand Down Expand Up @@ -273,7 +273,6 @@ public void Release()
}

_items.Clear();
_items.TrimExcess();
}

/// <summary>Destructor.</summary>
Expand Down
4 changes: 2 additions & 2 deletions src/Runtime/Interpreter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1069,7 +1069,7 @@ private void VisitTryNode(TryNode node, Context executionContext, Context callin
if (RuntimeResult.ShouldReturnTryCatch || RuntimeResult.Error is null)
return;

EzrRuntimeError error = RuntimeResult.Error!;
IEzrRuntimeError error = RuntimeResult.Error!;
RuntimeResult.Reset();

for (int i = 0; i < node.Cases.Count; i++)
Expand All @@ -1081,7 +1081,7 @@ private void VisitTryNode(TryNode node, Context executionContext, Context callin
return;

IEzrObject targetObject = RuntimeResult.Reference.Object;
if (targetObject is not EzrSharpSourceTypeWrapper target || !typeof(EzrRuntimeError).IsAssignableFrom(target.SharpType))
if (targetObject is not EzrSharpSourceTypeWrapper target || !typeof(IEzrRuntimeError).IsAssignableFrom(target.SharpType))
{
RuntimeResult.Failure(new EzrUnexpectedTypeError($"Expected error type, but got object of type \"{targetObject.TypeName}\"!", executionContext, errorType.StartPosition, errorType.EndPosition));
return;
Expand Down
4 changes: 2 additions & 2 deletions src/Runtime/RuntimeResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class RuntimeResult
/// <summary>
/// The error that occured in interpretation, if none occured, this is <see langword="null"/>.
/// </summary>
public EzrRuntimeError? Error;
public IEzrRuntimeError? Error;

/// <summary>
/// Should the interpreter return from the current execution?
Expand Down Expand Up @@ -164,7 +164,7 @@ public void Success(Reference reference)
/// Sets a failed expression execution.
/// </summary>
/// <param name="error">The error that caused the failure.</param>
public void Failure(EzrRuntimeError error)
public void Failure(IEzrRuntimeError error)
{
Reset();
Error = error;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,14 @@ public static void Show(SharpMethodParameters arguments)
}

/// <summary>
/// Basic error throwing function. Implements <see cref="RuntimeResult.Failure(EzrRuntimeError)"/>.
/// Basic error throwing function. Implements <see cref="RuntimeResult.Failure(IEzrRuntimeError)"/>.
/// </summary>
/// <remarks>
/// ezr² parameters:
/// <list type="table">
/// <item>
/// <term>error</term>
/// <description>(<see cref="EzrRuntimeError"/>) The error to throw.</description>
/// <description>(<see cref="IEzrRuntimeError"/>) The error to throw.</description>
/// </item>
/// </list>
///
Expand All @@ -97,7 +97,7 @@ public static void ThrowError(SharpMethodParameters arguments)
Reference reference = arguments.ArgumentReferences["error"];

IEzrObject referenceObject = reference.Object;
if (referenceObject is not EzrRuntimeError error)
if (referenceObject is not IEzrRuntimeError error)
arguments.Result.Failure(new EzrUnexpectedTypeError($"Expected runtime error, but got object of type \"{referenceObject.TypeName}\"!", arguments.ExecutionContext, referenceObject.StartPosition, referenceObject.EndPosition));
else
arguments.Result.Failure(error);
Expand Down
46 changes: 15 additions & 31 deletions src/Runtime/Types/Core/RuntimeErrors/EzrRuntimeError.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,41 +7,31 @@
namespace EzrSquared.Runtime.Types.Core.Errors;

/// <summary>
/// Base of all error type objects.
/// Implementation of <see cref="IEzrRuntimeError"/> with some utility methods.
/// </summary>
[SharpTypeWrapper("runtime_error")]
public class EzrRuntimeError : EzrObject
public class EzrRuntimeError : EzrObject, IEzrRuntimeError
{
/// <inheritdoc/>
public override string TypeName { get; protected internal set; } = "runtime error";

/// <inheritdoc/>
public override string Tag { get; protected internal set; } = "ezrSquared.RuntimeError";

/// <summary>
/// The name of the <see cref="EzrRuntimeError"/>.
/// </summary>
public readonly string Title;
/// <inheritdoc/>
public string Title { get; }

/// <summary>
/// The reason why the <see cref="EzrRuntimeError"/> occurred.
/// </summary>
public readonly string Details;
/// <inheritdoc/>
public string Details { get; }

/// <summary>
/// The context where the error occurred.
/// </summary>
public readonly Context ErrorContext;
/// <inheritdoc/>
public Context ErrorContext { get; }

/// <summary>
/// The starting position of the error.
/// </summary>
public readonly Position ErrorStartPosition;
/// <inheritdoc/>
public Position ErrorStartPosition { get; }

/// <summary>
/// The ending position of the error.
/// </summary>
public readonly Position ErrorEndPosition;
/// <inheritdoc/>
public Position ErrorEndPosition { get; }

/// <summary>
/// Creates a new runtime error object.
Expand Down Expand Up @@ -94,17 +84,11 @@ protected internal static string GetStringArgument(string argumentName, IEzrObje

switch (ezrObject)
{
case EzrString ezrString:
return ezrString.Value;

case EzrCharacter ezrCharacter:
return ezrCharacter.Value.ToString();

case EzrCharacterList ezrCharacterList:
return ezrCharacterList.StringValue;
case IEzrString ezrString:
return ezrString.StringValue;

default:
result.Failure(new EzrUnexpectedTypeError($"Expected {argumentName} of type string, character or character list, but got object of type \"{ezrObject.TypeName}\"!", context, ezrObject.StartPosition, ezrObject.EndPosition));
result.Failure(new EzrUnexpectedTypeError($"Expected {argumentName} to be text, but got object of type \"{ezrObject.TypeName}\"!", context, ezrObject.StartPosition, ezrObject.EndPosition));
return string.Empty;
}
}
Expand Down
32 changes: 32 additions & 0 deletions src/Runtime/Types/Core/RuntimeErrors/IEzrRuntimeError.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
namespace EzrSquared.Runtime.Types.Core.Errors;

/// <summary>
/// Base of all error types.
/// </summary>
public interface IEzrRuntimeError : IEzrObject
{
/// <summary>
/// The title of the error.
/// </summary>
public string Title { get; }

/// <summary>
/// The reason why the error occurred.
/// </summary>
public string Details { get; }

/// <summary>
/// The context where the error occurred.
/// </summary>
public Context ErrorContext { get; }

/// <summary>
/// The starting position of the error.
/// </summary>
public Position ErrorStartPosition { get; }

/// <summary>
/// The ending position of the error.
/// </summary>
public Position ErrorEndPosition { get; }
}
41 changes: 16 additions & 25 deletions src/Runtime/Types/Core/Text/EzrCharacter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace EzrSquared.Runtime.Types.Core.Text;
/// <param name="parentContext">The parent context.</param>
/// <param name="startPosition">The starting position of the object.</param>
/// <param name="endPosition">The ending position of the object.</param>
public class EzrCharacter(char value, Context parentContext, Position startPosition, Position endPosition) : EzrObject(parentContext, startPosition, endPosition)
public class EzrCharacter(char value, Context parentContext, Position startPosition, Position endPosition) : EzrObject(parentContext, startPosition, endPosition), IEzrString
{
/// <inheritdoc/>
public override string TypeName { get; protected internal set; } = "character";
Expand All @@ -26,6 +26,9 @@ public class EzrCharacter(char value, Context parentContext, Position startPosit
/// </summary>
public readonly char Value = value;

/// <inheritdoc/>
public string StringValue => Value.ToString();

/// <inheritdoc/>
public override void ComparisonEqual(IEzrObject other, RuntimeResult result)
{
Expand All @@ -37,10 +40,8 @@ public override void ComparisonEqual(IEzrObject other, RuntimeResult result)
result.Success(NewBooleanConstant(Value == otherInteger.Value)); break;
case EzrFloat otherFloat:
result.Success(NewBooleanConstant(Value == otherFloat.Value)); break;
case EzrString otherString:
result.Success(NewBooleanConstant(Value.ToString() == otherString.Value)); break;
case EzrCharacterList otherCharacterList:
result.Success(NewBooleanConstant(Value.ToString() == otherCharacterList.StringValue)); break;
case IEzrString otherString:
result.Success(NewBooleanConstant(StringValue == otherString.StringValue)); break;
default:
result.Success(NewBooleanConstant(false)); break;
}
Expand All @@ -57,10 +58,8 @@ public override void ComparisonNotEqual(IEzrObject other, RuntimeResult result)
result.Success(NewBooleanConstant(Value != otherInteger.Value)); break;
case EzrFloat otherFloat:
result.Success(NewBooleanConstant(Value != otherFloat.Value)); break;
case EzrString otherString:
result.Success(NewBooleanConstant(Value.ToString() != otherString.Value)); break;
case EzrCharacterList otherCharacterList:
result.Success(NewBooleanConstant(Value.ToString() != otherCharacterList.StringValue)); break;
case IEzrString otherString:
result.Success(NewBooleanConstant(StringValue != otherString.StringValue)); break;
default:
result.Success(NewBooleanConstant(true)); break;
}
Expand All @@ -77,10 +76,8 @@ public override void ComparisonLessThan(IEzrObject other, RuntimeResult result)
result.Success(NewBooleanConstant(Value < otherInteger.Value)); break;
case EzrFloat otherFloat:
result.Success(NewBooleanConstant(Value < otherFloat.Value)); break;
case EzrString otherString:
result.Success(NewBooleanConstant(Value.CompareTo(otherString.Value) < 0)); break;
case EzrCharacterList otherCharacterList:
result.Success(NewBooleanConstant(Value.CompareTo(otherCharacterList.StringValue) < 0)); break;
case IEzrString otherString:
result.Success(NewBooleanConstant(Value.CompareTo(otherString.StringValue) < 0)); break;
default:
result.Failure(IllegalOperation(other)); break;
}
Expand All @@ -97,10 +94,8 @@ public override void ComparisonGreaterThan(IEzrObject other, RuntimeResult resul
result.Success(NewBooleanConstant(Value > otherInteger.Value)); break;
case EzrFloat otherFloat:
result.Success(NewBooleanConstant(Value > otherFloat.Value)); break;
case EzrString otherString:
result.Success(NewBooleanConstant(Value.CompareTo(otherString.Value) > 0)); break;
case EzrCharacterList otherCharacterList:
result.Success(NewBooleanConstant(Value.CompareTo(otherCharacterList.StringValue) > 0)); break;
case IEzrString otherString:
result.Success(NewBooleanConstant(Value.CompareTo(otherString.StringValue) > 0)); break;
default:
result.Failure(IllegalOperation(other)); break;
}
Expand All @@ -117,10 +112,8 @@ public override void ComparisonLessThanOrEqual(IEzrObject other, RuntimeResult r
result.Success(NewBooleanConstant(Value <= otherInteger.Value)); break;
case EzrFloat otherFloat:
result.Success(NewBooleanConstant(Value <= otherFloat.Value)); break;
case EzrString otherString:
result.Success(NewBooleanConstant(Value.CompareTo(otherString.Value) <= 0)); break;
case EzrCharacterList otherCharacterList:
result.Success(NewBooleanConstant(Value.CompareTo(otherCharacterList.StringValue) <= 0)); break;
case IEzrString otherString:
result.Success(NewBooleanConstant(Value.CompareTo(otherString.StringValue) <= 0)); break;
default:
result.Failure(IllegalOperation(other)); break;
}
Expand All @@ -137,10 +130,8 @@ public override void ComparisonGreaterThanOrEqual(IEzrObject other, RuntimeResul
result.Success(NewBooleanConstant(Value >= otherInteger.Value)); break;
case EzrFloat otherFloat:
result.Success(NewBooleanConstant(Value >= otherFloat.Value)); break;
case EzrString otherString:
result.Success(NewBooleanConstant(Value.CompareTo(otherString.Value) >= 0)); break;
case EzrCharacterList otherCharacterList:
result.Success(NewBooleanConstant(Value.CompareTo(otherCharacterList.StringValue) >= 0)); break;
case IEzrString otherString:
result.Success(NewBooleanConstant(Value.CompareTo(otherString.StringValue) >= 0)); break;
default:
result.Failure(IllegalOperation(other)); break;
}
Expand Down
Loading

0 comments on commit 53e454f

Please sign in to comment.