Merge pull request #63 from kernigh/kernigh-rm-fix
small changes to C, Pascal, Modula-2, em_opt, getopt(), Makefile
This commit is contained in:
commit
8c80fa7334
38 changed files with 194 additions and 639 deletions
56
Makefile
56
Makefile
|
@ -63,29 +63,50 @@ PLATDEP = $(INSDIR)/lib/ack
|
||||||
|
|
||||||
.NOTPARALLEL:
|
.NOTPARALLEL:
|
||||||
|
|
||||||
MAKECMDGOALS ?= +ack +tests
|
ifeq ($(BUILDSYSTEM),)
|
||||||
BUILD_FILES = $(shell find * -name '*.lua')
|
ifneq ($(shell which ninja),)
|
||||||
|
|
||||||
ifneq ($(shell which ninja),)
|
|
||||||
BUILDSYSTEM = ninja
|
BUILDSYSTEM = ninja
|
||||||
BUILDFLAGS = $(NINJAFLAGS)
|
else
|
||||||
else
|
|
||||||
BUILDSYSTEM = make
|
BUILDSYSTEM = make
|
||||||
BUILDFLAGS = $(MAKEFLAGS)
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
LUA = $(BUILDDIR)/lua
|
build-file = $(BUILDDIR)/build.$(BUILDSYSTEM)
|
||||||
|
lua-files = $(shell find * -name '*.lua')
|
||||||
|
our-lua = $(BUILDDIR)/lua
|
||||||
|
|
||||||
ifneq ($(findstring +, $(MAKECMDGOALS)),)
|
# GNU make sets MAKECMDGOALS to the list of targets from the command
|
||||||
|
# line. We look for targets with '+' and forward them to BUILDSYSTEM.
|
||||||
|
# This handles commands like
|
||||||
|
# $ make util/opt+pkg util/ego+pkg
|
||||||
|
|
||||||
$(MAKECMDGOALS): $(BUILDDIR)/build.$(BUILDSYSTEM)
|
all-goals = +ack +tests
|
||||||
@$(BUILDSYSTEM) $(BUILDFLAGS) -f $^ $(MAKECMDGOALS)
|
plus-goals := $(patsubst all,$(all-goals),$(or $(MAKECMDGOALS),all))
|
||||||
|
plus-goals := $(foreach g,$(plus-goals),$(if $(findstring +,$(g)),$(g),))
|
||||||
|
|
||||||
|
# @true silences extra message, "make: Nothing to be done..."
|
||||||
|
|
||||||
|
all: build-plus-goals
|
||||||
|
@true
|
||||||
|
|
||||||
|
ifneq ($(plus-goals),)
|
||||||
|
$(plus-goals): build-plus-goals
|
||||||
|
@true
|
||||||
endif
|
endif
|
||||||
|
|
||||||
$(BUILDDIR)/build.$(BUILDSYSTEM): first/ackbuilder.lua Makefile $(BUILD_FILES) $(LUA)
|
build-plus-goals: $(build-file)
|
||||||
|
ifeq ($(BUILDSYSTEM),ninja)
|
||||||
|
@ninja $(NINJAFLAGS) -f $(build-file) $(plus-goals)
|
||||||
|
else ifeq ($(BUILDSYSTEM),make)
|
||||||
|
# GNU make passes MAKEFLAGS in environment.
|
||||||
|
@$(MAKE) -f $(build-file) $(plus-goals)
|
||||||
|
else
|
||||||
|
$(error unknown BUILDSYSTEM = $(BUILDSYSTEM))
|
||||||
|
endif
|
||||||
|
|
||||||
|
$(build-file): first/ackbuilder.lua Makefile $(lua-files) $(our-lua)
|
||||||
@mkdir -p $(BUILDDIR)
|
@mkdir -p $(BUILDDIR)
|
||||||
@$(LUA) first/ackbuilder.lua \
|
@$(our-lua) first/ackbuilder.lua \
|
||||||
first/build.lua build.lua \
|
first/build.lua build.lua \
|
||||||
--$(BUILDSYSTEM) \
|
--$(BUILDSYSTEM) \
|
||||||
DEFAULT_PLATFORM=$(DEFAULT_PLATFORM) \
|
DEFAULT_PLATFORM=$(DEFAULT_PLATFORM) \
|
||||||
|
@ -99,17 +120,16 @@ $(BUILDDIR)/build.$(BUILDSYSTEM): first/ackbuilder.lua Makefile $(BUILD_FILES) $
|
||||||
PREFIX=$(PREFIX) \
|
PREFIX=$(PREFIX) \
|
||||||
AR=$(AR) \
|
AR=$(AR) \
|
||||||
CC=$(CC) \
|
CC=$(CC) \
|
||||||
> $(BUILDDIR)/build.$(BUILDSYSTEM)
|
> $(build-file)
|
||||||
|
|
||||||
install:
|
install:
|
||||||
mkdir -p $(PREFIX)
|
mkdir -p $(PREFIX)
|
||||||
tar cf - -C $(INSDIR) . | tar xvf - -C $(PREFIX)
|
tar cf - -C $(INSDIR) . | tar xvf - -C $(PREFIX)
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
@rm -rf $(BUILDDIR)
|
rm -rf $(BUILDDIR)
|
||||||
|
|
||||||
$(LUA): first/lua-5.1/*.c first/lua-5.1/*.h
|
$(our-lua): first/lua-5.1/*.c first/lua-5.1/*.h
|
||||||
@echo Bootstrapping build
|
@echo Bootstrapping build
|
||||||
@mkdir -p $(BUILDDIR)
|
@mkdir -p $(BUILDDIR)
|
||||||
@$(CC) -o $(LUA) -O first/lua-5.1/*.c -lm
|
@$(CC) -o $(our-lua) -O first/lua-5.1/*.c -lm
|
||||||
|
|
||||||
|
|
8
README
8
README
|
@ -53,8 +53,6 @@ Requirements:
|
||||||
|
|
||||||
- GNU make.
|
- GNU make.
|
||||||
|
|
||||||
- Lua 5.1 and the luaposix library (used by the build system).
|
|
||||||
|
|
||||||
- (optionally) ninja; if you've got this, this will be autodetected and give
|
- (optionally) ninja; if you've got this, this will be autodetected and give
|
||||||
you faster builds.
|
you faster builds.
|
||||||
|
|
||||||
|
@ -63,9 +61,9 @@ Requirements:
|
||||||
architectures. Get both the qemu-system-* platform emulators and the qemu-*
|
architectures. Get both the qemu-system-* platform emulators and the qemu-*
|
||||||
userland emulators (only works on Linux).
|
userland emulators (only works on Linux).
|
||||||
|
|
||||||
- about 40MB free in /tmp (or some other temporary directory).
|
- about 115MB free in /tmp (or some other temporary directory).
|
||||||
|
|
||||||
- about 6MB in the target directory.
|
- about 15MB in the target directory.
|
||||||
|
|
||||||
Instructions:
|
Instructions:
|
||||||
|
|
||||||
|
@ -83,7 +81,7 @@ Instructions:
|
||||||
install ninja and it'll use all your cores. If you don't have ninja, you
|
install ninja and it'll use all your cores. If you don't have ninja, you
|
||||||
can still use make for parallel builds with:
|
can still use make for parallel builds with:
|
||||||
|
|
||||||
make MAKEFLAGS='-r -j8' # or however many cores you have
|
make -r -j8 # or however many cores you have
|
||||||
|
|
||||||
...but frankly, I recommend ninja.
|
...but frankly, I recommend ninja.
|
||||||
|
|
||||||
|
|
146
TakeAction
146
TakeAction
|
@ -1,146 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
|
|
||||||
case $# in
|
|
||||||
0) PAR='make install && make clean' ; CMD=Action ;;
|
|
||||||
1) PAR="$1" ; CMD=Action ;;
|
|
||||||
2) PAR="$1" ; CMD="$2" ;;
|
|
||||||
*) echo Syntax: "$0" [command [file]] ; exit 1 ;;
|
|
||||||
esac
|
|
||||||
if test -r "$CMD"
|
|
||||||
then :
|
|
||||||
else
|
|
||||||
case "$CMD" in
|
|
||||||
Action) echo No Action file present ;;
|
|
||||||
*) echo No Action file "($CMD)" present ;;
|
|
||||||
esac
|
|
||||||
fi
|
|
||||||
case $0 in
|
|
||||||
/*) THISFILE=$0
|
|
||||||
;;
|
|
||||||
*) if [ -f $0 ]
|
|
||||||
then
|
|
||||||
THISFILE=`pwd`/$0
|
|
||||||
else
|
|
||||||
THISFILE=$0
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
SYS=
|
|
||||||
RETC=0
|
|
||||||
{ while read LINE
|
|
||||||
do
|
|
||||||
eval set $LINE
|
|
||||||
case x"$1" in
|
|
||||||
x!*) ;;
|
|
||||||
xname) SYS="$2"
|
|
||||||
ACTION='$PAR'
|
|
||||||
DIR=.
|
|
||||||
FM=no
|
|
||||||
FAIL='Failed for $SYS, see $DIR/Out'
|
|
||||||
SUCC='$SYS -- done'
|
|
||||||
ATYPE=
|
|
||||||
FATAL=no
|
|
||||||
DOIT=yes
|
|
||||||
;;
|
|
||||||
xfatal) FATAL=yes ;;
|
|
||||||
xaction|xindir) case x$ATYPE in
|
|
||||||
x) ACTION=$2 ; ATYPE=$1
|
|
||||||
case $ATYPE$FM in
|
|
||||||
indirno) FAIL='Failed for $SYS' ;;
|
|
||||||
esac
|
|
||||||
;;
|
|
||||||
*) echo Already specified an $ATYPE for this name
|
|
||||||
RETC=65 ;;
|
|
||||||
esac ;;
|
|
||||||
xfailure) FM=yes
|
|
||||||
FAIL="$2" ;;
|
|
||||||
xsuccess) SUCC="$2" ;;
|
|
||||||
xdir) DIR="$2" ;;
|
|
||||||
xsystem) PAT="$2"
|
|
||||||
oIFS=$IFS
|
|
||||||
IFS="|"
|
|
||||||
eval set $2
|
|
||||||
case x`ack_sys` in
|
|
||||||
x$1|x$2|x$3|x$4|x$5|x$6|x$7) ;;
|
|
||||||
*) echo "Sorry, $SYS can only be made on $PAT systems"
|
|
||||||
DOIT=no
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
IFS=$oIFS
|
|
||||||
;;
|
|
||||||
xend) case $DOIT in
|
|
||||||
no) continue ;;
|
|
||||||
esac
|
|
||||||
case x$SYS in
|
|
||||||
x) echo Missing name line; RETC=65 ;;
|
|
||||||
*) if test -d $DIR
|
|
||||||
then (
|
|
||||||
cd $DIR
|
|
||||||
X=
|
|
||||||
case $ATYPE in
|
|
||||||
indir)
|
|
||||||
if $THISFILE "$PAR" $ACTION
|
|
||||||
then eval echo $SUCC
|
|
||||||
else RETC=2 ; eval echo $FAIL
|
|
||||||
fi ;;
|
|
||||||
*)
|
|
||||||
case "$ACTION" in
|
|
||||||
'$PAR')
|
|
||||||
ACTION="$PAR"
|
|
||||||
;;
|
|
||||||
*) ;;
|
|
||||||
esac
|
|
||||||
if [ -f No$CMD ]
|
|
||||||
then
|
|
||||||
x=`cat No$CMD`
|
|
||||||
if [ "$ACTION" = "$x" ]
|
|
||||||
then
|
|
||||||
ACTION='echo "No actions performed, No$CMD file present"'
|
|
||||||
SUCC='$SYS -- skipped'
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
if eval "{ $ACTION ; } >Out 2>&1 </dev/null"
|
|
||||||
then eval echo $SUCC
|
|
||||||
if [ "$SUCC" = '$SYS -- skipped' ]
|
|
||||||
then :
|
|
||||||
else echo "$ACTION" > No$CMD 2>/dev/null
|
|
||||||
fi
|
|
||||||
else RETC=1 ; X=: ; eval echo $FAIL
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
(echo ------- `pwd`
|
|
||||||
cat Out
|
|
||||||
$X rm -f Out
|
|
||||||
) 2>/dev/null 1>&- 1>&3
|
|
||||||
exit $RETC
|
|
||||||
)
|
|
||||||
case $? in
|
|
||||||
0) ;;
|
|
||||||
*) case $RETC in
|
|
||||||
0) RETC=$? ;;
|
|
||||||
esac ;;
|
|
||||||
esac
|
|
||||||
else
|
|
||||||
echo Directory $DIR for $SYS is inaccessible
|
|
||||||
RETC=66
|
|
||||||
fi ;;
|
|
||||||
esac
|
|
||||||
case $FATAL$RETC in
|
|
||||||
yes0) ;;
|
|
||||||
yes*) echo Fatal error, installation stopped.
|
|
||||||
exit $RETC ;;
|
|
||||||
esac
|
|
||||||
SYS=
|
|
||||||
;;
|
|
||||||
*) echo Unknown keyword "$1"
|
|
||||||
RETC=67 ;;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
exit $RETC
|
|
||||||
} <$CMD
|
|
||||||
RETX=$?
|
|
||||||
case $RETX in
|
|
||||||
0) exit $RETC ;;
|
|
||||||
*) exit $RETX ;;
|
|
||||||
esac
|
|
71
config.pm
71
config.pm
|
@ -1,71 +0,0 @@
|
||||||
-- ======================================================================= --
|
|
||||||
-- ACK CONFIGURATION --
|
|
||||||
-- (Edit this before building) --
|
|
||||||
-- ======================================================================= --
|
|
||||||
|
|
||||||
-- What platform to build for by default?
|
|
||||||
|
|
||||||
DEFAULT_PLATFORM = "pc86"
|
|
||||||
|
|
||||||
-- Where should the ACK put its temporary files?
|
|
||||||
|
|
||||||
ACK_TEMP_DIR = "/tmp"
|
|
||||||
|
|
||||||
-- Where is the ACK going to be installed, eventually?
|
|
||||||
|
|
||||||
PREFIX = "/tmp/ack-temp/staging"
|
|
||||||
|
|
||||||
-- ======================================================================= --
|
|
||||||
-- BROKEN ACK CONFIGURATION --
|
|
||||||
-- (Currently not editable) --
|
|
||||||
-- ======================================================================= --
|
|
||||||
|
|
||||||
-- FIXME: the following two variables must be set to their Minix variants
|
|
||||||
-- due to hard-coded references in the descr files.
|
|
||||||
|
|
||||||
-- Name of the platform-independent library directory; 'share' on modern
|
|
||||||
-- systems, 'lib' on Minix-like systems.
|
|
||||||
|
|
||||||
PLATIND = "lib"
|
|
||||||
|
|
||||||
-- Name of the platform-dependent library directory; 'lib' on modern
|
|
||||||
-- systems, 'lib.bin' on Minix-like systems.
|
|
||||||
|
|
||||||
PLATDEP = "lib.bin"
|
|
||||||
|
|
||||||
-- ======================================================================= --
|
|
||||||
-- BUILD SYSTEM CONFIGURATION --
|
|
||||||
-- (Not user servicable) --
|
|
||||||
-- ======================================================================= --
|
|
||||||
|
|
||||||
-- Absolute path to the ACK source directory.
|
|
||||||
|
|
||||||
ROOTDIR = posix.getcwd().."/"
|
|
||||||
|
|
||||||
-- Temporary directory used during the build process.
|
|
||||||
|
|
||||||
TEMPDIR = "/tmp/ack-temp/"
|
|
||||||
|
|
||||||
-- Directory in which dynamically generated header files will go during
|
|
||||||
-- the build process.
|
|
||||||
|
|
||||||
HEADERDIR = TEMPDIR.."headers/"
|
|
||||||
|
|
||||||
-- Directory in which tools used by the build process but which not actually
|
|
||||||
-- deployed with the ACK will go.
|
|
||||||
|
|
||||||
TOOLDIR = TEMPDIR.."tools/"
|
|
||||||
|
|
||||||
-- Directory in which the libraries used to build the ACK tools but which are
|
|
||||||
-- not actually deployed with the ACK will go.
|
|
||||||
|
|
||||||
LIBDIR = TEMPDIR.."lib/"
|
|
||||||
|
|
||||||
-- Staging area where the installation will be built before actually copying
|
|
||||||
-- it.
|
|
||||||
|
|
||||||
BINDIR = TEMPDIR.."staging/"
|
|
||||||
|
|
||||||
-- Directory that the pm cache goes in.
|
|
||||||
|
|
||||||
pm.intermediate_cache_dir = TEMPDIR.."pmcache/"
|
|
|
@ -122,7 +122,6 @@
|
||||||
!File: spec_arith.h
|
!File: spec_arith.h
|
||||||
/* describes internal compiler arithmetics */
|
/* describes internal compiler arithmetics */
|
||||||
/*#define SPECIAL_ARITHMETICS /* something different from native long */
|
/*#define SPECIAL_ARITHMETICS /* something different from native long */
|
||||||
#define UNSIGNED_ARITH unsigned arith /* when it is supported */
|
|
||||||
|
|
||||||
|
|
||||||
!File: static.h
|
!File: static.h
|
||||||
|
|
|
@ -95,7 +95,3 @@
|
||||||
/*#define USE_INSERT 1 /* use C_insertpart mechanism */
|
/*#define USE_INSERT 1 /* use C_insertpart mechanism */
|
||||||
|
|
||||||
|
|
||||||
!File: uns_arith.h
|
|
||||||
#define UNSIGNED_ARITH unsigned arith
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -34,12 +34,19 @@ init(char *s, int val)
|
||||||
np->offset = val;
|
np->offset = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
usage(void)
|
||||||
|
{
|
||||||
|
error("Usage: em_b [-w wordsize] [-B modulename] [-i inputfile] [-o outputfile]");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
int opt = getopt(argc, argv, "-w:B:i:o:");
|
int opt = getopt(argc, argv, "w:B:i:o:");
|
||||||
if (opt == -1)
|
if (opt == -1)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -66,11 +73,12 @@ main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
derfault:
|
default:
|
||||||
error("Usage: em_b [-w wordsize] [-B modulename] [-i inputfile] [-o outputfile]");
|
usage();
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (optind < argc)
|
||||||
|
usage();
|
||||||
|
|
||||||
init("auto", AUTO);
|
init("auto", AUTO);
|
||||||
init("extrn", EXTERN);
|
init("extrn", EXTERN);
|
||||||
|
|
|
@ -122,7 +122,6 @@
|
||||||
!File: spec_arith.h
|
!File: spec_arith.h
|
||||||
/* describes internal compiler arithmetics */
|
/* describes internal compiler arithmetics */
|
||||||
#undef SPECIAL_ARITHMETICS /* something different from native long */
|
#undef SPECIAL_ARITHMETICS /* something different from native long */
|
||||||
/*#define UNSIGNED_ARITH unsigned arith /* if it is supported */
|
|
||||||
|
|
||||||
|
|
||||||
!File: static.h
|
!File: static.h
|
||||||
|
|
|
@ -122,7 +122,6 @@
|
||||||
!File: spec_arith.h
|
!File: spec_arith.h
|
||||||
/* describes internal compiler arithmetics */
|
/* describes internal compiler arithmetics */
|
||||||
#undef SPECIAL_ARITHMETICS /* something different from native long */
|
#undef SPECIAL_ARITHMETICS /* something different from native long */
|
||||||
/*#define UNSIGNED_ARITH unsigned arith /* if it is supported */
|
|
||||||
|
|
||||||
|
|
||||||
!File: static.h
|
!File: static.h
|
||||||
|
|
|
@ -47,39 +47,8 @@ cstbin(expp, oper, expr)
|
||||||
expr_warning(expr, "division by 0");
|
expr_warning(expr, "division by 0");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (uns) {
|
if (uns)
|
||||||
#ifdef UNSIGNED_ARITH
|
o1 /= (unsigned arith) o2;
|
||||||
o1 /= (UNSIGNED_ARITH) o2;
|
|
||||||
#else
|
|
||||||
/* this is more of a problem than you might
|
|
||||||
think on C compilers which do not have
|
|
||||||
unsigned arith (== long (probably)).
|
|
||||||
*/
|
|
||||||
if (o2 & arith_sign) {/* o2 > max_arith */
|
|
||||||
o1 = ! (o1 >= 0 || o1 < o2);
|
|
||||||
/* this is the unsigned test
|
|
||||||
o1 < o2 for o2 > max_arith
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
else { /* o2 <= max_arith */
|
|
||||||
arith half, bit, hdiv, hrem, rem;
|
|
||||||
|
|
||||||
half = (o1 >> 1) & ~arith_sign;
|
|
||||||
bit = o1 & 01;
|
|
||||||
/* now o1 == 2 * half + bit
|
|
||||||
and half <= max_arith
|
|
||||||
and bit <= max_arith
|
|
||||||
*/
|
|
||||||
hdiv = half / o2;
|
|
||||||
hrem = half % o2;
|
|
||||||
rem = 2 * hrem + bit;
|
|
||||||
o1 = 2 * hdiv + (rem < 0 || rem >= o2);
|
|
||||||
/* that is the unsigned compare
|
|
||||||
rem >= o2 for o2 <= max_arith
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
o1 /= o2;
|
o1 /= o2;
|
||||||
break;
|
break;
|
||||||
|
@ -91,31 +60,8 @@ cstbin(expp, oper, expr)
|
||||||
expr_warning(expr, "modulo by 0");
|
expr_warning(expr, "modulo by 0");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (uns) {
|
if (uns)
|
||||||
#ifdef UNSIGNED_ARITH
|
o1 %= (unsigned arith) o2;
|
||||||
o1 %= (UNSIGNED_ARITH) o2;
|
|
||||||
#else
|
|
||||||
if (o2 & arith_sign) {/* o2 > max_arith */
|
|
||||||
o1 = (o1 >= 0 || o1 < o2) ? o1 : o1 - o2;
|
|
||||||
/* this is the unsigned test
|
|
||||||
o1 < o2 for o2 > max_arith
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
else { /* o2 <= max_arith */
|
|
||||||
arith half, bit, hrem, rem;
|
|
||||||
|
|
||||||
half = (o1 >> 1) & ~arith_sign;
|
|
||||||
bit = o1 & 01;
|
|
||||||
/* now o1 == 2 * half + bit
|
|
||||||
and half <= max_arith
|
|
||||||
and bit <= max_arith
|
|
||||||
*/
|
|
||||||
hrem = half % o2;
|
|
||||||
rem = 2 * hrem + bit;
|
|
||||||
o1 = (rem < 0 || rem >= o2) ? rem - o2 : rem;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
o1 %= o2;
|
o1 %= o2;
|
||||||
break;
|
break;
|
||||||
|
@ -146,16 +92,8 @@ cstbin(expp, oper, expr)
|
||||||
}
|
}
|
||||||
/* Fall through */
|
/* Fall through */
|
||||||
case '>':
|
case '>':
|
||||||
if (uns) {
|
if (uns)
|
||||||
#ifdef UNSIGNED_ARITH
|
o1 = (unsigned arith) o1 > (unsigned arith) o2;
|
||||||
o1 = (UNSIGNED_ARITH) o1 > (UNSIGNED_ARITH) o2;
|
|
||||||
#else
|
|
||||||
o1 = (o1 & arith_sign ?
|
|
||||||
(o2 & arith_sign ? o1 > o2 : 1) :
|
|
||||||
(o2 & arith_sign ? 0 : o1 > o2)
|
|
||||||
);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
o1 = o1 > o2;
|
o1 = o1 > o2;
|
||||||
break;
|
break;
|
||||||
|
@ -168,16 +106,8 @@ cstbin(expp, oper, expr)
|
||||||
}
|
}
|
||||||
/* Fall through */
|
/* Fall through */
|
||||||
case GREATEREQ:
|
case GREATEREQ:
|
||||||
if (uns) {
|
if (uns)
|
||||||
#ifdef UNSIGNED_ARITH
|
o1 = (unsigned arith) o1 >= (unsigned arith) o2;
|
||||||
o1 = (UNSIGNED_ARITH) o1 >= (UNSIGNED_ARITH) o2;
|
|
||||||
#else
|
|
||||||
o1 = (o1 & arith_sign ?
|
|
||||||
(o2 & arith_sign ? o1 >= o2 : 1) :
|
|
||||||
(o2 & arith_sign ? 0 : o1 >= o2)
|
|
||||||
);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
o1 = o1 >= o2;
|
o1 = o1 >= o2;
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -261,7 +261,7 @@ garbage:
|
||||||
register int base = 10, vch;
|
register int base = 10, vch;
|
||||||
register arith val = 0;
|
register arith val = 0;
|
||||||
int ovfl = 0;
|
int ovfl = 0;
|
||||||
arith ubound = ~(1<<(sizeof(arith)*8-1))/(base/2);
|
arith ubound = max_arith/(base/2);
|
||||||
|
|
||||||
/* Since the preprocessor only knows integers and has
|
/* Since the preprocessor only knows integers and has
|
||||||
* nothing to do with ellipsis we just return when the
|
* nothing to do with ellipsis we just return when the
|
||||||
|
|
|
@ -16,3 +16,7 @@
|
||||||
/* All preprocessor arithmetic should be done in longs.
|
/* All preprocessor arithmetic should be done in longs.
|
||||||
*/
|
*/
|
||||||
#define arith long /* dummy */
|
#define arith long /* dummy */
|
||||||
|
|
||||||
|
#define arith_size (sizeof(arith))
|
||||||
|
#define arith_sign ((arith) 1 << (arith_size * 8 - 1))
|
||||||
|
#define max_arith (~arith_sign)
|
||||||
|
|
|
@ -8,8 +8,6 @@
|
||||||
#include "Lpars.h"
|
#include "Lpars.h"
|
||||||
#include "arith.h"
|
#include "arith.h"
|
||||||
|
|
||||||
#define arith_sign (1L << (sizeof(arith)*8-1))
|
|
||||||
|
|
||||||
ch3bin(pval, pis_uns, oper, val, is_uns)
|
ch3bin(pval, pis_uns, oper, val, is_uns)
|
||||||
register arith *pval, val;
|
register arith *pval, val;
|
||||||
int oper, is_uns, *pis_uns;
|
int oper, is_uns, *pis_uns;
|
||||||
|
@ -22,37 +20,7 @@ ch3bin(pval, pis_uns, oper, val, is_uns)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (*pis_uns) {
|
if (*pis_uns) {
|
||||||
#ifdef UNSIGNED_ARITH
|
*pval /= (unsigned arith) val;
|
||||||
*pval /= (UNSIGNED_ARITH) val;
|
|
||||||
#else
|
|
||||||
/* this is more of a problem than you might
|
|
||||||
think on C compilers which do not have
|
|
||||||
unsigned arith (== long (probably)).
|
|
||||||
*/
|
|
||||||
if (val & arith_sign) {/* val > max_arith */
|
|
||||||
*pval = ! (*pval >= 0 || *pval < val);
|
|
||||||
/* this is the unsigned test
|
|
||||||
*pval < val for val > max_arith
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
else { /* val <= max_arith */
|
|
||||||
arith half, bit, hdiv, hrem, rem;
|
|
||||||
|
|
||||||
half = (*pval >> 1) & ~arith_sign;
|
|
||||||
bit = *pval & 01;
|
|
||||||
/* now *pval == 2 * half + bit
|
|
||||||
and half <= max_arith
|
|
||||||
and bit <= max_arith
|
|
||||||
*/
|
|
||||||
hdiv = half / val;
|
|
||||||
hrem = half % val;
|
|
||||||
rem = 2 * hrem + bit;
|
|
||||||
*pval = 2 * hdiv + (rem < 0 || rem >= val);
|
|
||||||
/* that is the unsigned compare
|
|
||||||
rem >= val for val <= max_arith
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
*pval = *pval / val;
|
*pval = *pval / val;
|
||||||
|
@ -64,29 +32,7 @@ ch3bin(pval, pis_uns, oper, val, is_uns)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (*pis_uns) {
|
if (*pis_uns) {
|
||||||
#ifdef UNSIGNED_ARITH
|
*pval %= (unsigned arith) val;
|
||||||
*pval %= (UNSIGNED_ARITH) val;
|
|
||||||
#else
|
|
||||||
if (val & arith_sign) {/* val > max_arith */
|
|
||||||
*pval = (*pval >= 0 || *pval < val) ? *pval : *pval - val;
|
|
||||||
/* this is the unsigned test
|
|
||||||
*pval < val for val > max_arith
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
else { /* val <= max_arith */
|
|
||||||
arith half, bit, hrem, rem;
|
|
||||||
|
|
||||||
half = (*pval >> 1) & ~arith_sign;
|
|
||||||
bit = *pval & 01;
|
|
||||||
/* now *pval == 2 * half + bit
|
|
||||||
and half <= max_arith
|
|
||||||
and bit <= max_arith
|
|
||||||
*/
|
|
||||||
hrem = half % val;
|
|
||||||
rem = 2 * hrem + bit;
|
|
||||||
*pval = (rem < 0 || rem >= val) ? rem - val : rem;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
*pval = *pval % val;
|
*pval = *pval % val;
|
||||||
|
@ -117,14 +63,7 @@ ch3bin(pval, pis_uns, oper, val, is_uns)
|
||||||
/* fall through */
|
/* fall through */
|
||||||
case '>':
|
case '>':
|
||||||
if (*pis_uns) {
|
if (*pis_uns) {
|
||||||
#ifdef UNSIGNED_ARITH
|
*pval = (unsigned arith) *pval > (unsigned arith) val;
|
||||||
*pval = (UNSIGNED_ARITH) *pval > (UNSIGNED_ARITH) val;
|
|
||||||
#else
|
|
||||||
*pval = (*pval & arith_sign ?
|
|
||||||
(val & arith_sign ? *pval > val : 1) :
|
|
||||||
(val & arith_sign ? 0 : *pval > val)
|
|
||||||
);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
else *pval = (*pval > val);
|
else *pval = (*pval > val);
|
||||||
break;
|
break;
|
||||||
|
@ -133,14 +72,7 @@ ch3bin(pval, pis_uns, oper, val, is_uns)
|
||||||
/* fall through */
|
/* fall through */
|
||||||
case GREATEREQ:
|
case GREATEREQ:
|
||||||
if (*pis_uns) {
|
if (*pis_uns) {
|
||||||
#ifdef UNSIGNED_ARITH
|
*pval = (unsigned arith) *pval >= (unsigned arith) val;
|
||||||
*pval = (UNSIGNED_ARITH) *pval >= (UNSIGNED_ARITH) val;
|
|
||||||
#else
|
|
||||||
*pval = (*pval & arith_sign ?
|
|
||||||
(val & arith_sign ? *pval >= val : 1) :
|
|
||||||
(val & arith_sign ? 0 : *pval >= val)
|
|
||||||
);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
else *pval = (*pval >= val);
|
else *pval = (*pval >= val);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -37,7 +37,7 @@ for _, plat in ipairs(vars.plats) do
|
||||||
"./errno/*.c",
|
"./errno/*.c",
|
||||||
"./locale/*.c",
|
"./locale/*.c",
|
||||||
"./malloc/*.c",
|
"./malloc/*.c",
|
||||||
"./math/*.c",
|
"./math/*.c", -- hypot.c
|
||||||
"./math/*.e",
|
"./math/*.e",
|
||||||
"./misc/environ.c", -- don't build everything here as it's all obsolete
|
"./misc/environ.c", -- don't build everything here as it's all obsolete
|
||||||
"./setjmp/*.c",
|
"./setjmp/*.c",
|
||||||
|
|
|
@ -23,4 +23,3 @@ installable {
|
||||||
name = "pkg",
|
name = "pkg",
|
||||||
map = installmap
|
map = installmap
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,66 +0,0 @@
|
||||||
/*
|
|
||||||
* stdlib.h - standard library
|
|
||||||
*
|
|
||||||
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
|
||||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
|
||||||
*/
|
|
||||||
/* $Id$ */
|
|
||||||
|
|
||||||
#ifndef _STDLIB_H
|
|
||||||
#define _STDLIB_H
|
|
||||||
|
|
||||||
#include <stddef.h>
|
|
||||||
|
|
||||||
#define EXIT_FAILURE 1
|
|
||||||
#define EXIT_SUCCESS 0
|
|
||||||
#define RAND_MAX 32767
|
|
||||||
#define MB_CUR_MAX sizeof(wchar_t)
|
|
||||||
|
|
||||||
typedef struct { int quot, rem; } div_t;
|
|
||||||
typedef struct { long quot, rem; } ldiv_t;
|
|
||||||
|
|
||||||
extern double atof(const char *_nptr);
|
|
||||||
extern int atoi(const char *_nptr);
|
|
||||||
extern long atol(const char *_nptr);
|
|
||||||
extern double strtod(const char *_nptr, char **_endptr);
|
|
||||||
extern long strtol(const char *_nptr, char **_endptr, int _base);
|
|
||||||
extern unsigned long strtoul(const char *_nptr, char **_endptr, int _base);
|
|
||||||
extern int rand(void);
|
|
||||||
extern void srand(unsigned int _seed);
|
|
||||||
extern void* calloc(size_t _nmemb, size_t _size);
|
|
||||||
extern void free(void *_ptr);
|
|
||||||
extern void* malloc(size_t _size);
|
|
||||||
extern void* realloc(void *_ptr, size_t _size);
|
|
||||||
extern void abort(void);
|
|
||||||
extern int atexit(void (*_func)(void));
|
|
||||||
extern void exit(int _status);
|
|
||||||
extern void _Exit(int _status);
|
|
||||||
extern char* getenv(const char *_name);
|
|
||||||
extern int setenv(const char *_name, const char *_value, int _overwrite);
|
|
||||||
extern int unsetenv(const char *_name);
|
|
||||||
extern int putenv(char *_string);
|
|
||||||
extern int system(const char *_string);
|
|
||||||
extern void* bsearch(const void *_key, const void *_base,
|
|
||||||
size_t _nmemb, size_t _size,
|
|
||||||
int (*_compar)(const void *, const void *));
|
|
||||||
extern void qsort(void *_base, size_t _nmemb, size_t _size,
|
|
||||||
int (*_compar)(const void *, const void *));
|
|
||||||
extern int abs(int _j);
|
|
||||||
extern div_t div(int _numer, int _denom);
|
|
||||||
extern long labs(long _j);
|
|
||||||
extern ldiv_t ldiv(long _numer, long _denom);
|
|
||||||
extern int mblen(const char *_s, size_t _n);
|
|
||||||
extern int mbtowc(wchar_t *_pwc, const char *_s, size_t _n);
|
|
||||||
extern int wctomb(char *_s, wchar_t _wchar);
|
|
||||||
extern size_t mbstowcs(wchar_t *_pwcs, const char *_s, size_t _n);
|
|
||||||
extern size_t wcstombs(char *_s, const wchar_t *_pwcs, size_t _n);
|
|
||||||
|
|
||||||
/* Extensions (not part of the standard) */
|
|
||||||
|
|
||||||
#define atof(n) strtod(n, (char **)NULL)
|
|
||||||
#define atoi(n) ((int)strtol(n, (char **)NULL, 10))
|
|
||||||
#define atol(n) strtol(n, (char **)NULL, 10)
|
|
||||||
#define atoll(n) strtoll(n, (char **)NULL, 10)
|
|
||||||
#define mblen(s, n) mbtowc((wchar_t *)0, s, n)
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -33,6 +33,7 @@ extern double ceil(double _x);
|
||||||
extern double fabs(double _x);
|
extern double fabs(double _x);
|
||||||
extern double floor(double _x);
|
extern double floor(double _x);
|
||||||
|
|
||||||
|
extern double hypot(double _x, double _y);
|
||||||
extern double pow(double _x, double _y);
|
extern double pow(double _x, double _y);
|
||||||
|
|
||||||
extern double frexp(double _x, int *_exp);
|
extern double frexp(double _x, int *_exp);
|
||||||
|
|
|
@ -1,11 +0,0 @@
|
||||||
/*
|
|
||||||
<tgmath.h> -- simple version used by "gimplify"
|
|
||||||
|
|
||||||
last edit: 2007-02-12 D A Gwyn
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* XXX -- Can't be done right without compiler support; it *may* suffice to
|
|
||||||
use automatic coercion to type double with the <math.h> prototypes. */
|
|
||||||
|
|
||||||
#include <math.h>
|
|
||||||
#include <complex.h>
|
|
|
@ -1,38 +0,0 @@
|
||||||
/*
|
|
||||||
* getpw - get a password from the password file
|
|
||||||
*/
|
|
||||||
/* $Id$ */
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
getpw(int uid, char buf[])
|
|
||||||
{
|
|
||||||
register FILE *pwf;
|
|
||||||
register int ch, i;
|
|
||||||
register char *bp;
|
|
||||||
|
|
||||||
pwf = fopen("/etc/passwd", "r");
|
|
||||||
if (pwf == NULL) return(1);
|
|
||||||
|
|
||||||
for (;;) {
|
|
||||||
bp = buf;
|
|
||||||
while ((ch = getc(pwf)) != '\n') {
|
|
||||||
if (ch == EOF) return 1;
|
|
||||||
*bp++ = ch;
|
|
||||||
}
|
|
||||||
*bp++ = '\0';
|
|
||||||
bp = buf;
|
|
||||||
for (i = 2; i; i--) {
|
|
||||||
while ((ch = *bp++) != ':') {
|
|
||||||
if(ch = '\0') return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
i = 0;
|
|
||||||
while ((ch = *bp++) != ':') {
|
|
||||||
if (ch < '0' || ch > '9') return 1;
|
|
||||||
i = i * 10 + (ch - '0');
|
|
||||||
}
|
|
||||||
if (i == uid) return(0);
|
|
||||||
}
|
|
||||||
/*NOTREACHED*/
|
|
||||||
}
|
|
|
@ -16,7 +16,7 @@ __fillbuf(register FILE *stream)
|
||||||
|
|
||||||
stream->_count = 0;
|
stream->_count = 0;
|
||||||
if (fileno(stream) < 0) return EOF;
|
if (fileno(stream) < 0) return EOF;
|
||||||
if (io_testflag(stream, (_IOEOF | _IOERR ))) return EOF;
|
if (io_testflag(stream, _IOEOF)) return EOF;
|
||||||
if (!io_testflag(stream, _IOREAD)) {
|
if (!io_testflag(stream, _IOREAD)) {
|
||||||
stream->_flags |= _IOERR;
|
stream->_flags |= _IOERR;
|
||||||
return EOF;
|
return EOF;
|
||||||
|
|
|
@ -123,7 +123,6 @@
|
||||||
!File: spec_arith.h
|
!File: spec_arith.h
|
||||||
/* describes internal compiler arithmetics */
|
/* describes internal compiler arithmetics */
|
||||||
/*#define SPECIAL_ARITHMETICS /* something different from native long */
|
/*#define SPECIAL_ARITHMETICS /* something different from native long */
|
||||||
/*#define UNSIGNED_ARITH unsigned arith /* when it is supported */
|
|
||||||
|
|
||||||
|
|
||||||
!File: static.h
|
!File: static.h
|
||||||
|
|
|
@ -94,7 +94,3 @@
|
||||||
#define USE_INSERT 1 /* use C_insertpart mechanism */
|
#define USE_INSERT 1 /* use C_insertpart mechanism */
|
||||||
|
|
||||||
|
|
||||||
!File: uns_arith.h
|
|
||||||
/*#define UNSIGNED_ARITH unsigned arith /* when it is supported */
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -94,7 +94,3 @@
|
||||||
/*#define USE_INSERT 1 /* use C_insertpart mechanism */
|
/*#define USE_INSERT 1 /* use C_insertpart mechanism */
|
||||||
|
|
||||||
|
|
||||||
!File: uns_arith.h
|
|
||||||
/*#define UNSIGNED_ARITH unsigned arith /* when it is supported */
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
|
|
||||||
extern char *symbol2str();
|
extern char *symbol2str();
|
||||||
|
|
||||||
#define arith_sign ((arith) (1L << (sizeof(arith) * 8 - 1)))
|
#define arith_sign ((arith) 1 << (sizeof(arith) * 8 - 1))
|
||||||
|
|
||||||
#ifndef NOCROSS
|
#ifndef NOCROSS
|
||||||
arith full_mask[MAXSIZE+1];/* full_mask[1] == 0xFF, full_mask[2] == 0xFFFF, .. */
|
arith full_mask[MAXSIZE+1];/* full_mask[1] == 0xFF, full_mask[2] == 0xFFFF, .. */
|
||||||
|
@ -117,49 +117,8 @@ divide(pdiv, prem)
|
||||||
register arith o1 = *pdiv;
|
register arith o1 = *pdiv;
|
||||||
register arith o2 = *prem;
|
register arith o2 = *prem;
|
||||||
|
|
||||||
#ifndef UNSIGNED_ARITH
|
*pdiv = (unsigned arith) o1 / (unsigned arith) o2;
|
||||||
/* this is more of a problem than you might
|
*prem = (unsigned arith) o1 % (unsigned arith) o2;
|
||||||
think on C compilers which do not have
|
|
||||||
unsigned long.
|
|
||||||
*/
|
|
||||||
if (o2 & arith_sign) {/* o2 > max_arith */
|
|
||||||
if (! (o1 >= 0 || o1 < o2)) {
|
|
||||||
/* this is the unsigned test
|
|
||||||
o1 < o2 for o2 > max_arith
|
|
||||||
*/
|
|
||||||
*prem = o2 - o1;
|
|
||||||
*pdiv = 1;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
*pdiv = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else { /* o2 <= max_arith */
|
|
||||||
arith half, bit, hdiv, hrem, rem;
|
|
||||||
|
|
||||||
half = (o1 >> 1) & ~arith_sign;
|
|
||||||
bit = o1 & 01;
|
|
||||||
/* now o1 == 2 * half + bit
|
|
||||||
and half <= max_arith
|
|
||||||
and bit <= max_arith
|
|
||||||
*/
|
|
||||||
hdiv = half / o2;
|
|
||||||
hrem = half % o2;
|
|
||||||
rem = 2 * hrem + bit;
|
|
||||||
*pdiv = 2*hdiv;
|
|
||||||
*prem = rem;
|
|
||||||
if (rem < 0 || rem >= o2) {
|
|
||||||
/* that is the unsigned compare
|
|
||||||
rem >= o2 for o2 <= max_arith
|
|
||||||
*/
|
|
||||||
*pdiv += 1;
|
|
||||||
*prem -= o2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
*pdiv = (UNSIGNED_ARITH) o1 / (UNSIGNED_ARITH) o2;
|
|
||||||
*prem = (UNSIGNED_ARITH) o1 % (UNSIGNED_ARITH) o2;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -200,22 +159,29 @@ cstibin(expp)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DIV:
|
case DIV:
|
||||||
case MOD:
|
|
||||||
if (o2 == 0) {
|
if (o2 == 0) {
|
||||||
node_error(exp, exp->nd_symb == DIV ?
|
node_error(exp, "division by 0");
|
||||||
"division by 0" :
|
|
||||||
"modulo by 0");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ((o1 < 0) != (o2 < 0)) {
|
if ((o1 < 0) != (o2 < 0)) {
|
||||||
if (o1 < 0) o1 = -o1;
|
if (o1 < 0) o1 = -o1;
|
||||||
else o2 = -o2;
|
else o2 = -o2;
|
||||||
if (exp->nd_symb == DIV) o1 = -((o1+o2-1)/o2);
|
o1 = -((o1+o2-1)/o2);
|
||||||
else o1 = ((o1+o2-1)/o2) * o2 - o1;
|
|
||||||
}
|
}
|
||||||
else {
|
else o1 /= o2;
|
||||||
if (exp->nd_symb == DIV) o1 /= o2;
|
break;
|
||||||
else o1 %= o2;
|
|
||||||
|
case MOD:
|
||||||
|
if (o2 == 0) {
|
||||||
|
node_error(exp, "modulo by 0");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
{
|
||||||
|
arith m = o1 % o2;
|
||||||
|
if (m != 0 && (o1 < 0) != (o2 < 0))
|
||||||
|
o1 = m + o2;
|
||||||
|
else
|
||||||
|
o1 = m;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
|
@ -51,8 +51,6 @@ arith
|
||||||
pointer_size = SZ_POINTER;
|
pointer_size = SZ_POINTER;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define arith_sign ((arith) (1L << (sizeof(arith) * 8 - 1)))
|
|
||||||
|
|
||||||
arith ret_area_size;
|
arith ret_area_size;
|
||||||
|
|
||||||
t_type
|
t_type
|
||||||
|
@ -306,14 +304,7 @@ chk_bounds(l1, l2, fund)
|
||||||
if (fund == T_INTEGER) {
|
if (fund == T_INTEGER) {
|
||||||
return l2 >= l1;
|
return l2 >= l1;
|
||||||
}
|
}
|
||||||
#ifdef UNSIGNED_ARITH
|
return (unsigned arith) l2 >= (unsigned arith) l1;
|
||||||
return (UNSIGNED_ARITH) l2 >= (UNSIGNED_ARITH) l1;
|
|
||||||
#else
|
|
||||||
return (l2 & arith_sign ?
|
|
||||||
(l1 & arith_sign ? l2 >= l1 : 1) :
|
|
||||||
(l1 & arith_sign ? 0 : l2 >= l1)
|
|
||||||
);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
|
|
@ -19,7 +19,7 @@ IMPLEMENTATION MODULE Terminal;
|
||||||
#else
|
#else
|
||||||
FROM Unix IMPORT read, write, open, ioctl;
|
FROM Unix IMPORT read, write, open, ioctl;
|
||||||
#endif
|
#endif
|
||||||
VAR fildes: INTEGER;
|
VAR fildes, fdout: INTEGER;
|
||||||
unreadch: CHAR;
|
unreadch: CHAR;
|
||||||
unread: BOOLEAN;
|
unread: BOOLEAN;
|
||||||
tty: ARRAY[0..8] OF CHAR;
|
tty: ARRAY[0..8] OF CHAR;
|
||||||
|
@ -87,7 +87,7 @@ IMPLEMENTATION MODULE Terminal;
|
||||||
|
|
||||||
PROCEDURE Write(ch: CHAR);
|
PROCEDURE Write(ch: CHAR);
|
||||||
BEGIN
|
BEGIN
|
||||||
IF write(fildes, ADR(ch), 1) < 0 THEN
|
IF write(fdout, ADR(ch), 1) < 0 THEN
|
||||||
;
|
;
|
||||||
END;
|
END;
|
||||||
END Write;
|
END Write;
|
||||||
|
@ -114,7 +114,9 @@ BEGIN
|
||||||
unread := FALSE;
|
unread := FALSE;
|
||||||
*)
|
*)
|
||||||
(* dtrg: changed so that instead of opening /dev/tty, fd 0 is always used. *)
|
(* dtrg: changed so that instead of opening /dev/tty, fd 0 is always used. *)
|
||||||
|
(* kernigh: sent output to fd 1 *)
|
||||||
tty := "stdio";
|
tty := "stdio";
|
||||||
fildes := 0;
|
fildes := 0;
|
||||||
|
fdout := 1;
|
||||||
unread := FALSE;
|
unread := FALSE;
|
||||||
END Terminal.
|
END Terminal.
|
||||||
|
|
|
@ -43,26 +43,28 @@ int
|
||||||
rmi(j,i)
|
rmi(j,i)
|
||||||
int j,i;
|
int j,i;
|
||||||
{
|
{
|
||||||
|
int m;
|
||||||
|
|
||||||
if (j == 0) TRP(EIDIVZ);
|
if (j == 0) TRP(EIDIVZ);
|
||||||
if (i == 0) return 0;
|
if (i == 0) return 0;
|
||||||
if ((i < 0) != (j < 0)) {
|
|
||||||
if (i < 0) i = -i;
|
m = i % j;
|
||||||
else j = -j;
|
if (m != 0 && (i < 0) != (j < 0))
|
||||||
return j*((i+j-1)/j)-i;
|
m += j;
|
||||||
}
|
return m;
|
||||||
else return i%j;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
long
|
long
|
||||||
rmil(j,i)
|
rmil(j,i)
|
||||||
long j,i;
|
long j,i;
|
||||||
{
|
{
|
||||||
|
long m;
|
||||||
|
|
||||||
if (j == 0) TRP(EIDIVZ);
|
if (j == 0) TRP(EIDIVZ);
|
||||||
if (i == 0) return 0L;
|
if (i == 0) return 0L;
|
||||||
if ((i < 0) != (j < 0)) {
|
|
||||||
if (i < 0) i = -i;
|
m = i % j;
|
||||||
else j = -j;
|
if (m != 0 && (i < 0) != (j < 0))
|
||||||
return j*((i+j-1)/j)-i;
|
m += j;
|
||||||
}
|
return m;
|
||||||
else return i%j;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,7 +91,7 @@ name cem
|
||||||
callname cc
|
callname cc
|
||||||
end
|
end
|
||||||
name pc
|
name pc
|
||||||
from .p
|
from .p.pas
|
||||||
to .k
|
to .k
|
||||||
program {EM}/lib/ack/em_pc
|
program {EM}/lib/ack/em_pc
|
||||||
mapflag -L PC_F={PC_F?} -L
|
mapflag -L PC_F={PC_F?} -L
|
||||||
|
|
49
tests/plat/bugs/bug-62-notvar_var_e.c
Normal file
49
tests/plat/bugs/bug-62-notvar_var_e.c
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
#include "test.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Function a() comes from this mail by Rune to tack-devel:
|
||||||
|
* https://sourceforge.net/p/tack/mailman/message/35809953/
|
||||||
|
*
|
||||||
|
* The peephole optimiser (util/opt) had a bug that rewrote
|
||||||
|
* xx(! i, i) as xx(1). It was confused with xx(i == i).
|
||||||
|
*/
|
||||||
|
|
||||||
|
void xx(int xfal, int x1234) {
|
||||||
|
ASSERT(xfal == 0);
|
||||||
|
ASSERT(x1234 == 1234);
|
||||||
|
}
|
||||||
|
|
||||||
|
void a(void) {
|
||||||
|
int i = 1234;
|
||||||
|
xx(! i, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
void xxxx(int x2005, int xfal, int xn567, int x2017) {
|
||||||
|
ASSERT(x2005 == 2005);
|
||||||
|
ASSERT(xfal == 0);
|
||||||
|
ASSERT(xn567 == -567);
|
||||||
|
ASSERT(x2017 == 2017);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Like a(), but with surrounding arguments. */
|
||||||
|
void b(void) {
|
||||||
|
int i = -567;
|
||||||
|
xxxx(2005, ! i, i, 2017);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* In c(), the fixed peephole optimiser may
|
||||||
|
* rewrite i == i as 1 and i != i as 0.
|
||||||
|
*/
|
||||||
|
void c(int i, int tru, int fal) {
|
||||||
|
ASSERT((i == i) == tru);
|
||||||
|
ASSERT((i != i) == fal);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Bypasses the CRT. */
|
||||||
|
void _m_a_i_n(void) {
|
||||||
|
a();
|
||||||
|
b();
|
||||||
|
c(62, 1, 0);
|
||||||
|
finished();
|
||||||
|
}
|
|
@ -13,7 +13,8 @@ definerule("plat_testsuite",
|
||||||
"tests/plat/*.e",
|
"tests/plat/*.e",
|
||||||
"tests/plat/*.p",
|
"tests/plat/*.p",
|
||||||
"tests/plat/b/*.b",
|
"tests/plat/b/*.b",
|
||||||
"tests/plat/bugs/*.mod"
|
"tests/plat/bugs/bug-22-inn_mod.mod",
|
||||||
|
"tests/plat/bugs/bug-62-notvar_var_e.c"
|
||||||
)
|
)
|
||||||
|
|
||||||
acklibrary {
|
acklibrary {
|
||||||
|
|
|
@ -38,7 +38,7 @@ finally combining the results into a single file.
|
||||||
.PP
|
.PP
|
||||||
Different machines can use different suffices,
|
Different machines can use different suffices,
|
||||||
but the following are recognized by most machines:
|
but the following are recognized by most machines:
|
||||||
.IP .p
|
.IP ".p .pas"
|
||||||
Pascal program.
|
Pascal program.
|
||||||
.IP .c
|
.IP .c
|
||||||
C module.
|
C module.
|
||||||
|
@ -395,7 +395,7 @@ l l l l.
|
||||||
input:name:output:description
|
input:name:output:description
|
||||||
\&.f:f77:.c:Fortran-to-C front end
|
\&.f:f77:.c:Fortran-to-C front end
|
||||||
\&.c:cem:.k:C front end [4,5,6]
|
\&.c:cem:.k:C front end [4,5,6]
|
||||||
\&.p:pc:.k:Pascal front end [2,3,6]
|
\&.p .pas:pc:.k:Pascal front end [2,3,6]
|
||||||
\&.b:basic:.k:Basic front end [6,8]
|
\&.b:basic:.k:Basic front end [6,8]
|
||||||
\&.ocm:ocm:.k:Occam front end [9]
|
\&.ocm:ocm:.k:Occam front end [9]
|
||||||
\&.mod:m2:.k:Modula-2 front end [11]
|
\&.mod:m2:.k:Modula-2 front end [11]
|
||||||
|
|
|
@ -346,7 +346,7 @@ int main(int argc, char* argv[])
|
||||||
opterr = 0;
|
opterr = 0;
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
int opt = getopt(argc, argv, "-M:P:O:vt");
|
int opt = getopt(argc, argv, "M:P:O:vt");
|
||||||
if (opt == -1)
|
if (opt == -1)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -364,17 +364,14 @@ int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
int o = atoi(optarg);
|
int o = atoi(optarg);
|
||||||
if (o <= 2)
|
if (o <= 2)
|
||||||
break;
|
Ophase = &O2phases[0];
|
||||||
if (o <= 3)
|
else if (o == 3)
|
||||||
Ophase = &O3phases[0];
|
Ophase = &O3phases[0];
|
||||||
Ophase = &O4phases[0];
|
else
|
||||||
|
Ophase = &O4phases[0];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 1:
|
|
||||||
add_file(optarg);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 't':
|
case 't':
|
||||||
keeptemps = 1;
|
keeptemps = 1;
|
||||||
goto addopt;
|
goto addopt;
|
||||||
|
@ -390,6 +387,9 @@ int main(int argc, char* argv[])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (i = optind; i < argc; i++)
|
||||||
|
add_file(argv[i]);
|
||||||
|
|
||||||
phase_args[nphase_args] = 0;
|
phase_args[nphase_args] = 0;
|
||||||
if (nuphases)
|
if (nuphases)
|
||||||
Ophase = uphases;
|
Ophase = uphases;
|
||||||
|
|
|
@ -17,6 +17,7 @@ cprogram {
|
||||||
matching(filenamesof("+flex"), "%.c$"),
|
matching(filenamesof("+flex"), "%.c$"),
|
||||||
},
|
},
|
||||||
deps = {
|
deps = {
|
||||||
|
"./*.h",
|
||||||
"+flex",
|
"+flex",
|
||||||
"+yacc",
|
"+yacc",
|
||||||
"modules/src/em_data+lib",
|
"modules/src/em_data+lib",
|
||||||
|
|
|
@ -87,7 +87,7 @@ pattern :
|
||||||
if (patCBO) {
|
if (patCBO) {
|
||||||
register int i;
|
register int i;
|
||||||
|
|
||||||
if (! rplCBO) {
|
if (! rplCBO) {
|
||||||
yyerror("No CBO in replacement");
|
yyerror("No CBO in replacement");
|
||||||
}
|
}
|
||||||
for (i=0; i<sizeof(CBO_instrs)/sizeof(int); i++) {
|
for (i=0; i<sizeof(CBO_instrs)/sizeof(int); i++) {
|
||||||
|
@ -153,8 +153,7 @@ optexpr : /* empty */
|
||||||
{ $$ = 0; }
|
{ $$ = 0; }
|
||||||
| expr
|
| expr
|
||||||
;
|
;
|
||||||
expr
|
expr : '$' argno
|
||||||
: '$' argno
|
|
||||||
{ $$ = lookup(0,EX_ARG,$2,0); }
|
{ $$ = lookup(0,EX_ARG,$2,0); }
|
||||||
| NUMBER
|
| NUMBER
|
||||||
{ $$ = lookup(0,EX_CON,(int)(short)$1,0); }
|
{ $$ = lookup(0,EX_CON,(int)(short)$1,0); }
|
||||||
|
@ -382,25 +381,26 @@ outpat(exprno, instrno)
|
||||||
{
|
{
|
||||||
register int i;
|
register int i;
|
||||||
|
|
||||||
outbyte(0); outshort(prevind); prevind=curind-3;
|
outbyte(0); outshort(prevind); prevind=curind-3;
|
||||||
out(patlen);
|
out(patlen);
|
||||||
for (i=0;i<patlen;i++) {
|
for (i=0;i<patlen;i++) {
|
||||||
if (patmnem[i] == op_CBO) outbyte(instrno);
|
if (patmnem[i] == op_CBO) outbyte(instrno);
|
||||||
else outbyte(patmnem[i]);
|
else outbyte(patmnem[i]);
|
||||||
}
|
}
|
||||||
out(exprno);
|
out(exprno);
|
||||||
out(rpllen);
|
out(rpllen);
|
||||||
for (i=0;i<rpllen;i++) {
|
for (i=0;i<rpllen;i++) {
|
||||||
if (rplmnem[i] == op_CBO) outbyte(instrno);
|
if (rplmnem[i] == op_CBO) outbyte(instrno);
|
||||||
else outbyte(rplmnem[i]);
|
else outbyte(rplmnem[i]);
|
||||||
out(rplexpr[i]);
|
out(rplexpr[i]);
|
||||||
}
|
}
|
||||||
#ifdef DIAGOPT
|
#ifdef DIAGOPT
|
||||||
outshort(patno);
|
/* outshort(patno); */
|
||||||
|
outshort(lino - 1);
|
||||||
#endif
|
#endif
|
||||||
patno++;
|
patno++;
|
||||||
printf("\n");
|
printf("\n");
|
||||||
if (patlen>maxpatlen) maxpatlen=patlen;
|
if (patlen>maxpatlen) maxpatlen=patlen;
|
||||||
}
|
}
|
||||||
|
|
||||||
outbyte(b) {
|
outbyte(b) {
|
||||||
|
@ -424,4 +424,3 @@ out(w) {
|
||||||
outshort(w);
|
outshort(w);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -641,13 +641,13 @@ lol lol bne $1==$2 :
|
||||||
loe loe bne $1==$2 :
|
loe loe bne $1==$2 :
|
||||||
lil lil bne $1==$2 :
|
lil lil bne $1==$2 :
|
||||||
|
|
||||||
lol lol teq $1==$2 : loc 1
|
lol lol cms teq $1==$2 && $3==w : loc 1
|
||||||
loe loe teq $1==$2 : loc 1
|
loe loe cms teq $1==$2 && $3==w : loc 1
|
||||||
lil lil teq $1==$2 : loc 1
|
lil lil cms teq $1==$2 && $3==w : loc 1
|
||||||
|
|
||||||
lol lol tne $1==$2 : loc 0
|
lol lol cms tne $1==$2 && $3==w : loc 0
|
||||||
loe loe tne $1==$2 : loc 0
|
loe loe cms tne $1==$2 && $3==w : loc 0
|
||||||
lil lil tne $1==$2 : loc 0
|
lil lil cms tne $1==$2 && $3==w : loc 0
|
||||||
|
|
||||||
lol loc CBO stl $3==w && $1==$4 : loc $2 lol $1 CBO w stl $4
|
lol loc CBO stl $3==w && $1==$4 : loc $2 lol $1 CBO w stl $4
|
||||||
lol loe CBO stl $3==w && $1==$4 : loe $2 lol $1 CBO w stl $4
|
lol loe CBO stl $3==w && $1==$4 : loe $2 lol $1 CBO w stl $4
|
||||||
|
|
Loading…
Reference in a new issue