const struct tvec_regdef *rd)
{ return (rv0->u == rv1->u); }
+/* --- @copy_int@, @copy_uint@ --- *
+ *
+ * Arguments: @union tvec_regval *rvd@ = destination register value
+ * @const union tvec_regval *rvs@ = source register value
+ * @const struct tvec_regdef *rd@ = register definition
+ *
+ * Returns: ---
+ *
+ * Use: Copy a register value.
+ */
+
+static void copy_int(union tvec_regval *rvd, const union tvec_regval *rvs,
+ const struct tvec_regdef *rd)
+ { rvd->i = rvs->i; }
+
+static void copy_uint(union tvec_regval *rvd, const union tvec_regval *rvs,
+ const struct tvec_regdef *rd)
+ { rvd->u = rvs->u; }
+
/* --- @tobuf_int@, @tobuf_uint@ --- *
*
* Arguments: @buf *b@ = buffer
/* Integer type definitions. */
const struct tvec_regty tvty_int = {
- init_int, trivial_release, eq_int,
+ init_int, trivial_release, eq_int, copy_int,
tobuf_int, frombuf_int,
parse_int, dump_int
};
const struct tvec_regty tvty_uint = {
- init_uint, trivial_release, eq_uint,
+ init_uint, trivial_release, eq_uint, copy_uint,
tobuf_uint, frombuf_uint,
parse_uint, dump_uint
};
/* Size type definitions. */
const struct tvec_regty tvty_size = {
- init_uint, trivial_release, eq_uint,
+ init_uint, trivial_release, eq_uint, copy_uint,
tobuf_uint, frombuf_uint,
parse_size, dump_size
};
const struct tvec_regdef *rd)
{ return (eqish_floating_p(rv1->f, rv0->f, rd->arg.p)); }
+/* --- @copy_float@ --- *
+ *
+ * Arguments: @union tvec_regval *rvd@ = destination register value
+ * @const union tvec_regval *rvs@ = source register value
+ * @const struct tvec_regdef *rd@ = register definition
+ *
+ * Returns: ---
+ *
+ * Use: Copy a register value.
+ */
+
+static void copy_float(union tvec_regval *rvd, const union tvec_regval *rvs,
+ const struct tvec_regdef *rd)
+ { rvd->f = rvs->f; }
+
/* --- @tobuf_float@ --- *
*
* Arguments: @buf *b@ = buffer
/* Floating-point type definition. */
const struct tvec_regty tvty_float = {
- init_float, trivial_release, eq_float,
+ init_float, trivial_release, eq_float, copy_float,
tobuf_float, frombuf_float,
parse_float, dump_float
};
/* Duration type definition. */
const struct tvec_regty tvty_duration = {
- init_float, trivial_release, eq_float,
+ init_float, trivial_release, eq_float, copy_float,
tobuf_float, frombuf_float,
parse_duration, dump_duration
};
const struct tvec_regdef *rd)
{ return (rv0->p == rv1->p); }
+/* --- @copy_tenum@ --- *
+ *
+ * Arguments: @union tvec_regval *rvd@ = destination register value
+ * @const union tvec_regval *rvs@ = source register value
+ * @const struct tvec_regdef *rd@ = register definition
+ *
+ * Returns: ---
+ *
+ * Use: Copy a register value.
+ */
+
+#define copy_ienum copy_int
+#define copy_uenum copy_uint
+#define copy_fenum copy_float
+
+static void copy_penum(union tvec_regval *rvd, const union tvec_regval *rvs,
+ const struct tvec_regdef *rd)
+ { rvd->p = rvs->p; }
+
/* --- @tobuf_tenum@ --- *
*
* Arguments: @buf *b@ = buffer
/* Enumeration type definitions. */
#define DEFTY_ENUM(tag, ty, slot) \
const struct tvec_regty tvty_##slot##enum = { \
- init_##slot##enum, trivial_release, eq_##slot##enum, \
+ init_##slot##enum, trivial_release, eq_##slot##enum, copy_##slot##enum, \
tobuf_##slot##enum, frombuf_##slot##enum, \
parse_##slot##enum, dump_##slot##enum \
};
/* Flags type definition. */
const struct tvec_regty tvty_flags = {
- init_uint, trivial_release, eq_uint,
+ init_uint, trivial_release, eq_uint, copy_uint,
tobuf_uint, frombuf_uint,
parse_flags, dump_flags
};
/* Character type definition. */
const struct tvec_regty tvty_char = {
- init_int, trivial_release, eq_int,
+ init_int, trivial_release, eq_int, copy_int,
tobuf_char, frombuf_char,
parse_char, dump_char
};
MEMCMP(rv0->bytes.p, ==, rv1->bytes.p, rv1->bytes.sz)));
}
+/* --- @copy_text@, @copy_bytes@ --- *
+ *
+ * Arguments: @union tvec_regval *rvd@ = destination register value
+ * @const union tvec_regval *rvs@ = source register value
+ * @const struct tvec_regdef *rd@ = register definition
+ *
+ * Returns: ---
+ *
+ * Use: Copy a register value.
+ */
+
+static void copy_text(union tvec_regval *rvd, const union tvec_regval *rvs,
+ const struct tvec_regdef *rd)
+{
+ size_t sz = rvs->text.sz;
+
+ if (!sz)
+ rvd->text.sz = 0;
+ else {
+ tvec_alloctext(rvd, sz);
+ memcpy(rvd->text.p, rvs->text.p, sz); rvd->text.p[sz] = 0;
+ }
+}
+
+static void copy_bytes(union tvec_regval *rvd, const union tvec_regval *rvs,
+ const struct tvec_regdef *rd)
+{
+ size_t sz = rvs->bytes.sz;
+
+ if (!sz)
+ rvd->bytes.sz = 0;
+ else {
+ tvec_alloctext(rvd, sz);
+ memcpy(rvd->bytes.p, rvs->bytes.p, sz);
+ }
+}
+
/* --- @tobuf_text@, @tobuf_bytes@ --- *
*
* Arguments: @buf *b@ = buffer
/* Text and byte string type definitions. */
const struct tvec_regty tvty_text = {
- init_text, release_text, eq_text,
+ init_text, release_text, eq_text, copy_text,
tobuf_text, frombuf_text,
parse_text, dump_text
};
const struct tvec_regty tvty_bytes = {
- init_bytes, release_bytes, eq_bytes,
+ init_bytes, release_bytes, eq_bytes, copy_bytes,
tobuf_bytes, frombuf_bytes,
parse_bytes, dump_bytes
};
{
if (rv->text.sz <= sz)
{ free(rv->text.p); rv->text.p = x_alloc(&arena_stdlib, sz + 1); }
- memset(rv->text.p, '?', sz); rv->text.sz = sz;
+ memset(rv->text.p, '?', sz); rv->text.p[sz] = 0; rv->text.sz = sz;
}
void tvec_allocbytes(union tvec_regval *rv, size_t sz)
rv0->buf.m == rv1->buf.m);
}
+/* --- @copy_buffer@ --- *
+ *
+ * Arguments: @union tvec_regval *rvd@ = destination register value
+ * @const union tvec_regval *rvs@ = source register value
+ * @const struct tvec_regdef *rd@ = register definition
+ *
+ * Returns: ---
+ *
+ * Use: Copy a register value.
+ */
+
+static void copy_buffer(union tvec_regval *rvd, const union tvec_regval *rvs,
+ const struct tvec_regdef *rd)
+{
+ if (rvd->buf.p) { free(rvd->buf.p); rvd->buf.p = 0; }
+ rvd->buf.sz = rvs->buf.sz;
+ rvd->buf.a = rvs->buf.a;
+ rvd->buf.m = rvs->buf.m;
+ rvd->buf.off = 0;
+}
+
/* --- @tobuf_buffer@ --- *
*
* Arguments: @buf *b@ = buffer
/* Buffer type definition. */
const struct tvec_regty tvty_buffer = {
- init_buffer, release_buffer, eq_buffer,
+ init_buffer, release_buffer, eq_buffer, copy_buffer,
tobuf_buffer, frombuf_buffer,
parse_buffer, dump_buffer
};