if (jv_get_kind(a) == JV_KIND_NUMBER && jv_get_kind(b) == JV_KIND_NUMBER) {
output[0] = jv_number(jv_number_value(a) +
jv_number_value(b));
+ } else if (jv_get_kind(a) == JV_KIND_STRING && jv_get_kind(b) == JV_KIND_STRING) {
+ output[0] = jv_string_concat(a, b);
} else if (jv_get_kind(a) == JV_KIND_ARRAY && jv_get_kind(b) == JV_KIND_ARRAY) {
output[0] = jv_array_concat(a, b);
} else if (jv_get_kind(a) == JV_KIND_OBJECT && jv_get_kind(b) == JV_KIND_OBJECT) {
return r;
}
+
static void jvp_string_free(jv_complex* s) {
if (jvp_refcnt_dec(s)) {
jvp_string* str = jvp_string_ptr(s);
return s->length_hashed >> 1;
}
+static jv_complex jvp_string_concat(jvp_string* a, jvp_string* b) {
+ uint32_t la = jvp_string_length(a), lb = jvp_string_length(b);
+ jvp_string* s = jvp_string_alloc(la + lb);
+ memcpy(s->data, a->data, la);
+ memcpy(s->data + la, b->data, lb);
+ s->data[la + lb] = 0;
+ jv_complex r = {&s->refcnt, {0,0}};
+ return r;
+}
+
static const uint32_t HASH_SEED = 0x432A9843;
static uint32_t rotl32 (uint32_t x, int8_t r){
return jvp_string_ptr(&j.val.complex)->data;
}
+jv jv_string_concat(jv a, jv b) {
+ jv j;
+ j.kind = JV_KIND_STRING;
+ j.val.complex = jvp_string_concat(jvp_string_ptr(&a.val.complex),
+ jvp_string_ptr(&b.val.complex));
+ jv_free(a);
+ jv_free(b);
+ return j;
+}
+
jv jv_string_fmt(const char* fmt, ...) {
int size = 1024;
while (1) {
int jv_string_length(jv);
uint32_t jv_string_hash(jv);
const char* jv_string_value(jv);
+jv jv_string_concat(jv, jv);
jv jv_string_fmt(const char*, ...);
jv jv_object();