Commit Graph

215 Commits

Author SHA1 Message Date
Lassi Kortela 9d4bf19367 Fix regression in ios_printf implementation
There was some problem with the way the varargs are handled. We had to
need to make (at least one) copy of them with va_copy(). The code is
brittle and I don't understand it, so just rip it all out and replace
with a fixed-size static buffer. It's a hack but we'll soon get rid of
printf completely so this will get us through the day until then.
2019-08-23 00:38:10 +03:00
Lassi Kortela da02e9e554 Add missing sys/stat.h
Fixes failed OpenBSD build. How did it work before?
2019-08-22 00:05:57 +03:00
Lassi Kortela 34d417b4fc Change library name to (upscheme 2019 unstable)
The "unstable" is a new addition.
2019-08-21 22:18:53 +03:00
Lassi Kortela 682cbf2400 Add builtin_spawn stub for Windows 2019-08-21 22:18:20 +03:00
Lassi Kortela 2ff16a0182 Add Windows ID functions
Mostly of them are dummy placeholders that return false
2019-08-21 22:17:06 +03:00
Lassi Kortela b2027fe023 Split setenv/unsetenv by platform
Windows apparently doesn't have unsetenv() at all, so use the WinAPI
native envar functions instead of the usual C ones.
2019-08-21 22:16:07 +03:00
Lassi Kortela 5caf337589 Stub builtin_environment_stack for Windows 2019-08-21 22:15:19 +03:00
Lassi Kortela 0d95c386ac Fix socket includes 2019-08-21 22:14:04 +03:00
Lassi Kortela ebefb2a519 Stub time functions for Windows
Need to rethink all time stuff and read the relevant SRFIs.
2019-08-21 22:12:19 +03:00
Lassi Kortela 6ffe6bf174 Add truly sinful float hacks for Watcom 2019-08-21 22:11:05 +03:00
Lassi Kortela 439eeb2b06 Use vsnprintf() instead of vasprintf()
Windows doesn't reliably offer *asprintf() (sprintf functions that
automatically malloc as much memory as they need) so hand-roll the
equivalent on all platforms.
2019-08-21 22:10:13 +03:00
Lassi Kortela c76379e6f5 Brace try/except in main() for Watcom 2019-08-21 22:08:21 +03:00
Lassi Kortela 60ff06fb6d Reorganize error functions and includes
These functions are complicated because they need to be marked
"noreturn" for the compiler. There are several fundamentally
incompatible ways of doing that. Since we have only a few "noreturn"
functions, let's just list all of those in one header file of which
there is a completely different version for each compiler.
2019-08-21 22:06:13 +03:00
Lassi Kortela debbcdf857 Add missing #endif 2019-08-19 09:49:14 +03:00
Lassi Kortela ddb6116df9 Add bits and endian for Watcom compiler 2019-08-19 01:20:40 +03:00
Lassi Kortela a6fd653000 Add missing includes for Windows 2019-08-19 01:20:02 +03:00
Lassi Kortela 69f46bd4c2 Do not use special _fileno for windows 2019-08-19 01:19:03 +03:00
Lassi Kortela d12fd5cea7 Split _enonfatal() for Windows 2019-08-19 01:18:36 +03:00
Lassi Kortela 35acc782d9 Remove asm byteswap implementations 2019-08-19 01:17:54 +03:00
Lassi Kortela e2dffd97fe Remove time.now and parsetime functions 2019-08-19 01:15:28 +03:00
Lassi Kortela 023937e5ea Use backward compatible variable initializers 2019-08-19 01:14:09 +03:00
Lassi Kortela 486ec48a76 Remove spurious time includes 2019-08-18 13:44:06 +03:00
Lassi Kortela d065a0039d Define float_t and double_t for Watcom C 2019-08-18 13:40:25 +03:00
Lassi Kortela 9571262535 Use backward compatible variable initializers 2019-08-18 13:40:04 +03:00
Lassi Kortela 7025b8cd32 Split fl_path_exists() into Unix and Windows 2019-08-18 13:39:08 +03:00
Lassi Kortela 3448e8f150 Include missing <stdarg.h> 2019-08-18 13:36:43 +03:00
Lassi Kortela 3dc58baa4a Include <sys/types.h> to get off_t
This header is even shipped by Windows compilers. The iostream stuff
uses off_t.
2019-08-18 00:09:43 +03:00
Lassi Kortela baea23ab29 Switch to portable noreturn attributes 2019-08-18 00:07:46 +03:00
Lassi Kortela edf7c991f4 Remove unneeded DLLEXPORT and STDCALL macros 2019-08-17 22:55:25 +03:00
Lassi Kortela b60d330df1 Add hacky subprocess spawn procedure 2019-08-14 20:31:39 +03:00
Lassi Kortela 2d0add09d5 Add color-name->rgb24 procedure 2019-08-14 20:02:48 +03:00
Lassi Kortela cfdb8f2928 Add get-ID procedures from draft SRFI 170 2019-08-14 17:48:13 +03:00
Lassi Kortela ca8e23c079 Add builtins.h file missing from last commit 2019-08-14 13:54:50 +03:00
Lassi Kortela 78a04430ce Add read-ini-file procedure
Reads a .ini file into an association list. No [section] parsing yet.
2019-08-14 13:49:56 +03:00
Lassi Kortela 7ac23c6f0b Add scanner interface to "struct buf"
Can be used to easily write simple parsers in C.
2019-08-14 13:46:50 +03:00
Lassi Kortela 44a8208d38 Add buf_put_ios() utility function
Fills a "struct buf" with the entire remainder of a stream.
2019-08-14 13:39:11 +03:00
Lassi Kortela a6ecac95e1 Rename fs*.c -> os*.c
I planned to put just the file system routines into these files, but
there are starting to be so many of them that I don't want to
duplicate the same set for networking, subprocesses etc.
2019-08-14 01:15:29 +03:00
Lassi Kortela bf11066313 Add stubs for Haiku, Minix and Solaris 2019-08-14 00:01:26 +03:00
Lassi Kortela 5ced8d91f6 Store boot image inside main executable
Previously the boot image was kept in the separate file "flisp.boot".
This caused all kinds of problems, as bootstrapping is wont to do. The
biggest problem was finding a portable and convenient pathname for it.

Instead of dealing with all that stuff about how to find the file,
just store the image in a huge C string constant that goes into the
main executable. This necessitates adding a C-string hex dumper into
the Lisp system, and making build.sh slightly more complicated, but
that's a small price to pay for not having to carry a separate file
everywhere we go. Also, flmain.c is a lot simpler now and we don't
have to play around with symlinks.
2019-08-13 23:07:44 +03:00
Lassi Kortela 2e8153019c Add read-u8 built-in (R7RS)
io.getc gets UTF-8 characters
2019-08-13 22:53:37 +03:00
Lassi Kortela c2da0753af Fix some more "long double" nonsense 2019-08-13 18:51:43 +03:00
Lassi Kortela 71098dd01b Fix some "long double" nonsense
Apparently in addition to "float", "double" and "long double" there
are now standard types in <math.h> called "float_t" and "double_t".
Those types don't need to be equivalent to "float" and "double". Gah!
2019-08-13 18:28:19 +03:00
Lassi Kortela 4a89521493 Use 'int' instead of 'char' for character variables
MINIX libc headers define the ctype.h toupper() etc. functions as
preprocessor macros that don't cast their argument to int! So a char
argument causes clang to say "warning: array subscript is of type
'char'".
2019-08-13 17:53:17 +03:00
Lassi Kortela 10eb936836 Start file system support for NetBSD 2019-08-13 15:53:37 +03:00
Lassi Kortela 9b737144ea Fix portability bugs uncovered by Alpine Linux/musl libc 2019-08-13 14:19:38 +03:00
Lassi Kortela 277abddaa8 Turn (import ...) into a macro to match Scheme syntax 2019-08-12 18:18:46 +03:00
Lassi Kortela 5012977d32 Start environment-stack implementation 2019-08-11 23:27:38 +03:00
Lassi Kortela f2068b5783 Add missing const qualifiers 2019-08-11 23:27:12 +03:00
Lassi Kortela 3b13e81eae Add concept of built-in libraries and (import) statement
R7RS syntax is: (import (library name here))

We translate this into the internal path "library/name/here". This will allow
us to easily load libraries from files later on by appending the ".sld" file
name extension.
2019-08-11 22:32:55 +03:00
Lassi Kortela c704079cae Add string buffer
TODO: Consider merging with 'struct ios'
2019-08-11 22:31:54 +03:00
Lassi Kortela b441573bde Enable #x-1_2_3 syntax and get rid of -0x123 2019-08-10 16:13:26 +03:00
Lassi Kortela d5bb6b3116 Start changing all instances of 0x to #x
After this commit -0x123 is still supported, but 0x123 is not.
2019-08-10 15:51:43 +03:00
Lassi Kortela 003068f575 Add first stab at SRFI 169 underscores support 2019-08-10 15:41:05 +03:00
Lassi Kortela 93813a9eb1 Remove unneeded numerical constants
To the extent we need these, we can get them from the stdlib.
2019-08-10 02:12:54 +03:00
Lassi Kortela 10660ac8ed Start fs implementation for DragonFly BSD 2019-08-10 02:04:11 +03:00
Lassi Kortela fe01d2faa1 Simplify FreeBSD get_exename() 2019-08-10 02:02:41 +03:00
Lassi Kortela 2950e6ae5b Set _X_OPEN_SOURCE and default compiler in build script 2019-08-10 01:43:47 +03:00
Lassi Kortela 0e75fcb197 Fix regression in u8_vprintf()
My fault
2019-08-10 01:05:41 +03:00
Lassi Kortela be3c93e2b8 Define _XOPEN_SOURCE to access some libc functions on Linux 2019-08-10 01:02:59 +03:00
Lassi Kortela 08027cac9b Add some missing system includes
Uncovered by Linux build
2019-08-10 01:02:27 +03:00
Lassi Kortela 10763df501 Add fallthrough comments to switch cases
Some versions of GCC warn otherwise, which is good.
2019-08-10 01:01:40 +03:00
Lassi Kortela 2ec07684d2 Get OS name from uname()
This implies that OS names have changed. Unix-like OS names are now
capitalized. "macos" is now "Darwin". Windows is now all-lowecase "windows".
"win32" is gone. "win64" was not used in the original code despite a reference
to it.
2019-08-10 00:35:16 +03:00
Lassi Kortela be6a18175f Add const qualifier to some symbol/keyword functions 2019-08-10 00:30:20 +03:00
Lassi Kortela 3751d83390 Remove unneeded prototypes using sockaddr_in 2019-08-10 00:16:30 +03:00
Lassi Kortela e9d6ca265c Unify preprocessor checks for win32
<https://sourceforge.net/p/predef/wiki/OperatingSystems/> says that _WIN32 is
always defined for both 32-bit and 64-bit versions of Windows.
2019-08-10 00:12:33 +03:00
Lassi Kortela 267cd00146 Remove unnecessary ifdef about unsetenv() return value
Posix now mandates that unsetenv() must return -1 and set errno on error.
2019-08-10 00:05:31 +03:00
Lassi Kortela 95a1c1032c Remove ifdef about memrchr() on MacOS
MacOS doesn't have memrchr() so there was an ifdef with a custom
implementation for it. Get rid of the ifdef by always using the custom
implementation.
2019-08-10 00:02:14 +03:00
Lassi Kortela daaa5aaed0 Break down timefuncs.c to unix and windows 2019-08-09 23:56:18 +03:00
Lassi Kortela 8a7ce61575 Replace uses of alloca() with malloc()
Gets rid of more #ifdef magic.
2019-08-09 23:45:10 +03:00
Lassi Kortela 41f6dbc1a2 Assume 64-bit pointers for now
To get rid of ifdef complexity. Put 32-bit support back in later.
2019-08-09 23:35:50 +03:00
Lassi Kortela d95a4660ad Fix missing NULL definition on FreeBSD 2019-08-09 23:31:27 +03:00
Lassi Kortela b0203bb89e Add more missing stdint.h includes 2019-08-09 23:31:21 +03:00
Lassi Kortela a28aff6892 Add missing stdint.h includes 2019-08-09 23:25:20 +03:00
Lassi Kortela 1d96278313 Break down dirpath.c into fs_*.c by OS
I much prefer this to using ifdefs. Requires a little help from the build
system but I find it worth it.
2019-08-09 23:12:19 +03:00
Lassi Kortela 99feb308bd Hoist argcount() into its own header file
Muffles compiler warnings about unused function.
2019-08-09 22:08:44 +03:00
Lassi Kortela 2610213b42 Do not include bswap* all over the place 2019-08-09 22:04:55 +03:00
Lassi Kortela a7296eeca5 Remove unused 64-bit byte swap 2019-08-09 22:03:36 +03:00
Lassi Kortela 4f047eb187 Replace BSD bzero() with standard memset() 2019-08-09 21:57:26 +03:00
Lassi Kortela 2b65fe4cef Remove unnecessary MacOS-specific includes 2019-08-09 21:56:23 +03:00
Lassi Kortela e19fe0b8bd Remove time.string and time.fromstring builtins
They are of dubious value, and the C implementation uses #if.
2019-08-09 21:50:52 +03:00
Lassi Kortela 36e2057616 Do not include count_bits() all over the place 2019-08-09 21:41:37 +03:00
Lassi Kortela c84c71adcc Get rid of INLINE and STATIC_INLINE
Nowadays compilers have good optimizers that know when to inline static
functions depending on the user's chosen optimization level (and speed vs size
optimization). We don't need to annotate functions manually.
2019-08-09 21:35:20 +03:00
Lassi Kortela 12fb30462b Simplify endian (byte order) detection
The following:

    #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
    #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__

are apparently semi-standard nowadays.
2019-08-09 21:30:30 +03:00
Lassi Kortela 5817003816 Replace index_t with uintptr_t 2019-08-09 21:13:48 +03:00
Lassi Kortela c0ef0c2549 Remove more useless typedefs 2019-08-09 21:11:40 +03:00
Lassi Kortela 36fd757689 Replace ptrint_t with standard intptr_t 2019-08-09 21:07:16 +03:00
Lassi Kortela b35ab48437 Replace "preferred int type" with intptr_t 2019-08-09 21:04:19 +03:00
Lassi Kortela d6a4029dde Replace idiosyncratic C types with standard ones
For number types, we rely on classic C types (char, short, int, long) to be
the correct sizes. For precise bit widths, use standard intN_t and uintN_t.
For size_t, just use system size_t.
2019-08-09 21:00:03 +03:00
Lassi Kortela d5d7406276 Remove unused Boehm GC hooks 2019-08-09 20:37:42 +03:00
Lassi Kortela 10ffed569e Fix build errors and warnings for OpenBSD 2019-08-09 20:20:17 +03:00
Lassi Kortela b7b4269455 Replace strcpy() and strcat() with safer functions 2019-08-09 20:14:42 +03:00
Lassi Kortela b5946dea77 Remove unused INITFILE config option 2019-08-09 20:11:02 +03:00
Lassi Kortela bb78dc0634 Fix compiler warnings (clang -Wextra) 2019-08-09 19:53:35 +03:00
Lassi Kortela 45a7ec7bc4 Remove include protections
Since we no longer have recursive includes, we don't need them. Removing the
protections uncovered a couple of accidental double-includes: good.
2019-08-09 19:47:22 +03:00
Lassi Kortela fe4550dad7 Replace cvalue_t with struct 2019-08-09 19:36:20 +03:00
Lassi Kortela b48261f21c Replace fltype_t with struct 2019-08-09 19:33:04 +03:00
Lassi Kortela c9f5e4faeb Replace symbol_t with struct 2019-08-09 19:30:15 +03:00
Lassi Kortela 193ced5e73 Replace cons_t with struct 2019-08-09 19:28:14 +03:00
Lassi Kortela d6f1579e17 Replace cprim_t with struct 2019-08-09 19:26:48 +03:00
Lassi Kortela fdcdd865b4 Replace function_t with struct 2019-08-09 19:26:48 +03:00
Lassi Kortela ece07d2e1a Replace cvtable_t with struct 2019-08-09 19:26:48 +03:00
Lassi Kortela 428e7a3825 Replace builtinspec_t with struct 2019-08-09 19:26:48 +03:00
Lassi Kortela e54797e4eb Replace fl_exception_context_t with struct 2019-08-09 19:26:48 +03:00
Lassi Kortela 262ace1efd Replace fl_readstate_t with struct 2019-08-09 19:26:42 +03:00
Lassi Kortela b561f9d4b0 Replace gensym_t with struct 2019-08-09 19:26:33 +03:00
Lassi Kortela f2fb37e520 Replace ios_t with struct 2019-08-09 19:26:20 +03:00
Lassi Kortela 41cf0e7b2c Replace htable_t with struct 2019-08-09 19:26:09 +03:00
Lassi Kortela 79d44c0780 Get rid of almost all recursive includes
Simple rule: include files should never include include files.

"Notes on Programming in C", Rob Pike, February 21, 1989
<https://www.lysator.liu.se/c/pikestyle.html>
2019-08-09 19:00:17 +03:00
Lassi Kortela 0701b22d29 Rename #include'd C files from .c to .h 2019-08-09 18:30:02 +03:00
Lassi Kortela d69e40aa3a Delete unused C file 2019-08-09 18:22:10 +03:00
Lassi Kortela 04b3c3b292 Replace tabs with spaces in Lisp printer 2019-08-09 17:25:13 +03:00
Lassi Kortela be9b2b364e Clean up whitespace
- Tabs to spaces
- Remove invisible whitespace at ends of lines
- Break or shorten long lines (not for all files)
2019-08-09 17:25:13 +03:00
Lassi Kortela 09c6368668 Run renamed .inc files by clang-format for the first time 2019-08-09 17:25:13 +03:00
Lassi Kortela 4128fbc535 Rename .inc files to use .h extension 2019-08-09 17:18:21 +03:00
Lassi Kortela d6f54bc13c Consolidate all C files into a "c" subdirectory 2019-08-09 15:02:58 +03:00