From bc1f49fa03effebed11d07ac0d6e94119213e2c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20R=C3=BC=C3=9Fler?= Date: Tue, 6 Feb 2024 17:00:09 +0100 Subject: [PATCH] Rename Value and PrimitiveValue to Item and Value --- app/elm/Vm/Stack.elm | 18 +++++++++--------- app/elm/Vm/Vm.elm | 16 ++++++++-------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/app/elm/Vm/Stack.elm b/app/elm/Vm/Stack.elm index 03d24a4..ec25363 100644 --- a/app/elm/Vm/Stack.elm +++ b/app/elm/Vm/Stack.elm @@ -1,6 +1,6 @@ module Vm.Stack exposing ( Arrays - , PrimitiveValue(..) + , Item(..) , Stack , Value(..) , toValue @@ -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 -> @@ -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 -> diff --git a/app/elm/Vm/Vm.elm b/app/elm/Vm/Vm.elm index f6775b9..014809a 100644 --- a/app/elm/Vm/Vm.elm +++ b/app/elm/Vm/Vm.elm @@ -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 -> @@ -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 ) @@ -303,7 +303,7 @@ toStackPrimitiveValue value vm = (\value_ ( accList, accVm ) -> let ( stackValue, newAccVm ) = - toStackPrimitiveValue value_ accVm + toStackValue value_ accVm in ( stackValue :: accList, newAccVm ) ) @@ -327,7 +327,7 @@ toStackPrimitiveValue value vm = (\value_ ( accList, accVm ) -> let ( stackValue, newAccVm ) = - toStackPrimitiveValue value_ accVm + toStackValue value_ accVm in ( stackValue :: accList, newAccVm ) ) @@ -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 }