diff options
author | Camil Staps | 2016-09-25 00:05:07 +0200 |
---|---|---|
committer | Camil Staps | 2016-09-25 00:05:07 +0200 |
commit | 1cd75335f0878864acb89d9a2818a971701ef680 (patch) | |
tree | 349382d6882cf239461d518ff78f2c8a81e73569 | |
parent | Made parse_file implementation dependent (diff) |
Cleanup: unsigned -> bool (stdbool.h)
-rw-r--r-- | interpreter/eval.c | 11 | ||||
-rw-r--r-- | interpreter/graphs.c | 2 | ||||
-rw-r--r-- | interpreter/graphs.h | 3 | ||||
-rw-r--r-- | interpreter/lex.c | 9 | ||||
-rw-r--r-- | interpreter/print.c | 10 | ||||
-rw-r--r-- | interpreter/syntax.c | 4 | ||||
-rw-r--r-- | interpreter/syntax.h | 6 |
7 files changed, 24 insertions, 21 deletions
diff --git a/interpreter/eval.c b/interpreter/eval.c index fda5697..f37039b 100644 --- a/interpreter/eval.c +++ b/interpreter/eval.c @@ -1,5 +1,6 @@ #include "eval.h" +#include <stdbool.h> #include <string.h> #include "code.h" @@ -20,7 +21,7 @@ typedef struct replacements { struct replacements* rest; } replacements; -void eval(fuspel* rules, struct node** node, unsigned to_rnf); +void eval(fuspel* rules, struct node** node, bool to_rnf); void push_repl(replacements* repls, char* name, struct node* node) { while (repls->rest) repls = repls->rest; @@ -115,7 +116,7 @@ struct node*** flatten_app_args(struct node** from) { return result; } -unsigned match_expr(fuspel* rules, expression* expr, struct node** node, +bool match_expr(fuspel* rules, expression* expr, struct node** node, replacements* repls) { replacements* _repls; for (_repls = repls; _repls->rest; _repls = _repls->rest); @@ -202,7 +203,7 @@ int match_rule(fuspel* rules, rewrite_rule* rule, struct node** node, } } -unsigned is_code_app(struct node* node) { +bool is_code_app(struct node* node) { for (; node->kind == NODE_APP; node = node->var1); return node->kind == NODE_CODE; } @@ -240,9 +241,9 @@ void eval_code_app(fuspel* rules, struct node** node) { struct node** root_node; #endif -void eval(fuspel* rules, struct node** node, unsigned to_rnf) { +void eval(fuspel* rules, struct node** node, bool to_rnf) { fuspel* _rules; - unsigned rerun; + bool rerun; replacements* repls; if (!node || !*node) diff --git a/interpreter/graphs.c b/interpreter/graphs.c index 1f0dcb4..3871a50 100644 --- a/interpreter/graphs.c +++ b/interpreter/graphs.c @@ -27,7 +27,7 @@ void use_node(struct node* node, unsigned int count) { } } -void free_node(struct node* node, unsigned int count, unsigned free_first) { +void free_node(struct node* node, unsigned int count, bool free_first) { if (!node) return; diff --git a/interpreter/graphs.h b/interpreter/graphs.h index 0cebe9e..a577095 100644 --- a/interpreter/graphs.h +++ b/interpreter/graphs.h @@ -1,6 +1,7 @@ #ifndef _H_GRAPHS #define _H_GRAPHS +#include <stdbool.h> #include "syntax.h" typedef enum { @@ -22,7 +23,7 @@ struct node { }; void use_node(struct node* node, unsigned int count); -void free_node(struct node* node, unsigned int count, unsigned free_first); +void free_node(struct node* node, unsigned int count, bool free_first); void remove_redirects(struct node *node); diff --git a/interpreter/lex.c b/interpreter/lex.c index 94820ca..ecf681f 100644 --- a/interpreter/lex.c +++ b/interpreter/lex.c @@ -1,14 +1,15 @@ #include "lex.h" +#include <stdbool.h> #include <string.h> #include "mem.h" -inline unsigned is_space_char(char input) { +inline bool is_space_char(char input) { return input == '\t' || input == ' ' || input == '\n' || input == '\r'; } -inline unsigned is_int_char(char input) { +inline bool is_int_char(char input) { return '0' <= input && input <= '9'; } @@ -19,7 +20,7 @@ unsigned char lex_int_length(char* input) { return n; } -inline unsigned is_name_char(char input) { +inline bool is_name_char(char input) { return (('A' <= input && input <= 'Z') || ('a' <= input && input <= 'z') || input == '_'); @@ -34,7 +35,7 @@ unsigned char lex_name_length(char* input) { token_list* lex(token_list* list, char* input) { token_list* first_list; - unsigned create_new_token; + bool create_new_token; while (*input && is_space_char(*input)) input++; if (*input == 0) { diff --git a/interpreter/print.c b/interpreter/print.c index bb6c03e..78976c2 100644 --- a/interpreter/print.c +++ b/interpreter/print.c @@ -1,9 +1,8 @@ #include "print.h" -#include <stdio.h> - #ifdef _FUSPEL_DEBUG #include <inttypes.h> +#include <stdbool.h> #endif #include "log.h" @@ -139,7 +138,7 @@ void push_visited_node(struct visited_nodes *list, struct node *node) { list->next->node = node; } -unsigned visited_node_exists(struct visited_nodes *list, struct node *node) { +bool visited_node_exists(struct visited_nodes *list, struct node *node) { while (list) { if (list->node == node) return 1; @@ -149,8 +148,8 @@ unsigned visited_node_exists(struct visited_nodes *list, struct node *node) { } void print_node_to_file(struct node* node, FILE* f, struct visited_nodes *visited) { - unsigned close = 0; - unsigned do_free_visited = 0; + bool close = 0; + bool do_free_visited = 0; if (visited_node_exists(visited, node)) return; @@ -164,7 +163,6 @@ void print_node_to_file(struct node* node, FILE* f, struct visited_nodes *visite if (!f) { char fname[20]; - printf(" === Drawing graph %d ===\n", file_count); sprintf(fname, "graph-%03u.dot", file_count++); f = fopen(fname, "w"); fprintf(f, "digraph {\n"); diff --git a/interpreter/syntax.c b/interpreter/syntax.c index 03bc2d4..81d9493 100644 --- a/interpreter/syntax.c +++ b/interpreter/syntax.c @@ -16,7 +16,7 @@ void free_token_list(token_list* list) { my_free(list->rest); } -unsigned empty_args_list(arg_list* list) { +bool empty_args_list(arg_list* list) { return !list; } @@ -59,7 +59,7 @@ void cpy_expression(expression* dst, expression* src) { } } -unsigned eq_expression(expression* a, expression* b) { +bool eq_expression(expression* a, expression* b) { if (a->kind != b->kind) return 0; diff --git a/interpreter/syntax.h b/interpreter/syntax.h index 0944842..0333013 100644 --- a/interpreter/syntax.h +++ b/interpreter/syntax.h @@ -1,6 +1,8 @@ #ifndef _H_SYNTAX #define _H_SYNTAX +#include <stdbool.h> + /* TOKENS */ typedef enum { @@ -65,11 +67,11 @@ typedef struct fuspel { struct fuspel* rest; } fuspel; -unsigned empty_args_list(arg_list*); +bool empty_args_list(arg_list*); unsigned char len_arg_list(arg_list*); void cpy_expression(expression* dst, expression* src); -unsigned eq_expression(expression*, expression*); +bool eq_expression(expression*, expression*); void concat_fuspel(fuspel* start, fuspel* end); fuspel* push_fuspel(fuspel*); |