Skip to content

Commit

Permalink
WIP clear debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
decioferreira committed Dec 13, 2024
1 parent 4d33518 commit f134fd2
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 63 deletions.
2 changes: 1 addition & 1 deletion bin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const crypto = require("node:crypto");
const AdmZip = require("adm-zip");
const which = require("which");
const tmp = require("tmp");
const { Elm } = require("./guida.js");
const { Elm } = require("./guida.min.js");
const FormData = require("form-data");

const rl = readline.createInterface({
Expand Down
10 changes: 5 additions & 5 deletions lib/guida.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ set -e
js="bin/guida.js"
min="bin/guida.min.js"

guida make --output=$js $@
elm make --optimize --output=$js $@

# uglifyjs $js --compress "pure_funcs=[F2,F3,F4,F5,F6,F7,F8,F9,A2,A3,A4,A5,A6,A7,A8,A9],pure_getters,keep_fargs=false,unsafe_comps,unsafe" | uglifyjs --mangle --output $min
uglifyjs $js --compress "pure_funcs=[F2,F3,F4,F5,F6,F7,F8,F9,A2,A3,A4,A5,A6,A7,A8,A9],pure_getters,keep_fargs=false,unsafe_comps,unsafe" | uglifyjs --mangle --output $min

# echo "Initial size: $(cat $js | wc -c) bytes ($js)"
# echo "Minified size:$(cat $min | wc -c) bytes ($min)"
# echo "Gzipped size: $(cat $min | gzip -c | wc -c) bytes"
echo "Initial size: $(cat $js | wc -c) bytes ($js)"
echo "Minified size:$(cat $min | wc -c) bytes ($min)"
echo "Gzipped size: $(cat $min | gzip -c | wc -c) bytes"
4 changes: 0 additions & 4 deletions src/Builder/Deps/Solver.elm
Original file line number Diff line number Diff line change
Expand Up @@ -447,10 +447,6 @@ initEnv =
Utils.newEmptyMVar
|> IO.bind
(\mvar ->
let
_ =
Debug.log "mvar1" mvar
in
Utils.forkIO (IO.bind (Utils.putMVar Http.managerEncoder mvar) Http.getManager)
|> IO.bind
(\_ ->
Expand Down
6 changes: 3 additions & 3 deletions src/Builder/File.elm
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ writeBinary encoder path value =

readBinary : Decode.Decoder a -> FilePath -> IO (Maybe a)
readBinary decoder path =
Utils.dirDoesFileExist (Debug.log "path1" path)
Utils.dirDoesFileExist path
|> IO.bind
(\pathExists ->
if pathExists then
Expand Down Expand Up @@ -164,7 +164,7 @@ writeEntry destination root entry =

exists : FilePath -> IO Bool
exists path =
Utils.dirDoesFileExist (Debug.log "path2" path)
Utils.dirDoesFileExist path



Expand All @@ -173,7 +173,7 @@ exists path =

remove : FilePath -> IO ()
remove path =
Utils.dirDoesFileExist (Debug.log "path3" path)
Utils.dirDoesFileExist path
|> IO.bind
(\exists_ ->
if exists_ then
Expand Down
55 changes: 25 additions & 30 deletions src/System/IO.elm
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,6 @@ type Msg

update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
let
_ =
Debug.log "next" model.next
in
case msg of
PureMsg index (IO fn) ->
case fn index model of
Expand Down Expand Up @@ -317,10 +313,6 @@ update msg model =
( { newRealWorld | next = Dict.insert index (ReplGetInputLineNext next) model.next }, sendReplGetInputLine { index = index, prompt = prompt } )

( newRealWorld, DirDoesFileExist next filename ) ->
let
_ =
Debug.log "DirDoesFileExist" ( index, filename )
in
( { newRealWorld | next = Dict.insert index (DirDoesFileExistNext next) model.next }, sendDirDoesFileExist { index = index, filename = filename } )

( newRealWorld, DirCreateDirectoryIfMissing next createParents filename ) ->
Expand Down Expand Up @@ -359,39 +351,38 @@ update msg model =
( newRealWorld, ReplGetInputLineWithInitial next prompt left right ) ->
( { newRealWorld | next = Dict.insert index (ReplGetInputLineWithInitialNext next) model.next }, sendReplGetInputLineWithInitial { index = index, prompt = prompt, left = left, right = right } )

( newRealWorld, ReadMVar next ) ->
( newRealWorld, ReadMVarWaiting next ) ->
( { newRealWorld | next = Dict.insert index (ReadMVarNext next) model.next }, Cmd.none )

( newRealWorld, ReadMVarDone next value ) ->
update (ReadMVarMsg index value) { newRealWorld | next = Dict.insert index (ReadMVarNext next) model.next }

( newRealWorld, TakeMVarWaiting next ) ->
( { newRealWorld | next = Dict.insert index (TakeMVarNext next) model.next }, Cmd.none )

( newRealWorld, TakeMVarTaken next value maybePutIndex ) ->
( newRealWorld, TakeMVarDone next value maybePutIndex ) ->
let
( updatedModel, updatedCmd ) =
update (ReadMVarMsg index value) { newRealWorld | next = Dict.insert index (TakeMVarNext next) model.next }
in
case Debug.log "maybePutIndex" maybePutIndex of
case maybePutIndex of
Just putIndex ->
update (PutMVarMsg (Debug.log "putIndex" putIndex)) updatedModel
update (PutMVarMsg putIndex) updatedModel
|> Tuple.mapSecond (\cmd -> Cmd.batch [ cmd, updatedCmd ])

Nothing ->
( updatedModel, updatedCmd )

( newRealWorld, PutMVarWaiting next ) ->
( { newRealWorld | next = Dict.insert (Debug.log "INDEX1" index) (PutMVarNext next) model.next }, Cmd.none )
( { newRealWorld | next = Dict.insert index (PutMVarNext next) model.next }, Cmd.none )

( newRealWorld, PutMVarDone next readSubscriberIds maybeTakeIndex value ) ->
let
_ =
Debug.log "readSubscriberIds maybeTakeIndex" ( readSubscriberIds, maybeTakeIndex )
in
List.foldr
(\readSubscriberId ( accModel, accCmd ) ->
update (ReadMVarMsg (Debug.log "readSubscriberId" readSubscriberId) value) accModel
update (ReadMVarMsg readSubscriberId value) accModel
|> Tuple.mapSecond (\cmd -> Cmd.batch [ cmd, accCmd ])
)
(update (PutMVarMsg index) { newRealWorld | next = Dict.insert (Debug.log "INDEX2" index) (PutMVarNext next) model.next })
(update (PutMVarMsg index) { newRealWorld | next = Dict.insert index (PutMVarNext next) model.next })
readSubscriberIds

GetLineMsg index input ->
Expand Down Expand Up @@ -527,8 +518,8 @@ update msg model =
Just (DirDoesFileExistNext fn) ->
update (PureMsg index (fn value)) model

nextFn ->
crash ("DirDoesFileExistMsg " ++ String.fromInt index ++ " - " ++ Debug.toString nextFn)
_ ->
crash "DirDoesFileExistMsg"

DirCreateDirectoryIfMissingMsg index ->
case Dict.get index model.next of
Expand Down Expand Up @@ -836,24 +827,25 @@ type ION a
| ExitWith (a -> IO a) Int
| DirFindExecutable (Maybe FilePath -> IO a) FilePath
| ReplGetInputLine (Maybe String -> IO a) String
| PutMVarWaiting (() -> IO a)
| PutMVarDone (() -> IO a) (List Int) (Maybe Int) Encode.Value
| DirDoesFileExist (Bool -> IO a) FilePath
| DirCreateDirectoryIfMissing (() -> IO a) Bool FilePath
| LockFile (() -> IO a) FilePath
| UnlockFile (() -> IO a) FilePath
| DirGetModificationTime (Int -> IO a) FilePath
| TakeMVarWaiting (Encode.Value -> IO a)
| TakeMVarTaken (Encode.Value -> IO a) Encode.Value (Maybe Int)
| DirDoesDirectoryExist (Bool -> IO a) FilePath
| DirCanonicalizePath (String -> IO a) FilePath
| ReadMVar (Encode.Value -> IO a)
| BinaryDecodeFileOrFail (Encode.Value -> IO a) FilePath
| Write (() -> IO a) FilePath Encode.Value
| DirRemoveFile (() -> IO a) FilePath
| DirRemoveDirectoryRecursive (() -> IO a) FilePath
| DirWithCurrentDirectory (() -> IO a) FilePath
| ReplGetInputLineWithInitial (Maybe String -> IO a) String String String
| ReadMVarWaiting (Encode.Value -> IO a)
| ReadMVarDone (Encode.Value -> IO a) Encode.Value
| TakeMVarWaiting (Encode.Value -> IO a)
| TakeMVarDone (Encode.Value -> IO a) Encode.Value (Maybe Int)
| PutMVarWaiting (() -> IO a)
| PutMVarDone (() -> IO a) (List Int) (Maybe Int) Encode.Value


type alias RealWorld =
Expand Down Expand Up @@ -993,14 +985,17 @@ bind f (IO ma) =
( s1, ReplGetInputLineWithInitial next prompt left right ) ->
( s1, ReplGetInputLineWithInitial (\value -> bind f (next value)) prompt left right )

( s1, ReadMVar next ) ->
( s1, ReadMVar (\value -> bind f (next value)) )
( s1, ReadMVarWaiting next ) ->
( s1, ReadMVarWaiting (\value -> bind f (next value)) )

( s1, ReadMVarDone next readValue ) ->
( s1, ReadMVarDone (\value -> bind f (next value)) readValue )

( s1, TakeMVarWaiting next ) ->
( s1, TakeMVarWaiting (\value -> bind f (next value)) )

( s1, TakeMVarTaken next takenValue maybePutIndex ) ->
( s1, TakeMVarTaken (\value -> bind f (next value)) takenValue maybePutIndex )
( s1, TakeMVarDone next takenValue maybePutIndex ) ->
( s1, TakeMVarDone (\value -> bind f (next value)) takenValue maybePutIndex )

( s1, PutMVarWaiting next ) ->
( s1, PutMVarWaiting (\() -> bind f (next ())) )
Expand Down
2 changes: 1 addition & 1 deletion src/Utils/Crash.elm
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ module Utils.Crash exposing (crash)

crash : String -> a
crash str =
Debug.todo str
crash str
26 changes: 7 additions & 19 deletions src/Utils/Main.elm
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ import Json.Encode as Encode
import Maybe.Extra as Maybe
import Prelude
import System.Exit as Exit
import System.IO as IO exposing (IO(..), MVarSubscriber(..))
import System.IO as IO exposing (IO(..))
import Time
import Utils.Crash exposing (crash)

Expand Down Expand Up @@ -935,10 +935,6 @@ newMVar encoder value =
newEmptyMVar
|> IO.bind
(\mvar ->
let
_ =
Debug.log "mvar2" mvar
in
putMVar encoder mvar value
|> IO.fmap (\_ -> mvar)
)
Expand All @@ -952,11 +948,11 @@ readMVar decoder (MVar ref) =
Just mVar ->
case mVar.value of
Just value ->
( s, IO.Pure value )
( s, IO.ReadMVarDone IO.pure value )

Nothing ->
( { s | mVars = Array.set ref { mVar | subscribers = IO.ReadSubscriber index :: mVar.subscribers } s.mVars }
, IO.ReadMVar IO.pure
, IO.ReadMVarWaiting IO.pure
)

Nothing ->
Expand Down Expand Up @@ -1002,7 +998,7 @@ takeMVar decoder (MVar ref) =
( Nothing, subscribers, Nothing )
in
( { s | mVars = Array.set ref { mVar | subscribers = newSubscribers, value = newValue } s.mVars }
, IO.TakeMVarTaken IO.pure value maybePutIndex
, IO.TakeMVarDone IO.pure value maybePutIndex
)

Nothing ->
Expand Down Expand Up @@ -1033,7 +1029,7 @@ putMVar encoder (MVar ref) value =
case mVar.value of
Just _ ->
( { s | mVars = Array.set ref { mVar | subscribers = IO.PutSubscriber index (encoder value) :: mVar.subscribers } s.mVars }
, Debug.log "PutMVarWaiting" (IO.PutMVarWaiting IO.pure)
, IO.PutMVarWaiting IO.pure
)

Nothing ->
Expand Down Expand Up @@ -1070,15 +1066,11 @@ putMVar encoder (MVar ref) value =
(IO.TakeSubscriber takeIndex) :: remainingSubscribers ->
( Nothing, Just takeIndex, remainingSubscribers )

all ->
let
_ =
Debug.log "ALL!!!" all
in
_ ->
( Just encodedValue, Nothing, nonReadSubscribers )
in
( { s | mVars = Array.set ref { mVar | subscribers = subscribers, value = newValue } s.mVars }
, Debug.log "PutMVarDone" (IO.PutMVarDone IO.pure readSubscriberIds maybeTakeIndex encodedValue)
, IO.PutMVarDone IO.pure readSubscriberIds maybeTakeIndex encodedValue
)

_ ->
Expand All @@ -1090,10 +1082,6 @@ newEmptyMVar : IO (MVar a)
newEmptyMVar =
IO
(\_ s ->
let
_ =
Debug.log "newEmptyMVar" (Array.length s.mVars)
in
( { s | mVars = Array.push { subscribers = [], value = Nothing } s.mVars }
, IO.Pure (MVar (Array.length s.mVars))
)
Expand Down

0 comments on commit f134fd2

Please sign in to comment.