[Tinyos-commits]
CVS: tinyos-1.x/tos/lib/VM/languages/motlle/mate/runtime
FNlist.nc, 1.2, 1.3 FNlistM.nc, 1.2, 1.3
David Gay
idgay at users.sourceforge.net
Sun Oct 23 14:58:03 PDT 2005
- Previous message: [Tinyos-commits] CVS: tinyos-1.x/tos/lib/VM/languages/motlle/mate
OPmframe.nc, NONE, 1.1 MOPcallM.nc, 1.2, 1.3 Memory.nc, 1.2,
1.3 MemoryM.nc, 1.2, 1.3 MotlleFrame.nc, 1.2,
1.3 MotlleObjectsM.nc, 1.3, 1.4 MotlleStack.nc, 1.2,
1.3 MotlleTypes.nc, 1.3, 1.4 MotlleValues.nc, 1.2,
1.3 motlle.ldf, 1.2, 1.3
- Next message: [Tinyos-commits] CVS: tinyos-1.x/tos/lib/VM/languages/motlle/mate
MotlleObjectsM.nc, 1.4, 1.5
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Update of /cvsroot/tinyos/tinyos-1.x/tos/lib/VM/languages/motlle/mate/runtime
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28499/runtime
Modified Files:
FNlist.nc FNlistM.nc
Log Message:
list functions
Index: FNlist.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/tos/lib/VM/languages/motlle/mate/runtime/FNlist.nc,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** FNlist.nc 30 Nov 2004 18:52:43 -0000 1.2
--- FNlist.nc 23 Oct 2005 21:58:01 -0000 1.3
***************
*** 2,7 ****
provides {
interface MateBytecode as Cons;
- interface MateBytecode as Car;
- interface MateBytecode as Cdr;
interface MateBytecode as PairP;
interface MateBytecode as ListP;
--- 2,5 ----
***************
*** 10,13 ****
--- 8,31 ----
interface MateBytecode as SetCdrB;
interface MateBytecode as List;
+ interface MateBytecode as Memq;
+ interface MateBytecode as Memv;
+ interface MateBytecode as Assq;
+ interface MateBytecode as Assv;
+ interface MateBytecode as ListTail;
+ interface MateBytecode as ListRef;
+ interface MateBytecode as Car;
+ interface MateBytecode as Cdr;
+ interface MateBytecode as Caar;
+ interface MateBytecode as Cadr;
+ interface MateBytecode as Cdar;
+ interface MateBytecode as Cddr;
+ interface MateBytecode as Caaar;
+ interface MateBytecode as Caadr;
+ interface MateBytecode as Cadar;
+ interface MateBytecode as Caddr;
+ interface MateBytecode as Cdaar;
+ interface MateBytecode as Cdadr;
+ interface MateBytecode as Cddar;
+ interface MateBytecode as Cdddr;
}
}
***************
*** 16,21 ****
Cons = FNlistM.Cons;
- Car = FNlistM.Car;
- Cdr = FNlistM.Cdr;
PairP = FNlistM.PairP;
ListP = FNlistM.ListP;
--- 34,37 ----
***************
*** 24,27 ****
--- 40,63 ----
SetCdrB = FNlistM.SetCdrB;
List = FNlistM.List;
+ Memq = FNlistM.Memq;
+ Memv = FNlistM.Memv;
+ Assq = FNlistM.Assq;
+ Assv = FNlistM.Assv;
+ ListTail = FNlistM.ListTail;
+ ListRef = FNlistM.ListRef;
+ Car = FNlistM.Car;
+ Cdr = FNlistM.Cdr;
+ Caar = FNlistM.Caar;
+ Cadr = FNlistM.Cadr;
+ Cdar = FNlistM.Cdar;
+ Cddr = FNlistM.Cddr;
+ Caaar = FNlistM.Caaar;
+ Caadr = FNlistM.Caadr;
+ Cadar = FNlistM.Cadar;
+ Caddr = FNlistM.Caddr;
+ Cdaar = FNlistM.Cdaar;
+ Cdadr = FNlistM.Cdadr;
+ Cddar = FNlistM.Cddar;
+ Cdddr = FNlistM.Cdddr;
FNlistM.S -> MProxy;
Index: FNlistM.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/tos/lib/VM/languages/motlle/mate/runtime/FNlistM.nc,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** FNlistM.nc 30 Nov 2004 18:52:43 -0000 1.2
--- FNlistM.nc 23 Oct 2005 21:58:01 -0000 1.3
***************
*** 2,7 ****
provides {
interface MateBytecode as Cons;
- interface MateBytecode as Car;
- interface MateBytecode as Cdr;
interface MateBytecode as PairP;
interface MateBytecode as ListP;
--- 2,5 ----
***************
*** 10,13 ****
--- 8,31 ----
interface MateBytecode as SetCdrB;
interface MateBytecode as List;
+ interface MateBytecode as Memq;
+ interface MateBytecode as Memv;
+ interface MateBytecode as Assq;
+ interface MateBytecode as Assv;
+ interface MateBytecode as ListTail;
+ interface MateBytecode as ListRef;
+ interface MateBytecode as Car;
+ interface MateBytecode as Cdr;
+ interface MateBytecode as Caar;
+ interface MateBytecode as Cadr;
+ interface MateBytecode as Cdar;
+ interface MateBytecode as Cddr;
+ interface MateBytecode as Caaar;
+ interface MateBytecode as Caadr;
+ interface MateBytecode as Cadar;
+ interface MateBytecode as Caddr;
+ interface MateBytecode as Cdaar;
+ interface MateBytecode as Cdadr;
+ interface MateBytecode as Cddar;
+ interface MateBytecode as Cdddr;
}
uses {
***************
*** 20,23 ****
--- 38,50 ----
}
implementation {
+ bool valid_list(MateContext *context, mvalue l, msize *len) {
+ bool ok = call T.valid_list(l, len);
+
+ if (!ok)
+ call E.error(context, MOTLLE_ERROR_BAD_VALUE);
+
+ return ok;
+ }
+
//FN cons: x1 x2 -> l. Make a new pair from elements x1 & x2
command result_t Cons.execute(uint8_t instr, MateContext* context) {
***************
*** 36,75 ****
}
- //FN car: l -> x. Returns first element of pair l
- command result_t Car.execute(uint8_t instr, MateContext* context) {
- mvalue l = call S.pop(context, 1);
-
- if (call T.pairp(l))
- {
- vpair p = call T.pair(l);
- call S.qpush(context, call V.read(&p->car));
- }
- else
- call E.error(context, MOTLLE_ERROR_BAD_TYPE);
- return SUCCESS;
- }
-
- command uint8_t Car.byteLength() {
- return 1;
- }
-
- //FN cdr: l -> x. Returns first element of pair l
- command result_t Cdr.execute(uint8_t instr, MateContext* context) {
- mvalue l = call S.pop(context, 1);
-
- if (call T.pairp(l))
- {
- vpair p = call T.pair(l);
- call S.qpush(context, call V.read(&p->cdr));
- }
- else
- call E.error(context, MOTLLE_ERROR_BAD_TYPE);
- return SUCCESS;
- }
-
- command uint8_t Cdr.byteLength() {
- return 1;
- }
-
//FN pair?: x -> b. TRUE if x is a pair
command result_t PairP.execute(uint8_t instr, MateContext* context) {
--- 63,66 ----
***************
*** 171,173 ****
--- 162,627 ----
return 1;
}
+
+ //FN assq: l x1 -> x2. Returns first element of l whose car is x1,
+ // or false if there is no such element.
+ command result_t Assq.execute(uint8_t nargs, MateContext* context) {
+ mvalue l = call S.pop(context, 1);
+ mvalue x = call S.pop(context, 1);
+ msize len;
+ mvalue result;
+
+ if (valid_list(context, l, &len))
+ {
+ for (;;)
+ {
+ vpair p;
+
+ if (call T.nilp(l))
+ {
+ result = call T.nil();
+ break;
+ }
+
+ p = call T.pair(l);
+ if (call T.pairp(p->car))
+ {
+ vpair elem = call T.pair(p->car);
+
+ if (x == elem->car)
+ {
+ result = p->car;
+ break;
+ }
+ }
+ l = p->cdr;
+ }
+ call S.qpush(context, result);
+ }
+ return SUCCESS;
+ }
+
+ command uint8_t Assq.byteLength() {
+ return 1;
+ }
+
+ //FN assv: l x1 -> x2. Returns first element of l whose car is x1,
+ // or false if there is no such element.
+ command result_t Assv.execute(uint8_t nargs, MateContext* context) {
+ return call Assq.execute(nargs, context);
+ }
+
+ command uint8_t Assv.byteLength() {
+ return 1;
+ }
+
+ //FN memq: l1 x -> l2. Returns l1 starting at the first element which is x,
+ // or false if there is no such element.
+ command result_t Memq.execute(uint8_t nargs, MateContext* context) {
+ mvalue l = call S.pop(context, 1);
+ mvalue x = call S.pop(context, 1);
+ msize len;
+ mvalue result;
+
+ if (valid_list(context, l, &len))
+ {
+ for (;;)
+ {
+ vpair p;
+
+ if (call T.nilp(l))
+ {
+ result = call T.nil();
+ break;
+ }
+
+ p = call T.pair(l);
+ if (p->car == x)
+ {
+ result = p;
+ break;
+ }
+ l = p->cdr;
+ }
+ call S.qpush(context, result);
+ }
+ return SUCCESS;
+ }
+
+ command uint8_t Memq.byteLength() {
+ return 1;
+ }
+
+ //FN memv: l1 x -> l2. Returns l1 starting at the first element which is x,
+ // or false if there is no such element.
+ command result_t Memv.execute(uint8_t nargs, MateContext* context) {
+ return call Memq.execute(nargs, context);
+ }
+
+ command uint8_t Memv.byteLength() {
+ return 1;
+ }
+
+ //FN list_tail: l1 n -> l2. Returns the nth cdr of l2
+ command result_t ListTail.execute(uint8_t nargs, MateContext* context) {
+ mvalue mn = call S.pop(context, n);
+ mvalue l = call S.pop(context, 1);
+
+ if (call T.intp(mn))
+ {
+ vint n = call T.inv(mn);
+
+ if (n < 0)
+ call E.error(context, MOTLLE_ERROR_BAD_VALUE);
+ while (n-- > 0)
+ {
+ if (!call T.pairp(l))
+ {
+ call E.error(context, MOTLLE_ERROR_BAD_VALUE);
+ return SUCCESS;
+ }
+ l = (call T.pair(l))->cdr;
+ }
+ call S.qpush(context, l);
+ }
+ else
+ call E.error(context, MOTLLE_ERROR_BAD_TYPE);
+ }
+
+ command uint8_t ListTail.byteLength() {
+ return 1;
+ }
+
+ //FN list_ref: l1 n -> l2. Returns the nth car of l2
+ command result_t ListRef.execute(uint8_t nargs, MateContext* context) {
+ mvalue mn = call S.pop(context, n);
+ mvalue l = call S.pop(context, 1);
+
+ if (call T.intp(mn))
+ {
+ vint n = call T.inv(mn);
+
+ if (n < 0)
+ call E.error(context, MOTLLE_ERROR_BAD_VALUE);
+ else
+ for (;;)
+ {
+ vpair p;
+
+ if (!call T.pairp(l))
+ {
+ call E.error(context, MOTLLE_ERROR_BAD_VALUE);
+ return SUCCESS;
+ }
+ p = call T.pair(l);
+ if (n-- == 0)
+ {
+ call S.qpush(context, p->car);
+ return SUCCESS;
+ }
+ else
+ l = p->cdr;
+ }
+ }
+ else
+ call E.error(context, MOTLLE_ERROR_BAD_TYPE);
+ }
+
+ command uint8_t ListRef.byteLength() {
+ return 1;
+ }
+
+ //FN reverse: l1 -> l2. Reverse list l1
+ command result_t Reverse.execute(uint8_t instr, MateContext* context) {
+ mvalue x = call S.pop(context, 1), result = call T.nil();
+ msize len, i;
+
+ if (valid_list(context, x, &len))
+ {
+ while (!call T.nilp(x))
+ {
+ vpair p = call T.pair(x);
+
+ x = p->cdr;
+ GCPRO1(x);
+ result = call T.alloc_list(p->car, result);
+ GCPOP1(x);
+ if (!result)
+ return SUCCESS;
+ }
+ call S.qpush(context, result);
+ }
+ return SUCCESS;
+ }
+
+ command uint8_t Reverse.byteLength() {
+ return 1;
+ }
+
+ //FN append: l1 l2 -> l3. Append list l1 to l2.
+ command result_t Append.execute(uint8_t instr, MateContext* context) {
+ mvalue l2 = call S.pop(context, 1);
+ mvalue l1 = call S.pop(context, 1);
+ msize len, i;
+
+ if (call T.nilp(l1))
+ call S.qpush(context, l2);
+ else if (valid_list(context, l1, &len))
+ {
+ /* Make n element list, then fill it in (this avoids
+ constantly protecting/unprotecting and accessing x) */
+ GCPRO1(x);
+ result = make_list(len);
+ GCPOP1(x);
+
+ if (result)
+ {
+ mvalue scanr = result;
+
+ for (;;)
+ {
+ vpair pl1 = call T.pair(l1);
+ vpair pr = call T.pair(scanr);
+
+ pr->car = pl1->car;
+ l1 = pl1->cdr;
+
+ if (call T.nilp(l1))
+ {
+ pr->cdr = l2;
+ break;
+ }
+ else
+ scanr = pr->cdr;
+ }
+
+ call S.qpush(context, result);
+ }
+ }
+ return SUCCESS;
+ }
+
+ command uint8_t Append.byteLength() {
+ return 1;
+ }
+
+ #define CAR(l) (l = l && call T.pairp(l) ? call V.read(&(call T.pair(l))->car) : NULL)
+ #define CDR(l) (l = l && call T.pairp(l) ? call V.read(&(call T.pair(l))->cdr) : NULL)
+ #define PUSH(l) (if (l) call S.qpush(context, l); else call E.error(context, MOTLLE_ERROR_BAD_TYPE))
+
+ //FN car: l -> x. Returns first element of pair l
+ command result_t Car.execute(uint8_t instr, MateContext* context) {
+ mvalue l = call S.pop(context, 1);
+
+ CAR(l);
+ PUSH(l);
+
+ return SUCCESS;
+ }
+
+ command uint8_t Car.byteLength() {
+ return 1;
+ }
+
+ //FN cdr: l -> x. Returns first element of pair l
+ command result_t Cdr.execute(uint8_t instr, MateContext* context) {
+ mvalue l = call S.pop(context, 1);
+
+ CDR(l);
+ PUSH(l);
+
+ return SUCCESS;
+ }
+
+ command uint8_t Cdr.byteLength() {
+ return 1;
+ }
+
+ //FN caar: l -> x. car(car(l))
+ command result_t Caar.execute(uint8_t instr, MateContext* context) {
+ mvalue l = call S.pop(context, 1);
+
+ CAR(l);
+ CAR(l);
+ PUSH(l);
+
+ return SUCCESS;
+ }
+
+ command uint8_t Caar.byteLength() {
+ return 1;
+ }
+
+ //FN cadr: l -> x. car(cdr(l))
+ command result_t Cadr.execute(uint8_t instr, MateContext* context) {
+ mvalue l = call S.pop(context, 1);
+
+ CDR(l);
+ CAR(l);
+ PUSH(l);
+
+ return SUCCESS;
+ }
+
+ command uint8_t Cadr.byteLength() {
+ return 1;
+ }
+
+ //FN cdar: l -> x. cdr(car(l))
+ command result_t Cdar.execute(uint8_t instr, MateContext* context) {
+ mvalue l = call S.pop(context, 1);
+
+ CAR(l);
+ CDR(l);
+ PUSH(l);
+
+ return SUCCESS;
+ }
+
+ command uint8_t Cdar.byteLength() {
+ return 1;
+ }
+
+ //FN cddr: l -> x. cdr(cdr(l))
+ command result_t Cddr.execute(uint8_t instr, MateContext* context) {
+ mvalue l = call S.pop(context, 1);
+
+ CDR(l);
+ CDR(l);
+ PUSH(l);
+
+ return SUCCESS;
+ }
+
+ command uint8_t Cddr.byteLength() {
+ return 1;
+ }
+
+ //FN caaar: l -> x. car(car(car(l)))
+ command result_t Caaar.execute(uint8_t instr, MateContext* context) {
+ mvalue l = call S.pop(context, 1);
+
+ CAR(l);
+ CAR(l);
+ CAR(l);
+ PUSH(l);
+
+ return SUCCESS;
+ }
+
+ command uint8_t Caaar.byteLength() {
+ return 1;
+ }
+
+ //FN caadr: l -> x. car(car(cdr(l)))
+ command result_t Caadr.execute(uint8_t instr, MateContext* context) {
+ mvalue l = call S.pop(context, 1);
+
+ CDR(l);
+ CAR(l);
+ CAR(l);
+ PUSH(l);
+
+ return SUCCESS;
+ }
+
+ command uint8_t Caadr.byteLength() {
+ return 1;
+ }
+
+ //FN cadar: l -> x. car(cdr(car(l)))
+ command result_t Cadar.execute(uint8_t instr, MateContext* context) {
+ mvalue l = call S.pop(context, 1);
+
+ CAR(l);
+ CDR(l);
+ CAR(l);
+ PUSH(l);
+
+ return SUCCESS;
+ }
+
+ command uint8_t Cadar.byteLength() {
+ return 1;
+ }
+
+ //FN caddr: l -> x. car(cdr(cdr(l)))
+ command result_t Caddr.execute(uint8_t instr, MateContext* context) {
+ mvalue l = call S.pop(context, 1);
+
+ CDR(l);
+ CDR(l);
+ CAR(l);
+ PUSH(l);
+
+ return SUCCESS;
+ }
+
+ command uint8_t Caddr.byteLength() {
+ return 1;
+ }
+
+ //FN cdaar: l -> x. cdr(car(car(l)))
+ command result_t Cdaar.execute(uint8_t instr, MateContext* context) {
+ mvalue l = call S.pop(context, 1);
+
+ CAR(l);
+ CAR(l);
+ CDR(l);
+ PUSH(l);
+
+ return SUCCESS;
+ }
+
+ command uint8_t Cdaar.byteLength() {
+ return 1;
+ }
+
+ //FN cdadr: l -> x. cdr(car(cdr(l)))
+ command result_t Cdaar.execute(uint8_t instr, MateContext* context) {
+ mvalue l = call S.pop(context, 1);
+
+ CDR(l);
+ CAR(l);
+ CDR(l);
+ PUSH(l);
+
+ return SUCCESS;
+ }
+
+ command uint8_t Cdadr.byteLength() {
+ return 1;
+ }
+
+ //FN cddar: l -> x. cdr(cdr(car(l)))
+ command result_t Cdaar.execute(uint8_t instr, MateContext* context) {
+ mvalue l = call S.pop(context, 1);
+
+ CAR(l);
+ CDR(l);
+ CDR(l);
+ PUSH(l);
+
+ return SUCCESS;
+ }
+
+ command uint8_t Cddar.byteLength() {
+ return 1;
+ }
+
+ //FN cdddr: l -> x. cdr(cdr(cdr(l)))
+ command result_t Cdaar.execute(uint8_t instr, MateContext* context) {
+ mvalue l = call S.pop(context, 1);
+
+ CDR(l);
+ CDR(l);
+ CDR(l);
+ PUSH(l);
+
+ return SUCCESS;
+ }
+
+ command uint8_t Cdddr.byteLength() {
+ return 1;
+ }
+
}
- Previous message: [Tinyos-commits] CVS: tinyos-1.x/tos/lib/VM/languages/motlle/mate
OPmframe.nc, NONE, 1.1 MOPcallM.nc, 1.2, 1.3 Memory.nc, 1.2,
1.3 MemoryM.nc, 1.2, 1.3 MotlleFrame.nc, 1.2,
1.3 MotlleObjectsM.nc, 1.3, 1.4 MotlleStack.nc, 1.2,
1.3 MotlleTypes.nc, 1.3, 1.4 MotlleValues.nc, 1.2,
1.3 motlle.ldf, 1.2, 1.3
- Next message: [Tinyos-commits] CVS: tinyos-1.x/tos/lib/VM/languages/motlle/mate
MotlleObjectsM.nc, 1.4, 1.5
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the Tinyos-commits
mailing list