Esempio n. 1
0
static int textio_next(Value *vret, Value *v, RefNode *node)
{
    Ref *ref = Value_ref(*v);

    if (!textio_gets_sub(vret, ref, TRUE)) {
        return FALSE;
    }
    if (!Value_bool(*vret)) {
        throw_stopiter();
        return FALSE;
    }
    return TRUE;
}
Esempio n. 2
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;
}