From: Rafał Długołęcki Date: Wed, 24 Jul 2013 07:11:26 +0000 (+0200) Subject: vlp-10 using coding style in control.c X-Git-Tag: 3.1~19 X-Git-Url: https://git.dlugolecki.net.pl/?a=commitdiff_plain;h=8f5c6c27803b5f1728614a8c847a96c94ae62453;p=vlp.git vlp-10 using coding style in control.c --- diff --git a/src/int/control.c b/src/int/control.c index 243df48..8ad1447 100644 --- a/src/int/control.c +++ b/src/int/control.c @@ -48,80 +48,87 @@ static void back1(); */ void go(word ah, word am) { - protdescr *ptr; - word pnum, plen, node, apt; - message msg; - - ptr = prototype[ M[ am+PROTNUM ] ]; - apt = am+M[ am ]; - if (ptr->kind == PROCESS) /* new process creation */ - { - thisp->template.addr = ah; /* save template address */ - thisp->template.mark = M[ ah+1 ]; - msg.control.type = CREATE; - msg.control.par = M[ am+PROTNUM ]; - moveparams(thispix, am, &msg, PARIN, LOADPAR); - msg.control.receiver.pix = 0; /* pix will create receiver */ - msg.control.receiver.mark= 0; /* mark will create receiver */ - msg.control.receiver.node = getnode(am); /* node we decided */ - sendmsg1( &msg); /* send create request */ -# ifdef RPCDBG - fprintf( - stderr, "send new process from %d to node %d\n", - thispix, - msg.control.receiver.node - ); -# endif - passivate(WAITFORNEW); /* and wait for return from process */ - } - else - if (isprocess((virtaddr*)(M+apt+SL))) /* remote procedure call */ - { - thisp->backobj.addr = ah; /* save template address */ - thisp->backobj.mark = M[ ah+1 ]; - thisp->M[ temporary ] = am; /* physical address also */ - { - virtaddr v; - loadvirt( v, apt+SL ); - obj2mess( M, &v, &msg.control.receiver ); - - /* fprintf( - stderr, "send rpc from process %d to (%d,%d,%d)\n", - thispix, - msg.control.receiver.node, - msg.control.receiver.pix, - msg.control.receiver.mark - );*/ - - } - msg.control.type = RPCALL; - msg.control.par = M[ am+PROTNUM ]; - moveparams(thispix, am, &msg, PARIN, LOADPAR); - sendmsg1( &msg); /* send RPC request */ - passivate(WAITFORRPC); /* and wait for RP return */ - } - else - { - M[ c1+M[ c1 ]+LSC ] = ic; /* save local control */ - loosen(); /* release DISPLAY */ - update(am, ah); /* update DISPLAY */ - c1 = am; /* new current */ - c2 = c1+ptr->span; - pnum = ptr->preflist; - plen = ptr->lthpreflist; - while (TRUE) /* search for executable prefix */ - if (plen <= 1) - { - ic = ptr->codeaddr; - break; - } - else + protdescr *ptr; + word pnum, plen, node, apt; + message msg; + + ptr = prototype[M[am + PROTNUM]]; + apt = am + M[am]; + /* new process creation */ + if (ptr->kind == PROCESS) { + /* save template address */ + thisp->template.addr = ah; + thisp->template.mark = M[ah + 1]; + msg.control.type = CREATE; + msg.control.par = M[am + PROTNUM]; + moveparams(thispix, am, &msg, PARIN, LOADPAR); + /* pix will create receiver */ + msg.control.receiver.pix = 0; + /* mark will create receiver */ + msg.control.receiver.mark= 0; + /* node we decided */ + msg.control.receiver.node = getnode(am); + /* send create request */ + sendmsg1(&msg); +#ifdef RPCDBG + fprintf(stderr, "send new process from %d to node %d\n", + thispix, msg.control.receiver.node); +#endif + /* and wait for return from process */ + passivate(WAITFORNEW); + } else if (isprocess((virtaddr*)(M+apt+SL))) { + /* remote procedure call */ + /* save template address */ + thisp->backobj.addr = ah; + thisp->backobj.mark = M[ah + 1]; + /* physical address also */ + thisp->M[temporary] = am; { - ptr = prototype[ M[ pnum ] ]; - plen--; - pnum++; - if (ptr->kind != RECORD) plen = 0; + virtaddr v; + loadvirt(v, apt + SL); + obj2mess(M, &v, &msg.control.receiver); + + /* + fprintf( + stderr, "send rpc from process %d to (%d,%d,%d)\n", + thispix, + msg.control.receiver.node, + msg.control.receiver.pix, + msg.control.receiver.mark + );*/ + } + msg.control.type = RPCALL; + msg.control.par = M[am + PROTNUM]; + moveparams(thispix, am, &msg, PARIN, LOADPAR); + /* send RPC request */ + sendmsg1(&msg); + /* and wait for RP return */ + passivate(WAITFORRPC); + } else { + /* save local control */ + M[c1 + M[c1] + LSC] = ic; + /* release DISPLAY */ + loosen(); + /* update DISPLAY */ + update(am, ah); + /* new current */ + c1 = am; + c2 = c1 + ptr->span; + pnum = ptr->preflist; + plen = ptr->lthpreflist; + /* search for executable prefix */ + while (TRUE) + if (plen <= 1) { + ic = ptr->codeaddr; + break; + } else { + ptr = prototype[M[pnum]]; + plen--; + pnum++; + if (ptr->kind != RECORD) + plen = 0; + } } } @@ -132,58 +139,76 @@ void go(word ah, word am) */ void goloc(word ah, word am) { - word t1; - protdescr *ptr; - - M[ c1+M[ c1 ]+LSC ] = ic; /* save local control */ - c1 = am; /* new current */ - t1 = M[ am+PROTNUM ]; - ptr = prototype[ t1 ]; - c2 = am+ptr->span; - ic = ptr->codeaddr; - M[ display+t1 ] = am; /* simulate update display */ - M[ display2+t1 ] = ah; - M[ am+M[ am ]+STATSL ]++; + word t1; + protdescr *ptr; + + /* save local control */ + M[c1 + M[c1] + LSC] = ic; + /* new current */ + c1 = am; + t1 = M[am + PROTNUM]; + ptr = prototype[t1]; + c2 = am + ptr->span; + ic = ptr->codeaddr; + /* simulate update display */ + M[display + t1] = am; + M[display2 + t1] = ah; + M[am + M[am]+STATSL ]++; } -/* Return from block. */ -void backbl(virtaddr *virt, word *am) +/** Return from block. */ +void backbl(virtaddr *virt, word *am) { - word t1; - - t1 = M[ c1+PROTNUM ]; - virt->addr = M[ display2+t1 ]; - virt->mark = M[ virt->addr+1 ]; /* prepare old address */ - *am = c1; /* am of old */ - M[ display+t1 ] = 0; /* simulate loosen */ - t1 = c1+M[ c1 ]; - M[ t1+STATSL ]--; /* remove from SL chain */ - c1 = M[ t1+SL ]; /* return up along SL */ - if (c1 == DUMMY) endprocess(0); /* return from main */ - c1 = M[ c1 ]; /* am of new current */ - c2 = c1+prototype[ M[ c1+PROTNUM ] ]->span; - ic = M[ c1+M[ c1 ]+LSC ]; - storevirt(*virt, *am+M[ *am ]+DL); /* force DL consistency */ + word t1; + + t1 = M[c1 + PROTNUM]; + virt->addr = M[display2 + t1]; + /* prepare old address */ + virt->mark = M[virt->addr + 1]; + /* am of old */ + *am = c1; + /* simulate loosen */ + M[display + t1] = 0; + t1 = c1 + M[c1]; + /* remove from SL chain */ + M[t1 + STATSL]--; + /* return up along SL */ + c1 = M[t1 + SL]; + /* return from main */ + if (c1 == DUMMY) + endprocess(0); + + /* am of new current */ + c1 = M[c1]; + c2 = c1 + prototype[M[c1 + PROTNUM]]->span; + ic = M[c1 + M[c1] + LSC]; + /* force DL consistency */ + storevirt(*virt, *am + M[*am]+DL); } /* Common code for some backs below. */ static void back1(word at1, word at2, virtaddr *virt, word *am) { - word t1; - - loosen(); - if (at1 == 0) endprocess(0); - t1 = M[ c1+PROTNUM ]; - virt->addr = M[ display2+t1 ]; /* ah of old */ - virt->mark = M[ virt->addr+1 ]; - *am = c1; /* am of old */ - storevirt(*virt, at2); /* loop up DL */ - at2 = M[ at1 ]; /* am of DL */ - update(at2, at1); - c1 = at2; - c2 = c1 + prototype[ M[ c1+PROTNUM ] ]->span; - ic = M[ c1+M[ c1 ]+LSC ]; + word t1; + + loosen(); + if (at1 == 0) + endprocess(0); + t1 = M[c1 + PROTNUM]; + /* ah of old */ + virt->addr = M[display2 + t1]; + virt->mark = M[virt->addr + 1]; + /* am of old */ + *am = c1; + /* loop up DL */ + storevirt(*virt, at2); + /* am of DL */ + at2 = M[at1]; + update(at2, at1); + c1 = at2; + c2 = c1 + prototype[M[c1 + PROTNUM]]->span; + ic = M[c1 + M[c1] + LSC]; } @@ -191,51 +216,55 @@ static void back1(word at1, word at2, virtaddr *virt, word *am) * Return from classes, coroutines and by end from procedures. */ void back(virtaddr *virt, word *am, word length) -{ - word t1, t2, plist; - int i; - protdescr *ptr; - message msg; - - t2 = c1+M[ c1 ]; - t1 = M[ t2+DL ]; /* ah of DL */ - ptr = prototype[ M[ c1+PROTNUM ] ]; /* prototype of current */ - if (ptr->kind == PROCESS) /* RETURN in process */ - { -# ifdef RPCDBG - fprintf( stderr, "return from process %d\n", thispix ); -# endif - if (M[ c1+PROTNUM ] == MAINBLOCK) endprocess(0); - { - virtaddr v; - loadvirt( v, t2+DL ); - obj2mess( M, &v, &msg.control.receiver ); /* father process */ - } - msg.control.type = CREACK; - moveparams(thispix, c1, &msg, PAROUT, LOADPAR); - sendmsg1(&msg); /* send create acknowledge */ - M[ t2+DL ] = 0; /* cut DL of new process head */ - passivate(STOPPED); /* and suspend new process */ - } - else - if (ptr->kind == COROUTINE) { - if (t1 != 0) /* nothing if detached */ - { - M[ t2+LSC ] = ic; - back1(t1, t2+DL, virt, am); - } - } - else - { - plist = ic; /* save begining of prototype list */ - if (ptr->lthpreflist==1 && t1==M[t2+SL] && M[t2+DL+1]==M[t2+SL+1]) - backbl(virt, am); - else - back1(t1, t2+DL, virt, am); + word t1, t2, plist; + int i; + protdescr *ptr; + message msg; + + t2 = c1 + M[c1]; + /* ah of DL */ + t1 = M[t2 + DL]; + /* prototype of current */ + ptr = prototype[M[c1 + PROTNUM]]; + /* RETURN in process */ + if (ptr->kind == PROCESS) { +#ifdef RPCDBG + fprintf( stderr, "return from process %d\n", thispix); +#endif + if (M[c1 + PROTNUM] == MAINBLOCK) + endprocess(0); + { + virtaddr v; + loadvirt(v, t2 + DL); + /* father process */ + obj2mess(M, &v, &msg.control.receiver); + } + msg.control.type = CREACK; + moveparams(thispix, c1, &msg, PAROUT, LOADPAR); + /* send create acknowledge */ + sendmsg1(&msg); + /* cut DL of new process head */ + M[t2 + DL] = 0; + /* and suspend new process */ + passivate(STOPPED); + } else if (ptr->kind == COROUTINE) { + /* nothing if detached */ + if (t1 != 0) { + M[t2 + LSC] = ic; + back1(t1, t2 + DL, virt, am); + } + } else { + /* save begining of prototype list */ + plist = ic; + if (ptr->lthpreflist == 1 && t1 == M[t2 + SL] && + M[t2 + DL + 1] == M[t2 + SL + 1]) + backbl(virt, am); + else + back1(t1, t2 + DL, virt, am); /* -# ifdef RPCDBG +#ifdef RPCDBG fprintf( stderr, "back (thisp=%d) from %s to %s\n", thispix, @@ -248,38 +277,47 @@ void back(virtaddr *virt, word *am, word length) ), isprocess((virtaddr*)(M+t2+RPCDL)) ? "PROCESS" : "OBJECT" ); -# endif +#endif */ - if ((ptr->kind == PROCEDURE || ptr->kind == FUNCTION) && - isprocess((virtaddr*)(M+t2+RPCDL))) - { - { - virtaddr v; - loadvirt( v, t2+RPCDL ); - obj2mess( M, &v, &msg.control.receiver ); /* remote DL */ - } - - /*fprintf( - stderr, "send rpc ack from process %d to (%d,%d,%d)\n", - thispix, - msg.control.receiver.node, - msg.control.receiver.pix, - msg.control.receiver.mark - );*/ - - msg.control.type = RPCACK; - moveparams(thispix, *am, &msg, PAROUT, LOADPAR); - sendmsg1(&msg); /* send RP return - acknowledge */ - gkill(virt); /* kill procedure object manualy */ - popmask(thispix); /* restore RPC mask from stack */ - for (i = 0; i < length; i++) /* and modify it */ - { - t1 = virtprot(M[ plist++ ]); /* prototype number */ - if (t1 > 0) enable(thispix, t1); - else disable(thispix, -t1); - } - evaluaterpc(thispix); /* check for enabled RPCs */ - } + if ((ptr->kind == PROCEDURE || ptr->kind == FUNCTION) && + isprocess((virtaddr*)(M+t2+RPCDL))) { + + { + virtaddr v; + loadvirt(v, t2 + RPCDL); + /* remote DL */ + obj2mess(M, &v, &msg.control.receiver); + } + + /* + fprintf(stderr, + "send rpc ack from process %d to (%d,%d,%d)\n", + thispix, + msg.control.receiver.node, + msg.control.receiver.pix, + msg.control.receiver.mark + ); + */ + msg.control.type = RPCACK; + moveparams(thispix, *am, &msg, PAROUT, LOADPAR); + /* send RP return - acknowledge */ + sendmsg1(&msg); + /* kill procedure object manualy */ + gkill(virt); + /* restore RPC mask from stack */ + popmask(thispix); + /* and modify it */ + for (i = 0; i < length; i++) { + /* prototype number */ + t1 = virtprot(M[plist++]); + if (t1 > 0) + enable(thispix, t1); + else + disable(thispix, -t1); + } + /* check for enabled RPCs */ + evaluaterpc(thispix); + } } } @@ -289,113 +327,139 @@ void back(virtaddr *virt, word *am, word length) */ void backpr(virtaddr *virt, word *am) { - word t1, t2, t3; - - t2 = c1+M[ c1 ]+DL; /* DL pointer of current */ - t1 = M[ t2 ]; /* ah of DL */ - t3 = c1+M[ c1 ]+SL; /* SL pointer */ - if (t1 == M[ t3 ] && M[ t2+1 ] == M[ t3+1 ]) backbl(virt, am); /* SL=DL */ - else back1(t1, t2, virt, am); + word t1, t2, t3; + /* DL pointer of current */ + t2 = c1 + M[c1] + DL; + /* ah of DL */ + t1 = M[t2]; + /* SL pointer */ + t3 = c1 + M[c1]+SL; + /* SL=DL */ + if (t1 == M[t3] && M[t2 + 1] == M[t3 + 1]) + backbl(virt, am); + else + back1(t1, t2, virt, am); } -/* End in classes and coroutines. */ +/** End in classes and coroutines. */ void fin(word backic, virtaddr *virt, word *am) { - word t1, t2, knd; - - knd = prototype[ M[ c1+PROTNUM ] ]->kind; - if (knd != COROUTINE && knd != PROCESS) - back(virt, am, (word) 0); /* a class - exit as above */ - else - { - ic = backic; /* backspace ic */ - t2 = c1+M[ c1 ]; - t1 = M[ t2+DL ]; /* ah of DL */ - if (t1 == 0) - { - if (M[ t2+SL ] == DUMMY) endprocess(0); - ic = 0; /* coroutine terminated */ - *am = 0; - detach(); + word t1, t2, knd; + + knd = prototype[M[c1 + PROTNUM]]->kind; + if (knd != COROUTINE && knd != PROCESS) { + /* a class - exit as above */ + back(virt, am, (word) 0); } - else - { - M[ t2+LSC ] = ic; - back1(t1, t2+DL, virt, am); + else { + /* backspace ic */ + ic = backic; + t2 = c1 + M[c1]; + /* ah of DL */ + t1 = M[t2 + DL]; + if (t1 == 0) { + if (M[t2 + SL] == DUMMY) + endprocess(0); + /* coroutine terminated */ + ic = 0; + *am = 0; + detach(); + } else { + M[t2 + LSC] = ic; + back1(t1, t2 + DL, virt, am); + } } - } } -/* Helper for attach/detach */ +/** Helper for attach/detach */ static void att2(virtaddr *virt, word ax, word at1) { - word t1, t2, phead; - - t1 = M[ display2+M[ c1+PROTNUM ] ]; /* ah of current */ - t2 = at1+M[ at1 ]+DL; /* DL of coroutine head */ - M[ t2 ] = t1; /* loop up DL */ - M[ t2+1 ] = M[ t1+1 ]; - M[ c1+M[ c1 ]+LSC ] = ic; /* preserve local control */ - loosen(); - phead = thisp->prochead; - storevirt(*virt, phead+M[ phead ]+CHD); - t2 = M[ ax+DL ]; - if (t2 == 0) errsignal(RTECORAC); /* coroutine active */ - M[ ax+DL ] = 0; /* cut DL of new coroutine head */ - c1 = M[ t2 ]; - update(c1, t2); - c2 = c1+prototype[ M[ c1+PROTNUM ] ]->span; - ic = M[ c1+M[ c1 ]+LSC ]; - if (ic == 0) errsignal(RTECORTM); /* coroutine terminated */ + word t1, t2, phead; + + /* ah of current */ + t1 = M[display2 + M[c1 + PROTNUM]]; + /* DL of coroutine head */ + t2 = at1 + M[at1] + DL; + /* loop up DL */ + M[t2] = t1; + M[t2 + 1] = M[t1 + 1]; + /* preserve local control */ + M[c1 + M[c1] + LSC] = ic; + loosen(); + phead = thisp->prochead; + storevirt(*virt, phead + M[phead] + CHD); + t2 = M[ax + DL]; + /* coroutine active */ + if (t2 == 0) + errsignal(RTECORAC); + /* cut DL of new coroutine head */ + M[ax + DL] = 0; + c1 = M[t2]; + update(c1, t2); + c2 = c1 + prototype[M[c1 + PROTNUM]]->span; + ic = M[ c1 + M[c1] + LSC]; + /* coroutine terminated */ + if (ic == 0) + errsignal(RTECORTM); } void attach(virtaddr *virt) { - word t1, ax, phead, chead; - int knd; - - if (M[ virt->addr+1 ] != virt->mark) errsignal(RTEILLAT); - else ax = M[ virt->addr ]; /* am */ - t1 = M[ ax+PROTNUM ]; - if (t1 == AINT || t1 == AREAL || t1 == AVIRT || t1 == FILEOBJECT) - errsignal(RTEILLAT); - knd = prototype[ t1 ]->kind; - if (knd != COROUTINE && knd != PROCESS) errsignal(RTEILLAT); - ax = ax+M[ ax ]; - phead = thisp->prochead; - chead = phead+M[ phead ]+CHD; - if (virt->addr != M[ chead ] || virt->mark != M[ chead+1 ]) - { - M[ ax+CL ] = M[ chead ]; - M[ ax+CL+1 ] = M[ chead+1 ]; - att2(virt, ax, M[ M[ chead ] ]); - } + word t1, ax, phead, chead; + int knd; + + if (M[virt->addr + 1] != virt->mark) + errsignal(RTEILLAT); + else { + /* am */ + ax = M[virt->addr]; + } + t1 = M[ax + PROTNUM]; + if (t1 == AINT || t1 == AREAL || t1 == AVIRT || t1 == FILEOBJECT) + errsignal(RTEILLAT); + knd = prototype[t1]->kind; + if (knd != COROUTINE && knd != PROCESS) + errsignal(RTEILLAT); + ax = ax + M[ax]; + phead = thisp->prochead; + chead = phead + M[phead] + CHD; + if (virt->addr != M[chead] || virt->mark != M[chead + 1]) { + M[ax + CL] = M[chead]; + M[ax + CL + 1] = M[chead + 1]; + att2(virt, ax, M[M[chead]]); + } } void detach() { - virtaddr virt; - word t1, phead; - - phead = thisp->prochead; - t1 = M[ M[ phead+M[ phead ]+CHD ] ]; /* am of coroutine head */ - loadvirt(virt, t1+M[ t1 ]+CL); /* coroutine link */ - if (M[ virt.addr+1 ] != virt.mark) errsignal(RTEILLDT); - att2(&virt, M[ virt.addr ]+M[ M[ virt.addr ] ], t1); + virtaddr virt; + word t1, phead; + + phead = thisp->prochead; + /* am of coroutine head */ + t1 = M[M[phead + M[phead] + CHD]]; + /* coroutine link */ + loadvirt(virt, t1 + M[t1] + CL); + if (M[virt.addr + 1] != virt.mark) + errsignal(RTEILLDT); + att2(&virt, M[virt.addr] + M[M[virt.addr]], t1); } /* Simulate execution of inner */ void inner(word level) { - word t1; - protdescr *ptr; - - ptr = prototype[ M[ c1+PROTNUM ] ]; /* prototype of current */ - t1 = ptr->lthpreflist; - if (t1 != level) - if (level == t1-1) ic = ptr->codeaddr; - else ic = prototype[ M[ ptr->preflist+level ] ]->codeaddr; + word t1; + protdescr *ptr; + + /* prototype of current */ + ptr = prototype[M[c1 + PROTNUM]]; + t1 = ptr->lthpreflist; + if (t1 != level) + if (level == t1-1) + ic = ptr->codeaddr; + else + ic = prototype[M[ptr->preflist + level]]->codeaddr; }