shithub: femtolisp

Download patch

ref: c92a5cae7db20bd30adf68b96e3ce63429fcb935
parent: 541946a4b943e6ac3054db05a0c7e3e7729f29f5
author: Sigrid Solveig Haflínudóttir <[email protected]>
date: Tue Nov 12 20:21:30 EST 2024

clean up and fix some of the types and type casts

--- a/3rd/mp/mpaux.c
+++ b/3rd/mp/mpaux.c
@@ -65,9 +65,9 @@
 
 // guarantee at least n significant bits
 void
-mpbits(mpint *b, int m)
+mpbits(mpint *b, uint32_t m)
 {
-	int n;
+	uint32_t n;
 
 	n = DIGITS(m);
 	if(b->size >= n){
@@ -153,7 +153,7 @@
 }
 
 // number of significant bits in mantissa
-int
+uint32_t
 mpsignif(mpint *n)
 {
 	int i, j;
@@ -172,10 +172,10 @@
 }
 
 // k, where n = 2**k * q for odd q
-int
+uint32_t
 mplowbits0(mpint *n)
 {
-	int k, bit, digit;
+	uint32_t k, bit, digit;
 	mpdigit d;
 
 	assert(n->flags & MPnorm);
--- a/3rd/mp/mpdiv.c
+++ b/3rd/mp/mpdiv.c
@@ -20,9 +20,9 @@
 
 	// division by one or small powers of two
 	if(divisor->top == 1 && (divisor->p[0] & divisor->p[0]-1) == 0){
-		vlong r = 0;
+		int64_t r = 0;
 		if(dividend->top > 0)
-			r = (vlong)dividend->sign * (dividend->p[0] & divisor->p[0]-1);
+			r = (int64_t)dividend->sign * (dividend->p[0] & divisor->p[0]-1);
 		if(quotient != nil){
 			sign = divisor->sign;
 			for(s = 0; ((divisor->p[0] >> s) & 1) == 0; s++)
--- a/3rd/mp/mpfmt.c
+++ b/3rd/mp/mpfmt.c
@@ -1,21 +1,6 @@
 #include "platform.h"
 
 static int
-toencx(mpint *b, char *buf, int len, int (*enc)(char*, int, uchar*, int))
-{
-	uchar *p;
-	int n, rv;
-
-	p = nil;
-	n = mptobe(b, nil, 0, &p);
-	if(n < 0)
-		return -1;
-	rv = (*enc)(buf, len, p, n);
-	LLT_FREE(p);
-	return rv;
-}
-
-static int
 topow2(mpint *b, char *buf, int len, int s)
 {
 	mpdigit *p, x;
@@ -104,7 +89,7 @@
 {
 	mpdigit x, y;
 	char *out;
-	int i, j;
+	uint32_t i, j;
 
 	if(len < 2)
 		return -1;
@@ -173,12 +158,6 @@
 		len--;
 	}
 	switch(base){
-	case 64:
-		rv = toencx(b, out, len, enc64);
-		break;
-	case 32:
-		rv = toencx(b, out, len, enc32);
-		break;
 	case 16:
 		rv = topow2(b, out, len, 4);
 		break;
--- a/3rd/mp/mplogic.c
+++ b/3rd/mp/mplogic.c
@@ -20,8 +20,7 @@
 {
 	mpint *t;
 	mpdigit *dp1, *dp2, *dpo, d1, d2, d;
-	int c1, c2, co;
-	int i;
+	uint32_t c1, c2, co, i;
 
 	assert(((b1->flags | b2->flags | sum->flags) & MPtimesafe) == 0);
 	if(b1->sign < 0) fl ^= 0x03;
@@ -49,10 +48,10 @@
 			d2 = 0;
 		if(d1 != (mpdigit)-1) c1 = 0;
 		if(d2 != (mpdigit)-1) c2 = 0;
-		if((fl & 2) != 0) d1 ^= -1;
-		if((fl & 8) != 0) d2 ^= -1;
+		if((fl & 2) != 0) d1 ^= -(mpdigit)1;
+		if((fl & 8) != 0) d2 ^= -(mpdigit)1;
 		d = d1 | d2;
-		if((fl & 32) != 0) d ^= -1;
+		if((fl & 32) != 0) d ^= -(mpdigit)1;
 		d += co;
 		if(d != 0) co = 0;
 		dpo[i] = d;
@@ -94,8 +93,8 @@
 {
 	mpint *t;
 	mpdigit *dp1, *dp2, *dpo, d1, d2, d;
-	int c1, c2, co;
-	int i, fl;
+	uint32_t c1, c2, co, i;
+	int fl;
 
 	assert(((b1->flags | b2->flags | sum->flags) & MPtimesafe) == 0);
 	if(b2->top > b1->top){
@@ -129,72 +128,6 @@
 	if(co)
 		dpo[sum->top++] = co;
 	mpnorm(sum);
-}
-
-void
-mptrunc(mpint *b, int n, mpint *r)
-{
-	int d, m, i, c;
-
-	assert(((b->flags | r->flags) & MPtimesafe) == 0);
-	mpbits(r, n);
-	r->top = DIGITS(n);
-	d = n / Dbits;
-	m = n % Dbits;
-	if(b->sign == -1){
-		c = 1;
-		for(i = 0; i < r->top; i++){
-			if(i < b->top)
-				r->p[i] = ~(b->p[i] - c);
-			else
-				r->p[i] = -1;
-			if(r->p[i] != 0)
-				c = 0;
-		}
-		if(m != 0)
-			r->p[d] &= (1<<m) - 1;
-	}else if(b->sign == 1){
-		if(d >= b->top){
-			mpassign(b, r);
-			mpnorm(r);
-			return;
-		}
-		if(b != r)
-			for(i = 0; i < d; i++)
-				r->p[i] = b->p[i];
-		if(m != 0)
-			r->p[d] = b->p[d] & (1<<m)-1;
-	}
-	r->sign = 1;
-	mpnorm(r);
-}
-
-void
-mpxtend(mpint *b, int n, mpint *r)
-{
-	int d, m, c, i;
-
-	d = (n - 1) / Dbits;
-	m = (n - 1) % Dbits;
-	if(d >= b->top){
-		mpassign(b, r);
-		return;
-	}
-	mptrunc(b, n, r);
-	mpbits(r, n);
-	if((r->p[d] & 1<<m) == 0){
-		mpnorm(r);
-		return;
-	}
-	r->p[d] |= -(1<<m);
-	r->sign = -1;
-	c = 1;
-	for(i = 0; i < r->top; i++){
-		r->p[i] = ~(r->p[i] - c);
-		if(r->p[i] != 0)
-			c = 0;
-	}
-	mpnorm(r);
 }
 
 void
--- a/3rd/mp/mpright.c
+++ b/3rd/mp/mpright.c
@@ -4,7 +4,7 @@
 void
 mpright(mpint *b, int shift, mpint *res)
 {
-	int d, l, r, i;
+	uint32_t d, l, r, i;
 	mpdigit this, last;
 
 	res->sign = b->sign;
--- a/3rd/mp/mptobe.c
+++ b/3rd/mp/mptobe.c
@@ -4,9 +4,9 @@
 //   return number of bytes converted
 //   if p == nil, allocate and result array
 int
-mptobe(mpint *b, uchar *p, uint n, uchar **pp)
+mptobe(mpint *b, uint8_t *p, uint32_t n, uint8_t **pp)
 {
-	uint m;
+	uint32_t m;
 
 	m = (mpsignif(b)+7)/8;
 	if(m == 0)
--- a/3rd/mp/mptober.c
+++ b/3rd/mp/mptober.c
@@ -1,7 +1,7 @@
 #include "platform.h"
 
 void
-mptober(mpint *b, uchar *p, int n)
+mptober(mpint *b, uint8_t *p, int n)
 {
 	int i, j, m;
 	mpdigit x;
--- a/3rd/mp/mptod.c
+++ b/3rd/mp/mptod.c
@@ -5,13 +5,13 @@
 double
 mptod(mpint *a)
 {
-	u64int v;
+	uint64_t v;
 	mpdigit w, r;
 	int sf, i, n, m, s;
 	FPdbleword x;
 
 	if(a->top == 0) return 0.0;
-	sf = mpsignif(a);
+	sf = (int)mpsignif(a);
 	if(sf > 1024) return a->sign < 0 ? D_NINF : D_PINF;
 	i = a->top - 1;
 	v = a->p[i];
@@ -49,7 +49,7 @@
 			return a->sign < 0 ? D_NINF : D_PINF;
 	}
 	x.lo = v;
-	x.hi = (u32int)(v >> 32) & (1<<20) - 1 | (sf + 1022) << 20 | a->sign & 1U<<31;
+	x.hi = (uint32_t)(v >> 32) & (1<<20) - 1 | (sf + 1022) << 20 | a->sign & 1U<<31;
 	return x.x;
 }
 
@@ -57,7 +57,7 @@
 dtomp(double d, mpint *a)
 {
 	FPdbleword x;
-	uvlong v;
+	uint64_t v;
 	int e;
 
 	if(a == nil)
@@ -69,7 +69,7 @@
 		mpassign(mpzero, a);
 		return a;
 	}
-	v = x.lo | (uvlong)(x.hi & (1<<20) - 1) << 32 | 1ULL<<52;
+	v = x.lo | (uint64_t)(x.hi & (1<<20) - 1) << 32 | 1ULL<<52;
 	if(e < 1075){
 		v += (1ULL<<(1074 - e)) - (~v >> (1075 - e) & 1);
 		v >>= 1075 - e;
--- a/3rd/mp/mptoi.c
+++ b/3rd/mp/mptoi.c
@@ -21,7 +21,7 @@
 int
 mptoi(mpint *b)
 {
-	uint x;
+	uint32_t x;
 
 	if(b->top==0)
 		return 0;
--- a/3rd/mp/mptoui.c
+++ b/3rd/mp/mptoui.c
@@ -6,7 +6,7 @@
  */
 
 mpint*
-uitomp(uint i, mpint *b)
+uitomp(uint32_t i, mpint *b)
 {
 	if(b == nil){
 		b = mpnew(0);
@@ -17,15 +17,15 @@
 	return mpnorm(b);
 }
 
-uint
+uint32_t
 mptoui(mpint *b)
 {
-	uint x;
+	uint32_t x;
 
 	x = *b->p;
 	if(b->sign < 0)
 		x = 0;
-	else if(b->top > 1 || (sizeof(mpdigit) > sizeof(uint) && x > MAXUINT))
+	else if(b->top > 1 || (sizeof(mpdigit) > sizeof(uint32_t) && x > MAXUINT))
 		x =  MAXUINT;
 	return x;
 }
--- a/3rd/mp/mptouv.c
+++ b/3rd/mp/mptouv.c
@@ -1,13 +1,13 @@
 #include "platform.h"
 
-#define VLDIGITS (int)(sizeof(vlong)/sizeof(mpdigit))
+#define VLDIGITS (int)(sizeof(int64_t)/sizeof(mpdigit))
 
 /*
- *  this code assumes that a vlong is an integral number of
+ *  this code assumes that a int64_t is an integral number of
  *  mpdigits long.
  */
 mpint*
-uvtomp(uvlong v, mpint *b)
+uvtomp(uint64_t v, mpint *b)
 {
 	int s;
 
@@ -24,11 +24,11 @@
 	return mpnorm(b);
 }
 
-uvlong
+uint64_t
 mptouv(mpint *b)
 {
-	uvlong v;
-	int s;
+	uint64_t v;
+	uint32_t s;
 
 	if(b->top == 0 || b->sign < 0)
 		return 0LL;
@@ -38,7 +38,7 @@
 
 	v = 0ULL;
 	for(s = 0; s < b->top; s++)
-		v |= (uvlong)b->p[s]<<(s*sizeof(mpdigit)*8);
+		v |= (uint64_t)b->p[s]<<(s*sizeof(mpdigit)*8);
 
 	return v;
 }
--- a/3rd/mp/mptov.c
+++ b/3rd/mp/mptov.c
@@ -1,16 +1,16 @@
 #include "platform.h"
 
-#define VLDIGITS (int)(sizeof(vlong)/sizeof(mpdigit))
+#define VLDIGITS (int)(sizeof(int64_t)/sizeof(mpdigit))
 
 /*
- *  this code assumes that a vlong is an integral number of
+ *  this code assumes that a int64_t is an integral number of
  *  mpdigits long.
  */
 mpint*
-vtomp(vlong v, mpint *b)
+vtomp(int64_t v, mpint *b)
 {
 	int s;
-	uvlong uv;
+	uint64_t uv;
 
 	if(b == nil){
 		b = mpnew(VLDIGITS*Dbits);
@@ -26,11 +26,11 @@
 	return mpnorm(b);
 }
 
-vlong
+int64_t
 mptov(mpint *b)
 {
-	uvlong v;
-	int s;
+	uint64_t v;
+	uint32_t s;
 
 	if(b->top == 0)
 		return 0LL;
@@ -37,14 +37,14 @@
 
 	if(b->top > VLDIGITS){
 		if(b->sign > 0)
-			return (vlong)MAXVLONG;
+			return (int64_t)MAXVLONG;
 		else
-			return (vlong)MINVLONG;
+			return (int64_t)MINVLONG;
 	}
 
 	v = 0ULL;
 	for(s = 0; s < b->top; s++)
-		v |= (uvlong)b->p[s]<<(s*sizeof(mpdigit)*8);
+		v |= (uint64_t)b->p[s]<<(s*sizeof(mpdigit)*8);
 
 	if(b->sign > 0){
 		if(v > MAXVLONG)
@@ -53,8 +53,8 @@
 		if(v > MINVLONG)
 			v = MINVLONG;
 		else
-			v = -(vlong)v;
+			v = -(int64_t)v;
 	}
 
-	return (vlong)v;
+	return (int64_t)v;
 }
--- a/3rd/mp/mpvecadd.c
+++ b/3rd/mp/mpvecadd.c
@@ -5,7 +5,7 @@
 mpvecadd(mpdigit *a, int alen, mpdigit *b, int blen, mpdigit *sum)
 {
 	int i;
-	uint carry;
+	uint32_t carry;
 	mpdigit x, y;
 
 	carry = 0;
--- a/3rd/mp/u16.c
+++ b/3rd/mp/u16.c
@@ -24,11 +24,11 @@
 }
 
 int
-dec16(uchar *out, int lim, char *in, int n)
+dec16(uint8_t *out, int lim, char *in, int n)
 {
 	int c, w = 0, i = 0;
-	uchar *start = out;
-	uchar *eout = out + lim;
+	uint8_t *start = out;
+	uint8_t *eout = out + lim;
 
 	while(n-- > 0){
 		c = dec16chr(*in++);
@@ -49,9 +49,9 @@
 }
 
 int
-enc16(char *out, int lim, uchar *in, int n)
+enc16(char *out, int lim, uint8_t *in, int n)
 {
-	uint c;
+	uint32_t c;
 	char *eout = out + lim;
 	char *start = out;
 
--- a/3rd/mp/u32.c
+++ /dev/null
@@ -1,143 +1,0 @@
-#include "platform.h"
-
-#define between(x,min,max)	(((min-1-x) & (x-max-1))>>8)
-
-int
-enc32chr(int o)
-{
-	int c;
-
-	c  = between(o,  0, 25) & ('A'+o);
-	c |= between(o, 26, 31) & ('2'+(o-26));
-	return c;
-}
-
-int
-dec32chr(int c)
-{
-	int o;
-
-	o  = between(c, 'A', 'Z') & (1+(c-'A'));
-	o |= between(c, 'a', 'z') & (1+(c-'a'));
-	o |= between(c, '2', '7') & (1+26+(c-'2'));
-	return o-1;
-}
-
-int
-dec32x(uchar *dest, int ndest, char *src, int nsrc, int (*chr)(int))
-{
-	uchar *start;
-	int i, j, u[8];
-
-	if(ndest+1 < (5*nsrc+7)/8)
-		return -1;
-	start = dest;
-	while(nsrc>=8){
-		for(i=0; i<8; i++){
-			j = chr(src[i]);
-			if(j < 0)
-				j = 0;
-			u[i] = j;
-		}
-		*dest++ = (u[0]<<3) | (0x7 & (u[1]>>2));
-		*dest++ = ((0x3 & u[1])<<6) | (u[2]<<1) | (0x1 & (u[3]>>4));
-		*dest++ = ((0xf & u[3])<<4) | (0xf & (u[4]>>1));
-		*dest++ = ((0x1 & u[4])<<7) | (u[5]<<2) | (0x3 & (u[6]>>3));
-		*dest++ = ((0x7 & u[6])<<5) | u[7];
-		src  += 8;
-		nsrc -= 8;
-	}
-	if(nsrc > 0){
-		if(nsrc == 1 || nsrc == 3 || nsrc == 6)
-			return -1;
-		for(i=0; i<nsrc; i++){
-			j = chr(src[i]);
-			if(j < 0)
-				j = 0;
-			u[i] = j;
-		}
-		*dest++ = (u[0]<<3) | (0x7 & (u[1]>>2));
-		if(nsrc == 2)
-			goto out;
-		*dest++ = ((0x3 & u[1])<<6) | (u[2]<<1) | (0x1 & (u[3]>>4));
-		if(nsrc == 4)
-			goto out;
-		*dest++ = ((0xf & u[3])<<4) | (0xf & (u[4]>>1));
-		if(nsrc == 5)
-			goto out;
-		*dest++ = ((0x1 & u[4])<<7) | (u[5]<<2) | (0x3 & (u[6]>>3));
-	}
-out:
-	return dest-start;
-}
-
-int
-enc32x(char *dest, int ndest, uchar *src, int nsrc, int (*chr)(int))
-{
-	char *start;
-	int j;
-
-	if(ndest <= (8*nsrc+4)/5)
-		return -1;
-	start = dest;
-	while(nsrc>=5){
-		j = (0x1f & (src[0]>>3));
-		*dest++ = chr(j);
-		j = (0x1c & (src[0]<<2)) | (0x03 & (src[1]>>6));
-		*dest++ = chr(j);
-		j = (0x1f & (src[1]>>1));
-		*dest++ = chr(j);
-		j = (0x10 & (src[1]<<4)) | (0x0f & (src[2]>>4));
-		*dest++ = chr(j);
-		j = (0x1e & (src[2]<<1)) | (0x01 & (src[3]>>7));
-		*dest++ = chr(j);
-		j = (0x1f & (src[3]>>2));
-		*dest++ = chr(j);
-		j = (0x18 & (src[3]<<3)) | (0x07 & (src[4]>>5));
-		*dest++ = chr(j);
-		j = (0x1f & (src[4]));
-		*dest++ = chr(j);
-		src  += 5;
-		nsrc -= 5;
-	}
-	if(nsrc){
-		j = (0x1f & (src[0]>>3));
-		*dest++ = chr(j);
-		j = (0x1c & (src[0]<<2));
-		if(nsrc == 1)
-			goto out;
-		j |= (0x03 & (src[1]>>6));
-		*dest++ = chr(j);
-		j = (0x1f & (src[1]>>1));
-		*dest++ = chr(j);
-		j = (0x10 & (src[1]<<4));
-		if(nsrc == 2)
-			goto out;
-		j |= (0x0f & (src[2]>>4));
-		*dest++ = chr(j);
-		j = (0x1e & (src[2]<<1));
-		if(nsrc == 3)
-			goto out;
-		j |= (0x01 & (src[3]>>7));
-		*dest++ = chr(j);
-		j = (0x1f & (src[3]>>2));
-		*dest++ = chr(j);
-		j = (0x18 & (src[3]<<3));
-out:
-		*dest++ = chr(j);
-	}
-	*dest = 0;
-	return dest-start;
-}
-
-int
-enc32(char *dest, int ndest, uchar *src, int nsrc)
-{
-	return enc32x(dest, ndest, src, nsrc, enc32chr);
-}
-
-int
-dec32(uchar *dest, int ndest, char *src, int nsrc)
-{
-	return dec32x(dest, ndest, src, nsrc, dec32chr);
-}
--- a/3rd/mp/u64.c
+++ /dev/null
@@ -1,141 +1,0 @@
-#include "platform.h"
-
-#define between(x,min,max)	(((min-1-x) & (x-max-1))>>8)
-
-int
-enc64chr(int o)
-{
-	int c;
-
-	c  = between(o,  0, 25) & ('A'+o);
-	c |= between(o, 26, 51) & ('a'+(o-26));
-	c |= between(o, 52, 61) & ('0'+(o-52));
-	c |= between(o, 62, 62) & ('+');
-	c |= between(o, 63, 63) & ('/');
-	return c;
-}
-
-int
-dec64chr(int c)
-{
-	int o;
-
-	o  = between(c, 'A', 'Z') & (1+(c-'A'));
-	o |= between(c, 'a', 'z') & (1+26+(c-'a'));
-	o |= between(c, '0', '9') & (1+52+(c-'0'));
-	o |= between(c, '+', '+') & (1+62);
-	o |= between(c, '/', '/') & (1+63);
-	return o-1;
-}
-
-int
-dec64x(uchar *out, int lim, char *in, int n, int (*chr)(int))
-{
-	uint32_t b24;
-	uchar *start = out;
-	uchar *e = out + lim;
-	int i, c;
-
-	b24 = 0;
-	i = 0;
-	while(n-- > 0){
-		c = chr(*in++);
-		if(c < 0)
-			continue;
-		switch(i){
-		case 0:
-			b24 = c<<18;
-			break;
-		case 1:
-			b24 |= c<<12;
-			break;
-		case 2:
-			b24 |= c<<6;
-			break;
-		case 3:
-			if(out + 3 > e)
-				goto exhausted;
-
-			b24 |= c;
-			*out++ = b24>>16;
-			*out++ = b24>>8;
-			*out++ = b24;
-			i = 0;
-			continue;
-		}
-		i++;
-	}
-	switch(i){
-	case 2:
-		if(out + 1 > e)
-			goto exhausted;
-		*out++ = b24>>16;
-		break;
-	case 3:
-		if(out + 2 > e)
-			goto exhausted;
-		*out++ = b24>>16;
-		*out++ = b24>>8;
-		break;
-	}
-exhausted:
-	return out - start;
-}
-
-int
-enc64x(char *out, int lim, uchar *in, int n, int (*chr)(int))
-{
-	int i;
-	uint32_t b24;
-	char *start = out;
-	char *e = out + lim;
-
-	for(i = n/3; i > 0; i--){
-		b24 = *in++<<16;
-		b24 |= *in++<<8;
-		b24 |= *in++;
-		if(out + 4 >= e)
-			goto exhausted;
-		*out++ = chr(b24>>18);
-		*out++ = chr((b24>>12)&0x3f);
-		*out++ = chr((b24>>6)&0x3f);
-		*out++ = chr(b24&0x3f);
-	}
-
-	switch(n%3){
-	case 2:
-		b24 = *in++<<16;
-		b24 |= *in<<8;
-		if(out + 4 >= e)
-			goto exhausted;
-		*out++ = chr(b24>>18);
-		*out++ = chr((b24>>12)&0x3f);
-		*out++ = chr((b24>>6)&0x3f);
-		*out++ = '=';
-		break;
-	case 1:
-		b24 = *in<<16;
-		if(out + 4 >= e)
-			goto exhausted;
-		*out++ = chr(b24>>18);
-		*out++ = chr((b24>>12)&0x3f);
-		*out++ = '=';
-		*out++ = '=';
-		break;
-	}
-exhausted:
-	*out = 0;
-	return out - start;
-}
-
-int
-enc64(char *out, int lim, uchar *in, int n)
-{
-	return enc64x(out, lim, in, n, enc64chr);
-}
-
-int
-dec64(uchar *out, int lim, char *in, int n)
-{
-	return dec64x(out, lim, in, n, dec64chr);
-}
--- a/3rd/utf/rune.c
+++ b/3rd/utf/rune.c
@@ -37,7 +37,7 @@
 	 * one character sequence
 	 *	00000-0007F => T1
 	 */
-	c = *(uchar*)str;
+	c = *(uint8_t*)str;
 	if(c < Tx) {
 		*rune = c;
 		return 1;
@@ -47,7 +47,7 @@
 	 * two character sequence
 	 *	0080-07FF => T2 Tx
 	 */
-	c1 = *(uchar*)(str+1) ^ Tx;
+	c1 = *(uint8_t*)(str+1) ^ Tx;
 	if(c1 & Testx)
 		goto bad;
 	if(c < T3) {
@@ -64,7 +64,7 @@
 	 * three character sequence
 	 *	0800-FFFF => T3 Tx Tx
 	 */
-	c2 = *(uchar*)(str+2) ^ Tx;
+	c2 = *(uint8_t*)(str+2) ^ Tx;
 	if(c2 & Testx)
 		goto bad;
 	if(c < T4) {
@@ -80,7 +80,7 @@
 	 *	10000-10FFFF => T4 Tx Tx Tx
 	 */
 	if(UTFmax >= 4) {
-		c3 = *(uchar*)(str+3) ^ Tx;
+		c3 = *(uint8_t*)(str+3) ^ Tx;
 		if(c3 & Testx)
 			goto bad;
 		if(c < T5) {
@@ -188,7 +188,7 @@
 
 	if(n <= 0)
 		return 0;
-	c = *(uchar*)str;
+	c = *(uint8_t*)str;
 	if(c < Tx)
 		return 1;
 	if(c < T3)
--- a/3rd/utf/runeistypedata
+++ b/3rd/utf/runeistypedata
@@ -1,5 +1,5 @@
 static
-uchar	_mergeddata[11769] =
+uint8_t	_mergeddata[11769] =
 {
 	0,0,0,0,0,0,0,0,0,1,1,1,1,1,0,0,
 	0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,
--- a/3rd/utf/utfnlen.c
+++ b/3rd/utf/utfnlen.c
@@ -10,7 +10,7 @@
 
 	es = s + m;
 	for(n = 0; s < es; n++) {
-		c = *(uchar*)s;
+		c = *(uint8_t*)s;
 		if(c < Runeself){
 			if(c == '\0')
 				break;
--- a/builtins.c
+++ b/builtins.c
@@ -28,7 +28,7 @@
 	value_t lst, first = FL(Nil);
 	value_t *pcdr = &first;
 	cons_t *c;
-	int i = 0;
+	uint32_t i = 0;
 
 	while(1){
 		lst = args[i++];
@@ -285,14 +285,12 @@
 
 BUILTIN("vector-alloc", vector_alloc)
 {
-	int i, k, a;
+	uint32_t i, k, a;
 	value_t f, v;
 	if(nargs < 1)
 		argcount(nargs, 1);
 	i = toulong(args[0]);
-	if(i < 0)
-		lerrorf(FL(ArgError), "invalid size: %d", i);
-	v = alloc_vector((unsigned)i, 0);
+	v = alloc_vector(i, 0);
 	a = 1;
 	for(k = 0; k < i; k++){
 		f = a < nargs ? args[a] : FL(unspecified);
--- a/cvalues.c
+++ b/cvalues.c
@@ -224,7 +224,7 @@
 		ctype n; \
 		USED(type); \
 		if(isfixnum(arg)) \
-			n = numval(arg); \
+			n = (ctype)numval(arg); \
 		else if(iscprim(arg)){ \
 			cprim_t *cp = (cprim_t*)ptr(arg); \
 			void *p = cp_data(cp); \
@@ -290,7 +290,11 @@
 #endif
 num_ctor(float, float, T_FLOAT)
 num_ctor(double, double, T_DOUBLE)
+#if defined(__plan9__)
 num_ctor(rune, uint32_t, T_UINT32)
+#else
+num_ctor(rune, int32_t, T_INT32)
+#endif
 
 static int
 cvalue_mpint_init(fltype_t *type, value_t arg, void *dest)
@@ -354,7 +358,7 @@
 toulong(value_t n)
 {
 	if(isfixnum(n))
-		return numval(n);
+		return (size_t)numval(n);
 	if(iscprim(n)){
 		cprim_t *cp = (cprim_t*)ptr(n);
 		return conv_to_ulong(cp_data(cp), cp_numtype(cp));
@@ -503,7 +507,6 @@
 {
 	size_t elsize, cnt, sz;
 	value_t arg;
-	int i;
 
 	if(nargs < 1)
 		argcount(nargs, 1);
@@ -515,6 +518,7 @@
 
 	value_t cv = cvalue(type, sz);
 	char *dest = cv_data(ptr(cv));
+	uint32_t i;
 	FOR_ARGS(i, 1, arg, args){
 		cvalue_init(type->eltype, arg, dest);
 		dest += elsize;
@@ -1487,10 +1491,10 @@
 BUILTIN("logand", logand)
 {
 	value_t v, e;
-	int i;
 	if(nargs == 0)
 		return fixnum(-1);
 	v = args[0];
+	uint32_t i;
 	FOR_ARGS(i, 1, e, args){
 		if(bothfixnums(v, e))
 			v = v & e;
@@ -1503,10 +1507,10 @@
 BUILTIN("logior", logior)
 {
 	value_t v, e;
-	int i;
 	if(nargs == 0)
 		return fixnum(0);
 	v = args[0];
+	uint32_t i;
 	FOR_ARGS(i, 1, e, args){
 		if(bothfixnums(v, e))
 			v = v | e;
@@ -1519,10 +1523,10 @@
 BUILTIN("logxor", logxor)
 {
 	value_t v, e;
-	int i;
 	if(nargs == 0)
 		return fixnum(0);
 	v = args[0];
+	uint32_t i;
 	FOR_ARGS(i, 1, e, args){
 		if(bothfixnums(v, e))
 			v = fixnum(numval(v) ^ numval(e));
--- a/equal.c
+++ b/equal.c
@@ -328,10 +328,10 @@
 */
 
 #ifdef BITS64
-#define MIX(a, b) int64hash((int64_t)(a) ^ (int64_t)(b));
+#define MIX(a, b) int64hash((uint64_t)(a) ^ (uint64_t)(b));
 #define doublehash(a) int64hash(a)
 #else
-#define MIX(a, b) int64to32hash(((int64_t)(a))<<32 | ((int64_t)(b)))
+#define MIX(a, b) int64to32hash(((uint64_t)(a))<<32 | ((uint64_t)(b)))
 #define doublehash(a) int64to32hash(a)
 #endif
 
--- a/flisp.c
+++ b/flisp.c
@@ -30,7 +30,7 @@
 int
 isbuiltin(value_t x)
 {
-	int i = uintval(x);
+	uint32_t i = uintval(x);
 	return tag(x) == TAG_FUNCTION && i < nelem(builtins) && builtins[i].name != nil;
 }
 
@@ -281,7 +281,7 @@
 }
 
 void *
-alloc_words(int n)
+alloc_words(uint32_t n)
 {
 	value_t *first;
 
@@ -899,7 +899,7 @@
 #pragma GCC diagnostic ignored "-Wpedantic"
 #define OP(x) op_##x:
 #define NEXT_OP goto *((uint8_t*)&&op_OP_LOADA0 + ops[op = *ip++])
-	static const int ops[] = {
+	static const intptr_t ops[] = {
 		[OP_LOADA0] = (uint8_t*)&&op_OP_LOADA0 - (uint8_t*)&&op_OP_LOADA0,
 		[OP_LOADA1] = (uint8_t*)&&op_OP_LOADA1 - (uint8_t*)&&op_OP_LOADA0,
 		[OP_LOADV] = (uint8_t*)&&op_OP_LOADV - (uint8_t*)&&op_OP_LOADA0,
@@ -1901,7 +1901,7 @@
 		uint32_t bp = top-5-sz;
 		value_t func = FL(stack)[bp];
 		const uint8_t *ip0 = cv_data((cvalue_t*)ptr(fn_bcode(func)));
-		value_t ip = ip1 - ip0 - 1; /* -1: ip1 is *after* the one that was being executed */
+		intptr_t ip = ip1 - ip0 - 1; /* -1: ip1 is *after* the one that was being executed */
 		value_t v = alloc_vector(sz+1, 0);
 		vector_elt(v, 0) = fixnum(ip);
 		vector_elt(v, 1) = func;
@@ -2032,7 +2032,7 @@
 BUILTIN("append", append)
 {
 	value_t first = FL(Nil), lst, lastcons = FL(Nil);
-	int i;
+	uint32_t i;
 	if(nargs == 0)
 		return FL(Nil);
 	fl_gc_handle(&first);
@@ -2108,7 +2108,7 @@
 		}
 		POPN(2);
 	}else{
-		int i;
+		size_t i;
 		while(FL(sp)+nargs+1 > FL(nstack))
 			grow_stack();
 		PUSH(FL(stack)[argSP]);
@@ -2292,7 +2292,7 @@
 fl_load_system_image(value_t sys_image_iostream)
 {
 	value_t e;
-	int saveSP;
+	uint32_t saveSP;
 	symbol_t *sym;
 
 	PUSH(sys_image_iostream);
--- a/flisp.h
+++ b/flisp.h
@@ -66,7 +66,7 @@
 	int  nargs;
 };
 
-typedef value_t (*builtin_t)(value_t*, int);
+typedef value_t (*builtin_t)(value_t*, uint32_t);
 
 #ifdef BITS64
 #define T_FIXNUM T_INT64
@@ -201,7 +201,7 @@
 
 /* conses */
 value_t mk_cons(void);
-void *alloc_words(int n);
+void *alloc_words(uint32_t n);
 
 char *uint2str(char *dest, size_t len, uint64_t num, uint32_t base);
 
@@ -298,7 +298,7 @@
 }function_t;
 
 #define CPRIM_NWORDS 2
-#define cv_class(cv) ((fltype_t*)(((uintptr_t)((cvalue_t*)cv)->type)&~3))
+#define cv_class(cv) ((fltype_t*)(((uintptr_t)((cvalue_t*)cv)->type)&~(uintptr_t)3))
 #define cv_len(cv) (((cvalue_t*)(cv))->len)
 #define cv_type(cv) (cv_class(cv)->type)
 #define cv_data(cv) (((cvalue_t*)(cv))->data)
@@ -315,7 +315,7 @@
 #define cptr(v) (iscprim(v) ? cp_data(ptr(v)) : cv_data(ptr(v)))
 
 #define BUILTIN(lname, cname) \
-	value_t fn_builtin_##cname(value_t *args, int nargs)
+	value_t fn_builtin_##cname(value_t *args, uint32_t nargs)
 
 #define BUILTIN_FN(l, c) extern BUILTIN(l, c);
 #include "builtin_fns.h"
--- a/flmain.c
+++ b/flmain.c
@@ -41,7 +41,7 @@
 
 	fl_init(512*1024);
 
-	value_t f = cvalue(FL(iostreamtype), sizeof(ios_t));
+	value_t f = cvalue(FL(iostreamtype), (int)sizeof(ios_t));
 	ios_t *s = value2c(ios_t*, f);
 	ios_static_buffer(s, boot, bootsz);
 
--- a/iostream.c
+++ b/iostream.c
@@ -78,7 +78,8 @@
 {
 	if(nargs < 1)
 		argcount(nargs, 1);
-	int i, r = 0, w = 0, c = 0, t = 0, a = 0;
+	size_t i;
+	int r = 0, w = 0, c = 0, t = 0, a = 0;
 	for(i = 1; i < nargs; i++){
 		if(args[i] == FL(rdsym))
 			r = 1;
@@ -317,7 +318,7 @@
 	return FL(t);
 }
 
-static char
+static uint8_t
 get_delim_arg(value_t arg)
 {
 	size_t uldelim = toulong(arg);
@@ -326,7 +327,7 @@
 		if((iscprim(arg) && cp_class(ptr(arg)) == FL(runetype)) || uldelim > 0xff)
 			lerrorf(FL(ArgError), "delimiter out of range");
 	}
-	return (char)uldelim;
+	return (uint8_t)uldelim;
 }
 
 BUILTIN("io-readuntil", io_readuntil)
@@ -338,7 +339,7 @@
 	ios_t dest;
 	ios_mem(&dest, 0);
 	ios_setbuf(&dest, data, 80, 0);
-	char delim = get_delim_arg(args[1]);
+	uint8_t delim = get_delim_arg(args[1]);
 	ios_t *src = toiostream(args[0]);
 	size_t n = ios_copyuntil(&dest, src, delim);
 	cv->len = n;
@@ -360,7 +361,7 @@
 	argcount(nargs, 3);
 	ios_t *dest = toiostream(args[0]);
 	ios_t *src = toiostream(args[1]);
-	char delim = get_delim_arg(args[2]);
+	uint8_t delim = get_delim_arg(args[2]);
 	return size_wrap(ios_copyuntil(dest, src, delim));
 }
 
--- a/meson.build
+++ b/meson.build
@@ -52,8 +52,6 @@
 	'3rd/mp/mpvectscmp.c',
 	'3rd/mp/strtomp.c',
 	'3rd/mp/u16.c',
-	'3rd/mp/u32.c',
-	'3rd/mp/u64.c',
 	'3rd/spooky.c',
 	'3rd/utf/rune.c',
 	'3rd/utf/runeistype.c',
--- a/operators.c
+++ b/operators.c
@@ -73,17 +73,17 @@
 conv_to_##name(void *data, numerictype_t tag) \
 { \
 	switch(tag){ \
-	case T_INT8:   return *(int8_t*)data; \
-	case T_UINT8:  return *(uint8_t*)data; \
-	case T_INT16:  return *(int16_t*)data; \
-	case T_UINT16: return *(uint16_t*)data; \
-	case T_INT32:  return *(int32_t*)data; \
-	case T_UINT32: return *(uint32_t*)data; \
-	case T_INT64:  return *(int64_t*)data; \
-	case T_UINT64: return *(uint64_t*)data; \
-	case T_MPINT:  return mptov(*(mpint**)data); \
-	case T_FLOAT:  return *(float*)data; \
-	case T_DOUBLE: return *(double*)data; \
+	case T_INT8:   return (ctype)*(int8_t*)data; \
+	case T_UINT8:  return (ctype)*(uint8_t*)data; \
+	case T_INT16:  return (ctype)*(int16_t*)data; \
+	case T_UINT16: return (ctype)*(uint16_t*)data; \
+	case T_INT32:  return (ctype)*(int32_t*)data; \
+	case T_UINT32: return (ctype)*(uint32_t*)data; \
+	case T_INT64:  return (ctype)*(int64_t*)data; \
+	case T_UINT64: return (ctype)*(uint64_t*)data; \
+	case T_MPINT:  return (ctype)mptov(*(mpint**)data); \
+	case T_FLOAT:  return (ctype)*(float*)data; \
+	case T_DOUBLE: return (ctype)*(double*)data; \
 	} \
 	return 0; \
 }
--- a/posix/mp.h
+++ b/posix/mp.h
@@ -1,12 +1,6 @@
 #pragma once
 
 typedef uint32_t mpdigit;
-typedef uint8_t uchar;
-typedef uint32_t u32int;
-typedef unsigned int uint;
-typedef int64_t vlong;
-typedef uint64_t uvlong;
-typedef uint64_t u64int;
 
 typedef union FPdbleword FPdbleword;
 union FPdbleword
@@ -14,11 +8,11 @@
 	double	x;
 	struct {
 #if BYTE_ORDER == LITTLE_ENDIAN
-		uint lo;
-		uint hi;
+		uint32_t lo;
+		uint32_t hi;
 #else
-		uint hi;
-		uint lo;
+		uint32_t hi;
+		uint32_t lo;
 #endif
 	};
 };
@@ -29,7 +23,7 @@
 #define DIGITS(x) ((Dbits - 1 + (x))/Dbits)
 
 // for converting between int's and mpint's
-#define MAXUINT ((uint)-1)
+#define MAXUINT ((uint32_t)-1)
 #define MAXINT (MAXUINT>>1)
 #define MININT (MAXINT+1)
 
@@ -38,20 +32,8 @@
 #define MAXVLONG (MAXUVLONG>>1)
 #define MINVLONG (MAXVLONG+1ULL)
 
-extern	int	dec64(uchar*, int, char*, int);
-extern	int	enc64(char*, int, uchar*, int);
-extern	int	dec64x(uchar*, int, char*, int, int (*)(int));
-extern	int	enc64x(char*, int, uchar*, int, int (*)(int));
-extern	int	dec32(uchar*, int, char*, int);
-extern	int	enc32(char*, int, uchar*, int);
-extern	int	dec32x(uchar*, int, char*, int, int (*)(int));
-extern	int	enc32x(char*, int, uchar*, int, int (*)(int));
-extern	int	dec16(uchar*, int, char*, int);
-extern	int	enc16(char*, int, uchar*, int);
-extern	int	dec64chr(int);
-extern	int	enc64chr(int);
-extern	int	dec32chr(int);
-extern	int	enc32chr(int);
+extern	int	dec16(uint8_t*, int, char*, int);
+extern	int	enc16(char*, int, uint8_t*, int);
 extern	uint32_t	dec16chr(int);
 extern	int	enc16chr(int);
 
@@ -65,8 +47,8 @@
 struct mpint
 {
 	int	sign;	/* +1 or -1 */
-	int	size;	/* allocated digits */
-	int	top;	/* significant digits */
+	uint32_t	size;	/* allocated digits */
+	uint32_t	top;	/* significant digits */
 	mpdigit	*p;
 	char	flags;
 };
@@ -86,33 +68,33 @@
 void	mpsetminbits(int n);	/* newly created mpint's get at least n bits */
 mpint*	mpnew(int n);		/* create a new mpint with at least n bits */
 void	mpfree(mpint *b);
-void	mpbits(mpint *b, int n);	/* ensure that b has at least n bits */
+void	mpbits(mpint *b, uint32_t n);	/* ensure that b has at least n bits */
 mpint*	mpnorm(mpint *b);		/* dump leading zeros */
 mpint*	mpcopy(mpint *b);
 void	mpassign(mpint *old, mpint *new);
 
 /* random bits */
-mpint*	mprand(int bits, void (*gen)(uchar*, int), mpint *b);
+mpint*	mprand(int bits, void (*gen)(uint8_t*, int), mpint *b);
 /* return uniform random [0..n-1] */
-mpint*	mpnrand(mpint *n, void (*gen)(uchar*, int), mpint *b);
+mpint*	mpnrand(mpint *n, void (*gen)(uint8_t*, int), mpint *b);
 
 /* conversion */
 mpint*	strtomp(const char*, char**, int, mpint*);	/* ascii */
 char*	mptoa(mpint*, int, char*, int);
-mpint*	letomp(uchar*, uint, mpint*);	/* byte array, little-endian */
-int	mptole(mpint*, uchar*, uint, uchar**);
-void	mptolel(mpint *b, uchar *p, int n);
-mpint*	betomp(uchar*, uint, mpint*);	/* byte array, big-endian */
-int	mptobe(mpint*, uchar*, uint, uchar**);
-void	mptober(mpint *b, uchar *p, int n);
-uint	mptoui(mpint*);			/* unsigned int */
-mpint*	uitomp(uint, mpint*);
+mpint*	letomp(uint8_t*, uint32_t, mpint*);	/* byte array, little-endian */
+int	mptole(mpint*, uint8_t*, uint32_t, uint8_t**);
+void	mptolel(mpint *b, uint8_t *p, int n);
+mpint*	betomp(uint8_t*, uint32_t, mpint*);	/* byte array, big-endian */
+int	mptobe(mpint*, uint8_t*, uint32_t, uint8_t**);
+void	mptober(mpint *b, uint8_t *p, int n);
+uint32_t	mptoui(mpint*);			/* unsigned int */
+mpint*	uitomp(uint32_t, mpint*);
 int	mptoi(mpint*);			/* int */
 mpint*	itomp(int, mpint*);
-uvlong	mptouv(mpint*);			/* unsigned vlong */
-mpint*	uvtomp(uvlong, mpint*);
-vlong	mptov(mpint*);			/* vlong */
-mpint*	vtomp(vlong, mpint*);
+uint64_t	mptouv(mpint*);			/* unsigned int64_t */
+mpint*	uvtomp(uint64_t, mpint*);
+int64_t	mptov(mpint*);			/* int64_t */
+mpint*	vtomp(int64_t, mpint*);
 double	mptod(mpint*);			/* double */
 mpint*	dtomp(double, mpint*);
 
@@ -135,8 +117,6 @@
 void	mpor(mpint *b1, mpint *b2, mpint *res);
 void	mpnot(mpint *b, mpint *res);
 void	mpxor(mpint *b1, mpint *b2, mpint *res);
-void	mptrunc(mpint *b, int n, mpint *res);
-void	mpxtend(mpint *b, int n, mpint *res);
 void	mpasr(mpint *b, int shift, mpint *res);
 
 /* modular arithmetic, time invariant when 0≤b1≤m-1 and 0≤b2≤m-1 */
@@ -160,8 +140,8 @@
 void	mpinvert(mpint *b, mpint *m, mpint *res);
 
 /* bit counting */
-int	mpsignif(mpint*);	/* number of sigificant bits in mantissa */
-int	mplowbits0(mpint*);	/* k, where n = 2**k * q for odd q */
+uint32_t	mpsignif(mpint*);	/* number of sigificant bits in mantissa */
+uint32_t	mplowbits0(mpint*);	/* k, where n = 2**k * q for odd q */
 
 /* well known constants */
 extern mpint	*mpzero, *mpone, *mptwo;
--- a/posix/platform.h
+++ b/posix/platform.h
@@ -25,8 +25,8 @@
 #include <wctype.h>
 #include <wchar.h>
 
-#define LLT_ALLOC(n) malloc(n)
-#define LLT_REALLOC(p, n) realloc((p), (n))
+#define LLT_ALLOC(n) malloc((size_t)(n))
+#define LLT_REALLOC(p, n) realloc((p), (size_t)(n))
 #define LLT_FREE(x) free(x)
 #define LLT_STRDUP(s) strdup(s)
 
--- a/posix/utf.h
+++ b/posix/utf.h
@@ -7,7 +7,7 @@
 	UTFmax = 4,
 };
 
-typedef uint32_t Rune;
+typedef int32_t Rune;
 
 int chartorune(Rune *rune, const char *str);
 int runetochar(char *str, const Rune *rune);
--- a/string.c
+++ b/string.c
@@ -120,11 +120,11 @@
 	value_t arg, buf = fn_builtin_buffer(nil, 0);
 	fl_gc_handle(&buf);
 	ios_t *s = value2c(ios_t*, buf);
-	int i;
 	value_t oldpr = symbol_value(FL(printreadablysym));
 	value_t oldpp = symbol_value(FL(printprettysym));
 	set(FL(printreadablysym), FL(f));
 	set(FL(printprettysym), FL(f));
+	uint32_t i;
 	FOR_ARGS(i, 0, arg, args){
 		USED(arg);
 		fl_print(s, args[i]);
--- a/table.c
+++ b/table.c
@@ -100,7 +100,7 @@
 		nt = cvalue(FL(tabletype), 2*sizeof(void*));
 	htable_t *h = (htable_t*)cv_data((cvalue_t*)ptr(nt));
 	htable_new(h, cnt/2);
-	int i;
+	size_t i;
 	value_t k = FL(Nil), arg;
 	FOR_ARGS(i, 0, arg, args){
 		if(i & 1)