shithub: sl

Download patch

ref: 51146831c5e7c6a3ba83620d1a00c0b3da28b414
parent: 9ceaddc0e5d8146dabfe56aea3acd54bf7e25ea3
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Wed Feb 5 18:28:43 EST 2025

a bit of cvalues move and rename

--- a/src/cvalues.c
+++ b/src/cvalues.c
@@ -5,6 +5,18 @@
 #include "iostream.h"
 #include "equal.h"
 
+enum {
+	MAX_INL_SIZE = 384,
+	CVALUE_NWORDS = 4,
+
+	CV_OWNED = 1<<0,
+	CV_PARENT = 1<<1,
+};
+
+#define owned(cv) ((uintptr_t)(cv)->type & CV_OWNED)
+#define hasparent(cv) ((uintptr_t)(cv)->type & CV_PARENT)
+#define isinlined(cv) ((cv)->data == &(cv)->_space[0])
+
 static void cvalue_init(fltype_t *type, value_t v, void *dest);
 
 void
@@ -71,7 +83,7 @@
 void
 cv_autorelease(cvalue_t *cv)
 {
-	cv->type = (fltype_t*)(((uintptr_t)cv->type) | CV_OWNED_BIT);
+	cv->type = (fltype_t*)(((uintptr_t)cv->type) | CV_OWNED);
 	add_finalizer(cv);
 }
 
@@ -143,7 +155,7 @@
 	pcv->len = sz;
 	pcv->type = type;
 	if(parent != FL_nil){
-		pcv->type = (fltype_t*)(((uintptr_t)pcv->type) | CV_PARENT_BIT);
+		pcv->type = (fltype_t*)(((uintptr_t)pcv->type) | CV_PARENT);
 		pcv->parent = parent;
 	}
 	cv = tagptr(pcv, TAG_CVALUE);
@@ -180,7 +192,7 @@
 	return string_from_cstrn(str, strlen(str));
 }
 
-int
+bool
 fl_isstring(value_t v)
 {
 	return iscvalue(v) && cv_isstr(ptr(v));
@@ -360,7 +372,7 @@
 	type_error("number", n);
 }
 
-int
+bool
 isarray(value_t v)
 {
 	return iscvalue(v) && cv_class(ptr(v))->eltype != nil;
@@ -634,7 +646,7 @@
 		memcpy(ncv->data, cv_data(cv), len);
 		cv_autorelease(ncv);
 		if(hasparent(cv)){
-			ncv->type = (fltype_t*)(((uintptr_t)ncv->type) & ~CV_PARENT_BIT);
+			ncv->type = (fltype_t*)(((uintptr_t)ncv->type) & ~CV_PARENT);
 			ncv->parent = FL_nil;
 		}
 	}else{
@@ -938,7 +950,7 @@
 	type_error("number", n);
 }
 
-int
+bool
 num_to_ptr(value_t a, fixnum_t *pi, numerictype_t *pt, void **pp)
 {
 	cprim_t *cp;
@@ -947,12 +959,12 @@
 		*pi = numval(a);
 		*pp = pi;
 		*pt = T_FIXNUM;
-		return 1;
+		return true;
 	}else if(iscprim(a)){
 		cp = ptr(a);
 		*pp = cp_data(cp);
 		*pt = cp_numtype(cp);
-		return 1;
+		return true;
 	}else if(iscvalue(a)){
 		cv = ptr(a);
 		*pp = cv_data(cv);
@@ -959,7 +971,7 @@
 		*pt = cv_class(cv)->numtype;
 		return valid_numtype(*pt);
 	}
-	return 0;
+	return false;
 }
 
 /*
@@ -1006,7 +1018,7 @@
 }
 
 _Noreturn void
-DivideByZeroError(void)
+divide_by_0_error(void)
 {
 	lerrorf(FL_DivideError, "/: division by zero");
 }
@@ -1028,7 +1040,7 @@
 	db = conv_to_double(bptr, tb);
 
 	if(db == 0 && tb < T_FLOAT)  // exact 0
-		DivideByZeroError();
+		divide_by_0_error();
 
 	da = da/db;
 
@@ -1094,8 +1106,8 @@
 		goto div_error;
 
 	return return_from_int64(conv_to_int64(aptr, ta) / b64);
- div_error:
-	DivideByZeroError();
+div_error:
+	divide_by_0_error();
 }
 
 static value_t
--- a/src/cvalues.h
+++ b/src/cvalues.h
@@ -5,13 +5,6 @@
 #else
 #define NWORDS(sz) (((sz)+3)>>2)
 #endif
-#define CVALUE_NWORDS 4
-#define MAX_INL_SIZE 384
-#define CV_OWNED_BIT  0x1
-#define CV_PARENT_BIT 0x2
-#define owned(cv) ((uintptr_t)(cv)->type & CV_OWNED_BIT)
-#define hasparent(cv) ((uintptr_t)(cv)->type & CV_PARENT_BIT)
-#define isinlined(cv) ((cv)->data == &(cv)->_space[0])
 
 void add_finalizer(cvalue_t *cv);
 void sweep_finalizers(void);
@@ -24,13 +17,13 @@
 value_t cvalue_static_cstring(const char *str);
 value_t string_from_cstrn(char *str, size_t n);
 value_t string_from_cstr(char *str);
-int fl_isstring(value_t v) fl_purefn;
+bool fl_isstring(value_t v) fl_purefn;
 void cv_pin(cvalue_t *cv);
 value_t mk_mpint(mpint *n);
 value_t size_wrap(size_t sz);
 size_t tosize(value_t n);
 off_t tooffset(value_t n);
-int isarray(value_t v) fl_purefn;
+bool isarray(value_t v) fl_purefn;
 int cvalue_array_init(fltype_t *ft, value_t arg, void *dest);
 size_t cvalue_arraylen(value_t v) fl_purefn;
 size_t ctype_sizeof(value_t type);
@@ -46,8 +39,8 @@
 value_t fl_add_any(value_t *args, uint32_t nargs);
 value_t fl_neg(value_t n);
 value_t fl_mul_any(value_t *args, uint32_t nargs);
-int num_to_ptr(value_t a, fixnum_t *pi, numerictype_t *pt, void **pp);
-_Noreturn void DivideByZeroError(void);
+bool num_to_ptr(value_t a, fixnum_t *pi, numerictype_t *pt, void **pp);
+_Noreturn void divide_by_0_error(void);
 value_t fl_div2(value_t a, value_t b);
 value_t fl_idiv2(value_t a, value_t b);
 void cvalues_init(void);
@@ -60,5 +53,4 @@
 value_t mk_uint64(uint64_t n);
 value_t mk_rune(Rune n);
 
-/* builtins.c */
 size_t llength(value_t v) fl_purefn;
--- a/src/flisp.c
+++ b/src/flisp.c
@@ -298,7 +298,8 @@
 	value_t *first;
 
 	assert(n > 0);
-	n = ALIGNED(n, 2);   // only allocate multiples of 2 words
+	if(n & 1) // only allocate multiples of 2 words
+		n++;
 	if(fl_unlikely((value_t*)FL(curheap) > (value_t*)FL(lim)+2-n)){
 		fl_gc(0);
 		while(fl_unlikely((value_t*)FL(curheap) > ((value_t*)FL(lim))+2-n))
--- a/src/operators.c
+++ b/src/operators.c
@@ -12,7 +12,7 @@
 	case T_INT32:  return itomp(*(int32_t*)data, nil);
 	case T_UINT32: return uitomp(*(uint32_t*)data, nil);
 	case T_INT64:  return vtomp(*(int64_t*)data, nil);
-	case T_UINT64: return uvtomp(*(int64_t*)data, nil);
+	case T_UINT64: return uvtomp(*(uint64_t*)data, nil);
 	case T_MPINT:  return mpcopy(*(mpint**)data);
 	case T_FLOAT:  return dtomp(*(float*)data, nil);
 	case T_DOUBLE: return dtomp(*(double*)data, nil);
--- a/src/vm.inc
+++ b/src/vm.inc
@@ -648,7 +648,7 @@
 		if(bothfixnums(a, b)){
 			if(b == 0){
 				FL(stack)[ipd] = (uintptr_t)ip;
-				DivideByZeroError();
+				divide_by_0_error();
 			}
 			v = fixnum(numval(a) / numval(b));
 		}else{