Remove unneeded debug output from the runtime.
This commit is contained in:
parent
521004084e
commit
c3d4ef22ce
21
runtime.c
21
runtime.c
|
@ -52,31 +52,26 @@ void stack_free(struct stack* stack) {
|
|||
}
|
||||
|
||||
void stack_push(struct stack* stack, struct node_parent* node) {
|
||||
printf("push\n");
|
||||
assert(stack->count < stack->size);
|
||||
stack->data[stack->count++] = node;
|
||||
}
|
||||
|
||||
struct node_parent* stack_peek(struct stack* stack, int32_t offset) {
|
||||
printf("peek %d\n", offset);
|
||||
assert(offset + 1 <= stack->count);
|
||||
return stack->data[stack->count - offset - 1];
|
||||
}
|
||||
|
||||
struct node_parent* stack_pop(struct stack* stack) {
|
||||
printf("pop\n");
|
||||
assert(stack->count > 0);
|
||||
return stack->data[--stack->count];
|
||||
}
|
||||
|
||||
void stack_popn(struct stack* stack, int32_t count) {
|
||||
printf("popn %d\n", count);
|
||||
assert(stack->count >= count);
|
||||
stack->count -= count;
|
||||
}
|
||||
|
||||
void stack_update(struct stack* stack, int32_t offset) {
|
||||
printf("update %d\n", offset);
|
||||
assert(stack->count >= offset + 2);
|
||||
struct node_ind* to_replace = (struct node_ind*) stack->data[stack->count - 1 - 1 - offset];
|
||||
to_replace->tag = 3;
|
||||
|
@ -92,7 +87,6 @@ void stack_alloc(struct stack* stack, int32_t count) {
|
|||
}
|
||||
|
||||
void stack_slide(struct stack* stack, int32_t count) {
|
||||
printf("slide %d\n", count);
|
||||
assert(stack->count > count);
|
||||
stack->data[stack->count - 1 - count] = stack->data[stack->count - 1];
|
||||
stack->count -= count;
|
||||
|
@ -108,7 +102,6 @@ int32_t stack_size(struct stack* stack) {
|
|||
}
|
||||
|
||||
struct node_parent* malloc_node_num(int32_t value) {
|
||||
printf("alloc int %d\n", value);
|
||||
struct node_num* node = malloc(sizeof(struct node_app));
|
||||
node->tag = 0;
|
||||
node->value = value;
|
||||
|
@ -116,7 +109,6 @@ struct node_parent* malloc_node_num(int32_t value) {
|
|||
}
|
||||
|
||||
struct node_parent* malloc_node_app(struct node_parent* left, struct node_parent* right) {
|
||||
printf("alloc app\n");
|
||||
struct node_app* node = malloc(sizeof(struct node_app));
|
||||
node->tag = 1;
|
||||
node->left = left;
|
||||
|
@ -124,7 +116,6 @@ struct node_parent* malloc_node_app(struct node_parent* left, struct node_parent
|
|||
return (struct node_parent*) node;
|
||||
}
|
||||
struct node_parent* malloc_node_global(int32_t arity, void (*function)(struct stack*)) {
|
||||
printf("alloc global %d %p\n", arity, function);
|
||||
struct node_global* node = malloc(sizeof(struct node_app));
|
||||
node->tag = 2;
|
||||
node->arity = arity;
|
||||
|
@ -132,14 +123,12 @@ struct node_parent* malloc_node_global(int32_t arity, void (*function)(struct st
|
|||
return (struct node_parent*) node;
|
||||
}
|
||||
struct node_parent* malloc_node_indirect(struct node_parent* target) {
|
||||
printf("alloc ind\n");
|
||||
struct node_ind* node = malloc(sizeof(struct node_app));
|
||||
node->tag = 3;
|
||||
node->next = target;
|
||||
return (struct node_parent*) node;
|
||||
}
|
||||
struct node_parent* malloc_node_data(char tag, struct node_parent** array) {
|
||||
printf("alloc data %d\n", tag);
|
||||
struct node_data* node = malloc(sizeof(struct node_data));
|
||||
node->tag = 4;
|
||||
node->ctag = tag;
|
||||
|
@ -154,12 +143,10 @@ void unwind(struct stack* stack) {
|
|||
if(node->tag == 0 || node->tag == 4) {
|
||||
return;
|
||||
} else if(node->tag == 1) {
|
||||
printf("unwind\n");
|
||||
stack_push(stack, ((struct node_app*) node)->left);
|
||||
} else if(node->tag == 2) {
|
||||
struct node_global* global = (struct node_global*) node;
|
||||
if(stack->size > global->arity) {
|
||||
printf("making call\n");
|
||||
struct node_parent* root = stack_peek(stack, global->arity);
|
||||
stack_popn(stack, global->arity + 1);
|
||||
stack_push(stack, root);
|
||||
|
@ -168,15 +155,12 @@ void unwind(struct stack* stack) {
|
|||
stack_push(stack, app->right);
|
||||
root = app->left;
|
||||
}
|
||||
printf("calling supercomb\n");
|
||||
global->function(stack);
|
||||
} else {
|
||||
printf("underflow\n");
|
||||
stack_popn(stack, stack_size(stack) - 1);
|
||||
return;
|
||||
}
|
||||
} else if(node->tag == 3) {
|
||||
printf("handling indirection\n");
|
||||
struct node_ind* ind = (struct node_ind*) node;
|
||||
stack_pop(stack);
|
||||
stack_push(stack, ind->next);
|
||||
|
@ -185,7 +169,6 @@ void unwind(struct stack* stack) {
|
|||
}
|
||||
|
||||
struct node_parent* pack(struct stack* stack, char tag, int count) {
|
||||
printf("pack %d %d\n", tag, count);
|
||||
assert(stack->count >= count);
|
||||
struct node_parent** new_array = malloc(sizeof(struct node_parent*) * count);
|
||||
struct node_parent** current_slot = new_array;
|
||||
|
@ -200,7 +183,6 @@ struct node_parent* pack(struct stack* stack, char tag, int count) {
|
|||
|
||||
void split(struct stack* stack, struct node_parent* node, int count) {
|
||||
assert(stack->count > 0);
|
||||
printf("split %d\n", count);
|
||||
struct node_data* data = (struct node_data*) node;
|
||||
while(count > 0) {
|
||||
stack_push(stack, data->array[count - 1]);
|
||||
|
@ -211,7 +193,6 @@ void split(struct stack* stack, struct node_parent* node, int count) {
|
|||
struct node_parent* eval(struct node_parent* start) {
|
||||
struct stack new_stack;
|
||||
stack_init(&new_stack);
|
||||
printf("eval begin\n");
|
||||
stack_push(&new_stack, start);
|
||||
unwind(&new_stack);
|
||||
struct node_parent* final_node = stack_pop(&new_stack);
|
||||
|
@ -224,6 +205,6 @@ extern void main_supercomb(struct stack* stack);
|
|||
int main(int argc, char** argv) {
|
||||
struct node_parent* result = eval(malloc_node_global(0, main_supercomb));
|
||||
if(result->tag == 0) {
|
||||
printf("integer generated! value: %d\n", ((struct node_num*)result)->value);
|
||||
printf("result was a number: %d\n", ((struct node_num*) result)->value);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user