Esempio n. 1
0
void
prim_foriter(PRIM_PROTOTYPE)
{
    CHECKOP(0);

    if (!fr->fors.st)
        abort_interp("Internal error; FOR stack underflow.");

    if (fr->fors.st->end.type == PROG_ARRAY) {
        stk_array *arr = fr->fors.st->end.data.array;

        if (fr->fors.st->didfirst) {
            result = array_next(arr, &fr->fors.st->cur);
        } else {
            result = array_first(arr, &fr->fors.st->cur);
            fr->fors.st->didfirst = 1;
        }
        if (result) {
            array_data *val = array_getitem(arr, &fr->fors.st->cur);

            if (val) {
                CHECKOFLOW(2);
                PushInst(&fr->fors.st->cur); /* push key onto stack */
                PushInst(val);  /* push value onto stack */
                tmp = 1;        /* tell following IF to NOT branch out of loop */
            } else {
                tmp = 0;        /* tell following IF to branch out of loop */
            }
        } else {
            fr->fors.st->cur.type = PROG_INTEGER;
            fr->fors.st->cur.line = 0;
            fr->fors.st->cur.data.number = 0;
            tmp = 0;            /* tell following IF to branch out of loop */
        }
    } else {
        int cur = fr->fors.st->cur.data.number;
        int end = fr->fors.st->end.data.number;

        tmp = fr->fors.st->step > 0;
        if (tmp)
            tmp = !(cur > end);
        else
            tmp = !(cur < end);
        if (tmp) {
            CHECKOFLOW(1);
            result = cur;
            fr->fors.st->cur.data.number += fr->fors.st->step;
            PushInt(result);
        }
    }
    CHECKOFLOW(1);
    PushInt(tmp);
}
Esempio n. 2
0
bool InstructThread::StartHeartbeat(const Address & Server)
{
	Instruction * p = new Instruction;
	
	BuildHeader(p, IPV4 | LOCAL_ADDRESS, Server.m_IPv4, Server.m_Port, HEARTBEAT_INTERVAL, 0x0);
	
	Packet * packet = &p->Data;
	BuildHeartbeat(packet, p->Identify);
	
	return PushInst(p);
}
Esempio n. 3
0
bool InstructThread::Login(const Address & Server, const std::string & Username,
	const std::string & Passwd)
{
	Instruction * p = new Instruction;
	
	BuildHeader(p, IPV4 | LOCAL_ADDRESS, Server.m_IPv4, Server.m_Port, 1, MAX_LOGIN_RETRY);
	
	Packet * packet = &p->Data;
	BuildLoginRequest(packet, Username, Passwd, p->Identify);
	
	return PushInst(p);
}