Matt Coles 8 anos atrás
pai
commit
db96312cee
4 arquivos alterados com 11 adições e 7 exclusões
  1. 2 2
      cw/main.c
  2. 2 1
      cw/simple.c
  3. 2 2
      cw/tests/twice.c
  4. 5 2
      cw/tests/var_maths.c

+ 2 - 2
cw/main.c

@@ -256,7 +256,6 @@ BIND* recursive_interpret(NODE *tree, ENV *env_ptr) {
256 256
       if(debug)printf("I got: ");
257 257
       if (var_bind->tree->type == CONSTANT) {
258 258
         if(debug){
259
-          printf("CONSTANT\n");
260 259
           print_leaf(var_bind->tree, 0);
261 260
         }
262 261
       } else {
@@ -315,6 +314,7 @@ BIND* recursive_interpret(NODE *tree, ENV *env_ptr) {
315 314
       return ret_val;
316 315
     } else {
317 316
       printf("HELP called a function with no return!!\n");
317
+      exit(1);
318 318
     }
319 319
   }
320 320
   if (tree->type == IF) {
@@ -376,7 +376,7 @@ BIND* recursive_interpret(NODE *tree, ENV *env_ptr) {
376 376
     if (debug) printf("Adding %d and %d\n", lhs->value, rhs->value);
377 377
     int result = lhs->value + rhs->value;
378 378
     return anon_binding((NODE*) get_int_token(result));
379
-  }
379
+ }
380 380
   if (tree->type == '-') {
381 381
     TOKEN* lhs = (TOKEN*) recursive_interpret(tree->left, env_ptr)->tree;
382 382
     TOKEN* rhs = (TOKEN*) recursive_interpret(tree->right, env_ptr)->tree;

+ 2 - 1
cw/simple.c

@@ -1,5 +1,6 @@
1 1
 int whammy(int a) {
2
-  return a + 5;
2
+  int x = a;
3
+  return x + 5;
3 4
 }
4 5
 
5 6
 function twice(function f) {

+ 2 - 2
cw/tests/twice.c

@@ -9,8 +9,8 @@ function twice(function f) {
9 9
 }
10 10
 
11 11
 int main() {
12
-  x = twice(whammy);
12
+  doublewhammy = twice(whammy);
13 13
 
14
-  return x(2);
14
+  return doublewhammy(2);
15 15
 }
16 16
 

+ 5 - 2
cw/tests/var_maths.c

@@ -1,6 +1,9 @@
1
-/* ##answer: 11*/
1
+/* ##answer: 30*/
2 2
 int main() {
3 3
   int x = 5;
4
+  int y = x - 4;
5
+  int z = 10 - x;
6
+  int w = x % z;
4 7
 
5
-  return x + 3 * 2;
8
+  return x*x + z / (w + y);
6 9
 }