FictionTools/z88dk/src/sccz80/codegen.c
/* Store the specified object type in the primary register */
/*      at the address on the top of the stack */
Store the specified object type in the primary register
at the address on the top of the stack
Store the specified object type in the primary register at the address on the top of the stack
void putstk(LVALUE *lval)
{
    char flags = 0;
    Type *ctype;
    Kind typeobj = lval->indirect_kind;
    ctype = retrstk(&flags);
    if ( ctype != NULL ) {
        switch_namespace(ctype->namespace);
    }
    if (flags & FARACC) {
        doexx();
        mainpop();
        zpop();
        doexx();
        switch (typeobj) {
        case KIND_DOUBLE:
            callrts("lp_pdoub");
            break;
        case KIND_CPTR:
            callrts("lp_pptr");
            break;
        case KIND_LONG:
            callrts("lp_plong");
            break;
        case KIND_CHAR:
            callrts("lp_pchar");
            break;
        case KIND_STRUCT:
            warningfmt("incompatible-pointer-types","Cannot assign a __far struct");
        default:
            callrts("lp_pint");
        }
        return;
    }
    if ( ctype->bit_size ) {
        int bit_offset = lval->ltype->bit_offset;
        int doinc = 0;
        if ( bit_offset >= 8 ) {
            bit_offset -= 8;
            doinc = 1;
        }
        if ( lval->ltype->bit_size + bit_offset <= 8 ) {
            int i;
            zpop();  
            if ( doinc ) {
                ol("inc\tde");
            }
            ol("ld\ta,l");
            if ( bit_offset >= 4) {
                for ( i = 0; i < (8 - bit_offset); i++ ) {
                    ol("rlca");
                }
            } else {
                for ( i = 0; i < bit_offset; i++ ) {
                    ol("rlca");
                }
            }
            outfmt("\tand\t%d\n",((1 << lval->ltype->bit_size) - 1) << bit_offset);
            ol("ld\tl,a");
            ol("ld\ta,(de)");
            outfmt("\tand\t%d\n",0xff - (((1 << lval->ltype->bit_size) - 1) << bit_offset));
            ol("or\tl");
            ol("ld\t(de),a");
        } else {
            asl_const(lval, lval->ltype->bit_offset);
            zand_const(lval,((1 << lval->ltype->bit_size) - 1) << bit_offset);
            zpop();  
            ol("ld\ta,(de)");
            outfmt("\tand\t%d\n",(0xffff - (((1 << lval->ltype->bit_size) - 1) << bit_offset)) % 256);
            ol("or\tl");
            ol("ld\t(de),a");
            ol("inc\tde");
            ol("ld\ta,(de)");
            outfmt("\tand\t%d\n",(0xffff - (((1 << lval->ltype->bit_size) - 1) << bit_offset)) / 256);
            ol("or\th");
            ol("ld\t(de),a");
        }
        return;
    }
    switch (typeobj) {
    case KIND_DOUBLE:
        if ( c_fp_size > 4) {
            mainpop();
            callrts("dstore");
        } else {
            zpopbc();
            callrts("dstore");
        }
        break;
    case KIND_CPTR:
        zpopbc();
        callrts("l_putptr");
        break;
    case KIND_LONG:
        zpopbc();
        callrts("l_plong");
        break;
    case KIND_CHAR:
        zpop();
        LoadAccum();
        ol("ld\t(de),a");
        break;
    case KIND_STRUCT:
        zpop();
        outfmt("\tld\tbc,%d\n",lval->ltype->size);
        ol("ldir");
        break;
    default:
        zpop();
        callrts("l_pint");
    }
}
void putstk ( LVALUE * lval ) { char flags = 0 ; Type * ctype ; Kind typeobj = lval -> indirect_kind ; ctype = retrstk ( & flags ) ; if ( ctype != NULL ) { switch_namespace ( ctype -> namespace ) ; } if ( flags & FARACC ) { doexx ( ) ; mainpop ( ) ; zpop ( ) ; doexx ( ) ; switch ( typeobj ) { case KIND_DOUBLE : callrts ( " " ) ; break ; case KIND_CPTR : callrts ( " " ) ; break ; case KIND_LONG : callrts ( " " ) ; break ; case KIND_CHAR : callrts ( " " ) ; break ; case KIND_STRUCT : warningfmt ( " " , " " ) ; default : callrts ( " " ) ; } return ; } if ( ctype -> bit_size ) { int bit_offset = lval -> ltype -> bit_offset ; int doinc = 0 ; if ( bit_offset >= 8 ) { bit_offset -= 8 ; doinc = 1 ; } if ( lval -> ltype -> bit_size + bit_offset <= 8 ) { int i ; zpop ( ) ; if ( doinc ) { ol ( " \t " ) ; } ol ( " \t " ) ; if ( bit_offset >= 4 ) { for ( i = 0 ; i < ( 8 - bit_offset ) ; i ++ ) { ol ( " " ) ; } } else { for ( i = 0 ; i < bit_offset ; i ++ ) { ol ( " " ) ; } } outfmt ( " \t \t \n " , ( ( 1 << lval -> ltype -> bit_size ) - 1 ) << bit_offset ) ; ol ( " \t " ) ; ol ( " \t " ) ; outfmt ( " \t \t \n " , 0xff - ( ( ( 1 << lval -> ltype -> bit_size ) - 1 ) << bit_offset ) ) ; ol ( " \t " ) ; ol ( " \t " ) ; } else { asl_const ( lval , lval -> ltype -> bit_offset ) ; zand_const ( lval , ( ( 1 << lval -> ltype -> bit_size ) - 1 ) << bit_offset ) ; zpop ( ) ; ol ( " \t " ) ; outfmt ( " \t \t \n " , ( 0xffff - ( ( ( 1 << lval -> ltype -> bit_size ) - 1 ) << bit_offset ) ) % 256 ) ; ol ( " \t " ) ; ol ( " \t " ) ; ol ( " \t " ) ; ol ( " \t " ) ; outfmt ( " \t \t \n " , ( 0xffff - ( ( ( 1 << lval -> ltype -> bit_size ) - 1 ) << bit_offset ) ) / 256 ) ; ol ( " \t " ) ; ol ( " \t " ) ; } return ; } switch ( typeobj ) { case KIND_DOUBLE : if ( c_fp_size > 4 ) { mainpop ( ) ; callrts ( " " ) ; } else { zpopbc ( ) ; callrts ( " " ) ; } break ; case KIND_CPTR : zpopbc ( ) ; callrts ( " " ) ; break ; case KIND_LONG : zpopbc ( ) ; callrts ( " " ) ; break ; case KIND_CHAR : zpop ( ) ; LoadAccum ( ) ; ol ( " \t " ) ; break ; case KIND_STRUCT : zpop ( ) ; outfmt ( " \t \t \n " , lval -> ltype -> size ) ; ol ( " " ) ; break ; default : zpop ( ) ; callrts ( " " ) ; } }
Store the specified object type in the primary register
at the address on the top of the stack
Store the specified object type in the primary register at the address on the top of the stack
//outfmt("; %s type=%d val_type=%d indirect=%d\n", lval->ltype->name, lval->type, lval->val_type, lval->indirect_kind); /* Store via long pointer... */ //outfmt(";Restore %p flags %02d\n",ptr, flags); /* exx pop hl, pop de, exx */ // de address // TODO: Shift left as necessary // hl = value, lets shift into the right place // de = destination address