Skip to content

Is it possible to change the value type ? #27

Description

@kdilayer

I'm new to libjit ... so a question:

Is it possible to return different value types from different branches in the same function or block?

In the example below I have used internal types but in my real case I would be using custom tagged types.

See example below - and I found this example in the archives: (https://lists.gnu.org/archive/html/libjit/2021-07/msg00001.html)

top--;
jit_insn_branch_if_not(function, stack[top], &label1);

jit_value_t common = jit_value_create(function, jit_type_int);  /*** dont know which type will be return yet*/

/* true */
tmp = jit_value_create_float64_constant(function, jit_type_float64, 100); /*** this branch will return jit_type_float64*/
jit_insn_store(function, common, tmp);

/* go to end */
jit_insn_branch(function, &label2);

/* label1 */
jit_insn_label(function, &label1);

/* false */
tmp = jit_value_create_nint_constant(function, jit_type_int, 200); /**** this branch will return jit_type_int*/
jit_insn_store(function, common, tmp);

/* label2 end */
jit_insn_label(function, &label2);

/* fill the stack top */
stack[top] = jit_insn_load(function, common);
top++;

/* return */
top--;
jit_insn_return(function, stack[top]);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions