ref: bd6157cf317c95546a015c2f764d096b13d4491a
parent: 33ccdc7f42803457a2bbb11eeb633f9dbafd6e9f
author: Sigrid Solveig Haflínudóttir <[email protected]>
date: Wed Feb 23 15:31:27 EST 2022
stop using ms extensions (does not work on openbsd with clang)
--- a/Makefile
+++ b/Makefile
@@ -2,7 +2,7 @@
DESTDIR?=
PREFIX?=/usr/local
CFLAGS?=-g -O2
-CFLAGS+=-Iinclude -Wall -Wno-missing-braces -Wno-parentheses -Wno-incompatible-pointer-types -fms-extensions
+CFLAGS+=-Iinclude -Wall -Wno-missing-braces -Wno-parentheses -Wno-incompatible-pointer-types
OFILES=\
libc/dofmt.o\
--- a/pc.y
+++ b/pc.y
@@ -13,9 +13,9 @@
typedef struct Num Num;
struct Num {
- mpint;
+ mpint i;
int b;
- Ref;
+ Ref r;
};
enum { STRONG = 0x100 };
@@ -55,8 +55,8 @@
Num *r;
r = emalloc(sizeof(Num));
- r->ref = 1;
- r->p = emalloc(sizeof(mpdigit));
+ r->r.ref = 1;
+ r->i.p = emalloc(sizeof(mpdigit));
mpassign(mpzero, r);
return r;
}
@@ -64,7 +64,7 @@
Num *
numincref(Num *n)
{
- incref(n);
+ incref(&n->r);
return n;
}
@@ -72,8 +72,8 @@
numdecref(Num *n)
{
if(n == nil) return nil;
- if(decref(n) == 0){
- free(n->p);
+ if(decref(&n->r) == 0){
+ free(n->i.p);
free(n);
return nil;
}
@@ -86,7 +86,7 @@
Num *m;
if(n == nil) return nil;
- if(n->ref == 1) return n;
+ if(n->r.ref == 1) return n;
m = numalloc();
mpassign(n, m);
m->b = n->b;
@@ -185,7 +185,7 @@
case 2: st = 1; sp = 2; break;
default: st = 0; sp = 0;
}
- if(n->sign < 0)
+ if(n->i.sign < 0)
sp++;
if(st != 0)
printhead(mpsignif(n), st, sp, q);
@@ -413,7 +413,7 @@
| '-' expr %prec unary { $$ = nummod($2); if($$ != nil) mpsub(mpzero, $$, $$); }
| '~' expr %prec unary { $$ = nummod($2); if($$ != nil) mpnot($$, $$); }
| '!' expr %prec unary { $$ = nummod($2); if($$ != nil) {itomp(mpcmp($$, mpzero) == 0, $$); $$->b = 0; } }
- | '$' expr { $$ = nummod($2); if($$ != nil) {if($2->sign > 0) mpxtend($2, mpsignif($2), $$); else mpassign($2, $$); } }
+ | '$' expr { $$ = nummod($2); if($$ != nil) {if($2->i.sign > 0) mpxtend($2, mpsignif($2), $$); else mpassign($2, $$); } }
| expr '?' expr ':' expr %prec '?' {
if($1 == nil || mpcmp($1, mpzero) != 0){
$$ = $3;
@@ -513,7 +513,7 @@
r = mpnew(0);
mpdiv(a, b, a, r);
if(!divmode && r->sign < 0){
- if(b->sign > 0)
+ if(b->i.sign > 0)
mpsub(a, mpone, a);
else
mpadd(a, mpone, a);
@@ -527,8 +527,8 @@
return error("division by zero");
}
mpdiv(a, b, nil, a);
- if(!divmode && a->sign < 0){
- if(b->sign > 0)
+ if(!divmode && a->i.sign < 0){
+ if(b->i.sign > 0)
mpadd(a, b, a);
else
mpsub(a, b, a);
@@ -547,7 +547,7 @@
break;
case LOLSH:
if(mpsignif(b) >= 31){
- if(b->sign > 0)
+ if(b->i.sign > 0)
error("left shift overflow");
itomp(-(mpcmp(a, mpzero) < 0), a);
}else
@@ -555,7 +555,7 @@
break;
case LORSH:
if(mpsignif(b) >= 31){
- if(b->sign < 0)
+ if(b->i.sign < 0)
error("right shift overflow");
itomp(-(mpcmp(a, mpzero) < 0), a);
}else
@@ -749,7 +749,7 @@
Num *r;
r = nummod(a[0]);
- r->sign = 1;
+ r->i.sign = 1;
return r;
}
@@ -772,7 +772,7 @@
mpleft(r, 1, r);
i = mpcmp(r, a[1]);
mpright(r, 1, r);
- if(i > 0 || i == 0 && (a[0]->sign < 0) ^ (q->top != 0 && (q->p[0] & 1) != 0))
+ if(i > 0 || i == 0 && (a[0]->i.sign < 0) ^ (q->top != 0 && (q->p[0] & 1) != 0))
mpsub(r, a[1], r);
mpsub(a[0], r, a[0]);
mpfree(q);
@@ -886,7 +886,7 @@
Num *
fnubits(int unused, Num **a)
{
- if(a[0]->sign < 0){
+ if(a[0]->i.sign < 0){
numdecref(a[0]);
return error("invalid argument");
}
@@ -900,7 +900,7 @@
fnsbits(int unused, Num **a)
{
a[0] = nummod(a[0]);
- if(a[0]->sign < 0) mpadd(a[0], mpone, a[0]);
+ if(a[0]->i.sign < 0) mpadd(a[0], mpone, a[0]);
itomp(mpsignif(a[0]) + 1, a[0]);
a[0]->b = 0;
return a[0];
@@ -913,13 +913,13 @@
mpdigit d;
a[0] = nummod(a[0]);
- if(a[0]->sign < 0){
+ if(a[0]->i.sign < 0){
numdecref(a[0]);
return error("invalid argument");
}
n = 0;
- for(i = 0; i < a[0]->top; i++){
- d = a[0]->p[i];
+ for(i = 0; i < a[0]->i.top; i++){
+ d = a[0]->i.p[i];
for(; d != 0; d &= d-1)
n++;
}
@@ -979,21 +979,21 @@
}
a[0] = nummod(a[0]);
mptrunc(a[0], n, a[0]);
- for(i = 0; i < a[0]->top; i++){
- v = a[0]->p[i];
+ for(i = 0; i < a[0]->i.top; i++){
+ v = a[0]->i.p[i];
m = -1;
for(j = sizeof(mpdigit) * 8; j >>= 1; ){
m ^= m << j;
v = v >> j & m | v << j & ~m;
}
- a[0]->p[i] = v;
+ a[0]->i.p[i] = v;
}
- for(i = 0; i < a[0]->top / 2; i++){
- v = a[0]->p[i];
- a[0]->p[i] = a[0]->p[a[0]->top - 1 - i];
- a[0]->p[a[0]->top - 1 - i] = v;
+ for(i = 0; i < a[0]->i.top / 2; i++){
+ v = a[0]->i.p[i];
+ a[0]->i.p[i] = a[0]->i.p[a[0]->i.top - 1 - i];
+ a[0]->i.p[a[0]->i.top - 1 - i] = v;
}
- mpleft(a[0], n - a[0]->top * sizeof(mpdigit) * 8, a[0]);
+ mpleft(a[0], n - a[0]->i.top * sizeof(mpdigit) * 8, a[0]);
numdecref(a[1]);
return a[0];
}
@@ -1016,7 +1016,7 @@
for(i = 0; i < n; i += 2){
if(toint(a[i+1], &w, 1)) goto fail;
mpleft(r, w, r);
- if(a[i]->sign < 0 || mpsignif(a[i]) > w){
+ if(a[i]->i.sign < 0 || mpsignif(a[i]) > w){
a[i] = nummod(a[i]);
mptrunc(a[i], w, a[i]);
}