PieterV
PieterV

Reputation: 836

The meaning of jl_value_t in julia source code

I'm trying to find my way around the Julia source code, namely codegen.cpp. They use a struct jl_value_t which refers to itself:

#define JL_DATA_TYPE \
    struct _jl_value_t *type;

typedef struct _jl_value_t {
    JL_DATA_TYPE
} jl_value_t;

When debugging the source code in eclipse, this doesn't seem to contain any useful information, however it is used very often. How should I interpret this struct? What information does it contain?

Upvotes: 8

Views: 431

Answers (1)

ivarne
ivarne

Reputation: 3783

To me it seems like a (dirty) trick to be able to write dynamic code in C. All boxed Julia values can have their own memory layout, as long as they start with a pointer to a type, so that the C code can check the type before accessing any of the other fields the type defines.

There are convenience functions to check some common types a jl_value_t* might point to. (eg. jl_is_type(v), jl_is_long(v), jl_is_symbol(v), jl_is_typevar(v), jl_is_bool(v)). When you know the type of the object pointed to you can cast the pointer to the correct struct from src/julia.h.

Upvotes: 11

Related Questions