// File: /workspace/github_c_makefile_star2_O2/johsteffens[P]beth/xoico/src/xoico.xo.c
// Function: xoico_func_s_parse
er_t xoico_func_s_parse( xoico_func_s* o, const xoico_host* host, x_source* source )
{
    // xoico_func.x:104:1
    BLM_INIT_LEVEL(0);
    xoico_compiler_s* compiler = xoico_host_a_compiler(host);
    
    x_source_point_s_setup_from_source(&(o->source_point),source );
    
    if( x_source_parse_bl(source," #?'('" ) ) // old style enclosed signature
    {
        BLM_RETURNV(er_t, x_source_parse_error_fa(source,"Signature-enclosure '( ...sig... )' is deprecated." ))
    }
    
    // We first try parsing a direct signature. If that fails, we assume the signature is referenced by an identifier.
    // This allows parsing without old style bracket enclosing. If that is a save practice under all circumstances is to be seen.
    s3_t index = x_source_get_index(source);
    xoico_signature_s* signature = ((xoico_signature_s*)BLM_LEVEL_T_PUSH(0,xoico_signature_s,xoico_signature_s_create()));
    
    if( xoico_signature_s_parse(signature,host, source ) != 0 )
    {
        bcore_error_remove_last();
        x_source_set_index(source,index );
        signature = NULL;
    }
    
    if( signature )
    {
        BLM_TRY(xoico_compiler_s_life_a_push(compiler,((bcore_inst*)(((xoico_signature_s*)bcore_fork(signature)) ))))
        o->pre_hash = bcore_tp_fold_tp( o->pre_hash, xoico_signature_s_get_hash(signature) );
        o->name = signature->name;
        BLM_TRY(xoico_compiler_s_register_item(compiler,((const xoico*)(signature ))))
        o->signature_global_name = signature->global_name;
        xoico_signature_s_attach( &(o->signature ),  xoico_signature_s_clone(signature));
        BLM_TRY(xoico_signature_s_relent(o->signature,host, xoico_host_a_obj_type(host) ))
        if( xoico_host_defines_transient_map(host) ) BLM_TRY(xoico_signature_s_convert_transient_types(o->signature,host, xoico_host_a_transient_map(host) ))
    }
    else // use of external signature definition
    {
        tp_t tp_signature_base_name = 0;
        tp_t tp_signature_global_name = 0;
    
        if( x_source_parse_bl(source," #?'^'" ) )
        {
            if( host->_ == ((tp_t)(TYPEOF_xoico_stamp_s)) )
            {
                tp_signature_base_name = ((const xoico_stamp_s*)(host))->trait_name;
            }
            else
            {
                BLM_RETURNV(er_t, x_source_parse_error_fa(source,"'^' can only be used inside a stamp." ))
            }
            BLM_TRY(x_source_parse_fa(source," ." ))
        }
        else
        {
            tp_t name = 0;
            BLM_TRY(xoico_host_a_parse_name_tp(host,source, (&(name)) ))
            if( x_source_parse_bl(source," #?'.'" ) )
            {
                tp_signature_base_name = name;
            }
            else
            {
                sz_t idx = -1;
                if( host->_ == ((tp_t)(TYPEOF_xoico_stamp_s)) && ( idx = xoico_funcs_s_get_index_from_name(&(((const xoico_stamp_s*)(host))->funcs),name ) ) >= 0 )
                {
                    tp_signature_global_name = ((const xoico_stamp_s*)(host))->funcs.data[ idx ]->signature_global_name;
                }
                else
                {
                    tp_signature_base_name = xoico_a_get_global_name_tp(((const xoico*)(host)));
                }
                o->name = name;
            }
        }
    
        if( !o->name )
        {BLM_INIT_LEVEL(2);
            st_s st_name;BLM_T_INIT_SPUSH(st_s, &st_name);;
            BLM_TRY(x_source_parse_fa(source," #name", (&(st_name)) )) // empty name is allowed
            o->name = xoico_compiler_s_entypeof(compiler,st_name.sc );
        BLM_DOWN();}
    
        if( !tp_signature_global_name )
        {BLM_INIT_LEVEL(2);
            tp_signature_global_name = xoico_compiler_s_entypeof(compiler,((st_s*)BLM_LEVEL_T_PUSH(2,st_s,st_s_create_fa("#<sc_t>_#<sc_t>", xoico_compiler_s_nameof(compiler,tp_signature_base_name ), xoico_compiler_s_nameof(compiler,o->name ) )))->sc );
        BLM_DOWN();}
    
        o->signature_global_name = tp_signature_global_name;
    }
    
    if( !x_source_parse_bl(source," #=?';'" ) ) BLM_TRY(xoico_body_s_parse(BCORE_PASS_CREATE(xoico_body_s,o->body),host, source ))
    
    BLM_TRY(x_source_parse_fa(source," #-?';' " )) // closing semicolon is optional
    
    BLM_RETURNV(er_t, 0)
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, %r15
leaq 0x106cf9(%rip), %rax    # 0x117dd0
movq (%rax), %rsi
leaq 0x18(%rsp), %r12
movq %r12, %rdi
callq 0x717f5
andq $0x0, 0x10(%r12)
movq %r14, %rdi
callq 0xdab3
movq %rax, %r12
leaq 0x48(%r15), %rdi
movq %rbx, %rsi
callq 0xdc7d
leaq 0x9942a(%rip), %rsi     # 0xaa535
movq %rbx, %rdi
callq 0xe5ff
testb %al, %al
je 0x1114a
leaq 0x9958c(%rip), %rsi     # 0xaa6aa
movq %rbx, %rdi
xorl %eax, %eax
callq 0xd7c4
movq %rax, %r13
leaq 0x18(%rsp), %rdi
callq 0x71b64
movq %r13, %rax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, %rdi
callq 0x10a95
movq %rax, %r13
callq 0xf958
leaq 0x18(%rsp), %rdi
movabsq $-0x231a5c50432e84f2, %rdx # imm = 0xDCE5A3AFBCD17B0E
xorl %esi, %esi
movq %rax, %rcx
callq 0x71967
movq %rax, %rbp
movq %rax, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0xfc0a
testq %rax, %rax
je 0x11226
callq 0x60473
movq %rbx, %rdi
movq %r13, %rsi
callq 0x10b09
leaq 0x99539(%rip), %rsi     # 0xaa6dd
movq %rbx, %rdi
callq 0xe5ff
testb %al, %al
je 0x111e6
movabsq $0x12d01d78049fae7, %rax # imm = 0x12D01D78049FAE7
cmpq %rax, (%r14)
jne 0x112e2
movq 0x30(%r14), %rbp
leaq 0x9d4e9(%rip), %rsi     # 0xae6b7
movq %rbx, %rdi
xorl %eax, %eax
callq 0xd600
testq %rax, %rax
jne 0x11128
movq %rbp, %rax
jmp 0x1121f
leaq 0x68(%rsp), %rdx
andq $0x0, (%rdx)
movq %r14, %rdi
movq %rbx, %rsi
callq 0xdcb4
testq %rax, %rax
jne 0x11128
leaq 0x994ff(%rip), %rsi     # 0xaa709
movq %rbx, %rdi
callq 0xe5ff
testb %al, %al
je 0x112ee
movq 0x68(%rsp), %rax
xorl %ebp, %ebp
jmp 0x11336
testq %rbp, %rbp
je 0x1119d
movq %rbp, %rdi
callq 0x6026d
movq %r12, %rdi
addq $0x20, %rdi
movq %rax, %rsi
callq 0x71a4d
movq 0x30(%r15), %r13
movq %rbp, %rdi
callq 0xfab9
movq %r13, %rdi
movq %rax, %rsi
callq 0xe705
movq %rax, 0x30(%r15)
movq 0x8(%rbp), %rax
movq %rax, 0x8(%r15)
movq %r12, %rdi
movq %rbp, %rsi
callq 0x114d0
testq %rax, %rax
jne 0x11128
movq 0x18(%rbp), %rax
movq %rax, 0x20(%r15)
leaq 0x40(%r15), %r12
movq %rbp, %rdi
callq 0xf979
movq %r12, %rdi
movq %rax, %rsi
callq 0x11556
movq 0x40(%r15), %r13
movq %r14, %rdi
callq 0xe8a0
movq %r13, %rdi
movq %rax, %rdx
callq 0xfa05
movq %r14, %rdi
callq 0x11578
testb %al, %al
je 0x113d9
movq (%r12), %r12
movq %r14, %rdi
callq 0x11588
movq %r12, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0xf993
jmp 0x113d9
leaq 0x993fb(%rip), %rsi     # 0xaa6e4
jmp 0x1111e
movabsq $0x12d01d78049fae7, %rax # imm = 0x12D01D78049FAE7
cmpq %rax, (%r14)
jne 0x11323
leaq 0x58(%r14), %rdi
movq 0x68(%rsp), %r13
movq %r13, %rsi
callq 0x11598
testq %rax, %rax
js 0x11323
movq 0x60(%r14), %rcx
movq (%rcx,%rax,8), %rax
movq 0x20(%rax), %rbp
xorl %eax, %eax
jmp 0x11332
movq %r14, %rdi
callq 0x115c2
xorl %ebp, %ebp
movq 0x68(%rsp), %r13
movq %r13, 0x8(%r15)
cmpq $0x0, 0x8(%r15)
je 0x1142b
testq %rbp, %rbp
jne 0x113d5
leaq 0x68(%rsp), %rbp
leaq 0x48(%rsp), %rcx
movq %rbp, (%rcx)
movq %rax, %r13
leaq 0x18(%rsp), %rsi
movq %rbp, %rdi
callq 0x717f5
movq $0x2, 0x10(%rbp)
movq %r12, %rdi
movq %r13, %rsi
callq 0xdad8
movq %rax, %r13
movq 0x8(%r15), %rsi
movq %r12, %rdi
callq 0xdad8
leaq 0x999ec(%rip), %rdi     # 0xaad7c
movq %r13, %rsi
movq %rax, %rdx
xorl %eax, %eax
callq 0x8ec7d
pushq $0x2
popq %rsi
movabsq $-0x503db0e6e1c2e704, %rdx # imm = 0xAFC24F191E3D18FC
movq %rbp, %rdi
movq %rax, %rcx
callq 0x71967
movq 0x8(%rax), %rsi
addq $0x140, %r12            # imm = 0x140
movq %r12, %rdi
callq 0x6f48c
movq %rax, %rbp
leaq 0x48(%rsp), %rdi
callq 0x71b48
movq %rbp, 0x20(%r15)
leaq 0x99330(%rip), %rsi     # 0xaa710
movq %rbx, %rdi
callq 0xe5ff
testb %al, %al
jne 0x11415
movq 0x38(%r15), %rdi
testq %rdi, %rdi
jne 0x11401
callq 0x10839
movq %rax, %rdi
movq %rax, 0x38(%r15)
movq %r14, %rsi
movq %rbx, %rdx
callq 0x10b30
testq %rax, %rax
jne 0x11128
leaq 0x992fc(%rip), %rsi     # 0xaa718
movq %rbx, %rdi
xorl %eax, %eax
callq 0xd600
jmp 0x11128
movq %rax, 0x8(%rsp)
leaq 0x68(%rsp), %r13
movq %r13, 0x10(%rsp)
leaq 0x18(%rsp), %rsi
movq %r13, %rdi
callq 0x717f5
movq $0x2, 0x10(%r13)
leaq 0x48(%rsp), %rdi
callq 0x8e048
movabsq $-0x503db0e6e1c2e704, %rsi # imm = 0xAFC24F191E3D18FC
movq %r13, %rdi
leaq 0x48(%rsp), %rdx
callq 0x71998
leaq 0xb0cb0(%rip), %rsi     # 0xc2127
movq %rbx, %rdi
leaq 0x48(%rsp), %rdx
xorl %eax, %eax
callq 0xd600
testq %rax, %rax
je 0x11498
movq %rax, %r13
leaq 0x68(%rsp), %rdi
jmp 0x11130
movq 0x50(%rsp), %rsi
leaq 0x140(%r12), %rdi
callq 0x6f48c
movq %rax, 0x8(%r15)
leaq 0x10(%rsp), %rdi
callq 0x71b48
movq 0x8(%rsp), %rax
jmp 0x11341