Skip to content

Commit

Permalink
[Rust] Refactor union case handling
Browse files Browse the repository at this point in the history
  • Loading branch information
ncave committed Oct 20, 2024
1 parent 8ae48e9 commit 37fa7b2
Show file tree
Hide file tree
Showing 3 changed files with 208 additions and 187 deletions.
10 changes: 5 additions & 5 deletions src/Fable.Transforms/Dart/Fable2Dart.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1590,7 +1590,7 @@ module Util =
else
failwith "Target idents/values lengths differ"

let getDecisionTargetAndBindValues (com: IDartCompiler) (ctx: Context) targetIndex boundValues =
let getDecisionTargetAndBoundValues (com: IDartCompiler) (ctx: Context) targetIndex boundValues =
let idents, target = getDecisionTarget ctx targetIndex
let identsAndValues = matchTargetIdentAndValues idents boundValues

Expand All @@ -1605,9 +1605,9 @@ module Util =
)

let target = FableTransforms.replaceValues replacements target
List.rev bindings, target
target, List.rev bindings
else
identsAndValues, target
target, identsAndValues

let transformDecisionTreeSuccess (com: IDartCompiler) (ctx: Context) returnStrategy targetIndex boundValues =
match returnStrategy with
Expand All @@ -1627,8 +1627,8 @@ module Util =

targetAssignment :: assignments, None
| ret ->
let bindings, target =
getDecisionTargetAndBindValues com ctx targetIndex boundValues
let target, bindings =
getDecisionTargetAndBoundValues com ctx targetIndex boundValues

let ctx, bindings =
((ctx, []), bindings)
Expand Down
15 changes: 7 additions & 8 deletions src/Fable.Transforms/Python/Fable2Python.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2590,9 +2590,8 @@ module Util =
else
failwith "Target idents/values lengths differ"

let getDecisionTargetAndBindValues (com: IPythonCompiler) (ctx: Context) targetIndex boundValues =
let getDecisionTargetAndBoundValues (com: IPythonCompiler) (ctx: Context) targetIndex boundValues =
let idents, target = getDecisionTarget ctx targetIndex

let identsAndValues = matchTargetIdentAndValues idents boundValues

if not com.Options.DebugMode then
Expand All @@ -2606,13 +2605,13 @@ module Util =
)

let target = FableTransforms.replaceValues replacements target
List.rev bindings, target
target, List.rev bindings
else
identsAndValues, target
target, identsAndValues

let transformDecisionTreeSuccessAsExpr (com: IPythonCompiler) (ctx: Context) targetIndex boundValues =
let bindings, target =
getDecisionTargetAndBindValues com ctx targetIndex boundValues
let target, bindings =
getDecisionTargetAndBoundValues com ctx targetIndex boundValues

match bindings with
| [] -> com.TransformAsExpr(ctx, target)
Expand Down Expand Up @@ -2667,8 +2666,8 @@ module Util =

targetAssignment @ assignments
| ret ->
let bindings, target =
getDecisionTargetAndBindValues com ctx targetIndex boundValues
let target, bindings =
getDecisionTargetAndBoundValues com ctx targetIndex boundValues

let bindings =
bindings
Expand Down
Loading

0 comments on commit 37fa7b2

Please sign in to comment.