示例#1
0
SemVal *p_addition(SemVal *lval, SemVal *rval)
{
    register ExprType type;

    if (p_testBinOp(op_add, lval, rval))
        return p_nullFrame(lval, rval);     /* test for correct types */

    p_bool2int(lval);                       /* convert pending booleans */
    p_bool2int(rval);

    if (p_conflict(lval, rval, op_add))     /* test type p_conflict */
        return p_nullFrame(lval, rval);

    type = lval->type;                      /* keep type for later */

    if ((type & rval->type & (unsigned)~e_typeMask) == e_const)
    {
        if (test_type(lval, e_int))
            lval->evalue += rval->evalue;
        else if (test_type(lval, e_str))
            p_catStrings(lval, rval);         /* create (cat) new string */
    }
    else 
    {
        p_binOp(lval, rval, op_add);
        set_type(lval, (type & e_typeMask) | e_stack);
    }

    return lval;                            /* return new expression */
}
示例#2
0
SemVal *p_subtract(SemVal *lval, SemVal *rval)
{
    register ExprType type;

    if (p_testBinOp(op_sub, lval, rval))
        return (lval);                      /* test for correct types */

    p_bool2int(lval);                             /* convert pending booleans */
    p_bool2int(rval);

    if (p_conflict(lval, rval, op_sub))       /* test type p_conflict */
        return(lval);

    type = lval->type;                      /* remember the type */

    if ((lval->type & rval->type & (size_t)~e_typeMask) == e_const)
        lval->evalue -= rval->evalue;
    else
    {
        p_binOp(lval, rval, op_sub);
        set_type(lval, type & (e_typeMask | e_stack));
    }

    return (lval);                          /* return new expression */
}
示例#3
0
文件: psmequal.c 项目: fbb-git/icmake
SemVal *p_smEqual(SemVal *lval, SemVal *rval)
{
    p_bool2int(lval);                           /* convert boolean to i */
    p_bool2int(rval);

    if (p_conflict(lval, rval, op_smeq))        /* test type p_conflict */
        return p_nullFrame(lval, rval);

    if ((lval->type & rval->type & (unsigned)~e_typeMask) == e_const)
    {
        if (test_type(lval, e_int))
            lval->evalue = (lval->evalue <= rval->evalue);
        else
        {
            lval->evalue =
                      (
                        strcmp
                        (
                            gp_stringTable[lval->evalue].string,
                            gp_stringTable[rval->evalue].string
                        )
                      ) <= 0;
            set_type(lval, e_int | e_const);
        }
    }
    else
        p_binOp(lval, rval, op_smeq);

    return lval;                            /* return new expression */
}
示例#4
0
文件: pgreater.c 项目: MDorwig/icmake
SemVal *p_greater(SemVal *lval, SemVal *rval)
{
    p_bool2int(lval);                             /* convert boolean to i */
    p_bool2int(rval);

    if (p_conflict(lval, rval, op_gr))        /* test type p_conflict */
        return(lval);

    if ((lval->type & rval->type & (size_t)~e_typeMask) == e_const)
    {
        if (test_type(lval, e_int))
            lval->evalue = (lval->evalue > rval->evalue);
        else
        {
            lval->evalue =
                      (
                        strcmp
                        (
                            gp_stringTable[lval->evalue].string,
                            gp_stringTable[rval->evalue].string
                        )
                      ) > 0;
            set_type(lval, e_int | e_const);
        }
    }
    else
        p_binOp(lval, rval, op_gr);

    return (lval);                          /* return new expression */
}
示例#5
0
文件: pcast.c 项目: fbb-git/icmake
SemVal *p_cast(ExprType target, SemVal *e)
{
    p_bool2int(e);                                /* convert boolean to int */

    switch (target)
    {
        case e_int:                        /* p_cast to ints */
            p_iCast(e);
        break;

        case e_str:                        /* p_cast to strings */
            p_sCast(e);
        break;

        case e_list:                       /* p_cast to lists */
            p_lCast(e);
        break;

        default:
        /* 
            default is entered in the switch to prevent a long compiler
            warning
        */
        break;
    }
    return e;
}
示例#6
0
SemVal *p_multiply(SemVal *lval, SemVal *rval)
{
    if (p_testBinOp(op_mul, lval, rval))
        return p_nullFrame(lval, rval);     /* test for correct types */


    p_bool2int(lval);                       /* convert pending booleans */
    p_bool2int(rval);

    if (p_conflict(lval, rval, op_mul))     /* test type p_conflict */
        return p_nullFrame(lval, rval);    

    if ((lval->type & rval->type & (unsigned)~e_typeMask) == e_const)
        lval->evalue *= rval->evalue;
    else
        p_binOp(lval, rval, op_mul);

    return lval;                            /* return new expression */
}