/simpletypesystem/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/simpletypesystem/trunk
130.1.4 by Gustav Hartvigsson
* Inpremented the manual mark and sweep thingys.
1
/*
2
Copyright (c) 2013-2016 Gustav Hartvigsson
3
4
Permission is hereby granted, free of charge, to any person obtaining a copy
5
of this software and associated documentation files (the "Software"), to deal
6
in the Software without restriction, including without limitation the rights
7
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
copies of the Software, and to permit persons to whom the Software is
9
furnished to do so, subject to the following conditions:
10
11
The above copyright notice and this permission notice shall be included in
12
all copies or substantial portions of the Software.
13
14
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
THE SOFTWARE.
21
 */
22
146 by Gustav Hartvigsson
* Reorderd includes in SimpleTypeSystem.h
23
#pragma once
24
121.1.1 by Gustav Hartvigsson
* added CMake rules for libgc in CMakeLists.txt and a findGC file.
25
#include <stdio.h>
26
#include <stdlib.h>
23 by Gustav Hartvigsson
* Fixed some of the build warnings.
27
#include <limits.h>
48 by Gustav Hartvigsson
* Finnished SLinkedList.
28
#include <stddef.h>
67 by Gustav Hartvigsson
* Readded s_wstring_to_string function*
29
#include <uchar.h>
72 by Gustav Hartvigsson
* Added our own types for stability and shit and giggles.
30
#include <stdint.h>
31
#include <inttypes.h>
32
#include <assert.h>
150 by Gustav Hartvigsson
* Fixed the tests in the CMake file
33
#include <math.h>
23 by Gustav Hartvigsson
* Fixed some of the build warnings.
34
121.1.1 by Gustav Hartvigsson
* added CMake rules for libgc in CMakeLists.txt and a findGC file.
35
#include "config.h"
36
5.2.7 by Gustav Hartvigsson
* Switched licence to a more permisive one.
37
/** @file
72 by Gustav Hartvigsson
* Added our own types for stability and shit and giggles.
38
 * @defgroup Definitions Definitions
39
 * @addtogroup Definitions
40
 * @{
121.1.1 by Gustav Hartvigsson
* added CMake rules for libgc in CMakeLists.txt and a findGC file.
41
 * @brief Declarations of the types and macros that are used extensively
42
 * throughout libssts.
43
 */
44
45
/**
46
 * @def S_BEGIN_DECLS
47
 * For interoperability with C++ we have to have this.
48
 *
49
 * Put at the beginning of header files.
50
 * @see S_END_DECLS
51
 */
52
53
/**
54
 * @def S_END_DECLS
55
 *
56
 * Put at end of header files.
57
 * @see S_BEGIN_DECLS
58
 */
59
5.2.7 by Gustav Hartvigsson
* Switched licence to a more permisive one.
60
#ifdef __cplusplus
163 by Gustav Hartvigsson
Small cleanup and use _Bool
61
  #define S_BEGIN_DECLS extern "C" {
62
  #define S_END_DECLS }
5.2.7 by Gustav Hartvigsson
* Switched licence to a more permisive one.
63
#else
163 by Gustav Hartvigsson
Small cleanup and use _Bool
64
  #define S_BEGIN_DECLS
65
  #define S_END_DECLS
5.2.7 by Gustav Hartvigsson
* Switched licence to a more permisive one.
66
#endif /*__cplusplus*/
67
121.1.1 by Gustav Hartvigsson
* added CMake rules for libgc in CMakeLists.txt and a findGC file.
68
S_BEGIN_DECLS
69
138 by Gustav Hartvigsson
* Fixed s_base_16_enc
70
/* Make sure that we use utf-32 with the suchar string. */
71
#define STDC_UTF_32 1
72
121.1.1 by Gustav Hartvigsson
* added CMake rules for libgc in CMakeLists.txt and a findGC file.
73
/* ***************************** GENERIC MACROS ***************************** */
74
121.1.2 by Gustav Hartvigsson
* Documented the SType enum.
75
/** @def
76
 */
77
121.1.1 by Gustav Hartvigsson
* added CMake rules for libgc in CMakeLists.txt and a findGC file.
78
/**
79
 * @def S_DEPRECATED
80
 * Mark function as deprecated.
81
 */
82
/**
83
 * @def S_UNUSED
84
 * Supress compiler warning that variable is unused.
85
 */
86
/**
87
 * @def S_ALIGNED_8
88
 * Macro to align memory to 8 bit.
89
 */
90
/**
91
 * @def S_ALIGNED_16
92
 * Macro to align memory to 16 bit.
93
 */
72 by Gustav Hartvigsson
* Added our own types for stability and shit and giggles.
94
#if defined(__GNUC__)
163 by Gustav Hartvigsson
Small cleanup and use _Bool
95
  #define S_DEPRECATED __attribute__((deprecated))
96
  #define S_UNUSED __attribute__((unused))
97
  #define S_ALIGNED_8 __attribute__((aligned (8)))
98
  #define S_ALIGNED_16 __attribute__((aligned (16)))
110 by Gustav Hartvigsson
* added S_ prifix to my macros. I should not be a scrub.
99
#elif defined(__MSC_VER)
163 by Gustav Hartvigsson
Small cleanup and use _Bool
100
  #define S_DEPRECATED __declspec(deprecated)
101
  // TODO, check if this rely works in MSVC.
102
  #define S_UNUSED __pragma(warning(suppress:4100))
103
  #define S_ALIGNED_8 __declspec(align(8))
104
  #define S_ALIGNED_16 __declspec(align(16))
5.2.7 by Gustav Hartvigsson
* Switched licence to a more permisive one.
105
#else
163 by Gustav Hartvigsson
Small cleanup and use _Bool
106
  #define S_DEPRECATED
107
  #define S_UNUSED
108
  #define S_ALIGNED_8
109
  #define S_ALIGNED_16
72 by Gustav Hartvigsson
* Added our own types for stability and shit and giggles.
110
#endif
5.2.7 by Gustav Hartvigsson
* Switched licence to a more permisive one.
111
121.1.1 by Gustav Hartvigsson
* added CMake rules for libgc in CMakeLists.txt and a findGC file.
112
/**
113
 * @def __S_ATOMIC__
114
 * The stupid atomic value.
115
 */
110 by Gustav Hartvigsson
* added S_ prifix to my macros. I should not be a scrub.
116
#if __STDC_NO_ATOMICS__
163 by Gustav Hartvigsson
Small cleanup and use _Bool
117
  #define __S_ATOMIC__ volatile
110 by Gustav Hartvigsson
* added S_ prifix to my macros. I should not be a scrub.
118
#else
163 by Gustav Hartvigsson
Small cleanup and use _Bool
119
  #define __S_ATOMIC__ __Atomic
110 by Gustav Hartvigsson
* added S_ prifix to my macros. I should not be a scrub.
120
#endif
121
121.1.1 by Gustav Hartvigsson
* added CMake rules for libgc in CMakeLists.txt and a findGC file.
122
/**
123
 * @def S_EXPORTED
124
 * Mark function as exported. This makes the function available from outside a
125
 * library on some platforms.
126
 *
127
 * @see S_HIDDEN
128
 */
129
/**
130
 * @def S_HIDDEN
131
 * Mark function as hidden. This hides a function so it is not exposed to the
132
 * outside of the library.
133
 *
134
 * @see S_EXPORTED
135
 */
136
120 by Gustav Hartvigsson
* Replaced how the macros are defined with the way that is described on the GCC wiki.
137
/*
138
 * Copied from: https://gcc.gnu.org/wiki/Visibility .. with modifications.
139
 */
140
#if defined _WIN32 || defined __CYGWIN__
141
  #ifdef BUILDING_DLL
142
    #ifdef __GNUC__
143
      #define S_EXPORTED __attribute__ ((dllexport))
144
    #else
145
      #define S_EXPORTED __declspec(dllexport) // Note: actually gcc seems to also supports this syntax.
146
    #endif
147
  #else
148
    #ifdef __GNUC__
149
      #define S_EXPORTED __attribute__ ((dllimport))
150
    #else
151
      #define S_EXPORTED __declspec(dllimport) // Note: actually gcc seems to also supports this syntax.
152
    #endif
153
  #endif
119 by Gustav Hartvigsson
* added S_EXPERTED to public functions.
154
  #define S_HIDDEN
86 by Gustav Hartvigsson
* added external .h files for dealing with stuff that may or may not be avalible on scertain platforms.
155
#else
120 by Gustav Hartvigsson
* Replaced how the macros are defined with the way that is described on the GCC wiki.
156
  #if __GNUC__ >= 4
157
    #define S_EXPORTED __attribute__ ((visibility ("default")))
158
    #define S_HIDDEN  __attribute__ ((visibility ("hidden")))
159
  #else
160
    #define S_EXPORTED
161
    #define S_HIDDEN
162
  #endif
86 by Gustav Hartvigsson
* added external .h files for dealing with stuff that may or may not be avalible on scertain platforms.
163
#endif
164
46 by Gustav Hartvigsson
* Renamed DynamicArray to SDynamicArray.
165
/**
121.1.1 by Gustav Hartvigsson
* added CMake rules for libgc in CMakeLists.txt and a findGC file.
166
 * FALSE has the absolute value of 0, it is used in as a way to represent a
167
 * false value. A "not" value.
168
 *
169
 * @see sboolean
46 by Gustav Hartvigsson
* Renamed DynamicArray to SDynamicArray.
170
 */
23 by Gustav Hartvigsson
* Fixed some of the build warnings.
171
#define FALSE 0
172
46 by Gustav Hartvigsson
* Renamed DynamicArray to SDynamicArray.
173
 /**
121.1.1 by Gustav Hartvigsson
* added CMake rules for libgc in CMakeLists.txt and a findGC file.
174
  * TRUE represents a value that is true. A value that is "not false".
175
  *
176
  * @see sboolean
46 by Gustav Hartvigsson
* Renamed DynamicArray to SDynamicArray.
177
  */
85 by Gustav Hartvigsson
* Better? Worse? Who knows?
178
#define TRUE !FALSE
23 by Gustav Hartvigsson
* Fixed some of the build warnings.
179
121.1.1 by Gustav Hartvigsson
* added CMake rules for libgc in CMakeLists.txt and a findGC file.
180
/**
181
 * Stupid macro to create a hash of a pointer.
182
 */
53 by Gustav Hartvigsson
* Finnished up s_map_add () ???
183
#define S_POINTER_TO_HASH_T(p) ((hash_t)(unsigned long) p)
184
150 by Gustav Hartvigsson
* Fixed the tests in the CMake file
185
186
/* ************************************************************************** *
187
 * Colours
188
 * ************************************************************************** */
46 by Gustav Hartvigsson
* Renamed DynamicArray to SDynamicArray.
189
121.1.1 by Gustav Hartvigsson
* added CMake rules for libgc in CMakeLists.txt and a findGC file.
190
/**
191
 * @defgroup Colours Colours
192
 * @addtogroup Colours
150 by Gustav Hartvigsson
* Fixed the tests in the CMake file
193
 *   @{
121.1.1 by Gustav Hartvigsson
* added CMake rules for libgc in CMakeLists.txt and a findGC file.
194
 * @brief Printing colours for terminal/console printing.
150 by Gustav Hartvigsson
* Fixed the tests in the CMake file
195
 *
121.1.1 by Gustav Hartvigsson
* added CMake rules for libgc in CMakeLists.txt and a findGC file.
196
 * Here is a list of macros for use when printing to the console.
197
 * @ref S_COLOR_RESET is used to reset the colours back to their original
198
 *      colour.
150 by Gustav Hartvigsson
* Fixed the tests in the CMake file
199
 *
121.1.1 by Gustav Hartvigsson
* added CMake rules for libgc in CMakeLists.txt and a findGC file.
200
 * An example on how to use them can be found in utils.h:
201
 * @code{.c}
202
#define s_err_print(p, ...)\
203
  fprintf (stderr, S_COLOR_RED "[ERR] " p S_COLOR_RESET "\n", ##__VA_ARGS__)
204
 * @endcode
205
 */
150 by Gustav Hartvigsson
* Fixed the tests in the CMake file
206
121.1.1 by Gustav Hartvigsson
* added CMake rules for libgc in CMakeLists.txt and a findGC file.
207
#define S_COLOR_RESET   "\033[0m"       /**< Reset */
208
#define S_COLOR_BLACK   "\033[30m"      /**< Black */
209
#define S_COLOR_RED     "\033[31m"      /**< Red */
210
#define S_COLOR_GREEN   "\033[32m"      /**< Green */
211
#define S_COLOR_YELLOW  "\033[33m"      /**< Yellow */
212
#define S_COLOR_BLUE    "\033[34m"      /**< Blue */
213
#define S_COLOR_MAGENTA "\033[35m"      /**< Magenta */
214
#define S_COLOR_CYAN    "\033[36m"      /**< Cyan */
215
#define S_COLOR_WHITE   "\033[37m"      /**< White */
216
#define S_COLOR_BOLDBLACK   "\033[1m\033[30m"      /**< Bold Black */
217
#define S_COLOR_BOLDRED     "\033[1m\033[31m"      /**< Bold Red */
218
#define S_COLOR_BOLDGREEN   "\033[1m\033[32m"      /**< Bold Green */
219
#define S_COLOR_BOLDYELLOW  "\033[1m\033[33m"      /**< Bold Yellow */
220
#define S_COLOR_BOLDBLUE    "\033[1m\033[34m"      /**< Bold Blue */
221
#define S_COLOR_BOLDMAGENTA "\033[1m\033[35m"      /**< Bold Magenta */
222
#define S_COLOR_BOLDCYAN    "\033[1m\033[36m"      /**< Bold Cyan */
223
#define S_COLOR_BOLDWHITE   "\033[1m\033[37m"      /**< Bold White */
224
150 by Gustav Hartvigsson
* Fixed the tests in the CMake file
225
/**   @} */
226
121.1.1 by Gustav Hartvigsson
* added CMake rules for libgc in CMakeLists.txt and a findGC file.
227
/** @} */
228
150 by Gustav Hartvigsson
* Fixed the tests in the CMake file
229
/* We include these last so it does not create any problems.
230
 * We want people only to have to include defs.h and not mm.h and types.h
231
 * anyway.
121.1.3 by Gustav Hartvigsson
* Made the GC switchable at rutime (once) when compiled with S_USE_GC set.
232
 *
233
 * It should be considered a continuation of defs.h.
234
 */
150 by Gustav Hartvigsson
* Fixed the tests in the CMake file
235
236
#include "types.h"
237
238
#include "primes.h" /* This is already included in types.h... */
239
121.1.3 by Gustav Hartvigsson
* Made the GC switchable at rutime (once) when compiled with S_USE_GC set.
240
#include "mm.h"
241
150 by Gustav Hartvigsson
* Fixed the tests in the CMake file
242
110 by Gustav Hartvigsson
* added S_ prifix to my macros. I should not be a scrub.
243
S_END_DECLS