[Commit] nickle/builtin toplevel.c,1.16,1.17
Keith Packard
commit at keithp.com
Sun Jun 29 22:53:45 PDT 2003
- Previous message: [Commit] nickle array.c, 1.19, 1.20 execute.c, 1.81, 1.82 gram.y,
1.123, 1.124 main.c, 1.33, 1.34 nickle.h, 1.104, 1.105 sched.c,
1.52, 1.53 type.c, 1.54, 1.55 value.c, 1.42, 1.43 value.h,
1.87, 1.88
- Next message: [Commit] nickle-www stale-source.html, NONE, 1.1 index.html, 1.27,
1.28
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Committed by: keithp
Update of /local/src/CVS/nickle/builtin
In directory home.keithp.com:/tmp/cvs-serv6103/builtin
Modified Files:
toplevel.c
Log Message:
Tag arrays as resizable/fixed-size. Add setdims and setdim builtins
Index: toplevel.c
===================================================================
RCS file: /local/src/CVS/nickle/builtin/toplevel.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- toplevel.c 29 Jun 2003 22:31:22 -0000 1.16
+++ toplevel.c 30 Jun 2003 04:53:43 -0000 1.17
@@ -69,6 +69,8 @@
{ do_gcd, "gcd", "i", "ii" },
{ do_setjmp, "setjmp", "p", "*cp" },
{ do_xor, "xor", "i", "ii" },
+ { do_setdims, "setdims", "v", "ApAi" },
+ { do_setdim, "setdim", "v", "Api" },
{ 0 }
};
@@ -314,8 +316,9 @@
ENTER();
Value ret;
int i;
+ int ndim = av->array.ndim;
- ret = NewArray(True, typePrim[rep_int], 1, &av->array.ndim);
+ ret = NewArray(True, False, typePrim[rep_int], 1, &ndim);
for (i = 0; i < av->array.ndim; i++) {
Value d = NewInt(ArrayLimits(&av->array)[i]);
BoxValueSet(ret->array.values, i, d);
@@ -323,6 +326,60 @@
RETURN (ret);
}
+Value
+do_setdims (Value av, Value dv)
+{
+ ENTER ();
+ Array *a = &av->array;
+ Array *d = &dv->array;
+ BoxPtr db = d->values;
+#define DIM_LOCAL 32
+ int dimLocal[DIM_LOCAL];
+ int *dims = a->ndim < DIM_LOCAL ? dimLocal : AllocateTemp (a->ndim * sizeof (int));
+ int i;
+
+ if (a->ndim != db->nvalues)
+ {
+ RaiseStandardException (exception_invalid_argument,
+ "setdims: size of dimensions must match dimensionality of array",
+ 2, NewInt (a->ndim), dv);
+ RETURN (Void);
+ }
+ for (i = 0; i < a->ndim; i++)
+ {
+ dims[i] = IntPart (BoxValueGet (db,i), "setdims: invalid dimension");
+ if (aborting)
+ RETURN (Void);
+ if (dims[i] < 0)
+ {
+ RaiseStandardException (exception_invalid_argument,
+ "setdims: dimensions must be non-negative",
+ 2, NewInt (i), NewInt (dims[i]));
+ RETURN (Void);
+ }
+ }
+ ArraySetDimensions (av, dims);
+ RETURN (Void);
+}
+
+Value
+do_setdim (Value av, Value dv)
+{
+ ENTER ();
+ int d = IntPart (dv, "setdim: invalid dimension");
+ if (aborting)
+ RETURN (Void);
+ if (d < 0)
+ {
+ RaiseStandardException (exception_invalid_argument,
+ "setdim: dimension must be non-negative",
+ 2, NewInt (d), Void);
+ RETURN (Void);
+ }
+ ArrayResize (av, 0, d);
+ RETURN (Void);
+}
+
Value
do_reference (Value av)
{
- Previous message: [Commit] nickle array.c, 1.19, 1.20 execute.c, 1.81, 1.82 gram.y,
1.123, 1.124 main.c, 1.33, 1.34 nickle.h, 1.104, 1.105 sched.c,
1.52, 1.53 type.c, 1.54, 1.55 value.c, 1.42, 1.43 value.h,
1.87, 1.88
- Next message: [Commit] nickle-www stale-source.html, NONE, 1.1 index.html, 1.27,
1.28
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the Commit
mailing list