Skip to content

Commit

Permalink
Reduce usage of records for more efficiency in the Elm compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
Viir committed Jul 6, 2024
1 parent 7987a15 commit e08d6da
Show file tree
Hide file tree
Showing 11 changed files with 626 additions and 682 deletions.
337 changes: 157 additions & 180 deletions implement/pine/ElmTime/compile-elm-program/src/ElmCompiler.elm

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ generateTemplateEvaluatingToExpression expression =
"Literal"
(Pine.LiteralExpression literal)

Pine.ParseAndEvalExpression parseAndEval ->
Pine.ParseAndEvalExpression envExpr exprExpr ->
buildFromTagAndArgument
"ParseAndEval"
(buildRecordExpression
[ ( "environment", generateTemplateEvaluatingToExpression parseAndEval.environment )
, ( "expression", generateTemplateEvaluatingToExpression parseAndEval.expression )
[ ( "environment", generateTemplateEvaluatingToExpression envExpr )
, ( "expression", generateTemplateEvaluatingToExpression exprExpr )
]
)

Expand All @@ -58,18 +58,18 @@ generateTemplateEvaluatingToExpression expression =
]
)

Pine.ConditionalExpression conditional ->
Pine.ConditionalExpression condition ifFalse ifTrue ->
buildFromTagAndArgument
"Conditional"
(buildRecordExpression
[ ( "condition"
, generateTemplateEvaluatingToExpression conditional.condition
, generateTemplateEvaluatingToExpression condition
)
, ( "ifFalse"
, generateTemplateEvaluatingToExpression conditional.ifFalse
, generateTemplateEvaluatingToExpression ifFalse
)
, ( "ifTrue"
, generateTemplateEvaluatingToExpression conditional.ifTrue
, generateTemplateEvaluatingToExpression ifTrue
)
]
)
Expand Down Expand Up @@ -97,7 +97,7 @@ buildPineExpressionSyntax config expression =
Nothing

else if FirCompiler.pineExpressionIsIndependent expression then
case Pine.evaluateExpression Pine.emptyEvalContext expression of
case Pine.evaluateExpression Pine.emptyEvalEnvironment expression of
Err _ ->
Nothing

Expand Down Expand Up @@ -232,16 +232,16 @@ buildPineExpressionSyntax config expression =
"Pine.ListExpression"
[ String.join "\n" listSyntax ]

Pine.ParseAndEvalExpression parseAndEval ->
Pine.ParseAndEvalExpression envExpr exprExpr ->
buildFromTagNameAndArguments
"Pine.ParseAndEvalExpression"
[ buildRecordSyntax
[ ( "environment"
, buildPineExpressionSyntax config parseAndEval.environment
, buildPineExpressionSyntax config envExpr
|> String.join "\n"
)
, ( "expression"
, buildPineExpressionSyntax config parseAndEval.expression
, buildPineExpressionSyntax config exprExpr
|> String.join "\n"
)
]
Expand All @@ -263,20 +263,20 @@ buildPineExpressionSyntax config expression =
|> String.join "\n"
]

Pine.ConditionalExpression conditional ->
Pine.ConditionalExpression condition ifFalse ifTrue ->
buildFromTagNameAndArguments
"Pine.ConditionalExpression"
[ buildRecordSyntax
[ ( "condition"
, buildPineExpressionSyntax config conditional.condition
, buildPineExpressionSyntax config condition
|> String.join "\n"
)
, ( "ifFalse"
, buildPineExpressionSyntax config conditional.ifFalse
, buildPineExpressionSyntax config ifFalse
|> String.join "\n"
)
, ( "ifTrue"
, buildPineExpressionSyntax config conditional.ifTrue
, buildPineExpressionSyntax config ifTrue
|> String.join "\n"
)
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import Pine
import Result.Extra


compileEvalContextForElmInteractive : InteractiveContext -> Result String Pine.EvalContext
compileEvalContextForElmInteractive : InteractiveContext -> Result String Pine.EvalEnvironment
compileEvalContextForElmInteractive context =
let
contextModulesTextsBatches : List (List String)
Expand Down Expand Up @@ -70,8 +70,8 @@ compileEvalContextForElmInteractive context =
)
)
)
(Ok Pine.emptyEvalContext.environment)
|> Result.map (\environmentValue -> { environment = environmentValue })
(Ok (Pine.ListValue []))
|> Result.map Pine.EvalEnvironment


expandElmInteractiveEnvironmentWithModuleTexts :
Expand Down Expand Up @@ -105,7 +105,7 @@ submissionInInteractive context previousSubmissions submission =
submissionWithHistoryInInteractive initialContext previousSubmissions submission


submissionWithHistoryInInteractive : Pine.EvalContext -> List String -> String -> Result String SubmissionResponse
submissionWithHistoryInInteractive : Pine.EvalEnvironment -> List String -> String -> Result String SubmissionResponse
submissionWithHistoryInInteractive initialContext previousSubmissions submission =
case previousSubmissions of
[] ->
Expand All @@ -121,12 +121,12 @@ submissionWithHistoryInInteractive initialContext previousSubmissions submission
submissionWithHistoryInInteractive expressionContext remainingPreviousSubmissions submission


submissionInInteractiveInPineContext : Pine.EvalContext -> String -> Result String ( Pine.EvalContext, SubmissionResponse )
submissionInInteractiveInPineContext expressionContext submission =
compileInteractiveSubmission expressionContext.environment submission
submissionInInteractiveInPineContext : Pine.EvalEnvironment -> String -> Result String ( Pine.EvalEnvironment, SubmissionResponse )
submissionInInteractiveInPineContext (Pine.EvalEnvironment envValue) submission =
compileInteractiveSubmission envValue submission
|> Result.andThen
(\pineExpression ->
case Pine.evaluateExpression expressionContext pineExpression of
case Pine.evaluateExpression (Pine.EvalEnvironment envValue) pineExpression of
Err error ->
Err ("Failed to evaluate expression:\n" ++ Pine.displayStringFromPineError error)

Expand All @@ -135,7 +135,7 @@ submissionInInteractiveInPineContext expressionContext submission =

Ok (Pine.ListValue [ newState, responseValue ]) ->
submissionResponseFromResponsePineValue responseValue
|> Result.map (Tuple.pair { environment = newState })
|> Result.map (Tuple.pair (Pine.EvalEnvironment newState))

Ok (Pine.ListValue resultList) ->
Err
Expand Down
Loading

0 comments on commit e08d6da

Please sign in to comment.