Logical ops.

This commit is contained in:
sforman 2023-07-29 11:37:07 -07:00
parent 2c9d5cf4bf
commit b1d4c3c5b8
1 changed files with 15 additions and 0 deletions

View File

@ -62,6 +62,10 @@ joy_eval symbol stack expression =
"rshift" -> joy_binary_math_op (swap_args Bitwise.shiftRightBy) stack expression
">>" -> joy_binary_math_op (swap_args Bitwise.shiftRightBy) stack expression
"/\\" -> joy_logical_op (&&) stack expression
"\\/" -> joy_logical_op (||) stack expression
"_\\/_" -> joy_logical_op (xor) stack expression
"clear" -> Ok ([], expression)
"concat" -> joy_concat stack expression
"cons" -> joy_cons stack expression
@ -151,6 +155,17 @@ joy_comparison_op op stack expression =
Err msg -> Err msg
joy_logical_op : (Bool -> Bool -> Bool) -> JList -> JList -> Result String (JList, JList)
joy_logical_op op stack expression =
case pop_bool(stack) of
Ok (a, s0) ->
case pop_bool(s0) of
Ok (b, s1) ->
Ok ((push_bool (op b a) s1), expression)
Err msg -> Err msg
Err msg -> Err msg
joy_concat : JList -> JList -> Result String (JList, JList)
joy_concat stack expression =
case pop_list(stack) of