diff options
Diffstat (limited to 'interpreter')
| -rw-r--r-- | interpreter/Makefile | 2 | ||||
| -rw-r--r-- | interpreter/eval.c | 15 | ||||
| -rw-r--r-- | interpreter/eval.h | 6 | ||||
| -rw-r--r-- | interpreter/fuspel.c | 17 | 
4 files changed, 34 insertions, 6 deletions
| diff --git a/interpreter/Makefile b/interpreter/Makefile index a1fba34..745b01e 100644 --- a/interpreter/Makefile +++ b/interpreter/Makefile @@ -1,4 +1,4 @@ -override CFLAGS+=-Werror -Wall -Wextra -Wno-missing-field-initializers -O3 -D_FUSPEL_CLI +override CFLAGS+=-Werror -Wall -Wextra -Wno-missing-field-initializers -O3 -D_FUSPEL_CLI -D_FUSPEL_DEBUG  DEPS=fuspel.h lex.h syntax.h print.h parse.h eval.h mem.h code.h graphs.h  OBJ=fuspel.o lex.o syntax.o print.o parse.o eval.o mem.o code.o graphs.o diff --git a/interpreter/eval.c b/interpreter/eval.c index 097dd21..1997d4e 100644 --- a/interpreter/eval.c +++ b/interpreter/eval.c @@ -210,6 +210,7 @@ void eval_code_app(struct fuspel *rules, struct node **node) {  #ifdef _FUSPEL_DEBUG  struct node **root_node; +bool debug_graphs;  #endif  void eval(struct fuspel *rules, struct node **node, bool to_rnf) { @@ -226,7 +227,7 @@ void eval(struct fuspel *rules, struct node **node, bool to_rnf) {  	repls = my_calloc(1, sizeof(struct replacements));  #ifdef _FUSPEL_DEBUG -	if (!root_node) { +	if (!root_node && debug_graphs) {  		root_node = node;  		print_node_to_file(*root_node, NULL, NULL);  	} @@ -235,7 +236,7 @@ void eval(struct fuspel *rules, struct node **node, bool to_rnf) {  	do {  		rerun = 0;  #ifdef _FUSPEL_DEBUG -		print_graph = true; +		print_graph = debug_graphs;  #endif  		switch ((*node)->kind) { @@ -346,10 +347,18 @@ void eval(struct fuspel *rules, struct node **node, bool to_rnf) {  	my_free(repls);  } -struct expression *eval_main(struct fuspel *rules) { +struct expression *eval_main(struct fuspel *rules +#ifdef _FUSPEL_DEBUG +		, bool debug_graphs_enabled +#endif +		) {  	struct node *main_node = my_calloc(1, sizeof(struct node));  	struct expression *expr = my_calloc(1, sizeof(struct expression)); +#ifdef _FUSPEL_DEBUG +	debug_graphs = debug_graphs_enabled; +#endif +  	main_node->kind = EXPR_NAME;  	main_node->used_count = 1;  	main_node->var1 = my_calloc(1, 5); diff --git a/interpreter/eval.h b/interpreter/eval.h index 3561965..7afe56e 100644 --- a/interpreter/eval.h +++ b/interpreter/eval.h @@ -3,6 +3,10 @@  #include "syntax.h" -struct expression *eval_main(struct fuspel*); +struct expression *eval_main(struct fuspel* +#ifdef _FUSPEL_DEBUG +		, bool debug_graphs +#endif +		);  #endif diff --git a/interpreter/fuspel.c b/interpreter/fuspel.c index b9ccd12..736a1c3 100644 --- a/interpreter/fuspel.c +++ b/interpreter/fuspel.c @@ -64,11 +64,17 @@ static char doc[] = "Interpret a fuspel program";  static char args_doc[] = "MODULE [MODULE [MODULE [..]]]";  static struct argp_option options[] = {  	{ "print-program", 'P', 0, 0, "Print the parsed program before execution" }, +#ifdef _FUSPEL_DEBUG +	{ "debug-graphs", 'g', 0, 0, "Make a dot graph after every rewriting step" }, +#endif // _FUSPEL_DEBUG  	{ 0 }  };  struct environment {  	struct fuspel *program;  	bool printProgram; +#ifdef _FUSPEL_DEBUG +	bool debugGraphs; +#endif // _FUSPEL_DEBUG  };  static error_t parse_opt(int key, char *arg, struct argp_state *state) { @@ -77,6 +83,11 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) {  		case 'P':  			env->printProgram = true;  			break; +#ifdef _FUSPEL_DEBUG +		case 'g': +			env->debugGraphs = true; +			break; +#endif // _FUSPEL_DEBUG  		case ARGP_KEY_ARG:  			env->program = import(env->program, arg);  			return 0; @@ -107,7 +118,11 @@ int main(int argc, char *argv[]) {  		printf("\n\n");  	} +#ifdef _FUSPEL_DEBUG +	result = eval_main(env.program, env.debugGraphs); +#else  	result = eval_main(env.program); +#endif  	if (result) {  		print_expression(result);  		printf("\n"); @@ -121,4 +136,4 @@ int main(int argc, char *argv[]) {  	return 0;  } -#endif +#endif // _FUSPEL_CLI | 
