// File: /workspace/github_c_makefile_star2_O1/vtereshkov[P]umka-lang/src/umka_const.c
// Function: constAssign
void constAssign(const Consts *consts, void *lhs, const Const *rhs, TypeKind typeKind, int size)
{
    if (typeOverflow(typeKind, *rhs))
        consts->error->handler(consts->error->context, "Overflow in assignment to %s", typeKindSpelling(typeKind));

    switch (typeKind)
    {
        case TYPE_INT8:         *(int8_t        *)lhs = rhs->intVal;         break;
        case TYPE_INT16:        *(int16_t       *)lhs = rhs->intVal;         break;
        case TYPE_INT32:        *(int32_t       *)lhs = rhs->intVal;         break;
        case TYPE_INT:          *(int64_t       *)lhs = rhs->intVal;         break;
        case TYPE_UINT8:        *(uint8_t       *)lhs = rhs->intVal;         break;
        case TYPE_UINT16:       *(uint16_t      *)lhs = rhs->intVal;         break;
        case TYPE_UINT32:       *(uint32_t      *)lhs = rhs->intVal;         break;
        case TYPE_UINT:         *(uint64_t      *)lhs = rhs->uintVal;        break;
        case TYPE_BOOL:         *(bool          *)lhs = rhs->intVal;         break;
        case TYPE_CHAR:         *(unsigned char *)lhs = rhs->intVal;         break;
        case TYPE_REAL32:       *(float         *)lhs = rhs->realVal;        break;
        case TYPE_REAL:         *(double        *)lhs = rhs->realVal;        break;
        case TYPE_PTR:          *(void *        *)lhs = rhs->ptrVal;         break;
        case TYPE_WEAKPTR:      *(uint64_t      *)lhs = rhs->weakPtrVal;     break;
        case TYPE_STR:          *(void *        *)lhs = rhs->ptrVal;         break;
        case TYPE_ARRAY:
        case TYPE_DYNARRAY:
        case TYPE_STRUCT:
        case TYPE_INTERFACE:
        case TYPE_CLOSURE:      memcpy(lhs, rhs->ptrVal, size);              break;
        case TYPE_FIBER:        *(void *        *)lhs = rhs->ptrVal;         break;
        case TYPE_FN:           *(int64_t       *)lhs = rhs->intVal;         break;

        default:          consts->error->handler(consts->error->context, "Illegal type"); return;
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdx, %r14
movq %rsi, %rbp
leal -0x4(%rcx), %r13d
cmpl $0x16, %r13d
ja 0xf003
movq (%r14), %rax
leaq 0x67cad(%rip), %rdx     # 0x76c44
movslq (%rdx,%r13,4), %rsi
addq %rdx, %rsi
jmpq *%rsi
cmpq $0x100, %rax            # imm = 0x100
jmp 0xefd3
movslq %eax, %rdx
jmp 0xeff3
movsbq %al, %rdx
jmp 0xeff3
cmpq $0x2, %rax
jmp 0xefd3
btrq $0x3f, %rax
movq %rax, %xmm0
ucomisd 0x67fe5(%rip), %xmm0    # 0x76fb0
jmp 0xefea
cmpq $0x10000, %rax          # imm = 0x10000
setae %al
jmp 0xefff
btrq $0x3f, %rax
movq %rax, %xmm0
ucomisd 0x67fbe(%rip), %xmm0    # 0x76fa8
seta %al
jmp 0xefff
movswq %ax, %rdx
cmpq %rax, %rdx
jmp 0xeffc
shrq $0x20, %rax
setne %al
testb %al, %al
je 0xf036
movq (%rdi), %rax
movq (%rax), %rdx
movq %rdx, (%rsp)
movq 0x20(%rax), %r12
movq %rdi, %rbx
movl %ecx, %edi
movl %r8d, %r15d
callq 0x1fe46
leaq 0x67ff8(%rip), %rsi     # 0x7701d
movq %r12, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq *(%rsp)
movq %rbx, %rdi
movl %r15d, %r8d
cmpl $0x16, %r13d
ja 0xf0a4
leaq 0x67c5d(%rip), %rax     # 0x76ca0
movslq (%rax,%r13,4), %rcx
addq %rax, %rcx
jmpq *%rcx
movq (%r14), %rax
movq %rax, (%rbp)
jmp 0xf0d1
movq (%r14), %rsi
movslq %r8d, %rdx
movq %rbp, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3260
movb (%r14), %al
movb %al, (%rbp)
jmp 0xf0d1
movzwl (%r14), %eax
movw %ax, (%rbp)
jmp 0xf0d1
movl (%r14), %eax
movl %eax, (%rbp)
jmp 0xf0d1
cmpq $0x0, (%r14)
setne (%rbp)
jmp 0xf0d1
xorps %xmm0, %xmm0
cvtsd2ss (%r14), %xmm0
movss %xmm0, (%rbp)
jmp 0xf0d1
movq (%rdi), %rax
movq (%rax), %rcx
movq 0x20(%rax), %rdi
leaq 0x67f5b(%rip), %rsi     # 0x77010
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmpq *%rcx
movsd (%r14), %xmm0
movsd %xmm0, (%rbp)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq