1
0
mirror of https://github.com/janet-lang/janet synced 2024-12-26 00:10:27 +00:00

More work on serializer.

This commit is contained in:
Calvin Rose 2017-05-12 00:03:00 -04:00
parent 58edb63607
commit 145688b49f
2 changed files with 11 additions and 9 deletions

View File

@ -381,13 +381,10 @@ static const char *gst_deserialize_impl(
gst_array_push(vm, visited, ret); gst_array_push(vm, visited, ret);
err = gst_deserialize_impl(vm, data, end, &data, visited, &parent); err = gst_deserialize_impl(vm, data, end, &data, visited, &parent);
if (err != NULL) return err; if (err != NULL) return err;
err = gst_deserialize_impl(vm, data, end, &data, visited, &def);
if (err != NULL) return err;
err = gst_deserialize_impl(vm, data, end, &data, visited, &env); err = gst_deserialize_impl(vm, data, end, &data, visited, &env);
if (err != NULL) return err; if (err != NULL) return err;
printf("parent: %s\n", (const char *)gst_to_string(vm, parent)); err = gst_deserialize_impl(vm, data, end, &data, visited, &def);
printf("def: %s\n", (const char *)gst_to_string(vm, def)); if (err != NULL) return err;
printf("env: %s\n", (const char *)gst_to_string(vm, env));
if (parent.type == GST_NIL) { if (parent.type == GST_NIL) {
ret.data.function->parent = NULL; ret.data.function->parent = NULL;
} else if (parent.type == GST_FUNCTION) { } else if (parent.type == GST_FUNCTION) {
@ -396,7 +393,7 @@ static const char *gst_deserialize_impl(
deser_error("expected function"); deser_error("expected function");
} }
deser_assert(def.type == GST_FUNCDEF, "expected funcdef"); deser_assert(def.type == GST_FUNCDEF, "expected funcdef");
ret.data.function->def = env.data.def; ret.data.function->def = def.data.def;
if (env.type == GST_NIL) { if (env.type == GST_NIL) {
ret.data.function->env = NULL; ret.data.function->env = NULL;
} else { } else {
@ -446,6 +443,7 @@ const char *gst_deserialize(
const char *err; const char *err;
GstArray *visited = gst_array(vm, 10); GstArray *visited = gst_array(vm, 10);
err = gst_deserialize_impl(vm, data, data + len, nextData, visited, &ret); err = gst_deserialize_impl(vm, data, data + len, nextData, visited, &ret);
printf("Read %ld\n", *nextData - data);
if (err != NULL) return err; if (err != NULL) return err;
*out = ret; *out = ret;
return NULL; return NULL;
@ -699,10 +697,10 @@ const char *gst_serialize_impl(
ev = fn->env ? gst_wrap_funcenv(fn->env) : gst_wrap_nil(); ev = fn->env ? gst_wrap_funcenv(fn->env) : gst_wrap_nil();
err = gst_serialize_impl(vm, buffer, visited, nextId, pv); err = gst_serialize_impl(vm, buffer, visited, nextId, pv);
if (err != NULL) return err; if (err != NULL) return err;
err = gst_serialize_impl(vm, buffer, visited, nextId, dv);
if (err != NULL) return err;
err = gst_serialize_impl(vm, buffer, visited, nextId, ev); err = gst_serialize_impl(vm, buffer, visited, nextId, ev);
if (err != NULL) return err; if (err != NULL) return err;
err = gst_serialize_impl(vm, buffer, visited, nextId, dv);
if (err != NULL) return err;
} }
break; break;
} }

View File

@ -14,5 +14,9 @@
(scheck 123412.12) (scheck 123412.12)
(scheck (funcdef (fn [] 1))) (scheck (funcdef (fn [] 1)))
(scheck (funcenv (fn [] 1))) (scheck (funcenv (fn [] 1)))
(scheck (funcenv ((fn [a] (fn [] a)) 1))) (do
(: producer (fn [a] (fn [] a)))
(: f (producer "hello!"))
(scheck (funcenv f))
)
(scheck (fn [] 1)) (scheck (fn [] 1))