compilation error fix and added the ability to build a runtime using an external heap object
This commit is contained in:
@@ -111,6 +111,8 @@ Object *Object_SliceBuffer(Object *buffer, int offset, int length, Heap *heap, E
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BufferSliceObject *slice;
|
||||||
|
|
||||||
if(buffer->type == &t_buffer)
|
if(buffer->type == &t_buffer)
|
||||||
{
|
{
|
||||||
BufferObject *original = (BufferObject*) buffer;
|
BufferObject *original = (BufferObject*) buffer;
|
||||||
@@ -118,7 +120,7 @@ Object *Object_SliceBuffer(Object *buffer, int offset, int length, Heap *heap, E
|
|||||||
if(offset == 0 && length == original->size)
|
if(offset == 0 && length == original->size)
|
||||||
return buffer;
|
return buffer;
|
||||||
|
|
||||||
BufferSliceObject *slice = (BufferSliceObject*) Heap_Malloc(heap, &t_buffer_slice, error);
|
slice = (BufferSliceObject*) Heap_Malloc(heap, &t_buffer_slice, error);
|
||||||
|
|
||||||
if(slice == NULL)
|
if(slice == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -149,7 +151,7 @@ Object *Object_SliceBuffer(Object *buffer, int offset, int length, Heap *heap, E
|
|||||||
{
|
{
|
||||||
assert(buffer->type == &t_buffer_slice);
|
assert(buffer->type == &t_buffer_slice);
|
||||||
|
|
||||||
BufferSliceObject *slice = (BufferSliceObject*) Heap_Malloc(heap, &t_buffer_slice, error);
|
slice = (BufferSliceObject*) Heap_Malloc(heap, &t_buffer_slice, error);
|
||||||
|
|
||||||
if(slice == NULL)
|
if(slice == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|||||||
+19
-19
@@ -18,6 +18,7 @@ struct xFrame {
|
|||||||
struct xRuntime {
|
struct xRuntime {
|
||||||
void *callback_userp;
|
void *callback_userp;
|
||||||
_Bool (*callback_addr)(Runtime*, void*);
|
_Bool (*callback_addr)(Runtime*, void*);
|
||||||
|
_Bool free_heap;
|
||||||
Object *builtins;
|
Object *builtins;
|
||||||
int depth;
|
int depth;
|
||||||
Frame *frame;
|
Frame *frame;
|
||||||
@@ -84,30 +85,16 @@ Executable *Runtime_GetCurrentExecutable(Runtime *runtime)
|
|||||||
return runtime->frame->exe;
|
return runtime->frame->exe;
|
||||||
}
|
}
|
||||||
|
|
||||||
Runtime *Runtime_New(int stack_size, int heap_size, void *callback_userp, _Bool (*callback_addr)(Runtime*, void*))
|
Runtime *Runtime_New2(int stack_size, Heap *heap, _Bool free_heap, void *callback_userp, _Bool (*callback_addr)(Runtime*, void*))
|
||||||
{
|
{
|
||||||
if(stack_size < 0)
|
if(stack_size < 0)
|
||||||
stack_size = 1024;
|
stack_size = 1024;
|
||||||
|
|
||||||
if(heap_size < 0)
|
Runtime *runtime = malloc(sizeof(Runtime));
|
||||||
heap_size = 65536;
|
|
||||||
|
|
||||||
Runtime *runtime;
|
|
||||||
|
|
||||||
|
if(runtime != NULL)
|
||||||
{
|
{
|
||||||
runtime = malloc(sizeof(Runtime));
|
runtime->heap = heap;
|
||||||
|
|
||||||
if(runtime == NULL)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
runtime->heap = Heap_New(heap_size);
|
|
||||||
|
|
||||||
if(runtime->heap == NULL)
|
|
||||||
{
|
|
||||||
free(runtime);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
runtime->stack = Stack_New(stack_size);
|
runtime->stack = Stack_New(stack_size);
|
||||||
|
|
||||||
if(runtime->stack == NULL)
|
if(runtime->stack == NULL)
|
||||||
@@ -116,19 +103,32 @@ Runtime *Runtime_New(int stack_size, int heap_size, void *callback_userp, _Bool
|
|||||||
free(runtime);
|
free(runtime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
runtime->free_heap = free_heap;
|
||||||
runtime->callback_userp = callback_userp;
|
runtime->callback_userp = callback_userp;
|
||||||
runtime->callback_addr = callback_addr;
|
runtime->callback_addr = callback_addr;
|
||||||
runtime->builtins = NULL;
|
runtime->builtins = NULL;
|
||||||
runtime->frame = NULL;
|
runtime->frame = NULL;
|
||||||
runtime->depth = 0;
|
runtime->depth = 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return runtime;
|
return runtime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Runtime *Runtime_New(int stack_size, int heap_size, void *callback_userp, _Bool (*callback_addr)(Runtime*, void*))
|
||||||
|
{
|
||||||
|
if(heap_size < 0)
|
||||||
|
heap_size = 65536;
|
||||||
|
|
||||||
|
Heap *heap = Heap_New(heap_size);
|
||||||
|
|
||||||
|
if(heap == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
return Runtime_New2(stack_size, heap, 1, callback_userp, callback_addr);
|
||||||
|
}
|
||||||
void Runtime_Free(Runtime *runtime)
|
void Runtime_Free(Runtime *runtime)
|
||||||
{
|
{
|
||||||
|
if(runtime->free_heap)
|
||||||
Heap_Free(runtime->heap);
|
Heap_Free(runtime->heap);
|
||||||
Stack_Free(runtime->stack);
|
Stack_Free(runtime->stack);
|
||||||
free(runtime);
|
free(runtime);
|
||||||
|
|||||||
Reference in New Issue
Block a user