1
0
mirror of https://github.com/janet-lang/janet synced 2025-12-04 07:38:09 +00:00

Add struct type.

This commit is contained in:
Calvin Rose
2017-04-15 16:05:59 -04:00
parent 20bb5a18f7
commit e90b66af58
17 changed files with 613 additions and 436 deletions

View File

@@ -1,5 +1,5 @@
#include <gst/gst.h>
#include "stringcache.h"
#include "cache.h"
/* The metadata header associated with an allocated block of memory */
#define gc_header(mem) ((GCMemoryHeader *)(mem) - 1)
@@ -102,6 +102,16 @@ void gst_mark(Gst *vm, GstValueUnion x, GstType type) {
}
break;
case GST_STRUCT:
if (gc_header(gst_struct_raw(x.st))->color != vm->black) {
uint32_t i, count;
count = gst_struct_capacity(x.st);
gc_header(gst_struct_raw(x.st))->color = vm->black;
for (i = 0; i < count; ++i)
gst_mark_value(vm, x.st[i]);
}
break;
case GST_THREAD:
if (gc_header(x.thread)->color != vm->black) {
GstThread *thread = x.thread;
@@ -185,9 +195,13 @@ void gst_sweep(Gst *vm) {
} else {
vm->blocks = next;
}
/* Remove from string cache */
if (current->tags & GST_MEMTAG_STRING) {
gst_stringcache_remove(vm, (uint8_t *)(current + 1) + 2 * sizeof(uint32_t));
if (current->tags) {
if (current->tags & GST_MEMTAG_STRING)
gst_cache_remove_string(vm, (char *)(current + 1));
if (current->tags & GST_MEMTAG_STRUCT)
gst_cache_remove_struct(vm, (char *)(current + 1));
if (current->tags & GST_MEMTAG_TUPLE)
gst_cache_remove_tuple(vm, (char *)(current + 1));
}
gst_raw_free(current);
} else {