Build the Basic run-time library (after some modernisation).

--HG--
branch : dtrg-buildsystem
This commit is contained in:
David Given 2013-05-14 16:11:29 +01:00
parent a68b117e96
commit d5f0107746
24 changed files with 89 additions and 381 deletions

View file

@ -54,6 +54,7 @@ include util/led/build.mk
include util/topgen/build.mk
include lang/cem/build.mk
include lang/basic/build.mk
include mach/proto/as/build.mk
include mach/proto/ncg/build.mk

View file

@ -33,7 +33,7 @@ define ackfile-rule
$o: $s $(ACK) \
$(CCOMPILER) \
$(PLATFORM_$(PLATFORM)) \
$(EM_ENCODE)
$(ACK_CORE_TOOLS)
@echo ACK $o
@mkdir -p $(dir $o)
$(hide) ACKDIR=$(INSDIR) $(ACK) $(ACKFLAGS) $(ackflags) -m$(PLATFORM) -c -o $o $s

4
lang/basic/build.mk Normal file
View file

@ -0,0 +1,4 @@
include lang/basic/lib/build.mk
#include lang/cem/cemcom.ansi/build.mk
#include lang/cem/libcc.ansi/build.mk

View file

@ -7,62 +7,7 @@
/* $Id$ */
#define __NO_DEFS
#include <math.h>
double
_atn(x)
double x;
{
/* Algorithm and coefficients from:
"Software manual for the elementary functions"
by W.J. Cody and W. Waite, Prentice-Hall, 1980
*/
double _atn(double x) { return atan(x); }
static double p[] = {
-0.13688768894191926929e+2,
-0.20505855195861651981e+2,
-0.84946240351320683534e+1,
-0.83758299368150059274e+0
};
static double q[] = {
0.41066306682575781263e+2,
0.86157349597130242515e+2,
0.59578436142597344465e+2,
0.15024001160028576121e+2,
1.0
};
static double a[] = {
0.0,
0.52359877559829887307710723554658381, /* pi/6 */
M_PI_2,
1.04719755119659774615421446109316763 /* pi/3 */
};
int neg = x < 0;
int n;
double g;
if (neg) {
x = -x;
}
if (x > 1.0) {
x = 1.0/x;
n = 2;
}
else n = 0;
if (x > 0.26794919243112270647) { /* 2-sqtr(3) */
n = n + 1;
x = (((0.73205080756887729353*x-0.5)-0.5)+x)/
(1.73205080756887729353+x);
}
/* ??? avoid underflow ??? */
g = x * x;
x += x * g * POLYNOM3(g, p) / POLYNOM4(g, q);
if (n > 1) x = -x;
x += a[n];
return neg ? -x : x;
}

48
lang/basic/lib/build.mk Normal file
View file

@ -0,0 +1,48 @@
define build-runtime-libbasic-impl
$(call reset)
$(eval objdir := $(PLATFORM))
$(call ackfile, lang/basic/lib/fif.e)
$(call ackfile, lang/basic/lib/fef.e)
$(call ackfile, lang/basic/lib/setline.e)
$(call ackfile, lang/basic/lib/abs.c)
$(call ackfile, lang/basic/lib/asc.c)
$(call ackfile, lang/basic/lib/asrt.c)
$(call ackfile, lang/basic/lib/atn.c)
$(call ackfile, lang/basic/lib/chr.c)
$(call ackfile, lang/basic/lib/conversion.c)
$(call ackfile, lang/basic/lib/error.c)
$(call ackfile, lang/basic/lib/exp.c)
$(call ackfile, lang/basic/lib/file.c)
$(call ackfile, lang/basic/lib/hlt.c)
$(call ackfile, lang/basic/lib/io.c)
$(call ackfile, lang/basic/lib/log.c)
$(call ackfile, lang/basic/lib/mki.c)
$(call ackfile, lang/basic/lib/oct.c)
$(call ackfile, lang/basic/lib/peek.c)
$(call ackfile, lang/basic/lib/power.c)
$(call ackfile, lang/basic/lib/print.c)
$(call ackfile, lang/basic/lib/random.c)
$(call ackfile, lang/basic/lib/read.c)
$(call ackfile, lang/basic/lib/return.c)
$(call ackfile, lang/basic/lib/salloc.c)
$(call ackfile, lang/basic/lib/sgn.c)
$(call ackfile, lang/basic/lib/sin.c)
$(call ackfile, lang/basic/lib/sqt.c)
$(call ackfile, lang/basic/lib/stop.c)
$(call ackfile, lang/basic/lib/string.c)
$(call ackfile, lang/basic/lib/swap.c)
$(call ackfile, lang/basic/lib/trace.c)
$(call ackfile, lang/basic/lib/trap.c)
$(call ackfile, lang/basic/lib/write.c)
$(call acklibrary, $(LIBDIR)/$(PLATFORM)/libbasic.a)
$(call installto, $(PLATIND)/$(PLATFORM)/libbasic.a)
endef
build-runtime-libbasic = $(eval $(build-runtime-libbasic-impl))
$(eval RUNTIMES += libbasic)

View file

@ -1,4 +1,5 @@
/* $Id$ */
#include <stdlib.h>
#include <stdio.h>
/* error takes an error value in the range of 0-255 */
/* and generates a trap */

View file

@ -10,88 +10,7 @@
#define __NO_DEFS
#include <math.h>
static double
ldexp(fl,exp)
double fl;
int exp;
double _exp(double x)
{
extern double _fef();
int sign = 1;
int currexp;
if (fl<0) {
fl = -fl;
sign = -1;
}
fl = _fef(fl,&currexp);
exp += currexp;
if (exp > 0) {
while (exp>30) {
fl *= (double) (1L << 30);
exp -= 30;
}
fl *= (double) (1L << exp);
}
else {
while (exp<-30) {
fl /= (double) (1L << 30);
exp += 30;
}
fl /= (double) (1L << -exp);
}
return sign * fl;
}
double
_exp(x)
double x;
{
/* Algorithm and coefficients from:
"Software manual for the elementary functions"
by W.J. Cody and W. Waite, Prentice-Hall, 1980
*/
static double p[] = {
0.25000000000000000000e+0,
0.75753180159422776666e-2,
0.31555192765684646356e-4
};
static double q[] = {
0.50000000000000000000e+0,
0.56817302698551221787e-1,
0.63121894374398503557e-3,
0.75104028399870046114e-6
};
double xn, g;
int n;
int negative = x < 0;
if (x <= M_LN_MIN_D) {
return M_MIN_D;
}
if (x >= M_LN_MAX_D) {
if (x > M_LN_MAX_D) error(3);
return M_MAX_D;
}
if (negative) x = -x;
/* ??? avoid underflow ??? */
n = x * M_LOG2E + 0.5; /* 1/ln(2) = log2(e), 0.5 added for rounding */
xn = n;
{
double x1 = (long) x;
double x2 = x - x1;
g = ((x1-xn*0.693359375)+x2) - xn*(-2.1219444005469058277e-4);
}
if (negative) {
g = -g;
n = -n;
}
xn = g * g;
x = g * POLYNOM2(xn, p);
n += 1;
return (ldexp(0.5 + x/(POLYNOM3(xn, q) - x), n));
return exp(x);
}

View file

@ -1,4 +1,4 @@
/* $Id$ */
#include <stdlib.h>
_hlt(nr)
int nr;

View file

@ -1,9 +1,8 @@
#include "bc_io.h"
#include <sgtty.h>
/* $Id$ */
struct sgttyb _ttydef;
/* dtrg --- this originally used sgtty.h to do clever tty manipulation.
* Strictly this should be converted to use termios, but for simplicity
* we're going to stick with plain stdio for now. */
/* BASIC has some nasty io characteristics */
@ -65,9 +64,6 @@ char *buf;
if( _chann == -1)
{
pos= _pos;
gtty(0,_ttydef);
_ttydef.sg_flags &= ~ECHO;
stty(0,_ttydef);
}else pos= _fdtable[_chann].pos;
c= buf;
while( (holder = fgetc(_chanrd)) != EOF && holder != '\n'){
@ -79,8 +75,6 @@ char *buf;
if( _chann== -1)
{
_pos=pos;
_ttydef.sg_flags |= ECHO;
stty(0,_ttydef);
} else _fdtable[_chann].pos= pos;
}
_tab(x)

View file

@ -10,48 +10,7 @@
#define __NO_DEFS
#include <math.h>
double
_log(x)
double x;
double _log(double x)
{
/* Algorithm and coefficients from:
"Software manual for the elementary functions"
by W.J. Cody and W. Waite, Prentice-Hall, 1980
*/
static double a[] = {
-0.64124943423745581147e2,
0.16383943563021534222e2,
-0.78956112887491257267e0
};
static double b[] = {
-0.76949932108494879777e3,
0.31203222091924532844e3,
-0.35667977739034646171e2,
1.0
};
extern double _fef();
double znum, zden, z, w;
int exponent;
if (x <= 0) {
error(3);
return -HUGE;
}
x = _fef(x, &exponent);
if (x > M_1_SQRT2) {
znum = (x - 0.5) - 0.5;
zden = x * 0.5 + 0.5;
}
else {
znum = x - 0.5;
zden = znum * 0.5 + 0.5;
exponent--;
}
z = znum/zden; w = z * z;
x = z + z * w * (POLYNOM2(w,a)/POLYNOM3(w,b));
z = exponent;
x += z * (-2.121944400546905827679e-4);
return x + z * 0.693359375;
return log(x);
}

View file

@ -1,3 +1,5 @@
#include <stdlib.h>
#include <stdio.h>
#include "bc_string.h"
/* $Id$ */

View file

@ -1,32 +1,4 @@
/* $Id$ */
#include <math.h>
/*
computes a^b.
uses log and exp
*/
double _power(double x, double y) { return pow(x, y); }
double _log(), _exp();
double
_power(base,pownr)
double pownr, base;
{
double temp;
long l;
if(pownr <= 0.0) {
if(pownr == 0.0) {
if(base <= 0.0)
error(3);
return(0.0);
}
l = base;
if(l != base)
error(3);
temp = _exp(base * _log(-pownr));
if(l & 1)
temp = -temp;
return(temp);
}
return(_exp(base * _log(pownr)));
}

View file

@ -1,3 +1,5 @@
#include <stdlib.h>
#include <stdio.h>
#include "bc_string.h"
#include "bc_io.h"

View file

@ -1,4 +1,5 @@
/* $Id$ */
#include <stdlib.h>
#include <stdio.h>
#if !defined(EM_WSIZE)
#define EM_WSIZE _EM_WSIZE

View file

@ -1,6 +1,4 @@
/* $Id$ */
extern char *malloc() ;
#include <stdlib.h>
char * salloc(length)
unsigned length;

View file

@ -10,96 +10,7 @@
#define __NO_DEFS
#include <math.h>
static double
sinus(x, cos_flag)
double x;
{
/* Algorithm and coefficients from:
"Software manual for the elementary functions"
by W.J. Cody and W. Waite, Prentice-Hall, 1980
*/
double _sin(double x) { return sin(x); }
double _cos(double x) { return cos(x); }
double _tan(double x) { return tan(x); }
static double r[] = {
-0.16666666666666665052e+0,
0.83333333333331650314e-2,
-0.19841269841201840457e-3,
0.27557319210152756119e-5,
-0.25052106798274584544e-7,
0.16058936490371589114e-9,
-0.76429178068910467734e-12,
0.27204790957888846175e-14
};
double xsqr;
double y;
int neg = 0;
if (x < 0) {
x = -x;
neg = 1;
}
if (cos_flag) {
neg = 0;
y = M_PI_2 + x;
}
else y = x;
/* ??? avoid loss of significance, if y is too large, error ??? */
y = y * M_1_PI + 0.5;
/* Use extended precision to calculate reduced argument.
Here we used 12 bits of the mantissa for a1.
Also split x in integer part x1 and fraction part x2.
*/
#define A1 3.1416015625
#define A2 -8.908910206761537356617e-6
{
double x1, x2;
extern double _fif();
_fif(y, 1.0, &y);
if (_fif(y, 0.5, &x1)) neg = !neg;
if (cos_flag) y -= 0.5;
x2 = _fif(x, 1.0, &x1);
x = x1 - y * A1;
x += x2;
x -= y * A2;
#undef A1
#undef A2
}
if (x < 0) {
neg = !neg;
x = -x;
}
/* ??? avoid underflow ??? */
y = x * x;
x += x * y * POLYNOM7(y, r);
return neg ? -x : x;
}
double
_sin(x)
double x;
{
return sinus(x, 0);
}
double
_cos(x)
double x;
{
if (x < 0) x = -x;
return sinus(x, 1);
}
/* EXTENSION */
double
_tan(x)
double x;
{
return _sin(x)/_cos(x);
}

View file

@ -10,62 +10,5 @@
#define __NO_DEFS
#include <math.h>
#define NITER 5
double _sqt(double x) { return sqrt(x); }
static double
ldexp(fl,exp)
double fl;
int exp;
{
extern double _fef();
int sign = 1;
int currexp;
if (fl<0) {
fl = -fl;
sign = -1;
}
fl = _fef(fl,&currexp);
exp += currexp;
if (exp > 0) {
while (exp>30) {
fl *= (double) (1L << 30);
exp -= 30;
}
fl *= (double) (1L << exp);
}
else {
while (exp<-30) {
fl /= (double) (1L << 30);
exp += 30;
}
fl /= (double) (1L << -exp);
}
return sign * fl;
}
double
_sqt(x)
double x;
{
extern double _fef();
int exponent;
double val;
if (x <= 0) {
if (x < 0) error(3);
return 0;
}
val = _fef(x, &exponent);
if (exponent & 1) {
exponent--;
val *= 2;
}
val = ldexp(val + 1.0, exponent/2 - 1);
/* was: val = (val + 1.0)/2.0; val = ldexp(val, exponent/2); */
for (exponent = NITER - 1; exponent >= 0; exponent--) {
val = (val + x / val) / 2.0;
}
return val;
}

View file

@ -1,4 +1,5 @@
/* $Id$ */
#include <stdlib.h>
#include <stdio.h>
_stop()
{

View file

@ -1,3 +1,5 @@
#include <stdlib.h>
#include <string.h>
#include "bc_string.h"
/* $Id$ */

View file

@ -1,3 +1,5 @@
#include <stdlib.h>
#include <stdio.h>
#include <signal.h>
#include <setjmp.h>

View file

@ -11,6 +11,8 @@ define build-platform-impl
$(eval q := $D/descr)
$(call installto, $(PLATIND)/descr/$(PLATFORM))
$(foreach f, $(platform-headers), $(call build-platform-headers, $f))
$(eval PLATFORM_$(PLATFORM) := \
$(PLATIND)/descr/$(PLATFORM) \
$(PLATFORM_HEADERS_$(PLATFORM)) \
@ -18,8 +20,6 @@ define build-platform-impl
$(PLATDEP)/$(PLATFORM)/ncg \
$(ARCHITECTURE_$(ARCH)))
$(foreach f, $(platform-headers), $(call build-platform-headers, $f))
# libsys
$(call reset)

View file

@ -14,6 +14,7 @@ define build-aal-impl
$(call cprogram, $(BINDIR)/aal)
$(call installto, $(INSDIR)/bin/aal)
$(eval AAL := $o)
$(eval ACK_CORE_TOOLS += $o)
$(call reset)
$(eval q := $D/aal.1)

View file

@ -24,6 +24,7 @@ define build-misc-impl
$(call cprogram, $(BINDIR)/em_encode)
$(call installto, $(PLATDEP)/em_encode)
$(eval EM_ENCODE := $o)
$(eval ACK_CORE_TOOLS += $o)
$(call reset)
$(eval objdir := decode)

View file

@ -67,6 +67,7 @@ $(eval $q: $(INCDIR)/em_spec.h)
$(call cprogram, $(BINDIR)/em_opt)
$(call installto, $(PLATDEP)/em_opt)
$(eval EM_OPT := $o)
$(eval ACK_CORE_TOOLS += $o)
$(call reset)
$(eval q := $D/em_opt.6)