Left- and Right-shift.

This commit is contained in:
sforman 2023-07-29 11:32:22 -07:00
parent a69b988684
commit 2c9d5cf4bf
1 changed files with 9 additions and 5 deletions

View File

@ -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)