コード例 #1
0
ファイル: fd.c プロジェクト: krytarowski/mindy
static void maybe_write(struct thread *thread)
{
    obj_t *fp = thread->fp;
    int fd = fixnum_value(fp[-9]);
    int nfound, res;
    obj_t *old_sp;

    nfound = output_writable(fd);
    if (nfound < 0) {
        if (errno != EINTR) {
            old_sp = pop_linkage(thread);
            thread->sp = old_sp + 2;
            old_sp[0] = obj_False;
            old_sp[1] = make_fixnum(errno);
            do_return(thread, old_sp, old_sp);
        } else {
            wait_for_output(thread, fd, maybe_write);
        }
    } else if (nfound == 0)
        wait_for_output(thread, fd, maybe_write);
    else {
                res = write(fd,
                    buffer_data(fp[-8]) + fixnum_value(fp[-7]),
                    fixnum_value(fp[-6]));
                results(thread, pop_linkage(thread), res, make_fixnum(res));
    }
}
コード例 #2
0
ファイル: fd.c プロジェクト: krytarowski/mindy
static void maybe_read(struct thread *thread)
{
    obj_t *fp = thread->fp;
    int fd = fixnum_value(fp[-9]);
    int nfound, res;
    obj_t *old_sp;

    nfound = input_available(fd);
    if (nfound < 0) {
        old_sp = pop_linkage(thread);
        thread->sp = old_sp + 2;
        old_sp[0] = obj_False;
        old_sp[1] = make_fixnum(errno);
        do_return(thread, old_sp, old_sp);
    }
    else if (nfound == 0)
        wait_for_input(thread, fd, maybe_read);
    else {
        res = mindy_read(fd,
                         (char *)(buffer_data(fp[-8]) + fixnum_value(fp[-7])),
                         fixnum_value(fp[-6]));

        results(thread, pop_linkage(thread), res, make_fixnum(res));
    }
}
コード例 #3
0
ファイル: interp.c プロジェクト: krytarowski/mindy
static void call_tail(struct thread *thread, int arg)
{
    obj_t *sp = thread->sp;
    obj_t *stuff = sp - arg - 1;
    obj_t *old_sp = pop_linkage(thread);

    while (stuff < sp)
        *old_sp++ = *stuff++;

    thread->sp = old_sp;

    invoke(thread, arg);
}
コード例 #4
0
ファイル: interp.c プロジェクト: krytarowski/mindy
static void op_dot_tail(int byte, struct thread *thread)
{
    obj_t *sp = thread->sp;
    obj_t arg = sp[-2];
    obj_t func = sp[-1];
    obj_t *old_sp = pop_linkage(thread);

    old_sp[0] = func;
    old_sp[1] = arg;
    thread->sp = old_sp + 2;

    invoke(thread, 1);
}
コード例 #5
0
ファイル: mindy.c プロジェクト: sparkhom/mindy
static void invoke_main(struct thread *thread, obj_t *vals)
{
    obj_t *fp = thread->fp;
    obj_t *args_end = fp - 5;
    obj_t *old_sp = pop_linkage(thread);
    struct variable *var = find_variable(module_BuiltinStuff, symbol("main"),
                                         false, false);

    if (var == NULL)
        lose("main undefined?");

    thread->sp = args_end;
    old_sp[0] = var->value;
    invoke(thread, args_end - old_sp - 1);
}
コード例 #6
0
ファイル: nlx.c プロジェクト: gitter-badger/mindy
MINDY_NORETURN
static void unlink_catch(struct thread *thread, obj_t *vals)
{
    obj_t catch_block;
    obj_t *old_sp;

    /* Unlink and invalidate the current catch block. */
    catch_block = thread->cur_catch;
    thread->cur_catch = obj_ptr(struct catch_block *, catch_block)->prev_catch;
    obj_ptr(struct catch_block *, catch_block)->thread = NULL;
    obj_ptr(struct catch_block *, catch_block)->prev_catch = obj_False;

    /* Return the same values we got. */
    old_sp = pop_linkage(thread);
    do_return(thread, old_sp, vals);
}
コード例 #7
0
ファイル: nlx.c プロジェクト: gitter-badger/mindy
MINDY_NORETURN
static void done_with_cleanup(struct thread *thread, obj_t *cleanup_vals)
{
    obj_t *old_sp, *vals;

    /* Get the pointer to the values from the protected form from the stack.
       We pushed it just before calling the cleanup, so it just below the
       cleanup values. */
    vals = obj_rawptr(cleanup_vals[-1]);

    /* Reset the stack to just after the protected form values. */
    thread->sp = cleanup_vals - 1;

    /* Return those values. */
    old_sp = pop_linkage(thread);
    do_return(thread, old_sp, vals);
}
コード例 #8
0
ファイル: input.c プロジェクト: gitter-badger/mindy
MINDY_NORETURN
static void getc_or_wait(struct thread *thread)
{
    // if (FBUFEMPTYP(stdin) && !feof(stdin)) {
    if (!feof(stdin)) {
        int fd = fileno(stdin);
        int nfound = input_available(fd);

        if (nfound < 0) {
            switch (errno) {
              case EBADF:
                error("Tried to getc with stdin broken.");
              case EINTR:
                wait_for_input(thread, fd, getc_or_wait);
              case EINVAL:
                lose("select failed with EINVAL?");
            }
        }
        else if (nfound == 0)
            wait_for_input(thread, fd, getc_or_wait);
    }

    {
        obj_t *old_sp;
        int c = mindy_getchar();

        old_sp = pop_linkage(thread);

        if (c != EOF)
            *old_sp = int_char(c);
        else
            *old_sp = obj_False;

        thread->sp = old_sp + 1;

        do_return(thread, old_sp, old_sp);
    }
}
コード例 #9
0
ファイル: interp.c プロジェクト: krytarowski/mindy
static void op_return_single(int byte, struct thread *thread)
{
    do_return(thread, pop_linkage(thread), thread->sp - 1);
}