shithub: femtolisp

Download patch

ref: f05ac5b9d4afa32ab0c50ea95d875cfbfcb4aa91
parent: 7da7a91bc8a0162bf0f21d298c1a356fc2cbce00
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Fri Mar 10 21:10:38 EST 2023

use uint8_t more

--- a/flisp.c
+++ b/flisp.c
@@ -128,10 +128,10 @@
     htable_free(&rs->gensyms);
 }
 
-static unsigned char *fromspace;
-static unsigned char *tospace;
-static unsigned char *curheap;
-static unsigned char *lim;
+static uint8_t *fromspace;
+static uint8_t *tospace;
+static uint8_t *curheap;
+static uint8_t *lim;
 static uint32_t heapsize;//bytes
 static uint32_t *consflags;
 
--- a/flisp.h
+++ b/flisp.h
@@ -104,8 +104,8 @@
 #define isconstant(s) ((s)->flags&0x1)
 #define iskeyword(s) ((s)->flags&0x2)
 #define symbol_value(s) (((symbol_t*)ptr(s))->binding)
-#define ismanaged(v) ((((unsigned char*)ptr(v)) >= fromspace) && \
-                      (((unsigned char*)ptr(v)) < fromspace+heapsize))
+#define ismanaged(v) ((((uint8_t*)ptr(v)) >= fromspace) && \
+                      (((uint8_t*)ptr(v)) < fromspace+heapsize))
 #define isgensym(x)  (issymbol(x) && ismanaged(x))
 
 #define isfunction(x) (tag(x) == TAG_FUNCTION && (x) > (N_BUILTINS<<3))
--- a/llt/dump.c
+++ b/llt/dump.c
@@ -29,7 +29,7 @@
         for(i=0; i < 16 && offs < len; i++, offs++) {
             ch = buffer[offs];
             linebuffer[i] = (ch<32 || ch>=0x7f) ? '.' : ch;
-            hexc[0] = hexdig[((unsigned char)ch)>>4];
+            hexc[0] = hexdig[((uint8_t)ch)>>4];
             hexc[1] = hexdig[ch&0x0f];
             pos += ios_write(dest, hexc, (i==7 || i==15) ? 4 : 3);
         }
--- a/llt/ios.c
+++ b/llt/ios.c
@@ -45,9 +45,9 @@
 #if defined(PLAN9)
 void *memrchr(const void *s, int c, size_t n)
 {
-    const unsigned char *src = (const unsigned char*)s + n;
-    unsigned char uc = c;
-    while (--src >= (unsigned char *) s)
+    const uint8_t *src = (const uint8_t*)s + n;
+    uint8_t uc = c;
+    while (--src >= (uint8_t *) s)
         if (*src == uc)
             return (void *) src;
     return NULL;
@@ -856,17 +856,17 @@
             return IOS_EOF;
     }
     if (ch == '\n') s->lineno++;
-    return (unsigned char)ch;
+    return (uint8_t)ch;
 }
 
 int ios_peekc(ios_t *s)
 {
     if (s->bpos < s->size)
-        return (unsigned char)s->buf[s->bpos];
+        return (uint8_t)s->buf[s->bpos];
     if (s->_eof) return IOS_EOF;
     size_t n = ios_readprep(s, 1);
     if (n == 0)  return IOS_EOF;
-    return (unsigned char)s->buf[s->bpos];
+    return (uint8_t)s->buf[s->bpos];
 }
 
 int ios_ungetc(int c, ios_t *s)
@@ -901,8 +901,8 @@
     if (c == IOS_EOF)
         return IOS_EOF;
     c0 = (char)c;
-    if ((unsigned char)c0 < 0x80) {
-        *pwc = (uint32_t)(unsigned char)c0;
+    if ((uint8_t)c0 < 0x80) {
+        *pwc = (uint32_t)(uint8_t)c0;
         return 1;
     }
     sz = u8_seqlen(&c0)-1;
@@ -927,8 +927,8 @@
     if (c == IOS_EOF)
         return IOS_EOF;
     c0 = (char)c;
-    if ((unsigned char)c0 < 0x80) {
-        *pwc = (uint32_t)(unsigned char)c0;
+    if ((uint8_t)c0 < 0x80) {
+        *pwc = (uint32_t)(uint8_t)c0;
         return 1;
     }
     sz = u8_seqlen(&c0)-1;
--- a/llt/ios.h
+++ b/llt/ios.h
@@ -34,27 +34,25 @@
     off_t fpos;       // cached file pos
     size_t lineno;    // current line number
 
-    // pointer-size integer to support platforms where it might have
-    // to be a pointer
-    long fd;
+    int fd;
 
-    unsigned char readonly:1;
-    unsigned char ownbuf:1;
-    unsigned char ownfd:1;
-    unsigned char _eof:1;
+    uint8_t readonly:1;
+    uint8_t ownbuf:1;
+    uint8_t ownfd:1;
+    uint8_t _eof:1;
 
     // this means you can read, seek back, then read the same data
     // again any number of times. usually only true for files and strings.
-    unsigned char rereadable:1;
+    uint8_t rereadable:1;
 
     // this enables "stenciled writes". you can alternately write and
     // seek without flushing in between. this performs read-before-write
     // to populate the buffer, so "rereadable" capability is required.
     // this is off by default.
-    //unsigned char stenciled:1;
+    //uint8_t stenciled:1;
 
     // request durable writes (fsync)
-    // unsigned char durable:1;
+    // uint8_t durable:1;
 
     // todo: mutex
     char local[IOS_INLSIZE];
--- a/llt/utf8.c
+++ b/llt/utf8.c
@@ -61,7 +61,7 @@
 /* returns length of next utf-8 sequence */
 size_t u8_seqlen(const char *s)
 {
-    return trailingBytesForUTF8[(unsigned int)(unsigned char)s[0]] + 1;
+    return trailingBytesForUTF8[(unsigned int)(uint8_t)s[0]] + 1;
 }
 
 /* returns the # of bytes needed to encode a certain character
@@ -113,17 +113,17 @@
             if (src >= src_end) break;
             continue;
         }
-        nb = trailingBytesForUTF8[(unsigned char)*src];
+        nb = trailingBytesForUTF8[(uint8_t)*src];
         if (src + nb >= src_end)
             break;
         ch = 0;
         switch (nb) {
-        case 5: ch += (unsigned char)*src++; ch <<= 6; // fallthrough
-        case 4: ch += (unsigned char)*src++; ch <<= 6; // fallthrough
-        case 3: ch += (unsigned char)*src++; ch <<= 6; // fallthrough
-        case 2: ch += (unsigned char)*src++; ch <<= 6; // fallthrough
-        case 1: ch += (unsigned char)*src++; ch <<= 6; // fallthrough
-        case 0: ch += (unsigned char)*src++;
+        case 5: ch += (uint8_t)*src++; ch <<= 6; // fallthrough
+        case 4: ch += (uint8_t)*src++; ch <<= 6; // fallthrough
+        case 3: ch += (uint8_t)*src++; ch <<= 6; // fallthrough
+        case 2: ch += (uint8_t)*src++; ch <<= 6; // fallthrough
+        case 1: ch += (uint8_t)*src++; ch <<= 6; // fallthrough
+        case 0: ch += (uint8_t)*src++;
         }
         ch -= offsetsFromUTF8[nb];
         dest[i++] = ch;
@@ -268,15 +268,15 @@
         }
         else {
             if (!isutf(sc)) { tot++; s++; continue; }
-            nb = trailingBytesForUTF8[(unsigned char)sc];
+            nb = trailingBytesForUTF8[(uint8_t)sc];
             ch = 0;
             switch (nb) {
-            case 5: ch += (unsigned char)*s++; ch <<= 6; // fallthrough
-            case 4: ch += (unsigned char)*s++; ch <<= 6; // fallthrough
-            case 3: ch += (unsigned char)*s++; ch <<= 6; // fallthrough
-            case 2: ch += (unsigned char)*s++; ch <<= 6; // fallthrough
-            case 1: ch += (unsigned char)*s++; ch <<= 6; // fallthrough
-            case 0: ch += (unsigned char)*s++;
+            case 5: ch += (uint8_t)*s++; ch <<= 6; // fallthrough
+            case 4: ch += (uint8_t)*s++; ch <<= 6; // fallthrough
+            case 3: ch += (uint8_t)*s++; ch <<= 6; // fallthrough
+            case 2: ch += (uint8_t)*s++; ch <<= 6; // fallthrough
+            case 1: ch += (uint8_t)*s++; ch <<= 6; // fallthrough
+            case 0: ch += (uint8_t)*s++;
             }
             ch -= offsetsFromUTF8[nb];
             w = wcwidth(ch);  // might return -1
@@ -294,7 +294,7 @@
 
     do {
         ch <<= 6;
-        ch += (unsigned char)s[(*i)];
+        ch += (uint8_t)s[(*i)];
         sz++;
     } while (s[*i] && (++(*i)) && !isutf(s[*i]));
     ch -= offsetsFromUTF8[sz-1];
@@ -310,7 +310,7 @@
 
     do {
         ch <<= 6;
-        ch += (unsigned char)s[(*i)++];
+        ch += (uint8_t)s[(*i)++];
         sz++;
     } while (!isutf(s[*i]));
     ch -= offsetsFromUTF8[sz-1];
@@ -536,7 +536,7 @@
         c = csz = 0;
         do {
             c <<= 6;
-            c += (unsigned char)s[i++];
+            c += (uint8_t)s[i++];
             csz++;
         } while (i < sz && !isutf(s[i]));
         c -= offsetsFromUTF8[csz-1];
@@ -623,11 +623,11 @@
    it's hard to know how many characters there are! */
 int u8_isvalid(const char *str, int length)
 {
-    const unsigned char *p, *pend = (unsigned char*)str + length;
-    unsigned char c;
+    const uint8_t *p, *pend = (uint8_t*)str + length;
+    uint8_t c;
     int ab;
 
-    for (p = (unsigned char*)str; p < pend; p++) {
+    for (p = (uint8_t*)str; p < pend; p++) {
         c = *p;
         if (c < 128)
             continue;
@@ -685,11 +685,11 @@
 int u8_reverse(char *dest, char * src, size_t len)
 {
     size_t si=0, di=len;
-    unsigned char c;
+    uint8_t c;
 
     dest[di] = '\0';
     while (si < len) {
-        c = (unsigned char)src[si];
+        c = (uint8_t)src[si];
         if ((~c) & 0x80) {
             di--;
             dest[di] = c;
--- a/print.c
+++ b/print.c
@@ -625,7 +625,7 @@
                              int weak)
 {
     if (type == bytesym) {
-        unsigned char ch = *(unsigned char*)data;
+        uint8_t ch = *(uint8_t*)data;
         if (print_princ)
             outc(ch, f);
         else if (weak)