//#define msgx

//  Convert expression to boolean expression
//  Links are not generated by p_expr2bool(), but they may exist.

#include "parser.ih"

void p_expr2bool(SemVal *sv)
{
    msg("BEGIN");
    //svOut(sv);

    switch (svType(sv) & (e_int | e_str | e_list | e_bool))
    {
        case e_int:
            msg("1");
            if (svTestType(sv, e_const))
            {
                svSetValue(sv, svValue(sv) != 0);
                svSetType(sv, e_int | e_const);
                return;
            }
        break;

        case e_str:
            msg("2");
            if (svTestType(sv, e_const))
            {
                svSetValue(sv, 1);
                svSetType(sv, e_int | e_const);
                return;
            }
        break;

        case e_bool:
            msg("3");
        return;
    }

            msg("4");
    svPushStack(sv);                                // convert to code 

            msg("5");
    svAddCode (sv, op_jmp_true);
            msg("6");
    svAddCode (sv, op_jmp, j_falselist);

            msg("7");
    svSetType(sv, e_stack | e_bool);
    msg("END");
}
