shithub: femtolisp

Download patch

ref: ca88d4dfc3831931281ca357af4413aa5385bd5d
parent: 0cbf98476b3fd0a1353c6383124578fc1fdac26b
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Wed Oct 30 21:08:43 EDT 2024

array-alloc: allow more FILL values to alternate between (if more than one)

--- a/cvalues.c
+++ b/cvalues.c
@@ -553,9 +553,10 @@
 BUILTIN("array-alloc", array_alloc)
 {
 	size_t elsize, sz;
-	long i, cnt;
+	long i, cnt, a;
 
-	argcount(nargs, 3);
+	if(nargs < 3)
+		argcount(nargs, 3);
 	cnt = toulong(args[1]);
 	if(cnt < 0)
 		lerrorf(ArgError, "invalid size: %d", cnt);
@@ -566,9 +567,12 @@
 
 	value_t cv = cvalue(type, sz);
 	char *dest = cv_data(ptr(cv));
+	a = 2;
 	for(i = 0; i < cnt; i++){
-		cvalue_init(type->eltype, args[2], dest);
+		cvalue_init(type->eltype, args[a], dest);
 		dest += elsize;
+		if((a = (a + 1) % nargs) == 0)
+			a = 2;
 	}
 	return cv;
 }