1
0
mirror of https://github.com/janet-lang/janet synced 2025-10-21 18:57:41 +00:00

Allow parser to parse files rather than just a repl. I think

there are some memory leak issues (problems with gc).
This commit is contained in:
Calvin Rose
2017-04-17 00:15:18 -04:00
parent f456de5fac
commit f52e290206
11 changed files with 162 additions and 142 deletions

View File

@@ -88,7 +88,7 @@ static const char *gst_deserialize_impl(
#define deser_assert(c, e) do{if(!(c))deser_error(e);}while(0)
/* Assert enough buffer */
#define deser_datacheck(len) do{if (end - data < (len)) deser_error(UEB);}while(0)
#define deser_datacheck(len) do{if (end < (data + len)) deser_error(UEB);}while(0)
/* Check for enough space to read uint32_t */
#define read_u32(out) do{deser_datacheck(4); (out)=bytes2u32(data); data += 4; }while(0)
@@ -485,6 +485,19 @@ const char *gst_serialize_impl(
write_byte(x.data.string[i]);
}
break;
case GST_STRUCT:
write_byte(206);
count = gst_struct_length(x.data.st);
write_u32(count);
for (i = 0; i < gst_struct_capacity(x.data.st); i += 2) {
if (x.data.st[i].type != GST_NIL) {
err = gst_serialize_impl(vm, buffer, visited, nextId, x.data.st[i]);
if (err != NULL) return err;
err = gst_serialize_impl(vm, buffer, visited, nextId, x.data.st[i + 1]);
if (err != NULL) return err;
}
}
break;
case GST_BYTEBUFFER:
write_byte(207);
count = x.data.buffer->count;