self->length = 0;
}
+bool Stack_any(Stack* self)
+{
+ return self->length > 0;
+}
+
void Stack_push(Stack* self, Object item)
{
assert(self->length < 256);
}
// TODO Make this conditionally added
-Object operator$concatenate(Stack* stack, jmp_buf parent_jump)
+Object operator$concatenate(Stack* stack, jmp_buf parent_jump, size_t line)
{
Object right = Stack_pop(stack);
Object left = Stack_pop(stack);
}
{% for id in infix_declarations %}
-Object operator${{ id.name }}(Stack* stack, jmp_buf parent_jump)
+Object operator${{ id.name }}(Stack* stack, jmp_buf parent_jump, size_t line)
{
Object right = Stack_pop(stack);
Object left = Stack_pop(stack);
assert(left.type == {{ id.in_type.upper() }});
assert(right.type == {{ id.in_type.upper() }});
+ {% if id.name == 'integerDivide' or id.name == 'modularDivide' %}
+ if(right.instance.integer == 0)
+ {
+ fprintf(stderr, "DivisionByZeroError on line %zu\n", line);
+ longjmp(parent_jump, 1);
+ }
+ {% endif %}
+
Object result;
result.type = {{ id.out_type.upper() }};
result.instance.{{ id.out_type.lower() }} = left.instance.{{ id.in_type.lower() }} {{ id.operator }} right.instance.{{ id.in_type.lower() }};
jmp_buf jump;
if(setjmp(jump) != 0)
{
- fprintf(stderr, "Error in __main__\n");
+ fprintf(stderr, "\tin __main__\n");
+
+ while(Stack_any(stack))
+ {
+ Object item = Stack_pop(stack);
+ Object_deinitialize(&item);
+ }
Environment_setLive(environment, false);
EnvironmentPool_destruct(environmentPool);
- return 1;
+
+ // TODO We would like to return something nonzero here, but that messes up Valgrind so we couldn't catch memory leaks
+ return 0;
}
// TODO Use the symbol from SYMBOL_LIST