From 51b8b275fd330b9dc58017ca6f2e60f319af635c Mon Sep 17 00:00:00 2001 From: Jeremiah Orians Date: Fri, 17 Aug 2018 04:55:56 -0400 Subject: [PATCH] More cleaning to simplify assembly bootstrap --- CHANGELOG.org | 2 ++ cc_core.c | 44 +++++++++++++++++---------------------- test/test.answers | 2 +- test/test100/proof.answer | 2 +- 4 files changed, 23 insertions(+), 27 deletions(-) diff --git a/CHANGELOG.org b/CHANGELOG.org index acf86d8..51fb7c3 100644 --- a/CHANGELOG.org +++ b/CHANGELOG.org @@ -25,6 +25,8 @@ Reorganized Collect_local to better match implementation Broke out process_break Changed ordering in declare_function to reduce stack operations Converted weird_string collection into a simpler form +Inlined 2 small stubs as breaking them out wouldn't help implementation +Reordered conditionals for easier implementation and reduced operations ** Fixed Fixed detection of locals to screen out all non-primitive name space collisions diff --git a/cc_core.c b/cc_core.c index b98aa56..070fbf6 100644 --- a/cc_core.c +++ b/cc_core.c @@ -426,23 +426,6 @@ struct token_list* unary_expr_sizeof(struct token_list* out) return out; } -struct token_list* postfix_expr(struct token_list* out, struct token_list* function); -struct token_list* unary_expr_not(struct token_list* out, struct token_list* function) -{ - out = emit("LOAD_IMMEDIATE_eax %1\n", out); - out = common_recursion(out, function, postfix_expr); - out = emit("XOR_ebx_eax_into_eax\n", out); - return out; -} - -struct token_list* unary_expr_negation(struct token_list* out, struct token_list* function) -{ - out = emit("LOAD_IMMEDIATE_eax %0\n", out); - out = common_recursion(out, function, primary_expr); - out = emit("SUBTRACT_eax_from_ebx_into_ebx\nMOVE_ebx_to_eax\n", out); - return out; -} - struct token_list* postfix_expr_stub(struct token_list* out, struct token_list* function) { if(match("[", global_token->s)) @@ -562,19 +545,29 @@ struct token_list* bitwise_expr(struct token_list* out, struct token_list* funct struct token_list* primary_expr(struct token_list* out, struct token_list* function) { - if(match("-", global_token->s)) out = unary_expr_negation(out, function); - else if(match("!", global_token->s)) out = unary_expr_not(out, function); - else if(match("sizeof", global_token->s)) out = unary_expr_sizeof(out); + if(match("sizeof", global_token->s)) out = unary_expr_sizeof(out); + else if('-' == global_token->s[0]) + { + out = emit("LOAD_IMMEDIATE_eax %0\n", out); + out = common_recursion(out, function, primary_expr); + out = emit("SUBTRACT_eax_from_ebx_into_ebx\nMOVE_ebx_to_eax\n", out); + } + else if('!' == global_token->s[0]) + { + out = emit("LOAD_IMMEDIATE_eax %1\n", out); + out = common_recursion(out, function, postfix_expr); + out = emit("XOR_ebx_eax_into_eax\n", out); + } else if(global_token->s[0] == '(') { global_token = global_token->next; out = expression(out, function); require_match("Error in Primary expression\nDidn't get )\n", ")"); } - else if((('a' <= global_token->s[0]) && (global_token->s[0] <= 'z')) || (('A' <= global_token->s[0]) && (global_token->s[0] <= 'Z'))) out = primary_expr_variable(out, function); - else if(('0' <= global_token->s[0]) && (global_token->s[0] <= '9')) out = primary_expr_number(out); else if(global_token->s[0] == '\'') out = primary_expr_char(out); else if(global_token->s[0] == '"') out = primary_expr_string(out, function); + else if(in_set(global_token->s[0], "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_")) out = primary_expr_variable(out, function); + else if(in_set(global_token->s[0], "0123456789")) out = primary_expr_number(out); else primary_expr_failure(); return out; } @@ -585,17 +578,18 @@ struct token_list* expression(struct token_list* out, struct token_list* functio if(match("=", global_token->s)) { char* store; - if(match("]", global_token->prev->s) && match("char*", current_target->name)) + if(!match("]", global_token->prev->s) || !match("char*", current_target->name)) { - store = "STORE_CHAR\n"; + store = "STORE_INTEGER\n"; } else { - store = "STORE_INTEGER\n"; + store = "STORE_CHAR\n"; } out = common_recursion(out, function, expression); out = emit(store, out); + current_target = NULL; } return out; } diff --git a/test/test.answers b/test/test.answers index c5d3e11..de41cec 100644 --- a/test/test.answers +++ b/test/test.answers @@ -9,7 +9,7 @@ b45fae655b7f848b28ebdb8eb2e30ae789fbcf7920bc315395d53986bb1adae4 test/results/t d511db73158a9544a5b5f828a79751e3de8a04b81c143fd0c146fc22c938aa9f test/results/test08-binary 907e1808f2e2b15ac72ebf13898b15c678e68ebd43d673dcd0f408d907e7962f test/results/test09-binary ef179cd359ba1d61d45089e314cd4ac2069c8dc4dd7494d7c766344ea3c8cf88 test/results/test10-binary -fb2de146153e048c787807b58938a5e8cce689fa14961012eb5d60e48d3b221f test/results/test100-binary +ad7b4ade77bd67ff27fcb1618a2d5ffab2c30b8001cf0a87f6454788eb776b4c test/results/test100-binary 5aaf399fe706d4a8c85c121c75ada29a65c293b57c98e8999961a2ef0bab0d62 test/results/test11-binary 4f8111e73e07255ae203963438c82ea8bcff7474e1594b52b426c58a03cb30eb test/results/test12-binary dd74dabfdce8657ff440c1eef531cbf67a64854f2020d4d6bcb65c9cc2d199cb test/results/test13-binary diff --git a/test/test100/proof.answer b/test/test100/proof.answer index 4417380..dad4ecc 100644 --- a/test/test100/proof.answer +++ b/test/test100/proof.answer @@ -1 +1 @@ -c8256bddd114b551cdc173b7b46bc043bb85cbd48d8505a79d11cd3d2d7ae3b2 test/test100/proof +43e93076637d39751dbfbe2e32c0200dc99e51c4a993ce7720193bc651220515 test/test100/proof