wip on intellisense (again)

This commit is contained in:
Alexander Nicholi 2021-02-02 11:14:45 -05:00
parent 9841e2186a
commit 7642710155
No known key found for this signature in database
GPG key ID: B75B2EB05540F74C
18 changed files with 242 additions and 52 deletions

View file

@ -28,6 +28,7 @@
#define append(ARRAYLIST, ITEM) concat((ARRAYLIST), (ITEM), 1)
#ifndef concat
#define concat(ARRAYLIST, ITEM, COUNT) \
({ \
autotype(ARRAYLIST) List = (ARRAYLIST); \
@ -43,6 +44,7 @@
} \
(ssize_t)(Idx); \
})
#endif /* concat */
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_ALG_ARRAYLIST_H_ */

View file

@ -10,6 +10,7 @@ COSMOPOLITAN_C_START_
#define APPEND(LIST_P, LIST_I, LIST_N, ITEM) \
CONCAT(LIST_P, LIST_I, LIST_N, ITEM, 1)
#ifndef CONCAT
#define CONCAT(LIST_P, LIST_I, LIST_N, ITEM, COUNT) \
({ \
autotype(LIST_P) ListP = (LIST_P); \
@ -31,6 +32,7 @@ COSMOPOLITAN_C_START_
} \
Entry; \
})
#endif /* CONCAT */
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */

View file

@ -11,6 +11,7 @@
* @return pointer to start of array
* @see ARRAYLEN()
*/
#ifndef reverse
#define reverse(ARRAY, COUNT) \
({ \
autotype(&(ARRAY)[0]) Array = (ARRAY); \
@ -26,6 +27,7 @@
} \
Array; \
})
#endif /* reverse */
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_ALG_REVERSE_H_ */

View file

@ -11,6 +11,7 @@
* @param n is the number of items in A
* @see ARRAYLEN()
*/
#ifndef shuffle
#define shuffle(R, A, n) \
do { \
autotype(A) Array = (A); \
@ -18,6 +19,7 @@
xchg(&Array[i], &Array[R() % (i + 1)]); \
} \
} while (0)
#endif /* shuffle */
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_RAND_SHUFFLE_H_ */

View file

@ -205,6 +205,7 @@ unsigned long hamming(unsigned long, unsigned long) pureconst;
* @see Intel's Six-Thousand Page Manual V.3A §8.2.3.1
* @see atomic_store()
*/
#ifndef atomic_load
#define atomic_load(MEM) \
({ \
autotype(MEM) Mem = (MEM); \
@ -212,6 +213,7 @@ unsigned long hamming(unsigned long, unsigned long) pureconst;
asm("mov\t%1,%0" : "=r"(Reg) : "m"(*Mem)); \
Reg; \
})
#endif /* atomic_load */
/**
* Saves scalar to memory w/ one operation.
@ -229,6 +231,7 @@ unsigned long hamming(unsigned long, unsigned long) pureconst;
* @see Intel Six-Thousand Page Manual Manual V.3A §8.2.3.1
* @see atomic_load()
*/
#ifndef atomic_store
#define atomic_store(MEM, VAL) \
({ \
autotype(VAL) Val = (VAL); \
@ -236,6 +239,7 @@ unsigned long hamming(unsigned long, unsigned long) pureconst;
asm("mov%z1\t%1,%0" : "=m"(*Mem) : "r"(Val)); \
Val; \
})
#endif /* atomic_store */
#define bts(MEM, BIT) __BitOp("bts", BIT, MEM) /** bit test and set */
#define btr(MEM, BIT) __BitOp("btr", BIT, MEM) /** bit test and reset */
@ -263,6 +267,7 @@ unsigned long hamming(unsigned long, unsigned long) pureconst;
* @return LOCALVAR[0]
* @see xchg()
*/
#ifndef lockxchg
#define lockxchg(MEMORY, LOCALVAR) \
({ \
_Static_assert( \
@ -270,6 +275,7 @@ unsigned long hamming(unsigned long, unsigned long) pureconst;
asm("xchg\t%0,%1" : "+%m"(*(MEMORY)), "+r"(*(LOCALVAR))); \
*(LOCALVAR); \
})
#endif /* lockxchg */
/**
* Compares and exchanges.
@ -278,6 +284,7 @@ unsigned long hamming(unsigned long, unsigned long) pureconst;
* @return true if value was exchanged, otherwise false
* @see lockcmpxchg()
*/
#ifndef cmpxchg
#define cmpxchg(IFTHING, ISEQUALTOME, REPLACEITWITHME) \
({ \
bool DidIt; \
@ -290,6 +297,7 @@ unsigned long hamming(unsigned long, unsigned long) pureconst;
: "cc"); \
DidIt; \
})
#endif /* cmpxchg */
/**
* Compares and exchanges w/ one operation.
@ -298,6 +306,7 @@ unsigned long hamming(unsigned long, unsigned long) pureconst;
* @return true if value was exchanged, otherwise false
* @see lockcmpxchg()
*/
#ifndef lockcmpxchg
#define lockcmpxchg(IFTHING, ISEQUALTOME, REPLACEITWITHME) \
({ \
bool DidIt; \
@ -310,27 +319,32 @@ unsigned long hamming(unsigned long, unsigned long) pureconst;
: "cc"); \
DidIt; \
})
#endif /* lockcmpxchg */
/**
* Gets value of extended control register.
*/
#ifndef xgetbv
#define xgetbv(xcr_register_num) \
({ \
unsigned hi, lo; \
asm("xgetbv" : "=d"(hi), "=a"(lo) : "c"(cr_register_num)); \
(uint64_t) hi << 32 | lo; \
})
#endif /* xgetbv */
/**
* Reads model-specific register.
* @note programs running as guests won't have authorization
*/
#ifndef rdmsr
#define rdmsr(msr) \
({ \
uint32_t lo, hi; \
asm volatile("rdmsr" : "=a"(lo), "=d"(hi) : "c"(msr)); \
(uint64_t) hi << 32 | lo; \
})
#endif rdmsr
/**
* Writes model-specific register.

View file

@ -7,6 +7,7 @@
/**
* Teleports code fragment inside _init().
*/
#ifndef INITIALIZER
#define INITIALIZER(PRI, NAME, CODE) \
asm(".section .init." #PRI "." #NAME ",\"ax\",@progbits\n\t" \
"call\t" #NAME "\n\t" \
@ -15,6 +16,7 @@
CODE; \
asm volatile("" : /* no outputs */ : "D"(rdi), "S"(rsi)); \
}
#endif /* INITIALIZER */
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_BITS_INITIALIZER_H_ */

View file

@ -251,6 +251,7 @@ int vdprintf(int, const char *, va_list) paramsnonnull();
void _init_onntconsoleevent(void);
void _init_wincrash(void);
#ifndef __SIGACTION
#define __SIGACTION(FN, SIG, ...) \
({ \
if (SupportsWindows()) { \
@ -279,6 +280,7 @@ void _init_wincrash(void);
} \
(FN)(SIG, __VA_ARGS__); \
})
#endif
#define dprintf(FD, FMT, ...) (dprintf)(FD, PFLINK(FMT), ##__VA_ARGS__)
#define sigaction(SIG, ACT, OLD) __SIGACTION(sigaction, SIG, ACT, OLD)

View file

@ -36,25 +36,28 @@ struct IoctlPtmGet {
char theduxname[16];
char workername[16];
};
enum FdKind {
kFdEmpty,
kFdFile,
kFdSocket,
kFdProcess,
kFdConsole,
kFdSerial,
kFdZip,
kFdEpoll,
};
struct Fd {
int64_t handle;
int64_t extra;
int kind;
unsigned flags;
};
struct Fds {
size_t f; // lowest free slot
size_t n; // monotonic capacity
struct Fd {
int64_t handle;
int64_t extra;
enum FdKind {
kFdEmpty,
kFdFile,
kFdSocket,
kFdProcess,
kFdConsole,
kFdSerial,
kFdZip,
kFdEpoll,
} kind;
unsigned flags;
} * p;
struct Fd * p;
struct Fd __init_p[OPEN_MAX];
};
@ -76,7 +79,7 @@ forceinline bool __isfdopen(int fd) {
return 0 <= fd && fd < g_fds.n && g_fds.p[fd].kind != kFdEmpty;
}
forceinline bool __isfdkind(int fd, enum FdKind kind) {
forceinline bool __isfdkind(int fd, int kind) {
return 0 <= fd && fd < g_fds.n && g_fds.p[fd].kind == kind;
}

View file

@ -45,6 +45,7 @@ union metasigaction {
struct sigaction$xnu_out xnu_out;
};
#ifndef SWITCHEROO
#define SWITCHEROO(S1, S2, A, B, C, D) \
do { \
autotype((S2).A) a = (typeof((S2).A))(S1).A; \
@ -59,6 +60,7 @@ union metasigaction {
memset(&((S2).D), 0, sizeof((S2).D)); \
memcpy(&((S2).D), &d, MIN(sizeof(d), sizeof((S2).D))); \
} while (0);
#endif
static void sigaction$cosmo2native(union metasigaction *sa) {
if (!sa) return;

View file

@ -20,6 +20,7 @@
#include "libc/calls/struct/metastat.internal.h"
#include "libc/dce.h"
#ifndef SWITCHEROO
#define SWITCHEROO(S1, S2, A, B, C, D, E, F, G, H, I, J, K, L, M) \
do { \
autotype((S2).A) a = (typeof((S2).A))(S1).A; \
@ -49,6 +50,7 @@
(S2).L = l; \
(S2).M = m; \
} while (0);
#endif
forceinline void stat2linux_xnu(union metastat *ms) {
SWITCHEROO(ms->xnu, ms->linux, st_dev, st_ino, st_nlink, st_mode, st_uid,

View file

@ -759,12 +759,14 @@ typedef uint64_t uintmax_t;
#define DebugBreak() asm("int3")
#ifndef VEIL
#define VEIL(CONSTRAINT, EXPRESSION) \
({ \
autotype(EXPRESSION) VeiledValue = (EXPRESSION); \
asm("" : "=" CONSTRAINT ""(VeiledValue) : "0"(VeiledValue)); \
VeiledValue; \
})
#endif /* VEIL */
#define CONCEAL(CONSTRAINT, EXPRESSION) \
({ \

View file

@ -6,9 +6,6 @@
#define SYMBOLIC(NAME) NAME(%rip)
#define LITERALLY(NAME) $NAME
/* clang-format on */
#elif defined(__VSCODE_INTELLISENSE__)
#define SYMBOLIC(NAME) 1
#define LITERALLY(NAME) 1
#else
#define SYMBOLIC(NAME) NAME
#define LITERALLY(NAME) NAME

View file

@ -3,6 +3,7 @@
#include "libc/str/str.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
#ifndef tinystrstr
#define tinystrstr(HAYSTACK, NEEDLE) \
({ \
autotype(HAYSTACK) Haystack = (HAYSTACK); \
@ -21,6 +22,7 @@
Found: \
Haystack; \
})
#endif /* tinystrstr */
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_STR_TINYSTRSTR_H_ */

View file

@ -27,7 +27,7 @@ forceinline int tpdecodecb(wint_t *out, int first,
if ((cb & 0b11000000) == 0b10000000) {
wc = wc << 6 | (cb & 0b00111111);
} else {
if (out) *out = u'<EFBFBD>';
if (out) *out = u'\xFFFD';
return -1;
}
}

View file

@ -8,6 +8,7 @@ COSMOPOLITAN_C_START_
* @fileoverview Microbenchmarking tools.
*/
#ifndef BENCHLOOP
#define BENCHLOOP(START, STOP, N, INIT, EXPR) \
({ \
unsigned long Iter, Count; \
@ -22,6 +23,7 @@ COSMOPOLITAN_C_START_
} \
Average; \
})
#endif /* BENCHLOOP */
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */