Commit graph

1891 commits

Author SHA1 Message Date
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
David Given b1576e2c77 Add support for negative constants in external initialisers. 2016-12-31 19:43:03 +00:00
David Given a01523a893 Allow programs to override binit() (so they can register their own modules). 2016-12-31 17:39:51 +00:00
David Given 803b81e3f4 Add support for the xor operator. 2016-12-31 17:36:12 +00:00
David Given c3e1ef1064 B patch table names shouldn't be in the B symbol namespace. 2016-12-31 00:14:28 +00:00
David Given fa02a855e8 Fix issue where !x was actually calculating !!x. 2016-12-31 00:14:04 +00:00
David Given ebd424e7f1 First draft of the B module code; a module name can now be specified as a
compiler flag, which is used to set the name of the patch table. The compiler
now understands C preprocessor line directives. Extend the standard library
somewhat.
2016-12-29 17:10:21 +00:00
David Given e50f4be710 Merge from default. 2016-12-26 19:44:48 +00:00
David Given c569ca15d8 Clean up how the language libraries refer to plat headers; they should be using
the +pkg forms of the rules and getting the headers via the paths in descr,
rather than depending on the +headers version.
2016-12-05 21:05:24 +01:00
David Given bbcc08a6b6 Fix putchar() return value. 2016-11-28 21:38:46 +01:00
David Given 9f34262f95 Implement enough libb to make 'Hello, world!' work. 2016-11-27 22:05:15 +01:00
David Given b9665c7c99 Fix some basic showstopping bugs; compilation now works up to failing to find
the libb standard library.
2016-11-27 21:08:14 +01:00
David Given 4485d89b23 Hook the B compiler up to the compiler driver. 2016-11-27 20:48:07 +01:00
David Given 5bce5fc4da Change the extension used by Basic files for .b to .bas, to avoid conflicts
with B.
2016-11-27 20:38:33 +01:00
David Given 707585b67d Perform initial (i.e. feature complete and compiling, but not necessarily
working) port of the B compiler to EM.
2016-11-27 20:28:19 +01:00
David Given cfc723250f Initial EM-ification; start threading word size stuff through the code. 2016-11-27 11:58:59 +01:00
David Given a69045c0e4 Import aap@github's B compiler. 2016-11-27 11:37:25 +01:00
David Given 3e69d1185a Fix a whole lot more stray prototypes. 2016-11-24 21:47:40 +01:00
David Given b8a2935f2b Fix more invalid prototypes of stdlib functions; build dependency fix. 2016-11-24 21:26:05 +01:00
David Given c084f9f224 Remove the Mark() and Release() procedures from the Pascal compiler and
standard library, because they never worked and come from an achingly old
version of the Pascal specification. Fix the implementations of New() and
Dispose() to use the standard C memory allocator rather than rolling their own
(also in C). Write test!
2016-11-24 20:35:26 +01:00