+'''
+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
#list(open('../defs.txt'))
void
-truthy(JoyListPtr stack, JoyListPtr expression)
+truthy(JoyListPtr stack, __attribute__((unused)) JoyListPtr expression)
{
- stack = expression;
-}
-/*
- JoyListPtr s = stack;
+ /*
+ Keep the original stack in case the top item is already a Boolean value.
+ */
+ JoyList s = *stack;
JoyList node = pop_any(stack);
switch (node->head->kind) {
case joyTrue:
- stack = s;
+ *stack = s;
+ break;
case joyFalse:
- stack = s;
+ *stack = s;
+ break;
case joyInt:
- push_thing(
- if (node->head->value.i);
+ if mpz_cmp_si(node->head->value.i, 0) {
+ 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:
-
- stack = expression;
+ printf("Cannot Boolify.\n");
+ exit(1);
+ }
}
-*/
JoyList def_abs_body;