Commit graph

2012 commits

Author SHA1 Message Date
David Given 436d50b54c Create correctly sized csa descriptors in the Basic compiler. 2018-09-20 00:49:31 +02:00
David Given 79fd34dac6 Call atexit handlers properly, avoiding a NPE and seg fault every time a
program exits.
2018-09-09 18:51:00 +02:00
David Given b76352de99 Remove stray #include. 2018-09-02 12:54:53 +02:00
David Given cb983fac44 Rip out the built-in preprocessor from cemcom.ansi, now it's no longer used. 2018-09-02 12:50:50 +02:00
David Given 6931ffa5a4 Disable the built-in preprocessor in cemcom.ansi; the external preprocessor is
always run. Fix a bug in block skipping in the preprocessor.
2018-09-02 12:39:00 +02:00
David Given f8fc5bc3d8 Implement single-line C++-style comments.
Fixes: #118
2018-09-02 12:14:59 +02:00
David Given 0e9736fdca Run through clang-format before editing. 2018-09-02 12:04:33 +02:00
David Given 274ed3cb6a Run through clang-format before editing. 2018-09-02 11:49:40 +02:00
David Given dd00b81080 Run files through clang-format before editing. 2018-09-02 11:36:15 +02:00
David Given 788f439a48 Run files through clang-format before editing. 2018-09-02 11:16:06 +02:00
David Given 7971bdba5a Warning-fixed and ansified the Modula-2 library. 2018-06-25 22:22:37 +02:00
David Given f8ba7ef962 Move the Modula-2 library includes into a directory in lang/m2 where they belong. 2018-06-24 20:32:59 +02:00
David Given 1702d873ea Warning-fix and protoise the basic library. 2018-06-24 00:35:51 +02:00
David Given fd94e219d4 Remove the attic. 2018-06-23 23:16:22 +02:00
David Given 59dbdea48a Move mktemp to sys; attic getgrent as noone will ever use this. 2018-06-23 23:15:42 +02:00
David Given 3f10299f43 Move the portable time code into core. clock() goes into sys (as it calls
times()).
2018-06-23 19:49:29 +02:00
David Given 64ae1d7583 Move time() into sys; change the name of the variable which controls it. 2018-06-23 19:40:50 +02:00
David Given bb78fd158c Move the big gnarly functions like system() and popen() into sys, and make them
build.
2018-06-23 19:18:16 +02:00
David Given 6a729b846a Move stdio into (mostly) sys. 2018-06-23 18:54:40 +02:00
David Given af22b7ea85 Change stdio to use atexit() rather than the internal __clean variable; this
breaks the dependency between exit/atexit and stdio. Buffers are no longer
flushed on abort() (because it's pretty risky). Move the relevant functions
into sys/core.
2018-06-23 18:35:45 +02:00
David Given f744a21699 All the opendir()/readdir() stuff is obsolete because it's all implemented in
terms of open() and read(), which isn't how it's done any more; move the
functions into an attic.
2018-06-23 18:25:26 +02:00
David Given df1cdf7762 Add the sys directory for libc functions which use system calls; move the
malloc functions in there.
2018-06-23 18:08:03 +02:00
David Given c4e4505a73 Move the errno functions into core. 2018-06-23 17:52:15 +02:00
David Given 538eefb573 Get em22 working. Remove the leading-underscore system calls from its libsys. 2018-06-23 15:57:57 +02:00
David Given 680b4071b7 Made the two OSX platforms work with the new libc layout. 2018-06-23 12:55:59 +02:00
David Given b727b7affd Make linuxppc work. 2018-06-23 12:41:54 +02:00
David Given b267b56ad9 Made linux68k work; commoned up all the generic linux includes. 2018-06-23 12:35:17 +02:00
David Given 66815ff987 Make linux386 work with the new libc layout. 2018-06-23 12:13:33 +02:00
David Given 32c881474e Create a basic and probably wrong common unistd.h, which replaces the plat one.
Made this work with cpm (but nothing else yet).
2018-06-23 11:46:55 +02:00
David Given dd0f959245 Move assert into core. 2018-06-23 11:16:06 +02:00
David Given 5fd8d772fd Move the string-to-float functions into core, after marking them as
ACKCONF_WANT_FLOAT.
2018-06-23 11:14:24 +02:00
David Given 94ffa3ba88 libc floating point and stdio floating point can now be turned on and off using
ACKCONF variables.
2018-06-23 00:04:14 +02:00
David Given 9bf1d548fc Rearrange the libc config files, ready for adding new options. 2018-06-22 23:43:15 +02:00
David Given b21c099a57 Get the em libc working again: remove the modula-2 termcap library, as it's a
straight copy of the libc one and having two symbols defined at once gets ass
upset.
2018-06-22 23:17:14 +02:00
David Given c0276416d8 Move some more libc functions into core. 2018-06-22 22:20:02 +02:00
David Given d1cdb07719 Realise that the libc core can safely call other libc core functions, even if
they're not defined in the core: so putw() can call stdio stuff, for example.
So the earlier concept of pureness isn't necessary. Rename accordingly.
2018-06-21 23:24:23 +02:00
David Given 62025c92bd The ctype functions are pure. 2018-06-21 23:06:29 +02:00
David Given d9d7ffe0d7 The maths library is pure. 2018-06-21 23:00:33 +02:00
David Given f9c059812b Moved the setjmp functions into the new pure directoy. 2018-06-21 22:55:42 +02:00
David Given 32f47b1d24 Move the pure locale functions into the new pure directory. 2018-06-21 22:54:25 +02:00
David Given b9d2f353d9 Move the pure stdlib functions into the new pure directory. 2018-06-21 22:52:31 +02:00
David Given 4dbdb7d8d5 Rethink the libc layout. 2018-06-21 22:47:02 +02:00
David Given 83e1b2ad94 Move the str and mem functions into the new src/core. 2018-06-21 22:39:08 +02:00
David Given 93f39e4bbf Run libcc.ansi through clang-format. 2018-06-21 22:33:47 +02:00
David Given 698613cd7d Turns out that the compiler needs access to the libpc headers too; refactor
into a separate target to avoid build loops and make it work.
2018-06-18 22:17:38 +02:00
David Given 11854f4dfe Ansify and warning fix. 2018-06-17 22:30:27 +02:00
David Given 5784f5fabe Run C files through clang-format. 2018-06-17 16:11:29 +02:00
David Given 9ede428e3c Use cproto to extract all the prototypes. 2018-06-17 16:10:57 +02:00
David Given 9947e7ac63 Added a pc.h to contain libpc prototypes; some ansification. 2018-06-17 15:54:18 +02:00
David Given d1671fc2e3 Move the private Pascal headers into libpc where they belong. 2018-06-17 15:44:33 +02:00
David Given 13e195d19f Warning fixes. 2018-06-17 15:42:26 +02:00
David Given 7eaa235fd1 Bodge the ancient em monitor library into building as a libsys for the em22
plat. It's completely untested, but it builds and makes e.out executables.
2018-06-13 21:44:25 +09:00
David Given 13a7abdd69 Rename a function to avoid a clash with an em system call. 2018-06-13 21:34:14 +09:00
David Given d623440c77 Add the core of a simple em22 platform. Unfortunately it doesn't work; the old
em libmon vanished decades ago (or never existed), and also ass appears to have
a different idea of what the em opcodes are to everything else and gets
confused.
2018-06-10 20:25:48 +09:00
David Given 3f049a4c29 Basic mid now throws an error on out-of-bounds parameters rather than returning
an uninitialised pointer (and crashing).

Fixes: #54
2018-06-05 09:53:56 +09:00
David Given b85c25e4e5 Fix resource leak.
Closes: #75
2018-06-02 20:59:11 +02:00
David Given d6e65833fb Format. 2018-06-02 20:57:43 +02:00
David Given 05ddefad65 Adopt a copy of Minix 2's ed; this allows the ACK's antiquated ed scripts to
run with a minimum of tweaking. Rewriting them for modern ed looks really hard.

Fixes: #84
2018-06-02 18:02:51 +02:00
David Given d5a9f1541a lchar() needs to return the character written. (This happens by magic on 386,
but no on PPC.) See #72.
2018-03-11 11:00:35 +01:00
David Given 6d91bdbbbd
Merge pull request #69 from kernigh/kernigh-stdc
use libc assert, strcmp; declare more functions; fewer clang warnings
2017-11-19 12:00:40 +01:00
David Given fb90b7b8d8
Merge pull request #66 from davidgiven/dtrg-warnings
lang/basic/lib: fewer warnings
2017-11-19 11:39:45 +01:00
George Koehler 87a2315037 strcmp, strncmp are in <string.h>
*Important:*  Do `make clean` to work around a problem and prevent
infinite rebuilds, https://github.com/davidgiven/ack/issues/68

I edit tokens.g in util/LLgen/src, so I regenerate tokens.c.  The
regeneration script bootstrap.sh can't find LLgen, but I can run the
same command by typing the path to llgen.
2017-11-14 17:35:35 -05:00
George Koehler 229b80a004 Free buf in GetFile().
aprintf() returns a const char *; the assignment to char * caused both
clang and gcc to warn of the dropped const.

Commit 893471a introduced a tiny memory leak, because GetFile()
stopped freeing buf.  The const return type of aprintf() suggests that
the buffer must not be freed.

Now use Malloc() to allocate the buffer and free() to free it.  This
also checks if we are out of memory, because Malloc() does the check
and aprintf() currently doesn't.
2017-11-13 21:34:31 -05:00
George Koehler 974fa93491 Silence warning about pointer cast to int.
This cast was safe because the pointer is a small constant integer,
but it causes warning from gcc.
2017-11-13 20:58:57 -05:00
George Koehler ddf9de3f49 strcpy() is in <string.h> 2017-11-13 17:57:02 -05:00
George Koehler 3463f0c944 bts2str(), long2str() are in <ack_string.h> 2017-11-10 18:00:00 -05:00
George Koehler ca4bd38206 Delete old "assert.h" files; use libc <assert.h>.
Edit build.lua for programs losing their private assert.h, so they
depend on a list of .h files excluding assert.h.

Remove modules/src/assert; it would be a dependency of cpp.ansi but we
didn't build it, so cpp.ansi uses the libc assert.

I hope that libc <assert.h> can better report failed assertions.  Some
old "assert.h" files didn't report the expression.  Some reported a
literal "x", because traditional C expanded the macro parameter x in
"x", but ANSI C89 doesn't expand macro parameters in string literals.
2017-11-09 22:22:13 -05:00
George Koehler 9ff79c53dd Update comment after commit 9a965ef. 2017-10-30 21:24:18 -04:00
George Koehler 50a7031007 Don't use '-' in option string to getopt().
@dram reported a build failure in FreeBSD at
https://github.com/davidgiven/ack/issues/1#issuecomment-273668299

Linux manual for getopt(3) says:
> If the first character of optstring is '-', then each nonoption
> argv-element is handled as if it were the argument of an option with
> character code 1....
>
> The use of '+' and '-' in optstring is a GNU extension.

GNU/Linux and OpenBSD handle '-' in this special way, but FreeBSD
seems not to.  If '-' is not special, then em_ego can't find its input
file, so the build must fail.  This commit stops using '-' in both
em_b and em_ego, but doesn't change mcg.

Also fix em_ego -O3 to not act like -O4.
2017-10-29 23:25:07 -04:00
George Koehler 59b3c10563 Use (arith) 1 << ... when getting the sign bit.
This prevents an overflow reported by @hexcoder- in
https://github.com/davidgiven/ack/issues/56

lang/cem/cpp.ansi/LLlex.c used a plain 1 << ... and caused an overflow
on machines where sizeof(int) < sizeof(long).  Using 1L << ... would
work for now but might fail later if arith became long long.

C doesn't specify whether negative integers use 2's complement or some
other format.  Therefore, (arith) 1 << ... has an undefined value.  It
should still work because the value is some integer where the sign bit
is set and all other bits are clear.

(unsigned arith) 1 << ... would also get the sign bit, but casting it
from unsigned back to signed would make the same undefined value.

(arith) -1 << ... would assume 2's complement.
2017-10-29 17:45:10 -04:00
George Koehler d36807b395 Remove UNSIGNED_ARITH from a few more files.
I missed these in commits 649410b and 1ab1306.
2017-10-29 17:03:51 -04:00
George Koehler 1ab1306baa Always use unsigned long in lang/cem
Same reason as commit 649410b.
2017-10-29 17:01:29 -04:00
George Koehler 038fb6fb55 Get correct sign of a MOD b when (a > 0) and (b < 0).
Reported by me in https://github.com/davidgiven/ack/issues/60

This doesn't change DIV.  Right now a DIV b does floor division and
a MOD b has the sign of b.  This is the same as Lua, Python, Ruby,
Tcl; but is different from other Modula-2 implementations.
2017-10-28 19:55:06 -04:00
George Koehler 649410bb27 Always use unsigned long.
Traditional C compilers had long but not unsigned long.  I now assume
that everyone can compile unsigned long.  Remove macro UNSIGNED_ARITH
and act like it is always defined.  The type `unsigned arith` works
because arith is a macro for long.
2017-10-28 17:56:20 -04:00
George Koehler 9a965efae8 Terminal now writes to fd 1, not fd 0.
Fixes problem where `./program </dev/null` didn't show output.
2017-10-28 17:20:39 -04:00
George Koehler 75ae957c75 Don't check ferror(fp) when reading fp.
If feof(fp) or ferror(fp) was set, then our libc returned EOF for all
later reads without trying to read.  Our libc now behaves like BSD
(and probably Illumos and musl) by checking only feof(fp).  For
difference, glibc doesn't check feof(fp).

I described the difference between our libc and BSD libc in
https://sourceforge.net/p/tack/mailman/message/35430300/
2017-10-28 16:20:48 -04:00
George Koehler 54028e403e Delete unused misc/getpw.c from libc.
@hexcoder- reported in https://github.com/davidgiven/ack/issues/57
that our getpw() has bugs.

I don't fix these bugs, because Illumos and Linux manual pages say
that getpw() is obsolete.  The function can overflow its buffer, so it
is never safe to use.  Our libc did not build getpw().
2017-10-28 14:25:39 -04:00
George Koehler 0a2dfd650d Delete malloc.h and tgmath.h from libc.
This malloc.h might get confused with the private malloc.h in our
libc.  C programs should #include <stdlib.h> for malloc().

This tgmath.h has no useful content, and never worked because
complex.h is missing.

Touch build.lua (by deleting some whitespace) so the *.h globs see
the deletions.
2017-10-28 14:24:35 -04:00
George Koehler b00a2c906d Build fdopen(), hypot(), putenv() in libc.
These functions are in POSIX; hypot() is in C99.  Also build cabs()
because it rides with hypot(), but don't declare cabs() in any header
file, because our compiler can't parse C99 "double complex" type.

Touch build.lua so it sees that .c files moved.
2017-10-28 13:33:57 -04:00
David Given 60e7d06d82 Ansification and warning fixes. 2017-08-06 11:58:36 +02:00
David Given a1043bc5fe Attempt to correct file system case sensitivity. 2017-08-06 11:15:53 +02:00
David Given fd10cf7ac2 Merge from trunk. 2017-08-06 10:42:16 +02:00
David Given a9f19a2a31 Merge. 2017-08-05 21:47:40 +02:00
David Given 064fd52d52 Update man page not to mention the filename length restriction removed in
893471a42e.
2017-08-02 00:07:51 +02:00
David Given f2e3d7b38c Don't define functions called itoa(), because this causes problems on platforms
that define itoa() in their libcs.
2017-07-23 21:19:07 +02:00
George Koehler f91bc2804d Tune the installed manual pages.
This commit slightly improves the formatting of the manuals.  My
OpenBSD machine uses mandoc(1) to format manuals.  I check the manuals
with `mandoc -T lint` and fix most of the warnings.  I also make
other changes where mandoc didn't warn me.

roff(7) says, "Each sentence should terminate at the end of an input
line," but we often forgot this rule.  I insert some newlines after
sentences that had ended mid-line.

roff(7) also says that blank lines "are only permitted within literal
contexts."  I delete blank lines.  This removes some extra blank lines
from mandoc's output.  If I do want a blank line in the output, I call
".sp 1" to make it in man(7).  If I want a blank line in the source,
but not the output, I put a plain dot "." so roff ignores it.

Hyphens used for command-line options, like \-a, should be escaped by
a backslash.  I insert a few missing backslashes.

mandoc warns if the date in .TH doesn't look like a date.  Our manuals
had a missing date or the RCS keyword "$Revision$".  Git doesn't
expand RCS keywords.  I put in today's date, 2017-01-18.

Some manuals used tab characters in filled mode.  That doesn't work.
I use .nf to turn off filled mode, or I use .IP in man(7) to make the
indentation without a tab character.

ack(1) defined a macro .SB but never used it, so I delete the
definition.  I also remove a call to the missing macro .RF.

mandoc warns about empty paragraphs.  I deleted them.  mandoc also
warned about these macro pairs in anm(1):

    .SM
    .B text

The .SM did nothing because the .B text is on a different line.  I
changed each pair to .SB for small bold text.

I make a few other small changes.
2017-01-18 23:02:30 -05:00
David Given b32be06881 Allow the full 8-bit byte range when reading program source. 2017-01-15 22:41:11 +01:00
David Given 5ff983ad9b Increase the number of items in a char set from 128 to 256, to cover all
possible bytes (7-bit bytes are so 70s).
2017-01-15 22:30:25 +01:00
David Given fd83b09c58 Fix typo. 2017-01-08 18:53:59 +01:00
David Given 612e14b4b4 Improve confusing error message when calling function procedures from a
top-level statement.

Fixes: #30
2017-01-08 11:25:57 +01:00
David Given ee5ef73dfb Run through clang-format. 2017-01-08 11:23:56 +01:00
David Given 893471a42e No longer truncate module names at 10 characters when constructing paths;
rename some library modules to their full names.
2017-01-07 23:00:52 +01:00
David Given d50a6f99de Run through clang-format. 2017-01-07 22:56:00 +01:00
David Given 9945b019d2 Add a B man page. 2017-01-07 22:35:02 +01:00
David Given 5a38ce2a69 Pre-and-post-modification operators now work substantially better (i.e.,
working).
2017-01-07 18:46:03 +01:00
David Given 77fc62285d Extern variables can now be written to. 2017-01-06 23:24:05 +01:00
David Given 62bc2ab97a Jump tables for switch now go in ROM (required by the EM spec). Forward gotos
now work.
2017-01-01 23:28:41 +00:00
David Given 8b8910595a Add proper support for negative constants in external initialisers. 2017-01-01 17:56:53 +00:00
David Given 049aff9f33 Remove the negative-constant code from the compiler; I think it's going to
break a=-1 (with no spaces). Backed out changeset dead3363ac7d.
2017-01-01 17:44:55 +00:00
David Given 374e7a1c57 Add support for the ~ operator. 2017-01-01 17:40:06 +00:00