summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkr.angelov <kr.angelov@gmail.com>2013-09-04 10:06:07 +0000
committerkr.angelov <kr.angelov@gmail.com>2013-09-04 10:06:07 +0000
commit805f95eac61ef17d7ec3f87dda1dfbc932951dee (patch)
tree62ab374454b87aa4d7d04bbee18ead8a4cbace37
parentae87c3d272104a933d148a544c9eab15865c1758 (diff)
remove the dependency on the HAVE_STATEMENT_EXPRESSIONS flag. This reduces the dependency on the ./configure script
-rw-r--r--src/runtime/c/configure.ac1
-rw-r--r--src/runtime/c/gu/exn.c26
-rw-r--r--src/runtime/c/gu/exn.h23
-rw-r--r--src/runtime/c/gu/file.c18
-rw-r--r--src/runtime/c/gu/in.c22
-rw-r--r--src/runtime/c/gu/map.c26
-rw-r--r--src/runtime/c/gu/mem.c5
-rw-r--r--src/runtime/c/gu/mem.h50
-rw-r--r--src/runtime/c/gu/out.c13
-rw-r--r--src/runtime/c/gu/string.c7
-rw-r--r--src/runtime/c/gu/type.c5
-rw-r--r--src/runtime/c/gu/write.c121
-rw-r--r--src/runtime/c/m4/c_ext.m416
-rw-r--r--src/runtime/c/pgf/parser.c10
-rw-r--r--src/runtime/c/pgf/reader.c10
15 files changed, 82 insertions, 271 deletions
diff --git a/src/runtime/c/configure.ac b/src/runtime/c/configure.ac
index f8f641c21..069822bbb 100644
--- a/src/runtime/c/configure.ac
+++ b/src/runtime/c/configure.ac
@@ -37,7 +37,6 @@ fi]
AC_C_ALIGNOF
AC_C_FAM_IN_MEM
-AC_C_STATEMENT_EXPRESSIONS
AC_C_ASCII
case "$target_cpu" in
diff --git a/src/runtime/c/gu/exn.c b/src/runtime/c/gu/exn.c
index ec68ec039..cdcf9c9f4 100644
--- a/src/runtime/c/gu/exn.c
+++ b/src/runtime/c/gu/exn.c
@@ -5,13 +5,14 @@
GuExn*
gu_new_exn(GuExn* parent, GuKind* catch, GuPool* pool)
{
- return gu_new_s(pool, GuExn,
- .state = GU_EXN_OK,
- .parent = parent,
- .catch = catch,
- .caught = NULL,
- .data.pool = pool,
- .data.data = NULL);
+ GuExn* exn = gu_new(GuExn, pool);
+ exn->state = GU_EXN_OK;
+ exn->parent = parent;
+ exn->catch = catch;
+ exn->caught = NULL;
+ exn->data.pool = pool;
+ exn->data.data = NULL;
+ return exn;
}
void
@@ -74,4 +75,15 @@ gu_exn_caught(GuExn* err)
return err->caught;
}
+void
+gu_raise_errno(GuExn* err)
+{
+ GuExnData* err_data = gu_raise(err, GuErrno);
+ if (err_data) {
+ GuErrno* gu_errno = gu_new(GuErrno, err_data->pool);
+ *gu_errno = errno;
+ err_data->data = gu_errno;
+ }
+}
+
GU_DEFINE_TYPE(GuErrno, signed, _);
diff --git a/src/runtime/c/gu/exn.h b/src/runtime/c/gu/exn.h
index 36e52917f..9ee70438a 100644
--- a/src/runtime/c/gu/exn.h
+++ b/src/runtime/c/gu/exn.h
@@ -38,10 +38,10 @@ struct GuExnData
{
/// The pool that the exception value should be allocated from.
- GuPool* const pool;
+ GuPool* pool;
/// The exception value.
- const void* data;
+ void* data;
};
struct GuExn {
@@ -146,10 +146,6 @@ gu_exn_raise_debug_(GuExn* err, GuType* type,
} \
GU_END
-#define gu_raise_i(error_, t_, ...) \
- gu_raise_new(error_, t_, gu_raise_pool_, gu_new_i(gu_raise_pool_, t_, __VA_ARGS__))
-
-
/// Check the status of the current exception frame
static inline bool
gu_ok(GuExn* exn) {
@@ -177,21 +173,8 @@ typedef int GuErrno;
extern GU_DECLARE_TYPE(GuErrno, signed);
-
-
-#define gu_raise_errno(error_) \
- gu_raise_i(error_, GuErrno, errno)
-
-#if 0
-
-typedef void (*GuExnPrintFn)(GuFn* clo, void* err, FILE* out);
-
-extern GuTypeTable gu_exn_default_printer;
-
void
-gu_exn_print(GuExn* err, FILE* out, GuTypeMap printer_map);
-
-#endif
+gu_raise_errno(GuExn* err);
/** @} */
diff --git a/src/runtime/c/gu/file.c b/src/runtime/c/gu/file.c
index ed1956537..f51eb1ca1 100644
--- a/src/runtime/c/gu/file.c
+++ b/src/runtime/c/gu/file.c
@@ -34,10 +34,12 @@ gu_file_flush(GuOutStream* stream, GuExn* err)
GuOut*
gu_file_out(FILE* file, GuPool* pool)
{
- GuFileOutStream* fos = gu_new_i(pool, GuFileOutStream,
- .stream.output = gu_file_output,
- .stream.flush = gu_file_flush,
- .file = file);
+ GuFileOutStream* fos = gu_new(GuFileOutStream, pool);
+ fos->stream.begin_buf = NULL;
+ fos->stream.end_buf = NULL;
+ fos->stream.output = gu_file_output;
+ fos->stream.flush = gu_file_flush;
+ fos->file = file;
return gu_new_out(&fos->stream, pool);
}
@@ -66,8 +68,10 @@ gu_file_input(GuInStream* stream, uint8_t* buf, size_t sz, GuExn* err)
GuIn*
gu_file_in(FILE* file, GuPool* pool)
{
- GuFileInStream* fis = gu_new_s(pool, GuFileInStream,
- .stream.input = gu_file_input,
- .file = file);
+ GuFileInStream* fis = gu_new(GuFileInStream, pool);
+ fis->stream.begin_buffer = NULL;
+ fis->stream.end_buffer = NULL;
+ fis->stream.input = gu_file_input;
+ fis->file = file;
return gu_new_in(&fis->stream, pool);
}
diff --git a/src/runtime/c/gu/in.c b/src/runtime/c/gu/in.c
index 4238475f8..b2f1f1ae7 100644
--- a/src/runtime/c/gu/in.c
+++ b/src/runtime/c/gu/in.c
@@ -307,12 +307,12 @@ gu_proxy_in_input(GuInStream* self, uint8_t* dst, size_t sz, GuExn* err)
GuInStream*
gu_in_proxy_stream(GuIn* in, GuPool* pool)
{
- return &gu_new_s(
- pool, GuProxyInStream,
- .stream.begin_buffer = gu_proxy_in_begin_buffer,
- .stream.end_buffer = gu_proxy_in_end_buffer,
- .stream.input = gu_proxy_in_input,
- .real_in = in)->stream;
+ GuProxyInStream* ins = gu_new(GuProxyInStream, pool);
+ ins->stream.begin_buffer = gu_proxy_in_begin_buffer;
+ ins->stream.end_buffer = gu_proxy_in_end_buffer;
+ ins->stream.input = gu_proxy_in_input;
+ ins->real_in = in;
+ return &ins->stream;
}
enum {
@@ -401,10 +401,12 @@ gu_data_in_begin_buffer(GuInStream* self, size_t* sz_out, GuExn* err)
GuIn*
gu_data_in(const uint8_t* data, size_t sz, GuPool* pool)
{
- GuDataIn* di = gu_new_s(pool, GuDataIn,
- .stream.begin_buffer = gu_data_in_begin_buffer,
- .data = data,
- .sz = sz);
+ GuDataIn* di = gu_new(GuDataIn, pool);
+ di->stream.begin_buffer = gu_data_in_begin_buffer;
+ di->stream.end_buffer = NULL;
+ di->stream.input = NULL;
+ di->data = data;
+ di->sz = sz;
return gu_new_in(&di->stream, pool);
}
diff --git a/src/runtime/c/gu/map.c b/src/runtime/c/gu/map.c
index cc3b7e829..6505953af 100644
--- a/src/runtime/c/gu/map.c
+++ b/src/runtime/c/gu/map.c
@@ -23,10 +23,10 @@ struct GuMapData {
};
struct GuMap {
- GuMapKind const kind;
- GuHasher* const hasher;
- size_t const key_size;
- size_t const value_size;
+ GuMapKind kind;
+ GuHasher* hasher;
+ size_t key_size;
+ size_t value_size;
const void* default_value;
GuMapData data;
@@ -380,16 +380,14 @@ gu_make_map(size_t key_size, GuHasher* hasher,
.values = value_size ? NULL : (uint8_t*) gu_map_no_values,
.zero_idx = SIZE_MAX
};
- GuMap* map = gu_new_i(
- pool, GuMap,
- .default_value = default_value,
- .hasher = hasher,
- .data = data,
- .key_size = key_size,
- .value_size = value_size,
- .fin.fn = gu_map_finalize,
- .kind = kind
- );
+ GuMap* map = gu_new(GuMap, pool);
+ map->default_value = default_value;
+ map->hasher = hasher;
+ map->data = data;
+ map->key_size = key_size;
+ map->value_size = value_size;
+ map->fin.fn = gu_map_finalize;
+ map->kind = kind;
gu_pool_finally(pool, &map->fin);
gu_map_resize(map);
return map;
diff --git a/src/runtime/c/gu/mem.c b/src/runtime/c/gu/mem.c
index bc3010790..ae355e5b6 100644
--- a/src/runtime/c/gu/mem.c
+++ b/src/runtime/c/gu/mem.c
@@ -339,8 +339,3 @@ gu_pool_free(GuPool* pool)
extern inline void* gu_malloc(GuPool* pool, size_t size);
-
-extern inline void*
-gu_malloc_init_aligned(GuPool* pool, size_t size, size_t alignment,
- const void* init);
-
diff --git a/src/runtime/c/gu/mem.h b/src/runtime/c/gu/mem.h
index e389bcc0c..e52e14968 100644
--- a/src/runtime/c/gu/mem.h
+++ b/src/runtime/c/gu/mem.h
@@ -112,24 +112,6 @@ gu_malloc(GuPool* pool, size_t size) {
#include <string.h>
-//@private
-static inline void*
-gu_malloc_init_aligned(GuPool* pool, size_t size, size_t alignment,
- const void* init)
-{
- void* p = gu_malloc_aligned(pool, size, alignment);
- memcpy(p, init, size);
- return p;
-}
-
-//@private
-static inline void*
-gu_malloc_init(GuPool* pool, size_t size, const void* init)
-{
- return gu_malloc_init_aligned(pool, size, 0, init);
-}
-
-
/** Allocate memory to store an array of objects of a given type. */
#define gu_new_n(type, n, pool) \
@@ -167,38 +149,6 @@ gu_malloc_init(GuPool* pool, size_t size, const void* init)
gu_alignof(pre_type), sizeof(pre_type), \
gu_alignof(type), sizeof(type))))
-
-
-
-
-#ifdef HAVE_STATEMENT_EXPRESSIONS
-#define gu_new_i(pool, type, ...) \
- ({ \
- type *gu_new_p_ = gu_new(type, pool); \
- memcpy((void*) gu_new_p_, &(type){ __VA_ARGS__ }, \
- sizeof(type)); \
- gu_new_p_; \
- })
-#else // HAVE_STATEMENT_EXPRESSIONS
-#define gu_new_i(pool, type, ...) \
- ((type*)gu_malloc_init_aligned((pool), sizeof(type), \
- gu_alignof(type), \
- &(type){ __VA_ARGS__ }))
-#endif // HAVE_STATEMENT_EXPRESSIONS
-
-/** @def gu_new_i(pool, type, ...)
- *
- * Allocate and initialize an object.
- *
- * @param pool The pool to allocate from.
- *
- * @param type The C type of the object to allocate.
- *
- * @param ... An initializer list for the object to allocate.
- */
-
-#define gu_new_s gu_new_i
-
// Alas, there's no portable way to get the alignment of flex structs.
#define gu_new_flex(pool_, type_, flex_member_, n_elems_) \
((type_ *)gu_malloc_aligned( \
diff --git a/src/runtime/c/gu/out.c b/src/runtime/c/gu/out.c
index 61df2c184..ab937c4a7 100644
--- a/src/runtime/c/gu/out.c
+++ b/src/runtime/c/gu/out.c
@@ -236,12 +236,13 @@ gu_proxy_out_flush(GuOutStream* self, GuExn* err)
GuOutStream*
gu_out_proxy_stream(GuOut* out, GuPool* pool)
{
- return &gu_new_s(pool, GuProxyOutStream,
- .stream.begin_buf = gu_proxy_out_buf_begin,
- .stream.end_buf = gu_proxy_out_buf_end,
- .stream.output = gu_proxy_out_output,
- .stream.flush = gu_proxy_out_flush,
- .real_out = out)->stream;
+ GuProxyOutStream* pos = gu_new(GuProxyOutStream, pool);
+ pos->stream.begin_buf = gu_proxy_out_buf_begin;
+ pos->stream.end_buf = gu_proxy_out_buf_end;
+ pos->stream.output = gu_proxy_out_output;
+ pos->stream.flush = gu_proxy_out_flush;
+ pos->real_out = out;
+ return &pos->stream;
}
diff --git a/src/runtime/c/gu/string.c b/src/runtime/c/gu/string.c
index 6f91e0a27..1a53c3a28 100644
--- a/src/runtime/c/gu/string.c
+++ b/src/runtime/c/gu/string.c
@@ -20,9 +20,10 @@ gu_string_buf(GuPool* pool)
GuBuf* buf = gu_new_buf(uint8_t, pool);
GuOut* out = gu_buf_out(buf, pool);
GuWriter* wtr = gu_new_utf8_writer(out, pool);
- return gu_new_s(pool, GuStringBuf,
- .bbuf = buf,
- .wtr = wtr);
+ GuStringBuf* sbuf = gu_new(GuStringBuf, pool);
+ sbuf->bbuf = buf;
+ sbuf->wtr = wtr;
+ return sbuf;
}
GuWriter*
diff --git a/src/runtime/c/gu/type.c b/src/runtime/c/gu/type.c
index 13fbfa42d..26260a614 100644
--- a/src/runtime/c/gu/type.c
+++ b/src/runtime/c/gu/type.c
@@ -98,9 +98,8 @@ gu_type_map_init(GuTypeMap* tmap, GuTypeTable* table)
GuTypeMap*
gu_new_type_map(GuTypeTable* table, GuPool* pool)
{
- GuTypeMap* tmap =
- gu_new_i(pool, GuTypeMap,
- .map = gu_new_map(GuKind, NULL, void*, &gu_null, pool));
+ GuTypeMap* tmap = gu_new(GuTypeMap, pool);
+ tmap->map = gu_new_map(GuKind, NULL, void*, &gu_null, pool);
gu_type_map_init(tmap, table);
return tmap;
}
diff --git a/src/runtime/c/gu/write.c b/src/runtime/c/gu/write.c
index 69573fb0d..bd3e136fb 100644
--- a/src/runtime/c/gu/write.c
+++ b/src/runtime/c/gu/write.c
@@ -36,127 +36,6 @@ gu_new_utf8_writer(GuOut* utf8_out, GuPool* pool)
return wtr;
}
-
-#if 0
-#ifdef GU_UCS_WCHAR
-#include <stdlib.h>
-#include <wchar.h>
-static const mbstate_t gu_init_mbstate; // implicitly initialized to zero
-#endif
-
-typedef struct GuLocaleWriter GuLocaleWriter;
-
-struct GuLocaleWriter {
- GuOutWriter owtr;
-#ifdef GU_UCS_WCHAR
- mbstate_t ps;
- size_t mb_cur_max;
-#endif
-};
-
-size_t
-gu_locale_writer_write(GuWriter* wtr, const uint8_t* utf8_src, size_t sz,
- GuExn* err)
-{
- GuLocaleWriter* lwtr = (GuLocaleWriter*) wtr;
- size_t done = 0;
- static const size_t bufsize = 256;
-#ifdef GU_UCS_WCHAR
- size_t margin = lwtr->mb_cur_max;
-#else
- size_t margin = 1;
-#endif
- GuOut* out = lwtr->owtr.out;
- if (gu_out_is_buffered(out)) {
- while (done < sz) {
- size_t dst_sz;
- uint8_t* dst = gu_out_begin_span(out, &dst_sz);
- if (!dst) {
- break;
- }
- if (dst_sz <= margin) {
- gu_out_end_span(out, 0);
- break;
- }
- size_t end = dst_sz - margin;
- const uint8_t*
- size_t n = done;
- while (n < sz && dst_i <= end) {
-#ifdef GU_UCS_WCHAR
- GuUCS ucs = gu_
- wchar_t wc = src[n];
- size_t nb = wcrtomb((char*) p, wc, &lwtr->ps);
-#else
- *p = (uint8_t) gu_ucs_char(buf[n], err);
- size_t nb = 1;
- if (!gu_ok(err)) {
- gu_exn_clear(err);
- nb = (size_t) -1;
- }
-#endif
- if (nb == (size_t) -1) {
- *p++ = (uint8_t) '?';
- } else {
- p += nb;
- }
-
- }
- for (
-
- }
-
-
-
- }
-
- uint8_t cbuf[256];
- while (done < size && gu_ok(err)) {
- uint8_t* p = cbuf;
- uint8_t* edge = &cbuf[bufsize - margin];
- size_t n;
- for (n = done; p <= edge && n < size; n++) {
-#ifdef GU_UCS_WCHAR
- wchar_t wc = buf[n];
- size_t nb = wcrtomb((char*) p, wc, &lwtr->ps);
-#else
- *p = (uint8_t) gu_ucs_char(buf[n], err);
- size_t nb = 1;
- if (!gu_ok(err)) {
- gu_exn_clear(err);
- nb = (size_t) -1;
- }
-#endif
- if (nb == (size_t) -1) {
- *p++ = (uint8_t) '?';
- } else {
- p += nb;
- }
- }
- gu_out_bytes(lwtr->owtr.out, cbuf, p - cbuf, err);
- if (gu_ok(err)) {
- done = n;
- }
- }
- return done;
-}
-
-GuWriter*
-gu_locale_writer(GuOut* out, GuPool* pool)
-{
- GuLocaleWriter* lwtr = gu_new_s(
- pool, GuLocaleWriter,
- .wtr.out.output = gu_locale_writer_output,
- .wtr.out.flush = gu_locale_writer_flush,
- .out = out);
-#ifdef GU_UCS_WCHAR
- lwtr->ps = gu_init_mbstate;
- lwtr->mb_cur_max = MB_CUR_MAX;
-#endif
- return (GuWriter*) lwtr;
-}
-
-#endif
-
extern inline void
gu_ucs_write(GuUCS ucs, GuWriter* wtr, GuExn* err);
diff --git a/src/runtime/c/m4/c_ext.m4 b/src/runtime/c/m4/c_ext.m4
index 7c35c7dc3..596e23782 100644
--- a/src/runtime/c/m4/c_ext.m4
+++ b/src/runtime/c/m4/c_ext.m4
@@ -41,22 +41,6 @@ AC_DEFUN([AC_C_FAM_IN_MEM],
fi
])
-
-## AC_C_STATEMENT_EXPRESSIONS
-AC_DEFUN([AC_C_STATEMENT_EXPRESSIONS],
-[
- AC_CACHE_CHECK([for statement expressions],
- ac_cv_c_statement_expressions,
- [AC_COMPILE_IFELSE(
- [AC_LANG_PROGRAM([], [int x = ({ int a = 42; a = a + 1; a; })])],
- [ac_cv_c_statement_expressions=yes],
- [ac_cv_c_statement_expressions=no])])
- if test $ac_cv_c_statement_expressions = yes; then
- AC_DEFINE([HAVE_STATEMENT_EXPRESSIONS], 1,
- [Define to 1 if statement expressions are supported.])
- fi
-])
-
## AC_C_ASCII
AC_DEFUN([AC_C_ASCII],
[
diff --git a/src/runtime/c/pgf/parser.c b/src/runtime/c/pgf/parser.c
index 0cf588aa1..7ca9babd8 100644
--- a/src/runtime/c/pgf/parser.c
+++ b/src/runtime/c/pgf/parser.c
@@ -2195,12 +2195,10 @@ pgf_parse_result(PgfParseState* state)
pgf_parsing_print_counts(state->ps);
#endif
- PgfExprEnum* en =
- &gu_new_i(state->ps->pool, PgfParseResult,
- .state = state,
- .en.next = pgf_parse_result_enum_next)->en;
-
- return en;
+ PgfParseResult* res = gu_new(PgfParseResult, state->ps->pool);
+ res->state = state;
+ res->en.next = pgf_parse_result_enum_next;
+ return &res->en;
}
void
diff --git a/src/runtime/c/pgf/reader.c b/src/runtime/c/pgf/reader.c
index f58809ef5..36eebee43 100644
--- a/src/runtime/c/pgf/reader.c
+++ b/src/runtime/c/pgf/reader.c
@@ -76,8 +76,14 @@ pgf_read_len(PgfReader* rdr)
// immediately.
gu_return_on_exn(rdr->err, 0);
if (len < 0) {
- gu_raise_i(rdr->err, PgfReadTagExn,
- .type = gu_type(GuLength), .tag = len);
+ GuExnData* err_data = gu_raise(rdr->err, PgfReadTagExn);
+ if (err_data) {
+ PgfReadTagExn* rtag = gu_new(PgfReadTagExn, err_data->pool);
+ rtag->type = gu_type(GuLength);
+ rtag->tag = len;
+ err_data->data = rtag;
+ }
+
return 0;
}
return (GuLength) len;