diff --git a/cc_core.c b/cc_core.c index c9b5875..ed6b550 100644 --- a/cc_core.c +++ b/cc_core.c @@ -122,12 +122,17 @@ struct token_list* function_call(struct token_list* out, struct token_list* func require_match("ERROR in process_expression_list\nNo ) was found\n", ")"); - if(bool) + if(2 == bool) + { + struct token_list* a = sym_lookup(s, function->locals); + out = emit(prepend_string("LOAD_EFFECTIVE_ADDRESS %", numerate_number(stack_index(a, function))), out); + out = emit("LOAD_INTEGER\nCALL_eax\n", out); + } + else if(1 == bool) { struct token_list* a = sym_lookup(s, function->arguments); out = emit(prepend_string("LOAD_EFFECTIVE_ADDRESS %", numerate_number(stack_index(a, function))), out); - out = emit("LOAD_INTEGER\n", out); - out = emit("CALL_eax\n", out); + out = emit("LOAD_INTEGER\nCALL_eax\n", out); } else { @@ -154,6 +159,16 @@ struct token_list* sym_get_value(char *s, struct token_list* out, struct token_l a= sym_lookup(s, function->locals); if(NULL != a) { + if(match("FUNCTION", a->type->name)) + { + if(!match("(", global_token->s)) + { + out = emit(prepend_string("#Loading address of function\nLOAD_EFFECTIVE_ADDRESS %", numerate_number(stack_index(a, function))), out); + out = emit("LOAD_INTEGER\n", out); + return out; + } + return function_call(out, function, s, 2); + } current_target = a->type; out = emit(prepend_string("LOAD_EFFECTIVE_ADDRESS %", numerate_number(stack_index(a, function))), out); if(!match("=", global_token->s)) out = emit("LOAD_INTEGER\x0A", out); @@ -172,7 +187,7 @@ struct token_list* sym_get_value(char *s, struct token_list* out, struct token_l out = emit("LOAD_INTEGER\n", out); return out; } - return function_call(out, function, s, TRUE); + return function_call(out, function, s, 1); } out = emit(prepend_string("LOAD_EFFECTIVE_ADDRESS %", numerate_number(stack_index(a, function))), out); if(!match("=", global_token->s) && !match("argv", s)) out = emit("LOAD_INTEGER\x0A", out); @@ -189,7 +204,7 @@ struct token_list* sym_get_value(char *s, struct token_list* out, struct token_l } else { - return function_call(out, function, s, FALSE); + return function_call(out, function, s, 0); } } diff --git a/test/test.answers b/test/test.answers index e36d066..f793ff0 100644 --- a/test/test.answers +++ b/test/test.answers @@ -9,7 +9,7 @@ d27eb315d694324650b11a421d6990eee60ac5921a5625bbccb43d806f09e156 test/results/t 8cc38294fb1261843cfc3956fad5a451c95bbc2ed687435d4e2d59df2c4a8567 test/results/test08-binary cc8f252877a85c0d7832094ff574d7173ac33940917bc1591358b8970651a81c test/results/test09-binary 3857aee4183de41bd00b014d616a5d73f4bfc57aa60a6073bb4113d6ff2fb8d5 test/results/test10-binary -9d70fbcb87a3002f8d6f8831d421926b482544f5363fd291387b57e34fb57f3e test/results/test100-binary +21477d1e283e0ecf4d91b64ce02ca391bbf9b6e4682fc4271028937546bf30b2 test/results/test100-binary dce2f0b35323cf6a2b01f74a9335100f2d8626028af545832dbdb503573db0e5 test/results/test11-binary 88602970fa07b5da7a42b4f2b2486fe03accc6796e05453c4ab934e986790bef test/results/test12-binary c85a57b5b1d65288efd47a3b12c6fca1efade9e7ec91e65efda5531d2c40d293 test/results/test13-binary diff --git a/test/test100/proof.answer b/test/test100/proof.answer index c104982..b887cf4 100644 --- a/test/test100/proof.answer +++ b/test/test100/proof.answer @@ -1 +1 @@ -ebee1401bceb90f543c7656d98264271ce477f527470f5050d5cdb8c8871cb86 test/test100/proof +929105510c8469704ae12dda52afb6a9f3c383e323564d6068021ee1059c6061 test/test100/proof