The base class of expression is the gcc_jit_rvalue *, representing an expression that can be on the `right'-hand side of an assignment: a value that can be computed somehow, and assigned `to' a storage area (such as a variable). It has a specific gcc_jit_type *.
Anothe important class is gcc_jit_lvalue *. A gcc_jit_lvalue *. is something that can of the `left'-hand side of an assignment: a storage area (such as a variable).
In other words, every assignment can be thought of as:
LVALUE = RVALUE;
Note that gcc_jit_lvalue * is a subclass of gcc_jit_rvalue *, where in an assignment of the form:
LVALUE_A = LVALUE_B;
the LVALUE_B implies reading the current value of that storage area, assigning it into the LVALUE_A.
So far the only expressions we’ve seen are i * i:
gcc_jit_rvalue *expr = gcc_jit_context_new_binary_op ( ctxt, NULL, GCC_JIT_BINARY_OP_MULT, int_type, gcc_jit_param_as_rvalue (param_i), gcc_jit_param_as_rvalue (param_i));
which is a gcc_jit_rvalue *, and the various function parameters: param_i and param_n, instances of gcc_jit_param *, which is a subclass of gcc_jit_lvalue * (and, in turn, of gcc_jit_rvalue *): we can both read from and write to function parameters within the body of a function.
Our new example has a couple of local variables. We create them by calling gcc_jit_function_new_local(), supplying a type and a name:
/* Build locals: */ gcc_jit_lvalue *i = gcc_jit_function_new_local (func, NULL, the_type, "i"); gcc_jit_lvalue *sum = gcc_jit_function_new_local (func, NULL, the_type, "sum");
These are instances of gcc_jit_lvalue * - they can be read from and written to.
Note that there is no precanned way to create `and' initialize a variable like in C:
int i = 0;
Instead, having added the local to the function, we have to separately add an assignment of 0 to local_i at the beginning of the function.