Skip to content

Commit

Permalink
WIP: Fix issue with printing nullptr
Browse files Browse the repository at this point in the history
  • Loading branch information
perlun committed Oct 3, 2023
1 parent 8f79943 commit 8d424b4
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/Perlang.Interpreter/Compiler/PerlangCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ private void RegisterGlobalClasses()

if (process.ExitCode != 0)
{
runtimeErrorHandler(new RuntimeError(null, $"Process exited with exit code {process.ExitCode}"));
runtimeErrorHandler(new RuntimeError(null, $"Process {executablePath} exited with exit code {process.ExitCode}"));
}

return executablePath;
Expand Down
12 changes: 12 additions & 0 deletions src/Perlang.Tests.Integration/EvalException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#nullable enable
using System;

namespace Perlang.Tests.Integration;

public class EvalException : Exception
{
public EvalException(string message, Exception innerException)
: base(message, innerException)
{
}
}
13 changes: 9 additions & 4 deletions src/Perlang.Tests.Integration/EvalHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,11 @@ internal static EvalResult<Exception> EvalWithResult(string source, params strin
// is known to not yet work.
throw new SkipException(e.Message);
}
catch (EvalException e)

Check warning on line 270 in src/Perlang.Tests.Integration/EvalHelper.cs

View workflow job for this annotation

GitHub Actions / publish-snapshot-packages (linux-arm)

The variable 'e' is declared but never used

Check warning on line 270 in src/Perlang.Tests.Integration/EvalHelper.cs

View workflow job for this annotation

GitHub Actions / publish-snapshot-packages (linux-arm)

The variable 'e' is declared but never used

Check warning on line 270 in src/Perlang.Tests.Integration/EvalHelper.cs

View workflow job for this annotation

GitHub Actions / publish-snapshot-packages (linux-arm64)

The variable 'e' is declared but never used

Check warning on line 270 in src/Perlang.Tests.Integration/EvalHelper.cs

View workflow job for this annotation

GitHub Actions / publish-snapshot-packages (linux-arm64)

The variable 'e' is declared but never used

Check warning on line 270 in src/Perlang.Tests.Integration/EvalHelper.cs

View workflow job for this annotation

GitHub Actions / publish-snapshot-packages (linux-x64)

The variable 'e' is declared but never used

Check warning on line 270 in src/Perlang.Tests.Integration/EvalHelper.cs

View workflow job for this annotation

GitHub Actions / publish-snapshot-packages (linux-x64)

The variable 'e' is declared but never used

Check warning on line 270 in src/Perlang.Tests.Integration/EvalHelper.cs

View workflow job for this annotation

GitHub Actions / publish-snapshot-packages (osx-arm64)

The variable 'e' is declared but never used

Check warning on line 270 in src/Perlang.Tests.Integration/EvalHelper.cs

View workflow job for this annotation

GitHub Actions / publish-snapshot-packages (osx-arm64)

The variable 'e' is declared but never used

Check warning on line 270 in src/Perlang.Tests.Integration/EvalHelper.cs

View workflow job for this annotation

GitHub Actions / publish-snapshot-packages (osx-x64)

The variable 'e' is declared but never used

Check warning on line 270 in src/Perlang.Tests.Integration/EvalHelper.cs

View workflow job for this annotation

GitHub Actions / publish-snapshot-packages (osx-x64)

The variable 'e' is declared but never used

Check warning on line 270 in src/Perlang.Tests.Integration/EvalHelper.cs

View workflow job for this annotation

GitHub Actions / publish-snapshot-packages (win-x64)

The variable 'e' is declared but never used

Check warning on line 270 in src/Perlang.Tests.Integration/EvalHelper.cs

View workflow job for this annotation

GitHub Actions / publish-snapshot-packages (win-x64)

The variable 'e' is declared but never used
{
// For now, re-throw this as-is.
throw;
}

// Return something else than `null` to make it reasonable for callers to distinguish that compiled mode
// (with no native "result") is being used, if needed.
Expand Down Expand Up @@ -379,22 +384,22 @@ private static void AssertFailParseErrorHandler(ParseError parseError)

private static void AssertFailNameResolutionErrorHandler(NameResolutionError nameResolutionError)
{
throw new Exception($"NameResolutionError occurred: {nameResolutionError.Message}", nameResolutionError);
throw new EvalException($"NameResolutionError occurred: {nameResolutionError.Message}", nameResolutionError);
}

private static void AssertFailRuntimeErrorHandler(RuntimeError runtimeError)
{
throw new Exception($"RuntimeError occurred: {runtimeError.Message}", runtimeError);
throw new EvalException($"RuntimeError occurred: {runtimeError.Message}", runtimeError);
}

private static void AssertFailValidationErrorHandler(ValidationError validationError)
{
throw new Exception($"ValidationError occurred: {validationError.Message}", validationError);
throw new EvalException($"ValidationError occurred: {validationError.Message}", validationError);
}

private static bool AssertFailCompilerWarningHandler(CompilerWarning compilerWarning)
{
throw new Exception($"CompilerWarning occurred: {compilerWarning.Message}", compilerWarning);
throw new EvalException($"CompilerWarning occurred: {compilerWarning.Message}", compilerWarning);
}
}
}
11 changes: 8 additions & 3 deletions src/stdlib/src/print.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,14 @@ namespace perlang
{
void print(const char* str)
{
// For plain strings, there's no need to use the overhead which `printf` induces. `puts` can potentially be a
// tiny bit faster.
puts(str);
if (str == nullptr) {
puts("null");
}
else {
// For plain strings, there's no need to use the overhead which `printf` induces. `puts` can potentially be a
// tiny bit faster.
puts(str);
}
}

void print(bool b)
Expand Down

0 comments on commit 8d424b4

Please sign in to comment.