diff runtime/context.c @ 66:d4b44ae2e34a

New variant of C backend works now
author Mike Pavone <pavone@retrodev.com>
date Sun, 06 Jun 2010 20:29:10 -0400
parents 04baa003de5a
children d1569087348f
line wrap: on
line diff
--- a/runtime/context.c	Tue Jun 01 01:13:54 2010 -0400
+++ b/runtime/context.c	Sun Jun 06 20:29:10 2010 -0400
@@ -19,18 +19,18 @@
 	c->stack_begin = new_stack();
 	c->current_stack = c->stack_begin;
 	return c;
-}
-
-void free_context(context * c)
-{
-	stackchunk *next,*current = c->stack_begin;
-	while(current)
-	{
-		next = current->next;
-		free(current);
-		current = next;
-	}
-	free(c);
+}
+
+void free_context(context * c)
+{
+	stackchunk *next,*current = c->stack_begin;
+	while(current)
+	{
+		next = current->next;
+		free(current);
+		current = next;
+	}
+	free(c);
 }
 
 void * alloc_stack(context * ct, uint32_t size)
@@ -64,8 +64,12 @@
 
 calldata * alloc_cdata(context * ct, calldata * lastframe, uint32_t num_params)
 {
-	calldata * retval = (calldata *)(((char *)alloc_stack(ct, sizeof(calldata)+(num_params-1)*sizeof(object *))) + sizeof(object *)*(num_params-1));
+	//Make sure we have enough space for at least 32 return values
+	calldata * retval = alloc_stack(ct, sizeof(calldata)+(31)*sizeof(object *));
+	//But only actually reserve space for the number requested
+	free_stack(ct, retval->params + num_params);
 	retval->lastframe = lastframe;
+	retval->callspace = num_params;
 	return retval;
 }