Mercurial > repos > rhope
comparison runtime/context.c @ 12:31f8182f3433
Finished fib test and did some small work on the c backend
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Mon, 25 May 2009 23:34:36 -0400 |
parents | 8d74ef7fa357 |
children | 640f541e9116 |
comparison
equal
deleted
inserted
replaced
11:3021dac0d8f5 | 12:31f8182f3433 |
---|---|
29 if(size > STACK_CHUNK_SIZE) | 29 if(size > STACK_CHUNK_SIZE) |
30 return NULL; | 30 return NULL; |
31 while(current && STACK_CHUNK_SIZE - current->used < size) | 31 while(current && STACK_CHUNK_SIZE - current->used < size) |
32 { | 32 { |
33 if(!current->next) | 33 if(!current->next) |
34 { | |
34 current->next = new_stack(); | 35 current->next = new_stack(); |
36 current->next->prev = current; | |
37 } | |
35 current = current->next; | 38 current = current->next; |
36 } | 39 } |
37 if(!current) | 40 if(!current) |
38 return NULL; | 41 return NULL; |
39 ct->current_stack = current; | 42 ct->current_stack = current; |
51 } | 54 } |
52 | 55 |
53 void free_stack(context * ct, void * data) | 56 void free_stack(context * ct, void * data) |
54 { | 57 { |
55 char * cdata = data; | 58 char * cdata = data; |
56 if(cdata < ct->current_stack->data || cdata >= ct->current_stack->data+STACK_CHUNK_SIZE) { | 59 while(cdata < ct->current_stack->data || cdata >= ct->current_stack->data+STACK_CHUNK_SIZE) { |
57 fputs("Tried to free stack data from outside of current stack chunk!", stderr); | 60 if(ct->current_stack == ct->stack_begin) |
58 exit(-1); | 61 { |
62 fprintf(stderr, "Attempt to free memory at %X using free_stack, but %X doesn't appear to be stack allocated\n", data, data); | |
63 exit(-1); | |
64 } | |
65 ct->current_stack->used = 0; | |
66 ct->current_stack = ct->current_stack->prev; | |
59 } | 67 } |
60 ct->current_stack->used = cdata-ct->current_stack->data; | 68 ct->current_stack->used = cdata-ct->current_stack->data; |
61 if(!ct->current_stack->used && ct->current_stack->prev) | 69 if(!ct->current_stack->used && ct->current_stack->prev) |
62 ct->current_stack = ct->current_stack->prev; | 70 ct->current_stack = ct->current_stack->prev; |
63 } | 71 } |