Disallow empty lists.

This commit is contained in:
Danila Fedorin 2019-05-30 18:14:35 -07:00
parent 281c589dc6
commit 5c2c13d83e
1 changed files with 23 additions and 6 deletions

View File

@ -96,13 +96,17 @@ viewRawCacheModelHierarchy rcmh =
<| List.indexedMap viewRawCacheModel rcmh
translationResult = Result.andThen validateCacheModelHierarchy
<| translateRawCacheModelHierarchy rcmh
errorHtml =
checkedResult =
case translationResult of
Ok h -> if h == [] then Err "Please specify at least one cache level." else Ok h
Err e -> Err e
errorHtml =
case checkedResult of
Ok _ -> viewError True ""
Err e -> viewError False e
newButton = button "Add level" CreateRawModel
useButton = resultButton translationResult "Use hierarchy" (UseHierarchy << Just)
useButton = resultButton checkedResult "Use hierarchy" (UseHierarchy << Just)
in
div []
[ h2 [] [ text "Cache hierarchy" ]
@ -208,12 +212,17 @@ viewAccessInput m =
, item = Parser.int
, trailing = Parser.Optional
}
parseErrorToString _ = "Unable to parse input. Please enter a sequence of numbers separated by commas."
parseResult = Parser.run (parser |. Parser.end) m.accessInput
accessButton = maybeButton (Result.toMaybe parseResult) "Access address" Access
errorHtml =
checkedResult =
case parseResult of
Ok is -> if is == [] then Err "Please enter at least one number." else Ok is
Err e -> Err <| parseErrorToString e
accessButton = resultButton checkedResult "Access address" Access
errorHtml =
case checkedResult of
Ok _ -> viewError True ""
Err lde -> viewError False "Unable to parse input. Please enter a sequence of numbers separated by commas."
Err e -> viewError False e
editHierarchyButton = button "Edit hierarchy" (UseHierarchy Nothing)
in
div []
@ -258,6 +267,14 @@ viewBase m =
<| Maybe.map (List.singleton << viewCacheHierarchy) <| m.hierarchy
Just _ -> []
accessView = Maybe.withDefault [] <| Maybe.map (List.singleton << viewAccessView m) <| Maybe.andThen (List.head) <| m.accessView
remainingAccessView =
case Maybe.map (\l -> List.length l - 1) m.accessView of
Just n -> if n <= 0 then [] else
[ div [ class "alert", class "alert-info" ] [ text <|
"Simulating more than one access. " ++ (String.fromInt n) ++
" addresses in queue." ]
]
_ -> []
in
div [ class "container" ]
<| [ viewDescription] ++ rawView ++ accessInputView ++ accessView ++ cacheView
<| [ viewDescription] ++ rawView ++ accessInputView ++ remainingAccessView ++ accessView ++ cacheView