2017-04-18 02:40:39 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2017 Calvin Rose
|
2017-07-02 01:51:16 +00:00
|
|
|
*
|
2017-04-18 02:40:39 +00:00
|
|
|
* 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:
|
2017-07-02 01:51:16 +00:00
|
|
|
*
|
2017-04-18 02:40:39 +00:00
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
2017-07-02 01:51:16 +00:00
|
|
|
*
|
2017-04-18 02:40:39 +00:00
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2017-11-06 03:05:47 +00:00
|
|
|
#include <dst/dst.h>
|
2017-02-09 20:02:59 +00:00
|
|
|
|
2017-11-01 21:53:43 +00:00
|
|
|
/*
|
2018-01-06 16:09:15 +00:00
|
|
|
* Define a number of functions that can be used internally on ANY Dst.
|
2017-11-01 21:53:43 +00:00
|
|
|
*/
|
|
|
|
|
2017-02-09 20:02:59 +00:00
|
|
|
/* Check if two values are equal. This is strict equality with no conversion. */
|
2018-01-06 16:09:15 +00:00
|
|
|
int dst_equals(Dst x, Dst y) {
|
2017-02-09 23:50:47 +00:00
|
|
|
int result = 0;
|
2017-11-28 23:27:55 +00:00
|
|
|
if (dst_type(x) != dst_type(y)) {
|
2017-02-09 20:02:59 +00:00
|
|
|
result = 0;
|
|
|
|
} else {
|
2017-11-28 23:27:55 +00:00
|
|
|
switch (dst_type(x)) {
|
2017-09-09 18:39:51 +00:00
|
|
|
case DST_NIL:
|
2017-11-28 23:27:55 +00:00
|
|
|
case DST_TRUE:
|
|
|
|
case DST_FALSE:
|
2017-04-15 20:05:59 +00:00
|
|
|
result = 1;
|
|
|
|
break;
|
2017-09-09 18:39:51 +00:00
|
|
|
case DST_REAL:
|
2017-11-28 23:27:55 +00:00
|
|
|
result = (dst_unwrap_real(x) == dst_unwrap_real(y));
|
2017-04-24 20:02:54 +00:00
|
|
|
break;
|
2017-09-09 18:39:51 +00:00
|
|
|
case DST_INTEGER:
|
2017-11-28 23:27:55 +00:00
|
|
|
result = (dst_unwrap_integer(x) == dst_unwrap_integer(y));
|
2017-04-15 20:05:59 +00:00
|
|
|
break;
|
2017-11-27 19:03:34 +00:00
|
|
|
case DST_STRING:
|
2017-11-28 23:27:55 +00:00
|
|
|
result = dst_string_equal(dst_unwrap_string(x), dst_unwrap_string(y));
|
2017-11-27 19:03:34 +00:00
|
|
|
break;
|
2018-01-04 02:36:10 +00:00
|
|
|
case DST_TUPLE:
|
|
|
|
result = dst_tuple_equal(dst_unwrap_tuple(x), dst_unwrap_tuple(y));
|
|
|
|
break;
|
2017-11-27 19:03:34 +00:00
|
|
|
case DST_STRUCT:
|
2017-11-28 23:27:55 +00:00
|
|
|
result = dst_struct_equal(dst_unwrap_struct(x), dst_unwrap_struct(y));
|
2017-11-27 19:03:34 +00:00
|
|
|
break;
|
2017-04-15 20:05:59 +00:00
|
|
|
default:
|
|
|
|
/* compare pointers */
|
2017-11-28 23:27:55 +00:00
|
|
|
result = (dst_unwrap_pointer(x) == dst_unwrap_pointer(y));
|
2017-04-15 20:05:59 +00:00
|
|
|
break;
|
2017-02-09 20:02:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Computes a hash value for a function */
|
2018-01-06 16:09:15 +00:00
|
|
|
int32_t dst_hash(Dst x) {
|
2017-11-28 23:27:55 +00:00
|
|
|
int32_t hash = 0;
|
|
|
|
switch (dst_type(x)) {
|
2017-09-09 18:39:51 +00:00
|
|
|
case DST_NIL:
|
2018-01-12 21:25:24 +00:00
|
|
|
hash = 0;
|
|
|
|
break;
|
2017-11-28 23:27:55 +00:00
|
|
|
case DST_FALSE:
|
2018-01-12 21:25:24 +00:00
|
|
|
hash = 1;
|
|
|
|
break;
|
2017-11-28 23:27:55 +00:00
|
|
|
case DST_TRUE:
|
2018-01-12 21:25:24 +00:00
|
|
|
hash = 2;
|
2017-04-15 20:05:59 +00:00
|
|
|
break;
|
2017-09-09 18:39:51 +00:00
|
|
|
case DST_STRING:
|
|
|
|
case DST_SYMBOL:
|
2017-11-28 23:27:55 +00:00
|
|
|
hash = dst_string_hash(dst_unwrap_string(x));
|
2017-04-15 20:05:59 +00:00
|
|
|
break;
|
2017-09-09 18:39:51 +00:00
|
|
|
case DST_TUPLE:
|
2017-11-29 20:17:56 +00:00
|
|
|
hash = dst_tuple_hash(dst_unwrap_tuple(x));
|
2017-04-15 20:05:59 +00:00
|
|
|
break;
|
2017-09-09 18:39:51 +00:00
|
|
|
case DST_STRUCT:
|
2017-11-29 20:17:56 +00:00
|
|
|
hash = dst_struct_hash(dst_unwrap_struct(x));
|
2017-04-15 20:05:59 +00:00
|
|
|
break;
|
2018-01-12 21:25:24 +00:00
|
|
|
case DST_INTEGER:
|
|
|
|
hash = dst_unwrap_integer(x);
|
2017-04-15 20:05:59 +00:00
|
|
|
default:
|
2017-07-09 17:09:20 +00:00
|
|
|
if (sizeof(double) == sizeof(void *)) {
|
|
|
|
/* Assuming 8 byte pointer */
|
2017-11-28 23:27:55 +00:00
|
|
|
uint64_t i = dst_u64(x);
|
|
|
|
hash = (int32_t)(i >> 32) ^ (int32_t)(i & 0xFFFFFFFF);
|
2017-07-09 17:09:20 +00:00
|
|
|
} else {
|
|
|
|
/* Assuming 4 byte pointer (or smaller) */
|
2017-11-28 23:27:55 +00:00
|
|
|
hash = (int32_t) (dst_unwrap_pointer(x) - NULL);
|
2017-07-09 17:09:20 +00:00
|
|
|
}
|
2017-04-15 20:05:59 +00:00
|
|
|
break;
|
2017-02-09 20:02:59 +00:00
|
|
|
}
|
|
|
|
return hash;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Compares x to y. If they are equal retuns 0. If x is less, returns -1.
|
|
|
|
* If y is less, returns 1. All types are comparable
|
|
|
|
* and should have strict ordering. */
|
2018-01-06 16:09:15 +00:00
|
|
|
int dst_compare(Dst x, Dst y) {
|
2017-11-28 23:27:55 +00:00
|
|
|
if (dst_type(x) == dst_type(y)) {
|
|
|
|
switch (dst_type(x)) {
|
2017-09-09 18:39:51 +00:00
|
|
|
case DST_NIL:
|
2017-11-28 23:27:55 +00:00
|
|
|
case DST_FALSE:
|
|
|
|
case DST_TRUE:
|
2017-02-09 20:02:59 +00:00
|
|
|
return 0;
|
2017-09-09 18:39:51 +00:00
|
|
|
case DST_REAL:
|
2017-11-06 03:05:47 +00:00
|
|
|
|
|
|
|
/* Check for nans to ensure total order */
|
2017-11-28 23:27:55 +00:00
|
|
|
if (dst_unwrap_real(x) != dst_unwrap_real(x))
|
|
|
|
return dst_unwrap_real(y) != dst_unwrap_real(y)
|
2017-11-06 03:05:47 +00:00
|
|
|
? 0
|
|
|
|
: -1;
|
2017-11-28 23:27:55 +00:00
|
|
|
if (dst_unwrap_real(y) != dst_unwrap_real(y))
|
2017-11-06 03:05:47 +00:00
|
|
|
return 1;
|
|
|
|
|
2017-11-28 23:27:55 +00:00
|
|
|
if (dst_unwrap_real(x) == dst_unwrap_real(y)) {
|
2017-02-09 20:02:59 +00:00
|
|
|
return 0;
|
|
|
|
} else {
|
2017-11-28 23:27:55 +00:00
|
|
|
return dst_unwrap_real(x) > dst_unwrap_real(y) ? 1 : -1;
|
2017-04-24 20:02:54 +00:00
|
|
|
}
|
2017-09-09 18:39:51 +00:00
|
|
|
case DST_INTEGER:
|
2017-11-28 23:27:55 +00:00
|
|
|
if (dst_unwrap_integer(x) == dst_unwrap_integer(y)) {
|
2017-04-24 20:02:54 +00:00
|
|
|
return 0;
|
|
|
|
} else {
|
2017-11-28 23:27:55 +00:00
|
|
|
return dst_unwrap_integer(x) > dst_unwrap_integer(y) ? 1 : -1;
|
2017-02-09 20:02:59 +00:00
|
|
|
}
|
2017-09-09 18:39:51 +00:00
|
|
|
case DST_STRING:
|
2017-11-28 23:27:55 +00:00
|
|
|
return dst_string_compare(dst_unwrap_string(x), dst_unwrap_string(y));
|
2017-09-09 18:39:51 +00:00
|
|
|
case DST_TUPLE:
|
2017-11-28 23:27:55 +00:00
|
|
|
return dst_tuple_compare(dst_unwrap_tuple(x), dst_unwrap_tuple(y));
|
2017-11-27 19:03:34 +00:00
|
|
|
case DST_STRUCT:
|
2017-11-28 23:27:55 +00:00
|
|
|
return dst_struct_compare(dst_unwrap_struct(x), dst_unwrap_struct(y));
|
2017-02-19 16:19:39 +00:00
|
|
|
default:
|
2017-11-28 23:27:55 +00:00
|
|
|
if (dst_unwrap_string(x) == dst_unwrap_string(y)) {
|
2017-02-09 20:02:59 +00:00
|
|
|
return 0;
|
|
|
|
} else {
|
2017-11-28 23:27:55 +00:00
|
|
|
return dst_unwrap_string(x) > dst_unwrap_string(y) ? 1 : -1;
|
2017-02-09 20:02:59 +00:00
|
|
|
}
|
|
|
|
}
|
2017-11-28 23:27:55 +00:00
|
|
|
} else if (dst_type(x) < dst_type(y)) {
|
2017-02-09 20:02:59 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
2017-11-25 04:17:04 +00:00
|
|
|
|
2017-11-27 00:31:40 +00:00
|
|
|
/* Get a value out af an associated data structure. For invalid
|
|
|
|
* data structure or invalid key, returns nil. */
|
2018-01-06 16:09:15 +00:00
|
|
|
Dst dst_get(Dst ds, Dst key) {
|
2017-11-28 23:27:55 +00:00
|
|
|
switch (dst_type(ds)) {
|
2017-11-25 04:17:04 +00:00
|
|
|
case DST_ARRAY:
|
2017-11-28 23:27:55 +00:00
|
|
|
if (dst_checktype(key, DST_INTEGER) &&
|
|
|
|
dst_unwrap_integer(key) >= 0 &&
|
|
|
|
dst_unwrap_integer(key) < dst_unwrap_array(ds)->count)
|
|
|
|
return dst_unwrap_array(ds)->data[dst_unwrap_integer(key)];
|
2017-11-25 04:17:04 +00:00
|
|
|
break;
|
|
|
|
case DST_TUPLE:
|
2017-11-28 23:27:55 +00:00
|
|
|
if (dst_checktype(key, DST_INTEGER) &&
|
|
|
|
dst_unwrap_integer(key) >= 0 &&
|
|
|
|
dst_unwrap_integer(key) < dst_tuple_length(dst_unwrap_tuple(ds)))
|
|
|
|
return dst_unwrap_tuple(ds)[dst_unwrap_integer(key)];
|
2017-11-25 04:17:04 +00:00
|
|
|
break;
|
|
|
|
case DST_BUFFER:
|
2017-11-28 23:27:55 +00:00
|
|
|
if (dst_checktype(key, DST_INTEGER) &&
|
|
|
|
dst_unwrap_integer(key) >= 0 &&
|
|
|
|
dst_unwrap_integer(key) < dst_unwrap_buffer(ds)->count)
|
|
|
|
return dst_wrap_integer(dst_unwrap_buffer(ds)->data[dst_unwrap_integer(key)]);
|
2017-11-25 04:17:04 +00:00
|
|
|
break;
|
|
|
|
case DST_STRING:
|
|
|
|
case DST_SYMBOL:
|
2017-11-28 23:27:55 +00:00
|
|
|
if (dst_checktype(key, DST_INTEGER) &&
|
|
|
|
dst_unwrap_integer(key) >= 0 &&
|
|
|
|
dst_unwrap_integer(key) < dst_string_length(dst_unwrap_string(ds)))
|
|
|
|
return dst_wrap_integer(dst_unwrap_string(ds)[dst_unwrap_integer(key)]);
|
2017-11-25 04:17:04 +00:00
|
|
|
break;
|
|
|
|
case DST_STRUCT:
|
2017-11-28 23:27:55 +00:00
|
|
|
return dst_struct_get(dst_unwrap_struct(ds), key);
|
2017-11-25 04:17:04 +00:00
|
|
|
case DST_TABLE:
|
2017-11-28 23:27:55 +00:00
|
|
|
return dst_table_get(dst_unwrap_table(ds), key);
|
2017-11-25 04:17:04 +00:00
|
|
|
default:
|
2017-11-27 00:31:40 +00:00
|
|
|
break;
|
2017-11-25 04:17:04 +00:00
|
|
|
}
|
2017-11-27 00:31:40 +00:00
|
|
|
return dst_wrap_nil();
|
2017-11-25 04:17:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Set a value in an associative data structure. Returns possible
|
|
|
|
* error message, and NULL if no error. */
|
2018-01-06 16:09:15 +00:00
|
|
|
void dst_put(Dst ds, Dst key, Dst value) {
|
2017-11-28 23:27:55 +00:00
|
|
|
switch (dst_type(ds)) {
|
2017-11-25 04:17:04 +00:00
|
|
|
case DST_ARRAY:
|
2017-11-28 23:27:55 +00:00
|
|
|
if (dst_checktype(key, DST_INTEGER) &&
|
|
|
|
dst_unwrap_integer(key) >= 0 &&
|
|
|
|
dst_unwrap_integer(key) < dst_unwrap_array(ds)->count)
|
|
|
|
dst_unwrap_array(ds)->data[dst_unwrap_integer(key)] = value;
|
2017-11-27 00:31:40 +00:00
|
|
|
return;
|
2017-11-25 04:17:04 +00:00
|
|
|
case DST_BUFFER:
|
2017-11-28 23:27:55 +00:00
|
|
|
if (dst_checktype(key, DST_INTEGER) &&
|
|
|
|
dst_checktype(value, DST_INTEGER) &&
|
|
|
|
dst_unwrap_integer(key) >= 0 &&
|
|
|
|
dst_unwrap_integer(key) < dst_unwrap_buffer(ds)->count)
|
|
|
|
dst_unwrap_buffer(ds)->data[dst_unwrap_integer(key)] = dst_unwrap_integer(value);
|
2017-11-27 00:31:40 +00:00
|
|
|
return;
|
2017-11-25 04:17:04 +00:00
|
|
|
case DST_TABLE:
|
2017-11-28 23:27:55 +00:00
|
|
|
dst_table_put(dst_unwrap_table(ds), key, value);
|
2017-11-27 00:31:40 +00:00
|
|
|
return;
|
2017-11-25 04:17:04 +00:00
|
|
|
default:
|
2017-11-27 00:31:40 +00:00
|
|
|
return;
|
2017-11-25 04:17:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the next key in an associative data structure. Used for iterating through an
|
|
|
|
* associative data structure. */
|
2018-01-06 16:09:15 +00:00
|
|
|
const DstKV *dst_next(Dst ds, const DstKV *kv) {
|
2017-11-28 23:27:55 +00:00
|
|
|
switch(dst_type(ds)) {
|
2017-11-25 04:17:04 +00:00
|
|
|
default:
|
2018-01-05 21:17:55 +00:00
|
|
|
return NULL;
|
2017-11-25 04:17:04 +00:00
|
|
|
case DST_TABLE:
|
2018-01-05 21:17:55 +00:00
|
|
|
return (const DstKV *) dst_table_next(dst_unwrap_table(ds), kv);
|
2017-11-25 04:17:04 +00:00
|
|
|
case DST_STRUCT:
|
2018-01-05 21:17:55 +00:00
|
|
|
return dst_struct_next(dst_unwrap_struct(ds), kv);
|
2017-11-25 04:17:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the length of an object. Returns errors for invalid types */
|
2018-01-06 16:09:15 +00:00
|
|
|
int32_t dst_length(Dst x) {
|
2017-11-28 23:27:55 +00:00
|
|
|
switch (dst_type(x)) {
|
2017-11-25 04:17:04 +00:00
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
case DST_STRING:
|
2017-11-28 23:27:55 +00:00
|
|
|
return dst_string_length(dst_unwrap_string(x));
|
2017-11-25 04:17:04 +00:00
|
|
|
case DST_ARRAY:
|
2017-11-28 23:27:55 +00:00
|
|
|
return dst_unwrap_array(x)->count;
|
2017-11-25 04:17:04 +00:00
|
|
|
case DST_BUFFER:
|
2017-11-28 23:27:55 +00:00
|
|
|
return dst_unwrap_buffer(x)->count;
|
2017-11-25 04:17:04 +00:00
|
|
|
case DST_TUPLE:
|
2017-11-28 23:27:55 +00:00
|
|
|
return dst_tuple_length(dst_unwrap_tuple(x));
|
2017-11-25 04:17:04 +00:00
|
|
|
case DST_STRUCT:
|
2017-11-28 23:27:55 +00:00
|
|
|
return dst_struct_length(dst_unwrap_struct(x));
|
2017-11-25 04:17:04 +00:00
|
|
|
case DST_TABLE:
|
2017-11-28 23:27:55 +00:00
|
|
|
return dst_unwrap_table(x)->count;
|
2017-11-25 04:17:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the capacity of an object. Returns 0 for invalid types */
|
2018-01-06 16:09:15 +00:00
|
|
|
int32_t dst_capacity(Dst x) {
|
2017-11-28 23:27:55 +00:00
|
|
|
switch (dst_type(x)) {
|
2017-11-25 04:17:04 +00:00
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
case DST_STRING:
|
2017-11-28 23:27:55 +00:00
|
|
|
return dst_string_length(dst_unwrap_string(x));
|
2017-11-25 04:17:04 +00:00
|
|
|
case DST_ARRAY:
|
2017-11-28 23:27:55 +00:00
|
|
|
return dst_unwrap_array(x)->capacity;
|
2017-11-25 04:17:04 +00:00
|
|
|
case DST_BUFFER:
|
2017-11-28 23:27:55 +00:00
|
|
|
return dst_unwrap_buffer(x)->capacity;
|
2017-11-25 04:17:04 +00:00
|
|
|
case DST_TUPLE:
|
2017-11-28 23:27:55 +00:00
|
|
|
return dst_tuple_length(dst_unwrap_tuple(x));
|
2017-11-25 04:17:04 +00:00
|
|
|
case DST_STRUCT:
|
2017-11-28 23:27:55 +00:00
|
|
|
return dst_struct_length(dst_unwrap_struct(x));
|
2017-11-25 04:17:04 +00:00
|
|
|
case DST_TABLE:
|
2017-11-28 23:27:55 +00:00
|
|
|
return dst_unwrap_table(x)->capacity;
|
2017-11-25 04:17:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-04 02:36:10 +00:00
|
|
|
/* Index into a data structure. Returns nil for out of bounds or invlalid data structure */
|
2018-01-06 16:09:15 +00:00
|
|
|
Dst dst_getindex(Dst ds, int32_t index) {
|
2017-11-28 23:27:55 +00:00
|
|
|
switch (dst_type(ds)) {
|
2017-11-25 04:17:04 +00:00
|
|
|
default:
|
|
|
|
return dst_wrap_nil();
|
|
|
|
case DST_STRING:
|
2017-11-28 23:27:55 +00:00
|
|
|
if (index >= dst_string_length(dst_unwrap_string(ds))) return dst_wrap_nil();
|
|
|
|
return dst_wrap_integer(dst_unwrap_string(ds)[index]);
|
2017-11-25 04:17:04 +00:00
|
|
|
case DST_ARRAY:
|
2017-11-28 23:27:55 +00:00
|
|
|
if (index >= dst_unwrap_array(ds)->count) return dst_wrap_nil();
|
|
|
|
return dst_unwrap_array(ds)->data[index];
|
2017-11-25 04:17:04 +00:00
|
|
|
case DST_BUFFER:
|
2017-11-28 23:27:55 +00:00
|
|
|
if (index >= dst_unwrap_buffer(ds)->count) return dst_wrap_nil();
|
|
|
|
return dst_wrap_integer(dst_unwrap_buffer(ds)->data[index]);
|
2017-11-25 04:17:04 +00:00
|
|
|
case DST_TUPLE:
|
2017-11-28 23:27:55 +00:00
|
|
|
if (index >= dst_tuple_length(dst_unwrap_tuple(ds))) return dst_wrap_nil();
|
|
|
|
return dst_unwrap_tuple(ds)[index];
|
2017-11-25 04:17:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set an index in a linear data structure. Does nothing if data structure
|
|
|
|
* is invalid */
|
2018-01-06 16:09:15 +00:00
|
|
|
void dst_setindex(Dst ds, Dst value, int32_t index) {
|
2017-11-28 23:27:55 +00:00
|
|
|
switch (dst_type(ds)) {
|
2017-11-25 04:17:04 +00:00
|
|
|
default:
|
|
|
|
return;
|
|
|
|
case DST_ARRAY:
|
2017-11-28 23:27:55 +00:00
|
|
|
if (index >= dst_unwrap_array(ds)->count) {
|
|
|
|
dst_array_ensure(dst_unwrap_array(ds), 2 * index);
|
|
|
|
dst_unwrap_array(ds)->count = index + 1;
|
2017-11-25 04:17:04 +00:00
|
|
|
}
|
2017-11-28 23:27:55 +00:00
|
|
|
dst_unwrap_array(ds)->data[index] = value;
|
2017-11-25 04:17:04 +00:00
|
|
|
return;
|
|
|
|
case DST_BUFFER:
|
2017-11-28 23:27:55 +00:00
|
|
|
if (!dst_checktype(value, DST_INTEGER)) return;
|
|
|
|
if (index >= dst_unwrap_buffer(ds)->count) {
|
|
|
|
dst_buffer_ensure(dst_unwrap_buffer(ds), 2 * index);
|
|
|
|
dst_unwrap_buffer(ds)->count = index + 1;
|
2017-11-25 04:17:04 +00:00
|
|
|
}
|
2017-11-28 23:27:55 +00:00
|
|
|
dst_unwrap_buffer(ds)->data[index] = dst_unwrap_integer(value);
|
2017-11-25 04:17:04 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|