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;
|
||||
}
|
||||
|
||||
BufferSliceObject *slice;
|
||||
|
||||
if(buffer->type == &t_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)
|
||||
return buffer;
|
||||
|
||||
BufferSliceObject *slice = (BufferSliceObject*) Heap_Malloc(heap, &t_buffer_slice, error);
|
||||
slice = (BufferSliceObject*) Heap_Malloc(heap, &t_buffer_slice, error);
|
||||
|
||||
if(slice == 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);
|
||||
|
||||
BufferSliceObject *slice = (BufferSliceObject*) Heap_Malloc(heap, &t_buffer_slice, error);
|
||||
slice = (BufferSliceObject*) Heap_Malloc(heap, &t_buffer_slice, error);
|
||||
|
||||
if(slice == NULL)
|
||||
return NULL;
|
||||
|
||||
+19
-19
@@ -18,6 +18,7 @@ struct xFrame {
|
||||
struct xRuntime {
|
||||
void *callback_userp;
|
||||
_Bool (*callback_addr)(Runtime*, void*);
|
||||
_Bool free_heap;
|
||||
Object *builtins;
|
||||
int depth;
|
||||
Frame *frame;
|
||||
@@ -84,30 +85,16 @@ Executable *Runtime_GetCurrentExecutable(Runtime *runtime)
|
||||
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)
|
||||
stack_size = 1024;
|
||||
|
||||
if(heap_size < 0)
|
||||
heap_size = 65536;
|
||||
|
||||
Runtime *runtime;
|
||||
Runtime *runtime = malloc(sizeof(Runtime));
|
||||
|
||||
if(runtime != NULL)
|
||||
{
|
||||
runtime = malloc(sizeof(Runtime));
|
||||
|
||||
if(runtime == NULL)
|
||||
return NULL;
|
||||
|
||||
runtime->heap = Heap_New(heap_size);
|
||||
|
||||
if(runtime->heap == NULL)
|
||||
{
|
||||
free(runtime);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
runtime->heap = heap;
|
||||
runtime->stack = Stack_New(stack_size);
|
||||
|
||||
if(runtime->stack == NULL)
|
||||
@@ -116,19 +103,32 @@ Runtime *Runtime_New(int stack_size, int heap_size, void *callback_userp, _Bool
|
||||
free(runtime);
|
||||
}
|
||||
|
||||
runtime->free_heap = free_heap;
|
||||
runtime->callback_userp = callback_userp;
|
||||
runtime->callback_addr = callback_addr;
|
||||
runtime->builtins = NULL;
|
||||
runtime->frame = NULL;
|
||||
runtime->depth = 0;
|
||||
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
if(runtime->free_heap)
|
||||
Heap_Free(runtime->heap);
|
||||
Stack_Free(runtime->stack);
|
||||
free(runtime);
|
||||
|
||||
Reference in New Issue
Block a user