Make fatcosmocc good enough to build ncurses 6.4

This commit is contained in:
Justine Tunney 2023-08-12 22:30:05 -07:00
parent 399d14aadf
commit 3f2f0e3a74
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
20 changed files with 295 additions and 139 deletions

View file

@ -113,6 +113,12 @@ _start:
call cosmo
9: .unreachable
// strongly link main() function (discarded by linker)
// libc_runtime had to weakly link, due to package.com
.section .yoink
call main
.previous
////////////////////////////////////////////////////////////////////////////////
#elif defined(__aarch64__)
@ -140,6 +146,12 @@ _start:
bl cosmo
.unreachable
// strongly link main() function (discarded by linker)
// libc_runtime had to weakly link, due to package.com
.section .yoink
bl main
.previous
////////////////////////////////////////////////////////////////////////////////
#else
#error "architecture unsupported"

View file

@ -97,14 +97,6 @@
#pragma GCC push_options
#pragma GCC diagnostic ignored "-Wc++-compat"
#endif
#define HAVE_STDBOOL_H 1
#if __STDC_VERSION__ + 0 >= 201112
typedef _Bool bool;
#else
#define bool int
#endif
#define true 1
#define false 0
typedef __WCHAR_TYPE__ wchar_t;
typedef __CHAR16_TYPE__ char16_t;
typedef __CHAR32_TYPE__ char32_t;
@ -113,6 +105,10 @@ typedef __CHAR32_TYPE__ char32_t;
#endif
#endif /* __cplusplus */
#ifndef __COSMOCC__
#include "libc/stdbool.h"
#endif
#define _LIBCPP_STDINT_H
typedef int errno_t;

View file

@ -1,3 +1,4 @@
#ifndef _STDBOOL_H
#define _STDBOOL_H
#include "libc/stdbool.h"
#endif /* _STDBOOL_H */

View file

@ -3,5 +3,6 @@
#include "libc/calls/calls.h"
#include "libc/calls/struct/sigaction.h"
#include "libc/calls/struct/siginfo.h"
#include "libc/sysv/consts/sig.h"
#include "libc/sysv/consts/sicode.h"
#endif /* COSMOPOLITAN_LIBC_ISYSTEM_SYS_SIGNAL_H_ */

View file

@ -29,8 +29,8 @@ int mergesort_r(void *, size_t, size_t,
#define __algalloc returnspointerwithnoaliases dontthrow nocallback dontdiscard
bool radix_sort_int32(int32_t *, size_t);
bool radix_sort_int64(int64_t *, size_t);
int radix_sort_int32(int32_t *, size_t);
int radix_sort_int64(int64_t *, size_t);
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */

View file

@ -29,22 +29,22 @@
#define get_byte_1(v) (((v) >> 11) & 0x7FF)
#define get_byte_2_flip_sign(v) (((unsigned)(v) >> 22) ^ 0x200)
bool radix_sort_int32(int32_t *A, size_t n) {
int radix_sort_int32(int32_t *A, size_t n) {
int32_t *T, *reader, *writer;
size_t i, pos, sum0, sum1, sum2, tsum, *b0, *b1, *b2;
if (n < HIST_SIZE) {
_intsort(A, n);
return true;
return 0;
}
if (!(T = (int32_t *)malloc(n * sizeof(int32_t)))) {
return false;
return -1;
}
if (!(b0 = (size_t *)calloc(HIST_SIZE * 3, sizeof(size_t)))) {
free(T);
return false;
return -1;
}
b1 = b0 + HIST_SIZE;
@ -97,5 +97,5 @@ bool radix_sort_int32(int32_t *A, size_t n) {
free(b0);
free(T);
return true;
return 0;
}

View file

@ -34,23 +34,23 @@
#define get_byte_2_flip_sign(v) (((unsigned)(v) >> 22) ^ 0x200)
#define get_byte_5_flip_sign(v) ((((v) >> 55) & 0x7FF) ^ 0x400)
bool radix_sort_int64(int64_t *A, size_t n) {
int radix_sort_int64(int64_t *A, size_t n) {
int64_t *T, *reader, *writer;
size_t *b0, *b1, *b2, *b3, *b4, *b5;
size_t i, pos, sum0, sum1, sum2, sum3, sum4, sum5, tsum;
if (n < HIST_SIZE) {
_longsort(A, n);
return true;
return 0;
}
if (!(T = (int64_t *)malloc(n * sizeof(int64_t)))) {
return false;
return -1;
}
if (!(b0 = (size_t *)calloc(HIST_SIZE * 6, sizeof(size_t)))) {
free(T);
return false;
return -1;
}
b1 = b0 + HIST_SIZE;
@ -140,5 +140,5 @@ bool radix_sort_int64(int64_t *A, size_t n) {
free(b0);
free(T);
return true;
return 0;
}

16
libc/stdbool.h Normal file
View file

@ -0,0 +1,16 @@
#ifndef COSMOPOLITAN_LIBC_STDBOOL_H_
#define COSMOPOLITAN_LIBC_STDBOOL_H_
#ifndef __cplusplus
#if __STDC_VERSION__ + 0 >= 201112
#define bool _Bool
#else
#define bool unsigned char
#endif
#define true 1
#define false 0
#endif /* __cplusplus */
#define __bool_true_false_are_defined
#endif /* COSMOPOLITAN_LIBC_STDBOOL_H_ */

View file

@ -15,7 +15,7 @@ COSMOPOLITAN_C_START_
typedef struct FILE {
uint8_t bufmode; /* 0x00 _IOFBF, etc. (ignored if fd=-1) */
bool noclose; /* 0x01 for fake dup() todo delete! */
char noclose; /* 0x01 for fake dup() todo delete! */
uint32_t iomode; /* 0x04 O_RDONLY, etc. (ignored if fd=-1) */
int32_t state; /* 0x08 0=OK, -1=EOF, >0=errno */
int fd; /* 0x0c ≥0=fd, -1=closed|buffer */

View file

@ -137,14 +137,6 @@ char *strtok_r(char *, const char *, char **) paramsnonnull((2, 3));
wchar_t *wcstok(wchar_t *, const wchar_t *, wchar_t **) paramsnonnull((2, 3));
char *wstrtrunc(uint16_t *) memcpyesque;
char *wstrntrunc(uint16_t *, size_t) memcpyesque;
bool _startswith(const char *, const char *) strlenesque;
bool _startswithi(const char *, const char *) strlenesque;
bool _startswith16(const char16_t *, const char16_t *) strlenesque;
bool _wcsstartswith(const wchar_t *, const wchar_t *) strlenesque;
bool _endswith(const char *, const char *) strlenesque;
bool _endswith16(const char16_t *, const char16_t *) strlenesque;
bool _wcsendswith(const wchar_t *, const wchar_t *) strlenesque;
const char *IndexDoubleNulString(const char *, unsigned) strlenesque;
int strverscmp(const char *, const char *);
wchar_t *wmemset(wchar_t *, wchar_t, size_t) memcpyesque;
char16_t *memset16(char16_t *, char16_t, size_t) memcpyesque;
@ -165,9 +157,6 @@ char *strtoupper(char *) libcesque paramsnonnull();
char *_chomp(char *) libcesque;
char16_t *_chomp16(char16_t *) libcesque;
wchar_t *_wchomp(wchar_t *) libcesque;
bool _istext(const void *, size_t) libcesque;
bool _isutf8(const void *, size_t) libcesque;
bool _escapedos(char16_t *, unsigned, const char16_t *, unsigned) libcesque;
typedef unsigned mbstate_t;
@ -214,6 +203,20 @@ dontthrow nocallback;
int __xpg_strerror_r(int, char *, size_t)
dontthrow nocallback;
#ifdef COSMO
bool _startswith(const char *, const char *) strlenesque;
bool _startswithi(const char *, const char *) strlenesque;
bool _startswith16(const char16_t *, const char16_t *) strlenesque;
bool _wcsstartswith(const wchar_t *, const wchar_t *) strlenesque;
bool _endswith(const char *, const char *) strlenesque;
bool _endswith16(const char16_t *, const char16_t *) strlenesque;
bool _wcsendswith(const wchar_t *, const wchar_t *) strlenesque;
const char *IndexDoubleNulString(const char *, unsigned) strlenesque;
bool _istext(const void *, size_t) libcesque;
bool _isutf8(const void *, size_t) libcesque;
bool _escapedos(char16_t *, unsigned, const char16_t *, unsigned) libcesque;
#endif
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_STR_STR_H_ */