diff -ruN klic-3.003-2002-01-02/runtime/gg_shvar.c klic-3.003-2002-01-03/runtime/gg_shvar.c
--- klic-3.003-2002-01-02/runtime/gg_shvar.c	Sat Dec 29 12:46:20 2001
+++ klic-3.003-2002-01-03/runtime/gg_shvar.c	Wed Jan  2 14:19:07 2002
@@ -21,6 +21,32 @@
 #define GG_CLASS_NAME() shvar
 #define GG_OBJ_TYPE struct Shvar
 
+#define cmp_forward_ptr(x,y) ( {\
+    int xv;                 \
+    int yv;                 \
+    int ret;                \
+    xv = get_space(x);      \
+    yv = get_space(y);      \
+    if ( xv == yv ) {       \
+      if ((x) < (y)) ret = 1; \
+      else         ret = 0; \
+    } else if ( xv < yv ) { \
+       ret = 1;             \
+    } else {                \
+       ret = 0;             \
+    }                       \
+    ret;} )
+
+#define is_forward_space_ptr(X) ( {\
+    int ok = 0;\
+    int cid = currid;\
+    while ( (cid = PLNE_ptr[cid]->direct) != (-1) ) {\
+       if ( (unsigned long)((long)(X)-(long)(PLNE_ptr[cid]->top_addr) ) < SHM_SIZE ) {\
+	 ok = 1; break;\
+       }\
+    }\
+    ok; } )
+
 typedef struct Shvar {
   struct generator_object_method_table *method_table;
   Sinfo chain;
diff -ruN klic-3.003-2002-01-02/runtime/shm.h klic-3.003-2002-01-03/runtime/shm.h
--- klic-3.003-2002-01-02/runtime/shm.h	Fri Dec 28 13:46:47 2001
+++ klic-3.003-2002-01-03/runtime/shm.h	Wed Jan  2 14:34:04 2002
@@ -21,8 +21,6 @@
 extern long N_PLNE;
   /* size of 1 Shared-memory plane */
 extern long SHM_SIZE;
-  /* last PE for Profile */
-extern long LAST_PE;
 extern long Disp_child;
 
 Extern int shm_trace_lock Init(0);
@@ -30,33 +28,20 @@
 #define MASTER 0
 
 #define MAX_N_PE  32
-#define MAX_N_PLNE 8
-
-#define is_shmconnect(X) (1)
-
-#define is_locala(X) \
-    ( (unsigned long)((long)(X)-(long)heaptop) < real_heapbytesize )
 
   /* Shared-memory address or no */
 #define is_shma(X) \
     ( (unsigned long)((long)(X)-(long)SHM_HEAP_TOP ) < SHP_SIZE )
 
-/* calculates a hash key for lock
-*/
+/* calculates a hash key for lock */
 #define HTBL_base 0
-  /* allocating shared-memory */
-#define g_key()      HTBL_base
-  /* updating the shared-memory management table */
-#define m_key()      (HTBL_base+1)
-  /* for Sequential GC */
-#define gc_key()     (HTBL_base+2)
-  /* updating atom table */
-#define a_key()     (HTBL_base+3)
-  /* updating functor table */
-#define f_key()     (HTBL_base+4)
-#define tr_key()    (HTBL_base+5)
-  /* queuing a goal to external process */
-#define p_key(penum)  (HTBL_base + 6 + (penum))
+#define g_key()  HTBL_base  /* allocating shared-memory */
+#define m_key()  (HTBL_base+1)  /* updating the shared-memory management table */
+#define gc_key() (HTBL_base+2)  /* for Sequential GC */
+#define a_key()  (HTBL_base+3)  /* updating atom table */
+#define f_key()  (HTBL_base+4)  /* updating functor table */
+#define tr_key() (HTBL_base+5)
+#define p_key(penum) (HTBL_base+6 + (penum))  /* queuing a goal to external process */
 
   /* global generator hook */
 #define is_genhook(X) ((long)(X) & 0x01)
@@ -89,16 +74,6 @@
   ADDRtbl_free = sl; \
 }while(0)
 
-#define makeshvar(svar) \
-do{ \
-  struct generator_susp* vcell; \
-  (svar) = (q) galloc((sizeof(struct generator_susp) / sizeof(q)) + 1); \
-  vcell = (struct generator_susp*) (((q*) svar) + 1); \
-  vcell->backpt = (q) (svar); \
-  vcell->u.o = tag_generator_susp(pSHM_VAR); \
-  *((q*) svar) = (q) vcell; \
-}while(0)
-
 
 #define get_space(X) ( {\
     int cid = currid;\
@@ -111,22 +86,6 @@
     } while( (cid = PLNE_ptr[cid]->direct) != (-1) ); \
     no; } )
 
-#define cmp_forward_ptr(x,y) ( {\
-    int xv;                 \
-    int yv;                 \
-    int ret;                \
-    xv = get_space(x);      \
-    yv = get_space(y);      \
-    if ( xv == yv ) {       \
-      if ((x) < (y)) ret = 1; \
-      else         ret = 0; \
-    } else if ( xv < yv ) { \
-       ret = 1;             \
-    } else {                \
-       ret = 0;             \
-    }                       \
-    ret;} )
-
 #define ck_new_galloc(X) \
 do{ \
     int cid = currid;\
@@ -136,19 +95,6 @@
 }while(0)
 
 
-#define is_cur_space_ptr(X) ( \
-    (unsigned long)((long)(X)-(long)(PLNE_ptr[currid]->top_addr) ) < SHM_SIZE )
-
-#define is_forward_space_ptr(X) ( {\
-    int ok = 0;\
-    int cid = currid;\
-    while ( (cid = PLNE_ptr[cid]->direct) != (-1) ) {\
-       if ( (unsigned long)((long)(X)-(long)(PLNE_ptr[cid]->top_addr) ) < SHM_SIZE ) {\
-	 ok = 1; break;\
-       }\
-    }\
-    ok; } )
-
 #define is_cur_or_forward_ptr(X) ( {\
     int ok = 0;\
     int cid = currid;\
@@ -159,16 +105,6 @@
     } while ( (cid = PLNE_ptr[cid]->direct) != (-1) ) ;\
     ok; } )
 
-#define ck_throw_new_galloc(num) \
-do{ \
-    int cid = currid;\
-    while( (cid=PLNE_ptr[cid]->direct) != -1 ) { \
-       if ( PLNE_ptr[cid]->proc[num] ) {new_galloc(cid);} \
-    }\
-}while(0)
-
-
-
 
   /* Structures */
 typedef struct addr_tbl {
@@ -221,12 +157,8 @@
 extern int* volatile pe_status;
 extern int* volatile cur_status;
 
-extern long* volatile Prof_measure;
-
 extern struct global_variables* top_shm_glbl;
 
-extern int* top_shm_pid;
-
 extern struct ex_goalrec** volatile top_shm_qp;
 
 /* runtime/shm_rsv.c */
@@ -261,12 +193,6 @@
 
 
 /* runtime/shm_throw.c */
- 
-/* convert real PE number from Logical PE number */
-extern int phisc_pe(int NO);
-
-/* copy into shared memory */
-extern struct ex_goalrec* shm_goal_copy(struct goalrec* qp, long prio);
 
 /* copy argument into shared memory */
 extern q shm_copy(q src);
@@ -299,13 +225,9 @@
 extern struct goalrec* shm_gc(struct goalrec* qp);
 
 /* for GC */
-
 extern q** shm_gcstack;
 extern q** shm_gcmax;
 extern q** shm_sp;
 extern int shm_gcstack_size;
-
-/* for debugging */
-#define debug_wait()  do{ while(!*pe_status) {} }while(0)
 
 #endif /* _KLIC_SHM_H_ */
diff -ruN klic-3.003-2002-01-02/runtime/shm_gc.c klic-3.003-2002-01-03/runtime/shm_gc.c
--- klic-3.003-2002-01-02/runtime/shm_gc.c	Sat Dec 29 12:46:20 2001
+++ klic-3.003-2002-01-03/runtime/shm_gc.c	Wed Jan  2 13:59:56 2002
@@ -6,7 +6,7 @@
 ----------------------------------------------------------- */
 
 #include <stdio.h>
-#include <klic/basic.h>  /* fatal */
+#include <klic/basic.h>  /* fatalf */
 #include <klic/struct.h>
 #include "timing.h"
 #include <klic/primitives.h>
@@ -16,6 +16,8 @@
 #include "shm.h"
 #include <time.h>
 
+extern q** make_shm_larger_stack();
+
 /* ------- Optinal Flags --------------------------------- */
 /* FLAGS                                                                */
 /*      IAFWD   ... Implicit All Forwarding                             */
@@ -54,12 +56,12 @@
 /* atomic swap(ptr,io) */
 /* *ptr <-> io */
 #define atomic_swap(ptr,io) ( {\
-     register long  v  asm ("g2") = (long)io;   \
-     register long* s1 asm ("g3") = (long*)ptr; \
+     register long  v  asm ("g2") = (long) io;   \
+     register long* s1 asm ("g3") = (long*) ptr; \
      asm volatile ("                            \
      swap [%%g3],%%g2;                          \
 " : "=g" (v) : "g" (v), "g" (s1) );             \
-  io = (q)v;                                    \
+  io = (q) v;                                    \
   } )
 
 /*
@@ -89,15 +91,9 @@
 #endif
 
 /* For debugging */
-#define ASSERT(cond,mess)      
-/* \
-        if (!(cond))            \
-          fatal((sprintf(msgstr,"** ASSERT ERROR: %s. **\n",mess),msgstr));
-*/
-
-char msgstr[128];
-
-q** make_shm_larger_stack();
+#define ASSERT(cond,mess)  /* \
+  if( !(cond) ) \
+    fatalf( "** ASSERT ERROR: %s. **\n", mess ); */
 
 #define push_shm_stack(addr,sp,max)                     \
 {                                                       \
@@ -127,8 +123,6 @@
   (unsigned long)((long)(X) - (long)(PLNE_ptr[currid]->top_addr) ) < SHM_SIZE )
 
 /* Global varibles */
-int shm_gc_times = 0;
-int measure_shmgc = 1;
 int F_shm_gc;
 q** shm_gcstack;
 q** shm_gcmax;
@@ -137,21 +131,24 @@
 
 extern struct ex_goalrec** top_shm_next;
 extern struct ex_goalrec** shm_qp;
-
 extern struct goalrec goal_queue_tail;
 
-/* checks shared-memory GC. called by "intrpt" routine */
-int ck_shm_gc()
+static int shm_gc_times = 0;
+static int measure_shmgc = 1;
+
+/* checks shared-memory GC.  called by "intrpt" routine */
+extern int
+ck_shm_gc()
 {
   declare_globals;
-  if ( oldid != currid ) {
+  if( oldid != currid ){
     F_shm_gc = 1;
-    return(1);
-  } else if ( PLNE_ptr[currid]->caddr > PLNE_ptr[currid]->limit1 ) {
+    return 1;
+  }else if( PLNE_ptr[currid]->caddr > PLNE_ptr[currid]->limit1 ){
     F_shm_gc = 1;
-    return(1);
-  } else {
-    return(0);
+    return 1;
+  }else{
+    return 0;
   }
 }
 
@@ -204,51 +201,54 @@
    *shm_qp = before;                               \
 }
 
-struct goalrec* shm_gc(qp)
-struct goalrec* qp;
+extern struct goalrec*
+shm_gc(qp)
+  struct goalrec* qp;
 {
-   declare_globals;
-   struct prioqrec *pq = prioq.next;
+  declare_globals;
+  struct prioqrec* pq = prioq.next;
 
-   struct timeval before, after;
-   int i,j;
-   q** sp = shm_sp;
-   q** max = shm_gcmax;
-   int qkey;
-   int key = gc_key();
-   *cur_status = 4;
+  struct timeval before, after;
+  int i, j;
+  q** sp = shm_sp;
+  q** max = shm_gcmax;
+  int qkey;
+  int key = gc_key();
+  *cur_status = 4;
+
+  /* printf("The %dth process Shared memory GC start!!\n",my_node); */
+  shm_gc_times++;
 
-/*   printf("The %dth process Shared memory GC start!!\n",my_node); */
-   shm_gc_times++;
 #ifdef TOPDOWN
-   if (measure_shmgc) {  gettimeofday(&before); }
+  if( measure_shmgc ){ gettimeofday(&before); }
 #endif
 
-   enter_shm_gc();
-/* chases my external pool */
-   qkey = p_key(my_node);
-   s_lock(qkey);
-   chase_ex_queue(ex_qp,sp,max);
-   s_unlock(qkey);
-
-/* chase qp */
-   for(; pq->prio >= 0; pq = pq->next) {
-     pq->q = chase_queue(pq->q, sp,max);
-   }
-   qp = chase_queue(qp, sp,max);
+  enter_shm_gc();
+  /* chases my external pool */
+  qkey = p_key(my_node);
+  s_lock(qkey);
+  chase_ex_queue(ex_qp, sp, max);
+  s_unlock(qkey);
+
+  /* chase qp */
+  for( ; pq->prio >= 0; pq = pq->next ){
+    pq->q = chase_queue(pq->q, sp, max);
+  }
+  qp = chase_queue(qp, sp, max);
 
-   shm_copy_terms(sp,max);
+  shm_copy_terms(sp, max);
 
-   exit_shm_gc();
+  exit_shm_gc();
 
 #ifdef TOPDOWN
-   if (measure_shmgc) {
-     gettimeofday(&after);
-     gcums += (after.tv_sec - before.tv_sec)*1000000+(after.tv_usec-before.tv_usec);
-   }
+  if( measure_shmgc ){
+    gettimeofday(&after);
+    gcums += (after.tv_sec - before.tv_sec)*1000000+(after.tv_usec-before.tv_usec);
+  }
 #endif
-   *cur_status = 3;
-   return(qp);
+
+  *cur_status = 3;
+  return qp;
 }
 
 #ifdef TOPDOWN
@@ -333,11 +333,11 @@
 /*									*/
 /* N.B. In gcc, these are compiled as constants under -O option.	*/
 /*									*/
-struct cons dummycons;
-struct functor dummyfunc;
-#define CDROFFSET	((q*)&(dummycons.cdr)- (q*)&dummycons)
-#define CARCDROFFSET	((q*)&(dummycons.car)- (q*)&(dummycons.cdr))
-#define FIRSTELTOFFSET	((q*)&(dummyfunc.args[0])- (q*)&dummyfunc)
+static struct cons dummycons;
+static struct functor dummyfunc;
+#define CDROFFSET	((q*) &(dummycons.cdr) - (q*) &dummycons)
+#define CARCDROFFSET	((q*) &(dummycons.car) - (q*) &(dummycons.cdr))
+#define FIRSTELTOFFSET	((q*) &(dummyfunc.args[0]) - (q*) &dummyfunc)
 
 #define qsizeof_cons	    (sizeof(struct cons)/sizeof(q))	   /* 2 */
 #define qsizeof_functor(n)  (sizeof(struct functor)/sizeof(q)+n-1) /* n+1 */
@@ -349,18 +349,17 @@
 /*									*/
 #if defined(SYNC_GC) && defined(PAR_GC)
 #define COPYING_MARK	makeref(sizeof(q))  /* impossible as normal object */
-#else
-#define lock_for_copying(fwdptraddr,offset,taggingfunc)
 #endif
 
-shm_copy_terms(sp,max)
-q** sp;
-q** max;
+static void
+shm_copy_terms(sp, max)
+  q** sp;
+  q** max;
 {
   declare_globals;
   q *objp, obj;
-  while (sp > shm_gcstack) {
-    (q)objp = pop_gc_command();
+  while( sp > shm_gcstack ){
+    (q) objp = pop_gc_command();
     ASSERT( isref(objp), "Shared heap topdown GC command error.");
     objp = refp(objp);	/* objp points to scavenging target cell */
     obj = *objp;	/* obj is content of scavenging target cell */
@@ -370,23 +369,23 @@
     ASSERT( !is_shma(objp) || within_new_space(objp), "objp in old space");
     ASSERT( obj == *objp, "obj != *objp");
 
-    switch ( ptagof(obj) ) {
+    switch( ptagof(obj) ){
     case CONS: {
       struct cons *old, *new;
       old = consp(obj);
 					/* in new space ? */
-      if ( within_new_space(old) ) continue;
+      if( within_new_space(old) ) continue;
 					/* already copied ? */
 #ifdef ISFWD
-      if ( isref(old->cdr) && within_new_space(refp(old->cdr)) ) {
-	*objp = makecons(refp(old->cdr)-CDROFFSET);
+      if( isref(old->cdr) && within_new_space(refp(old->cdr)) ){
+	*objp = makecons(refp(old->cdr) - CDROFFSET);
 	continue;
       }
 #endif
 #ifdef IAFWD
-      if ( isref(old->cdr) && within_new_space(refp(old->cdr)) &&
-	   (old->car == makeref(refp(old->cdr)+CARCDROFFSET)) ) {
-	*objp = makecons(refp(old->cdr)-CDROFFSET);
+      if( isref(old->cdr) && within_new_space(refp(old->cdr)) &&
+	  old->car == makeref(refp(old->cdr) + CARCDROFFSET) ){
+	*objp = makecons(refp(old->cdr) - CDROFFSET);
 	continue;
       }
 #endif
@@ -395,22 +394,22 @@
 	q x = COPYING_MARK;
 	volatile q* fpp = &(old->cdr);
 	int offset = CDROFFSET;
-	atomic_swap(fpp,x);
-	if ( x == COPYING_MARK ) {
+	atomic_swap(fpp, x);
+	if( x == COPYING_MARK ){
 	  /* being copied by somebody else */
-	  while ( x == COPYING_MARK ) x = *fpp;
+	  while( x == COPYING_MARK ) x = *fpp;
 	  ASSERT( isref(x) && within_new_space(refp(x)), "bad fwd");
-	  *objp = makecons(refp(x)-offset);
+	  *objp = makecons(refp(x) - offset);
 	  continue;
 	}
 					/* allocation */
-	new = (struct cons*)galloc(qsizeof_cons);
+	new = (struct cons*) galloc(qsizeof_cons);
 	new->cdr = x;			/* initialization of fwdptr position */
 	new->car = old->car;
       }
-#else
+#else  /* !defined(SYNC_GC) || !defined(PAR_GC) */
 					/* allocation */
-      new = (struct cons*)galloc(qsizeof_cons);
+      new = (struct cons*) galloc(qsizeof_cons);
 					/* initialization */
       new->cdr = old->cdr;
       new->car = old->car;
@@ -425,11 +424,11 @@
 #endif
 					/* nested scavenging */
       p_barrier();
-      if ( isatomic(new->car) ) {
-	   /* N.B. In IAFWD, new->cdr is already REF to new->car. */
+      if( isatomic(new->car) ){
+	/* N.B. In IAFWD, new->cdr is already REF to new->car. */
 	objp = &(new->cdr);
 	obj = *objp;
-      } else {
+      }else{
 	push_SCAVENGE(&(new->cdr));
 #ifdef ISFWD
 	old->car = makeref(&(new->car));
@@ -444,80 +443,81 @@
     }
     case VARREF: {
       q temp;
-      if ( within_new_space(refp(obj)) ) continue;
+      if( within_new_space(refp(obj)) ) continue;
       temp = derefone(obj);
-      if ( isref(temp) && obj == derefone(temp) ) {	/* double loop */
+      if( isref(temp) && obj == derefone(temp) ){	/* double loop */
         q svar;
         struct generator_susp* vcell;
         struct generator_object* addi;
         Shvar* gvar;
-        addi = n_lock(obj,temp);
-        if ( derefone(obj) != temp ) {
+        addi = n_lock(obj, temp);
+        if( derefone(obj) != temp ){
           obj = derefone(obj);
-          *objp = obj; goto TRO_LOOP;
+          *objp = obj;
+	  goto TRO_LOOP;
         }
-        svar = (q)galloc((sizeof(struct generator_susp)/sizeof(q))+1);
-        vcell = (struct generator_susp*)(((q*)svar)+1);
-        vcell->backpt = (q)svar;
-        derefone(svar) = (q)vcell;
-        gvar = (Shvar*)untag_generator_susp(addi);
-        if ( !gvar->chain ) {
-           vcell->u.o = tag_generator_susp(pSHM_VAR);
-        } else if ( within_new_space(gvar) ) {
-           vcell->u.o = tag_generator_susp(gvar);
-        } else {
-           Sinfo* dptr;
-           Sinfo* sptr;
-           Shvar* svar = (Shvar*)galloc((sizeof(Shvar)/sizeof(q)));
-           vcell->u.o = tag_generator_susp(svar);
-           svar->method = SHM_VAR;
-           dptr = (Sinfo*)&(svar->chain);
-           sptr = gvar->chain;
-           if ( !is_genhook(sptr) ) {
-             while(sptr && !within_new_space(sptr)) {
-               dptr->next = (Sinfo*)galloc((sizeof(Sinfo)/sizeof(q)));
-               dptr = dptr->next;
-               dptr->PE_num = sptr->PE_num;
-               dptr->prio = sptr->prio;
-               dptr->indp = sptr->indp;
-               sptr = sptr->next;
-             }
-             dptr->next = sptr;
-           } else {
-             if ( !within_new_space(sptr) ) {
-               Sinfo* addr = (Sinfo*)galloc((sizeof(Sinfo)/sizeof(q)));
-               sptr = untag_genhook(sptr);
-               dptr->next = tag_genhook(addr);
-               dptr = addr;
-               dptr->next = 0;
-               dptr->PE_num = sptr->PE_num;
-               dptr->prio = sptr->prio;
-               dptr->indp = sptr->indp;
-             } else {
-               dptr->next = sptr;
-             }
-           }
-         }
+        svar = (q) galloc((sizeof(struct generator_susp)/sizeof(q))+1);
+        vcell = (struct generator_susp*) (((q*)svar) + 1);
+        vcell->backpt = (q) svar;
+        derefone(svar) = (q) vcell;
+        gvar = (Shvar*) untag_generator_susp(addi);
+        if( !gvar->chain ){
+	  vcell->u.o = tag_generator_susp(pSHM_VAR);
+        }else if( within_new_space(gvar) ){
+	  vcell->u.o = tag_generator_susp(gvar);
+        }else{
+	  Sinfo* dptr;
+	  Sinfo* sptr;
+	  Shvar* svar = (Shvar*) galloc((sizeof(Shvar)/sizeof(q)));
+	  vcell->u.o = tag_generator_susp(svar);
+	  svar->method = SHM_VAR;
+	  dptr = (Sinfo*) &(svar->chain);
+	  sptr = gvar->chain;
+	  if( !is_genhook(sptr) ){
+	    while( sptr != NULL && !within_new_space(sptr) ){
+	      dptr->next = (Sinfo*) galloc((sizeof(Sinfo)/sizeof(q)));
+	      dptr = dptr->next;
+	      dptr->PE_num = sptr->PE_num;
+	      dptr->prio = sptr->prio;
+	      dptr->indp = sptr->indp;
+	      sptr = sptr->next;
+	    }
+	    dptr->next = sptr;
+	  }else{
+	    if( !within_new_space(sptr) ){
+	      Sinfo* addr = (Sinfo*) galloc((sizeof(Sinfo)/sizeof(q)));
+	      sptr = untag_genhook(sptr);
+	      dptr->next = tag_genhook(addr);
+	      dptr = addr;
+	      dptr->next = 0;
+	      dptr->PE_num = sptr->PE_num;
+	      dptr->prio = sptr->prio;
+	      dptr->indp = sptr->indp;
+	    }else{
+	      dptr->next = sptr;
+	    }
+	  }
+	}
 	a_barrier();
 	derefone(obj) = makeref(svar);
 	*objp = makeref(svar);
 	continue;
-      } else { /* obj is an invisible pointer */	  
+      }else{  /* obj is an invisible pointer */	  
 	*objp = obj = temp;
 	goto TRO_LOOP;
       }
     }
     case FUNCTOR: {
-      int i,arity;
+      int i, arity;
       q f;
       struct functor *old, *new;
       old = functorp(obj);
 					/* in new space ? */
-      if ( within_new_space(old) ) continue;
+      if( within_new_space(old) ) continue;
       f = functor_of(obj);
-      if ( isref(f) ) {
+      if( isref(f) ){
 	/*--- GENERIC OBJECT (data object) ---*/
-	struct data_object *dobj = (struct data_object *)old;
+	struct data_object* dobj = (struct data_object*) old;
 	obj = generic_shmcopy(dobj);
 	a_barrier();
 	*objp = obj;
@@ -527,8 +527,8 @@
 					/* already copied ? */
 #ifdef ISFWD
       /* arity > 0 is assumed */
-      if ( isref(old->args[0]) && within_new_space(refp(old->args[0])) ) {
-	new = (struct functor*)(refp(old->args[0])-FIRSTELTOFFSET);
+      if( isref(old->args[0]) && within_new_space(refp(old->args[0])) ){
+	new = (struct functor*) (refp(old->args[0]) - FIRSTELTOFFSET);
 	*objp = makefunctor(new);
 	continue;
       }
@@ -536,24 +536,24 @@
 #endif
 #ifdef IAFWD
       arity = arityof(f);
-      if ( isref(old->args[0]) && within_new_space(refp(old->args[0])) ) {
-	q* neweltp = refp(old->args[0])+1;
+      if( isref(old->args[0]) && within_new_space(refp(old->args[0])) ){
+	q* neweltp = refp(old->args[0]) + 1;
 	int copied = 1;
-	for (i=1; i<arity; i++,neweltp++) {
-	  if ( old->args[i] != makeref(neweltp) ) {
+	for( i=1; i<arity; i++, neweltp++ ){
+	  if( old->args[i] != makeref(neweltp) ){
 	    copied = 0;
-	    break; /* exit for statement */
+	    break;  /* exit for statement */
 	  }
 	  /* N.B. If arity is extremely large, neweltp might overflow.	*/
 	  /*   But in that case, makeref(neweltp) becomes makeref(0),	*/
 	  /*   which cannot be equal to old->args[i].			*/
 	}
-	if ( copied ) {
-	  new = (struct functor*)(refp(old->args[0])-FIRSTELTOFFSET);
+	if( copied ){
+	  new = (struct functor*) (refp(old->args[0]) - FIRSTELTOFFSET);
 	  *objp = makefunctor(new);
 	  continue;
 	}
-      } /* end if */
+      }  /* end if */
 #endif
 #if defined(SYNC_GC) && defined(PAR_GC)
       {
@@ -561,28 +561,28 @@
 	volatile q* fpp = &(old->args[0]);
 	int offset = FIRSTELTOFFSET;
 	atomic_swap(fpp,x);
-	if ( x == COPYING_MARK ) {
+	if( x == COPYING_MARK ){
 	  /* being copied by somebody else */
-	  while ( x == COPYING_MARK ) x = *fpp;
+	  while( x == COPYING_MARK ) x = *fpp;
 	  ASSERT( isref(x) && within_new_space(refp(x)), "bad fwd");
-	  *objp = makefunctor(refp(x)-offset);
+	  *objp = makefunctor(refp(x) - offset);
 	  continue;
 	}
 					/* allocation */
-	new = (struct functor*)galloc(qsizeof_functor(arity));
+	new = (struct functor*) galloc(qsizeof_functor(arity));
 					/* initialization */
 	new->functor = f;
 	new->args[0] = x;		/* initialization of fwdptr position */
-	for(i=1; i<arity; i++) {
+	for( i=1; i<arity; i++ ){
 	  new->args[i] = old->args[i];
 	}
       }
 #else
 					/* allocation */
-      new = (struct functor*)galloc(qsizeof_functor(arity));
+      new = (struct functor*) galloc(qsizeof_functor(arity));
 					/* initialization */
       new->functor = f;
-      for(i=0; i<arity; i++) {
+      for( i=0; i<arity; i++ ){
 	new->args[i] = old->args[i];
       }
 #endif
@@ -592,17 +592,16 @@
 					/* forwarding */
       old->args[0] = makeref(&(new->args[0]));
 #ifdef IAFWD
-      for(i=1; i<arity; i++) {
+      for( i=1; i<arity; i++ ){
 	old->args[i] = makeref(&(new->args[i]));
       }
 #endif
 					/* nested scavenging */
       p_barrier();
-      for (i=arity-1; i>0; i--) {
-	if ( ! isatomic(new->args[i]) ) {
+      for( i=arity-1; i>0; i-- ){
+	if( ! isatomic(new->args[i]) ){
 #ifdef ISFWD
 	  old->args[i] = makeref(&(new->args[i]));
-	
 #endif
 	  push_SCAVENGE(&(new->args[i]));
 	}
@@ -612,241 +611,250 @@
       goto TRO_LOOP;
     } /* case FUNCTOR */
     default: {
-      ASSERT(0,"Impossible case");
+      ASSERT(0, "Impossible case");
     }
     } /* switch statement */
   } /* while (sp > shm_gcstack) */
 }
 #endif /* TOPDOWN */
+
 #ifdef BOTTOMUP
-shm_copy_terms(sp,max)
-q** sp;
-q** max;
+static void
+shm_copy_terms(sp, max)
+  q** sp;
+  q** max;
 {
-   declare_globals;
-   q obj;
-   while(sp > shm_gcstack) {
-     q *objp = *--sp;
-      switch ( ptagof(objp) ) {
-      case ATOMIC: { /* in case of UPDATE */
-         q* conta = (q*)((long)(objp)-ATOMIC);
-         klic_barrier();
-         *conta = obj;
-         break;
-      }
-      case CONS:
-      case FUNCTOR: {
-         obj = (q)objp;
-         break;
-      }
-      default: {
-         obj = *objp;
-
-      ENTRY:
-         switch(ptagof(obj)) {
-         case CONS: {
-           struct cons* new;
-	   if ( !is_shma(obj) ) break; /* assume text-area */
-           if ( within_new_space(obj) ) break;
-           new = (struct cons*)galloc(2);
-           *objp = makecons(new);
-	   push_VALUE(makecons(new));
-           if ( !isatomic( new->cdr = cdr_of(obj) ) ) {
-	     push_UPDATE(&cdr_of(obj));
-	     push_SCAVENGE(&new->cdr);
-	   }
-	   if ( isatomic( new->car = car_of(obj) ) ) break;
-           push_UPDATE(&car_of(obj));
-           objp = &new->car;
-           obj = *objp;
-           goto ENTRY;
-         }
-         case ATOMIC: { break; }
-         case VARREF: {
-           q temp;
-           if ( within_new_space(obj) ) { break; }
-           temp = derefone(obj);
-           if ( isref(temp) && obj == derefone(temp) ) {
-             q svar;
-             struct generator_susp* vcell;
-             struct generator_object* addi;
-             Shvar* gvar;
-             addi = n_lock(obj,temp);
-             if ( derefone(obj) != temp ) {
-               obj = derefone(obj);
-               *objp = obj; goto ENTRY;
-             }
-             svar = (q)galloc((sizeof(struct generator_susp)/sizeof(q))+1);
-             vcell = (struct generator_susp*)(((q*)svar)+1);
-             vcell->backpt = (q)svar;
-             derefone(svar) = (q)vcell;
-             gvar = (Shvar*)untag_generator_susp(addi);
-             if ( !gvar->chain ) {
-               vcell->u.o = tag_generator_susp(pSHM_VAR);
-             } else if ( within_new_space(gvar) ) {
-               vcell->u.o = tag_generator_susp(gvar);
-             } else {
-               Sinfo* dptr;
-               Sinfo* sptr;
-               Shvar* svar = (Shvar*)galloc((sizeof(Shvar)/sizeof(q)));
-               vcell->u.o = tag_generator_susp(svar);
-               svar->method = SHM_VAR;
-               dptr = (Sinfo*)&(svar->chain);
-               sptr = gvar->chain;
-               if ( !is_genhook(sptr) ) {
-                 while(sptr && !within_new_space(sptr)) {
-                   dptr->next = (Sinfo*)galloc((sizeof(Sinfo)/sizeof(q)));
-                   dptr = dptr->next;
-                   dptr->PE_num = sptr->PE_num;
-                   dptr->prio = sptr->prio;
-                   dptr->indp = sptr->indp;
-                   sptr = sptr->next;
-                 }
-                 dptr->next = sptr;
-               } else {
-                 if ( !within_new_space(sptr) ) {
-                   Sinfo* addr = (Sinfo*)galloc((sizeof(Sinfo)/sizeof(q)));
-                   sptr = untag_genhook(sptr);
-                   dptr->next = tag_genhook(addr);
-                   dptr = addr;
-                   dptr->next = 0;
-                   dptr->PE_num = sptr->PE_num;
-                   dptr->prio = sptr->prio;
-                   dptr->indp = sptr->indp;
-                 } else {
-                   dptr->next = sptr;
-                 }
-               }
-             }
-             klic_barrier();
-             derefone(obj) = (q)svar;
-             *objp = obj = (q)svar;
-             break;
-           }
-
-           { /* in case of an invisible pointer */
-              *objp = obj = temp;
-              goto ENTRY;
-           }
-         }
-         default: { /* functor */
-           int i,arity,aritym1;
-           struct functor* new;
-           q f;
-	   if ( !is_shma(obj) ) break; /* assume text-area */
-           if ( within_new_space(obj) ) break;
-           f = functor_of(obj);
-           if ( isref(f) ) {
-              struct data_object *dobj
-               = (struct data_object *)functorp(obj);
-              obj = generic_shmcopy(dobj);
-              klic_barrier();
-              *objp = obj;
-              break;
-           }
-           arity = arityof(f);
-           aritym1 = arity-1;
-           new = (struct functor*)galloc(arity+1);
-           new->functor = f;
-           *objp = makefunctor(new);
-           push_VALUE(makefunctor(new));
-           for(i=0;i<aritym1;i++) {
-             if ( !isatomic( new->args[i] = arg(obj,i) ) ) {
-	       push_UPDATE(&arg(obj,i));
-	       push_SCAVENGE(&(new->args[i]));
-	     }
-           }
-	   if ( !isatomic( new->args[aritym1] = arg(obj,aritym1) ) ) {
-	     push_UPDATE(&arg(obj,aritym1));
-	     objp = &(new->args[aritym1]);
-	     obj = *objp;
-	     goto ENTRY;
-	   }
-         }
-         }/* switch(ptogof(obj)) */
+  declare_globals;
+  q obj;
+  while( sp > shm_gcstack ){
+    sp--;
+    q* objp = *sp;
+    switch( ptagof(objp) ){
+    case ATOMIC: {  /* in case of UPDATE */
+      q* conta = (q*) ((long)objp - ATOMIC);
+      klic_barrier();
+      *conta = obj;
+      break;
+    }
+    case CONS:
+    case FUNCTOR: {
+      obj = (q) objp;
+      break;
+    }
+    default: {
+      obj = *objp;
+
+    ENTRY:
+      switch( ptagof(obj) ){
+      case CONS: {
+	struct cons* new;
+	if( !is_shma(obj) ) break;  /* assume text-area */
+	if( within_new_space(obj) ) break;
+	new = (struct cons*) galloc(2);
+	*objp = makecons(new);
+	push_VALUE(makecons(new));
+	new->cdr = cdr_of(obj);
+	if( !isatomic(new->cdr) ){
+	  push_UPDATE(&cdr_of(obj));
+	  push_SCAVENGE(&new->cdr);
+	}
+	new->car = car_of(obj);
+	if( isatomic(new->car) ) break;
+	push_UPDATE(&car_of(obj));
+	objp = &new->car;
+	obj = *objp;
+	goto ENTRY;
       }
-      }/* switch(ptagof(objp)) */
-   }/* while( sp...) */
+      case ATOMIC: { break; }
+      case VARREF: {
+	q temp;
+	if( within_new_space(obj) ){ break; }
+	temp = derefone(obj);
+	if( isref(temp) && obj == derefone(temp) ){
+	  q svar;
+	  struct generator_susp* vcell;
+	  struct generator_object* addi;
+	  Shvar* gvar;
+	  addi = n_lock(obj,temp);
+	  if( derefone(obj) != temp ){
+	    obj = derefone(obj);
+	    *objp = obj;
+	    goto ENTRY;
+	  }
+	  svar = (q) galloc((sizeof(struct generator_susp)/sizeof(q))+1);
+	  vcell = (struct generator_susp*) (((q*)svar) + 1);
+	  vcell->backpt = (q) svar;
+	  derefone(svar) = (q) vcell;
+	  gvar = (Shvar*) untag_generator_susp(addi);
+	  if( !gvar->chain ){
+	    vcell->u.o = tag_generator_susp(pSHM_VAR);
+	  }else if( within_new_space(gvar) ){
+	    vcell->u.o = tag_generator_susp(gvar);
+	  }else{
+	    Sinfo* dptr;
+	    Sinfo* sptr;
+	    Shvar* svar = (Shvar*) galloc((sizeof(Shvar)/sizeof(q)));
+	    vcell->u.o = tag_generator_susp(svar);
+	    svar->method = SHM_VAR;
+	    dptr = (Sinfo*) &(svar->chain);
+	    sptr = gvar->chain;
+	    if( !is_genhook(sptr) ){
+	      while( sptr != NULL && !within_new_space(sptr)){
+		dptr->next = (Sinfo*) galloc((sizeof(Sinfo)/sizeof(q)));
+		dptr = dptr->next;
+		dptr->PE_num = sptr->PE_num;
+		dptr->prio = sptr->prio;
+		dptr->indp = sptr->indp;
+		sptr = sptr->next;
+	      }
+	      dptr->next = sptr;
+	    }else{
+	      if( !within_new_space(sptr) ){
+		Sinfo* addr = (Sinfo*) galloc((sizeof(Sinfo)/sizeof(q)));
+		sptr = untag_genhook(sptr);
+		dptr->next = tag_genhook(addr);
+		dptr = addr;
+		dptr->next = NULL;
+		dptr->PE_num = sptr->PE_num;
+		dptr->prio = sptr->prio;
+		dptr->indp = sptr->indp;
+	      }else{
+		dptr->next = sptr;
+	      }
+	    }
+	  }
+	  klic_barrier();
+	  derefone(obj) = (q) svar;
+	  *objp = obj = (q) svar;
+	  break;
+	}
+
+        {  /* in case of an invisible pointer */
+	  *objp = obj = temp;
+	  goto ENTRY;
+	}
+      }
+      default: {  /* functor */
+	int i, arity, aritym1;
+	struct functor* new;
+	q f;
+	if( !is_shma(obj) ) break;  /* assume text-area */
+	if( within_new_space(obj) ) break;
+	f = functor_of(obj);
+	if( isref(f) ){
+	  struct data_object* dobj = (struct data_object*) functorp(obj);
+	  obj = generic_shmcopy(dobj);
+	  klic_barrier();
+	  *objp = obj;
+	  break;
+	}
+	arity = arityof(f);
+	aritym1 = arity-1;
+	new = (struct functor*) galloc(arity+1);
+	new->functor = f;
+	*objp = makefunctor(new);
+	push_VALUE(makefunctor(new));
+	for( i=0; i<aritym1; i++ ){
+	  new->args[i] = arg(obj, i);
+	  if( !isatomic(new->args[i]) ){
+	    push_UPDATE(&arg(obj,i));
+	    push_SCAVENGE(&(new->args[i]));
+	  }
+	}
+	new->args[aritym1] = arg(obj, aritym1);
+	if( !isatomic(new->args[aritym1]) ){
+	  push_UPDATE(&arg(obj, aritym1));
+	  objp = &(new->args[aritym1]);
+	  obj = *objp;
+	  goto ENTRY;
+	}
+      }
+      }  /* switch(ptogof(obj)) */
+    }
+    }  /* switch(ptagof(objp)) */
+  }  /* while( sp...) */
 }
 #endif /* BOTTOMUP */
 
 
+static void
 get_new_plane()
 {
-   declare_globals;
-   int i,id,j;
-   s_lock(m_key());
-   if ( PLNE_ptr[currid]->direct == -1 ) {
-      id = (currid+1) % N_PLNE;
-      for(j=0;j<total_node;j++) {
-	if (PLNE_ptr[id]->proc[j]) {
-	  abend("Shared Memory overflow !!!");
-        }
+  declare_globals;
+  int i, id, j;
+  s_lock(m_key());
+  if( PLNE_ptr[currid]->direct == -1 ){
+    id = (currid + 1) % N_PLNE;
+    for( j=0; j<total_node; j++ ){
+      if( PLNE_ptr[id]->proc[j] ){
+	abend("Shared Memory overflow !!!");
       }
+    }
 
-      /* initialize table */
-      PLNE_ptr[id]->caddr = PLNE_ptr[id]->top_addr;
-      PLNE_ptr[id]->demand = 0;
-      PLNE_ptr[id]->direct = -1;
-      klic_barrier();
-      PLNE_ptr[currid]->direct = id;
-   } else {
-     id = PLNE_ptr[currid]->direct;
-   }
-   s_unlock(m_key());
-
-   currid = id;
-   PLNE_ptr[currid]->proc[my_node] = 1;
-   gallocp = glimit = (q*)1;
+    /* initialize table */
+    PLNE_ptr[id]->caddr = PLNE_ptr[id]->top_addr;
+    PLNE_ptr[id]->demand = 0;
+    PLNE_ptr[id]->direct = -1;
+    klic_barrier();
+    PLNE_ptr[currid]->direct = id;
+  }else{
+    id = PLNE_ptr[currid]->direct;
+  }
+  s_unlock(m_key());
+
+  currid = id;
+  PLNE_ptr[currid]->proc[my_node] = 1;
+  gallocp = glimit = (q*) 1;
 }
 
+static void
 enter_shm_gc()
 {
   declare_globals;
 #ifdef ASYNC_GC
-   if ( currid == oldid) {
-     PLNE_ptr[currid]->proc[my_node] = 3;
-     if ( PLNE_ptr[currid]->direct == -1 ) {
-       get_new_plane();
-     } else {
-       currid = PLNE_ptr[currid]->direct;
-       PLNE_ptr[currid]->proc[my_node] = 2;
-       gallocp = glimit = (q*)1;
-     }
-   } else {
-     PLNE_ptr[oldid]->proc[my_node] = 10;
-   }
-   {
-     int j,next;
-     next = (currid+1) % N_PLNE;
-     for(j=0;j<total_node;j++) {
-       if ( PLNE_ptr[next]->proc[j] ) {
-	 struct global_variables* tglbl = top_shm_glbl+j;
-	 tglbl->interrupt_off0 = 0;
-	 klic_barrier();
-	 tglbl->heaplimit0 = 0;
-       }
-       {
-	 int waitC=1000000;
-	 while (1) {
-           if ( !(PLNE_ptr[next]->proc[j]) ) break;
-	   if ( !(waitC--) ) abend("Shared-memory overflow!!!");
-	 }
-       }
-     }
-     oldid = currid;
-   }
-#endif
+  if( currid == oldid ){
+    PLNE_ptr[currid]->proc[my_node] = 3;
+    if( PLNE_ptr[currid]->direct == -1 ){
+      get_new_plane();
+    }else{
+      currid = PLNE_ptr[currid]->direct;
+      PLNE_ptr[currid]->proc[my_node] = 2;
+      gallocp = glimit = (q*) 1;
+    }
+  }else{
+    PLNE_ptr[oldid]->proc[my_node] = 10;
+  }
+  {
+    int j, next;
+    next = (currid + 1) % N_PLNE;
+    for( j=0; j<total_node; j++ ){
+      if( PLNE_ptr[next]->proc[j] ){
+	struct global_variables* tglbl = top_shm_glbl + j;
+	tglbl->interrupt_off0 = 0;
+	klic_barrier();
+	tglbl->heaplimit0 = 0;
+      }
+      {
+	int waitC = 1000000;
+	for(;;){
+	  if( !(PLNE_ptr[next]->proc[j]) ) break;
+	  if( !(waitC--) ) abend("Shared-memory overflow!!!");
+	}
+      }
+    }
+    oldid = currid;
+  }
+#endif  /* ASYNCGC */
 #ifdef SYNC_GC
   {
-    int i,j;
-    if ( !PLNE_ptr[currid]->demand ) {
+    int i, j;
+    if( !PLNE_ptr[currid]->demand ){
       s_lock(m_key());
-      if ( !PLNE_ptr[currid]->demand ) {
+      if( !PLNE_ptr[currid]->demand ){
 	PLNE_ptr[currid]->demand = 1;
-	for(j=0;j<total_node;j++) {
-	  if ( PLNE_ptr[currid]->proc[j] ) {
-	    struct global_variables* tglbl = top_shm_glbl+j;
+	for( j=0; j<total_node; j++ ){
+	  if( PLNE_ptr[currid]->proc[j] ){
+	    struct global_variables* tglbl = top_shm_glbl + j;
 	    tglbl->interrupt_off0 = 0;
 	    klic_barrier();
 	    tglbl->heaplimit0 = 0;
@@ -858,17 +866,19 @@
       s_unlock(m_key());
     }
     PLNE_ptr[currid]->proc[my_node] = 0;
-    for(i=0;i<total_node;i++) while( PLNE_ptr[currid]->proc[i] ) {}
+    for( i=0; i<total_node; i++)
+      while( PLNE_ptr[currid]->proc[i] )
+	{}
     currid = 1 - currid;
-    gallocp = glimit = (q*)1;
-    
+    gallocp = glimit = (q*) 1;
   }
-#endif
+#endif  /* SYNC_GC */
 #ifdef SEQ_GC
   s_lock(gc_key());
 #endif
 }
 
+static void
 exit_shm_gc()
 {
   declare_globals;
@@ -879,18 +889,19 @@
   {
     int i;
     PLNE_ptr[currid]->proc[my_node] = 1;
-    for(i=0;i<total_node;i++) while( !PLNE_ptr[currid]->proc[i] ) {}
+    for( i=0; i<total_node; i++)
+      while( !PLNE_ptr[currid]->proc[i] )
+	{}
   }
 #endif
 #ifdef ASYNC_GC
   {
     int i;
-    for(i=0;i<N_PLNE;i++) {
-      if ( i != currid && i != oldid )  PLNE_ptr[i]->proc[my_node] = 0;
+    for( i=0; i<N_PLNE; i++ ){
+      if( i != currid && i != oldid )  PLNE_ptr[i]->proc[my_node] = 0;
     }
-    PLNE_ptr[currid]->proc[my_node] = (-1);
+    PLNE_ptr[currid]->proc[my_node] = -1;
   }
 #endif
   F_shm_gc = 0;
 }
-
diff -ruN klic-3.003-2002-01-02/runtime/shm_machine.h klic-3.003-2002-01-03/runtime/shm_machine.h
--- klic-3.003-2002-01-02/runtime/shm_machine.h	Fri Dec 28 13:46:47 2001
+++ klic-3.003-2002-01-03/runtime/shm_machine.h	Wed Jan  2 12:42:53 2002
@@ -9,6 +9,8 @@
 #define _KLIC_SHM_MACHINE_H_
 
   /* lock-unlock */
+
+
 #ifdef SPARC
 
 #define n_lock(shvp,sadp) ( { \
@@ -38,7 +40,7 @@
         mov %%g5,%%g2;        \
 4:                            \
 " : "=g" (befp), "=g" (s1) : "g" (s1), "g" (s2), "g" (genp)  );    \
-  (shvp) = (q)s1;               \
+  (shvp) = (q) s1;               \
   befp;                       \
   } )
 
@@ -84,7 +86,8 @@
 
 #define klic_barrier()  do{ asm volatile ( "stbar;" : : ); }while(0)
 
-#endif
+#endif  /* SPARC */
+
 
 #ifdef ALPHA
 
@@ -112,7 +115,7 @@
 3:                            \
         mb;                   \
 " : "=g" (befp), "=g" (s1) : "g" (s1), "g" (s2), "g" (genp) : "$1" );    \
-  (shvp) = (q)s1;               \
+  (shvp) = (q) s1;               \
   befp;                       \
   } )
 
@@ -154,10 +157,10 @@
 " :  : "g" (val) ) ;        \
 }while(0)
 
-
 #define klic_barrier()  do{ asm volatile ( "mb;" : : ); }while(0)
 
-#endif
+#endif  /* ALPHA */
+
 
 #ifdef INTEL
 #define n_lock(shvp, sadp) ({ \
@@ -183,7 +186,7 @@
         movl  %%eax,%%ebx;      \
 4:                              \
 " : "=g" (befp), "=g" (s1) : "g" (s1), "g" (s2), "g" (genp)  );    \
-  (shvp) = (q)s1;               \
+  (shvp) = (q) s1;               \
   befp;                       \
   } )
 
@@ -224,6 +227,7 @@
 
 #define klic_barrier()  do{;}while(0)
 
-#endif
+#endif  /* INTEL */
+
 
 #endif /* _KLIC_SHM_MACHINE_H_ */
diff -ruN klic-3.003-2002-01-02/runtime/shm_obj.c klic-3.003-2002-01-03/runtime/shm_obj.c
--- klic-3.003-2002-01-02/runtime/shm_obj.c	Sat Dec 29 12:46:20 2001
+++ klic-3.003-2002-01-03/runtime/shm_obj.c	Wed Jan  2 14:18:35 2002
@@ -16,6 +16,11 @@
 #include <klic/gg_macro.h>
 #include "shm.h"
 
+extern void* calloc();
+
+#define is_cur_space_ptr(X) \
+  ((unsigned long) ((long)(X) - (long)(PLNE_ptr[currid]->top_addr)) < SHM_SIZE)
+
 /* unbound variable in shared memory (representating by a generic object)
         +-------------------+
         V                   |
@@ -35,35 +40,36 @@
   &GG_method_table0(shvar);
 struct generator_object_method_table* SHM_BUSY =
   &GG_method_table0(shbusy);
-Shvar xSHM_VAR = {&GG_method_table0(shvar),0};
-struct generator_object* pSHM_VAR = (struct generator_object*)&xSHM_VAR;
-Shvar xSHM_BUSY = {&GG_method_table0(shbusy),0};
+Shvar xSHM_VAR = {&GG_method_table0(shvar), 0};
+struct generator_object* pSHM_VAR = (struct generator_object*) &xSHM_VAR;
+Shvar xSHM_BUSY = {&GG_method_table0(shbusy), 0};
 struct generator_object* qSHM_BUSY = tag_generator_susp(&xSHM_BUSY);
 
 
 /* address drive table */
 #define ADDRBULK 2048
 TADDRtbl ADDRtbl = { &ADDRtbl, &ADDRtbl, 0, 0 };
-TADDRtbl *ADDRtbl_free = 0;
+TADDRtbl* ADDRtbl_free = NULL;
 
-#define new_addr_rec(lrec)			\
-{						\
-  TADDRtbl *temp;				\
-  while ((temp = ADDRtbl_free) == 0) {		\
-    ADDRtbl_free = more_addr_rec();		\
-  }						\
-  ADDRtbl_free = temp->next;			\
-  (lrec) = temp;				\
+#define new_addr_rec(lrec) \
+{ \
+  TADDRtbl* temp; \
+  temp = ADDRtbl_free; \
+  while( temp == NULL ){ \
+    ADDRtbl_free = more_addr_rec(); \
+  } \
+  ADDRtbl_free = temp->next; \
+  (lrec) = temp; \
 }
 
 /* Resume a goal with the same priority as current */
 
 #define resume_same_prio(gp) {        \
   declare_globals;                    \
-  if (resumed_goals == 0) {           \
+  if( resumed_goals == 0 ){           \
     resumed_goals = gp;               \
     gp->next = gp;                    \
-  } else {                            \
+  }else{                            \
     gp->next = resumed_goals->next;   \
     resumed_goals->next = gp;         \
   }                                   \
@@ -71,19 +77,22 @@
 }
 
 
-module shm_resume();
-const struct predicate shm_xresume_1 = { shm_resume, 0, 1 };
-module shm_request();
-const struct predicate shm_xrequest_1 = { shm_request, 0, 1 };
+static module shm_resume(struct global_variables* glbl,
+  struct goalrec* qp, q* allocp, const struct predicate* toppred);
+
+static module shm_request(struct global_variables* glbl,
+  struct goalrec* qp, q* allocp, const struct predicate* toppred);
 
+static const struct predicate shm_xresume_1 = { shm_resume, 0, 1 };
+static const struct predicate shm_xrequest_1 = { shm_request, 0, 1 };
 
-TADDRtbl *more_addr_rec()
+
+static TADDRtbl*
+more_addr_rec()
 {
   int k;
-  extern void *calloc();
-  TADDRtbl *bulk = (TADDRtbl*)
-      calloc(ADDRBULK, sizeof(TADDRtbl));
-  for (k = ADDRBULK-1; k > 0; k--) {
+  TADDRtbl* bulk = (TADDRtbl*) calloc(ADDRBULK, sizeof(TADDRtbl));
+  for( k = ADDRBULK-1; k > 0; k-- ){
     bulk[k-1].next = &bulk[k];
   }
   bulk[ADDRBULK-1].next = 0;
@@ -92,327 +101,336 @@
 
 /* d_shm_init
   initializes free chain of external trigger */
+extern void
 d_shm_init()
 {
-     TADDRtbl* bptr;
-     new_addr_rec(bptr);
+  TADDRtbl* bptr;
+  new_addr_rec(bptr);
 }
 
 
-
-Sinfo* shm_copy_chain(xp)
-Sinfo* xp;
+extern Sinfo*
+shm_copy_chain(xp)
+  Sinfo* xp;
 {
-    declare_globals;
-    Sinfo* ret;
-    Sinfo** retp = &ret;
-    while ( xp && !is_cur_or_forward_ptr(xp) ) {
-      Sinfo* sp = (Sinfo*)galloc(sizeof(Sinfo)/sizeof(q));
-      *sp = *xp;
-      *retp = sp;
-      retp = (Sinfo**)sp;
-      xp = xp->next;
-    }
-    *retp = xp;
-    return(ret);
+  declare_globals;
+  Sinfo* ret;
+  Sinfo** retp = &ret;
+  while( xp != NULL && !is_cur_or_forward_ptr(xp) ){
+    Sinfo* sp = (Sinfo*) galloc(sizeof(Sinfo)/sizeof(q));
+    *sp = *xp;
+    *retp = sp;
+    retp = (Sinfo**) sp;
+    xp = xp->next;
+  }
+  *retp = xp;
+  return ret;
 }
 
 
-Sinfo* shm_merge_chain(xp,yp)
-Sinfo* xp;
-Sinfo* yp;
-{
-    declare_globals;
-    Sinfo* ret;
-    Sinfo** retp = &ret;
-    while ( xp ) {
-      if ( !is_cur_or_forward_ptr(xp) ) { /* xp is old */
-        Sinfo* sp = (Sinfo*)galloc(sizeof(Sinfo)/sizeof(q));
-        *sp = *xp;
-        *retp = sp;
-        retp = (Sinfo**)sp;
-      } else if ( !is_cur_space_ptr(xp) ) {      /* xp is new */
-        while (yp) {
-          if ( !is_cur_or_forward_ptr(yp) ) { /* yp is old */
-            Sinfo* sp = (Sinfo*)galloc(sizeof(Sinfo)/sizeof(q));
-            *sp = *yp;
-            *retp = sp;
-            retp = (Sinfo**)sp;
-          } else if ( !is_cur_space_ptr(yp) ) { /* yp is new */
-            while (yp) {
-	      *retp = yp;
-              retp = (Sinfo**)yp;
-              yp = yp->next;
-            }
-            *retp = xp;
-	    return(ret);
-          } else {          /* yp is cur */
-            *retp = yp;
-            retp = (Sinfo**)yp;
-          }
-          yp = yp->next;
-        }
-        *retp = yp;
-      } else {                             /* xp is cur */
-	*retp = xp;
-	retp = (Sinfo**)xp;
+extern Sinfo*
+shm_merge_chain(xp, yp)
+  Sinfo* xp;
+  Sinfo* yp;
+{
+  declare_globals;
+  Sinfo* ret;
+  Sinfo** retp = &ret;
+  while( xp != NULL ){
+    if( !is_cur_or_forward_ptr(xp) ){  /* xp is old */
+      Sinfo* sp = (Sinfo*) galloc(sizeof(Sinfo)/sizeof(q));
+      *sp = *xp;
+      *retp = sp;
+      retp = (Sinfo**) sp;
+    }else if( !is_cur_space_ptr(xp) ){  /* xp is new */
+      while( yp != NULL ){
+	if( !is_cur_or_forward_ptr(yp) ){  /* yp is old */
+	  Sinfo* sp = (Sinfo*) galloc(sizeof(Sinfo)/sizeof(q));
+	  *sp = *yp;
+	  *retp = sp;
+	  retp = (Sinfo**) sp;
+	}else if( !is_cur_space_ptr(yp) ){  /* yp is new */
+	  while( yp != NULL ){
+	    *retp = yp;
+	    retp = (Sinfo**) yp;
+	    yp = yp->next;
+	  }
+	  *retp = xp;
+	  return ret;
+	}else{        /* yp is cur */
+	  *retp = yp;
+	  retp = (Sinfo**) yp;
+	}
+	yp = yp->next;
       }
-      xp = xp->next;
-    }
-    /* xp is no more new space */
-    while (yp) {
-      if ( !is_cur_or_forward_ptr(yp) ) { /* yp is old */
-	Sinfo* sp = (Sinfo*)galloc(sizeof(Sinfo)/sizeof(q));
-	*sp = *yp;
-	*retp = sp;
-	retp = (Sinfo**)sp;
-      } else break;
-      yp = yp->next;
+      *retp = yp;
+    }else{                  /* xp is cur */
+      *retp = xp;
+      retp = (Sinfo**) xp;
     }
-    *retp = yp;
-    return(ret);
+    xp = xp->next;
+  }
+  /* xp is no more new space */
+  while( yp != NULL ){
+    if( !is_cur_or_forward_ptr(yp) ){  /* yp is old */
+      Sinfo* sp = (Sinfo*) galloc(sizeof(Sinfo)/sizeof(q));
+      *sp = *yp;
+      *retp = sp;
+      retp = (Sinfo**) sp;
+    } else break;
+    yp = yp->next;
+  }
+  *retp = yp;
+  return ret;
 }
 
 
 /* shm_add_consumer(shrec,consumer_ref)
   adds a shared memory variable
 */
-Shvar* shm_add_consumer(shv,shobj,cvar,glbl)
-q shv;
-Shvar* shobj;
-q cvar;
-struct global_variables* glbl;
-{
-	q mid;
-	Sinfo* sptr;
-	ck_new_galloc(shv);
-	if ( shobj && shobj->chain ) {
-	  Sinfo* shrec = shobj->chain;
-	  Sinfo* bp = (Sinfo*)&(shobj->chain);
-	  ck_new_galloc(shrec);
-	  while ( !is_cur_or_forward_ptr(shrec) ) {
-	    sptr = (Sinfo*)galloc(sizeof(Sinfo)/sizeof(q));
-	    *sptr = *shrec;
-	    bp->next = sptr;
-	    bp = sptr;
-	    shrec = sptr->next;
-	  }
-	  sptr = (Sinfo*)galloc(sizeof(Sinfo)/sizeof(q));
-	  bp->next = sptr;
-	  sptr->next = shrec;
-	  sptr->PE_num = my_node;
-	  sptr->prio = current_prio;
-	  mid = derefone(cvar);
-	  derefone(cvar) = shv;
-	  derefone(mid) = 0;
-	  sptr->indp = create_local_tbl(tag_local(mid),shv);
-	  return(shobj);
-	} else {
-	  /* add first */
-	  Shvar *vr = (Shvar*)galloc((sizeof(Shvar)+sizeof(Sinfo))/sizeof(q));
-	  sptr = (Sinfo*)(vr+1);
-	  vr->method = SHM_VAR;
-	  vr->chain = sptr;
-	  sptr->next = 0;
-	  sptr->PE_num = my_node;
-	  sptr->prio = current_prio;
-	  mid = derefone(cvar);
-	  derefone(cvar) = shv;
-	  derefone(mid) = 0;
-	  sptr->indp = create_local_tbl(tag_local(mid),shv);
-	  return(vr);
-	}
+extern Shvar*
+shm_add_consumer(shv, shobj, cvar, glbl)
+  q shv;
+  Shvar* shobj;
+  q cvar;
+  struct global_variables* glbl;
+{
+  q mid;
+  Sinfo* sptr;
+  ck_new_galloc(shv);
+  if( shobj != NULL && shobj->chain != NULL ){
+    Sinfo* shrec = shobj->chain;
+    Sinfo* bp = (Sinfo*) &(shobj->chain);
+    ck_new_galloc(shrec);
+    while( !is_cur_or_forward_ptr(shrec) ){
+      sptr = (Sinfo*) galloc(sizeof(Sinfo)/sizeof(q));
+      *sptr = *shrec;
+      bp->next = sptr;
+      bp = sptr;
+      shrec = sptr->next;
+    }
+    sptr = (Sinfo*) galloc(sizeof(Sinfo)/sizeof(q));
+    bp->next = sptr;
+    sptr->next = shrec;
+    sptr->PE_num = my_node;
+    sptr->prio = current_prio;
+    mid = derefone(cvar);
+    derefone(cvar) = shv;
+    derefone(mid) = 0;
+    sptr->indp = create_local_tbl(tag_local(mid), shv);
+    return shobj;
+  }else{
+    /* add first */
+    Shvar* vr = (Shvar*) galloc((sizeof(Shvar)+sizeof(Sinfo))/sizeof(q));
+    sptr = (Sinfo*) (vr + 1);
+    vr->method = SHM_VAR;
+    vr->chain = sptr;
+    sptr->next = 0;
+    sptr->PE_num = my_node;
+    sptr->prio = current_prio;
+    mid = derefone(cvar);
+    derefone(cvar) = shv;
+    derefone(mid) = 0;
+    sptr->indp = create_local_tbl(tag_local(mid), shv);
+    return vr;
+  }
 }
 
 
-Shvar* create_genhook(la,ga)
-q* la;
-q* ga;
-{
-     declare_globals;
-     Shvar* varp;
-     Sinfo* sptr;
-     ck_new_galloc(ga);
-     varp = (Shvar*)galloc((sizeof(Shvar)+sizeof(Sinfo))/sizeof(q));
-     sptr = (Sinfo*)(varp+1);
-     varp->method = SHM_VAR;
-     varp->chain = tag_genhook(sptr);
-     sptr->PE_num = my_node;
-     sptr->next = 0;
-     sptr->prio = HIGHESTPRIO-1;
-     sptr->indp = create_local_tbl(la,ga);
-     return( varp );
+extern Shvar*
+create_genhook(la, ga)
+  q* la;
+  q* ga;
+{
+  declare_globals;
+  Shvar* varp;
+  Sinfo* sptr;
+  ck_new_galloc(ga);
+  varp = (Shvar*) galloc((sizeof(Shvar)+sizeof(Sinfo))/sizeof(q));
+  sptr = (Sinfo*) (varp + 1);
+  varp->method = SHM_VAR;
+  varp->chain = tag_genhook(sptr);
+  sptr->PE_num = my_node;
+  sptr->next = 0;
+  sptr->prio = HIGHESTPRIO - 1;
+  sptr->indp = create_local_tbl(la, ga);
+  return varp;
 }
 
-/* resume waiting process
+/* queueing other PE's resume routine
 */
-q* shm_resume_goals(allocp,hook)
-q* allocp;
-Sinfo *hook;
-{
-   declare_globals;
-
-   while(hook) {
-      if ( hook->PE_num == my_node ) {
-         TADDRtbl *sptr = hook->indp;
-         q term = (q)sptr->localA;
-	 q shm_term = (q)sptr->globalA;
-
-         free_local_tbl(sptr);
-
-         if ( isatomic(term) ) {
-           q wp = untag_local(term);
-           q top = (q)&sptr->localA;
-           derefone(top) = wp;
-           derefone(wp) = top;
-	   allocp = do_unify(allocp,top,shm_term);
-	 } else {
-	   struct goalrec* goal = (struct goalrec*)term;
-	   if ( goal && isatomic(goal->next) ) {
-	     long prio = intval(goal->next);
-	     if ( current_prio != prio ) {
-	       (void) enqueue_goal(NULL, prio, goal, glbl);
-	     } else {
-	       resume_same_prio(goal);
-	     }
-	     resumes++;
-	   }
-	 }
+static void resume_queueing(Pe_num, suspg, prio)
+  int Pe_num;
+  TADDRtbl* suspg;
+  long prio;
+{
+  struct ex_goalrec* tp;
+  struct goalrec* goal;
+
+  tp = (struct ex_goalrec*) galloc(5);
+  tp->prio = prio;
+  goal = &tp->goal;
+  goal->next = 0;
+  goal->pred = &shm_xresume_1;
+  goal->args[0] = (q) ((unsigned long)suspg + ATOMIC);
 
-      } else {
-         resume_queueing(hook->PE_num,hook->indp,hook->prio);
-      }
-      hook = hook->next;
-   }
-   return(allocp);
+  shm_goal_stack(tp, Pe_num);
 }
 
-/* queueing other PE's resume routine
+/* resume waiting process
 */
-resume_queueing(Pe_num,suspg,prio)
-int Pe_num;
-TADDRtbl *suspg;
-long prio;
+extern q*
+shm_resume_goals(allocp, hook)
+  q* allocp;
+  Sinfo* hook;
 {
-   struct ex_goalrec* tp;
-   struct goalrec *goal;
-
-   tp = (struct ex_goalrec*)galloc(5);
-   tp->prio = prio;
-   goal = &tp->goal;
-   goal->next = 0;
-   goal->pred = &shm_xresume_1;
-   goal->args[0] = (q)((unsigned long)suspg+ATOMIC);
+  declare_globals;
 
-   shm_goal_stack(tp,Pe_num);
+  while( hook != NULL ){
+    if( hook->PE_num == my_node ){
+      TADDRtbl* sptr = hook->indp;
+      q term = (q) sptr->localA;
+      q shm_term = (q) sptr->globalA;
+
+      free_local_tbl(sptr);
+
+      if( isatomic(term) ){
+	q wp = untag_local(term);
+	q top = (q) &sptr->localA;
+	derefone(top) = wp;
+	derefone(wp) = top;
+	allocp = do_unify(allocp, top, shm_term);
+      }else{
+	struct goalrec* goal = (struct goalrec*) term;
+	if( goal != NULL && isatomic(goal->next) ){
+	  long prio = intval(goal->next);
+	  if( current_prio != prio ){
+	    enqueue_goal(NULL, prio, goal, glbl);
+	  }else{
+	    resume_same_prio(goal);
+	  }
+	  resumes++;
+	}
+      }
+    }else{
+      resume_queueing(hook->PE_num, hook->indp, hook->prio);
+    }
+    hook = hook->next;
+  }
+  return allocp;
 }
 
 
-q* shm_ck_request(allocp,chain)
-q* allocp;
-Sinfo* chain;
+extern q*
+shm_ck_request(allocp, chain)
+  q* allocp;
+  Sinfo* chain;
 {
   declare_globals;
   Sinfo* sptr = untag_genhook(chain);
   int penum = sptr->PE_num;
   TADDRtbl* indp = sptr->indp;
-  if ( penum == my_node ) {
+  if( penum == my_node ){
     q temp;
     free_local_tbl(indp);
-    shm_arg_copy(&indp->localA,&temp);
-    allocp = do_unify(allocp,indp->globalA,temp);
-  } else {
-    shm_request_queueing(penum,current_prio,indp);
+    shm_arg_copy(&indp->localA, &temp);
+    allocp = do_unify(allocp, indp->globalA, temp);
+  }else{
+    shm_request_queueing(penum, current_prio, indp);
   }
-  return(allocp);
+  return allocp;
 }
-  
 
-shm_request_queueing(peno,prio,indp)
-int peno;
-long prio;
-TADDRtbl* indp;
+
+extern void
+shm_request_queueing(peno, prio, indp)
+  int peno;
+  long prio;
+  TADDRtbl* indp;
 {
-   struct ex_goalrec* tp;
-   struct goalrec *goal;
+  struct ex_goalrec* tp;
+  struct goalrec *goal;
 
-   tp = (struct ex_goalrec*)galloc(5);
-   tp->prio = prio;
-   goal = &tp->goal;
-   goal->next = 0;
-   goal->pred = &shm_xrequest_1;
-   goal->args[0] = (q)((unsigned long)(indp)+ATOMIC);
+  tp = (struct ex_goalrec*) galloc(5);
+  tp->prio = prio;
+  goal = &tp->goal;
+  goal->next = 0;
+  goal->pred = &shm_xrequest_1;
+  goal->args[0] = (q) ((unsigned long)indp + ATOMIC);
 
-   shm_goal_stack(tp,peno);
+  shm_goal_stack(tp, peno);
 }
 
 
-TADDRtbl* create_local_tbl(lcl,gbl)
-q* lcl;
-q* gbl;
+extern TADDRtbl*
+create_local_tbl(lcl, gbl)
+  q* lcl;
+  q* gbl;
 {
-    TADDRtbl* sl;
-    new_addr_rec(sl);
+  TADDRtbl* sl;
+  new_addr_rec(sl);
 
-    sl->next = ADDRtbl.next;
-    ADDRtbl.next = sl;
-    (sl->next)->prev = sl;
-    sl->prev = &ADDRtbl;
-    sl->localA = lcl;
-    sl->globalA = gbl;
+  sl->next = ADDRtbl.next;
+  ADDRtbl.next = sl;
+  (sl->next)->prev = sl;
+  sl->prev = &ADDRtbl;
+  sl->localA = lcl;
+  sl->globalA = gbl;
 
-    return(sl);
+  return sl;
 }
 
-module shm_resume(glbl,qp,allocp,toppred)
-struct global_variables *glbl;
-struct goalrec *qp;
-q *allocp;
-const struct predicate* toppred;
+static module
+shm_resume(glbl, qp, allocp, toppred)
+  struct global_variables* glbl;
+  struct goalrec* qp;
+  q* allocp;
+  const struct predicate* toppred;
 {
-    TADDRtbl *tp = (TADDRtbl*)((unsigned long)(qp->args[0])-ATOMIC);
-    free_local_tbl(tp);
-    if ( isatomic(tp->localA)) {  /* consumer */
-      q x = (q)untag_local(tp->localA);
-      q top = (q)&(tp->localA);
-      derefone(top) = x;
-      derefone(x) = top;
+  TADDRtbl* tp = (TADDRtbl*) ((unsigned long)(qp->args[0]) - ATOMIC);
+  free_local_tbl(tp);
+  if( isatomic(tp->localA) ){  /* consumer */
+    q x = (q) untag_local(tp->localA);
+    q top = (q) &(tp->localA);
+    derefone(top) = x;
+    derefone(x) = top;
+    qp = qp->next;
+    allocp = do_unify(allocp, top, tp->globalA);
+  }else{
+    struct goalrec* gp = (struct goalrec*) (tp->localA);
+    if( gp != NULL && isatomic(gp->next) ){
+      gp->next = qp->next;
+      qp = gp;
+      resumes++;
+    }else{
       qp = qp->next;
-      allocp = do_unify(allocp,top,tp->globalA);
-    } else {
-      struct goalrec* gp = (struct goalrec*)(tp->localA);
-      if ( gp && isatomic(gp->next) ) {
-	gp->next = qp->next;
-	qp = gp;
-	{ resumes++; }
-      } else {
-	qp = qp->next;
-      }
     }
-    heapp = allocp;
-    current_queue = qp;
-    return((module)(qp->pred)->func);
+  }
+  heapp = allocp;
+  current_queue = qp;
+  return (module) (qp->pred)->func;
 }
 
 
-module shm_request(glbl,qp,allocp,toppred)
-struct global_variables *glbl;
-struct goalrec *qp;
-q *allocp;
-const struct predicate* toppred;
-{
-    TADDRtbl *tp = (TADDRtbl*)((unsigned long)(qp->args[0])-ATOMIC);
-    q var = (q)tp->globalA;
-    free_local_tbl(tp);
-    qp = qp->next;
-
-    if ( isatomic(tp->localA) ) { /* local generator object */
-      q x = untag_local(tp->localA);
-      allocp = do_unify(allocp,x,var);
-    } else { /* shared-memory generator hook */
-      allocp = do_unify(allocp,tp->localA,var);
-    }
-    heapp = allocp;
-    current_queue = qp;
-    return((module)(qp->pred)->func);
+static module
+shm_request(glbl, qp, allocp, toppred)
+  struct global_variables* glbl;
+  struct goalrec* qp;
+  q* allocp;
+  const struct predicate* toppred;
+{
+  TADDRtbl* tp = (TADDRtbl*) ((unsigned long)(qp->args[0]) - ATOMIC);
+  q var = (q) tp->globalA;
+  free_local_tbl(tp);
+  qp = qp->next;
+
+  if( isatomic(tp->localA) ){  /* local generator object */
+    q x = untag_local(tp->localA);
+    allocp = do_unify(allocp, x, var);
+  }else{  /* shared-memory generator hook */
+    allocp = do_unify(allocp, tp->localA, var);
+  }
+  heapp = allocp;
+  current_queue = qp;
+  return (module) (qp->pred)->func;
 }
diff -ruN klic-3.003-2002-01-02/runtime/shm_rsv.c klic-3.003-2002-01-03/runtime/shm_rsv.c
--- klic-3.003-2002-01-02/runtime/shm_rsv.c	Sat Dec 29 12:46:20 2001
+++ klic-3.003-2002-01-03/runtime/shm_rsv.c	Wed Jan  2 14:12:02 2002
@@ -15,6 +15,8 @@
 #include "shm.h"
 #include <signal.h>
 
+#define MAX_N_PLNE 8
+
 /*
 #define SYNC_GC    /* Synchronous GC */
 /**/
@@ -22,58 +24,57 @@
 #define HPAGE  2048
 #define N_PAGE  64
 
+/* threshold value (favourable)THV1 %, (compel)THV2 % */
+#define THV1 90
+#define THV2 98
+
+/* table size for locking */
+#define LOCK_size  (6+total_node)
+
+
+/* shm.h */
+
 /* Number of plains (copying GC) */
 long N_PLNE = 3;
 
-long LAST_PE = 0;
-
 long Disp_child = 0;
 
-int MON_SIZE;
 int ATOM_TABLE_SIZE = 256*PAGE; /* 512KB */
+
 /* Heap size on shared memory */
 long SHM_SIZE = PAGE*N_PAGE;
-long SHM_SIZEq;
-
-long TOTAL_SIZE;
-
-/* threshold value (favourable)THV1 %, (compel)THV2 % */
-#define THV1 90
-#define THV2 98
-
-/* table size for locking */
-#define LOCK_size  (6+total_node)
 
 int* lockp[6+MAX_N_PE];
-
-
 volatile PLNE* PLNE_ptr[MAX_N_PLNE];
-
-  /* Management variables on shared memory */
-struct global_variables* shm_glblp = &globals;
 char* shm_start_addr;
 struct global_variables* top_shm_glbl;
 int* pe_status;
 int* cur_status;
-struct ex_goalrec **top_shm_qp;
-struct ex_goalrec **shm_qp;
-int* top_shm_pid;
-struct ex_goalrec **top_shm_next;
-
-  /* for Profile */
-long My_measure;
-long* Prof_measure = &My_measure;
-
-  /* current used plane number */
+struct ex_goalrec** top_shm_qp;
+struct ex_goalrec** shm_qp;
+struct ex_goalrec** top_shm_next;
 
   /* current shared memory top address of myself */
 q* gallocp = 0;
   /* current shared memory limit of myself */
 q* glimit = 0;
 
-long* get_page();
-int* init_lock();
-void abend();
+
+static int MON_SIZE;
+static long SHM_SIZEq;
+static long TOTAL_SIZE;
+
+  /* Management variables on shared memory */
+static struct global_variables* shm_glblp = &globals;
+static int* top_shm_pid;
+
+  /* for Profile */
+static long My_measure;
+static long* volatile Prof_measure = &My_measure;
+
+static long* get_page(int size);
+static int* init_lock(int* addr);
+extern void abend(char* mess);
 
 /* adjusts the memory boundary */
 #define adjust(x) ((long*)((((long)(x)+sizeof(long)-1)/sizeof(long))*sizeof(long)))
@@ -81,8 +82,9 @@
 /* Initialize shared memory.
   allocaltes shared memory and intializes shared variables.
 */
-struct global_variables* shm_init(glbl)
-struct global_variables* glbl;
+extern struct global_variables*
+shm_init(glbl)
+  struct global_variables* glbl;
 {
   long NUM_PE = total_node;
   long MY_PENO;
@@ -92,120 +94,121 @@
   long GLOBALS, EXT_INFO, LOCK_AREA, PLANE_INF, PROFILE_B;
   long BBUF[PAGE/sizeof(long)];
 
-  if ( NUM_PE < 1 || NUM_PE >= MAX_N_PE )  abend(" Number of processes ???");
-  if ( N_PLNE < 2 || N_PLNE >= MAX_N_PLNE )  abend(" Number of spacees ???");
-/* Management size on shared memory */
-     GLOBALS = reckon(sizeof(struct global_variables))*NUM_PE;
-     EXT_INFO = reckon(sizeof(long)*NUM_PE +
-                       sizeof(long)*NUM_PE +
-                       sizeof(struct goalrec*)*NUM_PE +
-                       sizeof(q*)*NUM_PE);
-     LOCK_AREA = reckon(sizeof(int)*LOCK_size);
-     PLANE_INF = reckon(sizeof(PLNE))*N_PLNE;
-     PROFILE_B = sizeof(long)*2;
-
-     MON_SIZE  =     ATOM_TABLE_SIZE + 
-                     GLOBALS +
-                     EXT_INFO +
-                     LOCK_AREA +
-                     PLANE_INF +
-                     PROFILE_B;
-
-/* Shared Heap size */
-    SHM_SIZE *= sizeof(q); /* byte count */
-    SHM_SIZE = ((SHM_SIZE+PAGE-1)/PAGE)*PAGE;
-    SHM_SIZEq = SHM_SIZE/sizeof(q);
-    SHP_SIZE = SHM_SIZE * N_PLNE;
+  if ( NUM_PE < 1 || MAX_N_PE <= NUM_PE )  abend(" Number of processes ???");
+  if ( N_PLNE < 2 || MAX_N_PLNE <= N_PLNE )  abend(" Number of spacees ???");
 
-    if ( NUM_PE == 1 ) SHP_SIZE = 0; /* only 1 process */
+  /* Management size on shared memory */
+  GLOBALS = reckon(sizeof(struct global_variables))*NUM_PE;
+  EXT_INFO = reckon(sizeof(long)*NUM_PE +
+                    sizeof(long)*NUM_PE +
+                    sizeof(struct goalrec*)*NUM_PE +
+                    sizeof(q*)*NUM_PE);
+  LOCK_AREA = reckon(sizeof(int)*LOCK_size);
+  PLANE_INF = reckon(sizeof(PLNE))*N_PLNE;
+  PROFILE_B = sizeof(long)*2;
+
+  MON_SIZE = ATOM_TABLE_SIZE +
+             GLOBALS +
+             EXT_INFO +
+             LOCK_AREA +
+             PLANE_INF +
+             PROFILE_B;
+
+  /* Shared Heap size */
+  SHM_SIZE *= sizeof(q);  /* byte count */
+  SHM_SIZE = ((SHM_SIZE+PAGE-1)/PAGE)*PAGE;
+  SHM_SIZEq = SHM_SIZE/sizeof(q);
+  SHP_SIZE = SHM_SIZE * N_PLNE;
 
-    LAST_PE = NUM_PE - 1;
+  if ( NUM_PE == 1 ) SHP_SIZE = 0;  /* only 1 process */
 
-    TOTAL_SIZE = MON_SIZE + SHP_SIZE;
+  TOTAL_SIZE = MON_SIZE + SHP_SIZE;
 
   /* management table */
-     sprintf(bf,"/tmp/SHM%d",getpid());
-     fds = open(bf,(O_RDWR|O_CREAT),0644);
-     for(j=0;j<(PAGE/sizeof(long));j++) BBUF[j] = -1;
-     lseek(fds,TOTAL_SIZE,SEEK_SET);
-     write(fds,BBUF,PAGE);
-/*     for(j=0;j<((TOTAL_SIZE+PAGE-1)/PAGE);j++) write(fds,BBUF,PAGE);*/
-
-     if ( (long)(shm_start_addr = (char*)
-         mmap(0,TOTAL_SIZE,(PROT_READ|PROT_WRITE),MAP_SHARED,fds,0))  == -1 ) {
-        perror(0); exit(1);
-     }
-     close(fds);
-     unlink(bf);
-
-     SHM_HEAP_TOP = MON_SIZE + (long)shm_start_addr;
-     SHP_SIZE += 0xff; /* allowance */
-     addr = adjust(shm_start_addr+ATOM_TABLE_SIZE);
-     top_shm_glbl = (struct global_variables*)addr;
-     for(i=0;i<NUM_PE;i++) {
-        *((struct global_variables*)addr)++ = *glbl;
-        addr = adjust(addr);
-     }
-     pe_status = (int*)addr;
-     addr += NUM_PE;
-     top_shm_pid = (int*)addr;
-     addr += NUM_PE;
-     top_shm_qp = (struct ex_goalrec **)addr;
-     addr += NUM_PE;
-     top_shm_next = (struct ex_goalrec**)addr;
-     addr += NUM_PE;
-     addr = adjust(addr);
-
-     for(i=0;i<NUM_PE;i++) {
-        *(pe_status+i) = 0;
-        *(top_shm_qp+i) = (struct ex_goalrec*)(top_shm_next+i);
-        *(top_shm_next+i) = 0;
-      }
+  sprintf(bf,"/tmp/SHM%d",getpid());
+  fds = open(bf,(O_RDWR|O_CREAT),0644);
+  for(j=0;j<(PAGE/sizeof(long));j++) BBUF[j] = -1;
+  lseek(fds,TOTAL_SIZE,SEEK_SET);
+  write(fds,BBUF,PAGE);
+  /* for(j=0;j<((TOTAL_SIZE+PAGE-1)/PAGE);j++) write(fds,BBUF,PAGE); */
+
+  shm_start_addr =
+    (char*) mmap(0, TOTAL_SIZE, (PROT_READ|PROT_WRITE), MAP_SHARED, fds, 0);
+  if( (long) shm_start_addr == -1 ) {
+    perror(0);
+    exit(1);
+  }
+  close(fds);
+  unlink(bf);
+
+  SHM_HEAP_TOP = MON_SIZE + (long) shm_start_addr;
+  SHP_SIZE += 0xff;  /* allowance */
+  addr = adjust(shm_start_addr+ATOM_TABLE_SIZE);
+  top_shm_glbl = (struct global_variables*) addr;
+  for( i=0; i<NUM_PE; i++ ){
+    *((struct global_variables*) addr)++ = *glbl;
+    addr = adjust(addr);
+  }
+  pe_status = (int*) addr;
+  addr += NUM_PE;
+  top_shm_pid = (int*) addr;
+  addr += NUM_PE;
+  top_shm_qp = (struct ex_goalrec**) addr;
+  addr += NUM_PE;
+  top_shm_next = (struct ex_goalrec**) addr;
+  addr += NUM_PE;
+  addr = adjust(addr);
+
+  for( i=0; i<NUM_PE; i++ ){
+    pe_status[i] = 0;
+    top_shm_qp[i] = (struct ex_goalrec*) (top_shm_next+i);
+    top_shm_next[i] = 0;
+  }
 
-     addr = adjust(init_lock(addr));
+  addr = adjust(init_lock(addr));
 
   /* local address table initialize */
-     d_shm_init();        /* inits external ADDRTBL */
+  d_shm_init();  /* inits external ADDRTBL */
+
+  for( i=0; i<N_PLNE; i++ ){
+    PLNE_ptr[i] = ((PLNE*) addr)++;
+    addr = adjust(addr);
+  }
 
-     for(i=0;i<N_PLNE;i++)  {
-       PLNE_ptr[i] = ((PLNE*)addr)++;
-       addr = adjust(addr);
-     }
-
-     MY_PENO = 0;  /* I am MASTER */
-     if ( NUM_PE == 1 ) { /* only one process */
-       glbl = shm_glblp = top_shm_glbl;
-       my_node = MY_PENO;
-       total_node = NUM_PE;
-       cur_status = pe_status + MY_PENO;
-       shm_qp = top_shm_qp + MY_PENO;
-       shm_glblp->par.aux.shm.ex_qp0 = (struct ex_goalrec*)top_shm_next + MY_PENO;
-       PLNE_ptr[0]->caddr = 0;
-       PLNE_ptr[1]->limit3 = (long*)MAXKLICINT;
-       /*
-	 This fix is temporary. (from Chik)
-	 */
-       init_shm_atom();		/* manages shared atom-id & funct-id */
-       /* end fix */
-       return( glbl );
-     }
+  MY_PENO = 0;  /* I am MASTER */
+  if ( NUM_PE == 1 ){  /* only one process */
+    glbl = shm_glblp = top_shm_glbl;
+    my_node = MY_PENO;
+    total_node = NUM_PE;
+    cur_status = pe_status + MY_PENO;
+    shm_qp = top_shm_qp + MY_PENO;
+    shm_glblp->par.aux.shm.ex_qp0 = (struct ex_goalrec*) top_shm_next + MY_PENO;
+    PLNE_ptr[0]->caddr = 0;
+    PLNE_ptr[1]->limit3 = (long*) MAXKLICINT;
+
+    /* This fix is temporary. (from Chik) */
+    init_shm_atom();  /* manages shared atom-id & funct-id */
+    /* end fix */
+
+    return glbl;
+  }
 
   /* Each Heap plains */
-   SHM_HEAP_TOP = (long)addr;
-   for(i=0;i<N_PLNE;i++) {
+  SHM_HEAP_TOP = (long) addr;
+  for( i=0; i<N_PLNE; i++ ){
 
-      PLNE_ptr[i]->top_addr = addr;
+    PLNE_ptr[i]->top_addr = addr;
 
-      PLNE_ptr[i]->caddr = addr;
-      PLNE_ptr[i]->direct = -1;
-      PLNE_ptr[i]->demand = 0;
-      for(j=0;j<=MAX_N_PE;j++) PLNE_ptr[i]->proc[j] = 0;
-      PLNE_ptr[i]->limit1 = addr+(SHM_SIZEq*THV1/100);
-      PLNE_ptr[i]->limit2 = addr+(SHM_SIZEq*THV2/100);
-      addr += SHM_SIZEq;
-      PLNE_ptr[i]->limit3 = addr;
+    PLNE_ptr[i]->caddr = addr;
+    PLNE_ptr[i]->direct = -1;
+    PLNE_ptr[i]->demand = 0;
+    for( j=0; j<=MAX_N_PE; j++ ) PLNE_ptr[i]->proc[j] = 0;
+    PLNE_ptr[i]->limit1 = addr+(SHM_SIZEq*THV1/100);
+    PLNE_ptr[i]->limit2 = addr+(SHM_SIZEq*THV2/100);
+    addr += SHM_SIZEq;
+    PLNE_ptr[i]->limit3 = addr;
   }
-  
+
   /* for Profile */
   Prof_measure = addr;
   *Prof_measure = 0;
@@ -216,20 +219,20 @@
 
   /* invoke parallel process */
   {
-     int child;
-     *(top_shm_pid) = getpid();
-     for (i=1;i<NUM_PE;i++) {
-         *(pe_status+i) = 1;
-         if ( child = fork() ) {
-            *(top_shm_pid+i) = child;
-	    if ( Disp_child ) 
-	      printf("The %dth-%d Child process start !\n",i,child);
-         } else {
-            MY_PENO = i;
-            break;
-         }
-     }
-
+    int child;
+    *(top_shm_pid) = getpid();
+    for( i=1; i<NUM_PE; i++ ){
+      pe_status[i] = 1;
+      child = fork();
+      if( child != 0 ){
+	top_shm_pid[i] = child;
+	if( Disp_child )
+	  printf("The %dth-%d Child process start !\n", i, child);
+      }else{
+	MY_PENO = i;
+	break;
+      }
+    }
   }
   glbl = shm_glblp = get_otherPE_glbl(MY_PENO);
   my_node = MY_PENO;
@@ -238,162 +241,162 @@
   shm_qp = top_shm_qp + MY_PENO;
   shm_glblp->par.aux.shm.ex_qp0 = (struct ex_goalrec*)(top_shm_next + MY_PENO);
 
- /* at first 0 plain */
-/*
+  /* at first 0 plain */
+  /*
   gallocp = glimit = 0;
   PLNE_ptr[currid]->proc[MY_PENO] = 1;
-*/
+  */
   /* this allocation will be disappeared */
   galloc(0);
 
   return( glbl );
 }
 
-/* finalize shared memory
-  detach shared memory
-*/
-shm_fin()
-{
-}
-
 /* galloc
   allocates shared memory specifyed size
   if no current space, get from shared memory pool
 */
-q* shm_galloc(siz)
-int siz;
+extern q*
+shm_galloc(siz)
+  int siz;
 {
   declare_globals;
-   q* temp = gallocp;
+  q* temp = gallocp;
  GET_L:
-   if((gallocp+=siz) <= glimit)  return(temp);
-   if ( glimit == 0 ) { /* this means initial state */
-      currid = 0;
-      PLNE_ptr[currid]->proc[my_node] = 1;
-   }
-   if( siz > HPAGE ) {
-      int npsize = (1+(siz/HPAGE))*HPAGE;
-      temp = gallocp = (q*)get_page(npsize);
-      glimit = gallocp + npsize;
-   } else {
-      temp = gallocp = (q*)get_page(HPAGE);
-      glimit = gallocp+HPAGE;
-   }
-   goto  GET_L;
+  gallocp += siz;
+  if( gallocp <= glimit )  return temp;
+  if( glimit == 0 ){  /* this means initial state */
+    currid = 0;
+    PLNE_ptr[currid]->proc[my_node] = 1;
+  }
+  if( siz > HPAGE ){
+    int npsize = (1+(siz/HPAGE)) * HPAGE;
+    temp = gallocp = (q*) get_page(npsize);
+    glimit = gallocp + npsize;
+  }else{
+    temp = gallocp = (q*) get_page(HPAGE);
+    glimit = gallocp + HPAGE;
+  }
+  goto GET_L;
 }
 
 /* get_page(siz)
   get shared memory from shared memory pool
 */
-long* get_page(siz)
-int siz;
+static long*
+get_page(siz)
+  int siz;
 {
-   declare_globals;
-   long *temp,*pos;
-   int key = g_key();
+  declare_globals;
+  long *temp, *pos;
+  int key = g_key();
 
  ReTry:
-   s_lock(key);
-   pos = PLNE_ptr[currid]->caddr;
-   temp = pos + siz;
-   if (PLNE_ptr[currid]->limit1>=temp) {
-     PLNE_ptr[currid]->caddr = temp;
-     s_unlock(key);
-     return(pos);
-   }
+  s_lock(key);
+  pos = PLNE_ptr[currid]->caddr;
+  temp = pos + siz;
+  if( PLNE_ptr[currid]->limit1 >= temp ){
+    PLNE_ptr[currid]->caddr = temp;
+    s_unlock(key);
+    return pos;
+  }
+
 #ifdef SYNC_GC
-   heaplimit = 0;
+  heaplimit = 0;
 #else
-   if ( currid != oldid ) {
-     if ( *cur_status == 4 ) { /* inside GC */
-        abend(" shared memory overflow !!!");
-     }
-     heaplimit = 0;
-   }
+  if( currid != oldid ){
+    if( *cur_status == 4 ){  /* inside GC */
+      abend(" shared memory overflow !!!");
+    }
+    heaplimit = 0;
+  }
 #endif
-   if (PLNE_ptr[currid]->limit3>=temp) {
-     PLNE_ptr[currid]->caddr = temp;
-     s_unlock(key);
-     return(pos);
-   }
-   s_unlock(key);
+
+  if( PLNE_ptr[currid]->limit3 >= temp ){
+    PLNE_ptr[currid]->caddr = temp;
+    s_unlock(key);
+    return pos;
+  }
+  s_unlock(key);
 
 #ifdef SYNC_GC
-   abend(" Shared memory overflow !!!");
+  abend(" Shared memory overflow !!!");
 #else
-   /* secondary try */
-   {
-      int i,j;
-      if ( PLNE_ptr[currid]->direct == -1 ) {
-        int key = m_key();
-        s_lock(key);
-        if ( PLNE_ptr[currid]->direct == -1 ) {
-          j = (currid+1) % N_PLNE;
-          for(i=0;i<total_node;i++) {
-            if (PLNE_ptr[j]->proc[i]) {
-              struct global_variables* tglbl = get_otherPE_glbl(i);
-              tglbl->interrupt_off0 = 0;
-              klic_barrier();
-              tglbl->heaplimit0 = 0;
-              sleep(1);
-              if (PLNE_ptr[j]->proc[i]) {
-                abend(" Shared memory overflow !!!");
-              }
-            }
-          }
-          /* initialize table */
-          PLNE_ptr[j]->caddr = PLNE_ptr[j]->top_addr;
-          PLNE_ptr[j]->demand = 0;
-          PLNE_ptr[j]->direct = -1;
-          PLNE_ptr[j]->proc[my_node] = 1;
-          PLNE_ptr[currid]->direct = j;
-          currid = j;
-          s_unlock(key);
-          goto ReTry;
-        }
-        s_unlock(key);
+  /* secondary try */
+  {
+    int i, j;
+    if( PLNE_ptr[currid]->direct == -1 ){
+      int key = m_key();
+      s_lock(key);
+      if( PLNE_ptr[currid]->direct == -1 ){
+	j = (currid + 1) % N_PLNE;
+	for( i=0; i<total_node; i++  ){
+	  if( PLNE_ptr[j]->proc[i] ){
+	    struct global_variables* tglbl = get_otherPE_glbl(i);
+	    tglbl->interrupt_off0 = 0;
+	    klic_barrier();
+	    tglbl->heaplimit0 = 0;
+	    sleep(1);
+	    if( PLNE_ptr[j]->proc[i] ){
+	      abend(" Shared memory overflow !!!");
+	    }
+	  }
+	}
+	/* initialize table */
+	PLNE_ptr[j]->caddr = PLNE_ptr[j]->top_addr;
+	PLNE_ptr[j]->demand = 0;
+	PLNE_ptr[j]->direct = -1;
+	PLNE_ptr[j]->proc[my_node] = 1;
+	PLNE_ptr[currid]->direct = j;
+	currid = j;
+	s_unlock(key);
+	goto ReTry;
       }
-      currid = PLNE_ptr[currid]->direct;
-      PLNE_ptr[currid]->proc[my_node] = 1;
-      goto ReTry;
+      s_unlock(key);
     }
-#endif
+    currid = PLNE_ptr[currid]->direct;
+    PLNE_ptr[currid]->proc[my_node] = 1;
+    goto ReTry;
+  }
+#endif  /* not SYNC_GC */
 }
 
 /* new_galloc --- change to the new plain from the old plain
 */
+extern void
 new_galloc(cid)
-int cid;
+  int cid;
 {
   declare_globals;
   currid = cid;
   PLNE_ptr[currid]->proc[my_node] = 1;
-  gallocp = glimit = (q*)1;
+  gallocp = glimit = (q*) 1;
 }
 
 /* initialize a lock table
 */
-int* init_lock(addr)
-int* addr;
+static int*
+init_lock(addr)
+  int* addr;
 {
   declare_globals;
-  int i,j;
-  for(i=0;i<LOCK_size;i++)  {
-      *addr = 0;
-      lockp[i] = (addr)++;
+  int i, j;
+  for( i=0; i<LOCK_size; i++ ){
+    *addr = 0;
+    lockp[i] = (addr)++;
   }
-  return((int*)addr);
+  return (int*) addr;
 }
 
 
 /* abend with a message
   make sence at debug time
 */
-void
+extern void
 abend(mess)
-char* mess;
+  char* mess;
 {
   declare_globals;
-  fprintf(stderr,"The %dth process - %s\n",my_node,mess);
+  fprintf(stderr, "The %dth process - %s\n", my_node, mess);
   kill(0, SIGTERM);
 }
diff -ruN klic-3.003-2002-01-02/runtime/shm_throw.c klic-3.003-2002-01-03/runtime/shm_throw.c
--- klic-3.003-2002-01-02/runtime/shm_throw.c	Tue Jan  1 14:17:47 2002
+++ klic-3.003-2002-01-03/runtime/shm_throw.c	Wed Jan  2 14:30:28 2002
@@ -12,77 +12,109 @@
 #include <klic/functorstuffs.h>  /* arityof */
 #include "susp.h"
 #include "gobj.h"
-#include "shm.h"
+#include "shm.h"  /* last_shm_var */
 #include <signal.h>
 
 #ifdef DEBUGLIB
 #include "trace.h"  /* trace_flag, trace_goal */
 #endif
 
+#define is_locala(X) \
+    ( (unsigned long)((long)(X)-(long)heaptop) < real_heapbytesize )
+
+#define makeshvar(svar) \
+do{ \
+  struct generator_susp* vcell; \
+  (svar) = (q) galloc((sizeof(struct generator_susp) / sizeof(q)) + 1); \
+  vcell = (struct generator_susp*) (((q*) svar) + 1); \
+  vcell->backpt = (q) (svar); \
+  vcell->u.o = tag_generator_susp(pSHM_VAR); \
+  *((q*) svar) = (q) vcell; \
+}while(0)
+
+#define ck_throw_new_galloc(num) \
+do{ \
+    int cid = currid;\
+    while( (cid=PLNE_ptr[cid]->direct) != -1 ) { \
+       if ( PLNE_ptr[cid]->proc[num] ) {new_galloc(cid);} \
+    }\
+}while(0)
+
 q last_shm_var;
 
-/* throw_goal_routine(qp,gp,Logical_process_number)
+/* phisc_pe(Logical_process_number)
+  convert a logical process number to a phisical shared process number
+*/
+static int
+phisc_pe(NO)
+  int NO;
+{
+    declare_globals;
+    if( 0 <= NO && NO < total_node )
+       return(NO);
+    else
+       abend("Invalid PE number !!!");
+}
+
+/* shm_goal_copy(Local_goal_pointer,priority)
+  copy a goal into shared memory
 */
-struct goalrec* throw_goal_routine(N,qp,gp)
-int N;
-struct goalrec *qp,*gp;
+static struct ex_goalrec*
+shm_goal_copy(qp, prio)
+  struct goalrec* qp;
+  long prio;
+{
+  int i, j;
+  int arity = qp->pred->arity;
+  struct ex_goalrec* sgoal;
+  struct goalrec* goal;
+  sgoal = (struct ex_goalrec*) galloc(arity + 4);
+  sgoal->prio = prio;
+  goal = &sgoal->goal;
+  goal->next = 0;
+  goal->pred = qp->pred;
+  for( i=0; i<arity; i++ ){
+    shm_arg_copy(&qp->args[i], &goal->args[i]);
+  }
+  return sgoal;
+}
+
+extern struct goalrec*
+throw_goal_routine(N, qp, gp)
+  int N;  /* logical process number */
+  struct goalrec *qp, *gp;
 {
   declare_globals;
   struct goalrec *ng;
   int k;
-  if ( is_shmconnect(N) ) {
-    int num = phisc_pe(N);
-    struct ex_goalrec *sh_goal;
-    *cur_status = 2;
+  int num = phisc_pe(N);
+  struct ex_goalrec* sh_goal;
+  *cur_status = 2;
 
-    ck_throw_new_galloc(num);
+  ck_throw_new_galloc(num);
 
 #ifdef DEBUGLIB
-    if (trace_flag) {
-      static long throw_trace_count = 0;
-      gp = trace_goal(gp, (num+1)*100000+throw_trace_count, NULL);
-      throw_trace_count++;
-    }
+  if( trace_flag ){
+    static long throw_trace_count = 0;
+    gp = trace_goal(gp, (num+1)*100000+throw_trace_count, NULL);
+    throw_trace_count++;
+  }
 #endif
 
-    sh_goal = shm_goal_copy(gp,current_prio);
-    shm_goal_stack(sh_goal,num);
-    *cur_status = 1;
-  } else {
-    abend(" Not implemeted yet..\n");
-  }
-  return(qp);
+  sh_goal = shm_goal_copy(gp, current_prio);
+  shm_goal_stack(sh_goal, num);
+  *cur_status = 1;
+  return qp;
 }
 
 
-/* shm_goal_copy(Local_goal_pointer,priority)
-  copy a goal into shared memory
-*/
-struct ex_goalrec *shm_goal_copy(qp,prio)
-struct goalrec *qp;
-long prio;
-{
-    int i,j;
-    int arity = qp->pred->arity;
-    struct ex_goalrec *sgoal;
-    struct goalrec *goal;
-    sgoal = (struct ex_goalrec*)galloc(arity+4);
-    sgoal->prio = prio;
-    goal = &sgoal->goal;
-    goal->next = 0;
-    goal->pred = qp->pred;
-    for(i=0;i<arity;i++) {
-       shm_arg_copy(&qp->args[i],&goal->args[i]);
-    }
-    return(sgoal);
-}
-
 /* shm_goal_stack(Shared_goal_pointer,stack_position)
   stack a goal to shared other process's stack
 */
+extern int
 shm_goal_stack(goal,num)
-struct ex_goalrec* goal;
-int num;
+  struct ex_goalrec* goal;
+  int num;
 {
     struct ex_goalrec* tqp;
     int key = p_key(num);
@@ -117,19 +149,6 @@
     }
 }
 
-/* phisc_pe(Logical_process_number)
-  covert a logical process number to a phisical shared process number
-*/
-int phisc_pe(NO)
-int NO;
-{
-    declare_globals;
-    if ( NO >= 0 && NO < total_node )
-       return(NO);
-    else
-       abend("Invalid PE number !!!");
-}
-
 /* ***************  Copy Routines  ****************************** */
 
 #define ck_arg_copy(x,y) {\
@@ -150,11 +169,9 @@
    }\
 }
 
-/* q shm_copy(SrcAddr)
-*/
 
-q shm_copy(src)
-q src;
+extern q shm_copy(src)
+  q src;  /* SrcAddr */
 {
   declare_globals;
    q cnp;
@@ -318,9 +335,10 @@
 /* shm_arg_copy(SrcAddr,DistAddr)
   copy data into shared memory recursively
 */
-shm_arg_copy(srcp,distp)
-q* srcp;
-q* distp;
+extern void
+shm_arg_copy(srcp, distp)
+  q* srcp;
+  q* distp;
 {
   declare_globals;
   q src,cnp;
@@ -481,7 +499,8 @@
            arity = arityof(f);
            cnp = (q)galloc(arity+1);
            ((struct functor*)cnp)->functor = functorp(src)->functor;
-/* First arg is special for Topdown GC */
+
+	   /* First arg is special for Topdown GC */
            for(i=0;i<arity;i++) {
              shm_arg_copy(&functorp(src)->args[i],&((struct functor*)cnp)->args[i]);
            }
@@ -494,4 +513,3 @@
        }
     }
 }
-
