diff --git a/README.md b/README.md
index f258f1b..329f9a5 100644
--- a/README.md
+++ b/README.md
@@ -44,16 +44,19 @@ Script interpreter.
## TODO
- libc3
- - atomic operations
- - DONE triple serial id
- - with ignore variables
+ - facts
+ - atomic operations
+ - DONE triple serial id
+ - negative facts : 4 + 2n = not 3 + 2n
+ - with ignore variables
+ - math
+ - floating point numbers
- boolean operators
- comparison operators
- arrays
- lists
- defmodule
- structs
- - negative facts : 4 + 2n = not 3 + 2n
- errors (setjmp, longjmp)
- stacktrace
- ffi ?
diff --git a/c3s/configure b/c3s/configure
index 94cde47..88dc913 100755
--- a/c3s/configure
+++ b/c3s/configure
@@ -42,7 +42,8 @@ echo "OBJECTS_DEBUG = $OBJECTS_DEBUG" >> ${CONFIG_MK}
CPPFLAGS="${CPPFLAGS:=}"
ENV_CFLAGS="${CFLAGS:=}"
DEFAULT_CFLAGS="-O2 -pipe -fPIC"
-LDFLAGS="-Wl,--allow-shlib-undefined ${LDFLAGS:=}"
+#LDFLAGS="-Wl,--allow-shlib-undefined ${LDFLAGS:=}"
+LDFLAGS="${LDFLAGS:=}"
LIBS="${LIBS:=-lm}"
# Common config for all targets
diff --git a/ic3/configure b/ic3/configure
index 12b955d..1044319 100755
--- a/ic3/configure
+++ b/ic3/configure
@@ -42,7 +42,8 @@ echo "OBJECTS_DEBUG = $OBJECTS_DEBUG" >> ${CONFIG_MK}
CPPFLAGS="${CPPFLAGS:=}"
ENV_CFLAGS="${CFLAGS:=}"
DEFAULT_CFLAGS="-O2 -pipe -fPIC"
-LDFLAGS="-Wl,--allow-shlib-undefined ${LDFLAGS:-}"
+#LDFLAGS="-Wl,--allow-shlib-undefined ${LDFLAGS:-}"
+LDFLAGS="${LDFLAGS:-}"
LIBS="${LIBS:=-lm}"
# Common config for all targets
diff --git a/libc3/buf.h b/libc3/buf.h
index c71019e..1258819 100644
--- a/libc3/buf.h
+++ b/libc3/buf.h
@@ -29,21 +29,19 @@
extern const sw buf_u8_to_hex_size;
-/* Stack constructors, call buf_clean after use. */
+/* Stack-allocation compatible functions, call buf_clean after use. */
+void buf_clean (s_buf *buf);
s_buf * buf_init (s_buf *buf, bool free, uw size, s8 *p);
s_buf * buf_init_1 (s_buf *buf, const s8 *p);
s_buf * buf_init_alloc (s_buf *buf, uw size);
s_buf * buf_init_str (s_buf *buf, const s_str *src);
-/* Constructors, call buf_delete after use. */
+/* Heap-allocation compatible functions, call buf_delete after use. */
+void buf_delete (s_buf *buf);
s_buf * buf_new (bool free, uw size, s8 *p);
s_buf * buf_new_alloc (uw bytes);
s_buf * buf_new_str (s_str *str);
-/* Destructors */
-void buf_clean (s_buf *buf);
-void buf_delete (s_buf *buf);
-
/* Modifiers */
sw buf_f (s_buf *buf, const char *fmt, ...);
sw buf_flush (s_buf *buf);
diff --git a/libc3/buf_inspect.c b/libc3/buf_inspect.c
index 22e363c..11548cf 100644
--- a/libc3/buf_inspect.c
+++ b/libc3/buf_inspect.c
@@ -242,6 +242,9 @@ f_buf_inspect buf_inspect (e_tag_type type)
case TAG_VAR:
return (f_buf_inspect) buf_inspect_var;
}
+ assert(! "buf_inspect: unknown tag type");
+ errx(1, "buf_inspect: unknown tag type");
+ return NULL;
}
sw buf_inspect_array (s_buf *buf, const s_array *a)
diff --git a/libc3/float.h b/libc3/float.h
new file mode 100644
index 0000000..6200085
--- /dev/null
+++ b/libc3/float.h
@@ -0,0 +1,43 @@
+/* c3
+ * Copyright 2022,2023 kmx.io <contact@kmx.io>
+ *
+ * Permission is hereby granted to use this software granted the above
+ * copyright notice and this permission paragraph are included in all
+ * copies and substantial portions of this software.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS-IS" WITHOUT ANY GUARANTEE OF
+ * PURPOSE AND PERFORMANCE. IN NO EVENT WHATSOEVER SHALL THE
+ * AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
+ * THIS SOFTWARE.
+ */
+/**
+ * @file float.h
+ * @brief Floating point numbers operations.
+ *
+ * Structure to manipulate floating point numbers.
+ */
+#ifndef FLOAT_H
+#define FLOAT_H
+
+#include "types.h"
+
+/* Stack-allocation compatible functions */
+s_float * float_init (s_float *f);
+s_float * float_init_1 (s_float *f, const s8 *s);
+s_float * float_init_sw (s_float *f, sw integer, sw bitshift);
+
+/* Heap-allocation compatible functions, call float_delete after use */
+void float_delete (s_float *f);
+s_float * float_new (s_float *f);
+s_float * float_new_1 (s_float *f, const s8 *s);
+s_float * float_new_sw (s_float *f, sw integer, sw bitshift);
+
+/* Modifiers */
+s_float * float_add (s_float *a, s_float *b);
+s_float * float_mul (s_float *a, s_float *b);
+s_float * float_neg (s_float *f);
+s_float * float_sq (s_float *f);
+s_float * float_sqrt (s_float *f);
+s_float * float_sub (s_float *a, s_float *b);
+
+#endif /* FLOAT_H */
diff --git a/libc3/real.c b/libc3/real.c
deleted file mode 100644
index 40631cf..0000000
--- a/libc3/real.c
+++ /dev/null
@@ -1,24 +0,0 @@
-/* c3
- * Copyright 2022,2023 kmx.io <contact@kmx.io>
- *
- * Permission is hereby granted to use this software granted the above
- * copyright notice and this permission paragraph are included in all
- * copies and substantial portions of this software.
- *
- * THIS SOFTWARE IS PROVIDED "AS-IS" WITHOUT ANY GUARANTEE OF
- * PURPOSE AND PERFORMANCE. IN NO EVENT WHATSOEVER SHALL THE
- * AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
- * THIS SOFTWARE.
- */
-#include "real.h"
-
-typedef struct real s_real;
-
-struct real {
- s_integer i;
- s_integer exponent;
-};
-
-/*
-typedef sw real[2][];
-*/
diff --git a/libc3/sources.mk b/libc3/sources.mk
index 2792a80..f2e0d2e 100644
--- a/libc3/sources.mk
+++ b/libc3/sources.mk
@@ -30,6 +30,7 @@ HEADERS = \
facts_spec_cursor.h \
facts_with.h \
facts_with_cursor.h \
+ float.h \
fn.h \
frame.h \
hash.h \
diff --git a/libc3/sources.sh b/libc3/sources.sh
index e2be60c..811c356 100644
--- a/libc3/sources.sh
+++ b/libc3/sources.sh
@@ -1,4 +1,4 @@
# sources.sh generated by update_sources
-HEADERS='abs.h arg.h array.h binding.h bool.h buf.h buf_file.h buf_inspect.h buf_parse.h buf_parse_c.h buf_save.h c3.h c_types.h call.h ceiling.h cfn.h character.h compare.h config.h env.h error.h error_handler.h eval.h fact.h facts.h facts_cursor.h facts_spec.h facts_spec_cursor.h facts_with.h facts_with_cursor.h fn.h frame.h hash.h ident.h integer.h io.h list.h log.h module.h operator.h quote.h set__fact.h set__tag.h set_cursor__fact.h set_cursor__tag.h set_item__fact.h set_item__tag.h sha1.h sign.h skiplist__fact.h skiplist_node__fact.h str.h sym.h tag.h tuple.h types.h ucd.h '
+HEADERS='abs.h arg.h array.h binding.h bool.h buf.h buf_file.h buf_inspect.h buf_parse.h buf_parse_c.h buf_save.h c3.h c_types.h call.h ceiling.h cfn.h character.h compare.h config.h env.h error.h error_handler.h eval.h fact.h facts.h facts_cursor.h facts_spec.h facts_spec_cursor.h facts_with.h facts_with_cursor.h float.h fn.h frame.h hash.h ident.h integer.h io.h list.h log.h module.h operator.h quote.h set__fact.h set__tag.h set_cursor__fact.h set_cursor__tag.h set_item__fact.h set_item__tag.h sha1.h sign.h skiplist__fact.h skiplist_node__fact.h str.h sym.h tag.h tuple.h types.h ucd.h '
SOURCES='abs.c arg.c array.c binding.c bool.c buf.c buf_file.c buf_inspect.c buf_parse.c buf_parse_c.c buf_save.c c3.c call.c ceiling.c cfn.c character.c compare.c env.c error.c error_handler.c eval.c fact.c facts.c facts_cursor.c facts_spec.c facts_spec_cursor.c facts_with.c facts_with_cursor.c fn.c frame.c hash.c ident.c integer.c io.c list.c log.c module.c operator.c quote.c set__fact.c set__tag.c set_cursor__fact.c set_cursor__tag.c set_item__fact.c set_item__tag.c sign.c skiplist__fact.c skiplist_node__fact.c str.c sym.c tag.c tuple.c ucd.c '
LO_SOURCES='abs.c arg.c array.c binding.c bool.c buf.c buf_file.c buf_inspect.c buf_parse.c buf_parse_c.c buf_save.c c3.c call.c ceiling.c cfn.c character.c compare.c env.c error.c error_handler.c eval.c fact.c facts.c facts_cursor.c facts_spec.c facts_spec_cursor.c facts_with.c facts_with_cursor.c fn.c frame.c hash.c ident.c integer.c io.c list.c log.c module.c operator.c quote.c set__fact.c set__tag.c set_cursor__fact.c set_cursor__tag.c set_item__fact.c set_item__tag.c sign.c skiplist__fact.c skiplist_node__fact.c str.c sym.c tag.c tuple.c ucd.c ../libtommath/bn_cutoffs.c ../libtommath/bn_mp_2expt.c ../libtommath/bn_mp_abs.c ../libtommath/bn_mp_add.c ../libtommath/bn_mp_add_d.c ../libtommath/bn_mp_and.c ../libtommath/bn_mp_clamp.c ../libtommath/bn_mp_clear.c ../libtommath/bn_mp_clear_multi.c ../libtommath/bn_mp_cmp.c ../libtommath/bn_mp_cmp_d.c ../libtommath/bn_mp_cmp_mag.c ../libtommath/bn_mp_cnt_lsb.c ../libtommath/bn_mp_complement.c ../libtommath/bn_mp_copy.c ../libtommath/bn_mp_count_bits.c ../libtommath/bn_mp_div.c ../libtommath/bn_mp_div_2.c ../libtommath/bn_mp_div_2d.c ../libtommath/bn_mp_div_3.c ../libtommath/bn_mp_div_d.c ../libtommath/bn_mp_dr_is_modulus.c ../libtommath/bn_mp_dr_reduce.c ../libtommath/bn_mp_dr_setup.c ../libtommath/bn_mp_error_to_string.c ../libtommath/bn_mp_exch.c ../libtommath/bn_mp_exptmod.c ../libtommath/bn_mp_gcd.c ../libtommath/bn_mp_get_i32.c ../libtommath/bn_mp_get_i64.c ../libtommath/bn_mp_get_mag_u32.c ../libtommath/bn_mp_get_mag_u64.c ../libtommath/bn_mp_grow.c ../libtommath/bn_mp_init.c ../libtommath/bn_mp_init_copy.c ../libtommath/bn_mp_init_multi.c ../libtommath/bn_mp_init_size.c ../libtommath/bn_mp_invmod.c ../libtommath/bn_mp_lcm.c ../libtommath/bn_mp_lshd.c ../libtommath/bn_mp_mod.c ../libtommath/bn_mp_mod_2d.c ../libtommath/bn_mp_montgomery_calc_normalization.c ../libtommath/bn_mp_montgomery_reduce.c ../libtommath/bn_mp_montgomery_setup.c ../libtommath/bn_mp_mul.c ../libtommath/bn_mp_mul_2.c ../libtommath/bn_mp_mul_2d.c ../libtommath/bn_mp_mul_d.c ../libtommath/bn_mp_mulmod.c ../libtommath/bn_mp_neg.c ../libtommath/bn_mp_or.c ../libtommath/bn_mp_radix_size.c ../libtommath/bn_mp_reduce.c ../libtommath/bn_mp_reduce_2k.c ../libtommath/bn_mp_reduce_2k_l.c ../libtommath/bn_mp_reduce_2k_setup.c ../libtommath/bn_mp_reduce_2k_setup_l.c ../libtommath/bn_mp_reduce_is_2k.c ../libtommath/bn_mp_reduce_is_2k_l.c ../libtommath/bn_mp_reduce_setup.c ../libtommath/bn_mp_rshd.c ../libtommath/bn_mp_set.c ../libtommath/bn_mp_sqr.c ../libtommath/bn_mp_sqrt.c ../libtommath/bn_mp_sub.c ../libtommath/bn_mp_sub_d.c ../libtommath/bn_mp_xor.c ../libtommath/bn_mp_zero.c ../libtommath/bn_s_mp_add.c ../libtommath/bn_s_mp_balance_mul.c ../libtommath/bn_s_mp_exptmod.c ../libtommath/bn_s_mp_exptmod_fast.c ../libtommath/bn_s_mp_invmod_fast.c ../libtommath/bn_s_mp_invmod_slow.c ../libtommath/bn_s_mp_karatsuba_mul.c ../libtommath/bn_s_mp_karatsuba_sqr.c ../libtommath/bn_s_mp_montgomery_reduce_fast.c ../libtommath/bn_s_mp_mul_digs.c ../libtommath/bn_s_mp_mul_digs_fast.c ../libtommath/bn_s_mp_mul_high_digs.c ../libtommath/bn_s_mp_mul_high_digs_fast.c ../libtommath/bn_s_mp_rand_platform.c ../libtommath/bn_s_mp_sqr.c ../libtommath/bn_s_mp_sqr_fast.c ../libtommath/bn_s_mp_sub.c ../libtommath/bn_s_mp_toom_mul.c ../libtommath/bn_s_mp_toom_sqr.c '
diff --git a/libc3/types.h b/libc3/types.h
index dcc2da9..5598a1a 100644
--- a/libc3/types.h
+++ b/libc3/types.h
@@ -115,6 +115,7 @@ typedef struct facts_cursor s_facts_cursor;
typedef struct facts_spec_cursor s_facts_spec_cursor;
typedef struct facts_with_cursor s_facts_with_cursor;
typedef struct facts_with_cursor_level s_facts_with_cursor_level;
+typedef struct float_ s_float;
typedef struct fn s_fn;
typedef struct frame s_frame;
typedef struct ident s_ident;
@@ -179,6 +180,11 @@ struct fact_w {
uw id; /* serial id */
};
+struct float_ {
+ sw integer;
+ sw bit_shift;
+};
+
struct frame {
s_binding *bindings;
s_frame *next;
diff --git a/sources.mk b/sources.mk
index 57455fa..74eb54e 100644
--- a/sources.mk
+++ b/sources.mk
@@ -9,8 +9,8 @@ C3_CONFIGURES = \
libc3/update_sources \
libtommath/configure \
libtommath/update_sources \
- test/configure \
test/update_sources \
+ test/configure \
ucd2c/configure \
C3_MAKEFILES = \
@@ -29,159 +29,170 @@ C3_C_SOURCES = \
c3s/c3s.c \
c3s/buf_readline.h \
ic3/buf_linenoise.c \
- ic3/buf_linenoise.h \
ic3/ic3.c \
+ ic3/buf_linenoise.h \
ic3/linenoise.c \
libc3/arg.c \
libc3/arg.h \
- libc3/binding.c \
- libc3/binding.h \
- libc3/bool.c \
- libc3/bool.h \
- libc3/set_item__tag.c \
- libc3/skiplist_node__fact.c \
+ libc3/set__fact.c \
+ libc3/set__fact.h \
libc3/set__tag.c \
- libc3/set_item__tag.h \
libc3/set__tag.h \
- libc3/set_cursor__tag.h \
+ libc3/set_cursor__fact.c \
+ libc3/set_cursor__fact.h \
libc3/set_cursor__tag.c \
+ libc3/set_cursor__tag.h \
+ libc3/binding.c \
+ libc3/binding.h \
+ libc3/facts.c \
+ libc3/facts_with_cursor.c \
+ libc3/array.c \
+ libc3/array.h \
libc3/buf.c \
- libc3/buf.h \
libc3/buf_file.c \
libc3/buf_file.h \
+ libc3/bool.c \
+ libc3/io.h \
+ libc3/io.c \
+ libc3/buf_parse.c \
+ libc3/abs.h \
+ libc3/ceiling.c \
libc3/buf_parse_c.c \
libc3/buf_parse_c.h \
libc3/buf_save.c \
- libc3/log.h \
- libc3/skiplist_node__fact.h \
+ libc3/buf_parse.h \
+ libc3/compare.c \
+ libc3/buf_inspect.c \
+ libc3/set_item__fact.c \
+ libc3/set_item__fact.h \
+ libc3/set_item__tag.c \
+ libc3/set_item__tag.h \
libc3/skiplist__fact.c \
libc3/skiplist__fact.h \
- libc3/set_item__fact.h \
- libc3/set_item__fact.c \
- libc3/set__fact.h \
- libc3/set__fact.c \
- libc3/set_cursor__fact.h \
- libc3/compare.h \
- libc3/buf_save.h \
- libc3/env.c \
- libc3/env.h \
- libc3/c_types.h \
+ libc3/skiplist_node__fact.c \
+ libc3/skiplist_node__fact.h \
libc3/call.c \
- libc3/call.h \
- libc3/log.c \
- libc3/array.h \
+ libc3/bool.h \
+ libc3/buf_save.h \
+ libc3/fact.h \
libc3/error.c \
+ libc3/list.h \
+ libc3/c3.c \
+ libc3/c3.h \
libc3/error.h \
+ libc3/env.h \
+ libc3/character.h \
+ libc3/compare.h \
+ libc3/operator.h \
+ libc3/operator.c \
+ libc3/tag.h \
+ libc3/sign.h \
+ libc3/buf.h \
+ libc3/ident.c \
libc3/error_handler.c \
+ libc3/frame.c \
+ libc3/set_cursor.c.in \
+ libc3/set_cursor.h.in \
+ libc3/set_item.c.in \
+ libc3/set_item.h.in \
libc3/error_handler.h \
- libc3/io.c \
- libc3/io.h \
- libc3/fact.h \
- libc3/character.c \
- libc3/array.c \
+ libc3/eval.c \
+ libc3/eval.h \
+ libc3/fact.c \
libc3/facts.h \
libc3/facts_cursor.c \
+ libc3/fn.h \
+ libc3/ceiling.h \
+ libc3/buf_inspect.h \
+ libc3/env.c \
libc3/facts_cursor.h \
libc3/facts_spec.c \
+ libc3/frame.h \
+ libc3/sign.c \
libc3/facts_spec.h \
libc3/facts_spec_cursor.c \
+ libc3/hash.c \
libc3/facts_spec_cursor.h \
- libc3/character.h \
- libc3/set_cursor__fact.c \
libc3/facts_with.c \
libc3/facts_with.h \
- libc3/facts_with_cursor.c \
- libc3/facts_with_cursor.h \
- libc3/fn.c \
- libc3/fn.h \
- libc3/frame.c \
- libc3/frame.h \
- libc3/hash.c \
libc3/hash.h \
- libc3/ident.c \
+ libc3/cfn.h \
+ libc3/tag.c \
+ libc3/abs.c \
+ libc3/facts_with_cursor.h \
libc3/ident.h \
- libc3/abs.h \
+ libc3/str.c \
+ libc3/c_types.h \
libc3/integer.c \
- libc3/integer.h \
libc3/list.c \
- libc3/list.h \
- libc3/module.h \
+ libc3/log.c \
+ libc3/log.h \
+ libc3/sym.h \
+ libc3/module.c \
libc3/quote.c \
libc3/quote.h \
+ libc3/integer.h \
+ libc3/character.c \
libc3/types.h \
- libc3/eval.h \
libc3/cfn.c \
- libc3/sign.h \
+ libc3/fn.c \
+ libc3/module.h \
libc3/set.c.in \
+ libc3/call.h \
libc3/set.h.in \
- libc3/set_cursor.c.in \
- libc3/set_cursor.h.in \
- libc3/str.c \
- libc3/eval.c \
- libc3/buf_inspect.h \
- libc3/ceiling.h \
- libc3/ceiling.c \
- libc3/set_item.c.in \
- libc3/set_item.h.in \
- libc3/fact.c \
+ libc3/sha1.h \
libc3/skiplist.c.in \
- libc3/operator.c \
- libc3/operator.h \
- libc3/buf_parse.c \
- libc3/abs.c \
libc3/skiplist.h.in \
libc3/skiplist_node.c.in \
libc3/skiplist_node.h.in \
libc3/str.h \
libc3/sym.c \
- libc3/sym.h \
- libc3/c3.h \
- libc3/facts.c \
- libc3/buf_inspect.c \
- libc3/buf_parse.h \
libc3/tuple.c \
libc3/tuple.h \
libc3/ucd.c \
libc3/ucd.h \
- libc3/c3.c \
- libc3/tag.h \
- libc3/module.c \
- libc3/tag.c \
- libc3/compare.c \
- libc3/cfn.h \
- libc3/sign.c \
- libc3/sha1.h \
- test/bool_test.c \
- test/buf_file_test.c \
- test/buf_inspect_test.c \
- test/buf_parse_test.c \
- test/buf_test.c \
- test/call_test.c \
- test/character_test.c \
- test/hash_test.c \
- test/fact_test.c \
- test/fact_test.h \
+ libc3/float.h \
test/facts_cursor_test.c \
test/facts_test.c \
test/facts_with_test.c \
- test/ident_test.c \
- test/env_test.c \
- test/libc3_test.c \
- test/tuple_test.c \
- test/list_test.c \
test/set__fact_test.c \
test/set__tag_test.c \
- test/compare_test.h \
- test/skiplist__fact_test.c \
- test/str_test.c \
- test/cfn_test.c \
test/test.c \
- test/test.h \
- test/sym_test.c \
test/tag_test.c \
+ test/sym_test.c \
test/tag_test.h \
+ test/tuple_test.c \
test/types_test.c \
+ test/skiplist__fact_test.c \
+ test/fact_test.c \
+ test/compare_test.h \
+ test/fact_test.h \
+ test/str_test.c \
+ test/list_test.c \
+ test/hash_test.c \
test/compare_test.c \
+ test/call_test.c \
+ test/ident_test.c \
+ test/libc3_test.c \
+ test/buf_inspect_test.c \
+ test/test.h \
+ test/bool_test.c \
+ test/cfn_test.c \
+ test/buf_parse_test.c \
+ test/buf_parse_test_s8.c \
+ test/buf_parse_test_s32.c \
+ test/buf_parse_test_s64.c \
+ test/buf_parse_test_u16.c \
+ test/buf_parse_test_u8.c \
+ test/buf_parse_test_u32.c \
+ test/buf_parse_test_u64.c \
+ test/buf_parse_test.h \
+ test/buf_test.c \
+ test/env_test.c \
+ test/buf_parse_test_su.h \
+ test/character_test.c \
+ test/buf_parse_test_s16.c \
+ test/buf_file_test.c \
ucd2c/ucd.h \
ucd2c/ucd2c.c \
diff --git a/sources.sh b/sources.sh
index 4b30810..afd3ca4 100644
--- a/sources.sh
+++ b/sources.sh
@@ -1,4 +1,4 @@
# sources.sh generated by update_sources
-C3_CONFIGURES='c3c/configure c3s/configure c3s/update_sources ic3/configure ic3/update_sources libc3/configure libc3/update_sources libtommath/configure libtommath/update_sources test/configure test/update_sources ucd2c/configure '
+C3_CONFIGURES='c3c/configure c3s/configure c3s/update_sources ic3/configure ic3/update_sources libc3/configure libc3/update_sources libtommath/configure libtommath/update_sources test/update_sources test/configure ucd2c/configure '
C3_MAKEFILES='c3c/Makefile c3s/Makefile ic3/Makefile libc3/Makefile libc3/gen.mk libtommath/Makefile test/Makefile ucd2c/Makefile '
-C3_C_SOURCES='c3c/c3c.c c3s/buf_readline.c c3s/c3s.c c3s/buf_readline.h ic3/buf_linenoise.c ic3/buf_linenoise.h ic3/ic3.c ic3/linenoise.c libc3/arg.c libc3/arg.h libc3/binding.c libc3/binding.h libc3/bool.c libc3/bool.h libc3/set_item__tag.c libc3/skiplist_node__fact.c libc3/set__tag.c libc3/set_item__tag.h libc3/set__tag.h libc3/set_cursor__tag.h libc3/set_cursor__tag.c libc3/buf.c libc3/buf.h libc3/buf_file.c libc3/buf_file.h libc3/buf_parse_c.c libc3/buf_parse_c.h libc3/buf_save.c libc3/log.h libc3/skiplist_node__fact.h libc3/skiplist__fact.c libc3/skiplist__fact.h libc3/set_item__fact.h libc3/set_item__fact.c libc3/set__fact.h libc3/set__fact.c libc3/set_cursor__fact.h libc3/compare.h libc3/buf_save.h libc3/env.c libc3/env.h libc3/c_types.h libc3/call.c libc3/call.h libc3/log.c libc3/array.h libc3/error.c libc3/error.h libc3/error_handler.c libc3/error_handler.h libc3/io.c libc3/io.h libc3/fact.h libc3/character.c libc3/array.c libc3/facts.h libc3/facts_cursor.c libc3/facts_cursor.h libc3/facts_spec.c libc3/facts_spec.h libc3/facts_spec_cursor.c libc3/facts_spec_cursor.h libc3/character.h libc3/set_cursor__fact.c libc3/facts_with.c libc3/facts_with.h libc3/facts_with_cursor.c libc3/facts_with_cursor.h libc3/fn.c libc3/fn.h libc3/frame.c libc3/frame.h libc3/hash.c libc3/hash.h libc3/ident.c libc3/ident.h libc3/abs.h libc3/integer.c libc3/integer.h libc3/list.c libc3/list.h libc3/module.h libc3/quote.c libc3/quote.h libc3/types.h libc3/eval.h libc3/cfn.c libc3/sign.h libc3/set.c.in libc3/set.h.in libc3/set_cursor.c.in libc3/set_cursor.h.in libc3/str.c libc3/eval.c libc3/buf_inspect.h libc3/ceiling.h libc3/ceiling.c libc3/set_item.c.in libc3/set_item.h.in libc3/fact.c libc3/skiplist.c.in libc3/operator.c libc3/operator.h libc3/buf_parse.c libc3/abs.c libc3/skiplist.h.in libc3/skiplist_node.c.in libc3/skiplist_node.h.in libc3/str.h libc3/sym.c libc3/sym.h libc3/c3.h libc3/facts.c libc3/buf_inspect.c libc3/buf_parse.h libc3/tuple.c libc3/tuple.h libc3/ucd.c libc3/ucd.h libc3/c3.c libc3/tag.h libc3/module.c libc3/tag.c libc3/compare.c libc3/cfn.h libc3/sign.c libc3/sha1.h test/bool_test.c test/buf_file_test.c test/buf_inspect_test.c test/buf_parse_test.c test/buf_test.c test/call_test.c test/character_test.c test/hash_test.c test/fact_test.c test/fact_test.h test/facts_cursor_test.c test/facts_test.c test/facts_with_test.c test/ident_test.c test/env_test.c test/libc3_test.c test/tuple_test.c test/list_test.c test/set__fact_test.c test/set__tag_test.c test/compare_test.h test/skiplist__fact_test.c test/str_test.c test/cfn_test.c test/test.c test/test.h test/sym_test.c test/tag_test.c test/tag_test.h test/types_test.c test/compare_test.c ucd2c/ucd.h ucd2c/ucd2c.c '
+C3_C_SOURCES='c3c/c3c.c c3s/buf_readline.c c3s/c3s.c c3s/buf_readline.h ic3/buf_linenoise.c ic3/ic3.c ic3/buf_linenoise.h ic3/linenoise.c libc3/arg.c libc3/arg.h libc3/set__fact.c libc3/set__fact.h libc3/set__tag.c libc3/set__tag.h libc3/set_cursor__fact.c libc3/set_cursor__fact.h libc3/set_cursor__tag.c libc3/set_cursor__tag.h libc3/binding.c libc3/binding.h libc3/facts.c libc3/facts_with_cursor.c libc3/array.c libc3/array.h libc3/buf.c libc3/buf_file.c libc3/buf_file.h libc3/bool.c libc3/io.h libc3/io.c libc3/buf_parse.c libc3/abs.h libc3/ceiling.c libc3/buf_parse_c.c libc3/buf_parse_c.h libc3/buf_save.c libc3/buf_parse.h libc3/compare.c libc3/buf_inspect.c libc3/set_item__fact.c libc3/set_item__fact.h libc3/set_item__tag.c libc3/set_item__tag.h libc3/skiplist__fact.c libc3/skiplist__fact.h libc3/skiplist_node__fact.c libc3/skiplist_node__fact.h libc3/call.c libc3/bool.h libc3/buf_save.h libc3/fact.h libc3/error.c libc3/list.h libc3/c3.c libc3/c3.h libc3/error.h libc3/env.h libc3/character.h libc3/compare.h libc3/operator.h libc3/operator.c libc3/tag.h libc3/sign.h libc3/buf.h libc3/ident.c libc3/error_handler.c libc3/frame.c libc3/set_cursor.c.in libc3/set_cursor.h.in libc3/set_item.c.in libc3/set_item.h.in libc3/error_handler.h libc3/eval.c libc3/eval.h libc3/fact.c libc3/facts.h libc3/facts_cursor.c libc3/fn.h libc3/ceiling.h libc3/buf_inspect.h libc3/env.c libc3/facts_cursor.h libc3/facts_spec.c libc3/frame.h libc3/sign.c libc3/facts_spec.h libc3/facts_spec_cursor.c libc3/hash.c libc3/facts_spec_cursor.h libc3/facts_with.c libc3/facts_with.h libc3/hash.h libc3/cfn.h libc3/tag.c libc3/abs.c libc3/facts_with_cursor.h libc3/ident.h libc3/str.c libc3/c_types.h libc3/integer.c libc3/list.c libc3/log.c libc3/log.h libc3/sym.h libc3/module.c libc3/quote.c libc3/quote.h libc3/integer.h libc3/character.c libc3/types.h libc3/cfn.c libc3/fn.c libc3/module.h libc3/set.c.in libc3/call.h libc3/set.h.in libc3/sha1.h libc3/skiplist.c.in libc3/skiplist.h.in libc3/skiplist_node.c.in libc3/skiplist_node.h.in libc3/str.h libc3/sym.c libc3/tuple.c libc3/tuple.h libc3/ucd.c libc3/ucd.h libc3/float.h test/facts_cursor_test.c test/facts_test.c test/facts_with_test.c test/set__fact_test.c test/set__tag_test.c test/test.c test/tag_test.c test/sym_test.c test/tag_test.h test/tuple_test.c test/types_test.c test/skiplist__fact_test.c test/fact_test.c test/compare_test.h test/fact_test.h test/str_test.c test/list_test.c test/hash_test.c test/compare_test.c test/call_test.c test/ident_test.c test/libc3_test.c test/buf_inspect_test.c test/test.h test/bool_test.c test/cfn_test.c test/buf_parse_test.c test/buf_parse_test_s8.c test/buf_parse_test_s32.c test/buf_parse_test_s64.c test/buf_parse_test_u16.c test/buf_parse_test_u8.c test/buf_parse_test_u32.c test/buf_parse_test_u64.c test/buf_parse_test.h test/buf_test.c test/env_test.c test/buf_parse_test_su.h test/character_test.c test/buf_parse_test_s16.c test/buf_file_test.c ucd2c/ucd.h ucd2c/ucd2c.c '
diff --git a/test/buf_parse_test.c b/test/buf_parse_test.c
index b065dc7..1948191 100644
--- a/test/buf_parse_test.c
+++ b/test/buf_parse_test.c
@@ -25,6 +25,7 @@
#include "../libc3/tag.h"
#include "../libc3/tuple.h"
#include "test.h"
+#include "buf_parse_test_su.h"
#define BUF_PARSE_TEST_BOOL(test, expected) \
do { \
@@ -635,22 +636,6 @@
test_context(NULL); \
} while (0)
-#define BUF_PARSE_TEST_S_PROTOTYPE(bits) \
- TEST_CASE_PROTOTYPE(buf_parse_s ## bits ## _binary); \
- TEST_CASE_PROTOTYPE(buf_parse_s ## bits ## _binary_negative); \
- TEST_CASE_PROTOTYPE(buf_parse_s ## bits ## _decimal); \
- TEST_CASE_PROTOTYPE(buf_parse_s ## bits ## _decimal_negative); \
- TEST_CASE_PROTOTYPE(buf_parse_s ## bits ## _hexadecimal); \
- TEST_CASE_PROTOTYPE(buf_parse_s ## bits ## _hexadecimal_negative); \
- TEST_CASE_PROTOTYPE(buf_parse_s ## bits ## _octal); \
- TEST_CASE_PROTOTYPE(buf_parse_s ## bits ## _octal_negative)
-
-#define BUF_PARSE_TEST_U_PROTOTYPE(bits) \
- TEST_CASE_PROTOTYPE(buf_parse_u ## bits ## _binary); \
- TEST_CASE_PROTOTYPE(buf_parse_u ## bits ## _decimal); \
- TEST_CASE_PROTOTYPE(buf_parse_u ## bits ## _hexadecimal); \
- TEST_CASE_PROTOTYPE(buf_parse_u ## bits ## _octal)
-
TEST_CASE_PROTOTYPE(buf_parse_bool);
TEST_CASE_PROTOTYPE(buf_parse_call);
TEST_CASE_PROTOTYPE(buf_parse_call_op);
@@ -670,22 +655,12 @@ TEST_CASE_PROTOTYPE(buf_parse_integer_oct);
TEST_CASE_PROTOTYPE(buf_parse_integer_bin);
TEST_CASE_PROTOTYPE(buf_parse_ident);
TEST_CASE_PROTOTYPE(buf_parse_list);
-BUF_PARSE_TEST_S_PROTOTYPE(8);
-BUF_PARSE_TEST_S_PROTOTYPE(16);
-BUF_PARSE_TEST_S_PROTOTYPE(32);
-BUF_PARSE_TEST_S_PROTOTYPE(64);
-TEST_CASE_PROTOTYPE(buf_parse_sw);
TEST_CASE_PROTOTYPE(buf_parse_str);
TEST_CASE_PROTOTYPE(buf_parse_str_character);
TEST_CASE_PROTOTYPE(buf_parse_str_u8);
TEST_CASE_PROTOTYPE(buf_parse_sym);
TEST_CASE_PROTOTYPE(buf_parse_tag);
TEST_CASE_PROTOTYPE(buf_parse_tuple);
-BUF_PARSE_TEST_U_PROTOTYPE(8);
-BUF_PARSE_TEST_U_PROTOTYPE(16);
-BUF_PARSE_TEST_U_PROTOTYPE(32);
-BUF_PARSE_TEST_U_PROTOTYPE(64);
-TEST_CASE_PROTOTYPE(buf_parse_uw);
void buf_parse_test ()
{
@@ -713,6 +688,7 @@ void buf_parse_test ()
TEST_CASE_RUN(buf_parse_list);
TEST_CASE_RUN(buf_parse_tag);
TEST_CASE_RUN(buf_parse_tuple);
+#ifdef C3_TEST_BUF_PARSE_SU
TEST_CASE_RUN(buf_parse_u8_binary);
TEST_CASE_RUN(buf_parse_u8_octal);
TEST_CASE_RUN(buf_parse_u8_hexadecimal);
@@ -763,6 +739,7 @@ void buf_parse_test ()
TEST_CASE_RUN(buf_parse_s8_decimal);
TEST_CASE_RUN(buf_parse_s8_decimal_negative);
TEST_CASE_RUN(buf_parse_sw);
+#endif /* C3_TEST_BUF_PARSE_SU */
TEST_CASE_RUN(buf_parse_cfn);
}
diff --git a/test/buf_parse_test_s.rb b/test/buf_parse_test_s.rb
deleted file mode 100644
index 2f2d0ca..0000000
--- a/test/buf_parse_test_s.rb
+++ /dev/null
@@ -1,146 +0,0 @@
-## c3
-## Copyright 2022,2023 kmx.io <contact@kmx.io>
-##
-## Permission is hereby granted to use this software granted the above
-## copyright notice and this permission paragraph are included in all
-## copies and substantial portions of this software.
-##
-## THIS SOFTWARE IS PROVIDED "AS-IS" WITHOUT ANY GUARANTEE OF
-## PURPOSE AND PERFORMANCE. IN NO EVENT WHATSOEVER SHALL THE
-## AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
-## THIS SOFTWARE.
-
-def one(out, su, bits, base_prefix, negative, digits, result)
- r = if result != 0 then "#{negative}#{result}" else "#{result}" end
- if r == "-9223372036854775808"
- # XXX bug in clang integer litterals
- r = "-9223372036854775807 - 1"
- end
- if su == "U"
- r = "#{r}U"
- end
- output = Proc.new do |digits|
- zeros = 0
- spaces = ""
- digits.each do |digit|
- if digit != 0 || zeros >= digits.count - 1
- break
- end
- zeros += 1
- end
- i = zeros
- while i >= 0
- test_digits = digits[i..(digits.count - 1)]
- test_digits = test_digits.join
- spaces = " " * (i + ((result.zero? && negative == "-") ? 1 : 0))
- out.puts " BUF_PARSE_TEST_#{su}(#{bits}, \"#{negative}#{base_prefix}#{test_digits}\", #{spaces}#{r});"
- i -= 1
- end
- end
- output.(digits)
- string_digits = false
- digits_upcase = digits.map do |digit|
- if digit.is_a?(String)
- string_digits = true
- digit.upcase
- else
- digit
- end
- end
- output.(digits_upcase) if string_digits
-end
-
-def count(out, su, bits, base, base_prefix, negative, max)
- result = 0
- base.each do |i|
- i = 0 if i == "0"
- base.each do |j|
- j = 0 if j == "0"
- base.each do |k|
- one(out, su, bits, base_prefix, negative, [i, j, k], result)
- result += 1
- if result > max
- return result
- end
- end
- end
- end
- return result
-end
-
-def number_to_base(m, base)
- digits = []
- radix = base.count
- while m > 0
- digits.push(base[m % radix])
- m = m / radix
- end
- digits.reverse
-end
-
-def integer_max(su, bits, negative)
- if negative == "-"
- 2 ** (if su == "S" then bits - 1; else bits; end)
- else
- 2 ** (if su == "S" then bits - 1; else bits; end) - 1
- end
-end
-
-BITS = [8, 16, 32, 64]
-
-licence = File.read("../licence.h")
-
-["S", "U"].each do |su|
- BITS.each do |bits|
- su_downcase = su.downcase
- filename = "buf_parse_test_#{su_downcase}#{bits}.c"
- filename_tmp = "#{filename}.tmp"
- File.open(filename_tmp, "w") do |out|
- out.puts licence
- out.puts '#include "buf_parse_test.h"'
- [[[0, 1], "0b", "binary"],
- [[0, 1, 2, 3, 4, 5, 6, 7], "0o", "octal"],
- [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "a", "b", "c", "d", "e", "f"],
- "0x", "hexadecimal"],
- [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], "", "decimal"]].each do |b|
- base = b[0]
- base_prefix = b[1]
- base_name = b[2]
- radix = base.count
- signs = if (su == "S")
- ["", "-"]
- else
- [""]
- end
- signs.each do |negative|
- function_name = "buf_parse_test_#{su_downcase}#{bits}_#{base_name}"
- if negative == "-"
- function_name += "_negative"
- end
- out.puts ''
- out.puts "void #{function_name} ()"
- out.puts '{'
- max = integer_max(su, bits, negative)
- result = count(out, su, bits, base, base_prefix, negative,
- max)
- BITS.each do |b|
- if b <= bits
- max = integer_max(su, b, negative)
- if result < max - 1
- digits = number_to_base(max - 1, base)
- one(out, su, bits, base_prefix, negative, digits, max - 1)
- end
- if result < max
- digits = number_to_base(max, base)
- one(out, su, bits, base_prefix, negative, digits, max)
- end
- end
- end
- out.puts "}"
- end
- end
- end # File.open
- cmd = "if ! cmp #{filename} #{filename_tmp}; then mv #{filename_tmp} #{filename}; echo #{filename}; else rm #{filename_tmp}; fi"
- raise "command failed" unless system(cmd)
- end
-end
diff --git a/test/buf_parse_test_s16.c b/test/buf_parse_test_s16.c
index 6262e13..4c3796b 100644
--- a/test/buf_parse_test_s16.c
+++ b/test/buf_parse_test_s16.c
@@ -11,6 +11,7 @@
* THIS SOFTWARE.
*/
#include "buf_parse_test.h"
+#ifdef C3_TEST_BUF_PARSE_SU
TEST_CASE(buf_parse_s16_binary)
{
@@ -18742,3 +18743,4 @@ TEST_CASE(buf_parse_s16_decimal_negative)
BUF_PARSE_TEST_S(16, "-32768", -32768);
}
TEST_CASE_END(buf_parse_s16_decimal_negative)
+#endif /* ifdef C3_TEST_BUF_PARSE_SU */
diff --git a/test/buf_parse_test_s32.c b/test/buf_parse_test_s32.c
index cd4317d..04c22ec 100644
--- a/test/buf_parse_test_s32.c
+++ b/test/buf_parse_test_s32.c
@@ -11,6 +11,7 @@
* THIS SOFTWARE.
*/
#include "buf_parse_test.h"
+#ifdef C3_TEST_BUF_PARSE_SU
TEST_CASE(buf_parse_s32_binary)
{
@@ -18761,3 +18762,4 @@ TEST_CASE(buf_parse_s32_decimal_negative)
BUF_PARSE_TEST_S(32, "-2147483648", -2147483648);
}
TEST_CASE_END(buf_parse_s32_decimal_negative)
+#endif /* ifdef C3_TEST_BUF_PARSE_SU */
diff --git a/test/buf_parse_test_s64.c b/test/buf_parse_test_s64.c
index 28fa7b6..1c8916b 100644
--- a/test/buf_parse_test_s64.c
+++ b/test/buf_parse_test_s64.c
@@ -11,6 +11,7 @@
* THIS SOFTWARE.
*/
#include "buf_parse_test.h"
+#ifdef C3_TEST_BUF_PARSE_SU
TEST_CASE(buf_parse_s64_binary)
{
@@ -18780,3 +18781,4 @@ TEST_CASE(buf_parse_s64_decimal_negative)
BUF_PARSE_TEST_S(64, "-9223372036854775808", -9223372036854775807 - 1);
}
TEST_CASE_END(buf_parse_s64_decimal_negative)
+#endif /* ifdef C3_TEST_BUF_PARSE_SU */
diff --git a/test/buf_parse_test_s8.c b/test/buf_parse_test_s8.c
index a8779f1..1f51d54 100644
--- a/test/buf_parse_test_s8.c
+++ b/test/buf_parse_test_s8.c
@@ -11,6 +11,7 @@
* THIS SOFTWARE.
*/
#include "buf_parse_test.h"
+#ifdef C3_TEST_BUF_PARSE_SU
TEST_CASE(buf_parse_s8_binary)
{
@@ -1711,3 +1712,4 @@ TEST_CASE(buf_parse_s8_decimal_negative)
BUF_PARSE_TEST_S(8, "-128", -128);
}
TEST_CASE_END(buf_parse_s8_decimal_negative)
+#endif /* ifdef C3_TEST_BUF_PARSE_SU */
diff --git a/test/buf_parse_test_su.h b/test/buf_parse_test_su.h
new file mode 100644
index 0000000..3ed8114
--- /dev/null
+++ b/test/buf_parse_test_su.h
@@ -0,0 +1,47 @@
+/* c3
+ * Copyright 2022,2023 kmx.io <contact@kmx.io>
+ *
+ * Permission is hereby granted to use this software granted the above
+ * copyright notice and this permission paragraph are included in all
+ * copies and substantial portions of this software.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS-IS" WITHOUT ANY GUARANTEE OF
+ * PURPOSE AND PERFORMANCE. IN NO EVENT WHATSOEVER SHALL THE
+ * AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
+ * THIS SOFTWARE.
+ */
+#ifndef BUF_PARSE_TEST_SU
+
+#include "test.h"
+
+#ifdef C3_TEST_BUF_PARSE_SU
+
+#define BUF_PARSE_TEST_S_PROTOTYPE(bits) \
+ TEST_CASE_PROTOTYPE(buf_parse_s ## bits ## _binary); \
+ TEST_CASE_PROTOTYPE(buf_parse_s ## bits ## _binary_negative); \
+ TEST_CASE_PROTOTYPE(buf_parse_s ## bits ## _decimal); \
+ TEST_CASE_PROTOTYPE(buf_parse_s ## bits ## _decimal_negative); \
+ TEST_CASE_PROTOTYPE(buf_parse_s ## bits ## _hexadecimal); \
+ TEST_CASE_PROTOTYPE(buf_parse_s ## bits ## _hexadecimal_negative); \
+ TEST_CASE_PROTOTYPE(buf_parse_s ## bits ## _octal); \
+ TEST_CASE_PROTOTYPE(buf_parse_s ## bits ## _octal_negative)
+
+#define BUF_PARSE_TEST_U_PROTOTYPE(bits) \
+ TEST_CASE_PROTOTYPE(buf_parse_u ## bits ## _binary); \
+ TEST_CASE_PROTOTYPE(buf_parse_u ## bits ## _decimal); \
+ TEST_CASE_PROTOTYPE(buf_parse_u ## bits ## _hexadecimal); \
+ TEST_CASE_PROTOTYPE(buf_parse_u ## bits ## _octal)
+
+BUF_PARSE_TEST_S_PROTOTYPE(8);
+BUF_PARSE_TEST_S_PROTOTYPE(16);
+BUF_PARSE_TEST_S_PROTOTYPE(32);
+BUF_PARSE_TEST_S_PROTOTYPE(64);
+TEST_CASE_PROTOTYPE(buf_parse_sw);
+BUF_PARSE_TEST_U_PROTOTYPE(8);
+BUF_PARSE_TEST_U_PROTOTYPE(16);
+BUF_PARSE_TEST_U_PROTOTYPE(32);
+BUF_PARSE_TEST_U_PROTOTYPE(64);
+TEST_CASE_PROTOTYPE(buf_parse_uw);
+
+#endif /* ifndef BUF_PARSE_TEST_SU */
+#endif /* ifdef C3_TEST_BUF_PARSE_SU */
diff --git a/test/buf_parse_test_su.rb b/test/buf_parse_test_su.rb
new file mode 100644
index 0000000..76b5368
--- /dev/null
+++ b/test/buf_parse_test_su.rb
@@ -0,0 +1,149 @@
+## c3
+## Copyright 2022,2023 kmx.io <contact@kmx.io>
+##
+## Permission is hereby granted to use this software granted the above
+## copyright notice and this permission paragraph are included in all
+## copies and substantial portions of this software.
+##
+## THIS SOFTWARE IS PROVIDED "AS-IS" WITHOUT ANY GUARANTEE OF
+## PURPOSE AND PERFORMANCE. IN NO EVENT WHATSOEVER SHALL THE
+## AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
+## THIS SOFTWARE.
+
+def one(out, su, bits, base_prefix, negative, digits, result)
+ r = if result != 0 then "#{negative}#{result}" else "#{result}" end
+ if r == "-9223372036854775808"
+ # XXX bug in clang integer litterals
+ r = "-9223372036854775807 - 1"
+ end
+ if su == "U"
+ r = "#{r}U"
+ end
+ output = Proc.new do |digits|
+ zeros = 0
+ spaces = ""
+ digits.each do |digit|
+ if digit != 0 || zeros >= digits.count - 1
+ break
+ end
+ zeros += 1
+ end
+ i = zeros
+ while i >= 0
+ test_digits = digits[i..(digits.count - 1)]
+ test_digits = test_digits.join
+ spaces = " " * (i + ((result.zero? && negative == "-") ? 1 : 0))
+ out.puts " BUF_PARSE_TEST_#{su}(#{bits}, \"#{negative}#{base_prefix}#{test_digits}\", #{spaces}#{r});"
+ i -= 1
+ end
+ end
+ output.(digits)
+ string_digits = false
+ digits_upcase = digits.map do |digit|
+ if digit.is_a?(String)
+ string_digits = true
+ digit.upcase
+ else
+ digit
+ end
+ end
+ output.(digits_upcase) if string_digits
+end
+
+def count(out, su, bits, base, base_prefix, negative, max)
+ result = 0
+ base.each do |i|
+ i = 0 if i == "0"
+ base.each do |j|
+ j = 0 if j == "0"
+ base.each do |k|
+ one(out, su, bits, base_prefix, negative, [i, j, k], result)
+ result += 1
+ if result > max
+ return result
+ end
+ end
+ end
+ end
+ return result
+end
+
+def number_to_base(m, base)
+ digits = []
+ radix = base.count
+ while m > 0
+ digits.push(base[m % radix])
+ m = m / radix
+ end
+ digits.reverse
+end
+
+def integer_max(su, bits, negative)
+ if negative == "-"
+ 2 ** (if su == "S" then bits - 1; else bits; end)
+ else
+ 2 ** (if su == "S" then bits - 1; else bits; end) - 1
+ end
+end
+
+BITS = [8, 16, 32, 64]
+
+licence = File.read("../licence.h")
+
+["S", "U"].each do |su|
+ BITS.each do |bits|
+ su_downcase = su.downcase
+ filename = "buf_parse_test_#{su_downcase}#{bits}.c"
+ filename_tmp = "#{filename}.tmp"
+ File.open(filename_tmp, "w") do |out|
+ out.puts licence
+ out.puts '#include "buf_parse_test.h"'
+ out.puts "#ifdef C3_TEST_BUF_PARSE_SU"
+ [[[0, 1], "0b", "binary"],
+ [[0, 1, 2, 3, 4, 5, 6, 7], "0o", "octal"],
+ [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "a", "b", "c", "d", "e", "f"],
+ "0x", "hexadecimal"],
+ [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], "", "decimal"]].each do |b|
+ base = b[0]
+ base_prefix = b[1]
+ base_name = b[2]
+ radix = base.count
+ signs = if (su == "S")
+ ["", "-"]
+ else
+ [""]
+ end
+ signs.each do |negative|
+ function_name = "buf_parse_#{su_downcase}#{bits}_#{base_name}"
+ if negative == "-"
+ function_name += "_negative"
+ end
+ out.puts ''
+ out.puts "TEST_CASE(#{function_name})"
+ out.puts '{'
+ max = integer_max(su, bits, negative)
+ result = count(out, su, bits, base, base_prefix, negative,
+ max)
+ BITS.each do |b|
+ if b <= bits
+ max = integer_max(su, b, negative)
+ if result < max - 1
+ digits = number_to_base(max - 1, base)
+ one(out, su, bits, base_prefix, negative, digits, max - 1)
+ end
+ if result < max
+ digits = number_to_base(max, base)
+ one(out, su, bits, base_prefix, negative, digits, max)
+ end
+ end
+ end
+ out.puts "}"
+ out.puts "TEST_CASE_END(#{function_name})"
+ end
+ end
+ out.puts "#endif /* ifdef C3_TEST_BUF_PARSE_SU */"
+ end # File.open
+ cmd = "if ! diff -u #{filename} #{filename_tmp}; then mv #{filename_tmp} #{filename}; echo #{filename}; else rm #{filename_tmp}; fi"
+ raise "command failed" unless system(cmd)
+ end
+end
diff --git a/test/buf_parse_test_u16.c b/test/buf_parse_test_u16.c
index 292c21d..073d817 100644
--- a/test/buf_parse_test_u16.c
+++ b/test/buf_parse_test_u16.c
@@ -11,6 +11,7 @@
* THIS SOFTWARE.
*/
#include "buf_parse_test.h"
+#ifdef C3_TEST_BUF_PARSE_SU
TEST_CASE(buf_parse_u16_binary)
{
@@ -9377,3 +9378,4 @@ TEST_CASE(buf_parse_u16_decimal)
BUF_PARSE_TEST_U(16, "65535", 65535U);
}
TEST_CASE_END(buf_parse_u16_decimal)
+#endif /* ifdef C3_TEST_BUF_PARSE_SU */
diff --git a/test/buf_parse_test_u32.c b/test/buf_parse_test_u32.c
index 790c9dc..16ddb47 100644
--- a/test/buf_parse_test_u32.c
+++ b/test/buf_parse_test_u32.c
@@ -11,6 +11,7 @@
* THIS SOFTWARE.
*/
#include "buf_parse_test.h"
+#ifdef C3_TEST_BUF_PARSE_SU
TEST_CASE(buf_parse_u32_binary)
{
@@ -9387,3 +9388,4 @@ TEST_CASE(buf_parse_u32_decimal)
BUF_PARSE_TEST_U(32, "4294967295", 4294967295U);
}
TEST_CASE_END(buf_parse_u32_decimal)
+#endif /* ifdef C3_TEST_BUF_PARSE_SU */
diff --git a/test/buf_parse_test_u64.c b/test/buf_parse_test_u64.c
index f915bcc..af5163a 100644
--- a/test/buf_parse_test_u64.c
+++ b/test/buf_parse_test_u64.c
@@ -11,6 +11,7 @@
* THIS SOFTWARE.
*/
#include "buf_parse_test.h"
+#ifdef C3_TEST_BUF_PARSE_SU
TEST_CASE(buf_parse_u64_binary)
{
@@ -9397,3 +9398,4 @@ TEST_CASE(buf_parse_u64_decimal)
BUF_PARSE_TEST_U(64, "18446744073709551615", 18446744073709551615U);
}
TEST_CASE_END(buf_parse_u64_decimal)
+#endif /* ifdef C3_TEST_BUF_PARSE_SU */
diff --git a/test/buf_parse_test_u8.c b/test/buf_parse_test_u8.c
index beada5a..ec805d4 100644
--- a/test/buf_parse_test_u8.c
+++ b/test/buf_parse_test_u8.c
@@ -11,6 +11,7 @@
* THIS SOFTWARE.
*/
#include "buf_parse_test.h"
+#ifdef C3_TEST_BUF_PARSE_SU
TEST_CASE(buf_parse_u8_binary)
{
@@ -1587,3 +1588,4 @@ TEST_CASE(buf_parse_u8_decimal)
BUF_PARSE_TEST_U(8, "255", 255U);
}
TEST_CASE_END(buf_parse_u8_decimal)
+#endif /* ifdef C3_TEST_BUF_PARSE_SU */
diff --git a/test/configure b/test/configure
index da66cf2..82aba7e 100755
--- a/test/configure
+++ b/test/configure
@@ -42,7 +42,8 @@ echo "OBJECTS_DEBUG = $OBJECTS_DEBUG" >> ${CONFIG_MK}
CPPFLAGS="${CPPFLAGS:=}"
ENV_CFLAGS="${CFLAGS:=}"
DEFAULT_CFLAGS="-O2 -pipe"
-LDFLAGS="-Wl,--allow-shlib-undefined ${LDFLAGS:=}"
+#LDFLAGS="-Wl,--allow-shlib-undefined ${LDFLAGS:=}"
+LDFLAGS="${LDFLAGS:=}"
LIBS="${LIBS:=} -lm"
# Common config for all targets