// File: /workspace/github_c_makefile_star2_O1/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 0xeee8
movq (%r14), %rcx
movq 0x20(%rcx), %rdi
leaq 0x6811c(%rip), %rsi     # 0x77000
xorl %eax, %eax
callq *(%rcx)
addl $-0x4, %r15d
cmpl $0x16, %r15d
ja 0xef2a
leaq 0x67cef(%rip), %rax     # 0x76be8
movslq (%rax,%r15,4), %rcx
addq %rax, %rcx
jmpq *%rcx
movq (%rbx), %rax
movq (%rax), %rax
jmp 0xef5c
movq (%rbx), %rax
movzbl (%rax), %eax
jmp 0xef5c
movq (%rbx), %rax
movzwl (%rax), %eax
jmp 0xef5c
movq (%rbx), %rax
movsd (%rax), %xmm0
jmp 0xef6c
movq (%rbx), %rax
movl (%rax), %eax
jmp 0xef5c
movq (%r14), %rax
movq (%rax), %rcx
movq 0x20(%rax), %rdi
leaq 0x680d5(%rip), %rsi     # 0x77010
xorl %eax, %eax
popq %rbx
popq %r14
popq %r15
jmpq *%rcx
movq (%rbx), %rax
movsbq (%rax), %rax
jmp 0xef5c
movq (%rbx), %rax
movswq (%rax), %rax
jmp 0xef5c
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 0xef5f