Skip to content

Commit

Permalink
Clean up for readability and consistency
Browse files Browse the repository at this point in the history
Notice we can reuse `emitReferenceExpression` to implement `emitClosureArgument`. This change not only removes redundant parts but also enables reusing the entries in `environmentFunctions`
  • Loading branch information
Viir committed Jul 20, 2023
1 parent 29a9d0b commit 5b3a0fe
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2482,26 +2482,10 @@ emitExpressionInDeclarationBlockLessClosureArgument stackBeforeAddingDeps origin

emitClosureArgument : EmitStack -> { closureCaptures : List String } -> Result String Pine.Expression
emitClosureArgument stack { closureCaptures } =
let
emitForName name =
case Dict.get name stack.environmentDeconstructions of
Nothing ->
Err
("Failed to find declaration for closure capture '"
++ name
++ "'. There are "
++ String.fromInt (Dict.size stack.environmentDeconstructions)
++ " environment deconstructions in scope: "
++ String.join ", " (Dict.keys stack.environmentDeconstructions)
)

Just _ ->
Ok (ReferenceExpression name)
in
closureCaptures
|> List.map emitForName
|> List.map (emitReferenceExpression >> (|>) stack)
|> Result.Extra.combine
|> Result.andThen (ListExpression >> emitExpression stack)
|> Result.map Pine.ListExpression


type alias ClosureFunctionEntry =
Expand Down Expand Up @@ -3302,15 +3286,15 @@ emitReferenceExpression name compilation =
case Dict.get name compilation.environmentDeconstructions of
Nothing ->
Err
("Failed getting deconstruction for '"
("Failed referencing '"
++ name
++ "'. "
++ String.fromInt (Dict.size compilation.environmentDeconstructions)
++ " deconstructions on the current stack: "
++ " deconstructions in scope: "
++ String.join ", " (Dict.keys compilation.environmentDeconstructions)
++ ". "
++ String.fromInt (List.length compilation.environmentFunctions)
++ " functions on the current stack: "
++ " functions in scope: "
++ String.join ", " (List.map .functionName compilation.environmentFunctions)
)

Expand Down
2 changes: 1 addition & 1 deletion implement/elm-time/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace ElmTime;

public class Program
{
public static string AppVersionId => "2023-07-18";
public static string AppVersionId => "2023-07-19";

private static int AdminInterfaceDefaultPort => 4000;

Expand Down
4 changes: 2 additions & 2 deletions implement/elm-time/elm-time.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<TargetFramework>net7.0</TargetFramework>
<RootNamespace>ElmTime</RootNamespace>
<AssemblyName>elm-time</AssemblyName>
<AssemblyVersion>2023.0718.0.0</AssemblyVersion>
<FileVersion>2023.0718.0.0</FileVersion>
<AssemblyVersion>2023.0719.0.0</AssemblyVersion>
<FileVersion>2023.0719.0.0</FileVersion>
<Nullable>enable</Nullable>
<GenerateEmbeddedFilesManifest>true</GenerateEmbeddedFilesManifest>
</PropertyGroup>
Expand Down

0 comments on commit 5b3a0fe

Please sign in to comment.