示例#1
0
文件: log.c 项目: Revlin/MoarVM
static char * jitcode_name(MVMThreadContext *tc, MVMJitCode *code) {
    MVMuint64 cuuid_len;
    MVMuint64 name_len;
    MVMuint8 *cuuid = MVM_string_ascii_encode(tc, code->sf->body.cuuid,
                                              &cuuid_len);
    MVMuint8 *name  = MVM_string_ascii_encode(tc, code->sf->body.name,
                                              &name_len);
    MVMuint64 dirname_len = strlen(tc->instance->jit_bytecode_dir);
    // 4 chars for prefix, 3 chars for the separators, 4 for the postfix, 1 for the 0
    char *filename = MVM_malloc(dirname_len + name_len + cuuid_len + 12);
    char *dst = filename;
    memcpy(dst, tc->instance->jit_bytecode_dir, dirname_len);
    dst[dirname_len] = '/';
    dst += dirname_len + 1;
    memcpy(dst, "jit-", 4);
    dst += 4;
    memcpy(dst, cuuid, cuuid_len);
    dst[cuuid_len] = '.';
    dst += cuuid_len + 1;
    memcpy(dst, name, name_len);
    dst += name_len;
    memcpy(dst, ".bin", 5);
    MVM_free(name);
    MVM_free(cuuid);
    return filename;
}
示例#2
0
MVMint32 MVM_unicode_name_to_property_code(MVMThreadContext *tc, MVMString *name) {
    MVMuint64 size;
    unsigned char *cname = MVM_string_ascii_encode(tc, name, &size);
    MVMUnicodeNameHashEntry *result;
    if (!property_codes_by_names_aliases) {
        generate_property_codes_by_names_aliases(tc);
    }
    HASH_FIND(hash_handle, property_codes_by_names_aliases, cname, strlen((const char *)cname), result);
    free(cname); /* not really codepoint, really just an index */
    return result ? result->codepoint : 0;
}
示例#3
0
/* Looks up a codepoint by name. Lazily constructs a hash. */
MVMCodepoint32 MVM_unicode_lookup_by_name(MVMThreadContext *tc, MVMString *name) {
    MVMuint64 size;
    unsigned char *cname = MVM_string_ascii_encode(tc, name, &size);
    MVMUnicodeNameHashEntry *result;
    if (!codepoints_by_name) {
        generate_codepoints_by_name(tc);
    }
    HASH_FIND(hash_handle, codepoints_by_name, cname, strlen((const char *)cname), result);
    free(cname);
    return result ? result->codepoint : -1;
}
示例#4
0
MVMint32 MVM_unicode_name_to_property_value_code(MVMThreadContext *tc, MVMint64 property_code, MVMString *name) {
    MVMuint64 size;
    unsigned char *cname = MVM_string_ascii_encode(tc, name, &size);
    MVMUnicodeNameHashEntry *result;

    if (property_code < 0 || property_code >= MVMNUMPROPERTYCODES)
        return 0;

    if (!unicode_property_values_hashes) {
        generate_unicode_property_values_hashes(tc);
    }
    HASH_FIND(hash_handle, unicode_property_values_hashes[property_code], cname, strlen((const char *)cname), result);
    free(cname); /* not really codepoint, really just an index */
    return result ? result->codepoint : 0;
}
示例#5
0
文件: coerce.c 项目: krunen/MoarVM
MVMnum64 MVM_coerce_s_n(MVMThreadContext *tc, MVMString *s) {
    char     *enc = MVM_string_ascii_encode(tc, s, NULL);
    MVMnum64  n;
    if (strcmp(enc, "NaN") == 0)
        n = MVM_num_nan(tc);
    else if (strcmp(enc, "Inf") == 0)
        n = MVM_num_posinf(tc);
    else if (strcmp(enc, "+Inf") == 0)
        n = MVM_num_posinf(tc);
    else if (strcmp(enc, "-Inf") == 0)
        n = MVM_num_neginf(tc);
    else
        n = atof(enc);
    MVM_free(enc);
    return n;
}
示例#6
0
文件: coerce.c 项目: krunen/MoarVM
MVMint64 MVM_coerce_s_i(MVMThreadContext *tc, MVMString *s) {
    char     *enc = MVM_string_ascii_encode(tc, s, NULL);
    MVMint64  i   = strtoll(enc, NULL, 10);
    MVM_free(enc);
    return i;
}
示例#7
0
文件: ascii.c 项目: dagurval/MoarVM
/* Encodes the specified string to ASCII not returning length.  */
MVMuint8 * MVM_string_ascii_encode_any(MVMThreadContext *tc, MVMString *str) {
    MVMuint64 output_size;
    return MVM_string_ascii_encode(tc, str, &output_size);
}
示例#8
0
MVMnum64 MVM_coerce_s_n(MVMThreadContext *tc, MVMString *s) {
    char     *enc = MVM_string_ascii_encode(tc, s, NULL);
    MVMnum64  n   = atof(enc);
    free(enc);
    return n;
}