Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 202
PieterV Avatar asked Feb 16 '14 13:02

PieterV


1 Answers

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.

like image 134
ivarne Avatar answered Sep 29 '22 07:09

ivarne