Beispiel #1
0
void throw_stopiter()
{
    if (fg->error != VALUE_NULL) {
        unref(fg->error);
    }
    fg->error = vp_Value(ref_new(fs->cls_stopiter));
}
Beispiel #2
0
static int textio_new(Value *vret, Value *v, RefNode *node)
{
    RefTextIO *tio;
    RefCharset *cs = Value_vp(v[2]);
    Ref *r = ref_new(fs->cls_textio);
    *vret = vp_Value(r);

    tio = buf_new(NULL, sizeof(RefTextIO));
    r->v[INDEX_TEXTIO_TEXTIO] = vp_Value(tio);
    r->v[INDEX_TEXTIO_STREAM] = Value_cp(v[1]);

    tio->in.ic = (void*)-1;
    tio->out.ic = (void*)-1;
    tio->cs = cs;
    tio->trans = FALSE;

    if (fg->stk_top > v + 3 && Value_bool(v[3])) {
        tio->trans = TRUE;
    }
    if (fg->stk_top > v + 4) {
        r->v[INDEX_TEXTIO_NEWLINE] = Value_cp(v[4]);
    }

    return TRUE;
}
Beispiel #3
0
static int mapentry_new(Value *vret, Value *v, RefNode *node)
{
    Ref *r = ref_new(fv->cls_entry);
    *vret = vp_Value(r);
    r->v[INDEX_ENTRY_KEY] = Value_cp(v[1]);
    r->v[INDEX_ENTRY_VAL] = Value_cp(v[2]);
    return TRUE;
}
Beispiel #4
0
static void v_ctextio_init(void)
{
    Ref *ref = ref_new(fs->cls_textio);

    fg->v_ctextio = vp_Value(ref);
    ref->v[INDEX_TEXTIO_STREAM] = Value_cp(fg->v_cio);
    ref->v[INDEX_TEXTIO_TEXTIO] = vp_Value(fv->ref_textio_utf8);
}
Beispiel #5
0
static int strio_dup(Value *vret, Value *v, RefNode *node)
{
    RefBytesIO *src = Value_bytesio(*v);
    Ref *r = ref_new(fv->cls_strio);

    *vret = vp_Value(r);
    r->v[INDEX_TEXTIO_STREAM] = vp_Value(bytesio_new_sub(src->buf.p, src->buf.size));
    r->v[INDEX_TEXTIO_TEXTIO] = vp_Value(fv->ref_textio_utf8);

    return TRUE;
}
Beispiel #6
0
int map_iterator(Value *vret, Value *v, RefNode *node)
{
    RefMap *rm = Value_vp(*v);
    int type = FUNC_INT(node);
    Ref *r = ref_new(cls_mapiter);

    rm->lock_count++;
    r->v[INDEX_MAPITER_VAL] = Value_cp(*v);
    r->v[INDEX_MAPITER_TYPE] = int32_Value(type);
    r->v[INDEX_MAPITER_PTR] = ptr_Value(NULL);
    r->v[INDEX_MAPITER_IDX] = int32_Value(0);
    *vret = vp_Value(r);

    return TRUE;
}
Beispiel #7
0
static int strio_new(Value *vret, Value *v, RefNode *node)
{
    RefStr *src;
    Ref *r = ref_new(fv->cls_strio);

    *vret = vp_Value(r);

    if (fg->stk_top > v + 1) {
        src = Value_vp(v[1]);
    } else {
        src = fs->str_0;
    }
    r->v[INDEX_TEXTIO_STREAM] = vp_Value(bytesio_new_sub(src->c, src->size));
    r->v[INDEX_TEXTIO_TEXTIO] = vp_Value(fv->ref_textio_utf8);

    return TRUE;
}
Beispiel #8
0
void init_stdio()
{
    RefFileHandle *fh;
    Ref *r = ref_new(fv->cls_fileio);
    fg->v_cio = vp_Value(r);

    init_stream_ref(r, STREAM_READ|STREAM_WRITE);

    STDIN_FILENO = (FileHandle)GetStdHandle(STD_INPUT_HANDLE);
    STDOUT_FILENO = (FileHandle)GetStdHandle(STD_OUTPUT_HANDLE);
    STDERR_FILENO = (FileHandle)GetStdHandle(STD_ERROR_HANDLE);

    fh = buf_new(NULL, sizeof(RefFileHandle));
    r->v[INDEX_FILEIO_HANDLE] = vp_Value(fh);
    fh->fd_read = STDIN_FILENO;
    fh->fd_write = STDOUT_FILENO;

    fv->console_read = FALSE;
    fv->console_write = FALSE;
    fv->console_error = FALSE;
}
Beispiel #9
0
static int mapiter_next(Value *vret, Value *v, RefNode *node)
{
    Ref *r = Value_ref(*v);
    RefMap *map = Value_vp(r->v[INDEX_MAPITER_VAL]);
    int idx = Value_integral(r->v[INDEX_MAPITER_IDX]);
    HashValueEntry *ep = Value_ptr(r->v[INDEX_MAPITER_PTR]);

    if (ep != NULL) {
        ep = ep->next;
    }
    while (ep == NULL && idx < map->entry_num) {
        ep = map->entry[idx];
        idx++;
    }

    r->v[INDEX_MAPITER_IDX] = int32_Value(idx);
    r->v[INDEX_MAPITER_PTR] = ptr_Value(ep);

    if (ep != NULL) {
        switch (Value_integral(r->v[INDEX_MAPITER_TYPE])) {
        case ITERATOR_KEY:
            *vret = Value_cp(ep->key);
            break;
        case ITERATOR_VAL:
            *vret = Value_cp(ep->val);
            break;
        default: {
            Ref *r2 = ref_new(fv->cls_entry);
            *vret = vp_Value(r2);
            r2->v[INDEX_ENTRY_KEY] = Value_cp(ep->key);
            r2->v[INDEX_ENTRY_VAL] = Value_cp(ep->val);
            break;
        }
        }
    } else {
        throw_stopiter();
        return FALSE;
    }
    return TRUE;
}
Beispiel #10
0
void throw_error_vprintf(RefNode *err_m, const char *err_name, const char *fmt, va_list va)
{
    RefNode *err = Hash_get_p(&err_m->u.m.h, intern(err_name, -1));
    Ref *r;

    if (err == NULL) {
        const RefStr *m = err_m->name;
        fatal_errorf("ClassNotFound:%r.%s", m, err_name);
    }

    if (fg->error != VALUE_NULL) {
        unref(fg->error);
    }
    r = ref_new(err);
    fg->error = vp_Value(r);

    if (fmt != NULL) {
        StrBuf msg;
        StrBuf_init_refstr(&msg, 0);
        StrBuf_vprintf(&msg, fmt, va);
        r->v[1] = StrBuf_str_Value(&msg, fs->cls_str);
    }
}