Comparison ops.
This commit is contained in:
parent
36dc5b619f
commit
a69b988684
|
|
@ -46,6 +46,14 @@ joy_eval symbol stack expression =
|
||||||
"/" -> joy_binary_math_op (//) stack expression
|
"/" -> joy_binary_math_op (//) stack expression
|
||||||
"%" -> joy_binary_math_op (modBy) stack expression
|
"%" -> joy_binary_math_op (modBy) stack expression
|
||||||
|
|
||||||
|
"<" -> joy_comparison_op (<) stack expression
|
||||||
|
">" -> joy_comparison_op (>) stack expression
|
||||||
|
"<=" -> joy_comparison_op (<=) stack expression
|
||||||
|
">=" -> joy_comparison_op (>=) stack expression
|
||||||
|
"<>" -> joy_comparison_op (/=) stack expression
|
||||||
|
"!=" -> joy_comparison_op (/=) stack expression
|
||||||
|
"=" -> joy_comparison_op (==) stack expression
|
||||||
|
|
||||||
"and" -> joy_binary_math_op (Bitwise.and) stack expression
|
"and" -> joy_binary_math_op (Bitwise.and) stack expression
|
||||||
"or" -> joy_binary_math_op (Bitwise.or) stack expression
|
"or" -> joy_binary_math_op (Bitwise.or) stack expression
|
||||||
"xor" -> joy_binary_math_op (Bitwise.xor) stack expression
|
"xor" -> joy_binary_math_op (Bitwise.xor) stack expression
|
||||||
|
|
@ -122,6 +130,18 @@ joy_binary_math_op op stack expression =
|
||||||
Err msg -> Err msg
|
Err msg -> Err msg
|
||||||
Err msg -> Err msg
|
Err msg -> Err msg
|
||||||
|
|
||||||
|
|
||||||
|
joy_comparison_op : (Int -> Int -> Bool) -> JList -> JList -> Result String (JList, JList)
|
||||||
|
joy_comparison_op op stack expression =
|
||||||
|
case pop_int(stack) of
|
||||||
|
Ok (a, s0) ->
|
||||||
|
case pop_int(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 : JList -> JList -> Result String (JList, JList)
|
||||||
joy_concat stack expression =
|
joy_concat stack expression =
|
||||||
case pop_list(stack) of
|
case pop_list(stack) of
|
||||||
|
|
@ -222,6 +242,14 @@ joy_truthy stack expression =
|
||||||
Err msg -> Err msg
|
Err msg -> Err msg
|
||||||
|
|
||||||
|
|
||||||
|
push_bool : Bool -> JList -> JList
|
||||||
|
push_bool flag stack =
|
||||||
|
if flag then
|
||||||
|
JoyTrue :: stack
|
||||||
|
else
|
||||||
|
JoyFalse :: stack
|
||||||
|
|
||||||
|
|
||||||
push_int : Int -> JList -> JList
|
push_int : Int -> JList -> JList
|
||||||
push_int i stack = (JoyInt i) :: stack
|
push_int i stack = (JoyInt i) :: stack
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue