summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2023-06-11 14:03:16 +0200
committerTyge Løvset <[email protected]>2023-06-11 14:59:06 +0200
commitb564ef6bdfcd2437f1b4997f42054c45ccdedbb1 (patch)
treeb6c5458b8bc47279d18408f25e79eb6118808d78
parentf3529a2600141dc7f84c734ea3bf5db8f7090e56 (diff)
downloadSTC-modified-b564ef6bdfcd2437f1b4997f42054c45ccdedbb1.tar.gz
STC-modified-b564ef6bdfcd2437f1b4997f42054c45ccdedbb1.zip
Added priv/linkage.h and renamed priv/template2.h => priv/template_undef.h.
Make all examples c++ compatible, except those using cspan.h Removed: crange_obj() Renamed: crange_make() => crange_init() Renamed: cspan_make() => cspan_init() Renamed: cstr_NULL => cstr_null Renamed: csview_NULL => csview_null
-rw-r--r--docs/carc_api.md2
-rw-r--r--docs/cbox_api.md2
-rw-r--r--docs/ccommon_api.md14
-rw-r--r--docs/cmap_api.md2
-rw-r--r--docs/cspan_api.md2
-rw-r--r--docs/cstr_api.md4
-rw-r--r--docs/csview_api.md2
-rw-r--r--include/stc/algo/coroutine.h2
-rw-r--r--include/stc/algo/crange.h18
-rw-r--r--include/stc/algo/filter.h2
-rw-r--r--include/stc/algo/sort.h1
-rw-r--r--include/stc/carc.h5
-rw-r--r--include/stc/cbox.h5
-rw-r--r--include/stc/ccommon.h51
-rw-r--r--include/stc/clist.h3
-rw-r--r--include/stc/cmap.h3
-rw-r--r--include/stc/cpque.h3
-rw-r--r--include/stc/cqueue.h3
-rw-r--r--include/stc/crand.h3
-rw-r--r--include/stc/cregex.h4
-rw-r--r--include/stc/csmap.h3
-rw-r--r--include/stc/cspan.h9
-rw-r--r--include/stc/cstack.h3
-rw-r--r--include/stc/cstr.h20
-rw-r--r--include/stc/csview.h18
-rw-r--r--include/stc/cvec.h3
-rw-r--r--include/stc/priv/linkage.h40
-rw-r--r--include/stc/utf8.h34
-rw-r--r--misc/examples/astar.c2
-rw-r--r--misc/examples/box.c2
-rw-r--r--misc/examples/box2.c6
-rw-r--r--misc/examples/csmap_find.c12
-rw-r--r--misc/examples/csmap_insert.c12
-rw-r--r--misc/examples/dining_philosophers.c5
-rw-r--r--misc/examples/forfilter.c5
-rwxr-xr-xmisc/examples/make.sh14
-rw-r--r--misc/examples/music_arc.c2
-rw-r--r--misc/examples/new_list.c2
-rw-r--r--misc/examples/new_sptr.c3
-rw-r--r--misc/examples/new_vec.c8
-rw-r--r--misc/examples/person_arc.c3
-rw-r--r--misc/examples/prime.c4
-rw-r--r--misc/examples/printspan.c8
-rw-r--r--misc/examples/read.c2
-rw-r--r--misc/examples/shape.c2
-rw-r--r--misc/examples/vikings.c10
-rw-r--r--src/cregex.c32
-rw-r--r--src/utf8code.c41
48 files changed, 254 insertions, 182 deletions
diff --git a/docs/carc_api.md b/docs/carc_api.md
index 9f3d8cb9..22e6bac2 100644
--- a/docs/carc_api.md
+++ b/docs/carc_api.md
@@ -67,7 +67,7 @@ bool carc_X_value_eq(const i_val* x, const i_val* y);
| Type name | Type definition | Used to represent... |
|:------------------|:--------------------------------------------------|:-----------------------|
-| `carc_NULL` | `{NULL, NULL}` | Init nullptr const |
+| `carc_null` | `{0}` | Init nullptr const |
| `carc_X` | `struct { carc_X_value* get; long* use_count; }` | The carc type |
| `carc_X_value` | `i_val` | The carc element type |
| `carc_X_raw` | `i_valraw` | Convertion type |
diff --git a/docs/cbox_api.md b/docs/cbox_api.md
index 5914a5ad..9151f56d 100644
--- a/docs/cbox_api.md
+++ b/docs/cbox_api.md
@@ -64,7 +64,7 @@ bool cbox_X_value_eq(const i_val* x, const i_val* y);
| Type name | Type definition | Used to represent... |
|:-------------------|:--------------------------------|:------------------------|
-| `cbox_NULL` | `{NULL}` | Init nullptr const |
+| `cbox_null` | `{0}` | Init nullptr const |
| `cbox_X` | `struct { cbox_X_value* get; }` | The cbox type |
| `cbox_X_value` | `i_val` | The cbox element type |
diff --git a/docs/ccommon_api.md b/docs/ccommon_api.md
index cd9be505..1f0847da 100644
--- a/docs/ccommon_api.md
+++ b/docs/ccommon_api.md
@@ -82,17 +82,16 @@ c_forrange (i, 30, 0, -5) printf(" %lld", i);
### crange
A number sequence generator type, similar to [boost::irange](https://www.boost.org/doc/libs/release/libs/range/doc/html/range/reference/ranges/irange.html). The **crange_value** type is `long long`. Below *start*, *stop*, and *step* are of type *crange_value*:
```c
-crange& crange_obj(...) // create a compound literal crange object
-crange crange_make(stop); // will generate 0, 1, ..., stop-1
-crange crange_make(start, stop); // will generate start, start+1, ... stop-1
-crange crange_make(start, stop, step); // will generate start, start+step, ... upto-not-including stop
+crange crange_init(stop); // will generate 0, 1, ..., stop-1
+crange crange_init(start, stop); // will generate start, start+1, ... stop-1
+crange crange_init(start, stop, step); // will generate start, start+step, ... upto-not-including stop
// note that step may be negative.
crange_iter crange_begin(crange* self);
crange_iter crange_end(crange* self);
void crange_next(crange_iter* it);
// 1. All primes less than 32:
-crange r1 = crange_make(3, 32, 2);
+crange r1 = crange_init(3, 32, 2);
printf("2"); // first prime
c_forfilter (i, crange, r1, isPrime(*i.ref))
printf(" %lld", *i.ref);
@@ -100,7 +99,8 @@ c_forfilter (i, crange, r1, isPrime(*i.ref))
// 2. The first 11 primes:
printf("2");
-c_forfilter (i, crange, crange_obj(3, INT64_MAX, 2),
+crange range = crange_init(3, INT64_MAX, 2);
+c_forfilter (i, crange, range,
isPrime(*i.ref) &&
c_flt_take(10)
){
@@ -140,7 +140,7 @@ bool isPrime(long long i) {
int main() {
// Get 10 prime numbers starting from 1000. Skip the first 15 primes,
// then select every 25th prime (including the initial).
- crange R = crange_make(1001, INT64_MAX, 2); // 1001, 1003, ...
+ crange R = crange_init(1001, INT64_MAX, 2); // 1001, 1003, ...
c_forfilter (i, crange, R,
isPrime(*i.ref) &&
diff --git a/docs/cmap_api.md b/docs/cmap_api.md
index 69e547a0..8ef322e6 100644
--- a/docs/cmap_api.md
+++ b/docs/cmap_api.md
@@ -277,7 +277,7 @@ typedef struct {
cstr country;
} Viking;
-#define Viking_init() ((Viking){cstr_NULL, cstr_NULL})
+#define Viking_init() ((Viking){cstr_null, cstr_null})
static inline int Viking_cmp(const Viking* a, const Viking* b) {
int c = cstr_cmp(&a->name, &b->name);
diff --git a/docs/cspan_api.md b/docs/cspan_api.md
index 3a811ebf..c78bb8a0 100644
--- a/docs/cspan_api.md
+++ b/docs/cspan_api.md
@@ -26,7 +26,7 @@ i.e., it may be expanded multiple times. However, all integer arguments are safe
`cspan_at(&ms3, i++, j++, k++)` is allowed. If the number of arguments does not match the span rank,
a compile error is issued. Runtime bounds checks are enabled by default (define `STC_NDEBUG` or `NDEBUG` to disable).
```c
-SpanType cspan_make(T SpanType, {v1, v2, ...}); // make a 1-d cspan from values
+SpanType cspan_init(T SpanType, {v1, v2, ...}); // make a 1-d cspan from values
SpanType cspan_from(STCContainer* cnt); // make a 1-d cspan from compatible STC container
SpanType cspan_from_array(ValueType array[]); // make a 1-d cspan from C array
SpanTypeN cspan_md(ValueType* data, intptr_t xdim, ...); // make a multi-dimensional cspan
diff --git a/docs/cstr_api.md b/docs/cstr_api.md
index 438dbf27..c7d19e0c 100644
--- a/docs/cstr_api.md
+++ b/docs/cstr_api.md
@@ -18,7 +18,7 @@ All cstr definitions and prototypes are available by including a single header f
## Methods
```c
-cstr cstr_init(void); // constructor; same as cstr_NULL.
+cstr cstr_init(void); // constructor; same as cstr_null.
cstr cstr_lit(const char literal_only[]); // cstr from literal; no strlen() call.
cstr cstr_from(const char* str); // constructor using strlen()
cstr cstr_from_n(const char* str, intptr_t n); // constructor with n first bytes of str
@@ -153,7 +153,7 @@ char* cstrnstrn(const char* str, const char* search, intptr_t slen, intpt
| Name | Value |
|:------------------|:------------------|
| `c_NPOS` | `INTPTR_MAX` |
-| `cstr_NULL` | cstr null value |
+| `cstr_null` | empty cstr value |
## Example
```c
diff --git a/docs/csview_api.md b/docs/csview_api.md
index 879822d3..a02b007a 100644
--- a/docs/csview_api.md
+++ b/docs/csview_api.md
@@ -112,7 +112,7 @@ uint64_t csview_hash(const csview* x);
| Name | Value | Usage |
|:---------------|:---------------------|:---------------------------------------------|
-| `csview_NULL` | same as `c_sv("")` | `sview = csview_NULL;` |
+| `csview_null` | same as `c_sv("")` | `sview = csview_null;` |
| `c_SV(sv)` | printf argument | `printf("sv: %.*s\n", c_SV(sv));` |
## Example
diff --git a/include/stc/algo/coroutine.h b/include/stc/algo/coroutine.h
index 67ea5a40..5cd6d68f 100644
--- a/include/stc/algo/coroutine.h
+++ b/include/stc/algo/coroutine.h
@@ -56,7 +56,7 @@ int main(void) {
return 0;
}
*/
-#include <stc/ccommon.h>
+#include "../ccommon.h"
enum {
cco_state_final = -1,
diff --git a/include/stc/algo/crange.h b/include/stc/algo/crange.h
index 56c317da..34ed541b 100644
--- a/include/stc/algo/crange.h
+++ b/include/stc/algo/crange.h
@@ -27,14 +27,15 @@
int main()
{
- crange r1 = crange_make(80, 90);
+ crange r1 = crange_init(80, 90);
c_foreach (i, crange, r1)
printf(" %lld", *i.ref);
puts("");
// use a temporary crange object.
int a = 100, b = INT32_MAX;
- c_forfilter (i, crange, crange_obj(a, b, 8),
+ crange r2 = crange_init(a, b, 8);
+ c_forfilter (i, crange, r2,
c_flt_skip(i, 10) &&
c_flt_take(i, 3))
printf(" %lld", *i.ref);
@@ -44,20 +45,17 @@ int main()
#ifndef STC_CRANGE_H_INCLUDED
#define STC_CRANGE_H_INCLUDED
-#include <stc/ccommon.h>
-
-#define crange_obj(...) \
- (*(crange[]){crange_make(__VA_ARGS__)})
+#include "../ccommon.h"
typedef long long crange_value;
typedef struct { crange_value start, end, step, value; } crange;
typedef struct { crange_value *ref, end, step; } crange_iter;
-#define crange_make(...) c_MACRO_OVERLOAD(crange_make, __VA_ARGS__)
-#define crange_make_1(stop) crange_make_3(0, stop, 1)
-#define crange_make_2(start, stop) crange_make_3(start, stop, 1)
+#define crange_init(...) c_MACRO_OVERLOAD(crange_init, __VA_ARGS__)
+#define crange_init_1(stop) crange_init_3(0, stop, 1)
+#define crange_init_2(start, stop) crange_init_3(start, stop, 1)
-STC_INLINE crange crange_make_3(crange_value start, crange_value stop, crange_value step)
+STC_INLINE crange crange_init_3(crange_value start, crange_value stop, crange_value step)
{ crange r = {start, stop - (step > 0), step}; return r; }
STC_INLINE crange_iter crange_begin(crange* self)
diff --git a/include/stc/algo/filter.h b/include/stc/algo/filter.h
index 8dc1ad74..f5de1811 100644
--- a/include/stc/algo/filter.h
+++ b/include/stc/algo/filter.h
@@ -47,7 +47,7 @@ int main()
#ifndef STC_FILTER_H_INCLUDED
#define STC_FILTER_H_INCLUDED
-#include <stc/ccommon.h>
+#include "../ccommon.h"
// c_forfilter:
diff --git a/include/stc/algo/sort.h b/include/stc/algo/sort.h
index bbd58427..2e73b0fb 100644
--- a/include/stc/algo/sort.h
+++ b/include/stc/algo/sort.h
@@ -42,6 +42,7 @@ int main() {
}
*/
#include "../ccommon.h"
+
#ifndef i_type
#define i_at(arr, idx) (&arr[idx])
#ifndef i_tag
diff --git a/include/stc/carc.h b/include/stc/carc.h
index 756b604f..749b1fc1 100644
--- a/include/stc/carc.h
+++ b/include/stc/carc.h
@@ -49,10 +49,11 @@ int main() {
c_drop(ArcPers, &p, &q);
}
*/
-#include "ccommon.h"
+#include "priv/linkage.h"
#ifndef CARC_H_INCLUDED
#define CARC_H_INCLUDED
+#include "ccommon.h"
#include "forward.h"
#include <stdlib.h>
@@ -72,7 +73,7 @@ int main() {
#define c_atomic_dec_and_test(v) (atomic_fetch_sub(v, 1) == 1)
#endif
-#define carc_NULL {NULL, NULL}
+#define carc_null {0}
#endif // CARC_H_INCLUDED
#define _i_prefix carc_
diff --git a/include/stc/cbox.h b/include/stc/cbox.h
index 699b32ac..d7f6246d 100644
--- a/include/stc/cbox.h
+++ b/include/stc/cbox.h
@@ -57,15 +57,16 @@ int main() {
}
}
*/
-#include "ccommon.h"
+#include "priv/linkage.h"
#ifndef CBOX_H_INCLUDED
#define CBOX_H_INCLUDED
+#include "ccommon.h"
#include "forward.h"
#include <stdlib.h>
#include <string.h>
-#define cbox_NULL {NULL}
+#define cbox_null {0}
#endif // CBOX_H_INCLUDED
#define _i_prefix cbox_
diff --git a/include/stc/ccommon.h b/include/stc/ccommon.h
index e491a567..5f280218 100644
--- a/include/stc/ccommon.h
+++ b/include/stc/ccommon.h
@@ -117,10 +117,6 @@
/* Function macros and others */
-#define c_init(C, ...) \
- C##_from_n((C##_raw[])__VA_ARGS__, c_sizeof((C##_raw[])__VA_ARGS__)/c_sizeof(C##_raw))
-#define c_make(C, ...) c_init(C, __VA_ARGS__) // [deprecated]
-
#define c_litstrlen(literal) (c_sizeof("" literal) - 1)
#define c_arraylen(a) (intptr_t)(sizeof(a)/sizeof 0[a])
@@ -210,16 +206,23 @@ STC_INLINE intptr_t cnextpow2(intptr_t n) {
; (_inc > 0) ^ (i > _end); i += _inc)
#ifndef __cplusplus
+ #define c_init(C, ...) \
+ C##_from_n((C##_raw[])__VA_ARGS__, c_sizeof((C##_raw[])__VA_ARGS__)/c_sizeof(C##_raw))
#define c_forlist(it, T, ...) \
- for (struct {T* ref; int size, index;} \
- it = {.ref=(T[])__VA_ARGS__, .size=(int)(sizeof((T[])__VA_ARGS__)/sizeof(T))} \
- ; it.index < it.size; ++it.ref, ++it.index)
+ for (struct {T* ref; int size, index;} \
+ it = {.ref=(T[])__VA_ARGS__, .size=(int)(sizeof((T[])__VA_ARGS__)/sizeof(T))} \
+ ; it.index < it.size; ++it.ref, ++it.index)
#else
- #include <initializer_list>
- #define c_forlist(it, T, ...) \
- for (struct {std::initializer_list<T> _il; std::initializer_list<T>::iterator ref; size_t size, index;} \
- it = {._il=__VA_ARGS__, .ref=it._il.begin(), .size=it._il.size()} \
- ; it.index < it.size; ++it.ref, ++it.index)
+ #include <initializer_list>
+ template <class C, class T>
+ inline C _from_n(C (*func)(const T[], intptr_t), std::initializer_list<T> il)
+ { return func(&*il.begin(), il.size()); }
+
+ #define c_init(C, ...) _from_n<C,C##_raw>(C##_from_n, __VA_ARGS__)
+ #define c_forlist(it, T, ...) \
+ for (struct {std::initializer_list<T> _il; std::initializer_list<T>::iterator ref; size_t size, index;} \
+ it = {._il=__VA_ARGS__, .ref=it._il.begin(), .size=it._il.size()} \
+ ; it.index < it.size; ++it.ref, ++it.index)
#endif
#define c_drop(C, ...) \
@@ -236,23 +239,9 @@ STC_INLINE intptr_t cnextpow2(intptr_t n) {
#define c_umul128(a, b, lo, hi) \
asm("mulq %3" : "=a"(*(lo)), "=d"(*(hi)) : "a"(a), "rm"(b))
#endif
-#endif // CCOMMON_H_INCLUDED
-#undef STC_API
-#undef STC_DEF
-
-#ifdef i_extern
-# define i_import
-#endif
-#if !defined(i_static) && !defined(STC_STATIC) && (defined(i_header) || defined(STC_HEADER) || \
- defined(i_implement) || defined(STC_IMPLEMENT))
- #define STC_API extern
- #define STC_DEF
-#else
- #define i_static
- #define STC_API static inline
- #define STC_DEF static inline
-#endif
-#if defined(STC_IMPLEMENT) || defined(i_import)
- #define i_implement
-#endif
+// [deprecated]:
+#define c_make(...) c_init(__VA_ARGS__)
+#define cspan_make(...) cspan_init(__VA_ARGS__)
+#define crange_make(...) crange_init(__VA_ARGS__)
+#endif // CCOMMON_H_INCLUDED
diff --git a/include/stc/clist.h b/include/stc/clist.h
index 310db204..4d05a3d1 100644
--- a/include/stc/clist.h
+++ b/include/stc/clist.h
@@ -51,9 +51,10 @@
}
}
*/
-#include "ccommon.h"
+#include "priv/linkage.h"
#ifndef CLIST_H_INCLUDED
+#include "ccommon.h"
#include "forward.h"
#include <stdlib.h>
#include <string.h>
diff --git a/include/stc/cmap.h b/include/stc/cmap.h
index f6c3eb07..2e234fb5 100644
--- a/include/stc/cmap.h
+++ b/include/stc/cmap.h
@@ -47,9 +47,10 @@ int main(void) {
cmap_ichar_drop(&m);
}
*/
-#include "ccommon.h"
+#include "priv/linkage.h"
#ifndef CMAP_H_INCLUDED
+#include "ccommon.h"
#include "forward.h"
#include <stdlib.h>
#include <string.h>
diff --git a/include/stc/cpque.h b/include/stc/cpque.h
index 31a53ece..b66c7735 100644
--- a/include/stc/cpque.h
+++ b/include/stc/cpque.h
@@ -20,9 +20,10 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
-#include "ccommon.h"
+#include "priv/linkage.h"
#ifndef CPQUE_H_INCLUDED
+#include "ccommon.h"
#include <stdlib.h>
#include "forward.h"
#endif
diff --git a/include/stc/cqueue.h b/include/stc/cqueue.h
index 28515877..3adc1bcb 100644
--- a/include/stc/cqueue.h
+++ b/include/stc/cqueue.h
@@ -20,9 +20,10 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
-#include "ccommon.h"
+#include "priv/linkage.h"
#ifndef CQUEUE_H_INCLUDED
+#include "ccommon.h"
#include "forward.h"
#include <stdlib.h>
#include <string.h>
diff --git a/include/stc/crand.h b/include/stc/crand.h
index 95a65fb0..89b681cd 100644
--- a/include/stc/crand.h
+++ b/include/stc/crand.h
@@ -20,10 +20,11 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
-#include "ccommon.h"
+#include "priv/linkage.h"
#ifndef CRAND_H_INCLUDED
#define CRAND_H_INCLUDED
+#include "ccommon.h"
/*
// crand: Pseudo-random number generator
#include "stc/crand.h"
diff --git a/include/stc/cregex.h b/include/stc/cregex.h
index 43a7fcbf..1d1d441f 100644
--- a/include/stc/cregex.h
+++ b/include/stc/cregex.h
@@ -22,6 +22,8 @@ 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.
*/
+#include "priv/linkage.h"
+
#ifndef CREGEX_H_INCLUDED
#define CREGEX_H_INCLUDED
/*
@@ -157,6 +159,7 @@ cstr cregex_replace_pattern_6(const char* pattern, const char* input, const char
/* destroy regex */
void cregex_drop(cregex* re);
+#endif // CREGEX_H_INCLUDED
#if defined i_implement
# include "../../src/cregex.c"
@@ -164,7 +167,6 @@ void cregex_drop(cregex* re);
#if defined i_import
# include "../../src/utf8code.c"
#endif
-#endif // CREGEX_H_INCLUDED
#undef i_opt
#undef i_header
#undef i_static
diff --git a/include/stc/csmap.h b/include/stc/csmap.h
index 7638b8f2..28598f0a 100644
--- a/include/stc/csmap.h
+++ b/include/stc/csmap.h
@@ -49,9 +49,10 @@ int main(void) {
csmap_sx_drop(&m);
}
*/
-#include "ccommon.h"
+#include "priv/linkage.h"
#ifndef CSMAP_H_INCLUDED
+#include "ccommon.h"
#include "forward.h"
#include <stdlib.h>
#include <string.h>
diff --git a/include/stc/cspan.h b/include/stc/cspan.h
index dd6cb1c0..d7a72267 100644
--- a/include/stc/cspan.h
+++ b/include/stc/cspan.h
@@ -60,6 +60,7 @@ int demo2() {
#ifndef STC_CSPAN_H_INCLUDED
#define STC_CSPAN_H_INCLUDED
+#include "priv/linkage.h"
#include "ccommon.h"
#define using_cspan(...) c_MACRO_OVERLOAD(using_cspan, __VA_ARGS__)
@@ -80,7 +81,7 @@ int demo2() {
return (Self){.data=raw, .shape={(int32_t)n}}; \
} \
STC_INLINE Self Self##_slice_(Self##_value* v, const int32_t shape[], const int32_t stri[], \
- const int rank, const int32_t a[][2]) { \
+ const int rank, const int32_t a[][2]) { \
Self s = {.data=v}; int outrank; \
s.data += _cspan_slice(s.shape, s.stride.d, &outrank, shape, stri, rank, a); \
c_ASSERT(outrank == RANK); \
@@ -115,8 +116,8 @@ typedef struct { int32_t d[6]; } cspan_idx6;
#define cspan_md(array, ...) \
{.data=array, .shape={__VA_ARGS__}, .stride={.d={__VA_ARGS__}}}
-/* For static initialization, use cspan_make(). c_init() for non-static only. */
-#define cspan_make(SpanType, ...) \
+/* For static initialization, use cspan_init(). c_init() for non-static only. */
+#define cspan_init(SpanType, ...) \
{.data=(SpanType##_value[])__VA_ARGS__, .shape={sizeof((SpanType##_value[])__VA_ARGS__)/sizeof(SpanType##_value)}}
#define cspan_slice(OutSpan, parent, ...) \
@@ -210,6 +211,7 @@ STC_API intptr_t _cspan_next2(int rank, int32_t pos[], const int32_t shape[], co
STC_API intptr_t _cspan_slice(int32_t odim[], int32_t ostri[], int* orank,
const int32_t shape[], const int32_t stri[],
int rank, const int32_t a[][2]);
+#endif // STC_CSPAN_H_INCLUDED
/* -------------------------- IMPLEMENTATION ------------------------- */
#if defined(i_implement) || defined(i_static)
@@ -260,7 +262,6 @@ STC_DEF intptr_t _cspan_slice(int32_t odim[], int32_t ostri[], int* orank,
return off;
}
#endif
-#endif
#undef i_opt
#undef i_header
#undef i_implement
diff --git a/include/stc/cstack.h b/include/stc/cstack.h
index fa0fab2b..fb4eae4b 100644
--- a/include/stc/cstack.h
+++ b/include/stc/cstack.h
@@ -20,10 +20,11 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
-#include "ccommon.h"
+#include "priv/linkage.h"
#ifndef CSTACK_H_INCLUDED
#define CSTACK_H_INCLUDED
+#include "ccommon.h"
#include <stdlib.h>
#include "forward.h"
#endif // CSTACK_H_INCLUDED
diff --git a/include/stc/cstr.h b/include/stc/cstr.h
index 0c5b67d8..bdfee39b 100644
--- a/include/stc/cstr.h
+++ b/include/stc/cstr.h
@@ -24,7 +24,7 @@
/* A string type with short string optimization in C99 with good small-string
* optimization (22 characters with 24 bytes string).
*/
-#define _i_no_undef
+#define _i_nested
#include "utf8.h"
#ifndef CSTR_H_INCLUDED
@@ -67,7 +67,7 @@ extern char* _cstr_internal_move(cstr* self, intptr_t pos1, intptr_t pos2);
/**************************** PUBLIC API **********************************/
#define cstr_lit(literal) cstr_from_n(literal, c_litstrlen(literal))
-#define cstr_NULL (c_LITERAL(cstr){{{0}, 0}})
+#define cstr_null (c_LITERAL(cstr){0})
#define cstr_toraw(self) cstr_str(self)
extern char* cstr_reserve(cstr* self, intptr_t cap);
@@ -97,7 +97,7 @@ STC_INLINE csview cstr_sv(const cstr* s) {
}
STC_INLINE cstr cstr_init(void)
- { return cstr_NULL; }
+ { return cstr_null; }
STC_INLINE cstr cstr_from_n(const char* str, const intptr_t len) {
cstr s;
@@ -132,7 +132,7 @@ STC_INLINE cstr* cstr_take(cstr* self, const cstr s) {
STC_INLINE cstr cstr_move(cstr* self) {
cstr tmp = *self;
- *self = cstr_NULL;
+ *self = cstr_null;
return tmp;
}
@@ -440,8 +440,8 @@ cstr cstr_tocase(csview sv, int k) {
#endif // i_import
/* -------------------------- IMPLEMENTATION ------------------------- */
+#if defined i_import || (defined i_implement && !defined _i_nested)
#ifndef CSTR_C_INCLUDED
-#if defined i_import || (defined i_implement && !defined _i_no_undef)
#define CSTR_C_INCLUDED
uint64_t cstr_hash(const cstr *self) {
@@ -573,7 +573,7 @@ bool cstr_getdelim(cstr *self, const int delim, FILE *fp) {
cstr
cstr_replace_sv(csview in, csview search, csview repl, int32_t count) {
- cstr out = cstr_NULL;
+ cstr out = cstr_null;
intptr_t from = 0; char* res;
if (!count) count = INT32_MAX;
if (search.size)
@@ -625,7 +625,7 @@ intptr_t cstr_vfmt(cstr* self, intptr_t start, const char* fmt, va_list args) {
#endif
cstr cstr_from_fmt(const char* fmt, ...) {
- cstr s = cstr_NULL;
+ cstr s = cstr_null;
va_list args;
va_start(args, fmt);
cstr_vfmt(&s, 0, fmt, args);
@@ -649,17 +649,17 @@ intptr_t cstr_printf(cstr* self, const char* fmt, ...) {
va_end(args);
return n;
}
-#endif // i_implement
#endif // CSTR_C_INCLUDED
+#endif // i_implement
#if defined __GNUC__ && !defined __clang__
# pragma GCC diagnostic pop
#endif
-#ifndef _i_no_undef
+#ifndef _i_nested
#undef i_opt
#undef i_header
#undef i_static
#undef i_implement
#undef i_import
#endif
-#undef _i_no_undef
+#undef _i_nested
diff --git a/include/stc/csview.h b/include/stc/csview.h
index a1893063..c16f58bc 100644
--- a/include/stc/csview.h
+++ b/include/stc/csview.h
@@ -20,14 +20,14 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
-#define _i_no_undef
+#define _i_nested
#include "utf8.h"
#ifndef CSVIEW_H_INCLUDED
#define CSVIEW_H_INCLUDED
-#define csview_NULL c_sv_1("")
-#define csview_init() csview_NULL
+#define csview_null c_sv_1("")
+#define csview_init() csview_null
#define csview_drop(p) c_default_drop(p)
#define csview_clone(sv) c_default_clone(sv)
#define csview_lit(literal) c_sv_1(literal)
@@ -42,7 +42,7 @@ extern csview csview_token(csview sv, const char* sep, intptr_t* start);
STC_INLINE csview csview_from(const char* str)
{ return c_LITERAL(csview){str, c_strlen(str)}; }
-STC_INLINE void csview_clear(csview* self) { *self = csview_NULL; }
+STC_INLINE void csview_clear(csview* self) { *self = csview_null; }
STC_INLINE intptr_t csview_size(csview sv) { return sv.size; }
STC_INLINE bool csview_empty(csview sv) { return sv.size == 0; }
@@ -150,8 +150,8 @@ STC_INLINE csview cstr_u8_substr(const cstr* self , intptr_t bytepos, intptr_t u
#endif
/* -------------------------- IMPLEMENTATION ------------------------- */
+#if defined i_import || (defined i_implement && !defined _i_nested)
#ifndef CSVIEW_C_INCLUDED
-#if defined i_import || (defined i_implement && !defined _i_no_undef)
#define CSVIEW_C_INCLUDED
csview_iter csview_advance(csview_iter it, intptr_t pos) {
@@ -201,13 +201,13 @@ csview csview_token(csview sv, const char* sep, intptr_t* start) {
*start += tok.size + sep_size;
return tok;
}
-#endif
-#endif
-#ifndef _i_no_undef
+#endif // CSVIEW_C_INCLUDED
+#endif // i_implement
+#ifndef _i_nested
#undef i_static
#undef i_header
#undef i_implement
#undef i_import
#undef i_opt
#endif
-#undef _i_no_undef
+#undef _i_nested
diff --git a/include/stc/cvec.h b/include/stc/cvec.h
index 747c654d..874f4f47 100644
--- a/include/stc/cvec.h
+++ b/include/stc/cvec.h
@@ -58,9 +58,10 @@ int main() {
cvec_str_drop(&svec);
}
*/
-#include "ccommon.h"
+#include "priv/linkage.h"
#ifndef CVEC_H_INCLUDED
+#include "ccommon.h"
#include "forward.h"
#include <stdlib.h>
#include <string.h>
diff --git a/include/stc/priv/linkage.h b/include/stc/priv/linkage.h
new file mode 100644
index 00000000..7f63f5f1
--- /dev/null
+++ b/include/stc/priv/linkage.h
@@ -0,0 +1,40 @@
+/* MIT License
+ *
+ * Copyright (c) 2023 Tyge Løvset
+ *
+ * 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.
+ */
+#undef STC_API
+#undef STC_DEF
+
+#ifdef i_extern // [deprecated]
+# define i_import
+#endif
+#if !defined(i_static) && !defined(STC_STATIC) && (defined(i_header) || defined(STC_HEADER) || \
+ defined(i_implement) || defined(STC_IMPLEMENT))
+ #define STC_API extern
+ #define STC_DEF
+#else
+ #define i_static
+ #define STC_API static inline
+ #define STC_DEF static inline
+#endif
+#if defined(STC_IMPLEMENT) || defined(i_import)
+ #define i_implement
+#endif
diff --git a/include/stc/utf8.h b/include/stc/utf8.h
index d6c759eb..190cc7f3 100644
--- a/include/stc/utf8.h
+++ b/include/stc/utf8.h
@@ -1,9 +1,31 @@
-
-#include "ccommon.h"
+/* MIT License
+ *
+ * Copyright (c) 2023 Tyge Løvset
+ *
+ * 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.
+ */
+#include "priv/linkage.h"
#ifndef UTF8_H_INCLUDED
#define UTF8_H_INCLUDED
+#include "ccommon.h"
#include <ctype.h>
#include "forward.h"
@@ -53,9 +75,9 @@ STC_INLINE bool utf8_isspace(uint32_t c) {
/* decode next utf8 codepoint. https://bjoern.hoehrmann.de/utf-8/decoder/dfa */
typedef struct { uint32_t state, codep; } utf8_decode_t;
+extern const uint8_t utf8_dtab[]; /* utf8code.c */
STC_INLINE uint32_t utf8_decode(utf8_decode_t* d, const uint32_t byte) {
- extern const uint8_t utf8_dtab[]; /* utf8code.c */
const uint32_t type = utf8_dtab[byte];
d->codep = d->state ? (byte & 0x3fu) | (d->codep << 6)
: (0xffU >> type) & byte;
@@ -116,14 +138,14 @@ STC_INLINE intptr_t utf8_pos(const char* s, intptr_t index)
{ return (intptr_t)(utf8_at(s, index) - s); }
#endif // UTF8_H_INCLUDED
-#if defined i_import || (defined i_implement && !defined _i_no_undef)
+#if defined i_import || (defined i_implement && !defined _i_nested)
# include "../../src/utf8code.c"
#endif
-#ifndef _i_no_undef
+#ifndef _i_nested
#undef i_static
#undef i_header
#undef i_implement
#undef i_import
#undef i_opt
#endif
-#undef _i_no_undef
+#undef _i_nested
diff --git a/misc/examples/astar.c b/misc/examples/astar.c
index db6bbd70..1b3876aa 100644
--- a/misc/examples/astar.c
+++ b/misc/examples/astar.c
@@ -21,7 +21,7 @@ point;
point
point_init(int x, int y, int width)
{
- return (point) { x, y, 0, width };
+ return c_LITERAL(point){ x, y, 0, width };
}
int
diff --git a/misc/examples/box.c b/misc/examples/box.c
index e352aa2b..a9131afa 100644
--- a/misc/examples/box.c
+++ b/misc/examples/box.c
@@ -5,7 +5,7 @@
typedef struct { cstr name, last; } Person;
Person Person_make(const char* name, const char* last) {
- return (Person){.name = cstr_from(name), .last = cstr_from(last)};
+ return c_LITERAL(Person){.name = cstr_from(name), .last = cstr_from(last)};
}
uint64_t Person_hash(const Person* a) {
diff --git a/misc/examples/box2.c b/misc/examples/box2.c
index 33212ef4..963a3815 100644
--- a/misc/examples/box2.c
+++ b/misc/examples/box2.c
@@ -29,12 +29,12 @@ typedef struct {
#include <stc/cbox.h> // BoxBoxPoint
Point origin(void) {
- return (Point){ .x=1.0, .y=2.0 };
+ return c_LITERAL(Point){ .x=1.0, .y=2.0 };
}
cbox_Point boxed_origin(void) {
// Allocate this point on the heap, and return a pointer to it
- return cbox_Point_make((Point){ .x=1.0, .y=2.0 });
+ return cbox_Point_make(c_LITERAL(Point){ .x=1.0, .y=2.0 });
}
@@ -47,7 +47,7 @@ int main(void) {
};
// Heap allocated rectangle
- cbox_Rectangle boxed_rectangle = cbox_Rectangle_make((Rectangle){
+ cbox_Rectangle boxed_rectangle = cbox_Rectangle_make(c_LITERAL(Rectangle){
.top_left = origin(),
.bottom_right = { .x=3.0, .y=-4.0 }
});
diff --git a/misc/examples/csmap_find.c b/misc/examples/csmap_find.c
index a8928410..c123e398 100644
--- a/misc/examples/csmap_find.c
+++ b/misc/examples/csmap_find.c
@@ -50,12 +50,12 @@ int main()
print_collection_csmap_istr(&m1);
typedef cvec_istr_value pair;
- cvec_istr_push(&v, (pair){43, "Tc"});
- cvec_istr_push(&v, (pair){41, "Nb"});
- cvec_istr_push(&v, (pair){46, "Pd"});
- cvec_istr_push(&v, (pair){42, "Mo"});
- cvec_istr_push(&v, (pair){44, "Ru"});
- cvec_istr_push(&v, (pair){44, "Ru"}); // attempt a duplicate
+ cvec_istr_push(&v, c_LITERAL(pair){43, "Tc"});
+ cvec_istr_push(&v, c_LITERAL(pair){41, "Nb"});
+ cvec_istr_push(&v, c_LITERAL(pair){46, "Pd"});
+ cvec_istr_push(&v, c_LITERAL(pair){42, "Mo"});
+ cvec_istr_push(&v, c_LITERAL(pair){44, "Ru"});
+ cvec_istr_push(&v, c_LITERAL(pair){44, "Ru"}); // attempt a duplicate
puts("Inserting the following vector data into m1:");
print_collection_cvec_istr(&v);
diff --git a/misc/examples/csmap_insert.c b/misc/examples/csmap_insert.c
index f96cc08f..18a88ec3 100644
--- a/misc/examples/csmap_insert.c
+++ b/misc/examples/csmap_insert.c
@@ -34,7 +34,7 @@ int main()
// insert single values
csmap_ii m1 = {0};
csmap_ii_insert(&m1, 1, 10);
- csmap_ii_push(&m1, (csmap_ii_value){2, 20});
+ csmap_ii_push(&m1, c_LITERAL(csmap_ii_value){2, 20});
puts("The original key and mapped values of m1 are:");
print_ii(m1);
@@ -61,11 +61,11 @@ int main()
csmap_ii m2 = {0};
cvec_ii v = {0};
typedef cvec_ii_value ipair;
- cvec_ii_push(&v, (ipair){43, 294});
- cvec_ii_push(&v, (ipair){41, 262});
- cvec_ii_push(&v, (ipair){45, 330});
- cvec_ii_push(&v, (ipair){42, 277});
- cvec_ii_push(&v, (ipair){44, 311});
+ cvec_ii_push(&v, c_LITERAL(ipair){43, 294});
+ cvec_ii_push(&v, c_LITERAL(ipair){41, 262});
+ cvec_ii_push(&v, c_LITERAL(ipair){45, 330});
+ cvec_ii_push(&v, c_LITERAL(ipair){42, 277});
+ cvec_ii_push(&v, c_LITERAL(ipair){44, 311});
puts("Inserting the following vector data into m2:");
c_foreach (e, cvec_ii, v)
diff --git a/misc/examples/dining_philosophers.c b/misc/examples/dining_philosophers.c
index f9c05e71..e13eb055 100644
--- a/misc/examples/dining_philosophers.c
+++ b/misc/examples/dining_philosophers.c
@@ -29,9 +29,10 @@ struct Dining {
// Philosopher coroutine
void philosopher(struct Philosopher* p)
{
+ double duration;
cco_routine(p) {
while (1) {
- double duration = 1.0 + crandf()*2.0;
+ duration = 1.0 + crandf()*2.0;
printf("Philosopher %d is thinking for %.0f minutes...\n", p->id, duration*10);
cco_timer_await(&p->tm, duration);
@@ -46,7 +47,7 @@ void philosopher(struct Philosopher* p)
cco_sem_release(p->left_fork);
cco_sem_release(p->right_fork);
}
-
+
cco_final:
printf("Philosopher %d finished\n", p->id);
}
diff --git a/misc/examples/forfilter.c b/misc/examples/forfilter.c
index 94a84065..d39693b5 100644
--- a/misc/examples/forfilter.c
+++ b/misc/examples/forfilter.c
@@ -55,7 +55,8 @@ fn main() {
void demo2(void)
{
IVec vector = {0};
- c_forfilter (x, crange, crange_obj(INT64_MAX),
+ crange r = crange_init(INT64_MAX);
+ c_forfilter (x, crange, r,
c_flt_skipwhile(x, *x.ref != 11) &&
(*x.ref % 2) != 0 &&
c_flt_take(x, 5)
@@ -124,7 +125,7 @@ void demo5(void)
{
#define flt_even(i) ((*i.ref & 1) == 0)
#define flt_mid_decade(i) ((*i.ref % 10) != 0)
- crange R = crange_make(1963, INT32_MAX);
+ crange R = crange_init(1963, INT32_MAX);
c_forfilter (i, crange, R,
c_flt_skip(i,15) &&
diff --git a/misc/examples/make.sh b/misc/examples/make.sh
index 61d9f879..cf224950 100755
--- a/misc/examples/make.sh
+++ b/misc/examples/make.sh
@@ -7,13 +7,13 @@ if [ "$(uname)" = 'Linux' ]; then
fi
cc=gcc; cflags="-std=c99 -s -O3 -Wall -Wextra -Wpedantic -Wconversion -Wwrite-strings -Wdouble-promotion -Wno-unused-parameter -Wno-maybe-uninitialized -Wno-implicit-fallthrough -Wno-missing-field-initializers"
-#cc=gcc; cflags="-DSTC_STATIC -std=c99 -g -Werror -Wfatal-errors -Wpedantic -Wall $sanitize"
-#cc=tcc; cflags="-DSTC_STATIC -std=c99 -Wall"
-#cc=clang; cflags="-DSTC_STATIC -std=c99 -s -O3 -Wall -Wextra -Wpedantic -Wconversion -Wwrite-strings -Wdouble-promotion -Wno-unused-parameter -Wno-unused-function -Wno-implicit-fallthrough -Wno-missing-field-initializers"
-#cc=gcc; cflags="-DSTC_STATIC -x c++ -std=c++20 -O2 -s -Wall"
-#cc=cl; cflags="-DSTC_STATIC -nologo -O2 -MD -W3 -wd4003"
-#cc=cl; cflags="-DSTC_STATIC -nologo -TP -wd4003"
-#cc=cl; cflags="-DSTC_STATIC -nologo -std:c11 -wd4003"
+#cc=gcc; cflags="-std=c99 -g -Werror -Wfatal-errors -Wpedantic -Wall $sanitize"
+#cc=tcc; cflags="-std=c99 -Wall"
+#cc=clang; cflags="-std=c99 -s -O3 -Wall -Wextra -Wpedantic -Wconversion -Wwrite-strings -Wdouble-promotion -Wno-unused-parameter -Wno-unused-function -Wno-implicit-fallthrough -Wno-missing-field-initializers"
+#cc=gcc; cflags="-x c++ -std=c++20 -O2 -s -Wall"
+#cc=cl; cflags="-nologo -O2 -MD -W3 -wd4003"
+#cc=cl; cflags="-nologo -TP -std:c++20 -wd4003"
+#cc=cl; cflags="-nologo -std:c11 -wd4003"
if [ "$cc" = "cl" ]; then
oflag='/Fe:'
diff --git a/misc/examples/music_arc.c b/misc/examples/music_arc.c
index 9c7173ef..18ea30c0 100644
--- a/misc/examples/music_arc.c
+++ b/misc/examples/music_arc.c
@@ -13,7 +13,7 @@ int Song_cmp(const Song* x, const Song* y)
{ return cstr_cmp(&x->title, &y->title); }
Song Song_make(const char* artist, const char* title)
- { return (Song){cstr_from(artist), cstr_from(title)}; }
+ { return c_LITERAL(Song){cstr_from(artist), cstr_from(title)}; }
void Song_drop(Song* s) {
printf("drop: %s\n", cstr_str(&s->title));
diff --git a/misc/examples/new_list.c b/misc/examples/new_list.c
index 993f1aac..382943bb 100644
--- a/misc/examples/new_list.c
+++ b/misc/examples/new_list.c
@@ -45,7 +45,7 @@ int main()
{
MyStruct my = {0};
clist_i32_push_back(&my.intlst, 123);
- clist_pnt_push_back(&my.pntlst, (Point){123, 456});
+ clist_pnt_push_back(&my.pntlst, c_LITERAL(Point){123, 456});
MyStruct_drop(&my);
clist_pnt plst = c_init(clist_pnt, {{42, 14}, {32, 94}, {62, 81}});
diff --git a/misc/examples/new_sptr.c b/misc/examples/new_sptr.c
index aa8dd175..36a61f9c 100644
--- a/misc/examples/new_sptr.c
+++ b/misc/examples/new_sptr.c
@@ -30,7 +30,8 @@ uint64_t Person_hash(const Person* p);
Person Person_make(const char* name, const char* last) {
- return (Person){.name = cstr_from(name), .last = cstr_from(last)};
+ Person p = {.name = cstr_from(name), .last = cstr_from(last)};
+ return p;
}
int Person_cmp(const Person* a, const Person* b) {
diff --git a/misc/examples/new_vec.c b/misc/examples/new_vec.c
index d4b66883..e10910d9 100644
--- a/misc/examples/new_vec.c
+++ b/misc/examples/new_vec.c
@@ -26,10 +26,10 @@ int main()
{
MyStruct my = {0};
- cvec_pnt_push(&my.pntvec, (Point){42, 14});
- cvec_pnt_push(&my.pntvec, (Point){32, 94});
- cvec_pnt_push(&my.pntvec, (Point){62, 81});
- cvec_pnt_push(&my.pntvec, (Point){32, 91});
+ cvec_pnt_push(&my.pntvec, c_LITERAL(Point){42, 14});
+ cvec_pnt_push(&my.pntvec, c_LITERAL(Point){32, 94});
+ cvec_pnt_push(&my.pntvec, c_LITERAL(Point){62, 81});
+ cvec_pnt_push(&my.pntvec, c_LITERAL(Point){32, 91});
cvec_pnt_sort(&my.pntvec);
diff --git a/misc/examples/person_arc.c b/misc/examples/person_arc.c
index b4b926da..3614c02d 100644
--- a/misc/examples/person_arc.c
+++ b/misc/examples/person_arc.c
@@ -6,7 +6,8 @@
typedef struct { cstr name, last; } Person;
Person Person_make(const char* name, const char* last) {
- return (Person){.name = cstr_from(name), .last = cstr_from(last)};
+ Person p = {.name = cstr_from(name), .last = cstr_from(last)};
+ return p;
}
int Person_cmp(const Person* a, const Person* b) {
diff --git a/misc/examples/prime.c b/misc/examples/prime.c
index cb0f8926..34fa144c 100644
--- a/misc/examples/prime.c
+++ b/misc/examples/prime.c
@@ -41,7 +41,9 @@ int main(void)
puts("\n");
puts("Show the last 50 primes using a temporary crange generator:");
- c_forfilter (i, crange, crange_obj(n - 1, 0, -2),
+ crange range = crange_init(n - 1, 0, -2);
+
+ c_forfilter (i, crange, range,
cbits_test(&primes, *i.ref/2) &&
c_flt_take(i, 50)
){
diff --git a/misc/examples/printspan.c b/misc/examples/printspan.c
index b5099ed5..7564bd88 100644
--- a/misc/examples/printspan.c
+++ b/misc/examples/printspan.c
@@ -22,22 +22,22 @@ void printMe(intspan container) {
int main()
{
- intspan sp1 = cspan_make(intspan, {1, 2});
+ intspan sp1 = cspan_init(intspan, {1, 2});
printMe( sp1 );
printMe( c_init(intspan, {1, 2, 3}) );
int arr[] = {1, 2, 3, 4, 5, 6};
intspan sp2 = cspan_from_array(arr);
- printMe( (intspan)cspan_subspan(&sp2, 1, 4) );
+ printMe( c_LITERAL(intspan)cspan_subspan(&sp2, 1, 4) );
cvec_int vec = c_init(cvec_int, {1, 2, 3, 4, 5});
- printMe( (intspan)cspan_from(&vec) );
+ printMe( c_LITERAL(intspan)cspan_from(&vec) );
printMe( sp2 );
cstack_int stk = c_init(cstack_int, {1, 2, 3, 4, 5, 6, 7});
- printMe( (intspan)cspan_from(&stk) );
+ printMe( c_LITERAL(intspan)cspan_from(&stk) );
csset_str set = c_init(csset_str, {"5", "7", "4", "3", "8", "2", "1", "9", "6"});
printf("%d:", (int)csset_str_size(&set));
diff --git a/misc/examples/read.c b/misc/examples/read.c
index 545d706a..3c1cadf6 100644
--- a/misc/examples/read.c
+++ b/misc/examples/read.c
@@ -9,7 +9,7 @@ cvec_str read_file(const char* name)
{
cvec_str vec = cvec_str_init();
c_with (FILE* f = fopen(name, "r"), fclose(f))
- c_with (cstr line = cstr_NULL, cstr_drop(&line))
+ c_with (cstr line = cstr_null, cstr_drop(&line))
while (cstr_getline(&line, f))
cvec_str_push(&vec, cstr_clone(line));
return vec;
diff --git a/misc/examples/shape.c b/misc/examples/shape.c
index 22e993db..1d9fe5c5 100644
--- a/misc/examples/shape.c
+++ b/misc/examples/shape.c
@@ -137,7 +137,7 @@ int main(void)
{
Shapes shapes = {0};
- Triangle* tri1 = c_new(Triangle, Triangle_from((Point){5, 7}, (Point){12, 7}, (Point){12, 20}));
+ Triangle* tri1 = c_new(Triangle, Triangle_from(c_LITERAL(Point){5, 7}, c_LITERAL(Point){12, 7}, c_LITERAL(Point){12, 20}));
Polygon* pol1 = c_new(Polygon, Polygon_init());
Polygon* pol2 = c_new(Polygon, Polygon_init());
diff --git a/misc/examples/vikings.c b/misc/examples/vikings.c
index cf087119..d9024052 100644
--- a/misc/examples/vikings.c
+++ b/misc/examples/vikings.c
@@ -44,12 +44,12 @@ static inline RViking Viking_toraw(const Viking* vp) {
int main()
{
Vikings vikings = {0};
- Vikings_emplace(&vikings, (RViking){"Einar", "Norway"}, 20);
- Vikings_emplace(&vikings, (RViking){"Olaf", "Denmark"}, 24);
- Vikings_emplace(&vikings, (RViking){"Harald", "Iceland"}, 12);
- Vikings_emplace(&vikings, (RViking){"Björn", "Sweden"}, 10);
+ Vikings_emplace(&vikings, c_LITERAL(RViking){"Einar", "Norway"}, 20);
+ Vikings_emplace(&vikings, c_LITERAL(RViking){"Olaf", "Denmark"}, 24);
+ Vikings_emplace(&vikings, c_LITERAL(RViking){"Harald", "Iceland"}, 12);
+ Vikings_emplace(&vikings, c_LITERAL(RViking){"Björn", "Sweden"}, 10);
- Vikings_value* v = Vikings_get_mut(&vikings, (RViking){"Einar", "Norway"});
+ Vikings_value* v = Vikings_get_mut(&vikings, c_LITERAL(RViking){"Einar", "Norway"});
v->second += 3; // add 3 hp points to Einar
c_forpair (vk, hp, Vikings, vikings) {
diff --git a/src/cregex.c b/src/cregex.c
index 1af719b4..9b7179b6 100644
--- a/src/cregex.c
+++ b/src/cregex.c
@@ -28,20 +28,20 @@ THE SOFTWARE.
#include <setjmp.h>
#ifdef i_import
-# define _i_extern
+# define _i_import
#endif
#ifndef CREGEX_H_INCLUDED
# include "../include/stc/cregex.h"
#endif
-#ifdef _i_extern
+#ifdef _i_import
# include "utf8code.c"
#endif
-#ifdef _i_extern
+#ifdef _i_import
# define i_implement
#else
# undef i_implement
#endif
-#undef _i_extern
+#undef _i_import
#include "../include/stc/cstr.h"
typedef uint32_t _Rune; /* Utf8 code point */
@@ -944,14 +944,14 @@ _runematch(_Rune s, _Rune r)
case ASC_LO: inv = 1; case ASC_lo: return inv ^ (islower((int)r) != 0);
case ASC_UP: inv = 1; case ASC_up: return inv ^ (isupper((int)r) != 0);
case ASC_XD: inv = 1; case ASC_xd: return inv ^ (isxdigit((int)r) != 0);
- case UTF_AN: inv = 1; case UTF_an: return inv ^ utf8_isalnum(r);
- case UTF_BL: inv = 1; case UTF_bl: return inv ^ utf8_isblank(r);
- case UTF_SP: inv = 1; case UTF_sp: return inv ^ utf8_isspace(r);
- case UTF_LL: inv = 1; case UTF_ll: return inv ^ utf8_islower(r);
- case UTF_LU: inv = 1; case UTF_lu: return inv ^ utf8_isupper(r);
- case UTF_LC: inv = 1; case UTF_lc: return inv ^ utf8_iscased(r);
- case UTF_AL: inv = 1; case UTF_al: return inv ^ utf8_isalpha(r);
- case UTF_WR: inv = 1; case UTF_wr: return inv ^ utf8_isword(r);
+ case UTF_AN: inv = 1; case UTF_an: return inv ^ (int)utf8_isalnum(r);
+ case UTF_BL: inv = 1; case UTF_bl: return inv ^ (int)utf8_isblank(r);
+ case UTF_SP: inv = 1; case UTF_sp: return inv ^ (int)utf8_isspace(r);
+ case UTF_LL: inv = 1; case UTF_ll: return inv ^ (int)utf8_islower(r);
+ case UTF_LU: inv = 1; case UTF_lu: return inv ^ (int)utf8_isupper(r);
+ case UTF_LC: inv = 1; case UTF_lc: return inv ^ (int)utf8_iscased(r);
+ case UTF_AL: inv = 1; case UTF_al: return inv ^ (int)utf8_isalpha(r);
+ case UTF_WR: inv = 1; case UTF_wr: return inv ^ (int)utf8_isword(r);
case UTF_cc: case UTF_CC:
case UTF_lt: case UTF_LT:
case UTF_nd: case UTF_ND:
@@ -972,7 +972,7 @@ _runematch(_Rune s, _Rune r)
case UTF_latin: case UTF_LATIN:
n = (int)s - UTF_GRP;
inv = n & 1;
- return inv ^ utf8_isgroup(n / 2, r);
+ return inv ^ (int)utf8_isgroup(n / 2, r);
}
return s == r;
}
@@ -1220,7 +1220,7 @@ _build_subst(const char* replace, int nmatch, const csview match[],
cstr_buf buf = cstr_buffer(subst);
intptr_t len = 0, cap = buf.cap;
char* dst = buf.data;
- cstr mstr = cstr_NULL;
+ cstr mstr = cstr_null;
while (*replace != '\0') {
if (*replace == '$') {
@@ -1293,8 +1293,8 @@ cregex_find_pattern_4(const char* pattern, const char* input,
cstr
cregex_replace_sv_6(const cregex* re, csview input, const char* replace, int count,
bool (*mfun)(int, csview, cstr*), int rflags) {
- cstr out = cstr_NULL;
- cstr subst = cstr_NULL;
+ cstr out = cstr_null;
+ cstr subst = cstr_null;
csview match[CREG_MAX_CAPTURES];
int nmatch = cregex_captures(re) + 1;
if (!count) count = INT32_MAX;
diff --git a/src/utf8code.c b/src/utf8code.c
index 6a133050..4abf10ea 100644
--- a/src/utf8code.c
+++ b/src/utf8code.c
@@ -461,28 +461,31 @@ static const URange16 Latin_range16[] = {
#define UNI_ENTRY(Code) \
{ Code##_range16, sizeof(Code##_range16)/sizeof(URange16) }
-#ifndef __cplusplus
+#ifdef __cplusplus
+#define _e_arg(k, v) v
+#else
+#define _e_arg(k, v) [k] = v
static
#endif
const UGroup _utf8_unicode_groups[U8G_SIZE] = {
- [U8G_Cc] = UNI_ENTRY(Cc),
- [U8G_Lt] = UNI_ENTRY(Lt),
- [U8G_Nd] = UNI_ENTRY(Nd),
- [U8G_Nl] = UNI_ENTRY(Nl),
- [U8G_Pc] = UNI_ENTRY(Pc),
- [U8G_Pd] = UNI_ENTRY(Pd),
- [U8G_Pf] = UNI_ENTRY(Pf),
- [U8G_Pi] = UNI_ENTRY(Pi),
- [U8G_Sc] = UNI_ENTRY(Sc),
- [U8G_Zl] = UNI_ENTRY(Zl),
- [U8G_Zp] = UNI_ENTRY(Zp),
- [U8G_Zs] = UNI_ENTRY(Zs),
- [U8G_Arabic] = UNI_ENTRY(Arabic),
- [U8G_Cyrillic] = UNI_ENTRY(Cyrillic),
- [U8G_Devanagari] = UNI_ENTRY(Devanagari),
- [U8G_Greek] = UNI_ENTRY(Greek),
- [U8G_Han] = UNI_ENTRY(Han),
- [U8G_Latin] = UNI_ENTRY(Latin),
+ _e_arg(U8G_Cc, UNI_ENTRY(Cc)),
+ _e_arg(U8G_Lt, UNI_ENTRY(Lt)),
+ _e_arg(U8G_Nd, UNI_ENTRY(Nd)),
+ _e_arg(U8G_Nl, UNI_ENTRY(Nl)),
+ _e_arg(U8G_Pc, UNI_ENTRY(Pc)),
+ _e_arg(U8G_Pd, UNI_ENTRY(Pd)),
+ _e_arg(U8G_Pf, UNI_ENTRY(Pf)),
+ _e_arg(U8G_Pi, UNI_ENTRY(Pi)),
+ _e_arg(U8G_Sc, UNI_ENTRY(Sc)),
+ _e_arg(U8G_Zl, UNI_ENTRY(Zl)),
+ _e_arg(U8G_Zp, UNI_ENTRY(Zp)),
+ _e_arg(U8G_Zs, UNI_ENTRY(Zs)),
+ _e_arg(U8G_Arabic, UNI_ENTRY(Arabic)),
+ _e_arg(U8G_Cyrillic, UNI_ENTRY(Cyrillic)),
+ _e_arg(U8G_Devanagari, UNI_ENTRY(Devanagari)),
+ _e_arg(U8G_Greek, UNI_ENTRY(Greek)),
+ _e_arg(U8G_Han, UNI_ENTRY(Han)),
+ _e_arg(U8G_Latin, UNI_ENTRY(Latin)),
};
#endif