Comparison operations.
This commit is contained in:
parent
c591bf4138
commit
d94153583c
|
|
@ -339,7 +339,6 @@ proc dip(stack: JoyListType, expression: JoyListType, dictionary: JoyMapType): (
|
||||||
dictionary
|
dictionary
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
proc i(stack: JoyListType, expression: JoyListType, dictionary: JoyMapType): (JoyListType, JoyListType, JoyMapType) =
|
proc i(stack: JoyListType, expression: JoyListType, dictionary: JoyMapType): (JoyListType, JoyListType, JoyMapType) =
|
||||||
let (body_node, s0) = pop_list_node(stack)
|
let (body_node, s0) = pop_list_node(stack)
|
||||||
return (
|
return (
|
||||||
|
|
@ -348,7 +347,6 @@ proc i(stack: JoyListType, expression: JoyListType, dictionary: JoyMapType): (Jo
|
||||||
dictionary
|
dictionary
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
proc loop(stack: JoyListType, expression: JoyListType, dictionary: JoyMapType): (JoyListType, JoyListType, JoyMapType) =
|
proc loop(stack: JoyListType, expression: JoyListType, dictionary: JoyMapType): (JoyListType, JoyListType, JoyMapType) =
|
||||||
let (body_node, s0) = pop_list_node(stack)
|
let (body_node, s0) = pop_list_node(stack)
|
||||||
let (flag, s1) = pop_bool(s0)
|
let (flag, s1) = pop_bool(s0)
|
||||||
|
|
|
||||||
|
|
@ -96,6 +96,8 @@ let pop_bool : joy_list -> bool * joy_list =
|
||||||
| JoyFalse -> (false, tail)
|
| JoyFalse -> (false, tail)
|
||||||
| _ -> raise (ValueError "Not a Boolean value."))
|
| _ -> raise (ValueError "Not a Boolean value."))
|
||||||
|
|
||||||
|
let push_bool b stack = if b then JoyTrue :: stack else JoyFalse :: stack
|
||||||
|
|
||||||
(*
|
(*
|
||||||
██████╗ ██████╗ ██╗███╗ ██╗████████╗███████╗██████╗
|
██████╗ ██████╗ ██╗███╗ ██╗████████╗███████╗██████╗
|
||||||
██╔══██╗██╔══██╗██║████╗ ██║╚══██╔══╝██╔════╝██╔══██╗
|
██╔══██╗██╔══██╗██║████╗ ██║╚══██╔══╝██╔════╝██╔══██╗
|
||||||
|
|
@ -255,9 +257,7 @@ let i s e d =
|
||||||
let loop s e d =
|
let loop s e d =
|
||||||
let body, s0 = pop_list s in
|
let body, s0 = pop_list s in
|
||||||
let flag, s1 = pop_bool s0 in
|
let flag, s1 = pop_bool s0 in
|
||||||
if flag then
|
if flag then (s1, body @ (JoyList body :: j_loop :: e), d) else (s1, e, d)
|
||||||
(s1, body @ (JoyList body :: j_loop :: e), d)
|
|
||||||
else (s1, e, d)
|
|
||||||
|
|
||||||
(*
|
(*
|
||||||
██████╗ ██████╗ ██████╗ ███████╗ ██╗ ██╗ ██████╗ ██████╗ ██████╗ ███████╗
|
██████╗ ██████╗ ██████╗ ███████╗ ██╗ ██╗ ██████╗ ██████╗ ██████╗ ███████╗
|
||||||
|
|
@ -295,6 +295,30 @@ let joy_eval sym stack expression dictionary =
|
||||||
let a, s0 = pop_int stack in
|
let a, s0 = pop_int stack in
|
||||||
let b, s1 = pop_int s0 in
|
let b, s1 = pop_int s0 in
|
||||||
(JoyInt (b - a) :: s1, expression, dictionary)
|
(JoyInt (b - a) :: s1, expression, dictionary)
|
||||||
|
| "<" ->
|
||||||
|
let a, s0 = pop_int stack in
|
||||||
|
let b, s1 = pop_int s0 in
|
||||||
|
(push_bool (b < a) s1, expression, dictionary)
|
||||||
|
| ">" ->
|
||||||
|
let a, s0 = pop_int stack in
|
||||||
|
let b, s1 = pop_int s0 in
|
||||||
|
(push_bool (b > a) s1, expression, dictionary)
|
||||||
|
| "<=" ->
|
||||||
|
let a, s0 = pop_int stack in
|
||||||
|
let b, s1 = pop_int s0 in
|
||||||
|
(push_bool (b <= a) s1, expression, dictionary)
|
||||||
|
| ">=" ->
|
||||||
|
let a, s0 = pop_int stack in
|
||||||
|
let b, s1 = pop_int s0 in
|
||||||
|
(push_bool (b >= a) s1, expression, dictionary)
|
||||||
|
| "!=" ->
|
||||||
|
let a, s0 = pop_int stack in
|
||||||
|
let b, s1 = pop_int s0 in
|
||||||
|
(push_bool (b != a) s1, expression, dictionary)
|
||||||
|
| "=" ->
|
||||||
|
let a, s0 = pop_int stack in
|
||||||
|
let b, s1 = pop_int s0 in
|
||||||
|
(push_bool (b = a) s1, expression, dictionary)
|
||||||
| "branch" -> branch stack expression dictionary
|
| "branch" -> branch stack expression dictionary
|
||||||
| "i" -> i stack expression dictionary
|
| "i" -> i stack expression dictionary
|
||||||
| "loop" -> loop stack expression dictionary
|
| "loop" -> loop stack expression dictionary
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue