// File: /workspace/github_c_makefile_star2_O2/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, %r15
leal -0x4(%rcx), %r13d
cmpl $0x16, %r13d
ja 0x62b6
movq (%r14), %rax
movq %rax, %xmm0
leaq 0x63a2c(%rip), %rdx     # 0x69c44
movslq (%rdx,%r13,4), %rsi
addq %rdx, %rsi
jmpq *%rsi
cmpq $0xff, %rax
ja 0x62b6
jmp 0x6326
movslq %eax, %rdx
cmpq %rax, %rdx
jne 0x62b6
jmp 0x6337
movsbq %al, %rdx
cmpq %rax, %rdx
jne 0x62b6
jmp 0x6326
cmpq $0x1, %rax
ja 0x62b6
jmp 0x633f
movdqa 0x63d50(%rip), %xmm1    # 0x69fb0
pand %xmm0, %xmm1
ucomisd 0x63d8c(%rip), %xmm1    # 0x69ff8
ja 0x62b6
jmp 0x634d
cmpq $0xffff, %rax           # imm = 0xFFFF
ja 0x62b6
jmp 0x632e
movdqa 0x63d28(%rip), %xmm1    # 0x69fb0
pand %xmm0, %xmm1
ucomisd 0x63d5c(%rip), %xmm1    # 0x69ff0
ja 0x62b6
jmp 0x6380
movswq %ax, %rdx
cmpq %rax, %rdx
jne 0x62b6
jmp 0x632e
movq %rax, %rdx
shrq $0x20, %rdx
je 0x6337
movq (%rdi), %rax
movq (%rax), %rdx
movq %rdx, (%rsp)
movq 0x20(%rax), %r12
movq %rdi, %rbp
movl %ecx, %edi
movl %r8d, %ebx
callq 0x1601e
leaq 0x63d45(%rip), %rsi     # 0x6a01d
movq %r12, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq *(%rsp)
movq %rbp, %rdi
movl %ebx, %r8d
cmpl $0x16, %r13d
ja 0x6358
leaq 0x639aa(%rip), %rax     # 0x69ca0
movslq (%rax,%r13,4), %rcx
addq %rax, %rcx
jmpq *%rcx
movq (%r14), %rax
movq %rax, (%r15)
jmp 0x6385
movq (%r14), %rsi
movslq %r8d, %rdx
movq %r15, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3260
movq (%r14), %rax
movb %al, (%r15)
jmp 0x6385
movq (%r14), %rax
movw %ax, (%r15)
jmp 0x6385
movq (%r14), %rax
movl %eax, (%r15)
jmp 0x6385
movq (%r14), %rax
testq %rax, %rax
setne (%r15)
jmp 0x6385
movq (%r14), %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, (%r15)
jmp 0x6385
movq (%rdi), %rax
movq (%rax), %rcx
movq 0x20(%rax), %rdi
leaq 0x63ca7(%rip), %rsi     # 0x6a010
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmpq *%rcx
movq (%r14), %xmm0
movq %xmm0, (%r15)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq