[Commit] nickle ChangeLog, 1.31, 1.32 array.c, 1.23,
1.24 builtin-file.c, 1.14, 1.15 builtin-string.c, 1.7,
1.8 builtin-toplevel.c, 1.22, 1.23 builtin.5c, 1.5,
1.6 compile.c, 1.147, 1.148 execute.c, 1.88, 1.89 file.c, 1.60,
1.61 gram.y, 1.129, 1.130 hash.c, 1.6, 1.7 main.c, 1.36,
1.37 sched.c, 1.54, 1.55 scope.c, 1.28, 1.29 type.c, 1.61,
1.62 value.c, 1.45, 1.46 value.h, 1.100, 1.101
Keith Packard
commit at keithp.com
Thu Apr 15 22:26:48 PDT 2004
- Previous message: [Commit] nickle ChangeLog,1.30,1.31 lex.l,1.71,1.72
- Next message: [Commit] nickle ChangeLog, 1.32, 1.33 autogen.sh, 1.7,
1.8 configure.in, 1.31, 1.32 version.m4, 1.10, 1.11
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Committed by: keithp
Update of /local/src/CVS/nickle
In directory home.keithp.com:/tmp/cvs-serv8379
Modified Files:
ChangeLog array.c builtin-file.c builtin-string.c
builtin-toplevel.c builtin.5c compile.c execute.c file.c
gram.y hash.c main.c sched.c scope.c type.c value.c value.h
Log Message:
2004-04-15 Keith Packard <keithp at keithp.com>
* array.c: (ArrayEqual), (ArrayPrint), (ArrayHash), (ArrayMark),
(BoxVectorMark), (NewBoxVector), (FillBoxVector), (NewArray),
(ArrayResize):
* builtin-toplevel.c: (do_dims), (do_setdims):
* execute.c: (BuildFrame), (ThreadArrayInd),
(ThreadArrayReplicate), (ThreadArrayInit), (ThreadRaise),
(ThreadExceptionCall), (ThreadOpArray), (ThreadsRun):
* file.c: (FileFilter), (FileMakePipe):
* gram.y:
* hash.c: (HashKeys):
* main.c: (setArgv):
* sched.c: (RaiseException), (RaiseStandardException):
* scope.c: (NamespaceLocate):
* type.c: (TypeCompatibleAssign):
* value.c: (CopyMutable):
* value.h:
Change resizable array representation to be a vector
of single entry boxes. This allows clean semantics
for array shrinking -- outranged elements still have
storage, but are no longer accessible through the
array, even if the array is subsequently enlarged.
* builtin-file.c: (do_File_filter), (do_File_end),
(do_File_ungetb):
Change File::end semantic to actually peek at the file
and check whether the next read would return EOF.
This seems like the only useful semantic here.
* builtin-string.c: (do_String_new):
Was using ArrayDims instead of ArrayLimits
* builtin.5c:
white space change
* compile.c: (AppendObj):
Must propogate error when appending objects together
Index: ChangeLog
===================================================================
RCS file: /local/src/CVS/nickle/ChangeLog,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -d -r1.31 -r1.32
--- a/ChangeLog 16 Apr 2004 03:37:12 -0000 1.31
+++ b/ChangeLog 16 Apr 2004 05:26:44 -0000 1.32
@@ -1,3 +1,42 @@
+2004-04-15 Keith Packard <keithp at keithp.com>
+
+ * array.c: (ArrayEqual), (ArrayPrint), (ArrayHash), (ArrayMark),
+ (BoxVectorMark), (NewBoxVector), (FillBoxVector), (NewArray),
+ (ArrayResize):
+ * builtin-toplevel.c: (do_dims), (do_setdims):
+ * execute.c: (BuildFrame), (ThreadArrayInd),
+ (ThreadArrayReplicate), (ThreadArrayInit), (ThreadRaise),
+ (ThreadExceptionCall), (ThreadOpArray), (ThreadsRun):
+ * file.c: (FileFilter), (FileMakePipe):
+ * gram.y:
+ * hash.c: (HashKeys):
+ * main.c: (setArgv):
+ * sched.c: (RaiseException), (RaiseStandardException):
+ * scope.c: (NamespaceLocate):
+ * type.c: (TypeCompatibleAssign):
+ * value.c: (CopyMutable):
+ * value.h:
+ Change resizable array representation to be a vector
+ of single entry boxes. This allows clean semantics
+ for array shrinking -- outranged elements still have
+ storage, but are no longer accessible through the
+ array, even if the array is subsequently enlarged.
+
+ * builtin-file.c: (do_File_filter), (do_File_end),
+ (do_File_ungetb):
+ Change File::end semantic to actually peek at the file
+ and check whether the next read would return EOF.
+ This seems like the only useful semantic here.
+
+ * builtin-string.c: (do_String_new):
+ Was using ArrayDims instead of ArrayLimits
+
+ * builtin.5c:
+ white space change
+
+ * compile.c: (AppendObj):
+ Must propogate error when appending objects together
+
2004-04-15 Bart Massey <bart at cs.pdx.edu>
* lex.l:
Index: array.c
===================================================================
RCS file: /local/src/CVS/nickle/array.c,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -d -r1.23 -r1.24
--- a/array.c 11 Apr 2004 06:06:51 -0000 1.23
+++ b/array.c 16 Apr 2004 05:26:44 -0000 1.24
@@ -66,8 +66,8 @@
ai = 0; bi = 0;
while (ai < alimit && bi < blimit)
{
- if (False (Equal ( BoxValue (a->values, ai),
- BoxValue (b->values, bi))))
+ if (False (Equal ( ArrayValue (a, ai),
+ ArrayValue (b, bi))))
return FalseVal;
ai = ArrayNextI (a, ai);
bi = ArrayNextI (b, bi);
@@ -118,7 +118,7 @@
i = 0;
while (i < limit)
{
- if (!Print (f, BoxValueGet (a->values, i), format, base, width, prec, fill))
+ if (!Print (f, ArrayValueGet (a, i), format, base, width, prec, fill))
{
ret = False;
break;
@@ -165,7 +165,7 @@
int limit = ArrayLimit (av);
for (i = 0; i < limit; i = ArrayNextI (a, i))
- h = hrot(h) ^ ValueInt (ValueHash (BoxValueGet (a->values, i)));
+ h = hrot(h) ^ ValueInt (ValueHash (ArrayValueGet (a, i)));
return h;
}
@@ -174,7 +174,10 @@
{
Array *array = object;
- MemReference (array->values);
+ if (array->resizable)
+ MemReference (array->u.resize);
+ else
+ MemReference (array->u.fix);
}
ValueRep ArrayRep = {
@@ -202,6 +205,46 @@
ArrayHash,
};
+static void
+BoxVectorMark (void *object)
+{
+ BoxVectorPtr bv = object;
+ int i;
+ BoxPtr *boxes = BoxVectorBoxes (bv);
+
+ MemReference (bv->type);
+ for (i = 0; i < bv->nvalues; i++)
+ MemReference (boxes[i]);
+}
+
+DataType BoxVectorType = { BoxVectorMark, 0, "BoxVectorType" };
+
+static BoxVectorPtr
+NewBoxVector (int nvalues, TypePtr type)
+{
+ ENTER ();
+ BoxVectorPtr bv = ALLOCATE (&BoxVectorType,
+ sizeof (BoxVector) +
+ nvalues * sizeof (BoxPtr));
+ int i;
+ BoxPtr *boxes = BoxVectorBoxes (bv);
+
+ bv->nvalues = nvalues;
+ bv->type = type;
+ for (i = 0; i < nvalues; i++)
+ boxes[i] = 0;
+ RETURN (bv);
+}
+
+static void
+FillBoxVector (BoxVectorPtr bv, BoxPtr *boxes, int n)
+{
+ ENTER();
+ while (n--)
+ *boxes++ = NewBox (False, False, 1, bv->type);
+ EXIT ();
+}
+
Value
NewArray (Bool constant, Bool resizable, TypePtr type, int ndim, int *dims)
{
@@ -220,67 +263,86 @@
ents = 0;
ret = ALLOCATE (&ArrayRep.data, sizeof (Array) + (ndim * 2) * sizeof (int));
ret->array.ndim = ndim;
- ret->array.resizable = resizable;
- ret->array.values = 0;
- ret->array.values = NewBox (constant, True, ents, type);
for (dim = 0; dim < ndim; dim++)
ArrayLimits(&ret->array)[dim] = ArrayDims(&ret->array)[dim] = dims[dim];
+ ret->array.resizable = resizable;
+ if (resizable)
+ {
+ ret->array.u.resize = 0;
+ ret->array.u.resize = NewBoxVector (ents, type);
+ FillBoxVector (ret->array.u.resize,
+ BoxVectorBoxes (ret->array.u.resize),
+ ents);
+ }
+ else
+ {
+ ret->array.u.fix = 0;
+ ret->array.u.fix = NewBox (constant, True, ents, type);
+ }
RETURN (ret);
}
void
ArrayResize (Value av, int dim, int size)
{
- Array *a = &av->array;
- int *dims = ArrayDims(a);
- int *limits = ArrayLimits(a);
+ ENTER ();
+ Array *a = &av->array;
+ int *dims = ArrayDims(a);
+ int *limits = ArrayLimits(a);
+ int odim = dims[dim];
+ int ents;
+ int d;
+ int stride; /* size of each chunk */
+ int nchunk; /* number of chunks */
+ int c;
+ int unit;
+ int good;
+ BoxPtr *b;
assert (av->array.resizable);
+
+ if (size == limits[dim])
+ return;
+
+ ents = a->u.resize->nvalues;
+
+ stride = 1;
+ for (d = 0; d <= dim; d++)
+ stride *= dims[d];
+ if (stride)
+ nchunk = ents / stride;
+ else
+ nchunk = 1;
+
+ /*
+ * Resize if necessary.
+ */
if (dims[dim] < size || dims[dim] > size * 2)
{
- ENTER ();
- BoxPtr obox = a->values;
- BoxPtr nbox;
- int odim = dims[dim];
- int ents = obox->nvalues;
- int chunk_size;
- int chunk_ostride;
- int chunk_nstride;
- int chunk_zero;
- int d;
- int nchunk;
- Value *o, *n;
-
- if (!ents)
+ int ostride = stride;
+ int nstride = stride;
+ BoxVectorPtr nboxes;
+ BoxPtr *o, *n;
+
+ if (odim < size)
{
- chunk_ostride = 0;
- for (d = 0; d < a->ndim; d++)
+ /* was empty */
+ if (odim == 0)
{
- dims[d] = 1;
- limits[d] = 1;
+ odim = 1;
+ ents = 1;
+ nstride = 1;
+ for (d = 0; d < a->ndim; d++)
+ dims[d] = 1;
}
- odim = 1;
- ents = 1;
- nchunk = 1;
- }
- else
- {
- chunk_ostride = 1;
- for (d = 0; d <= dim; d++)
- chunk_ostride *= dims[d];
- nchunk = ents / chunk_ostride;
- }
- chunk_nstride = chunk_ostride;
- if (odim < size)
- {
/* bigger */
while (odim < size)
{
odim <<= 1;
ents <<= 1;
- chunk_nstride <<= 1;
+ nstride <<= 1;
}
- chunk_size = chunk_ostride;
+ good = ostride;
}
else if (size > 0)
{
@@ -289,40 +351,63 @@
{
odim >>= 1;
ents >>= 1;
- chunk_nstride >>= 1;
+ nstride >>= 1;
}
- chunk_size = chunk_nstride;
+ good = nstride;
}
else
{
/* empty */
ents = 0;
- chunk_nstride = 0;
- chunk_size = 0;
+ nstride = 0;
+ size = 0;
+ nchunk = 0;
for (d = 0; d < a->ndim; d++)
{
dims[d] = 0;
limits[d] = 0;
}
}
- nbox = NewBox (a->values->constant, True, ents, a->values->u.type);
- o = BoxElements (a->values);
- n = BoxElements (nbox);
- chunk_zero = chunk_nstride - chunk_size;
- while (nchunk--)
+
+ nboxes = NewBoxVector (ents, a->u.resize->type);
+ o = BoxVectorBoxes (a->u.resize);
+ n = BoxVectorBoxes (nboxes);
+ for (c = 0; c < nchunk; c++)
{
- memcpy (n, o, chunk_size * sizeof (Value));
- o += chunk_ostride;
- n += chunk_size;
- memset (n, '\0', chunk_zero * sizeof (Value));
- n += chunk_zero;
+ memcpy (n, o, good * sizeof (BoxPtr));
+ if (nstride > good)
+ FillBoxVector (nboxes, n + good, nstride - good);
+ o += ostride;
+ n += nstride;
}
- BoxSetReplace (a->values, nbox, chunk_ostride, chunk_nstride);
- a->values = nbox;
+ a->u.resize = nboxes;
dims[dim] = odim;
- EXIT ();
+ limits[dim] = size;
+ stride = nstride;
+ }
+ /*
+ * When shrinking the array, replace the
+ * now discarded entries with new boxes.
+ * This leaves growing trivial; all unused
+ * elements of the array have clean boxes
+ */
+ if (limits[dim] > size)
+ {
+ b = BoxVectorBoxes (a->u.resize);
+
+ unit = stride / dims[dim];
+ good = size * unit;
+
+ for (c = 0; c < nchunk; c++)
+ {
+ FillBoxVector (a->u.resize,
+ b + good,
+ stride - good);
+ b += stride;
+ }
}
limits[dim] = size;
+ EXIT ();
}
void
Index: builtin-file.c
===================================================================
RCS file: /local/src/CVS/nickle/builtin-file.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- a/builtin-file.c 27 Feb 2004 03:50:15 -0000 1.14
+++ b/builtin-file.c 16 Apr 2004 05:26:44 -0000 1.15
@@ -209,10 +209,10 @@
int err;
/* set up arguments */
- args = AllocateTemp ((ArrayDims(&argv->array)[0] + 1) * sizeof (char *));
- for (argc = 0; argc < ArrayDims(&argv->array)[0]; argc++)
+ args = AllocateTemp ((ArrayLimits(&argv->array)[0] + 1) * sizeof (char *));
+ for (argc = 0; argc < ArrayLimits(&argv->array)[0]; argc++)
{
- arg = BoxValue (argv->array.values, argc);
+ arg = ArrayValue (&argv->array, argc);
args[argc] = StringChars (&arg->string);
}
args[argc] = 0;
@@ -364,10 +364,21 @@
do_File_end (Value f)
{
ENTER ();
+
if (f->file.flags & FileEnd)
RETURN (TrueVal);
else
+ {
+ Value b = do_File_getb(f);
+
+ if (b == Void)
+ RETURN(Void);
+
+ do_File_ungetb (b, f);
+ if (f->file.flags & FileEnd)
+ RETURN (TrueVal);
RETURN (FalseVal);
+ }
}
Value
@@ -441,15 +452,10 @@
{
ENTER ();
- if (f->file.flags & FileOutputBlocked)
- ThreadSleep (running, f, PriorityIo);
- else
+ if (!aborting)
{
- if (!aborting)
- {
- complete = True;
- FileUnput (f, IntPart (v, "ungetb: non integer"));
- }
+ complete = True;
+ FileUnput (f, IntPart (v, "ungetb: non integer"));
}
RETURN (v);
}
Index: builtin-string.c
===================================================================
RCS file: /local/src/CVS/nickle/builtin-string.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- a/builtin-string.c 27 Feb 2004 03:50:15 -0000 1.7
+++ b/builtin-string.c 16 Apr 2004 05:26:44 -0000 1.8
@@ -66,16 +66,16 @@
if (ValueIsArray(av) && av->array.ndim == 1)
{
- len = ArrayDims(&av->array)[0];
+ len = ArrayLimits(&av->array)[0];
size = 0;
for (i = 0; i < len; i++)
- size += StringCharSize (IntPart (BoxValue (av->array.values, i),
+ size += StringCharSize (IntPart (ArrayValue (&av->array, i),
"new: array element not integer"));
ret = NewString (size);
s = StringChars (&ret->string);
for (i = 0; i < len; i++)
{
- s += StringPutChar (IntPart (BoxValue (av->array.values, i),
+ s += StringPutChar (IntPart (ArrayValue (&av->array, i),
"new: array element not integer"),
s);
}
Index: builtin-toplevel.c
===================================================================
RCS file: /local/src/CVS/nickle/builtin-toplevel.c,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -d -r1.22 -r1.23
--- a/builtin-toplevel.c 11 Apr 2004 06:27:11 -0000 1.22
+++ b/builtin-toplevel.c 16 Apr 2004 05:26:44 -0000 1.23
@@ -331,8 +331,8 @@
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);
+ Value d = NewInt(ArrayLimits(&av->array)[i]);
+ ArrayValueSet(&ret->array, i, d);
}
RETURN (ret);
}
@@ -343,13 +343,12 @@
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)
+ if (a->ndim != ArrayNvalues(d))
{
RaiseStandardException (exception_invalid_argument,
"setdims: size of dimensions must match dimensionality of array",
@@ -366,7 +365,7 @@
for (i = 0; i < a->ndim; i++)
{
int j = a->ndim - 1 - i;
- dims[j] = IntPart (BoxValueGet (db,i), "setdims: invalid dimension");
+ dims[j] = IntPart (ArrayValueGet (d,i), "setdims: invalid dimension");
if (aborting)
RETURN (Void);
if (dims[j] < 0)
Index: builtin.5c
===================================================================
RCS file: /local/src/CVS/nickle/builtin.5c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- a/builtin.5c 4 Dec 2003 07:04:18 -0000 1.5
+++ b/builtin.5c 16 Apr 2004 05:26:44 -0000 1.6
@@ -101,5 +101,5 @@
# parse the command line
extend namespace Command {
- argv = process_args (argv);
+ argv = process_args (argv);
}
Index: compile.c
===================================================================
RCS file: /local/src/CVS/nickle/compile.c,v
retrieving revision 1.147
retrieving revision 1.148
diff -u -d -r1.147 -r1.148
--- a/compile.c 11 Apr 2004 06:06:51 -0000 1.147
+++ b/compile.c 16 Apr 2004 05:26:44 -0000 1.148
@@ -140,6 +140,8 @@
firsti = ObjCode (first, ObjLast (first));
*firsti = *lasti;
}
+ if (last->error)
+ first->error = True;
return first;
}
Index: execute.c
===================================================================
RCS file: /local/src/CVS/nickle/execute.c,v
retrieving revision 1.88
retrieving revision 1.89
diff -u -d -r1.88 -r1.89
--- a/execute.c 11 Apr 2004 06:06:51 -0000 1.88
+++ b/execute.c 16 Apr 2004 05:26:45 -0000 1.89
@@ -60,7 +60,7 @@
array = NewArray (True, False, typePoly, 1, &extra);
BoxValueSet (frame->frame, fe, array);
for (; fe < argc; fe++)
- BoxValueSet (array->array.values, fe-nformal, Copy (Arg(fe)));
+ ArrayValueSet (&array->array, fe-nformal, Copy (Arg(fe)));
}
if (tail)
{
@@ -334,13 +334,13 @@
ENTER ();
Array *a = &dim->array;
int i;
- int ndim = ArrayDims(a)[0];
+ int ndim = ArrayLimits(a)[0];
int *dims;
dims = AllocateTemp (ndim * sizeof (int));
for (i = 0; i < ndim; i++)
{
- dims[i] = IntPart (BoxValueGet(a->values, i), "Invalid array dimension");
+ dims[i] = IntPart (ArrayValueGet(a, i), "Invalid array dimension");
if (aborting)
RETURN (0);
}
@@ -426,11 +426,12 @@
int total;
Value *elements;
+ assert (!array->array.resizable);
for (i = 0; i < dim; i++)
dimsize *= ArrayDims(&array->array)[i];
start = start - dimsize;
total = ArrayDims(&array->array)[dim] * dimsize;
- elements = BoxElements (array->array.values);
+ elements = BoxElements (array->array.u.fix);
for (i = start + dimsize; i % total; i += dimsize)
memmove (elements + i, elements + start,
dimsize * sizeof (elements[0]));
@@ -492,7 +493,7 @@
if (aborting)
break;
complete=True;
- BoxValueSet (array->array.values, i, Copy (value));
+ ArrayValueSet (&array->array, i, Copy (value));
}
complete = True;
/*
@@ -595,7 +596,7 @@
*/
args = NewArray (False, False, typePoly, 1, &argc);
for (i = 0; i < argc; i++)
- BoxValueSet (args->array.values, i, Arg(i));
+ ArrayValueSet (&args->array, i, Arg(i));
if (!aborting)
{
RaiseException (thread, exception, args, next);
@@ -636,12 +637,12 @@
RETURN (Void);
}
complete = True;
- argc = args->array.values->nvalues;
+ argc = ArrayLimits(&args->array)[0];
for (i = 0; i < argc; i++)
{
STACK_PUSH (thread->thread.continuation.stack,
thread->thread.continuation.value);
- thread->thread.continuation.value = BoxValue(args->array.values, i);
+ thread->thread.continuation.value = ArrayValue(&args->array, i);
}
/*
* Call the function
@@ -777,12 +778,14 @@
i = ThreadArrayIndex (v, thread, stack, value, 0, True, !fetch);
if (!aborting)
{
+ BoxPtr box = ArrayValueBox (&v->array, i);
+ int elt = ArrayValueElt (&v->array, i);
if (typeCheck)
- ThreadBoxCheck (v->array.values, i);
+ ThreadBoxCheck (box, elt);
if (fetch)
- value = BoxValue (v->array.values, i);
+ value = BoxValue (box, elt);
else
- value = NewRef (v->array.values, i);
+ value = NewRef (box, elt);
}
break;
case rep_hash:
@@ -1190,19 +1193,19 @@
1, value);
break;
}
- for (i = 0; i < ArrayDims(&value->array)[0]; i++)
+ for (i = 0; i < ArrayLimits(&value->array)[0]; i++)
{
- STACK_PUSH (cstack, BoxValue (value->array.values, i));
+ STACK_PUSH (cstack, ArrayValue (&value->array, i));
if (aborting)
{
STACK_DROP (cstack, i + 1);
break;
}
}
- if (i != ArrayDims(&value->array)[0])
+ if (i != ArrayLimits(&value->array)[0])
break;
complete = True;
- value = NewInt (ArrayDims(&value->array)[0]);
+ value = NewInt (ArrayLimits(&value->array)[0]);
break;
case OpCall:
case OpTailCall:
Index: file.c
===================================================================
RCS file: /local/src/CVS/nickle/file.c,v
retrieving revision 1.60
retrieving revision 1.61
diff -u -d -r1.60 -r1.61
--- a/file.c 11 Apr 2004 06:06:52 -0000 1.60
+++ b/file.c 16 Apr 2004 05:26:45 -0000 1.61
@@ -778,7 +778,7 @@
/* set up process files */
for (i = 0; i < 3; i++) {
- Value f = BoxValue (filev->array.values, i);
+ Value f = ArrayValue (&filev->array, i);
if (i == 0 && !(f->file.flags & FileReadable)) {
RaiseStandardException (exception_invalid_argument,
"File::filter: process input not readable",
@@ -835,7 +835,7 @@
RETURN(0);
}
for (i = 0; i < 3; i++) {
- Value f = BoxValue (filev->array.values, i);
+ Value f = ArrayValue (&filev->array, i);
if (f->file.flags & FilePipe)
f->file.pid = pid;
}
@@ -859,10 +859,10 @@
files = NewArray (False, False, typePrim[rep_file], 1, &two);
file = FileCreate (fds[0], FileReadable);
file->file.flags |= FilePipe;
- BoxValueSet (files->array.values, 0, file);
+ ArrayValueSet (&files->array, 0, file);
file = FileCreate (fds[1], FileWritable);
file->file.flags |= FilePipe;
- BoxValueSet (files->array.values, 1, file);
+ ArrayValueSet (&files->array, 1, file);
RETURN (files);
}
Index: gram.y
===================================================================
RCS file: /local/src/CVS/nickle/gram.y,v
retrieving revision 1.129
retrieving revision 1.130
diff -u -d -r1.129 -r1.130
--- a/gram.y 11 Apr 2004 06:06:52 -0000 1.129
+++ b/gram.y 16 Apr 2004 05:26:45 -0000 1.130
@@ -1664,11 +1664,11 @@
len++;
array = NewArray (False, False, typePrim[rep_string], 1, &len);
len--;
- BoxValueSet (array->array.values, len, AtomString (name));
+ ArrayValueSet (&array->array, len, AtomString (name));
e = colonnames;
while (--len >= 0)
{
- BoxValueSet (array->array.values, len, AtomString (e->tree.right->atom.atom));
+ ArrayValueSet (&array->array, len, AtomString (e->tree.right->atom.atom));
e = e->tree.left;
}
e = NewExprConst (POLY_CONST, array);
Index: hash.c
===================================================================
RCS file: /local/src/CVS/nickle/hash.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- a/hash.c 15 Apr 2004 05:37:36 -0000 1.6
+++ b/hash.c 16 Apr 2004 05:26:45 -0000 1.7
@@ -427,7 +427,7 @@
{
if (HashEltValid (e))
{
- BoxValueSet (keys->array.values, i, HashEltKey (e));
+ ArrayValueSet (&keys->array, i, HashEltKey (e));
i++;
}
HashEltStep (e);
Index: main.c
===================================================================
RCS file: /local/src/CVS/nickle/main.c,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -d -r1.36 -r1.37
--- a/main.c 11 Apr 2004 06:06:52 -0000 1.36
+++ b/main.c 16 Apr 2004 05:26:45 -0000 1.37
@@ -31,7 +31,7 @@
args = NewArray (True, True, typePrim[rep_string], 1, &argc);
for (i = 0; i < argc; i++)
- BoxValueSet (args->array.values, i, NewStrString (argv[i]));
+ ArrayValueSet (&args->array, i, NewStrString (argv[i]));
setVar (GlobalNamespace, "argv", args,
NewTypeArray (typePrim[rep_string],
NewExprTree (COMMA, 0, 0), False));
Index: sched.c
===================================================================
RCS file: /local/src/CVS/nickle/sched.c,v
retrieving revision 1.54
retrieving revision 1.55
diff -u -d -r1.54 -r1.55
--- a/sched.c 27 Feb 2004 03:50:16 -0000 1.54
+++ b/sched.c 16 Apr 2004 05:26:45 -0000 1.55
@@ -1069,11 +1069,11 @@
PrintError ("Unhandled exception %A (", except->symbol.name);
if (args)
{
- BoxPtr values = args->array.values;
- for (i = 0; i < values->nvalues; i++)
+ int dim = ArrayLimits(&args->array)[0];
+ for (i = 0; i < dim; i++)
{
- PrintError ("%v", BoxValueGet (values, i));
- if (i < values->nvalues - 1)
+ PrintError ("%v", ArrayValueGet (&args->array, i));
+ if (i < dim - 1)
PrintError (", ");
}
}
@@ -1135,10 +1135,10 @@
va_start (va, argc);
i = argc + 1;
args = NewArray (False, False, typePoly, 1, &i);
- BoxValueSet (args->array.values, 0, NewStrString (string));
+ ArrayValueSet (&args->array, 0, NewStrString (string));
if (argc)
for (i = 0; i < argc; i++)
- BoxValueSet (args->array.values, i + 1, va_arg (va, Value));
+ ArrayValueSet (&args->array, i + 1, va_arg (va, Value));
standardException = se;
standardExceptionArgs = args;
SetSignalException ();
Index: scope.c
===================================================================
RCS file: /local/src/CVS/nickle/scope.c,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -d -r1.28 -r1.29
--- a/scope.c 27 Feb 2004 03:50:16 -0000 1.28
+++ b/scope.c 16 Apr 2004 05:26:45 -0000 1.29
@@ -243,7 +243,7 @@
GetNamespace (&namespace, &f);
for (i = 0; i < ArrayLimits(&names->array)[0]; i++)
{
- string = BoxValue (names->array.values, i);
+ string = ArrayValue (&names->array, i);
if (aborting)
return False;
if (!ValueIsString(string))
Index: type.c
===================================================================
RCS file: /local/src/CVS/nickle/type.c,v
retrieving revision 1.61
retrieving revision 1.62
diff -u -d -r1.61 -r1.62
--- a/type.c 11 Apr 2004 06:06:52 -0000 1.61
+++ b/type.c 16 Apr 2004 05:26:45 -0000 1.62
@@ -1099,15 +1099,16 @@
if (TypePoly (ArrayType(&b->array)))
{
int i;
- BoxPtr box = b->array.values;
- for (i = 0; i < box->nvalues; i++)
- if (BoxValueGet (box, i) &&
- !TypeCompatibleAssign (a->array.type,
- BoxValueGet (box, i)))
+ for (i = 0; i < ArrayNvalues(&b->array); i++)
+ {
+ Value v = ArrayValueGet (&b->array, i);
+ if (v &&
+ !TypeCompatibleAssign (a->array.type, v))
{
return False;
}
+ }
return True;
}
else
Index: value.c
===================================================================
RCS file: /local/src/CVS/nickle/value.c,v
retrieving revision 1.45
retrieving revision 1.46
diff -u -d -r1.45 -r1.46
--- a/value.c 27 Feb 2004 03:50:16 -0000 1.45
+++ b/value.c 16 Apr 2004 05:26:45 -0000 1.46
@@ -577,18 +577,35 @@
int i;
BoxPtr box, nbox;
int n;
-
+
switch (ValueTag(v)) {
case rep_array:
- if (v->array.values->constant)
+ if (!v->array.resizable && ArrayValueBox(&v->array,0)->constant)
RETURN (v);
nv = NewArray (False, v->array.resizable, ArrayType(&v->array),
v->array.ndim, ArrayDims(&v->array));
for (i = 0; i < v->array.ndim; i++)
ArrayLimits(&nv->array)[i] = ArrayLimits(&v->array)[i];
- box = v->array.values;
- nbox = nv->array.values;
- n = box->nvalues;
+ if (v->array.resizable)
+ {
+ BoxPtr *o, *n;
+ int l = ArrayNvalues (&v->array);
+ o = BoxVectorBoxes (v->array.u.resize);
+ n = BoxVectorBoxes (nv->array.u.resize);
+ for (i = 0; i < l; i++)
+ {
+ BoxValueSet (*n, 0, Copy (BoxValueGet (*o, 0)));
+ n++;
+ o++;
+ }
+ RETURN(nv);
+ }
+ else
+ {
+ box = v->array.u.fix;
+ nbox = nv->array.u.fix;
+ n = ArrayNvalues (&v->array);
+ }
break;
case rep_struct:
if (v->structs.values->constant)
Index: value.h
===================================================================
RCS file: /local/src/CVS/nickle/value.h,v
retrieving revision 1.100
retrieving revision 1.101
diff -u -d -r1.100 -r1.101
--- a/value.h 11 Apr 2004 06:06:52 -0000 1.100
+++ b/value.h 16 Apr 2004 05:26:45 -0000 1.101
@@ -556,16 +556,40 @@
#define StringChars(s) ((char *) ((s) + 1))
+/*
+ * Resizable arrays are actually vectors of single entry
+ * boxes. Otherwise shrinking the array leaves old references
+ * dangling.
+ */
+
+typedef struct _boxVector {
+ DataType *data;
+ int nvalues;
+ TypePtr type;
+} BoxVector, *BoxVectorPtr;
+
+#define BoxVectorBoxes(v) ((BoxPtr *) ((v) + 1))
+
typedef struct _array {
BaseValue base;
unsigned int resizable : 1;
unsigned int ndim : (sizeof (int) * 8 - 1);
- BoxPtr values;
+ union {
+ BoxPtr fix;
+ BoxVectorPtr resize;
+ } u;
} Array;
#define ArrayDims(a) ((int *) ((a) + 1))
#define ArrayLimits(a) (ArrayDims(a) + (a)->ndim)
-#define ArrayType(a) ((a)->values->u.type)
+#define ArrayConstant
+#define ArrayNvalues(a) ((a)->resizable ? (a)->u.resize->nvalues : (a)->u.fix->nvalues)
+#define ArrayValueBox(a,i) ((a)->resizable ? BoxVectorBoxes((a)->u.resize)[i] : (a)->u.fix)
+#define ArrayValueElt(a,i) ((a)->resizable ? 0 : (i))
+#define ArrayType(a) ((a)->resizable ? (a)->u.resize->type : (a)->u.fix->u.type)
+#define ArrayValue(a,i) (BoxValue(ArrayValueBox(a,i),ArrayValueElt(a,i)))
+#define ArrayValueGet(a,i) (BoxValueGet(ArrayValueBox(a,i),ArrayValueElt(a,i)))
+#define ArrayValueSet(a,i,v) (BoxValueSet(ArrayValueBox(a,i),ArrayValueElt(a,i), v))
typedef struct _io_chain {
DataType *data;
- Previous message: [Commit] nickle ChangeLog,1.30,1.31 lex.l,1.71,1.72
- Next message: [Commit] nickle ChangeLog, 1.32, 1.33 autogen.sh, 1.7,
1.8 configure.in, 1.31, 1.32 version.m4, 1.10, 1.11
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the Commit
mailing list