Skip to content

Commit

Permalink
Rename Value and PrimitiveValue to Item and Value
Browse files Browse the repository at this point in the history
  • Loading branch information
cruessler committed Feb 6, 2024
1 parent 871368b commit bc1f49f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
18 changes: 9 additions & 9 deletions app/elm/Vm/Stack.elm
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Vm.Stack exposing
( Arrays
, PrimitiveValue(..)
, Item(..)
, Stack
, Value(..)
, toValue
Expand All @@ -15,29 +15,29 @@ import Vm.Type as Type
{-| This module mainly holds the definition for a `Value` as it is represented
on the stack.
-}
type PrimitiveValue
type Value
= Word String
| Int Int
| Float Float
| List (List PrimitiveValue)
| List (List Value)
| ArrayId Int


type Value
type Item
= Void
| Address Int
| Value PrimitiveValue
| Value Value


type alias Stack =
List Value
List Item


type alias Arrays =
Dict Int { items : Array PrimitiveValue, origin : Int, id : Maybe Int }
Dict Int { items : Array Value, origin : Int, id : Maybe Int }


encodeValue : Arrays -> Value -> E.Value
encodeValue : Arrays -> Item -> E.Value
encodeValue arrays value =
case value of
Void ->
Expand All @@ -50,7 +50,7 @@ encodeValue arrays value =
E.string <| Type.toDebugString <| toTypeValue arrays primitive


toTypeValue : Arrays -> PrimitiveValue -> Type.Value
toTypeValue : Arrays -> Value -> Type.Value
toTypeValue arrays value =
case value of
Word string ->
Expand Down
16 changes: 8 additions & 8 deletions app/elm/Vm/Vm.elm
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,10 @@ incrementProgramCounter vm =
{ vm | programCounter = vm.programCounter + 1 }


{-| Convert a `Stack.PrimitiveValue` to a `Type.Value`. If the value is a
{-| Convert a `Stack.Value` to a `Type.Value`. If the value is a
`Stack.ArrayId`, use the VM’s enviromnent to resolve it to an array.
-}
toTypeValue : Stack.PrimitiveValue -> Vm -> Result Error Type.Value
toTypeValue : Stack.Value -> Vm -> Result Error Type.Value
toTypeValue value vm =
case value of
Stack.Word string ->
Expand Down Expand Up @@ -281,11 +281,11 @@ toTypeValue value vm =
|> Result.map Type.Array


{-| Convert a `Type.Value` to a `Stack.PrimitiveValue`. If the value is a
{-| Convert a `Type.Value` to a `Stack.Value`. If the value is a
`Type.Array`, assign it an id and store it in the VM’s enviromnent.
-}
toStackPrimitiveValue : Type.Value -> Vm -> ( Stack.PrimitiveValue, Vm )
toStackPrimitiveValue value vm =
toStackValue : Type.Value -> Vm -> ( Stack.Value, Vm )
toStackValue value vm =
case value of
Type.Word word ->
( Stack.Word word, vm )
Expand All @@ -303,7 +303,7 @@ toStackPrimitiveValue value vm =
(\value_ ( accList, accVm ) ->
let
( stackValue, newAccVm ) =
toStackPrimitiveValue value_ accVm
toStackValue value_ accVm
in
( stackValue :: accList, newAccVm )
)
Expand All @@ -327,7 +327,7 @@ toStackPrimitiveValue value vm =
(\value_ ( accList, accVm ) ->
let
( stackValue, newAccVm ) =
toStackPrimitiveValue value_ accVm
toStackValue value_ accVm
in
( stackValue :: accList, newAccVm )
)
Expand Down Expand Up @@ -361,7 +361,7 @@ pushValue1 : Type.Value -> Vm -> Vm
pushValue1 value vm =
let
( newValue, newVm ) =
toStackPrimitiveValue value vm
toStackValue value vm
in
{ newVm | stack = Stack.Value newValue :: newVm.stack }

Expand Down

0 comments on commit bc1f49f

Please sign in to comment.