Skip to content

Commit

Permalink
Clean up and document declaration block expression case in Fir language
Browse files Browse the repository at this point in the history
  • Loading branch information
Viir committed Dec 25, 2023
1 parent 7643c7f commit c2905b9
Show file tree
Hide file tree
Showing 4 changed files with 167 additions and 193 deletions.
20 changes: 7 additions & 13 deletions implement/elm-time/ElmTime/compile-elm-program/src/ElmCompiler.elm
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import FirCompiler
, ElmModuleInCompilation
, EmitStack
, Expression(..)
, LetBlockStruct
, ModuleImports
, countListElementsExpression
, emitExpressionInDeclarationBlock
Expand Down Expand Up @@ -775,7 +774,6 @@ compileElmSyntaxExpression stack elmExpression =

Elm.Syntax.Expression.LetExpression letBlock ->
compileElmSyntaxLetBlock stack letBlock
|> Result.map LetBlockExpression

Elm.Syntax.Expression.ParenthesizedExpression parenthesizedExpression ->
compileElmSyntaxExpression stack (Elm.Syntax.Node.value parenthesizedExpression)
Expand Down Expand Up @@ -885,7 +883,7 @@ compileElmSyntaxApplication stack appliedFunctionElmSyntax argumentsElmSyntax =
compileElmSyntaxLetBlock :
CompilationStack
-> Elm.Syntax.Expression.LetBlock
-> Result String LetBlockStruct
-> Result String Expression
compileElmSyntaxLetBlock stackBefore letBlock =
letBlock.declarations
|> List.concatMap
Expand Down Expand Up @@ -937,11 +935,7 @@ compileElmSyntaxLetBlock stackBefore letBlock =
Ok letEntries ->
compileElmSyntaxExpression stack (Elm.Syntax.Node.value letBlock.expression)
|> Result.map
(\expression ->
{ declarations = List.concat letEntries
, expression = expression
}
)
(DeclarationBlockExpression (Dict.fromList (List.concat letEntries)))
)


Expand Down Expand Up @@ -1174,14 +1168,15 @@ compileElmSyntaxCaseBlockCase stackBefore caseBlockValueExpression ( elmPatternN
>> (|>) caseBlockValueExpression
)
)
|> Dict.fromList

stack =
{ stackBefore
| availableDeclarations =
stackBefore.availableDeclarations
|> Dict.union
(Dict.map (always DeconstructionDeclaration)
(Dict.fromList deconstructionDeclarations)
deconstructionDeclarations
)
}
in
Expand All @@ -1196,10 +1191,9 @@ compileElmSyntaxCaseBlockCase stackBefore caseBlockValueExpression ( elmPatternN
expression

else
LetBlockExpression
{ declarations = deconstructionDeclarations
, expression = expression
}
DeclarationBlockExpression
deconstructionDeclarations
expression
}
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -634,15 +634,12 @@ transformExpressionWithOptionalReplacement findReplacement expression =
mappedFunctionExpression
mappedArguments

LetBlockExpression letBlock ->
LetBlockExpression
{ letBlock
| declarations =
letBlock.declarations
|> List.map (Tuple.mapSecond (transformExpressionWithOptionalReplacement findReplacement))
, expression =
transformExpressionWithOptionalReplacement findReplacement letBlock.expression
}
DeclarationBlockExpression declarations innerExpression ->
DeclarationBlockExpression
(declarations
|> Dict.map (always (transformExpressionWithOptionalReplacement findReplacement))
)
(transformExpressionWithOptionalReplacement findReplacement innerExpression)

StringTagExpression tag tagged ->
StringTagExpression tag (transformExpressionWithOptionalReplacement findReplacement tagged)
Expand Down Expand Up @@ -1090,8 +1087,8 @@ expressionAsJson expression =
)
]

LetBlockExpression _ ->
[ ( "LetBlock"
DeclarationBlockExpression _ _ ->
[ ( "DeclarationBlock"
, []
|> Json.Encode.object
)
Expand Down
Loading

0 comments on commit c2905b9

Please sign in to comment.