diff --git a/Makefile b/Makefile index 98f36bef3..52e792e64 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/first/core.mk b/first/core.mk index 143748d98..f1530d4d9 100644 --- a/first/core.mk +++ b/first/core.mk @@ -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 diff --git a/lang/basic/build.mk b/lang/basic/build.mk new file mode 100644 index 000000000..9a61c3578 --- /dev/null +++ b/lang/basic/build.mk @@ -0,0 +1,4 @@ +include lang/basic/lib/build.mk +#include lang/cem/cemcom.ansi/build.mk +#include lang/cem/libcc.ansi/build.mk + diff --git a/lang/basic/lib/atn.c b/lang/basic/lib/atn.c index db53b81bd..18c4dc6ef 100644 --- a/lang/basic/lib/atn.c +++ b/lang/basic/lib/atn.c @@ -7,62 +7,7 @@ /* $Id$ */ -#define __NO_DEFS #include -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; -} diff --git a/lang/basic/lib/build.mk b/lang/basic/lib/build.mk new file mode 100644 index 000000000..9f54a4b4e --- /dev/null +++ b/lang/basic/lib/build.mk @@ -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) + diff --git a/lang/basic/lib/error.c b/lang/basic/lib/error.c index 6d8f9aa3c..b2d893adc 100644 --- a/lang/basic/lib/error.c +++ b/lang/basic/lib/error.c @@ -1,4 +1,5 @@ -/* $Id$ */ +#include +#include /* error takes an error value in the range of 0-255 */ /* and generates a trap */ diff --git a/lang/basic/lib/exp.c b/lang/basic/lib/exp.c index 32cb9eff9..c16344e56 100644 --- a/lang/basic/lib/exp.c +++ b/lang/basic/lib/exp.c @@ -10,88 +10,7 @@ #define __NO_DEFS #include -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); } diff --git a/lang/basic/lib/hlt.c b/lang/basic/lib/hlt.c index 3ba8a681f..20f4d5276 100644 --- a/lang/basic/lib/hlt.c +++ b/lang/basic/lib/hlt.c @@ -1,4 +1,4 @@ -/* $Id$ */ +#include _hlt(nr) int nr; diff --git a/lang/basic/lib/io.c b/lang/basic/lib/io.c index b7343e278..e0d7581f0 100644 --- a/lang/basic/lib/io.c +++ b/lang/basic/lib/io.c @@ -1,9 +1,8 @@ #include "bc_io.h" -#include -/* $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) diff --git a/lang/basic/lib/log.c b/lang/basic/lib/log.c index 06833cd0a..e194f51d7 100644 --- a/lang/basic/lib/log.c +++ b/lang/basic/lib/log.c @@ -10,48 +10,7 @@ #define __NO_DEFS #include -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); } diff --git a/lang/basic/lib/oct.c b/lang/basic/lib/oct.c index 29a9040c3..ea73bc11d 100644 --- a/lang/basic/lib/oct.c +++ b/lang/basic/lib/oct.c @@ -1,3 +1,5 @@ +#include +#include #include "bc_string.h" /* $Id$ */ diff --git a/lang/basic/lib/power.c b/lang/basic/lib/power.c index 517262342..4a33806cd 100644 --- a/lang/basic/lib/power.c +++ b/lang/basic/lib/power.c @@ -1,32 +1,4 @@ -/* $Id$ */ +#include -/* - 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))); -} diff --git a/lang/basic/lib/print.c b/lang/basic/lib/print.c index 4ed9806bf..a4bdebfc1 100644 --- a/lang/basic/lib/print.c +++ b/lang/basic/lib/print.c @@ -1,3 +1,5 @@ +#include +#include #include "bc_string.h" #include "bc_io.h" diff --git a/lang/basic/lib/random.c b/lang/basic/lib/random.c index 3707d1e70..17340eddb 100644 --- a/lang/basic/lib/random.c +++ b/lang/basic/lib/random.c @@ -1,4 +1,5 @@ -/* $Id$ */ +#include +#include #if !defined(EM_WSIZE) #define EM_WSIZE _EM_WSIZE diff --git a/lang/basic/lib/salloc.c b/lang/basic/lib/salloc.c index c8e36b372..ef221a273 100644 --- a/lang/basic/lib/salloc.c +++ b/lang/basic/lib/salloc.c @@ -1,6 +1,4 @@ -/* $Id$ */ - -extern char *malloc() ; +#include char * salloc(length) unsigned length; diff --git a/lang/basic/lib/sin.c b/lang/basic/lib/sin.c index b6c3daab6..6503d92e6 100644 --- a/lang/basic/lib/sin.c +++ b/lang/basic/lib/sin.c @@ -10,96 +10,7 @@ #define __NO_DEFS #include -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); -} diff --git a/lang/basic/lib/sqt.c b/lang/basic/lib/sqt.c index dbc9fa7a3..b71483ef7 100644 --- a/lang/basic/lib/sqt.c +++ b/lang/basic/lib/sqt.c @@ -10,62 +10,5 @@ #define __NO_DEFS #include -#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; -} diff --git a/lang/basic/lib/stop.c b/lang/basic/lib/stop.c index 571562a89..8ef27cabf 100644 --- a/lang/basic/lib/stop.c +++ b/lang/basic/lib/stop.c @@ -1,4 +1,5 @@ -/* $Id$ */ +#include +#include _stop() { diff --git a/lang/basic/lib/string.c b/lang/basic/lib/string.c index bc8485991..4ccc69191 100644 --- a/lang/basic/lib/string.c +++ b/lang/basic/lib/string.c @@ -1,3 +1,5 @@ +#include +#include #include "bc_string.h" /* $Id$ */ diff --git a/lang/basic/lib/trap.c b/lang/basic/lib/trap.c index 6079686d0..4bcf742ee 100644 --- a/lang/basic/lib/trap.c +++ b/lang/basic/lib/trap.c @@ -1,3 +1,5 @@ +#include +#include #include #include diff --git a/plat/build.mk b/plat/build.mk index 3f8994fc9..89acb8c2e 100644 --- a/plat/build.mk +++ b/plat/build.mk @@ -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) diff --git a/util/arch/build.mk b/util/arch/build.mk index b70893f41..4d283f881 100644 --- a/util/arch/build.mk +++ b/util/arch/build.mk @@ -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) diff --git a/util/misc/build.mk b/util/misc/build.mk index 52367113c..dfa8ac7c1 100644 --- a/util/misc/build.mk +++ b/util/misc/build.mk @@ -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) diff --git a/util/opt/build.mk b/util/opt/build.mk index bb3c464a6..9928d40cf 100644 --- a/util/opt/build.mk +++ b/util/opt/build.mk @@ -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)