1
0
mirror of https://github.com/janet-lang/janet synced 2025-10-31 07:33:01 +00:00
Fix compiler bug when compiling desturctured bindings in a top-level
def or var. Also introduce janet_table_clone API call to make this
easier.
This commit is contained in:
Calvin Rose
2019-07-07 23:18:39 -05:00
parent 044fc7c461
commit affcb5b459
4 changed files with 33 additions and 7 deletions

View File

@@ -208,6 +208,18 @@ const JanetKV *janet_table_to_struct(JanetTable *t) {
return janet_struct_end(st);
}
/* Clone a table. */
JanetTable *janet_table_clone(JanetTable *table) {
JanetTable *newTable = janet_gcalloc(JANET_MEMORY_TABLE, sizeof(JanetTable));
memcpy(newTable, table, sizeof(JanetTable));
newTable->data = malloc(newTable->capacity * sizeof(JanetKV));
if (NULL == newTable->data) {
JANET_OUT_OF_MEMORY;
}
memcpy(newTable->data, table->data, table->capacity * sizeof(JanetKV));
return newTable;
}
/* Merge a table or struct into a table */
static void janet_table_mergekv(JanetTable *table, const JanetKV *kvs, int32_t cap) {
int32_t i;