Exemplo n.º 1
0
void
crb_runtime_error(int line_number, RuntimeError id, ...)
{
    va_list     ap;
    VString     message;

    self_check();
    va_start(ap, id);
    crb_vstr_clear(&message);
    format_message(&crb_runtime_error_message_format[id],
                   &message, ap);
    fprintf(stderr, "%3d:%s\n", line_number, message.string);
    va_end(ap);

    exit(1);
}
Exemplo n.º 2
0
void
crb_compile_error(CompileError id, ...)
{
    va_list     ap;
    VString     message;
    int         line_number;

    self_check();
    va_start(ap, id);
    line_number = crb_get_current_interpreter()->current_line_number;
    crb_vstr_clear(&message);
    format_message(&crb_compile_error_message_format[id],
                   &message, ap);
    fprintf(stderr, "%3d:%s\n", line_number, message.string);
    va_end(ap);

    exit(1);
}
Exemplo n.º 3
0
Arquivo: util.c Projeto: BluePanM/code
CRB_Char *
CRB_value_to_string(CRB_Value *value)
{
    VString     vstr;
    char        buf[LINE_BUF_SIZE];
    CRB_Char    wc_buf[LINE_BUF_SIZE];
    int         i;

    crb_vstr_clear(&vstr);

    switch (value->type) {
    case CRB_BOOLEAN_VALUE:
        if (value->u.boolean_value) {
            CRB_mbstowcs("true", wc_buf);
        } else {
            CRB_mbstowcs("false", wc_buf);
        }
        crb_vstr_append_string(&vstr, wc_buf);
        break;
    case CRB_INT_VALUE:
        sprintf(buf, "%d", value->u.int_value);
        CRB_mbstowcs(buf, wc_buf);
        crb_vstr_append_string(&vstr, wc_buf);
        break;
    case CRB_DOUBLE_VALUE:
        sprintf(buf, "%f", value->u.double_value);
        CRB_mbstowcs(buf, wc_buf);
        crb_vstr_append_string(&vstr, wc_buf);
        break;
    case CRB_STRING_VALUE:
        crb_vstr_append_string(&vstr, value->u.object->u.string.string);
        break;
    case CRB_NATIVE_POINTER_VALUE:
        sprintf(buf, "(%s:%p)",
                value->u.native_pointer.info->name,
                value->u.native_pointer.pointer);
        CRB_mbstowcs(buf, wc_buf);
        crb_vstr_append_string(&vstr, wc_buf);
        break;
    case CRB_NULL_VALUE:
        CRB_mbstowcs("null", wc_buf);
        crb_vstr_append_string(&vstr, wc_buf);
        break;
    case CRB_ARRAY_VALUE:
        CRB_mbstowcs("(", wc_buf);
        crb_vstr_append_string(&vstr, wc_buf);
        for (i = 0; i < value->u.object->u.array.size; i++) {
            CRB_Char *new_str;
            if (i > 0) {
                CRB_mbstowcs(", ", wc_buf);
                crb_vstr_append_string(&vstr, wc_buf);
            }
            new_str = CRB_value_to_string(&value->u.object->u.array.array[i]);
            crb_vstr_append_string(&vstr, new_str);
            MEM_free(new_str);
        }
        CRB_mbstowcs(")", wc_buf);
        crb_vstr_append_string(&vstr, wc_buf);
        break;
    default:
        DBG_panic(("value->type..%d\n", value->type));
    }

    return vstr.string;
}
Exemplo n.º 4
0
CRB_Char *
CRB_value_to_string(CRB_Interpreter *inter, CRB_LocalEnvironment *env,
                    int line_number, CRB_Value *value)
{
    VString     vstr;
    char        buf[LINE_BUF_SIZE];
    CRB_Char    wc_buf[LINE_BUF_SIZE];
    int         i;

    crb_vstr_clear(&vstr);

    switch (value->type) {
    case CRB_BOOLEAN_VALUE:
        if (value->u.boolean_value) {
            CRB_mbstowcs("true", wc_buf);
        } else {
            CRB_mbstowcs("false", wc_buf);
        }
        crb_vstr_append_string(&vstr, wc_buf);
        break;
    case CRB_INT_VALUE:
        sprintf(buf, "%d", value->u.int_value);
        CRB_mbstowcs(buf, wc_buf);
        crb_vstr_append_string(&vstr, wc_buf);
        break;
    case CRB_DOUBLE_VALUE:
        sprintf(buf, "%f", value->u.double_value);
        CRB_mbstowcs(buf, wc_buf);
        crb_vstr_append_string(&vstr, wc_buf);
        break;
    case CRB_STRING_VALUE:
        crb_vstr_append_string(&vstr, value->u.object->u.string.string);
        break;
    case CRB_NATIVE_POINTER_VALUE:
        sprintf(buf, "%s(%p)", value->u.object->u.native_pointer.info->name,
                value->u.object->u.native_pointer.pointer);
        CRB_mbstowcs(buf, wc_buf);
        crb_vstr_append_string(&vstr, wc_buf);
        break;
    case CRB_NULL_VALUE:
        CRB_mbstowcs("null", wc_buf);
        crb_vstr_append_string(&vstr, wc_buf);
        break;
    case CRB_ARRAY_VALUE:
        CRB_mbstowcs("(", wc_buf);
        crb_vstr_append_string(&vstr, wc_buf);
        for (i = 0; i < value->u.object->u.array.size; i++) {
            CRB_Char *new_str;
            if (i > 0) {
                CRB_mbstowcs(", ", wc_buf);
                crb_vstr_append_string(&vstr, wc_buf);
            }
            new_str = CRB_value_to_string(inter, env, line_number,
                                          &value->u.object->u.array.array[i]);
            crb_vstr_append_string(&vstr, new_str);
            MEM_free(new_str);
        }
        CRB_mbstowcs(")", wc_buf);
        crb_vstr_append_string(&vstr, wc_buf);
        break;
    case CRB_ASSOC_VALUE:
        CRB_mbstowcs("(", wc_buf);
        crb_vstr_append_string(&vstr, wc_buf);
        for (i = 0; i < value->u.object->u.assoc.member_count; i++) {
            CRB_Char *new_str;
            if (i > 0) {
                CRB_mbstowcs(", ", wc_buf);
                crb_vstr_append_string(&vstr, wc_buf);
            }
            new_str
                = CRB_mbstowcs_alloc(inter, env, line_number,
                                     value->u.object->u.assoc.member[i].name);
            DBG_assert(new_str != NULL, ("new_str is null.\n"));
            crb_vstr_append_string(&vstr, new_str);
            MEM_free(new_str);

            CRB_mbstowcs("=>", wc_buf);
            crb_vstr_append_string(&vstr, wc_buf);
            new_str = CRB_value_to_string(inter, env, line_number,
                                          &value->u.object
                                          ->u.assoc.member[i].value);
            crb_vstr_append_string(&vstr, new_str);
            MEM_free(new_str);
        }
        CRB_mbstowcs(")", wc_buf);
        crb_vstr_append_string(&vstr, wc_buf);
        break;
    case CRB_CLOSURE_VALUE:
        CRB_mbstowcs("closure(", wc_buf);
        crb_vstr_append_string(&vstr, wc_buf);
        if (value->u.closure.function->name == NULL) {
            CRB_mbstowcs("null", wc_buf);
            crb_vstr_append_string(&vstr, wc_buf);
        } else {
            CRB_Char *new_str;
            
            new_str = CRB_mbstowcs_alloc(inter, env, line_number,
                                         value->u.closure.function->name);
            DBG_assert(new_str != NULL, ("new_str is null.\n"));
            crb_vstr_append_string(&vstr, new_str);
            MEM_free(new_str);
        }
        CRB_mbstowcs(")", wc_buf);
        crb_vstr_append_string(&vstr, wc_buf);
        break;
    case CRB_FAKE_METHOD_VALUE:
        CRB_mbstowcs("fake_method(", wc_buf);
        crb_vstr_append_string(&vstr, wc_buf);
        {
            CRB_Char *new_str;

            new_str = CRB_mbstowcs_alloc(inter, env, line_number,
                                         value->u.fake_method.method_name);
            DBG_assert(new_str != NULL, ("new_str is null.\n"));
            crb_vstr_append_string(&vstr, new_str);
            MEM_free(new_str);
        }
        CRB_mbstowcs(")", wc_buf);
        crb_vstr_append_string(&vstr, wc_buf);
        break;
    case CRB_SCOPE_CHAIN_VALUE: /* FALLTHRU*/
    default:
        DBG_panic(("value->type..%d\n", value->type));
    }

    return vstr.string;
}