From 299b0d67859cfe8122564e53b2093f18273b13b6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rafa=C5=82=20D=C5=82ugo=C5=82=C4=99cki?= Date: Mon, 22 Jul 2013 05:51:05 +0200 Subject: [PATCH] vlp-10 using coding style in runsys.c --- src/int/runsys.c | 443 +++++++++++++++++++++++++++-------------------- 1 file changed, 253 insertions(+), 190 deletions(-) diff --git a/src/int/runsys.c b/src/int/runsys.c index 310ba4f..6ff0c81 100644 --- a/src/int/runsys.c +++ b/src/int/runsys.c @@ -39,61 +39,84 @@ or Andrzej Salwicki */ void runsys() { - word apt, i; - procaddr father; + word apt, i; + procaddr father; - for (i = 0; i < MAXPROCESS; i++ ) /* initialize process descriptors */ - { - process[ i ].used = FALSE; /* not used */ - process[ i ].mark = -1; /* initial mark for processes */ - process[ i ].M = NULL; /* memory not allocated */ - process[ i ].hash = NULL; - } - process[ 0 ].M = M; /* always contains code */ - dispoff = VIRTSC-(lastprot+1); /* DISPLAY offset in process object */ - disp2off = dispoff-(lastprot+1); /* indirect DISPLAY offset */ - ready = qinit(); /* initialize Round-Robin queue */ - ranset(); /* init pseudo-random no. generator */ + /* initialize process descriptors */ + for (i = 0; i < MAXPROCESS; i++) { + /* not used */ + process[i].used = FALSE; + /* initial mark for processes */ + process[i].mark = -1; + /* memory not allocated */ + process[i].M = NULL; + process[i].hash = NULL; + } + /* always contains code */ + process[0].M = M; + /* DISPLAY offset in process object */ + dispoff = VIRTSC - (lastprot + 1); + /* indirect DISPLAY offset */ + disp2off = dispoff - (lastprot + 1); + /* initialize Round-Robin queue */ + ready = qinit(); + /* init pseudo-random no. generator */ + ranset(); #if OS2 - { - SEL gsel, lsel; - DosGetInfoSeg(&gsel, &lsel); - ginf = MAKEPGINFOSEG(gsel); - } + { + SEL gsel, lsel; + DosGetInfoSeg(&gsel, &lsel); + ginf = MAKEPGINFOSEG(gsel); + } #endif - if (!remote) /* create main process */ - { - father.node = 0; /* dummy DL for generated process */ - father.pix = 0; - father.mark = 0; - thispix = 0; /* current process index */ - thisp = &process[ thispix ]; /* current process descr pointer */ - initprocess((word) 0, (word) MAINBLOCK, &father); - mainprog = thisp->prochead; /* am of main */ - c1 = thisp->c1; /* pointers to current object */ - c2 = thisp->c2; - ic = thisp->ic; /* instruction counter */ - param = thisp->param; /* parameter vector */ - apt = mainprog+M[ mainprog ]; /* LWA+1 of main */ - display = apt+dispoff; /* DISPLAY in main */ - display2 = apt+disp2off; /* indirect DISPLAY in main */ - mnoff = 2; /* offset of variable mainprog */ - storevirt(thisp->procref, mainprog+mnoff); /* init variable main */ - M[ apt+STATSL ]++; /* flag main included in SL chain */ - thisp->status = STOPPED; - activate(thispix); /* activate main process */ - } - else /* remote */ - { - thispix = 0; /* a dirty trick: set junk current -*/ - thisp = &process[ thispix ];/* process for first -transfer() */ - } /* (must save 'context' somewhere) */ + /* create main process */ + if (!remote) { + /* dummy DL for generated process */ + father.node = 0; + father.pix = 0; + father.mark = 0; + /* current process index */ + thispix = 0; + /* current process descr pointer */ + thisp = &process[thispix]; + initprocess((word) 0, (word) MAINBLOCK, &father); + /* am of main */ + mainprog = thisp->prochead; + /* pointers to current object */ + c1 = thisp->c1; + c2 = thisp->c2; + /* instruction counter */ + ic = thisp->ic; + /* parameter vector */ + param = thisp->param; + /* LWA+1 of main */ + apt = mainprog + M[mainprog]; + /* DISPLAY in main */ + display = apt + dispoff; + /* indirect DISPLAY in main */ + display2 = apt + disp2off; + /* offset of variable mainprog */ + mnoff = 2; + /* init variable main */ + storevirt(thisp->procref, mainprog + mnoff); + /* flag main included in SL chain */ + M[apt + STATSL]++; + thisp->status = STOPPED; + /* activate main process */ + activate(thispix); + } + /* remote */ + else { + /* a dirty trick: set junk current */ + thispix = 0; + /* process for first transfer() */ + thisp = &process[thispix]; + /* (must save 'context' somewhere) */ + } #if DLINK - net_attention(); + net_attention(); #endif } @@ -102,81 +125,107 @@ transfer() */ */ void initprocess(word pix, word prot, procaddr *father) { - procdescr *p; - protdescr *ptr; - word i, j, ah, am, apt; + procdescr *p; + protdescr *ptr; + word i, j, ah, am, apt; #ifdef RPCDBG -fprintf(stderr,"new process(n,p,m) (%d,%d,%d)",0,pix,process[pix].mark); -fprintf(stderr," from (%d,%d,%d)\n",father->node,father->pix,father->mark); + fprintf(stderr, "new process(n,p,m) (%d,%d,%d)", 0, pix, + process[pix].mark); + fprintf(stderr, " from (%d,%d,%d)\n", father->node, father->pix, + father->mark); #endif - p = &process[ pix ]; + p = &process[pix]; #ifdef OBJECTADDR - hash_create(p,119); + hash_create(p, 119); #endif - p->used = TRUE; /* process descriptor is used */ - p->prot = prot; /* prototype number */ - p->freeitem = 0; /* null list of free dictionary items */ - p->upper = memorysize-1; /* highest memory address */ - p->lower = freem; /* lowest address for data */ - p->headk = p->lower; /* head of killed objects list */ - p->M[ p->headk ] = MAXAPPT; /* maximum appetite sentinel */ - p->headk2 = 0; - ah = p->upper-1; /* dict. item for process itself */ - p->lastitem = ah; /* first word used by dictionary */ - ptr = prototype[ prot ]; - if (p->upper - p->lower - ptr->appetite < 512) - if (prot == MAINBLOCK) - abend("Memory size too small (use /m option)\n"); - else errsignal(RTEMEMOV); + /* process descriptor is used */ + p->used = TRUE; + /* prototype number */ + p->prot = prot; + /* null list of free dictionary items */ + p->freeitem = 0; + /* highest memory address */ + p->upper = memorysize - 1; + /* lowest address for data */ + p->lower = freem; + /* head of killed objects list */ + p->headk = p->lower; + /* maximum appetite sentinel */ + p->M[ p->headk ] = MAXAPPT; + p->headk2 = 0; + /* dict. item for process itself */ + ah = p->upper - 1; + /* first word used by dictionary */ + p->lastitem = ah; + ptr = prototype[prot]; + if (p->upper - p->lower - ptr->appetite < 512) + if (prot == MAINBLOCK) + abend("Memory size too small (use /m option)\n"); + else errsignal(RTEMEMOV); /* generate process object */ - p->lastused = p->lower+ptr->appetite; - am = p->lower+1; - p->M[ am ] = ptr->appetite; - p->M[ am+PROTNUM ] = prot; - for (i = PROTNUM+1; i < ptr->appetite; i++) - p->M[ am+i ] = 0; - p->M[ ah ] = am; - p->M[ ah+1 ] = 0; - p->prochead = am; - p->procref.addr = ah; - p->procref.mark = 0; - p->c1 = am; /* initialize current object ptrs */ - p->c2 = am+ptr->span; - apt = am+ptr->appetite; - p->M[ apt+CHD ] = ah; /* initialize coroutine head ptr */ - p->M[ apt+CHD+1 ] = 0; - p->M[ apt+SL ] = DUMMY; /* dummy SL for process */ - p->M[ 1 ] = 1; /* absolute none */ - for (i = MAINBLOCK; i <= lastprot; i++) /* initialize DISPLAY */ - p->M[ apt+dispoff+i ] = 0; - p->M[ apt+disp2off+MAINBLOCK ] = DUMMY; /* dummmy entry for MAIN */ - j = ptr->preflist; /* set DISPLAY entries for process */ + p->lastused = p->lower + ptr->appetite; + am = p->lower + 1; + p->M[am] = ptr->appetite; + p->M[am + PROTNUM] = prot; + for (i = PROTNUM + 1; i < ptr->appetite; i++) + p->M[am + i] = 0; + p->M[ah] = am; + p->M[ah + 1] = 0; + p->prochead = am; + p->procref.addr = ah; + p->procref.mark = 0; + /* initialize current object ptrs */ + p->c1 = am; + p->c2 = am + ptr->span; + apt = am + ptr->appetite; + /* initialize coroutine head ptr */ + p->M[apt + CHD] = ah; + p->M[apt + CHD + 1] = 0; + /* dummy SL for process */ + p->M[apt + SL] = DUMMY; + /* absolute none */ + p->M[1] = 1; + /* initialize DISPLAY */ + for (i = MAINBLOCK; i <= lastprot; i++) { + /* dummmy entry for MAIN */ + p->M[apt + dispoff + i] = 0; + } + p->M[apt + disp2off + MAINBLOCK] = DUMMY; + /* set DISPLAY entries for process */ + j = ptr->preflist; + + for (i = j + ptr->lthpreflist - 1; i >= j; i--) { + /* physical address */ + p->M[apt + dispoff + M[i]] = am; + /* indirect address */ + p->M[apt + disp2off + M[i]] = ah; + } - for (i = j+ptr->lthpreflist-1; i >= j; i--) - { - p->M[ apt+dispoff+M[ i ] ] = am; /* physical address */ - p->M[ apt+disp2off+M[ i ] ] = ah; /* indirect address */ - } + { + virtaddr v; + mess2obj(p, father, &v); + p->M[apt + DL] = v.addr; + p->M[apt + DL + 1] = v.mark; + } + p->msgqueue = qinit(); + p->rpcwait = qinit(); + p->rpcmask = sinit(); + /* initialy all RPCs are disabled */ + pushmask(pix); + /* trace line number */ + p->trlnumber = 0; + /* search for executable prefix */ + i = ptr->preflist; + while (prototype[p->M[i]]->kind == RECORD) + i++; - { - virtaddr v; - mess2obj( p, father, &v ); - p->M[ apt+DL ] = v.addr; - p->M[ apt+DL+1 ] = v.mark; - } - p->msgqueue = qinit(); - p->rpcwait = qinit(); - p->rpcmask = sinit(); - pushmask(pix); /* initialy all RPCs are disabled */ - p->trlnumber = 0; /* trace line number */ - i = ptr->preflist; /* search for executable prefix */ - while (prototype[ p->M[ i ] ]->kind == RECORD) i++; - p->ic = prototype[ M[ i ] ]->codeaddr; /* first instruction address */ - p->force_compactification=FALSE; + /* first instruction address */ + p->ic = prototype[M[i]]->codeaddr; + p->force_compactification = FALSE; } @@ -185,10 +234,15 @@ fprintf(stderr," from (%d,%d,%d)\n",father->node,father->pix,father->mark); */ bool member(virtaddr *virt, word *am) { - *am = M[ virt->addr ]; - /* if (virt->mark == M[ virt->addr+1] ) fprintf(stderr, "Yes"); - else {fprintf(stderr, "No");}; */ - return (virt->mark == M[ virt->addr+1 ]); + *am = M[virt->addr]; +/* + if (virt->mark == M[virt->addr + 1]) + fprintf(stderr, "Yes"); + else { + fprintf(stderr, "No"); + } +*/ + return (virt->mark == M[virt->addr + 1]); } /** @@ -196,31 +250,34 @@ bool member(virtaddr *virt, word *am) */ void update(word am, word ah) { - word t1, t2, t3, t4, t5, t6; - protdescr *ptr; + word t1, t2, t3, t4, t5, t6; + protdescr *ptr; - while (TRUE) - { - t1 = am+M[ am ]; - M[ t1+STATSL ]++; /* flag object included in SL */ - ptr = prototype[ M[ am+PROTNUM ] ]; - t2 = ptr->preflist; - t3 = t2+ptr->lthpreflist-1; - for (t4 = t3; t4 >= t2; t4-- ) - { - t6 = M[ t4 ]; - t5 = display+t6; - if (M[ t5 ] == 0) /* entry to be updated */ - { - M[ t5 ] = am; - M[ display2+t6 ] = ah; - } - } - ah = M[ t1+SL ]; - if (ah == DUMMY) break; - if (M[ ah+1 ] != M[ t1+SL+1 ]) errsignal(RTESLCOF); - am = M[ ah ]; - } + while (TRUE) { + t1 = am + M[am]; + /* flag object included in SL */ + M[t1 + STATSL]++; + ptr = prototype[M[am + PROTNUM]]; + t2 = ptr->preflist; + t3 = t2 + ptr->lthpreflist - 1; + for (t4 = t3; t4 >= t2; t4--) { + t6 = M[t4]; + t5 = display + t6; + /* entry to be updated */ + if (M[ t5 ] == 0) { + M[t5] = am; + M[display2 + t6] = ah; + } + } + ah = M[t1 + SL]; + if (ah == DUMMY) + break; + + if (M[ah + 1] != M[t1 + SL + 1]) + errsignal(RTESLCOF); + + am = M[ah]; + } } /** @@ -228,22 +285,26 @@ void update(word am, word ah) */ void loosen() { - word t1, t2, t3; - protdescr *ptr; + word t1, t2, t3; + protdescr *ptr; - t1 = c1; - while (TRUE) - { - ptr = prototype[ M[ t1+PROTNUM ] ]; - t2 = ptr->preflist; - for (t3 = t2+ptr->lthpreflist-1; t3 >= t2; t3-- ) - M[ display+M[ t3 ] ] = 0; - t3 = t1+M[ t1 ]; - M[ t3+STATSL ]--; /* flag object removed from SL */ - t1 = M[ t3+SL ]; /* ah of SL */ - if (t1 == DUMMY) break; /* still not main */ - t1 = M[ t1 ]; /* am of SL */ - } + t1 = c1; + while (TRUE) { + ptr = prototype[M[t1 + PROTNUM]]; + t2 = ptr->preflist; + for (t3 = t2 + ptr->lthpreflist - 1; t3 >= t2; t3--) + M[display + M[t3]] = 0; + t3 = t1 + M[t1]; + /* flag object removed from SL */ + M[t3 + STATSL]--; + /* ah of SL */ + t1 = M[t3 + SL]; + /* still not main */ + if (t1 == DUMMY) + break; + /* am of SL */ + t1 = M[t1]; + } } /** @@ -256,19 +317,20 @@ static int tracecnt = 0; */ void trace(word lineno) { - thisp->trlnumber = lineno; - if (debug && lineno > 0) - { - tracecnt++; - if (tracecnt == MAXTRACNT) /* change line */ - { - tracecnt = 0; - fprintf(tracefile, "\n"); - } - fprintf(tracefile, "%6ld", (long) lineno); - } - trapmsg(); /* check for waiting message */ - rpc2(); /* check for RPC message */ + thisp->trlnumber = lineno; + if (debug && lineno > 0) { + tracecnt++; + /* change line */ + if (tracecnt == MAXTRACNT) { + tracecnt = 0; + fprintf(tracefile, "\n"); + } + fprintf(tracefile, "%6ld", (long) lineno); + } + /* check for waiting message */ + trapmsg(); + /* check for RPC message */ + rpc2(); } /** @@ -276,29 +338,30 @@ void trace(word lineno) */ void endrun(int status) { - MESSAGE msg; - G_MESSAGE m; - int i; - - if (debug) fclose(tracefile); + MESSAGE msg; + G_MESSAGE m; + int i; + if (debug) + fclose(tracefile); - msg.msg_type = MSG_INT; - msg.param.pword[0] = INT_EXITING; - strcpy(msg.param.pstr,ProgName); - write(internal_sock,&msg,sizeof(MESSAGE)); - m.msg_type = MSG_GRAPH; - m.param.pword[0] = GRAPH_FREE; - write(graph_sock,&m,sizeof(G_MESSAGE)); - close(internal_sock); - close(graph_sock); - close(net_sock); - unlink(mygname); - unlink(mykname); - unlink(mynname); - for(i=0;i<255;i++) - if (DirConn[i]!=-1) close(DirConn[i]); - exit(status); + msg.msg_type = MSG_INT; + msg.param.pword[0] = INT_EXITING; + strcpy(msg.param.pstr, ProgName); + write(internal_sock, &msg, sizeof(MESSAGE)); + m.msg_type = MSG_GRAPH; + m.param.pword[0] = GRAPH_FREE; + write(graph_sock, &m, sizeof(G_MESSAGE)); + close(internal_sock); + close(graph_sock); + close(net_sock); + unlink(mygname); + unlink(mykname); + unlink(mynname); + for(i = 0; i < 255; i++) + if (DirConn[i] != -1) + close(DirConn[i]); + exit(status); } -- 2.30.2