ref: 93f71e4a1522ecaa376f68958ff4024c9c2f3902
parent: ca88d4dfc3831931281ca357af4413aa5385bd5d
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Wed Oct 30 21:14:46 EDT 2024
vector-alloc: same as array-alloc - more FILL values
--- a/builtins.c
+++ b/builtins.c
@@ -276,17 +276,21 @@
BUILTIN("vector-alloc", vector_alloc)
{
- int i, k;
+ int i, k, a;
value_t f, v;
- if(nargs < 1 || nargs > 2)
+ if(nargs < 1)
argcount(nargs, 1);
i = toulong(args[0]);
if(i < 0)
lerrorf(ArgError, "invalid size: %d", i);
v = alloc_vector((unsigned)i, 0);
- f = nargs == 2 ? args[1] : FL_UNSPECIFIED;
- for(k = 0; k < i; k++)
+ a = 1;
+ for(k = 0; k < i; k++){
+ f = a < nargs ? args[a] : FL_UNSPECIFIED;
vector_elt(v, k) = f;
+ if((a = (a + 1) % nargs) < 1)
+ a = 1;
+ }
return v;
}
--- a/cvalues.c
+++ b/cvalues.c
@@ -571,7 +571,7 @@
for(i = 0; i < cnt; i++){
cvalue_init(type->eltype, args[a], dest);
dest += elsize;
- if((a = (a + 1) % nargs) == 0)
+ if((a = (a + 1) % nargs) < 2)
a = 2;
}
return cv;