shithub: sl

Download patch

ref: 6852848f02c1443d7e0caf5882bad40cd64b9bfc
parent: b980c33f7efe5e173e196b6c47de5c99b705b017
author: spew <spew@cbza.org>
date: Tue Apr 8 10:01:44 EDT 2025

print 64 bit ptr as unsigned and allow ptr negation

--- a/src/cvalues.c
+++ b/src/cvalues.c
@@ -962,6 +962,7 @@
 {
 	s64int i64;
 	u64int ui64;
+	uintptr uiptr;
 	mpint *mp;
 	sl_numtype pt;
 	sl_fx pi;
@@ -998,7 +999,14 @@
 			i64 = -(s64int)ui64;
 			goto i64neg;
 		case T_PTR:
-			// a pointer is not exactly a number
+			uiptr = *(uintptr*)a;
+			if(uiptr >= (u64int)INT64_MAX+1){
+				mp = uvtomp(uiptr, nil);
+				mp->sign = -1;
+				return mk_bignum(mp);
+			}
+			i64 = -(s64int)uiptr;
+			goto i64neg;
 			break;
 		case T_BIGNUM:
 			mp = mpcopy(*(mpint**)a);
--- a/src/plan9/platform.h
+++ b/src/plan9/platform.h
@@ -39,12 +39,12 @@
 #define BITS64
 #define PRIdPTR PRId64
 #define PRIuPTR PRIu64
-#define PRIxPTR PRIx64
+#define PRIxPTR PRIux64
 typedef long long ssize;
 #else
 #define PRIdPTR "ld"
 #define PRIuPTR "lud"
-#define PRIxPTR "llux"
+#define PRIxPTR "lux"
 typedef long ssize;
 #endif
 
@@ -75,6 +75,7 @@
 #define PRId64 "lld"
 #define PRIu64 "llud"
 #define PRIx64 "llx"
+#define PRIux64 "llux"
 
 #define INT32_MAX 0x7fffffff
 #define UINT32_MAX 0xffffffffU