shithub: femtolisp

Download patch

ref: 2728527553570e8cdec19b4c305a723f040e63ad
parent: 9607be7406fb7c452bd13b92ea2c8178083c189a
author: Sigrid Solveig Haflínudóttir <[email protected]>
date: Mon Mar 20 11:27:13 EDT 2023

cosmetics

--- a/builtins.c
+++ b/builtins.c
@@ -59,12 +59,12 @@
 
 static value_t fl_memq(value_t *args, uint32_t nargs)
 {
+    value_t v;
+    cons_t *c;
     argcount("memq", nargs, 2);
-    while (iscons(args[1])) {
-        cons_t *c = (cons_t*)ptr(args[1]);
-        if (c->car == args[0])
-            return args[1];
-        args[1] = c->cdr;
+    for (v = args[1]; iscons(v); v = c->cdr) {
+        if ((c = ptr(v))->car == args[0])
+            return v;
     }
     return FL_F;
 }
--- a/flisp.c
+++ b/flisp.c
@@ -926,13 +926,15 @@
     // temporary variables (not necessary to preserve across calls)
     uint32_t op, i;
     symbol_t *sym;
-    static cons_t *c;
-    static value_t *pv;
-    static int64_t accum;
-    static value_t func, v, e;
+    cons_t *c;
+    value_t *pv;
+    int64_t accum;
+    value_t func, v, e;
 
     n = 0;
+    v = 0;
     USED(n);
+    USED(v);
  apply_cl_top:
     captured = 0;
     func = Stack[SP-nargs-1];
@@ -1109,56 +1111,56 @@
             type_error("apply", "function", func);
         OP(OP_TCALLL) n = GET_INT32(ip); ip+=4; goto do_tcall;
         OP(OP_CALLL)  n = GET_INT32(ip); ip+=4; goto do_call;
-        OP(OP_JMP) ip += (intptr_t)GET_INT16(ip); NEXT_OP;
+        OP(OP_JMP) ip += GET_INT16(ip); NEXT_OP;
         OP(OP_BRF)
             v = POP();
-            if (v == FL_F) ip += (intptr_t)GET_INT16(ip);
+            if (v == FL_F) ip += GET_INT16(ip);
             else ip += 2;
             NEXT_OP;
         OP(OP_BRT)
             v = POP();
-            if (v != FL_F) ip += (intptr_t)GET_INT16(ip);
+            if (v != FL_F) ip += GET_INT16(ip);
             else ip += 2;
             NEXT_OP;
-        OP(OP_JMPL) ip += (intptr_t)GET_INT32(ip); NEXT_OP;
+        OP(OP_JMPL) ip += GET_INT32(ip); NEXT_OP;
         OP(OP_BRFL)
             v = POP();
-            if (v == FL_F) ip += (intptr_t)GET_INT32(ip);
+            if (v == FL_F) ip += GET_INT32(ip);
             else ip += 4;
             NEXT_OP;
         OP(OP_BRTL)
             v = POP();
-            if (v != FL_F) ip += (intptr_t)GET_INT32(ip);
+            if (v != FL_F) ip += GET_INT32(ip);
             else ip += 4;
             NEXT_OP;
         OP(OP_BRNE)
-            if (Stack[SP-2] != Stack[SP-1]) ip += (intptr_t)GET_INT16(ip);
+            if (Stack[SP-2] != Stack[SP-1]) ip += GET_INT16(ip);
             else ip += 2;
             POPN(2);
             NEXT_OP;
         OP(OP_BRNEL)
-            if (Stack[SP-2] != Stack[SP-1]) ip += (intptr_t)GET_INT32(ip);
+            if (Stack[SP-2] != Stack[SP-1]) ip += GET_INT32(ip);
             else ip += 4;
             POPN(2);
             NEXT_OP;
         OP(OP_BRNN)
             v = POP();
-            if (v != NIL) ip += (intptr_t)GET_INT16(ip);
+            if (v != NIL) ip += GET_INT16(ip);
             else ip += 2;
             NEXT_OP;
         OP(OP_BRNNL)
             v = POP();
-            if (v != NIL) ip += (intptr_t)GET_INT32(ip);
+            if (v != NIL) ip += GET_INT32(ip);
             else ip += 4;
             NEXT_OP;
         OP(OP_BRN)
             v = POP();
-            if (v == NIL) ip += (intptr_t)GET_INT16(ip);
+            if (v == NIL) ip += GET_INT16(ip);
             else ip += 2;
             NEXT_OP;
         OP(OP_BRNL)
             v = POP();
-            if (v == NIL) ip += (intptr_t)GET_INT32(ip);
+            if (v == NIL) ip += GET_INT32(ip);
             else ip += 4;
             NEXT_OP;
         OP(OP_RET)
--- a/llt/hashing.c
+++ b/llt/hashing.c
@@ -3,14 +3,16 @@
 lltuint_t nextipow2(lltuint_t i)
 {
     if (i==0) return 1;
-    if ((i&(i-1))==0) return i;
-    if (i&TOP_BIT) return TOP_BIT;
-
-    // repeatedly clear bottom bit
-    while (i&(i-1))
-        i = i&(i-1);
-
-    return i<<1;
+    i |= i >> 1;
+    i |= i >> 2;
+    i |= i >> 4;
+    i |= i >> 8;
+    i |= i >> 16;
+#ifdef BITS64
+    i |= i >> 32;
+#endif
+    i++;
+    return i ? i : TOP_BIT;
 }
 
 uint32_t int32hash(uint32_t a)