Skip to content

Commit

Permalink
(tests) Implement more EvalHelper methods for compiled mode (#463)
Browse files Browse the repository at this point in the history
This is a preparation for removing interpreted mode completely, expected
to follow shortly.
  • Loading branch information
perlun authored Apr 23, 2024
1 parent 142ccf3 commit 783c5df
Show file tree
Hide file tree
Showing 12 changed files with 434 additions and 130 deletions.
2 changes: 2 additions & 0 deletions release-notes/v0.5.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

### Tests
- Add `AsciiString_indexed_outside_string` test [[#449][449]]
- Implement more `EvalHelper` methods for compiled mode [[#463][463]]

[446]: https://github.com/perlang-org/perlang/pull/446
[447]: https://github.com/perlang-org/perlang/pull/447
Expand All @@ -46,4 +47,5 @@
[458]: https://github.com/perlang-org/perlang/pull/458
[459]: https://github.com/perlang-org/perlang/pull/459
[462]: https://github.com/perlang-org/perlang/pull/462
[463]: https://github.com/perlang-org/perlang/pull/463
[464]: https://github.com/perlang-org/perlang/pull/464
7 changes: 7 additions & 0 deletions src/Perlang.Interpreter/Compiler/PerlangCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,13 @@ private void RegisterGlobalClasses()
// Enable warnings on e.g. narrowing conversion from `long long` to `unsigned long long`.
"-Wconversion",

// This could be added, but the problem is that division by zero has undefined behavior in C++. :/ I
// think the long-term goal for Perlang in this regard is to use proper hardware exceptions for this
// (which is natively supported on x86 and amd64, at least), and propagate it as a Perlang exception.
// For platforms without hardware support, we might have to emulate this in software for a coherent
// dev experience. For now, let Clang warn about it when dividing with a zero constant.
//"-Wno-division-by-zero",

// ...but do not warn on implicit conversion from `int` to `float` or `double`. For now, we are
// aiming at mimicking the C# semantics in this.
"-Wno-implicit-int-float-conversion",
Expand Down
22 changes: 16 additions & 6 deletions src/Perlang.Tests.Integration/Assignment/AssignmentTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using System;
using System.Linq;
using FluentAssertions;
using Perlang.Compiler;
using Xunit;
using static Perlang.Tests.Integration.EvalHelper;

Expand Down Expand Up @@ -37,8 +40,7 @@ public void assignment_is_right_associative()
}, output);
}

// TODO: This is a bug; create a GitHub issue for it so we can look into it at some point.
[Fact(Skip = "Gives a TypeValidationError: Internal compiler error: var c initializer a = var inference has not been attempted")]
[Fact]
public void assignment_on_right_hand_side_of_variable_is_right_associative()
{
string source = @"
Expand Down Expand Up @@ -182,11 +184,19 @@ public void undefined_variable_cannot_be_reassigned()
unknown = ""what"";
";

var result = EvalWithRuntimeErrorCatch(source);
var exception = result.Errors.First();
if (PerlangMode.ExperimentalCompilation) {
Action action = () => EvalReturningOutput(source);

Assert.Single(result.Errors);
Assert.Matches("Undefined variable 'unknown'.", exception.Message);
action.Should().Throw<PerlangCompilerException>()
.WithMessage("*use of undeclared identifier 'unknown'*");
}
else {
var result = EvalWithRuntimeErrorCatch(source);
var exception = result.Errors.First();

Assert.Single(result.Errors);
Assert.Matches("Undefined variable 'unknown'.", exception.Message);
}
}
}
}
Loading

0 comments on commit 783c5df

Please sign in to comment.