// File: /workspace/github_c_makefile_star2_O2/vtereshkov[P]umka-lang/src/umka_const.c
// Function: constDeref
void constDeref(const Consts *consts, Const *constant, TypeKind typeKind)
{
    if (!constant->ptrVal)
        consts->error->handler(consts->error->context, "Pointer is null");

    switch (typeKind)
    {
        case TYPE_INT8:         constant->intVal     = *(int8_t         *)constant->ptrVal; break;
        case TYPE_INT16:        constant->intVal     = *(int16_t        *)constant->ptrVal; break;
        case TYPE_INT32:        constant->intVal     = *(int32_t        *)constant->ptrVal; break;
        case TYPE_INT:          constant->intVal     = *(int64_t        *)constant->ptrVal; break;
        case TYPE_UINT8:        constant->intVal     = *(uint8_t        *)constant->ptrVal; break;
        case TYPE_UINT16:       constant->intVal     = *(uint16_t       *)constant->ptrVal; break;
        case TYPE_UINT32:       constant->intVal     = *(uint32_t       *)constant->ptrVal; break;
        case TYPE_UINT:         constant->uintVal    = *(uint64_t       *)constant->ptrVal; break;
        case TYPE_BOOL:         constant->intVal     = *(bool           *)constant->ptrVal; break;
        case TYPE_CHAR:         constant->intVal     = *(unsigned char  *)constant->ptrVal; break;
        case TYPE_REAL32:       constant->realVal    = *(float          *)constant->ptrVal; break;
        case TYPE_REAL:         constant->realVal    = *(double         *)constant->ptrVal; break;
        case TYPE_PTR:          constant->ptrVal     = *(void *         *)constant->ptrVal; break;
        case TYPE_WEAKPTR:      constant->weakPtrVal = *(uint64_t       *)constant->ptrVal; break;
        case TYPE_STR:          constant->ptrVal     = *(void *         *)constant->ptrVal; break;
        case TYPE_ARRAY:
        case TYPE_DYNARRAY:
        case TYPE_STRUCT:
        case TYPE_INTERFACE:
        case TYPE_CLOSURE:      break;  // Always represented by pointer, not dereferenced
        case TYPE_FIBER:        constant->ptrVal     = *(void *         *)constant->ptrVal; break;
        case TYPE_FN:           constant->intVal     = *(int64_t        *)constant->ptrVal; break;

        default:                consts->error->handler(consts->error->context, "Illegal type"); return;
    }
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
movl %edx, %r15d
movq %rsi, %rbx
movq %rdi, %r14
cmpq $0x0, (%rsi)
jne 0x6160
movq (%r14), %rcx
movq 0x20(%rcx), %rdi
leaq 0x63ea4(%rip), %rsi     # 0x6a000
xorl %eax, %eax
callq *(%rcx)
addl $-0x4, %r15d
cmpl $0x16, %r15d
ja 0x61a2
leaq 0x63a77(%rip), %rax     # 0x69be8
movslq (%rax,%r15,4), %rcx
addq %rax, %rcx
jmpq *%rcx
movq (%rbx), %rax
movq (%rax), %rax
jmp 0x61d4
movq (%rbx), %rax
movzbl (%rax), %eax
jmp 0x61d4
movq (%rbx), %rax
movzwl (%rax), %eax
jmp 0x61d4
movq (%rbx), %rax
movsd (%rax), %xmm0
jmp 0x61e4
movq (%rbx), %rax
movl (%rax), %eax
jmp 0x61d4
movq (%r14), %rax
movq (%rax), %rcx
movq 0x20(%rax), %rdi
leaq 0x63e5d(%rip), %rsi     # 0x6a010
xorl %eax, %eax
popq %rbx
popq %r14
popq %r15
jmpq *%rcx
movq (%rbx), %rax
movsbq (%rax), %rax
jmp 0x61d4
movq (%rbx), %rax
movswq (%rax), %rax
jmp 0x61d4
movq (%rbx), %rax
movslq (%rax), %rax
movq %rax, (%rbx)
popq %rbx
popq %r14
popq %r15
retq
movq (%rbx), %rax
cvtss2sd (%rax), %xmm0
movsd %xmm0, (%rbx)
jmp 0x61d7