Exemple #1
0
/**
 * key同士を比較
 */
static int mapentry_cmp(Value *vret, Value *v, RefNode *node)
{
    Value v1 = v[0];
    Value v2 = v[1];
    Value vr;

    Value_push("vv", Value_ref(v1)->v[INDEX_ENTRY_KEY], Value_ref(v2)->v[INDEX_ENTRY_KEY]);
    if (!call_member_func(fs->symbol_stock[T_CMP], 1, TRUE)) {
        return FALSE;
    }

    vr = fg->stk_top[-1];
    if (Value_isint(vr) && Value_integral(vr) == 0) {
        Value_pop();
        // keyが同じなら、valueを比較
        Value_push("vv", Value_ref(v1)->v[INDEX_ENTRY_VAL], Value_ref(v2)->v[INDEX_ENTRY_VAL]);
        if (!call_member_func(fs->symbol_stock[T_CMP], 1, TRUE)) {
            return FALSE;
        }
    }
    *vret = fg->stk_top[-1];
    fg->stk_top--;

    return TRUE;
}
Exemple #2
0
static int textio_print_sub(Value v_textio, StrBuf *sb, Value v, Ref *r_loc)
{
    RefNode *v_type = Value_type(v);
    int result = TRUE;
    Value vb;
    RefTextIO *tio;

    if (v_textio != VALUE_NULL) {
        Ref *ref = Value_ref(v_textio);
        vb = ref->v[INDEX_TEXTIO_STREAM];
        tio = Value_vp(ref->v[INDEX_TEXTIO_TEXTIO]);
    } else {
        vb = VALUE_NULL;
        tio = NULL;
    }

    // よく使う型
    if (Value_isint(v)) {
        char c_buf[32];
        sprintf(c_buf, "%d", Value_integral(v));
        if (!stream_write_sub_s(vb, sb, c_buf, -1, tio)) {
            result = FALSE;
        }
    } else if (v_type == fs->cls_int) {
        RefInt *mp = Value_vp(v);
        char *c_buf = malloc(BigInt_str_bufsize(&mp->bi, 10));
        BigInt_str(&mp->bi, 10, c_buf, FALSE);
        if (!stream_write_sub_s(vb, sb, c_buf, -1, tio)) {
            result = FALSE;
        }
        free(c_buf);
    } else if (v_type == fs->cls_str) {
        RefStr *rs = Value_vp(v);
        if (!stream_write_sub_s(vb, sb, rs->c, rs->size, tio)) {
            result = FALSE;
        }
    } else if (v_type == fv->cls_strio) {
        RefBytesIO *mb = Value_bytesio(v);
        if (!stream_write_sub_s(vb, sb, mb->buf.p, mb->buf.size, tio)) {
            result = FALSE;
        }
    } else if (v_type == fs->cls_module) {
        RefNode *nd = Value_vp(v);
        RefStr *rs = nd->name;
        if (!stream_write_sub_s(vb, sb, "Module(", 7, tio)) {
            return FALSE;
        }
        if (!stream_write_sub_s(vb, sb, rs->c, rs->size, tio)) {
            return FALSE;
        }
        if (!stream_write_sub_s(vb, sb, ")", 1, tio)) {
            return FALSE;
        }
    } else if (v_type != fs->cls_null) {
        Value vret;
        fs->Value_push("v", v);
        if (!call_member_func(fs->str_tostr, 0, TRUE)) {
            return FALSE;
        }
        vret = fg->stk_top[-1];
        if (Value_type(vret) == fs->cls_str) {
            RefStr *rs = Value_vp(vret);
            if (!stream_write_sub_s(vb, sb, rs->c, rs->size, tio)) {
                return FALSE;
            }
        } else {
        }
        Value_pop();
    }
    return result;
}