Skip to content

Commit

Permalink
remove Debug.todos #12
Browse files Browse the repository at this point in the history
  • Loading branch information
decioferreira committed Oct 27, 2024
1 parent 4968f04 commit e3b2b76
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 12 deletions.
3 changes: 3 additions & 0 deletions bin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ const io = {
this.send({ index, value: ioRefs[id].value });
}
},
mVectorRead: function (index, i, array) {
this.send({ index, value: array[i] });
},
dirCreateDirectoryIfMissing: function (index, createParents, filename) {
fs.mkdir(filename, { recursive: createParents }, (err) => {
this.send({ index, value: null });
Expand Down
2 changes: 1 addition & 1 deletion src/Compiler/Type/Solve.elm
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ This sorts variables into the young and old pools accordingly.
-}
generalize : Mark -> Mark -> Int -> Pools -> IO ()
generalize youngMark visitMark youngRank pools =
IO.mVectorRead (Decode.list UF.variableDecoder) pools youngRank
IO.mVectorRead (Decode.list UF.variableDecoder) (Encode.list UF.variableEncoder) pools youngRank
|> IO.bind
(\youngVars ->
poolToRankTable youngMark youngRank youngVars
Expand Down
27 changes: 18 additions & 9 deletions src/Data/IO.elm
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ type Effect
= Exit String Int
| NewIORef Encode.Value
| ReadIORef Int
| MVectorRead Int Encode.Value
| WriteIORef Int Encode.Value
| GetLine
| HPutStr Handle String
Expand Down Expand Up @@ -355,17 +356,25 @@ mVectorWrite decoder encoder ioRef i x =
(Array.set i (Just x))


mVectorRead : Decode.Decoder a -> IORef (Array (Maybe a)) -> Int -> IO a
mVectorRead decoder ioRef i =
mVectorRead : Decode.Decoder a -> (a -> Encode.Value) -> IORef (Array (Maybe a)) -> Int -> IO a
mVectorRead decoder encoder ioRef i =
readIORef (Decode.array (Decode.maybe decoder)) ioRef
|> fmap
|> bind
(\vector ->
case Maybe.join (Array.get i vector) of
Just a ->
a

Nothing ->
todo "Failed to find index on vector"
make decoder
(MVectorRead i
(Encode.array
(\maybeValue ->
case maybeValue of
Just value ->
encoder value

Nothing ->
Encode.null
)
vector
)
)
)


Expand Down
10 changes: 10 additions & 0 deletions src/Terminal/Main.elm
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,16 @@ effectToCmd index portOut effect =
]
}

IO.MVectorRead i array ->
portOut
{ index = index
, value =
Encode.object
[ ( "fn", Encode.string "mVectorRead" )
, ( "args", Encode.list identity [ Encode.int i, array ] )
]
}

IO.WriteIORef id value ->
portOut
{ index = index
Expand Down
8 changes: 6 additions & 2 deletions src/Utils/Main.elm
Original file line number Diff line number Diff line change
Expand Up @@ -752,8 +752,12 @@ fpMakeRelative root path =


fpAddTrailingPathSeparator : FilePath -> FilePath
fpAddTrailingPathSeparator _ =
todo "fpAddTrailingPathSeparator"
fpAddTrailingPathSeparator path =
if String.endsWith "/" path then
path

else
path ++ "/"


fpPathSeparator : Char
Expand Down

0 comments on commit e3b2b76

Please sign in to comment.