void repl_init() { char input[INPUT_SIZE] = ""; printf("%s", ">>> "); init_system(); symboltable_t* context = newSymbolTable(); while (EXIT_STATUS == 0 && fgets(input, INPUT_SIZE, stdin)) { list_t* expressions = parse(input)->value->value.l; object_t* value = eval(expressions, context); object_t* o = z_list(); z_conj(o->value->value.l, value); z_println(o->value->value.l); free(expressions); if (EXIT_STATUS == 0) { printf("%s", ">>> "); } } }
object_t* z_print(list_t* args) { object_t* obj = newObject(); object_t* o = z_first(args); struct atom *atom; if(o == NULL) { printf("undefined"); return obj; } switch(o->value->type) { case Int: printf("%d", o->value->value.i); return obj; case Float: printf("%f", o->value->value.f); return obj; case Char: printf("%c", o->value->value.c); return obj; case String: printf("%s",o->value->value.s); return obj; case Bool: if(o->value->value.b) { printf("True"); } else { printf("False"); } return obj; case List: atom = o->value->value.l->head; printf("( "); while (atom != NULL) { object_t *l = z_list(); z_conj(l->value->value.l, atom->value); z_print(l->value->value.l); printf(" "); atom = atom->next; } printf(")"); return obj; case Exception: printf("<Exception Object>"); return obj; case Function: if (o->value->value.function->body != NULL) { printf("<Function Object> ( %s ", o->value->value.function->name); atom = o->value->value.function->args->head; printf("( "); while (atom != NULL) { object_t *l = z_list(); z_conj(l->value->value.l, atom->value); z_print(l->value->value.l); printf(" "); atom = atom->next; } printf(") "); atom = o->value->value.function->body->head; printf("( "); while (atom != NULL) { object_t *l = z_list(); z_conj(l->value->value.l, atom->value); z_print(l->value->value.l); printf(" "); atom = atom->next; } printf(") )"); } else { printf("<Native Function Object>"); } return obj; case FunctionReference: printf("%s",o->value->value.s); return obj; case Symbol: printf("%s", o->value->value.s); return obj; } printf("<object> @ %d", o->id); }