summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2011-12-14 17:14:29 -0800
committerKaz Kylheku <kaz@kylheku.com>2011-12-14 17:14:29 -0800
commit93e4c50d09dcc20d7b244b66987f869143d45dd0 (patch)
tree83a176f4793df2dbfcf195b0649290cf8b3986c2
parent311294aef85c349ee71c3925a52d0888073a1fa0 (diff)
downloadtxr-93e4c50d09dcc20d7b244b66987f869143d45dd0.tar.gz
txr-93e4c50d09dcc20d7b244b66987f869143d45dd0.tar.bz2
txr-93e4c50d09dcc20d7b244b66987f869143d45dd0.zip
* eval.c (eval_init): Removed registration for vec_get_fil.
Renamed vec_set_fill to vec-set-length. * hash.c (equal_hash): vec_fill to vec_length name change. (hash_grow, make_hash): No need to call vec_set_length. * lib.c (equal, vecref, vec_push, length_vec, list_vector, obj_print, obj_pprint): vec_fill to vec_length name change. (vector): Argument now represents actual length, not just allocated size. (vec_get_fill): Function removed; did exactly the same thing as length_vec. (vec_set_fill): Function renamed to vec_set_length. (vector_list): Allocate a 0 length vector initially. * lib.h (enum vecindex): member changes name from vec_fill to vec_length. (vector): Parameter name changed. (vec_set_fill): Redeclared. (vec_get_fill): Declaration removed. * txr.1: Doc stubs updated.
-rw-r--r--ChangeLog25
-rw-r--r--eval.c3
-rw-r--r--hash.c10
-rw-r--r--lib.c73
-rw-r--r--lib.h7
-rw-r--r--txr.14
6 files changed, 68 insertions, 54 deletions
diff --git a/ChangeLog b/ChangeLog
index 1dfaffb5..6acad037 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,30 @@
2011-12-14 Kaz Kylheku <kaz@kylheku.com>
+ * eval.c (eval_init): Removed registration for vec_get_fil.
+ Renamed vec_set_fill to vec-set-length.
+
+ * hash.c (equal_hash): vec_fill to vec_length name change.
+ (hash_grow, make_hash): No need to call vec_set_length.
+
+ * lib.c (equal, vecref, vec_push, length_vec, list_vector,
+ obj_print, obj_pprint): vec_fill to vec_length name change.
+ (vector): Argument now represents actual length, not just allocated
+ size.
+ (vec_get_fill): Function removed; did exactly the same thing
+ as length_vec.
+ (vec_set_fill): Function renamed to vec_set_length.
+ (vector_list): Allocate a 0 length vector initially.
+
+ * lib.h (enum vecindex): member changes name from vec_fill
+ to vec_length.
+ (vector): Parameter name changed.
+ (vec_set_fill): Redeclared.
+ (vec_get_fill): Declaration removed.
+
+ * txr.1: Doc stubs updated.
+
+2011-12-14 Kaz Kylheku <kaz@kylheku.com>
+
* lib.c (car, cdr): Semantics fix for lazy conses.
Ignore the return value of the lazy cons function: do not
return nil if the function returns nil.
diff --git a/eval.c b/eval.c
index e4931400..d8755fa4 100644
--- a/eval.c
+++ b/eval.c
@@ -1280,8 +1280,7 @@ void eval_init(void)
reg_fun(intern(lit("break-str"), user_package), func_n2(break_str));
reg_fun(intern(lit("vector"), user_package), func_n1(vector));
- reg_fun(intern(lit("vec-get-fill"), user_package), func_n1(vec_get_fill));
- reg_fun(intern(lit("vec-set-fill"), user_package), func_n2(vec_set_fill));
+ reg_fun(intern(lit("vec-set-length"), user_package), func_n2(vec_set_length));
reg_fun(vecref_s, func_n2(vecref));
reg_fun(intern(lit("vec-push"), user_package), func_n2(vec_push));
reg_fun(intern(lit("length-vec"), user_package), func_n1(length_vec));
diff --git a/hash.c b/hash.c
index 892dfa5c..db7be842 100644
--- a/hash.c
+++ b/hash.c
@@ -117,9 +117,9 @@ static cnum equal_hash(val obj)
return ((cnum) obj->f.f.interp_fun + equal_hash(obj->f.env)) & NUM_MAX;
case VEC:
{
- val fill = obj->v.vec[vec_fill];
- cnum i, h = equal_hash(obj->v.vec[vec_fill]);
- cnum len = c_num(fill);
+ val length = obj->v.vec[vec_length];
+ cnum i, h = equal_hash(obj->v.vec[vec_length]);
+ cnum len = c_num(length);
for (i = 0; i < len; i++)
h = (h + equal_hash(obj->v.vec[i])) & NUM_MAX;
@@ -228,8 +228,6 @@ static void hash_grow(struct hash *h)
bug_unless (new_modulus > h->modulus);
- vec_set_fill(new_table, num(new_modulus));
-
for (i = 0; i < h->modulus; i++) {
val conses = *vecref_l(h->table, num(i));
@@ -256,8 +254,6 @@ val make_hash(val weak_keys, val weak_vals, val equal_based)
val table = vector(mod);
val hash = cobj((mem_t *) h, hash_s, &hash_ops);
- vec_set_fill(table, mod);
-
h->flags = (hash_flags_t) flags;
h->modulus = c_num(mod);
h->count = 0;
diff --git a/lib.c b/lib.c
index 575465e7..ac21e04d 100644
--- a/lib.c
+++ b/lib.c
@@ -578,11 +578,11 @@ val equal(val left, val right)
return nil;
case VEC:
if (type(right) == VEC) {
- cnum i, fill;
- if (!equal(left->v.vec[vec_fill], right->v.vec[vec_fill]))
+ cnum i, length;
+ if (!equal(left->v.vec[vec_length], right->v.vec[vec_length]))
return nil;
- fill = c_num(left->v.vec[vec_fill]);
- for (i = 0; i < fill; i++) {
+ length = c_num(left->v.vec[vec_length]);
+ for (i = 0; i < length; i++) {
if (!equal(left->v.vec[i], right->v.vec[i]))
return nil;
}
@@ -2279,9 +2279,10 @@ val orf(val first_fun, ...)
return func_f1(out, do_or);
}
-val vector(val alloc)
+val vector(val length)
{
- cnum alloc_plus = c_num(alloc) + 2;
+ int i;
+ cnum alloc_plus = c_num(length) + 2;
val vec = make_obj();
val *v = (val *) chk_malloc(alloc_plus * sizeof *v);
#ifdef HAVE_VALGRIND
@@ -2290,30 +2291,26 @@ val vector(val alloc)
v += 2;
vec->v.type = VEC;
vec->v.vec = v;
- v[vec_alloc] = alloc;
- v[vec_fill] = zero;
+ v[vec_alloc] = length;
+ v[vec_length] = length;
+ for (i = 0; i < alloc_plus - 2; i++)
+ vec->v.vec[i] = nil;
return vec;
}
-val vec_get_fill(val vec)
-{
- type_check(vec, VEC);
- return vec->v.vec[vec_fill];
-}
-
-val vec_set_fill(val vec, val fill)
+val vec_set_length(val vec, val length)
{
type_check(vec, VEC);
{
- cnum new_fill = c_num(fill);
- cnum old_fill = c_num(vec->v.vec[vec_fill]);
+ cnum new_length = c_num(length);
+ cnum old_length = c_num(vec->v.vec[vec_length]);
cnum old_alloc = c_num(vec->v.vec[vec_alloc]);
- cnum fill_delta = new_fill - old_fill;
- cnum alloc_delta = new_fill - old_alloc;
+ cnum length_delta = new_length - old_length;
+ cnum alloc_delta = new_length - old_alloc;
if (alloc_delta > 0) {
- cnum new_alloc = max(new_fill, 2*old_alloc);
+ cnum new_alloc = max(new_length, 2*old_alloc);
val *newvec = (val *) chk_realloc((mem_t *) (vec->v.vec - 2),
(new_alloc + 2) * sizeof *newvec);
vec->v.vec = newvec + 2;
@@ -2323,13 +2320,13 @@ val vec_set_fill(val vec, val fill)
#endif
}
- if (fill_delta > 0) {
+ if (length_delta > 0) {
cnum i;
- for (i = old_fill; i < new_fill; i++)
+ for (i = old_length; i < new_length; i++)
vec->v.vec[i] = nil;
}
- vec->v.vec[vec_fill] = fill;
+ vec->v.vec[vec_length] = length;
}
return vec;
@@ -2338,29 +2335,29 @@ val vec_set_fill(val vec, val fill)
val vecref(val vec, val ind)
{
type_check(vec, VEC);
- range_bug_unless (c_num(ind) < c_num(vec->v.vec[vec_fill]));
+ range_bug_unless (c_num(ind) < c_num(vec->v.vec[vec_length]));
return vec->v.vec[c_num(ind)];
}
val *vecref_l(val vec, val ind)
{
type_check(vec, VEC);
- range_bug_unless (c_num(ind) < c_num(vec->v.vec[vec_fill]));
+ range_bug_unless (c_num(ind) < c_num(vec->v.vec[vec_length]));
return vec->v.vec + c_num(ind);
}
val vec_push(val vec, val item)
{
- val fill = vec_get_fill(vec);
- vec_set_fill(vec, plus(fill, one));
- *vecref_l(vec, fill) = item;
- return fill;
+ val length = length_vec(vec);
+ vec_set_length(vec, plus(length, one));
+ *vecref_l(vec, length) = item;
+ return length;
}
val length_vec(val vec)
{
type_check(vec, VEC);
- return vec->v.vec[vec_fill];
+ return vec->v.vec[vec_length];
}
val size_vec(val vec)
@@ -2371,7 +2368,7 @@ val size_vec(val vec)
val vector_list(val list)
{
- val vec = vector(num(2));
+ val vec = vector(0);
if (!listp(list))
uw_throwf(error_s, lit("vector_list: list expected, not ~s"), list, nao);
@@ -2389,7 +2386,7 @@ val list_vector(val vec)
type_check(vec, VEC);
- len = c_num(vec->v.vec[vec_fill]);
+ len = c_num(vec->v.vec[vec_length]);
for (i = 0; i < len; i++)
list_collect(ptail, vec->v.vec[i]);
@@ -3236,11 +3233,11 @@ val obj_print(val obj, val out)
return obj;
case VEC:
{
- cnum i, fill = c_num(obj->v.vec[vec_fill]);
+ cnum i, length = c_num(obj->v.vec[vec_length]);
put_string(out, lit("#("));
- for (i = 0; i < fill; i++) {
+ for (i = 0; i < length; i++) {
obj_print(obj->v.vec[i], out);
- if (i < fill - 1)
+ if (i < length - 1)
put_char(out, chr(' '));
}
put_char(out, chr(')'));
@@ -3324,11 +3321,11 @@ val obj_pprint(val obj, val out)
return obj;
case VEC:
{
- cnum i, fill = c_num(obj->v.vec[vec_fill]);
+ cnum i, length = c_num(obj->v.vec[vec_length]);
put_string(out, lit("#("));
- for (i = 0; i < fill; i++) {
+ for (i = 0; i < length; i++) {
obj_pprint(obj->v.vec[i], out);
- if (i < fill - 1)
+ if (i < length - 1)
put_char(out, chr(' '));
}
put_char(out, chr(')'));
diff --git a/lib.h b/lib.h
index c4a0f72a..30fd35c1 100644
--- a/lib.h
+++ b/lib.h
@@ -118,7 +118,7 @@ struct func {
} f;
};
-enum vecindex { vec_alloc = -2, vec_fill = -1 };
+enum vecindex { vec_alloc = -2, vec_length = -1 };
struct vec {
type_t type;
@@ -491,9 +491,8 @@ val chain(val first_fun, ...);
val andf(val first_fun, ...);
val orf(val first_fun, ...);
val swap_12_21(val fun);
-val vector(val alloc);
-val vec_get_fill(val vec);
-val vec_set_fill(val vec, val fill);
+val vector(val length);
+val vec_set_length(val vec, val fill);
val vecref(val vec, val ind);
val *vecref_l(val vec, val ind);
val vec_push(val vec, val item);
diff --git a/txr.1 b/txr.1
index d9cf29c8..803f8cbb 100644
--- a/txr.1
+++ b/txr.1
@@ -5124,9 +5124,7 @@ The following are Lisp functions and variables built-in to TXR.
.SS Function vector
-.SS Function vec-get-fill
-
-.SS Function vec-set-fill
+.SS Function vec-set-length
.SS Function vecref