Reorder the functions a bit.
This commit is contained in:
parent
1b00b22f55
commit
acab437f6e
48
src/Main.elm
48
src/Main.elm
|
@ -166,6 +166,30 @@ parseMove = succeed Move
|
|||
initialScope : Scope
|
||||
initialScope = Child End Dict.empty Dict.empty
|
||||
|
||||
setScopeFunction : String -> Function -> Scope -> Scope
|
||||
setScopeFunction s f scope = case scope of
|
||||
End -> setScopeFunction s f initialScope
|
||||
Child p fs vs -> Child p (Dict.insert s f fs) vs
|
||||
|
||||
setScopeVariable : String -> Int -> Scope -> Scope
|
||||
setScopeVariable s v scope = case scope of
|
||||
End -> setScopeVariable s v initialScope
|
||||
Child p fs vs -> Child p fs (Dict.insert s v vs)
|
||||
|
||||
scopeFunction : String -> Scope -> Maybe Function
|
||||
scopeFunction s scope = case scope of
|
||||
End -> Nothing
|
||||
Child p fs _ -> case Dict.get s fs of
|
||||
Just f -> Just f
|
||||
Nothing -> scopeFunction s p
|
||||
|
||||
scopeVariable : String -> Scope -> Maybe Int
|
||||
scopeVariable s scope = case scope of
|
||||
End -> Nothing
|
||||
Child p _ vs -> case Dict.get s vs of
|
||||
Just i -> Just i
|
||||
Nothing -> scopeVariable s p
|
||||
|
||||
initialState : State
|
||||
initialState =
|
||||
{ penMode = Up
|
||||
|
@ -214,30 +238,6 @@ downScope state =
|
|||
in
|
||||
Ok ((), { state | scope = newScope })
|
||||
|
||||
setScopeFunction : String -> Function -> Scope -> Scope
|
||||
setScopeFunction s f scope = case scope of
|
||||
End -> setScopeFunction s f initialScope
|
||||
Child p fs vs -> Child p (Dict.insert s f fs) vs
|
||||
|
||||
setScopeVariable : String -> Int -> Scope -> Scope
|
||||
setScopeVariable s v scope = case scope of
|
||||
End -> setScopeVariable s v initialScope
|
||||
Child p fs vs -> Child p fs (Dict.insert s v vs)
|
||||
|
||||
scopeFunction : String -> Scope -> Maybe Function
|
||||
scopeFunction s scope = case scope of
|
||||
End -> Nothing
|
||||
Child p fs _ -> case Dict.get s fs of
|
||||
Just f -> Just f
|
||||
Nothing -> scopeFunction s p
|
||||
|
||||
scopeVariable : String -> Scope -> Maybe Int
|
||||
scopeVariable s scope = case scope of
|
||||
End -> Nothing
|
||||
Child p _ vs -> case Dict.get s vs of
|
||||
Just i -> Just i
|
||||
Nothing -> scopeVariable s p
|
||||
|
||||
lookupFunction : String -> Step Function
|
||||
lookupFunction s state = case scopeFunction s state.scope of
|
||||
Just f -> Ok (f, state)
|
||||
|
|
Loading…
Reference in New Issue
Block a user