diff options
Diffstat (limited to 'src/program.c')
-rw-r--r-- | src/program.c | 46 |
1 files changed, 25 insertions, 21 deletions
diff --git a/src/program.c b/src/program.c index 3be7c67..efb9407 100644 --- a/src/program.c +++ b/src/program.c @@ -299,7 +299,7 @@ TslProgramResult tsl_program_run(TslProgram *self) { stack_value.data.number = instruction_type2->value; stack_value.type = TSL_STACK_VALUE_TYPE_NUMBER; cleanup_if_error(tsl_buffer_append(&self->stack_values, &stack_value, sizeof(stack_value))); - printf("loadn %f\n", instruction_type2->value); + /*printf("loadn %f\n", instruction_type2->value);*/ instruction += sizeof(TslInstructionType2); break; } @@ -308,7 +308,7 @@ TslProgramResult tsl_program_run(TslProgram *self) { stack_value.data.boolean = instruction_type3->value; stack_value.type = TSL_STACK_VALUE_TYPE_BOOL; cleanup_if_error(tsl_buffer_append(&self->stack_values, &stack_value, sizeof(stack_value))); - printf("loadb %s\n", instruction_type3->value ? "true" : "false"); + /*printf("loadb %s\n", instruction_type3->value ? "true" : "false");*/ instruction += sizeof(TslInstructionType3); break; } @@ -317,7 +317,7 @@ TslProgramResult tsl_program_run(TslProgram *self) { stack_value.data.str = instruction_type4->value; stack_value.type = TSL_STACK_VALUE_TYPE_STRING; cleanup_if_error(tsl_buffer_append(&self->stack_values, &stack_value, sizeof(stack_value))); - printf("loads \"%.*s\"\n", (int)instruction_type4->value.size, instruction_type4->value.data); + /*printf("loads \"%.*s\"\n", (int)instruction_type4->value.size, instruction_type4->value.data);*/ instruction += sizeof(TslInstructionType4); break; } @@ -326,7 +326,7 @@ TslProgramResult tsl_program_run(TslProgram *self) { stack_value.data.integer = instruction_type1->value; stack_value.type = TSL_STACK_VALUE_TYPE_FUNCTION; cleanup_if_error(tsl_buffer_append(&self->stack_values, &stack_value, sizeof(stack_value))); - printf("loadf %d\n", instruction_type1->value); + /*printf("loadf %d\n", instruction_type1->value);*/ instruction += sizeof(TslInstructionType1); break; } @@ -335,7 +335,7 @@ TslProgramResult tsl_program_run(TslProgram *self) { stack_value.data.str = instruction_type4->value; stack_value.type = TSL_STACK_VALUE_TYPE_VARIABLE_NAME; cleanup_if_error(tsl_buffer_append(&self->stack_values, &stack_value, sizeof(stack_value))); - printf("loadv \"%.*s\"\n", (int)instruction_type4->value.size, instruction_type4->value.data); + /*printf("loadv \"%.*s\"\n", (int)instruction_type4->value.size, instruction_type4->value.data);*/ instruction += sizeof(TslInstructionType4); break; } @@ -343,7 +343,7 @@ TslProgramResult tsl_program_run(TslProgram *self) { TslStackValue stack_value; stack_value.type = TSL_STACK_VALUE_TYPE_NULL; cleanup_if_error(tsl_buffer_append(&self->stack_values, &stack_value, sizeof(stack_value))); - printf("loadnull\n"); + /*printf("loadnull\n");*/ instruction += sizeof(TslInstructionType5); break; } @@ -358,7 +358,7 @@ TslProgramResult tsl_program_run(TslProgram *self) { cleanup_if_error(map_value); cleanup_if_error(tsl_value_create_from_stack_value(self, stack_value, map_value)); - printf("setv \"%.*s\"\n", (int)instruction_type4->value.size, instruction_type4->value.data); + /*printf("setv \"%.*s\"\n", (int)instruction_type4->value.size, instruction_type4->value.data);*/ instruction += sizeof(TslInstructionType4); break; } @@ -367,7 +367,7 @@ TslProgramResult tsl_program_run(TslProgram *self) { stack_value.data.integer = instruction_type1->value; stack_value.type = TSL_STACK_VALUE_TYPE_LIST; cleanup_if_error(tsl_buffer_append(&self->stack_values, &stack_value, sizeof(stack_value))); - printf("list %d\n", instruction_type1->value); + /*printf("list %d\n", instruction_type1->value);*/ instruction += sizeof(TslInstructionType1); break; } @@ -376,7 +376,7 @@ TslProgramResult tsl_program_run(TslProgram *self) { stack_value.data.integer = instruction_type1->value; stack_value.type = TSL_STACK_VALUE_TYPE_MAP; cleanup_if_error(tsl_buffer_append(&self->stack_values, &stack_value, sizeof(stack_value))); - printf("map %d\n", instruction_type1->value); + /*printf("map %d\n", instruction_type1->value);*/ instruction += sizeof(TslInstructionType1); break; } @@ -384,7 +384,7 @@ TslProgramResult tsl_program_run(TslProgram *self) { TslStackValue stack_value; stack_value.type = TSL_STACK_VALUE_TYPE_INDEX; cleanup_if_error(tsl_buffer_append(&self->stack_values, &stack_value, sizeof(stack_value))); - printf("mindex\n"); + /*printf("mindex\n");*/ instruction += sizeof(TslInstructionType5); break; } @@ -393,7 +393,7 @@ TslProgramResult tsl_program_run(TslProgram *self) { TslStackValue *args = tsl_buffer_pop(&self->stack_values, sizeof(TslStackValue) * (1 + instruction_type1->value)); (void)args; /* TODO: Implement this */ - printf("callf %d\n", instruction_type1->value); + /*printf("callf %d\n", instruction_type1->value);*/ instruction += sizeof(TslInstructionType1); break; } @@ -409,25 +409,25 @@ TslProgramResult tsl_program_run(TslProgram *self) { stack_value.type = TSL_STACK_VALUE_TYPE_VARIABLE; cleanup_if_error(tsl_buffer_append(&self->stack_values, &stack_value, sizeof(stack_value))); - printf("add\n"); + /*printf("add\n");*/ instruction += sizeof(TslInstructionType5); break; } case TSL_OPCODE_SUB: { cleanup_if_error(tsl_program_perform_operation(self, number_operation_sub)); - printf("sub\n"); + /*printf("sub\n");*/ instruction += sizeof(TslInstructionType5); break; } case TSL_OPCODE_MUL: { cleanup_if_error(tsl_program_perform_operation(self, number_operation_mul)); - printf("mul\n"); + /*printf("mul\n");*/ instruction += sizeof(TslInstructionType5); break; } case TSL_OPCODE_DIV: { cleanup_if_error(tsl_program_perform_operation(self, number_operation_div)); - printf("div\n"); + /*printf("div\n");*/ instruction += sizeof(TslInstructionType5); break; } @@ -436,7 +436,7 @@ TslProgramResult tsl_program_run(TslProgram *self) { stack_value.data.str = instruction_type4->value; stack_value.type = TSL_STACK_VALUE_TYPE_COMMAND_ARG; cleanup_if_error(tsl_buffer_append(&self->stack_values, &stack_value, sizeof(stack_value))); - printf("loadca \"%.*s\"\n", (int)instruction_type4->value.size, instruction_type4->value.data); + /*printf("loadca \"%.*s\"\n", (int)instruction_type4->value.size, instruction_type4->value.data);*/ instruction += sizeof(TslInstructionType4); break; } @@ -451,19 +451,19 @@ TslProgramResult tsl_program_run(TslProgram *self) { { /* TODO: Support infinite amount of args */ assert(args_end - args_begin < 255); - printf("Running command: "); + /*printf("Running command: ");*/ while(arg != args_end) { assert(arg->type == TSL_STACK_VALUE_TYPE_COMMAND_ARG); temp_null_save[arg_index] = arg->data.str.data[arg->data.str.size]; arg->data.str.data[arg->data.str.size] = '\0'; command_args[arg_index] = arg->data.str.data; - printf("%s ", command_args[arg_index]); + /*printf("%s ", command_args[arg_index]);*/ ++arg_index; ++arg; } command_args[arg_index] = NULL; - printf("\n"); + /*printf("\n");*/ } tsl_command_exec(command_args, program_output_temp, NULL); @@ -480,7 +480,7 @@ TslProgramResult tsl_program_run(TslProgram *self) { command_args[arg_index] = NULL; } - printf("callc %d\n", instruction_type1->value); + /*printf("callc %d\n", instruction_type1->value);*/ instruction += sizeof(TslInstructionType1); break; } @@ -488,7 +488,11 @@ TslProgramResult tsl_program_run(TslProgram *self) { } cleanup: - assert(self->stack_values.size == 0); /* All push instructions (mostly load) haven't been handled yet. This is a bug in the compiler */ + /* + If self->stack_values.size is more than 0, then there are operations (for example CALLF) that pushes a value to the stack but the returned value + is not assigned to any variable. At the end of functions, these stack values are cleaned up even if they are not handled. + */ + tsl_buffer_deinit(&self->stack_values); GC_FREE(self->variables); /* Free the root object, resulting in all objects in the program being free'd */ self->variables = NULL; |