diff options
author | Yann Herklotz <ymherklotz@gmail.com> | 2017-03-19 22:14:18 +0000 |
---|---|---|
committer | Yann Herklotz <ymherklotz@gmail.com> | 2017-03-19 22:14:18 +0000 |
commit | f2a7153067561a82f5aaf9edd1cb9e01ee12cb6b (patch) | |
tree | b5f19e340297815855f3be9d0813735c0cc97f48 /c_compiler | |
parent | 5bb277cc67c7c3fa8fa3024f1ed3da81a71636e2 (diff) | |
download | Compiler-f2a7153067561a82f5aaf9edd1cb9e01ee12cb6b.tar.gz Compiler-f2a7153067561a82f5aaf9edd1cb9e01ee12cb6b.zip |
Completely working recursion and with correct frame
Diffstat (limited to 'c_compiler')
-rw-r--r-- | c_compiler/src/expression.cpp | 1 | ||||
-rw-r--r-- | c_compiler/src/function.cpp | 2 | ||||
-rw-r--r-- | c_compiler/test/in/recursion.c | 13 |
3 files changed, 7 insertions, 9 deletions
diff --git a/c_compiler/src/expression.cpp b/c_compiler/src/expression.cpp index e19d845..98ca018 100644 --- a/c_compiler/src/expression.cpp +++ b/c_compiler/src/expression.cpp @@ -146,6 +146,7 @@ VariableStackBindings PostfixFunctionCall::printAsm(VariableStackBindings bindin } std::cout << "\tjal\t" << postfix_expression_->id() << "\n\tnop\n"; + std::cout << "\tsw\t$2," << bindings.currentExpressionStackPosition() << "($fp)\n"; return bindings; } diff --git a/c_compiler/src/function.cpp b/c_compiler/src/function.cpp index 55d8a2c..35e02f4 100644 --- a/c_compiler/src/function.cpp +++ b/c_compiler/src/function.cpp @@ -59,8 +59,6 @@ VariableStackBindings Function::printAsm(VariableStackBindings bindings, unsigne unsigned max_depth = 0; statement_->countExpressionDepth(max_depth); - std::cout << "# max depth: " << max_depth << "\n"; - if(max_argument_count < 4) max_argument_count = 4; diff --git a/c_compiler/test/in/recursion.c b/c_compiler/test/in/recursion.c index 3c16e33..8a1a170 100644 --- a/c_compiler/test/in/recursion.c +++ b/c_compiler/test/in/recursion.c @@ -1,13 +1,12 @@ int fact(int n) { - if(n <= 1) { - return 1; - } else { - int x = fact(n-1); - return x * n; - } + if(n <= 1) { + return 1; + } else { + return fact(n-1) * n; + } } int main() { - return fact(5); + return fact(5); } |