Exemplo n.º 1
0
int main()
{
    printf("%s", banner);

    ctx = mn_create();

    if (!mn_exec_file(ctx, stdfilename)) {
        char *error_message = (char*)mn_error_message();
        printf("Error while reading standard library\n");
        printf("%s", error_message);
        mem_free(error_message);
        mn_destroy(ctx);
        return 1;
    }

    if (!mn_register_clif(ctx, "debug", 0, repl_clif_dbg) ||
            !mn_register_clif(ctx, "quit", 0, repl_clif_quit) ||
            !mn_register_clif(ctx, "load", 1, repl_clif_load)) {
        char *error_message = (char*)mn_error_message();
        printf("Error while setting up REPL environment\n");
        printf("%s", error_message);
        mem_free(error_message);
        mn_destroy(ctx);
        return 1;
    }

    while (!quit_request) {

        char *line;
        struct MoonValue *value;

        if (!(line = repl_read())) {
            printf("Null line read\n");
            break;
        }

        ts_start();
        value = repl_evaluate(line);

        if (mn_error_state()) {
            char *error_message = (char*)mn_error_message();
            printf("%s", error_message);
            mem_free(error_message);

        } else {
            long long time = ts_ustop();
            printf("%s", response_prefix);
            repl_print(value);
            printf("\n%s%lld.%lldms\n\n", time_prefix, time / 1000, time % 1000);
            mn_dispose(value);
        }

        mem_free(line);
    }

    ts_deinit();
    mn_destroy(ctx);
    return 0;
}
Exemplo n.º 2
0
static void deinit(void) {
    // others...
    sb_deinit();
    ti_deinit();
    ts_deinit();
    tl_deinit();
    comm_deinit();
    options_deinit();
}