// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movl %r8d, -0x20(%rbp)
movl -0x1c(%rbp), %edi
movq -0x18(%rbp), %rax
movq (%rax), %rsi
callq 0x8ae0
testb $0x1, %al
jne 0x88f0
jmp 0x892b
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq (%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq 0x20(%rax), %rax
movq %rax, -0x30(%rbp)
movl -0x1c(%rbp), %edi
callq 0x23b40
movq -0x30(%rbp), %rdi
movq -0x28(%rbp), %rcx
movq %rax, %rdx
leaq 0x1cf6c6(%rip), %rsi    # 0x1d7fed
movb $0x0, %al
callq *%rcx
movl -0x1c(%rbp), %eax
addl $-0x4, %eax
movl %eax, %ecx
movq %rcx, -0x38(%rbp)
subl $0x16, %eax
ja 0x8ab7
movq -0x38(%rbp), %rax
leaq 0x1cf2f9(%rip), %rcx    # 0x1d7c44
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x18(%rbp), %rax
movq (%rax), %rax
movb %al, %cl
movq -0x10(%rbp), %rax
movb %cl, (%rax)
jmp 0x8ad7
movq -0x18(%rbp), %rax
movq (%rax), %rax
movw %ax, %cx
movq -0x10(%rbp), %rax
movw %cx, (%rax)
jmp 0x8ad7
movq -0x18(%rbp), %rax
movq (%rax), %rax
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, (%rax)
jmp 0x8ad7
movq -0x18(%rbp), %rax
movq (%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, (%rax)
jmp 0x8ad7
movq -0x18(%rbp), %rax
movq (%rax), %rax
movb %al, %cl
movq -0x10(%rbp), %rax
movb %cl, (%rax)
jmp 0x8ad7
movq -0x18(%rbp), %rax
movq (%rax), %rax
movw %ax, %cx
movq -0x10(%rbp), %rax
movw %cx, (%rax)
jmp 0x8ad7
movq -0x18(%rbp), %rax
movq (%rax), %rax
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, (%rax)
jmp 0x8ad7
movq -0x18(%rbp), %rax
movq (%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, (%rax)
jmp 0x8ad7
movq -0x18(%rbp), %rax
cmpq $0x0, (%rax)
setne %cl
movq -0x10(%rbp), %rax
andb $0x1, %cl
movb %cl, (%rax)
jmp 0x8ad7
movq -0x18(%rbp), %rax
movq (%rax), %rax
movb %al, %cl
movq -0x10(%rbp), %rax
movb %cl, (%rax)
jmp 0x8ad7
movq -0x18(%rbp), %rax
movsd (%rax), %xmm0
cvtsd2ss %xmm0, %xmm0
movq -0x10(%rbp), %rax
movss %xmm0, (%rax)
jmp 0x8ad7
movq -0x18(%rbp), %rax
movsd (%rax), %xmm0
movq -0x10(%rbp), %rax
movsd %xmm0, (%rax)
jmp 0x8ad7
movq -0x18(%rbp), %rax
movq (%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, (%rax)
jmp 0x8ad7
movq -0x18(%rbp), %rax
movq (%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, (%rax)
jmp 0x8ad7
movq -0x18(%rbp), %rax
movq (%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, (%rax)
jmp 0x8ad7
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movq (%rax), %rsi
movslq -0x20(%rbp), %rdx
callq 0x3270
jmp 0x8ad7
movq -0x18(%rbp), %rax
movq (%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, (%rax)
jmp 0x8ad7
movq -0x18(%rbp), %rax
movq (%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, (%rax)
jmp 0x8ad7
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq (%rax), %rcx
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq 0x20(%rax), %rdi
leaq 0x1cf50d(%rip), %rsi    # 0x1d7fe0
movb $0x0, %al
callq *%rcx
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)