shithub: sl

Download patch

ref: 2f893ee47b89cffc0834548a39ec0ba479c887d8
parent: 064fc0481ad5568482744f2d66db0980e93eea95
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Thu Apr 3 16:18:59 EDT 2025

fix #byte → #utf8 (use symbol's name directly)

--- a/src/print.c
+++ b/src/print.c
@@ -706,7 +706,7 @@
 // printing in a context where a type is already implied, e.g. inside
 // an array.
 static void
-cvalue_printdata(sl_ios *f, void *data, usize len, sl_v type, int weak)
+cvalue_printdata(sl_ios *f, void *data, usize len, sl_v type, bool weak)
 {
 	int n;
 	if(type == sl_utf8sym){
@@ -714,7 +714,10 @@
 		if(sl.print_princ)
 			outc(f, ch);
 		else{
-			n = ios_printf(f, weak ? "0x%hhx" : "#byte(0x%hhx)", ch);
+			if(weak)
+				n = ios_printf(f, "0x%hhx", ch);
+			else
+				n = ios_printf(f, "#%s(0x%hhx)", sym_name_(sl_utf8sym), ch);
 			if(n < 1)
 				goto err;
 			sl.hpos += n;
@@ -847,7 +850,7 @@
 			for(i = 0; i < cnt; i++){
 				if(i > 0)
 					outc(f, ' ');
-				cvalue_printdata(f, data, elsize, eltype, 1);
+				cvalue_printdata(f, data, elsize, eltype, true);
 				data = (char*)data + elsize;
 			}
 			outc(f, ')');
@@ -900,7 +903,7 @@
 	}else{
 		sl_v type = cv_type(cv);
 		usize len = iscprim(v) ? cv_class(cv)->size : cv_len(cv);
-		cvalue_printdata(f, data, len, type, 0);
+		cvalue_printdata(f, data, len, type, false);
 	}
 }
 
--- a/src/sl.h
+++ b/src/sl.h
@@ -180,6 +180,7 @@
 #define isconst(s) ((s)->flags & FLAG_CONST)
 #define iskeyword(s) ((s)->flags & FLAG_KEYWORD)
 #define sym_value(s) (((sl_sym*)ptr(s))->binding)
+#define sym_name_(s) (((sl_sym*)ptr(s))->name)
 #define sym_to_numtype(s) (((sl_sym*)ptr(s))->numtype)
 #define ismanaged(v) ((((u8int*)ptr(v)) >= slg.fromspace) && (((u8int*)ptr(v)) < slg.fromspace+slg.heapsize))
 #define isgensym(x)  (issym(x) && ismanaged(x))