[Tinyos-commits] CVS: tinyos-1.x/tos/lib/VM/languages/motlle/mate/runtime FNseq.nc, 1.3, 1.4 FNseqM.nc, 1.5, 1.6

David Gay idgay at users.sourceforge.net
Tue Oct 25 11:21:09 PDT 2005


Update of /cvsroot/tinyos/tinyos-1.x/tos/lib/VM/languages/motlle/mate/runtime
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21257

Modified Files:
	FNseq.nc FNseqM.nc 
Log Message:
map


Index: FNseq.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/tos/lib/VM/languages/motlle/mate/runtime/FNseq.nc,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** FNseq.nc	25 Oct 2005 16:54:08 -0000	1.3
--- FNseq.nc	25 Oct 2005 18:21:06 -0000	1.4
***************
*** 1,5 ****
  configuration FNseq {
    provides {
!     //interface MateBytecode as Map;
      interface MateBytecode as ForEach;
      interface MateBytecode as Vector2List;
--- 1,5 ----
  configuration FNseq {
    provides {
!     interface MateBytecode as Map;
      interface MateBytecode as ForEach;
      interface MateBytecode as Vector2List;
***************
*** 8,12 ****
      interface MateBytecode as List2String;
      interface MateBytecode as Length;
-     interface MotlleFrame as MapFrame;
      interface MateBytecode as Memq;
      interface MateBytecode as Memv;
--- 8,11 ----
***************
*** 20,23 ****
--- 19,23 ----
    components FNseqM, MProxy, MOPcall;
  
+   Map = FNseqM.Map;
    ForEach = FNseqM.ForEach;
    Vector2List = FNseqM.Vector2List;
***************
*** 26,30 ****
    List2String = FNseqM.List2String;
    Length = FNseqM.Length;
-   MapFrame = FNseqM.MapFrame;
    Memq = FNseqM.Memq;
    Memv = FNseqM.Memv;
--- 26,29 ----
***************
*** 41,43 ****
--- 40,43 ----
    FNseqM.Exec -> MOPcall.Exec;
    FNseqM.MapFrame <- MProxy.MotlleFrame[MOTLLE_MAP_FRAME];
+   FNseqM.ForeachFrame <- MProxy.MotlleFrame[MOTLLE_FOREACH_FRAME];
  }

Index: FNseqM.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/tos/lib/VM/languages/motlle/mate/runtime/FNseqM.nc,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** FNseqM.nc	25 Oct 2005 16:54:08 -0000	1.5
--- FNseqM.nc	25 Oct 2005 18:21:06 -0000	1.6
***************
*** 1,5 ****
  module FNseqM {
    provides {
!     //interface MateBytecode as Map;
      interface MateBytecode as ForEach;
      interface MateBytecode as Vector2List;
--- 1,5 ----
  module FNseqM {
    provides {
!     interface MateBytecode as Map;
      interface MateBytecode as ForEach;
      interface MateBytecode as Vector2List;
***************
*** 8,11 ****
--- 8,12 ----
      interface MateBytecode as List2String;
      interface MateBytecode as Length;
+     interface MotlleFrame as ForeachFrame;
      interface MotlleFrame as MapFrame;
      interface MateBytecode as Memq;
***************
*** 227,231 ****
  	    if (call T.nullp(l))
  	      {
! 		result = call T.nil();
  		break;
  	      }
--- 228,232 ----
  	    if (call T.nullp(l))
  	      {
! 		result = call T.make_bool(FALSE);
  		break;
  	      }
***************
*** 278,282 ****
  
  	    if (call T.nullp(l))
! 	      break;
  
  	    p = call T.pair(l);
--- 279,286 ----
  
  	    if (call T.nullp(l))
! 	      {
! 		l = call T.make_bool(FALSE);
! 		break;
! 	      }
  
  	    p = call T.pair(l);
***************
*** 379,389 ****
    }
  
-   struct map_frame {
-     msize idx, len;
-     uint8_t nargs;
-     uint16_t retpc;
-     void *sp;
-   };
- 
    bool map_length(MateContext *context, uint8_t i, msize *len) {
      mvalue x = call S.get(context, i);
--- 383,386 ----
***************
*** 403,406 ****
--- 400,445 ----
    }
  
+   bool check_map_args(MateContext *context, uint8_t nargs, msize *len) {
+     bool first = TRUE;
+     uint8_t i;
+     mvalue fn;
+ 
+     /* Check min/max args */
+     if (nargs <= 1 || --nargs >= 16)
+       {
+ 	call E.error(context, MOTLLE_ERROR_BAD_VALUE);
+ 	return FALSE;
+       }
+ 
+     fn = call S.get(context, nargs);
+     if (!call T.functionp(fn))
+       {
+ 	call E.error(context, MOTLLE_ERROR_BAD_VALUE);
+ 	return FALSE;
+       }
+ 
+     /* Check that all sequences are of the same lengths */
+     for (i = 0; i < nargs; i++)
+       {
+ 	msize nlen;
+ 
+ 	if (!map_length(context, i, &nlen))
+ 	  return FALSE;
+ 
+ 	if (first)
+ 	  {
+ 	    first = FALSE;
+ 	    *len = nlen;
+ 	  }
+ 	else if (*len != nlen)
+ 	  {
+ 	    call E.error(context, MOTLLE_ERROR_BAD_VALUE);
+ 	    return FALSE;
+ 	  }
+       }
+ 
+     return TRUE;
+   }
+ 
    mvalue map_arg(void *sp, msize idx, uint8_t i) {
      mvalue arg = call S.getOtherFrame(sp, i);
***************
*** 420,429 ****
    }
  
!   command void MapFrame.execute(MateContext *context, void *vframe) {
!     struct map_frame *frame = vframe;
!     uint8_t i, nargs = frame->nargs, idx = frame->idx++;
  
!     if (idx != 0)
!       call S.pop(context, 1); // get rid of the old result
  
      if (idx == frame->len)
--- 459,472 ----
    }
  
!   struct foreach_frame {
!     msize idx, len;
!     uint8_t nargs;
!     uint16_t retpc;
!     void *sp;
!   };
  
!   void foreach_execute(MateContext *context, struct foreach_frame *frame,
! 		       mvalue result) {
!     uint8_t i, nargs = frame->nargs, idx = frame->idx++;
  
      if (idx == frame->len)
***************
*** 431,441 ****
  	/* Done. Get rid of the frame and old arguments. */
  	context->pc = frame->retpc;
! 	call S.pop_frame(context, sizeof(struct map_frame));
  	call S.pop(context, nargs + 1);
! 	call S.qpush(context, call T.make_int(42));
! 	return;
        }
! 
!     if (call S.reserve(context, (nargs + 1) * sizeof(svalue)))
        {
  	for (i = 0; i < nargs; i++)
--- 474,482 ----
  	/* Done. Get rid of the frame and old arguments. */
  	context->pc = frame->retpc;
! 	call S.pop_frame(context, sizeof(struct foreach_frame));
  	call S.pop(context, nargs + 1);
! 	call S.qpush(context, result);
        }
!     else if (call S.reserve(context, (nargs + 1) * sizeof(svalue)))
        {
  	for (i = 0; i < nargs; i++)
***************
*** 446,507 ****
    }
  
!   command msize MapFrame.gc_forward(MateContext *context, void *vframe, uint8_t *lfp, uint8_t *lsp) {
!     return sizeof(struct map_frame);
!   }
  
!   void push_map_frame(MateContext *context, uint8_t nargs, msize len) {
!     struct map_frame *frame;
!     void *map_sp = call S.sp(context);
  
!     frame = call S.alloc_frame(context, MOTLLE_MAP_FRAME,
! 			       sizeof(struct map_frame));
!     if (frame)
!       {
! 	frame->idx = 0;
! 	frame->len = len;
! 	frame->nargs = nargs;
! 	frame->retpc = context->pc;
! 	frame->sp = map_sp;
! 	context->pc = 2;
!       }
    }
  
!   bool check_map_args(MateContext *context, uint8_t nargs, msize *len) {
!     bool first = TRUE;
!     uint8_t i;
!     mvalue fn;
! 
!     /* Check min/max args */
!     if (nargs <= 1 || --nargs >= 16)
!       {
! 	call E.error(context, MOTLLE_ERROR_BAD_VALUE);
! 	return FALSE;
!       }
! 
!     fn = call S.get(context, nargs);
!     if (!call T.functionp(fn))
!       {
! 	call E.error(context, MOTLLE_ERROR_BAD_VALUE);
! 	return FALSE;
!       }
! 
!     /* Check that all sequences are of the same lengths */
!     for (i = 0; i < nargs; i++)
!       {
! 	msize nlen;
  
! 	if (!map_length(context, i, &nlen))
! 	  return FALSE;
  
! 	if (first)
! 	  *len = nlen;
! 	else if (*len != nlen)
! 	  {
! 	    call E.error(context, MOTLLE_ERROR_BAD_VALUE);
! 	    return FALSE;
! 	  }
!       }
  
!     return TRUE;
    }
  
--- 487,520 ----
    }
  
!   command void ForeachFrame.execute(MateContext *context, void *vframe) {
!     struct foreach_frame *frame = vframe;
  
!     if (frame->idx != 0)
!       call S.pop(context, 1); // get rid of the old result
  
!     foreach_execute(context, frame, call T.make_int(42));
    }
  
!   command msize ForeachFrame.gc_forward(MateContext *context, void *vframe, uint8_t *lfp, uint8_t *lsp) {
!     return sizeof(struct foreach_frame);
!   }
  
!   void init_foreach_frame(MateContext *context, struct foreach_frame *frame, uint8_t nargs, msize len, void *map_sp) {
!     frame->idx = 0;
!     frame->len = len;
!     frame->nargs = nargs - 1;
!     frame->retpc = context->pc;
!     frame->sp = map_sp;
!     context->pc = 2;
!   }
  
!   void push_foreach_frame(MateContext *context, uint8_t nargs, msize len) {
!     struct foreach_frame *frame;
!     void *map_sp = call S.sp(context);
  
!     frame = call S.alloc_frame(context, MOTLLE_FOREACH_FRAME,
! 			       sizeof(struct foreach_frame));
!     if (frame)
!       init_foreach_frame(context, frame, nargs, len, map_sp);
    }
  
***************
*** 513,517 ****
  
      if (check_map_args(context, nargs, &len))
!       push_map_frame(context, nargs, len);
  
      return SUCCESS;
--- 526,530 ----
  
      if (check_map_args(context, nargs, &len))
!       push_foreach_frame(context, nargs, len);
  
      return SUCCESS;
***************
*** 522,531 ****
    }
  
! #if 0
!   //xFN map: fn x1 ... -> x.: apply fn to the n-tuple formed by taking
    //   one element from each xi list/vector/string.
    //   Each xi must have the same length. The result is the result of
    //   the calls to fn.
!   command result_t Map.execute(uint8_t instr, MateContext* context) {
      return SUCCESS;
    }
--- 535,594 ----
    }
  
!   struct map_frame {
!     struct foreach_frame foreach;
!     mvalue results, last_result;
!   };
! 
!   command void MapFrame.execute(MateContext *context, void *vframe) {
!     struct map_frame *frame = vframe;
! 
!     if (frame->foreach.idx != 0)
!       {
! 	/* Add last result to list */
! 	mvalue result = call S.pop(context, 1);
! 	vpair presult = call T.alloc_list(result, call T.nil());
! 
! 	result = call T.make_pair(presult);
! 	if (frame->results == call T.nil())
! 	  frame->results = result;
! 	else
! 	  call V.write(&(call T.pair(frame->last_result))->cdr, result);
! 	frame->last_result = result;
!       }
! 
!     foreach_execute(context, &frame->foreach, frame->results);
!   }
! 
!   command msize MapFrame.gc_forward(MateContext *context, void *vframe, uint8_t *lfp, uint8_t *lsp) {
!     struct map_frame *frame = vframe;
! 
!     call GC.forward(&frame->results);
!     call GC.forward(&frame->last_result);
!     return sizeof(struct map_frame);
!   }
! 
!   void push_map_frame(MateContext *context, uint8_t nargs, msize len) {
!     struct map_frame *frame;
!     void *map_sp = call S.sp(context);
! 
!     frame = call S.alloc_frame(context, MOTLLE_MAP_FRAME,
! 			       sizeof(struct map_frame));
!     if (frame)
!       {
! 	init_foreach_frame(context, &frame->foreach, nargs, len, map_sp);
! 	frame->results = frame->last_result = call T.nil();
!       }
!   }
! 
!   //FN map: fn x1 ... -> x.: apply fn to the n-tuple formed by taking
    //   one element from each xi list/vector/string.
    //   Each xi must have the same length. The result is the result of
    //   the calls to fn.
!   command result_t Map.execute(uint8_t nargs, MateContext* context) {
!     msize len;
! 
!     if (check_map_args(context, nargs, &len))
!       push_map_frame(context, nargs, len);
! 
      return SUCCESS;
    }
***************
*** 534,538 ****
      return 1;
    }
- #endif
  }
    
--- 597,600 ----



More information about the Tinyos-commits mailing list