truthy
This commit is contained in:
parent
7874496090
commit
b1a06979c2
|
|
@ -1,3 +1,18 @@
|
||||||
|
'''
|
||||||
|
It's cheap, but it works.
|
||||||
|
|
||||||
|
Doesn't handle non-alnum names.
|
||||||
|
|
||||||
|
Because the strings are parsed at start time, rather than compile time,
|
||||||
|
it's basically the same as implementing an inscribe command
|
||||||
|
and using it to write a simple Joy script to load the defs:
|
||||||
|
|
||||||
|
for line in defs:
|
||||||
|
print(f'[{line}] inscribe')
|
||||||
|
|
||||||
|
Eh?
|
||||||
|
|
||||||
|
'''
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
#list(open('../defs.txt'))
|
#list(open('../defs.txt'))
|
||||||
|
|
|
||||||
|
|
@ -583,26 +583,39 @@ clear(JoyListPtr stack, __attribute__((unused)) JoyListPtr expression)
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
truthy(JoyListPtr stack, JoyListPtr expression)
|
truthy(JoyListPtr stack, __attribute__((unused)) JoyListPtr expression)
|
||||||
{
|
{
|
||||||
stack = expression;
|
/*
|
||||||
}
|
Keep the original stack in case the top item is already a Boolean value.
|
||||||
/*
|
*/
|
||||||
JoyListPtr s = stack;
|
JoyList s = *stack;
|
||||||
JoyList node = pop_any(stack);
|
JoyList node = pop_any(stack);
|
||||||
switch (node->head->kind) {
|
switch (node->head->kind) {
|
||||||
case joyTrue:
|
case joyTrue:
|
||||||
stack = s;
|
*stack = s;
|
||||||
|
break;
|
||||||
case joyFalse:
|
case joyFalse:
|
||||||
stack = s;
|
*stack = s;
|
||||||
|
break;
|
||||||
case joyInt:
|
case joyInt:
|
||||||
push_thing(
|
if mpz_cmp_si(node->head->value.i, 0) {
|
||||||
if (node->head->value.i);
|
push_thing(JoyTrue, stack);
|
||||||
|
} else {
|
||||||
|
push_thing(JoyFalse, stack);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case joyList:
|
||||||
|
if (node->head->value.el) {
|
||||||
|
push_thing(JoyTrue, stack);
|
||||||
|
} else {
|
||||||
|
push_thing(JoyFalse, stack);
|
||||||
|
}
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
|
printf("Cannot Boolify.\n");
|
||||||
stack = expression;
|
exit(1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
JoyList def_abs_body;
|
JoyList def_abs_body;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue