aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYann Herklotz <ymherklotz@gmail.com>2017-03-19 22:14:18 +0000
committerYann Herklotz <ymherklotz@gmail.com>2017-03-19 22:14:18 +0000
commitf2a7153067561a82f5aaf9edd1cb9e01ee12cb6b (patch)
treeb5f19e340297815855f3be9d0813735c0cc97f48
parent5bb277cc67c7c3fa8fa3024f1ed3da81a71636e2 (diff)
downloadCompiler-f2a7153067561a82f5aaf9edd1cb9e01ee12cb6b.tar.gz
Compiler-f2a7153067561a82f5aaf9edd1cb9e01ee12cb6b.zip
Completely working recursion and with correct frame
-rw-r--r--.gitignore3
-rw-r--r--c_compiler/src/expression.cpp1
-rw-r--r--c_compiler/src/function.cpp2
-rw-r--r--c_compiler/test/in/recursion.c13
-rw-r--r--vgcore.8901bin21749760 -> 0 bytes
5 files changed, 10 insertions, 9 deletions
diff --git a/.gitignore b/.gitignore
index aae6581..994633a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -25,3 +25,6 @@ out/
# emacs temp files
.#*
+
+
+vgcore.*
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);
}
diff --git a/vgcore.8901 b/vgcore.8901
deleted file mode 100644
index 7785ee3..0000000
--- a/vgcore.8901
+++ /dev/null
Binary files differ