mirror of
https://github.com/janet-lang/janet
synced 2025-08-05 21:43:55 +00:00
Fix serilaization bug. Still need to serialize c functions.
This commit is contained in:
parent
145688b49f
commit
f066047112
3
.vscode/settings.json
vendored
Normal file
3
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
// Place your settings in this file to overwrite default and user settings.
|
||||
{
|
||||
}
|
@ -339,7 +339,7 @@ static const char *gst_deserialize_impl(
|
||||
if (err != NULL) return err;
|
||||
}
|
||||
read_u32(byteCodeLen);
|
||||
deser_datacheck(byteCodeLen);
|
||||
deser_datacheck(byteCodeLen * sizeof(uint16_t));
|
||||
def->byteCode = gst_alloc(vm, byteCodeLen * sizeof(uint16_t));
|
||||
def->byteCodeLen = byteCodeLen;
|
||||
for (i = 0; i < byteCodeLen; ++i) {
|
||||
@ -412,8 +412,12 @@ static const char *gst_deserialize_impl(
|
||||
|
||||
case 216: /* C function */
|
||||
/* TODO - add registry for c functions */
|
||||
read_u32(length);
|
||||
/* For now just add 64 bit integer */
|
||||
{
|
||||
int64_t rawp;
|
||||
read_i64(rawp);
|
||||
ret.type = GST_NIL;
|
||||
}
|
||||
break;
|
||||
|
||||
case 217: /* Reference */
|
||||
@ -443,7 +447,6 @@ const char *gst_deserialize(
|
||||
const char *err;
|
||||
GstArray *visited = gst_array(vm, 10);
|
||||
err = gst_deserialize_impl(vm, data, data + len, nextData, visited, &ret);
|
||||
printf("Read %ld\n", *nextData - data);
|
||||
if (err != NULL) return err;
|
||||
*out = ret;
|
||||
return NULL;
|
||||
@ -453,7 +456,7 @@ const char *gst_deserialize(
|
||||
BUFFER_DEFINE(real, GstReal)
|
||||
BUFFER_DEFINE(integer, GstInteger)
|
||||
BUFFER_DEFINE(u32, uint32_t)
|
||||
BUFFER_DEFINE(u16, uint32_t)
|
||||
BUFFER_DEFINE(u16, uint16_t)
|
||||
|
||||
/* Serialize a value and write to a buffer. Returns possible
|
||||
* error messages. */
|
||||
@ -541,13 +544,13 @@ const char *gst_serialize_impl(
|
||||
if (err != NULL) return err;
|
||||
}
|
||||
}
|
||||
/* Record reference */
|
||||
/* Record reference after serialization */
|
||||
gst_table_put(vm, visited, x, gst_wrap_integer(*nextId));
|
||||
*nextId = *nextId + 1;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Record reference */
|
||||
/* Record reference before serialization */
|
||||
gst_table_put(vm, visited, x, gst_wrap_integer(*nextId));
|
||||
*nextId = *nextId + 1;
|
||||
|
||||
|
@ -162,6 +162,9 @@ int gst_stl_length(Gst *vm) {
|
||||
case GST_STRUCT:
|
||||
ret.data.integer = gst_struct_length(x.data.st);
|
||||
break;
|
||||
case GST_FUNCDEF:
|
||||
ret.data.integer = x.data.def->byteCodeLen;
|
||||
break;
|
||||
}
|
||||
gst_c_return(vm, ret);
|
||||
}
|
||||
@ -404,8 +407,9 @@ int gst_stl_thread(Gst *vm) {
|
||||
GstThread *t;
|
||||
GstValue callee = gst_arg(vm, 0);
|
||||
if (callee.type != GST_FUNCTION && callee.type != GST_CFUNCTION)
|
||||
gst_c_throwc(vm, "expected function");
|
||||
gst_c_throwc(vm, "expected function in thread constructor");
|
||||
t = gst_thread(vm, callee, 10);
|
||||
t->parent = vm->thread;
|
||||
gst_c_return(vm, gst_wrap_thread(t));
|
||||
}
|
||||
|
||||
|
@ -41,7 +41,7 @@ GstThread *gst_thread(Gst *vm, GstValue callee, uint32_t capacity) {
|
||||
gst_frame_env(stack) = NULL;
|
||||
gst_frame_callee(stack) = callee;
|
||||
gst_thread_endframe(vm, thread);
|
||||
thread->parent = vm->thread;
|
||||
thread->parent = NULL; /* Need to set parent manually */
|
||||
return thread;
|
||||
}
|
||||
|
||||
@ -143,8 +143,6 @@ void gst_thread_endframe(Gst *vm, GstThread *thread) {
|
||||
gst_thread_pushnil(vm, thread, locals - gst_frame_size(stack));
|
||||
}
|
||||
}
|
||||
stack = thread->data + thread->count;
|
||||
gst_frame_args(stack) = gst_frame_size(stack) + GST_FRAME_SIZE;
|
||||
}
|
||||
}
|
||||
|
||||
|
21
core/vm.c
21
core/vm.c
@ -397,14 +397,6 @@ int gst_continue(Gst *vm) {
|
||||
if (vm->thread->parent == NULL)
|
||||
return GST_RETURN_ERROR;
|
||||
vm->thread = vm->thread->parent;
|
||||
while (vm->thread->count < GST_FRAME_SIZE) {
|
||||
if (vm->thread->parent) {
|
||||
vm->thread->status = GST_THREAD_DEAD;
|
||||
vm->thread = vm->thread->parent;
|
||||
} else {
|
||||
return GST_RETURN_ERROR;
|
||||
}
|
||||
}
|
||||
stack = vm->thread->data + vm->thread->count;
|
||||
stack[gst_frame_ret(stack)] = vm->ret;
|
||||
pc = gst_frame_pc(stack);
|
||||
@ -424,21 +416,16 @@ int gst_continue(Gst *vm) {
|
||||
/* Run the vm with a given function. This function is
|
||||
* called to start the vm. */
|
||||
int gst_run(Gst *vm, GstValue callee) {
|
||||
int status;
|
||||
GstValue *stack;
|
||||
vm->thread = gst_thread(vm, callee, 64);
|
||||
if (vm->thread == NULL)
|
||||
return GST_RETURN_CRASH;
|
||||
stack = gst_thread_stack(vm->thread);
|
||||
/* If callee was not actually a function, get the delegate function */
|
||||
callee = gst_frame_callee(stack);
|
||||
if (callee.type == GST_CFUNCTION) {
|
||||
vm->ret.type = GST_NIL;
|
||||
status = callee.data.cfunction(vm);
|
||||
gst_thread_popframe(vm, vm->thread);
|
||||
return status;
|
||||
} else {
|
||||
return callee.data.cfunction(vm);
|
||||
} else if (callee.type == GST_FUNCTION) {
|
||||
return gst_continue(vm);
|
||||
} else {
|
||||
return GST_RETURN_CRASH;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user