From: sforman Date: Sat, 29 Jul 2023 18:32:22 +0000 (-0700) Subject: Left- and Right-shift. X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=2c9d5cf4bfd89289b0e28ef5b28a382d6dcb37f2;p=joypy%2FThun.git Left- and Right-shift. --- diff --git a/implementations/Elm/src/Joy.elm b/implementations/Elm/src/Joy.elm index df52ded..7c0da9c 100644 --- a/implementations/Elm/src/Joy.elm +++ b/implementations/Elm/src/Joy.elm @@ -57,6 +57,10 @@ joy_eval symbol stack expression = "and" -> joy_binary_math_op (Bitwise.and) stack expression "or" -> joy_binary_math_op (Bitwise.or) stack expression "xor" -> joy_binary_math_op (Bitwise.xor) stack expression + "lshift" -> joy_binary_math_op (swap_args Bitwise.shiftLeftBy) stack expression + "<<" -> joy_binary_math_op (swap_args Bitwise.shiftLeftBy) stack expression + "rshift" -> joy_binary_math_op (swap_args Bitwise.shiftRightBy) stack expression + ">>" -> joy_binary_math_op (swap_args Bitwise.shiftRightBy) stack expression "clear" -> Ok ([], expression) "concat" -> joy_concat stack expression @@ -96,6 +100,7 @@ joy_i stack expression = Ok (a, s0) -> Ok (s0, a ++ expression) Err msg -> Err msg + joy_dip : JList -> JList -> Result String (JList, JList) joy_dip stack expression = case pop_list(stack) of @@ -131,6 +136,10 @@ joy_binary_math_op op stack expression = Err msg -> Err msg +swap_args : (Int -> Int -> Int) -> (Int -> Int -> Int) +swap_args op = (\a b -> op b a) + + joy_comparison_op : (Int -> Int -> Bool) -> JList -> JList -> Result String (JList, JList) joy_comparison_op op stack expression = case pop_int(stack) of @@ -292,7 +301,6 @@ isnt_int (item, stack) = Err "Not an integer." - isnt_list : (JoyType, JList) -> Result String (JList, JList) isnt_list (item, stack) = case item of @@ -310,7 +318,6 @@ isnt_bool (item, stack) = _ -> Err "Not a Boolean value." - -- Printer joyTermToString : JoyType -> String @@ -326,9 +333,6 @@ joyTermToString term = joyExpressionToString expr = String.join " " (List.map joyTermToString expr) - - - -- Use the old S-expression lexing trick. tokenize : String -> (List String)