Exemplo n.º 1
0
int main()
{
    hlt_execution_context* ctx = 0;
    hlt_exception* excpt = 0;
    hlt_string s;

    hlt_init();
    ctx = hlt_global_execution_context();

    hlt_port a;

    a = hlt_port_from_asciiz("80/tcp", &excpt, ctx);
    s = hlt_object_to_string(&hlt_type_info_hlt_port, &a, 0, &excpt, ctx);
    hlt_string_print(stdout, s, 1, &excpt, ctx);
    assert(! excpt);

    a = hlt_port_from_asciiz("53/udp", &excpt, ctx);
    s = hlt_object_to_string(&hlt_type_info_hlt_port, &a, 0, &excpt, ctx);
    hlt_string_print(stdout, s, 1, &excpt, ctx);
    assert(! excpt);

    a = hlt_port_from_asciiz("can't parse", &excpt, ctx);
    assert(excpt);

    GC_DTOR(excpt, hlt_exception, ctx);

    return 0;
}
Exemplo n.º 2
0
static hlt_string __exception_render(const hlt_exception* e, hlt_execution_context* ctx)
{
    hlt_exception* excpt = 0;

    if ( ! e )
        return hlt_string_from_asciiz("(Null)", &excpt, ctx);

    hlt_string s = hlt_string_from_asciiz(e->type->name, &excpt, ctx);

    if ( e->arg ) {
        hlt_string arg = hlt_object_to_string(e->type->argtype, e->arg, 0, &excpt, ctx);
        s = hlt_string_concat(s, hlt_string_from_asciiz(" with argument '", &excpt, ctx), &excpt,
                              ctx);
        s = hlt_string_concat(s, arg, &excpt, ctx);
        s = hlt_string_concat(s, hlt_string_from_asciiz("'", &excpt, ctx), &excpt, ctx);
    }

    if ( e->vid != HLT_VID_MAIN ) {
        char buffer[1024];
        snprintf(buffer, sizeof(buffer), " in virtual thread %" PRId64, e->vid);
        s = hlt_string_concat(s, hlt_string_from_asciiz(buffer, &excpt, ctx), &excpt, ctx);
    }

    if ( e->location ) {
        char buffer[1024];
        snprintf(buffer, sizeof(buffer), " (from %s)", e->location);
        s = hlt_string_concat(s, hlt_string_from_asciiz(buffer, &excpt, ctx), &excpt, ctx);
    }

    return s;
}
Exemplo n.º 3
0
static hlt_string _embedded_to_string(const hlt_type_info* type, void* obj, __hlt_pointer_stack* seen, hlt_exception** excpt, hlt_execution_context* ctx)
{
    hlt_string s = hlt_object_to_string(type, obj, 0, excpt, ctx);
    hlt_string prefix = hlt_string_from_asciiz("object(", excpt, ctx);
    s = hlt_string_concat(prefix, s, excpt, ctx);
    s = hlt_string_concat_asciiz(s, ")", excpt, ctx);
    return s;
}
Exemplo n.º 4
0
static hlt_string _optional_to_string(const hlt_type_info* type, void* obj, __hlt_pointer_stack* seen, hlt_exception** excpt, hlt_execution_context* ctx)
{
    hlt_union* u = (hlt_union *)obj;

    void* v = hlt_union_get(u, -1, excpt, ctx);

    if ( ! v )
        return hlt_string_from_asciiz("(not set)", excpt, ctx);

    hlt_union_field f = hlt_union_get_type(type, u, -1, excpt, ctx);
    return hlt_object_to_string(f.type, v, 0, excpt, ctx);
}
Exemplo n.º 5
0
static hlt_string _addr_to_string(const hlt_type_info* type, void* obj, __hlt_pointer_stack* seen, hlt_exception** excpt, hlt_execution_context* ctx)
{
    return hlt_object_to_string(type, obj, 0, excpt, ctx);
}
Exemplo n.º 6
0
static hlt_string _uint_to_string(const hlt_type_info* type, void* obj, __hlt_pointer_stack* seen, hlt_exception** excpt, hlt_execution_context* ctx)
{
    return hlt_object_to_string(type, obj, HLT_CONVERT_UNSIGNED, excpt, ctx);
}