Example #1
0
int main(void)
{
    message_queue *q = mq_create();
    message_node  *n = NULL;
    printf("size should be 0, is %d\n", mq_size(q));
    mq_push_msgz(q, "one");
    mq_push_msgz(q, "two");
    mq_push_msgz(q, "three");
    printf("size should be 3, is %d\n", mq_size(q));
    n = mq_pop(q);
    printf("expecting \"one\", got \"%s\"\n", n->message);
    mn_destroy(n);
    mq_push_msgz(q, "four");
    n = mq_pop(q);
    printf("expecting \"two\", got \"%s\"\n", n->message);
    mn_destroy(n);
    n = mq_pop(q);
    printf("expecting \"three\", got \"%s\"\n", n->message);
    mn_destroy(n);
    printf("size should be 1, is %d\n", mq_size(q));
    n = mq_pop(q);
    printf("expecting \"four\", got \"%s\"\n", n->message);
    mn_destroy(n);
    printf("size should be 0, is %d\n", mq_size(q));
    n = mq_pop(q);
    printf("expecting \"%p\", got \"%p\"\n", NULL, n);
    mq_destroy(q);
    return 0;
}
Example #2
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;
}
Example #3
0
void MoonContextDeleter::operator()(MoonContext *ctx)
{
    mn_destroy(ctx);
}