Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(interpreter) Remove unused methods #491

Merged
merged 1 commit into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions release-notes/v0.5.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
- Minor stdlib cleanups [[#476][476]]

#### Maintenance
- Remove unused methods [[#491][491]]

### Fixed

Expand Down Expand Up @@ -81,3 +82,4 @@
[482]: https://github.com/perlang-org/perlang/pull/482
[486]: https://github.com/perlang-org/perlang/pull/486
[488]: https://github.com/perlang-org/perlang/pull/488
[491]: https://github.com/perlang-org/perlang/pull/491
94 changes: 0 additions & 94 deletions src/Perlang.Interpreter/Typing/TypeResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -786,100 +786,6 @@ public override VoidObject VisitVarStmt(Stmt.Var stmt)
return VoidObject.Void;
}

private static ITypeReference? GreaterType(ITypeReference leftTypeReference, ITypeReference rightTypeReference)
{
// TODO: Return the number of bits here or something instead. Also, think about whether we need to special-case
// TODO: signed and unsigned integers.
var leftMaxValue = GetApproximateMaxValue(leftTypeReference.ClrType);
var rightMaxValue = GetApproximateMaxValue(rightTypeReference.ClrType);

if (leftMaxValue == null || rightMaxValue == null)
{
return null;
}

if (leftMaxValue > rightMaxValue)
{
return leftTypeReference;
}
else
{
return rightTypeReference;
}
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused since de3ff2e.


/// <summary>
/// Returns the approximate max value for the given type.
///
/// The "approximate" part is important to understand how to properly use this method. Do _not_ use it in
/// case you need an exact value. It is only suited for "size comparisons", to determine which one of two
/// values that uses the "larger" type. For example, Double is larger than Single; Double is also larger
/// than Decimal (even though the latter has a higher level of precision). Because of this, an example of
/// types for which this method will return an approximate, inexact return value is Decimal.
/// </summary>
/// <param name="type">A Type.</param>
/// <returns>The approximate max value for the given type.</returns>
/// <exception cref="ArgumentOutOfRangeException">The given type is not supported by this method.</exception>
private static double? GetApproximateMaxValue(Type? type)
{
var typeCode = Type.GetTypeCode(type);

switch (typeCode)
{
case TypeCode.Empty:
case TypeCode.DBNull:
case TypeCode.Char:
case TypeCode.Boolean:
case TypeCode.DateTime:
case TypeCode.String:
// The types above are unsuitable for arithmetic operations. We might at some point consider
// relaxing this and supporting Ruby-like things, like '*' * 10 to produce '**********'.
// However, after having used Ruby for a long time, our conclusion is that such constructs are
// rarely used and even though they add a bit of elegance/syntactic sugar to the expressiveness
// of the language, the cost in terms of added complexity might not be worth it.
return null;

case TypeCode.Object:
if (type == typeof(BigInteger))
{
// Note: this is insanely wrong. It means that Double, Decimal and BigInteger are currently
// treated as "same size". The end result is that expressions like `5.0 ** 31` will return a
// `double`, not a `BigInteger`. `10.0 ** 309` will return positive infinity, where `10 ** 309`
// will return a large number. I'm not even sure what the "proper" semantics here would be
// actually.
return Convert.ToDouble(Decimal.MaxValue);
}

return null;

case TypeCode.SByte:
return SByte.MaxValue;
case TypeCode.Byte:
return Byte.MaxValue;
case TypeCode.Int16:
return Int16.MaxValue;
case TypeCode.UInt16:
return UInt16.MaxValue;
case TypeCode.Int32:
return Int32.MaxValue;
case TypeCode.UInt32:
return UInt32.MaxValue;
case TypeCode.Int64:
return Int64.MaxValue;
case TypeCode.UInt64:
return UInt64.MaxValue;
case TypeCode.Single:
return Single.MaxValue;
case TypeCode.Double:
return Double.MaxValue;
case TypeCode.Decimal:
// Note: this will likely loose some precision.
return Convert.ToDouble(Decimal.MaxValue);
default:
throw new ArgumentException($"{typeCode} is not supported");
}
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused since 3dda89d.


private static void ResolveExplicitTypes(ITypeReference typeReference)
{
if (typeReference.TypeSpecifier == null)
Expand Down
Loading