Skip to content

Commit

Permalink
Expand automated test compiling Elm compiler
Browse files Browse the repository at this point in the history
Add steps for compiling increasingly expansive Elm modules and check if the results when compiling these equal the results from the JavaScript-based compilation route.
  • Loading branch information
Viir committed May 18, 2024
1 parent 6c1bde4 commit 1880a32
Show file tree
Hide file tree
Showing 3 changed files with 524 additions and 98 deletions.
60 changes: 34 additions & 26 deletions implement/pine/ElmInteractive/ElmInteractiveEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace ElmTime.ElmInteractive;
public static class ElmInteractiveEnvironment
{
public record ParsedInteractiveEnvironment(
IReadOnlyList<(string moduleName, ElmModule moduleContent)> Modules);
IReadOnlyList<(string moduleName, PineValue moduleValue, ElmModule moduleContent)> Modules);

public static Result<string, PineValue> ApplyFunctionInElmModule(
PineVM pineVM,
Expand All @@ -25,8 +25,7 @@ public static Result<string, PineValue> ApplyFunctionInElmModule(
ParseFunctionFromElmModule(
interactiveEnvironment: interactiveEnvironment,
moduleName: moduleName,
declarationName: declarationName,
pineVM: pineVM)
declarationName: declarationName)
.AndThen(functionRecord =>
{
var combinedArguments =
Expand Down Expand Up @@ -57,8 +56,7 @@ public static Result<string, PineValue> ApplyFunctionInElmModule(
public static Result<string, FunctionRecord> ParseFunctionFromElmModule(
PineValue interactiveEnvironment,
string moduleName,
string declarationName,
PineVM? pineVM = null)
string declarationName)
{
return
ParseInteractiveEnvironment(interactiveEnvironment)
Expand All @@ -78,29 +76,12 @@ public static Result<string, FunctionRecord> ParseFunctionFromElmModule(
if (functionDeclaration.Value is null)
return (Result<string, FunctionRecord>)"declaration " + declarationName + " not found";
return
ParseTagged(functionDeclaration.Value)
.AndThen(taggedFunctionDeclaration =>
taggedFunctionDeclaration.name is "Function"
?
ParseFunctionRecordFromValue(taggedFunctionDeclaration.value, pineVM)
:
/*
(Result<string, FunctionRecord>)"Unexpected tag: " + taggedFunctionDeclaration.name
If the declaration has zero parameters, it could be encoded as plain PineValue without wrapping in a 'Function' record.
*/
new FunctionRecord(
innerFunction: new Expression.LiteralExpression(functionDeclaration.Value),
functionParameterCount: 0,
envFunctions: [],
argumentsAlreadyCollected: [])
);
return ParseFunctionRecordFromValueTagged(functionDeclaration.Value);
});
}

public static Result<string, PineValue> ApplyFunction(
PineVM pineVM,
IPineVM pineVM,
FunctionRecord functionRecord,
IReadOnlyList<PineValue> arguments)
{
Expand Down Expand Up @@ -137,6 +118,33 @@ public record FunctionRecord(
IReadOnlyList<PineValue> envFunctions,
IReadOnlyList<PineValue> argumentsAlreadyCollected);

/// <summary>
/// Analog to 'parseFunctionRecordFromValueTagged' in the Elm compiler.
/// </summary>
public static Result<string, FunctionRecord> ParseFunctionRecordFromValueTagged(
PineValue pineValue,
PineVM? pineVM = null)
{
return
ParseTagged(pineValue)
.AndThen(taggedFunctionDeclaration =>
taggedFunctionDeclaration.name is "Function"
?
ParseFunctionRecordFromValue(taggedFunctionDeclaration.value, pineVM)
:
/*
(Result<string, FunctionRecord>)"Unexpected tag: " + taggedFunctionDeclaration.name
If the declaration has zero parameters, it could be encoded as plain PineValue without wrapping in a 'Function' record.
*/
new FunctionRecord(
innerFunction: new Expression.LiteralExpression(pineValue),
functionParameterCount: 0,
envFunctions: [],
argumentsAlreadyCollected: [])
);
}

/// <summary>
/// Analog to 'parseFunctionRecordFromValue' in the Elm compiler.
/// </summary>
Expand Down Expand Up @@ -216,7 +224,7 @@ public static Result<string, ParsedInteractiveEnvironment> ParseInteractiveEnvir
};
}

public static Result<string, (string moduleName, ElmModule moduleContent)> ParseNamedElmModule(
public static Result<string, (string moduleName, PineValue moduleValue, ElmModule moduleContent)> ParseNamedElmModule(
PineValue moduleValue) =>
ParseTagged(moduleValue)
.AndThen(tagged =>
Expand All @@ -225,7 +233,7 @@ public static Result<string, ParsedInteractiveEnvironment> ParseInteractiveEnvir
return
ParseElmModule(tagged.value)
.Map(module => (moduleName, module));
.Map(module => (moduleName, tagged.value, module));
});

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion implement/pine/ElmInteractive/InteractiveSessionPine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ private InteractiveSessionPine(
appCodeTree: appCodeTree));
}

private static (IPineVM, PineVMCache?) BuildPineVM(
public static (IPineVM, PineVMCache?) BuildPineVM(
bool caching,
DynamicPGOShare? autoPGO)
{
Expand Down
Loading

0 comments on commit 1880a32

Please sign in to comment.