Cmp, comes with GMP.
This commit is contained in:
parent
42e7724e77
commit
45865acc2f
|
|
@ -6,18 +6,12 @@
|
||||||
%}
|
%}
|
||||||
struct dict_entry;
|
struct dict_entry;
|
||||||
%%
|
%%
|
||||||
!=, neq
|
|
||||||
"%", mod
|
"%", mod
|
||||||
*, mul
|
*, mul
|
||||||
+, add
|
+, add
|
||||||
-, sub
|
-, sub
|
||||||
/, div_joyfunc
|
/, div_joyfunc
|
||||||
<, lt
|
|
||||||
<=, le
|
|
||||||
<>, neq
|
|
||||||
=, eq
|
|
||||||
>, gt
|
|
||||||
>=, ge
|
|
||||||
bool, truthy
|
bool, truthy
|
||||||
branch, branch
|
branch, branch
|
||||||
clear, clear
|
clear, clear
|
||||||
|
cmp, cmp_joyfunc
|
||||||
|
|
@ -362,6 +362,39 @@ BINARY_MATH_OP(sub)
|
||||||
BINARY_MATH_OP(mul)
|
BINARY_MATH_OP(mul)
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
With mpz_cmp we can implement the rest of the comparison functions as definitions:
|
||||||
|
|
||||||
|
G E L
|
||||||
|
eq [false] [true] [false] cmp
|
||||||
|
gt [true] [false] [false] cmp
|
||||||
|
lt [false] [false] [true] cmp
|
||||||
|
neq [true] [false] [true] cmp
|
||||||
|
le [false] [true] [true] cmp
|
||||||
|
ge [true] [true] [false] cmp
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
cmp_joyfunc(JoyListPtr stack, JoyListPtr expression)
|
||||||
|
{
|
||||||
|
int hmm;
|
||||||
|
mpz_t *a, *b;
|
||||||
|
JoyList G, E, L;
|
||||||
|
L = pop_list_node(stack);
|
||||||
|
E = pop_list_node(stack);
|
||||||
|
G = pop_list_node(stack);
|
||||||
|
b = pop_int(stack);
|
||||||
|
a = pop_int(stack);
|
||||||
|
hmm = mpz_cmp(*a, *b);
|
||||||
|
if (hmm > 0) {
|
||||||
|
push_quote(G, expression);
|
||||||
|
} else if (hmm < 0) {
|
||||||
|
push_quote(L, expression);
|
||||||
|
} else {
|
||||||
|
push_quote(E, expression);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void branch(JoyListPtr stack, JoyListPtr expression) {stack = expression;}
|
void branch(JoyListPtr stack, JoyListPtr expression) {stack = expression;}
|
||||||
void clear(JoyListPtr stack, JoyListPtr expression) {stack = expression;}
|
void clear(JoyListPtr stack, JoyListPtr expression) {stack = expression;}
|
||||||
void div_joyfunc(JoyListPtr stack, JoyListPtr expression) {stack = expression;}
|
void div_joyfunc(JoyListPtr stack, JoyListPtr expression) {stack = expression;}
|
||||||
|
|
|
||||||
|
|
@ -59,15 +59,10 @@ typedef void (*JoyFunc)(JoyListPtr, JoyListPtr);
|
||||||
void add(JoyListPtr stack, JoyListPtr expression);
|
void add(JoyListPtr stack, JoyListPtr expression);
|
||||||
void branch(JoyListPtr stack, JoyListPtr expression);
|
void branch(JoyListPtr stack, JoyListPtr expression);
|
||||||
void clear(JoyListPtr stack, JoyListPtr expression);
|
void clear(JoyListPtr stack, JoyListPtr expression);
|
||||||
|
void cmp_joyfunc(JoyListPtr stack, JoyListPtr expression);
|
||||||
void div_joyfunc(JoyListPtr stack, JoyListPtr expression);
|
void div_joyfunc(JoyListPtr stack, JoyListPtr expression);
|
||||||
void eq(JoyListPtr stack, JoyListPtr expression);
|
|
||||||
void ge(JoyListPtr stack, JoyListPtr expression);
|
|
||||||
void gt(JoyListPtr stack, JoyListPtr expression);
|
|
||||||
void le(JoyListPtr stack, JoyListPtr expression);
|
|
||||||
void lt(JoyListPtr stack, JoyListPtr expression);
|
|
||||||
void mod(JoyListPtr stack, JoyListPtr expression);
|
void mod(JoyListPtr stack, JoyListPtr expression);
|
||||||
void mul(JoyListPtr stack, JoyListPtr expression);
|
void mul(JoyListPtr stack, JoyListPtr expression);
|
||||||
void neq(JoyListPtr stack, JoyListPtr expression);
|
|
||||||
void sub(JoyListPtr stack, JoyListPtr expression);
|
void sub(JoyListPtr stack, JoyListPtr expression);
|
||||||
void truthy(JoyListPtr stack, JoyListPtr expression);
|
void truthy(JoyListPtr stack, JoyListPtr expression);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,3 +9,30 @@
|
||||||
/*el = text_to_expression(text);*/
|
/*el = text_to_expression(text);*/
|
||||||
/*print_list(el);*/
|
/*print_list(el);*/
|
||||||
/*printf("\n");*/
|
/*printf("\n");*/
|
||||||
|
|
||||||
|
concat
|
||||||
|
cons
|
||||||
|
dip
|
||||||
|
dup
|
||||||
|
first
|
||||||
|
i
|
||||||
|
loop
|
||||||
|
pop
|
||||||
|
rest
|
||||||
|
stack
|
||||||
|
swaack
|
||||||
|
swap
|
||||||
|
|
||||||
|
|
||||||
|
pop_any(), pop_int(), and add
|
||||||
|
|
||||||
|
With cmp (provided by the GMP lib) we can implement the rest of
|
||||||
|
the comparison functions as definitions:
|
||||||
|
|
||||||
|
G E L
|
||||||
|
eq [false] [true] [false] cmp
|
||||||
|
gt [true] [false] [false] cmp
|
||||||
|
lt [false] [false] [true] cmp
|
||||||
|
neq [true] [false] [true] cmp
|
||||||
|
le [false] [true] [true] cmp
|
||||||
|
ge [true] [true] [false] cmp
|
||||||
Loading…
Reference in New Issue