Add features.h for feature test macros.

Because we use an amalgated build, feature
test macros should be set in a single file that
is included before any other headers, and is placed
at the top of the amalgamated build.
This commit is contained in:
Calvin Rose 2019-12-30 19:06:15 -05:00
parent 2ba4337e6f
commit 9dd152dc28
46 changed files with 99 additions and 28 deletions

View File

@ -67,7 +67,8 @@ all: $(JANET_TARGET) $(JANET_LIBRARY) $(JANET_STATIC_LIBRARY)
JANET_HEADERS=src/include/janet.h src/conf/janetconf.h
JANET_LOCAL_HEADERS=src/core/util.h \
JANET_LOCAL_HEADERS=src/core/features.h \
src/core/util.h \
src/core/state.h \
src/core/gc.h \
src/core/vector.h \

View File

@ -93,7 +93,7 @@ set "amalg_files="
for %%f in (src\core\*.c) do (
set "amalg_files=!amalg_files! %%f"
)
janet.exe tools\amalg.janet src\core\util.h src\core\state.h src\core\gc.h src\core\vector.h src\core\fiber.h src\core\regalloc.h src\core\compile.h src\core\emit.h src\core\symcache.h %amalg_files% build\core_image.c > build\janet.c
janet.exe tools\amalg.janet src\core\features.h src\core\util.h src\core\state.h src\core\gc.h src\core\vector.h src\core\fiber.h src\core\regalloc.h src\core\compile.h src\core\emit.h src\core\symcache.h %amalg_files% build\core_image.c > build\janet.c
janet.exe tools\removecr.janet build\janet.c
@rem Gen shell.c

View File

@ -88,6 +88,7 @@ boot_gen = gen.process('src/boot/boot.janet', extra_args: 'janet_gen_boot')
# Order is important here, as some headers
# depend on other headers for the amalg target
core_headers = [
'src/core/features.h',
'src/core/util.h',
'src/core/state.h',
'src/core/gc.h',

View File

@ -21,6 +21,7 @@
*/
#ifndef JANET_AMALG
#include "features.h"
#include <janet.h>
#include "gc.h"
#endif

View File

@ -21,6 +21,7 @@
*/
#ifndef JANET_AMALG
#include "features.h"
#include <janet.h>
#include "gc.h"
#include "util.h"

View File

@ -21,6 +21,7 @@
*/
#ifndef JANET_AMALG
#include "features.h"
#include <janet.h>
#include "util.h"
#endif

View File

@ -21,6 +21,7 @@
*/
#ifndef JANET_AMALG
#include "features.h"
#include <janet.h>
#include "gc.h"
#include "util.h"

View File

@ -21,6 +21,7 @@
*/
#ifndef JANET_AMALG
#include "features.h"
#include <janet.h>
#include "gc.h"
#include "util.h"

View File

@ -21,6 +21,7 @@
*/
#ifndef JANET_AMALG
#include "features.h"
#include <janet.h>
#include "state.h"
#include "fiber.h"

View File

@ -21,6 +21,7 @@
*/
#ifndef JANET_AMALG
#include "features.h"
#include <janet.h>
#include "compile.h"
#include "emit.h"

View File

@ -21,6 +21,7 @@
*/
#ifndef JANET_AMALG
#include "features.h"
#include <janet.h>
#include "compile.h"
#include "emit.h"

View File

@ -24,6 +24,7 @@
#define JANET_COMPILE_H
#ifndef JANET_AMALG
#include "features.h"
#include <janet.h>
#include "regalloc.h"
#endif

View File

@ -21,6 +21,7 @@
*/
#ifndef JANET_AMALG
#include "features.h"
#include <janet.h>
#include <math.h>
#include "compile.h"

View File

@ -21,6 +21,7 @@
*/
#ifndef JANET_AMALG
#include "features.h"
#include <janet.h>
#include "gc.h"
#include "state.h"

View File

@ -21,6 +21,7 @@
*/
#ifndef JANET_AMALG
#include "features.h"
#include <janet.h>
#include "emit.h"
#include "vector.h"

36
src/core/features.h Normal file
View File

@ -0,0 +1,36 @@
/*
* Copyright (c) 2019 Calvin Rose
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
/* Feature test macros */
#ifndef JANET_FEATURES_H_defined
#define JANET_FEATURES_H_defined
#if !defined(_POSIX_C_SOURCE)
#define _POSIX_C_SOURCE 200112L
#endif
#if !defined(_BSD_SOURCE) && defined(JANET_BSD)
#define _BSD_SOURCE 1
#endif
#endif

View File

@ -21,6 +21,7 @@
*/
#ifndef JANET_AMALG
#include "features.h"
#include <janet.h>
#include "fiber.h"
#include "state.h"

View File

@ -21,6 +21,7 @@
*/
#ifndef JANET_AMALG
#include "features.h"
#include <janet.h>
#include "state.h"
#include "symcache.h"

View File

@ -24,6 +24,7 @@
#define JANET_GC_H
#ifndef JANET_AMALG
#include "features.h"
#include <janet.h>
#endif

View File

@ -27,6 +27,7 @@
#include <math.h>
#ifndef JANET_AMALG
#include "features.h"
#include <janet.h>
#include "util.h"
#endif

View File

@ -21,6 +21,7 @@
*/
#ifndef JANET_AMALG
#include "features.h"
#include <janet.h>
#include "util.h"
#endif

View File

@ -21,6 +21,7 @@
*/
#ifndef JANET_AMALG
#include "features.h"
#include <janet.h>
#include "state.h"
#include "vector.h"

View File

@ -20,13 +20,14 @@
* IN THE SOFTWARE.
*/
#include <math.h>
#ifndef JANET_AMALG
#include "features.h"
#include <janet.h>
#include "util.h"
#endif
#include <math.h>
static JANET_THREAD_LOCAL JanetRNG janet_vm_rng = {0, 0, 0, 0, 0};
static int janet_rng_get(void *p, Janet key, Janet *out);

View File

@ -21,6 +21,7 @@
*/
#ifndef JANET_AMALG
#include "features.h"
#include <janet.h>
#include "util.h"
#endif

View File

@ -21,6 +21,7 @@
*/
#ifndef JANET_AMALG
#include "features.h"
#include <janet.h>
#include "util.h"
#endif

View File

@ -21,6 +21,7 @@
*/
#ifndef JANET_AMALG
#include "features.h"
#include <janet.h>
#include <string.h>
#include "util.h"

View File

@ -20,16 +20,17 @@
* IN THE SOFTWARE.
*/
#include <string.h>
#include <ctype.h>
#ifndef JANET_AMALG
#include "features.h"
#include <janet.h>
#include "util.h"
#include "state.h"
#include <math.h>
#endif
#include <string.h>
#include <ctype.h>
/* Implements a pretty printer for Janet. The pretty printer
* is simple and not that flexible, but fast. */

View File

@ -21,6 +21,7 @@
*/
#ifndef JANET_AMALG
#include "features.h"
#include <janet.h>
#include "regalloc.h"
#include "util.h"

View File

@ -21,6 +21,7 @@
*/
#ifndef JANET_AMALG
#include "features.h"
#include <janet.h>
#include "state.h"
#endif

View File

@ -21,6 +21,7 @@
*/
#ifndef JANET_AMALG
#include "features.h"
#include <janet.h>
#include "compile.h"
#include "util.h"

View File

@ -20,15 +20,16 @@
* IN THE SOFTWARE.
*/
#include <string.h>
#ifndef JANET_AMALG
#include "features.h"
#include <janet.h>
#include "gc.h"
#include "util.h"
#include "state.h"
#endif
#include <string.h>
/* Begin building a string */
uint8_t *janet_string_begin(int32_t length) {
JanetStringHead *head = janet_gcalloc(JANET_MEMORY_STRING, sizeof(JanetStringHead) + length + 1);

View File

@ -40,14 +40,15 @@
* '0xdeadbeef'.
*/
#include <math.h>
#include <string.h>
#ifndef JANET_AMALG
#include "features.h"
#include <janet.h>
#include "util.h"
#endif
#include <math.h>
#include <string.h>
/* Lookup table for getting values of characters when parsing numbers. Handles
* digits 0-9 and a-z (and A-Z). A-Z have values of 10 to 35. */
static uint8_t digit_lookup[128] = {

View File

@ -21,6 +21,7 @@
*/
#ifndef JANET_AMALG
#include "features.h"
#include <janet.h>
#include "gc.h"
#include "util.h"

View File

@ -25,9 +25,8 @@
* checks, all symbols are interned so that there is a single copy of it in the
* whole program. Equality is then just a pointer check. */
#include <string.h>
#ifndef JANET_AMALG
#include "features.h"
#include <janet.h>
#include "state.h"
#include "gc.h"
@ -35,6 +34,8 @@
#include "symcache.h"
#endif
#include <string.h>
/* Cache state */
JANET_THREAD_LOCAL const uint8_t **janet_vm_cache = NULL;
JANET_THREAD_LOCAL uint32_t janet_vm_cache_capacity = 0;

View File

@ -24,6 +24,7 @@
#define JANET_SYMCACHE_H_defined
#ifndef JANET_AMALG
#include "features.h"
#include <janet.h>
#endif

View File

@ -21,6 +21,7 @@
*/
#ifndef JANET_AMALG
#include "features.h"
#include <janet.h>
#include "gc.h"
#include "util.h"

View File

@ -21,6 +21,7 @@
*/
#ifndef JANET_AMALG
#include "features.h"
#include <janet.h>
#include "gc.h"
#include "util.h"

View File

@ -21,6 +21,7 @@
*/
#ifndef JANET_AMALG
#include "features.h"
#include <janet.h>
#include "symcache.h"
#include "gc.h"

View File

@ -21,6 +21,7 @@
*/
#ifndef JANET_AMALG
#include "features.h"
#include <janet.h>
#include "util.h"
#endif

View File

@ -20,15 +20,16 @@
* IN THE SOFTWARE.
*/
#include <inttypes.h>
#ifndef JANET_AMALG
#include "features.h"
#include <janet.h>
#include "util.h"
#include "state.h"
#include "gc.h"
#endif
#include <inttypes.h>
/* Base 64 lookup table for digits */
const char janet_base64[65] =
"0123456789"

View File

@ -23,21 +23,13 @@
#ifndef JANET_UTIL_H_defined
#define JANET_UTIL_H_defined
#include <stdio.h>
#include <errno.h>
#ifndef JANET_AMALG
#include "features.h"
#include <janet.h>
#endif
/* For internal usage */
#if !defined(_POSIX_C_SOURCE)
#define _POSIX_C_SOURCE 200112L
#endif
#if !defined(_BSD_SOURCE) && defined(JANET_BSD)
#define _BSD_SOURCE 1
#endif
#include <stdio.h>
#include <errno.h>
/* Handle runtime errors */
#ifndef janet_exit

View File

@ -21,6 +21,7 @@
*/
#ifndef JANET_AMALG
#include "features.h"
#include <janet.h>
#endif

View File

@ -21,6 +21,7 @@
*/
#ifndef JANET_AMALG
#include "features.h"
#include "vector.h"
#include "util.h"
#endif

View File

@ -24,6 +24,7 @@
#define JANET_VECTOR_H_defined
#ifndef JANET_AMALG
#include "features.h"
#include <janet.h>
#endif

View File

@ -21,6 +21,7 @@
*/
#ifndef JANET_AMALG
#include "features.h"
#include <janet.h>
#include "state.h"
#include "fiber.h"

View File

@ -21,8 +21,9 @@
*/
#ifndef JANET_AMALG
#include <math.h>
#include "features.h"
#include <janet.h>
#include <math.h>
#include "util.h"
#include "state.h"
#endif