Matt Coles před 8 roky
rodič
revize
9285348596
12 změnil soubory, kde provedl 1253 přidání a 1233 odebrání
  1. 978 1027
      tac/C.tab.c
  2. 47 61
      tac/C.tab.h
  3. 138 124
      tac/lex.yy.c
  4. 8 0
      tac/list.c
  5. 1 0
      tac/list.h
  6. 24 18
      tac/main.c
  7. 7 3
      tac/simple.c
  8. 14 0
      tac/simple.c.orig
  9. 14 0
      tac/simple_BACKUP_41992.c
  10. 6 0
      tac/simple_BASE_41992.c
  11. 6 0
      tac/simple_LOCAL_41992.c
  12. 10 0
      tac/simple_REMOTE_41992.c

Diff nebyl zobrazen, protože je příliš veliký
+ 978 - 1027
tac/C.tab.c


+ 47 - 61
tac/C.tab.h

@@ -1,14 +1,13 @@
1
-/* A Bison parser, made by GNU Bison 2.3.  */
1
+/* A Bison parser, made by GNU Bison 3.0.4.  */
2 2
 
3
-/* Skeleton interface for Bison's Yacc-like parsers in C
3
+/* Bison interface for Yacc-like parsers in C
4 4
 
5
-   Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006
6
-   Free Software Foundation, Inc.
5
+   Copyright (C) 1984, 1989-1990, 2000-2015 Free Software Foundation, Inc.
7 6
 
8
-   This program is free software; you can redistribute it and/or modify
7
+   This program is free software: you can redistribute it and/or modify
9 8
    it under the terms of the GNU General Public License as published by
10
-   the Free Software Foundation; either version 2, or (at your option)
11
-   any later version.
9
+   the Free Software Foundation, either version 3 of the License, or
10
+   (at your option) any later version.
12 11
 
13 12
    This program is distributed in the hope that it will be useful,
14 13
    but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -16,9 +15,7 @@
16 15
    GNU General Public License for more details.
17 16
 
18 17
    You should have received a copy of the GNU General Public License
19
-   along with this program; if not, write to the Free Software
20
-   Foundation, Inc., 51 Franklin Street, Fifth Floor,
21
-   Boston, MA 02110-1301, USA.  */
18
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
22 19
 
23 20
 /* As a special exception, you may create a larger work that contains
24 21
    part or all of the Bison parser skeleton and distribute that work
@@ -33,65 +30,54 @@
33 30
    This special exception was added by the Free Software Foundation in
34 31
    version 2.2 of Bison.  */
35 32
 
36
-/* Tokens.  */
33
+#ifndef YY_YY_C_TAB_H_INCLUDED
34
+# define YY_YY_C_TAB_H_INCLUDED
35
+/* Debug traces.  */
36
+#ifndef YYDEBUG
37
+# define YYDEBUG 1
38
+#endif
39
+#if YYDEBUG
40
+extern int yydebug;
41
+#endif
42
+
43
+/* Token type.  */
37 44
 #ifndef YYTOKENTYPE
38 45
 # define YYTOKENTYPE
39
-   /* Put the tokens into the symbol table, so that GDB and other debuggers
40
-      know about them.  */
41
-   enum yytokentype {
42
-     IDENTIFIER = 258,
43
-     CONSTANT = 259,
44
-     STRING_LITERAL = 260,
45
-     LE_OP = 261,
46
-     GE_OP = 262,
47
-     EQ_OP = 263,
48
-     NE_OP = 264,
49
-     EXTERN = 265,
50
-     AUTO = 266,
51
-     INT = 267,
52
-     VOID = 268,
53
-     FUNCTION = 269,
54
-     APPLY = 270,
55
-     LEAF = 271,
56
-     IF = 272,
57
-     ELSE = 273,
58
-     WHILE = 274,
59
-     CONTINUE = 275,
60
-     BREAK = 276,
61
-     RETURN = 277
62
-   };
46
+  enum yytokentype
47
+  {
48
+    IDENTIFIER = 258,
49
+    CONSTANT = 259,
50
+    STRING_LITERAL = 260,
51
+    LE_OP = 261,
52
+    GE_OP = 262,
53
+    EQ_OP = 263,
54
+    NE_OP = 264,
55
+    EXTERN = 265,
56
+    AUTO = 266,
57
+    INT = 267,
58
+    VOID = 268,
59
+    FUNCTION = 269,
60
+    APPLY = 270,
61
+    LEAF = 271,
62
+    IF = 272,
63
+    ELSE = 273,
64
+    WHILE = 274,
65
+    CONTINUE = 275,
66
+    BREAK = 276,
67
+    RETURN = 277
68
+  };
63 69
 #endif
64
-/* Tokens.  */
65
-#define IDENTIFIER 258
66
-#define CONSTANT 259
67
-#define STRING_LITERAL 260
68
-#define LE_OP 261
69
-#define GE_OP 262
70
-#define EQ_OP 263
71
-#define NE_OP 264
72
-#define EXTERN 265
73
-#define AUTO 266
74
-#define INT 267
75
-#define VOID 268
76
-#define FUNCTION 269
77
-#define APPLY 270
78
-#define LEAF 271
79
-#define IF 272
80
-#define ELSE 273
81
-#define WHILE 274
82
-#define CONTINUE 275
83
-#define BREAK 276
84
-#define RETURN 277
85
-
86
-
87
-
88 70
 
71
+/* Value type.  */
89 72
 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
90 73
 typedef int YYSTYPE;
91
-# define yystype YYSTYPE /* obsolescent; will be withdrawn */
92
-# define YYSTYPE_IS_DECLARED 1
93 74
 # define YYSTYPE_IS_TRIVIAL 1
75
+# define YYSTYPE_IS_DECLARED 1
94 76
 #endif
95 77
 
78
+
96 79
 extern YYSTYPE yylval;
97 80
 
81
+int yyparse (void);
82
+
83
+#endif /* !YY_YY_C_TAB_H_INCLUDED  */

+ 138 - 124
tac/lex.yy.c

@@ -7,8 +7,8 @@
7 7
 
8 8
 #define FLEX_SCANNER
9 9
 #define YY_FLEX_MAJOR_VERSION 2
10
-#define YY_FLEX_MINOR_VERSION 5
11
-#define YY_FLEX_SUBMINOR_VERSION 35
10
+#define YY_FLEX_MINOR_VERSION 6
11
+#define YY_FLEX_SUBMINOR_VERSION 1
12 12
 #if YY_FLEX_SUBMINOR_VERSION > 0
13 13
 #define FLEX_BETA
14 14
 #endif
@@ -46,7 +46,6 @@ typedef int16_t flex_int16_t;
46 46
 typedef uint16_t flex_uint16_t;
47 47
 typedef int32_t flex_int32_t;
48 48
 typedef uint32_t flex_uint32_t;
49
-typedef uint64_t flex_uint64_t;
50 49
 #else
51 50
 typedef signed char flex_int8_t;
52 51
 typedef short int flex_int16_t;
@@ -54,7 +53,6 @@ typedef int flex_int32_t;
54 53
 typedef unsigned char flex_uint8_t; 
55 54
 typedef unsigned short int flex_uint16_t;
56 55
 typedef unsigned int flex_uint32_t;
57
-#endif /* ! C99 */
58 56
 
59 57
 /* Limits of integral types. */
60 58
 #ifndef INT8_MIN
@@ -85,27 +83,17 @@ typedef unsigned int flex_uint32_t;
85 83
 #define UINT32_MAX             (4294967295U)
86 84
 #endif
87 85
 
88
-#endif /* ! FLEXINT_H */
89
-
90
-#ifdef __cplusplus
91
-
92
-/* The "const" storage-class-modifier is valid. */
93
-#define YY_USE_CONST
94
-
95
-#else	/* ! __cplusplus */
96
-
97
-/* C99 requires __STDC__ to be defined as 1. */
98
-#if defined (__STDC__)
99
-
100
-#define YY_USE_CONST
86
+#endif /* ! C99 */
101 87
 
102
-#endif	/* defined (__STDC__) */
103
-#endif	/* ! __cplusplus */
88
+#endif /* ! FLEXINT_H */
104 89
 
105
-#ifdef YY_USE_CONST
90
+/* TODO: this is always defined, so inline it */
106 91
 #define yyconst const
92
+
93
+#if defined(__GNUC__) && __GNUC__ >= 3
94
+#define yynoreturn __attribute__((__noreturn__))
107 95
 #else
108
-#define yyconst
96
+#define yynoreturn
109 97
 #endif
110 98
 
111 99
 /* Returned upon end-of-file. */
@@ -141,7 +129,15 @@ typedef unsigned int flex_uint32_t;
141 129
 
142 130
 /* Size of default input buffer. */
143 131
 #ifndef YY_BUF_SIZE
132
+#ifdef __ia64__
133
+/* On IA-64, the buffer size is 16k, not 8k.
134
+ * Moreover, YY_BUF_SIZE is 2*YY_READ_BUF_SIZE in the general case.
135
+ * Ditto for the __ia64__ case accordingly.
136
+ */
137
+#define YY_BUF_SIZE 32768
138
+#else
144 139
 #define YY_BUF_SIZE 16384
140
+#endif /* __ia64__ */
145 141
 #endif
146 142
 
147 143
 /* The state buf must be large enough to hold one state per character in the main buffer.
@@ -158,7 +154,7 @@ typedef struct yy_buffer_state *YY_BUFFER_STATE;
158 154
 typedef size_t yy_size_t;
159 155
 #endif
160 156
 
161
-extern yy_size_t yyleng;
157
+extern int yyleng;
162 158
 
163 159
 extern FILE *yyin, *yyout;
164 160
 
@@ -167,6 +163,7 @@ extern FILE *yyin, *yyout;
167 163
 #define EOB_ACT_LAST_MATCH 2
168 164
 
169 165
     #define YY_LESS_LINENO(n)
166
+    #define YY_LINENO_REWIND_TO(ptr)
170 167
     
171 168
 /* Return all but the first "n" matched characters back to the input stream. */
172 169
 #define yyless(n) \
@@ -196,12 +193,12 @@ struct yy_buffer_state
196 193
 	/* Size of input buffer in bytes, not including room for EOB
197 194
 	 * characters.
198 195
 	 */
199
-	yy_size_t yy_buf_size;
196
+	int yy_buf_size;
200 197
 
201 198
 	/* Number of characters read into yy_ch_buf, not including EOB
202 199
 	 * characters.
203 200
 	 */
204
-	yy_size_t yy_n_chars;
201
+	int yy_n_chars;
205 202
 
206 203
 	/* Whether we "own" the buffer - i.e., we know we created it,
207 204
 	 * and can realloc() it to grow it, and should free() it to
@@ -224,7 +221,7 @@ struct yy_buffer_state
224 221
 
225 222
     int yy_bs_lineno; /**< The line count. */
226 223
     int yy_bs_column; /**< The column count. */
227
-    
224
+
228 225
 	/* Whether to try to fill the input buffer when we reach the
229 226
 	 * end of it.
230 227
 	 */
@@ -252,7 +249,7 @@ struct yy_buffer_state
252 249
 /* Stack of input buffers. */
253 250
 static size_t yy_buffer_stack_top = 0; /**< index of top of stack. */
254 251
 static size_t yy_buffer_stack_max = 0; /**< capacity of stack. */
255
-static YY_BUFFER_STATE * yy_buffer_stack = 0; /**< Stack as an array. */
252
+static YY_BUFFER_STATE * yy_buffer_stack = NULL; /**< Stack as an array. */
256 253
 
257 254
 /* We provide macros for accessing buffer states in case in the
258 255
  * future we want to put the buffer states in a more general
@@ -271,11 +268,11 @@ static YY_BUFFER_STATE * yy_buffer_stack = 0; /**< Stack as an array. */
271 268
 
272 269
 /* yy_hold_char holds the character lost when yytext is formed. */
273 270
 static char yy_hold_char;
274
-static yy_size_t yy_n_chars;		/* number of characters read into yy_ch_buf */
275
-yy_size_t yyleng;
271
+static int yy_n_chars;		/* number of characters read into yy_ch_buf */
272
+int yyleng;
276 273
 
277 274
 /* Points to current character in buffer. */
278
-static char *yy_c_buf_p = (char *) 0;
275
+static char *yy_c_buf_p = NULL;
279 276
 static int yy_init = 0;		/* whether we need to initialize */
280 277
 static int yy_start = 0;	/* start state number */
281 278
 
@@ -300,7 +297,7 @@ static void yy_init_buffer (YY_BUFFER_STATE b,FILE *file  );
300 297
 
301 298
 YY_BUFFER_STATE yy_scan_buffer (char *base,yy_size_t size  );
302 299
 YY_BUFFER_STATE yy_scan_string (yyconst char *yy_str  );
303
-YY_BUFFER_STATE yy_scan_bytes (yyconst char *bytes,yy_size_t len  );
300
+YY_BUFFER_STATE yy_scan_bytes (yyconst char *bytes,int len  );
304 301
 
305 302
 void *yyalloc (yy_size_t  );
306 303
 void *yyrealloc (void *,yy_size_t  );
@@ -334,7 +331,7 @@ void yyfree (void *  );
334 331
 
335 332
 typedef unsigned char YY_CHAR;
336 333
 
337
-FILE *yyin = (FILE *) 0, *yyout = (FILE *) 0;
334
+FILE *yyin = NULL, *yyout = NULL;
338 335
 
339 336
 typedef int yy_state_type;
340 337
 
@@ -343,19 +340,22 @@ extern int yylineno;
343 340
 int yylineno = 1;
344 341
 
345 342
 extern char *yytext;
343
+#ifdef yytext_ptr
344
+#undef yytext_ptr
345
+#endif
346 346
 #define yytext_ptr yytext
347 347
 
348 348
 static yy_state_type yy_get_previous_state (void );
349 349
 static yy_state_type yy_try_NUL_trans (yy_state_type current_state  );
350 350
 static int yy_get_next_buffer (void );
351
-static void yy_fatal_error (yyconst char msg[]  );
351
+static void yynoreturn yy_fatal_error (yyconst char* msg  );
352 352
 
353 353
 /* Done after the current pattern has been matched and before the
354 354
  * corresponding action - sets up yytext.
355 355
  */
356 356
 #define YY_DO_BEFORE_ACTION \
357 357
 	(yytext_ptr) = yy_bp; \
358
-	yyleng = (yy_size_t) (yy_cp - yy_bp); \
358
+	yyleng = (int) (yy_cp - yy_bp); \
359 359
 	(yy_hold_char) = *yy_cp; \
360 360
 	*yy_cp = '\0'; \
361 361
 	(yy_c_buf_p) = yy_cp;
@@ -384,7 +384,7 @@ static yyconst flex_int16_t yy_accept[98] =
384 384
 
385 385
     } ;
386 386
 
387
-static yyconst flex_int32_t yy_ec[256] =
387
+static yyconst YY_CHAR yy_ec[256] =
388 388
     {   0,
389 389
         1,    1,    1,    1,    1,    1,    1,    1,    2,    3,
390 390
         2,    2,    1,    1,    1,    1,    1,    1,    1,    1,
@@ -416,7 +416,7 @@ static yyconst flex_int32_t yy_ec[256] =
416 416
         1,    1,    1,    1,    1
417 417
     } ;
418 418
 
419
-static yyconst flex_int32_t yy_meta[46] =
419
+static yyconst YY_CHAR yy_meta[46] =
420 420
     {   0,
421 421
         1,    1,    1,    1,    1,    1,    2,    1,    1,    1,
422 422
         1,    1,    1,    1,    3,    1,    1,    1,    1,    1,
@@ -425,7 +425,7 @@ static yyconst flex_int32_t yy_meta[46] =
425 425
         3,    3,    3,    1,    1
426 426
     } ;
427 427
 
428
-static yyconst flex_int16_t yy_base[101] =
428
+static yyconst flex_uint16_t yy_base[101] =
429 429
     {   0,
430 430
         0,    0,  130,  131,  131,  131,  110,   41,  131,  104,
431 431
       131,  131,  131,  131,  131,  131,  117,   32,  131,  131,
@@ -455,7 +455,7 @@ static yyconst flex_int16_t yy_def[101] =
455 455
 
456 456
     } ;
457 457
 
458
-static yyconst flex_int16_t yy_nxt[177] =
458
+static yyconst flex_uint16_t yy_nxt[177] =
459 459
     {   0,
460 460
         4,    5,    6,    7,    8,    9,   10,   11,   12,   13,
461 461
        14,   15,   16,   17,   18,   19,   20,   21,   22,   23,
@@ -567,19 +567,19 @@ void yyset_extra (YY_EXTRA_TYPE user_defined  );
567 567
 
568 568
 FILE *yyget_in (void );
569 569
 
570
-void yyset_in  (FILE * in_str  );
570
+void yyset_in  (FILE * _in_str  );
571 571
 
572 572
 FILE *yyget_out (void );
573 573
 
574
-void yyset_out  (FILE * out_str  );
574
+void yyset_out  (FILE * _out_str  );
575 575
 
576
-yy_size_t yyget_leng (void );
576
+			int yyget_leng (void );
577 577
 
578 578
 char *yyget_text (void );
579 579
 
580 580
 int yyget_lineno (void );
581 581
 
582
-void yyset_lineno (int line_number  );
582
+void yyset_lineno (int _line_number  );
583 583
 
584 584
 /* Macros after this point can all be overridden by user definitions in
585 585
  * section 1.
@@ -593,8 +593,12 @@ extern int yywrap (void );
593 593
 #endif
594 594
 #endif
595 595
 
596
+#ifndef YY_NO_UNPUT
597
+    
596 598
     static void yyunput (int c,char *buf_ptr  );
597 599
     
600
+#endif
601
+
598 602
 #ifndef yytext_ptr
599 603
 static void yy_flex_strncpy (char *,yyconst char *,int );
600 604
 #endif
@@ -615,7 +619,12 @@ static int input (void );
615 619
 
616 620
 /* Amount of stuff to slurp up with each read. */
617 621
 #ifndef YY_READ_BUF_SIZE
622
+#ifdef __ia64__
623
+/* On IA-64, the buffer size is 16k, not 8k */
624
+#define YY_READ_BUF_SIZE 16384
625
+#else
618 626
 #define YY_READ_BUF_SIZE 8192
627
+#endif /* __ia64__ */
619 628
 #endif
620 629
 
621 630
 /* Copy whatever the last rule matched to the standard output. */
@@ -623,7 +632,7 @@ static int input (void );
623 632
 /* This used to be an fputs(), but since the string might contain NUL's,
624 633
  * we now use fwrite().
625 634
  */
626
-#define ECHO fwrite( yytext, yyleng, 1, yyout )
635
+#define ECHO do { if (fwrite( yytext, (size_t) yyleng, 1, yyout )) {} } while (0)
627 636
 #endif
628 637
 
629 638
 /* Gets input and stuffs it into "buf".  number of characters read, or YY_NULL,
@@ -634,7 +643,7 @@ static int input (void );
634 643
 	if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \
635 644
 		{ \
636 645
 		int c = '*'; \
637
-		yy_size_t n; \
646
+		size_t n; \
638 647
 		for ( n = 0; n < max_size && \
639 648
 			     (c = getc( yyin )) != EOF && c != '\n'; ++n ) \
640 649
 			buf[n] = (char) c; \
@@ -647,7 +656,7 @@ static int input (void );
647 656
 	else \
648 657
 		{ \
649 658
 		errno=0; \
650
-		while ( (result = fread(buf, 1, max_size, yyin))==0 && ferror(yyin)) \
659
+		while ( (result = (int) fread(buf, 1, max_size, yyin))==0 && ferror(yyin)) \
651 660
 			{ \
652 661
 			if( errno != EINTR) \
653 662
 				{ \
@@ -702,7 +711,7 @@ extern int yylex (void);
702 711
 
703 712
 /* Code executed at the end of each rule. */
704 713
 #ifndef YY_BREAK
705
-#define YY_BREAK break;
714
+#define YY_BREAK /*LINTED*/break;
706 715
 #endif
707 716
 
708 717
 #define YY_RULE_SETUP \
@@ -712,14 +721,10 @@ extern int yylex (void);
712 721
  */
713 722
 YY_DECL
714 723
 {
715
-	register yy_state_type yy_current_state;
716
-	register char *yy_cp, *yy_bp;
717
-	register int yy_act;
724
+	yy_state_type yy_current_state;
725
+	char *yy_cp, *yy_bp;
726
+	int yy_act;
718 727
     
719
-#line 28 "C.flex"
720
-
721
-#line 722 "lex.yy.c"
722
-
723 728
 	if ( !(yy_init) )
724 729
 		{
725 730
 		(yy_init) = 1;
@@ -746,7 +751,12 @@ YY_DECL
746 751
 		yy_load_buffer_state( );
747 752
 		}
748 753
 
749
-	while ( 1 )		/* loops until end-of-file is reached */
754
+	{
755
+#line 28 "C.flex"
756
+
757
+#line 758 "lex.yy.c"
758
+
759
+	while ( /*CONSTCOND*/1 )		/* loops until end-of-file is reached */
750 760
 		{
751 761
 		yy_cp = (yy_c_buf_p);
752 762
 
@@ -762,7 +772,7 @@ YY_DECL
762 772
 yy_match:
763 773
 		do
764 774
 			{
765
-			register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)];
775
+			YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)] ;
766 776
 			if ( yy_accept[yy_current_state] )
767 777
 				{
768 778
 				(yy_last_accepting_state) = yy_current_state;
@@ -774,7 +784,7 @@ yy_match:
774 784
 				if ( yy_current_state >= 98 )
775 785
 					yy_c = yy_meta[(unsigned int) yy_c];
776 786
 				}
777
-			yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
787
+			yy_current_state = yy_nxt[yy_base[yy_current_state] + (flex_int16_t) yy_c];
778 788
 			++yy_cp;
779 789
 			}
780 790
 		while ( yy_base[yy_current_state] != 131 );
@@ -1001,7 +1011,7 @@ YY_RULE_SETUP
1001 1011
 #line 76 "C.flex"
1002 1012
 ECHO;
1003 1013
 	YY_BREAK
1004
-#line 1005 "lex.yy.c"
1014
+#line 1015 "lex.yy.c"
1005 1015
 case YY_STATE_EOF(INITIAL):
1006 1016
 	yyterminate();
1007 1017
 
@@ -1132,6 +1142,7 @@ case YY_STATE_EOF(INITIAL):
1132 1142
 			"fatal flex scanner internal error--no action found" );
1133 1143
 	} /* end of action switch */
1134 1144
 		} /* end of scanning one token */
1145
+	} /* end of user's declarations */
1135 1146
 } /* end of yylex */
1136 1147
 
1137 1148
 /* yy_get_next_buffer - try to read in a new buffer
@@ -1143,9 +1154,9 @@ case YY_STATE_EOF(INITIAL):
1143 1154
  */
1144 1155
 static int yy_get_next_buffer (void)
1145 1156
 {
1146
-    	register char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf;
1147
-	register char *source = (yytext_ptr);
1148
-	register int number_to_move, i;
1157
+    	char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf;
1158
+	char *source = (yytext_ptr);
1159
+	int number_to_move, i;
1149 1160
 	int ret_val;
1150 1161
 
1151 1162
 	if ( (yy_c_buf_p) > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] )
@@ -1174,7 +1185,7 @@ static int yy_get_next_buffer (void)
1174 1185
 	/* Try to read more data. */
1175 1186
 
1176 1187
 	/* First move last chars to start of buffer. */
1177
-	number_to_move = (int) ((yy_c_buf_p) - (yytext_ptr)) - 1;
1188
+	number_to_move = (int) ((yy_c_buf_p) - (yytext_ptr) - 1);
1178 1189
 
1179 1190
 	for ( i = 0; i < number_to_move; ++i )
1180 1191
 		*(dest++) = *(source++);
@@ -1187,21 +1198,21 @@ static int yy_get_next_buffer (void)
1187 1198
 
1188 1199
 	else
1189 1200
 		{
1190
-			yy_size_t num_to_read =
1201
+			int num_to_read =
1191 1202
 			YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1;
1192 1203
 
1193 1204
 		while ( num_to_read <= 0 )
1194 1205
 			{ /* Not enough room in the buffer - grow it. */
1195 1206
 
1196 1207
 			/* just a shorter name for the current buffer */
1197
-			YY_BUFFER_STATE b = YY_CURRENT_BUFFER;
1208
+			YY_BUFFER_STATE b = YY_CURRENT_BUFFER_LVALUE;
1198 1209
 
1199 1210
 			int yy_c_buf_p_offset =
1200 1211
 				(int) ((yy_c_buf_p) - b->yy_ch_buf);
1201 1212
 
1202 1213
 			if ( b->yy_is_our_buffer )
1203 1214
 				{
1204
-				yy_size_t new_size = b->yy_buf_size * 2;
1215
+				int new_size = b->yy_buf_size * 2;
1205 1216
 
1206 1217
 				if ( new_size <= 0 )
1207 1218
 					b->yy_buf_size += b->yy_buf_size / 8;
@@ -1214,7 +1225,7 @@ static int yy_get_next_buffer (void)
1214 1225
 				}
1215 1226
 			else
1216 1227
 				/* Can't grow it, we don't own it. */
1217
-				b->yy_ch_buf = 0;
1228
+				b->yy_ch_buf = NULL;
1218 1229
 
1219 1230
 			if ( ! b->yy_ch_buf )
1220 1231
 				YY_FATAL_ERROR(
@@ -1256,9 +1267,9 @@ static int yy_get_next_buffer (void)
1256 1267
 	else
1257 1268
 		ret_val = EOB_ACT_CONTINUE_SCAN;
1258 1269
 
1259
-	if ((yy_size_t) ((yy_n_chars) + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) {
1270
+	if (((yy_n_chars) + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) {
1260 1271
 		/* Extend the array by 50%, plus the number we really need. */
1261
-		yy_size_t new_size = (yy_n_chars) + number_to_move + ((yy_n_chars) >> 1);
1272
+		int new_size = (yy_n_chars) + number_to_move + ((yy_n_chars) >> 1);
1262 1273
 		YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) yyrealloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,new_size  );
1263 1274
 		if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf )
1264 1275
 			YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" );
@@ -1277,14 +1288,14 @@ static int yy_get_next_buffer (void)
1277 1288
 
1278 1289
     static yy_state_type yy_get_previous_state (void)
1279 1290
 {
1280
-	register yy_state_type yy_current_state;
1281
-	register char *yy_cp;
1291
+	yy_state_type yy_current_state;
1292
+	char *yy_cp;
1282 1293
     
1283 1294
 	yy_current_state = (yy_start);
1284 1295
 
1285 1296
 	for ( yy_cp = (yytext_ptr) + YY_MORE_ADJ; yy_cp < (yy_c_buf_p); ++yy_cp )
1286 1297
 		{
1287
-		register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1);
1298
+		YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1);
1288 1299
 		if ( yy_accept[yy_current_state] )
1289 1300
 			{
1290 1301
 			(yy_last_accepting_state) = yy_current_state;
@@ -1296,7 +1307,7 @@ static int yy_get_next_buffer (void)
1296 1307
 			if ( yy_current_state >= 98 )
1297 1308
 				yy_c = yy_meta[(unsigned int) yy_c];
1298 1309
 			}
1299
-		yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
1310
+		yy_current_state = yy_nxt[yy_base[yy_current_state] + (flex_int16_t) yy_c];
1300 1311
 		}
1301 1312
 
1302 1313
 	return yy_current_state;
@@ -1309,10 +1320,10 @@ static int yy_get_next_buffer (void)
1309 1320
  */
1310 1321
     static yy_state_type yy_try_NUL_trans  (yy_state_type yy_current_state )
1311 1322
 {
1312
-	register int yy_is_jam;
1313
-    	register char *yy_cp = (yy_c_buf_p);
1323
+	int yy_is_jam;
1324
+    	char *yy_cp = (yy_c_buf_p);
1314 1325
 
1315
-	register YY_CHAR yy_c = 1;
1326
+	YY_CHAR yy_c = 1;
1316 1327
 	if ( yy_accept[yy_current_state] )
1317 1328
 		{
1318 1329
 		(yy_last_accepting_state) = yy_current_state;
@@ -1324,15 +1335,17 @@ static int yy_get_next_buffer (void)
1324 1335
 		if ( yy_current_state >= 98 )
1325 1336
 			yy_c = yy_meta[(unsigned int) yy_c];
1326 1337
 		}
1327
-	yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
1338
+	yy_current_state = yy_nxt[yy_base[yy_current_state] + (flex_int16_t) yy_c];
1328 1339
 	yy_is_jam = (yy_current_state == 97);
1329 1340
 
1330
-	return yy_is_jam ? 0 : yy_current_state;
1341
+		return yy_is_jam ? 0 : yy_current_state;
1331 1342
 }
1332 1343
 
1333
-    static void yyunput (int c, register char * yy_bp )
1344
+#ifndef YY_NO_UNPUT
1345
+
1346
+    static void yyunput (int c, char * yy_bp )
1334 1347
 {
1335
-	register char *yy_cp;
1348
+	char *yy_cp;
1336 1349
     
1337 1350
     yy_cp = (yy_c_buf_p);
1338 1351
 
@@ -1342,10 +1355,10 @@ static int yy_get_next_buffer (void)
1342 1355
 	if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 )
1343 1356
 		{ /* need to shift things up to make room */
1344 1357
 		/* +2 for EOB chars. */
1345
-		register yy_size_t number_to_move = (yy_n_chars) + 2;
1346
-		register char *dest = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[
1358
+		int number_to_move = (yy_n_chars) + 2;
1359
+		char *dest = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[
1347 1360
 					YY_CURRENT_BUFFER_LVALUE->yy_buf_size + 2];
1348
-		register char *source =
1361
+		char *source =
1349 1362
 				&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move];
1350 1363
 
1351 1364
 		while ( source > YY_CURRENT_BUFFER_LVALUE->yy_ch_buf )
@@ -1354,7 +1367,7 @@ static int yy_get_next_buffer (void)
1354 1367
 		yy_cp += (int) (dest - source);
1355 1368
 		yy_bp += (int) (dest - source);
1356 1369
 		YY_CURRENT_BUFFER_LVALUE->yy_n_chars =
1357
-			(yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_buf_size;
1370
+			(yy_n_chars) = (int) YY_CURRENT_BUFFER_LVALUE->yy_buf_size;
1358 1371
 
1359 1372
 		if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 )
1360 1373
 			YY_FATAL_ERROR( "flex scanner push-back overflow" );
@@ -1367,6 +1380,8 @@ static int yy_get_next_buffer (void)
1367 1380
 	(yy_c_buf_p) = yy_cp;
1368 1381
 }
1369 1382
 
1383
+#endif
1384
+
1370 1385
 #ifndef YY_NO_INPUT
1371 1386
 #ifdef __cplusplus
1372 1387
     static int yyinput (void)
@@ -1391,7 +1406,7 @@ static int yy_get_next_buffer (void)
1391 1406
 
1392 1407
 		else
1393 1408
 			{ /* need more input */
1394
-			yy_size_t offset = (yy_c_buf_p) - (yytext_ptr);
1409
+			int offset = (yy_c_buf_p) - (yytext_ptr);
1395 1410
 			++(yy_c_buf_p);
1396 1411
 
1397 1412
 			switch ( yy_get_next_buffer(  ) )
@@ -1516,7 +1531,7 @@ static void yy_load_buffer_state  (void)
1516 1531
 	if ( ! b )
1517 1532
 		YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
1518 1533
 
1519
-	b->yy_buf_size = size;
1534
+	b->yy_buf_size = (yy_size_t)size;
1520 1535
 
1521 1536
 	/* yy_ch_buf has to be 2 characters longer than the size given because
1522 1537
 	 * we need to put in 2 end-of-buffer characters.
@@ -1551,10 +1566,6 @@ static void yy_load_buffer_state  (void)
1551 1566
 	yyfree((void *) b  );
1552 1567
 }
1553 1568
 
1554
-#ifndef __cplusplus
1555
-extern int isatty (int );
1556
-#endif /* __cplusplus */
1557
-    
1558 1569
 /* Initializes or reinitializes a buffer.
1559 1570
  * This function is sometimes called more than once on the same buffer,
1560 1571
  * such as during a yyrestart() or at EOF.
@@ -1667,7 +1678,7 @@ void yypop_buffer_state (void)
1667 1678
  */
1668 1679
 static void yyensure_buffer_stack (void)
1669 1680
 {
1670
-	yy_size_t num_to_alloc;
1681
+	int num_to_alloc;
1671 1682
     
1672 1683
 	if (!(yy_buffer_stack)) {
1673 1684
 
@@ -1675,15 +1686,15 @@ static void yyensure_buffer_stack (void)
1675 1686
 		 * scanner will even need a stack. We use 2 instead of 1 to avoid an
1676 1687
 		 * immediate realloc on the next call.
1677 1688
          */
1678
-		num_to_alloc = 1;
1689
+      num_to_alloc = 1; /* After all that talk, this was set to 1 anyways... */
1679 1690
 		(yy_buffer_stack) = (struct yy_buffer_state**)yyalloc
1680 1691
 								(num_to_alloc * sizeof(struct yy_buffer_state*)
1681 1692
 								);
1682 1693
 		if ( ! (yy_buffer_stack) )
1683 1694
 			YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" );
1684
-								  
1695
+
1685 1696
 		memset((yy_buffer_stack), 0, num_to_alloc * sizeof(struct yy_buffer_state*));
1686
-				
1697
+
1687 1698
 		(yy_buffer_stack_max) = num_to_alloc;
1688 1699
 		(yy_buffer_stack_top) = 0;
1689 1700
 		return;
@@ -1692,7 +1703,7 @@ static void yyensure_buffer_stack (void)
1692 1703
 	if ((yy_buffer_stack_top) >= ((yy_buffer_stack_max)) - 1){
1693 1704
 
1694 1705
 		/* Increase the buffer to prepare for a possible push. */
1695
-		int grow_size = 8 /* arbitrary grow size */;
1706
+		yy_size_t grow_size = 8 /* arbitrary grow size */;
1696 1707
 
1697 1708
 		num_to_alloc = (yy_buffer_stack_max) + grow_size;
1698 1709
 		(yy_buffer_stack) = (struct yy_buffer_state**)yyrealloc
@@ -1712,7 +1723,7 @@ static void yyensure_buffer_stack (void)
1712 1723
  * @param base the character buffer
1713 1724
  * @param size the size in bytes of the character buffer
1714 1725
  * 
1715
- * @return the newly allocated buffer state object. 
1726
+ * @return the newly allocated buffer state object.
1716 1727
  */
1717 1728
 YY_BUFFER_STATE yy_scan_buffer  (char * base, yy_size_t  size )
1718 1729
 {
@@ -1722,7 +1733,7 @@ YY_BUFFER_STATE yy_scan_buffer  (char * base, yy_size_t  size )
1722 1733
 	     base[size-2] != YY_END_OF_BUFFER_CHAR ||
1723 1734
 	     base[size-1] != YY_END_OF_BUFFER_CHAR )
1724 1735
 		/* They forgot to leave room for the EOB's. */
1725
-		return 0;
1736
+		return NULL;
1726 1737
 
1727 1738
 	b = (YY_BUFFER_STATE) yyalloc(sizeof( struct yy_buffer_state )  );
1728 1739
 	if ( ! b )
@@ -1731,7 +1742,7 @@ YY_BUFFER_STATE yy_scan_buffer  (char * base, yy_size_t  size )
1731 1742
 	b->yy_buf_size = size - 2;	/* "- 2" to take care of EOB's */
1732 1743
 	b->yy_buf_pos = b->yy_ch_buf = base;
1733 1744
 	b->yy_is_our_buffer = 0;
1734
-	b->yy_input_file = 0;
1745
+	b->yy_input_file = NULL;
1735 1746
 	b->yy_n_chars = b->yy_buf_size;
1736 1747
 	b->yy_is_interactive = 0;
1737 1748
 	b->yy_at_bol = 1;
@@ -1754,24 +1765,25 @@ YY_BUFFER_STATE yy_scan_buffer  (char * base, yy_size_t  size )
1754 1765
 YY_BUFFER_STATE yy_scan_string (yyconst char * yystr )
1755 1766
 {
1756 1767
     
1757
-	return yy_scan_bytes(yystr,strlen(yystr) );
1768
+	return yy_scan_bytes(yystr,(int) strlen(yystr) );
1758 1769
 }
1759 1770
 
1760 1771
 /** Setup the input buffer state to scan the given bytes. The next call to yylex() will
1761 1772
  * scan from a @e copy of @a bytes.
1762
- * @param bytes the byte buffer to scan
1763
- * @param len the number of bytes in the buffer pointed to by @a bytes.
1773
+ * @param yybytes the byte buffer to scan
1774
+ * @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes.
1764 1775
  * 
1765 1776
  * @return the newly allocated buffer state object.
1766 1777
  */
1767
-YY_BUFFER_STATE yy_scan_bytes  (yyconst char * yybytes, yy_size_t  _yybytes_len )
1778
+YY_BUFFER_STATE yy_scan_bytes  (yyconst char * yybytes, int  _yybytes_len )
1768 1779
 {
1769 1780
 	YY_BUFFER_STATE b;
1770 1781
 	char *buf;
1771
-	yy_size_t n, i;
1782
+	yy_size_t n;
1783
+	int i;
1772 1784
     
1773 1785
 	/* Get memory for full buffer, including space for trailing EOB's. */
1774
-	n = _yybytes_len + 2;
1786
+	n = (yy_size_t) (_yybytes_len + 2);
1775 1787
 	buf = (char *) yyalloc(n  );
1776 1788
 	if ( ! buf )
1777 1789
 		YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" );
@@ -1797,9 +1809,9 @@ YY_BUFFER_STATE yy_scan_bytes  (yyconst char * yybytes, yy_size_t  _yybytes_len
1797 1809
 #define YY_EXIT_FAILURE 2
1798 1810
 #endif
1799 1811
 
1800
-static void yy_fatal_error (yyconst char* msg )
1812
+static void yynoreturn yy_fatal_error (yyconst char* msg )
1801 1813
 {
1802
-    	(void) fprintf( stderr, "%s\n", msg );
1814
+			(void) fprintf( stderr, "%s\n", msg );
1803 1815
 	exit( YY_EXIT_FAILURE );
1804 1816
 }
1805 1817
 
@@ -1827,7 +1839,7 @@ static void yy_fatal_error (yyconst char* msg )
1827 1839
  */
1828 1840
 int yyget_lineno  (void)
1829 1841
 {
1830
-        
1842
+    
1831 1843
     return yylineno;
1832 1844
 }
1833 1845
 
@@ -1850,7 +1862,7 @@ FILE *yyget_out  (void)
1850 1862
 /** Get the length of the current token.
1851 1863
  * 
1852 1864
  */
1853
-yy_size_t yyget_leng  (void)
1865
+int yyget_leng  (void)
1854 1866
 {
1855 1867
         return yyleng;
1856 1868
 }
@@ -1865,29 +1877,29 @@ char *yyget_text  (void)
1865 1877
 }
1866 1878
 
1867 1879
 /** Set the current line number.
1868
- * @param line_number
1880
+ * @param _line_number line number
1869 1881
  * 
1870 1882
  */
1871
-void yyset_lineno (int  line_number )
1883
+void yyset_lineno (int  _line_number )
1872 1884
 {
1873 1885
     
1874
-    yylineno = line_number;
1886
+    yylineno = _line_number;
1875 1887
 }
1876 1888
 
1877 1889
 /** Set the input stream. This does not discard the current
1878 1890
  * input buffer.
1879
- * @param in_str A readable stream.
1891
+ * @param _in_str A readable stream.
1880 1892
  * 
1881 1893
  * @see yy_switch_to_buffer
1882 1894
  */
1883
-void yyset_in (FILE *  in_str )
1895
+void yyset_in (FILE *  _in_str )
1884 1896
 {
1885
-        yyin = in_str ;
1897
+        yyin = _in_str ;
1886 1898
 }
1887 1899
 
1888
-void yyset_out (FILE *  out_str )
1900
+void yyset_out (FILE *  _out_str )
1889 1901
 {
1890
-        yyout = out_str ;
1902
+        yyout = _out_str ;
1891 1903
 }
1892 1904
 
1893 1905
 int yyget_debug  (void)
@@ -1895,9 +1907,9 @@ int yyget_debug  (void)
1895 1907
         return yy_flex_debug;
1896 1908
 }
1897 1909
 
1898
-void yyset_debug (int  bdebug )
1910
+void yyset_debug (int  _bdebug )
1899 1911
 {
1900
-        yy_flex_debug = bdebug ;
1912
+        yy_flex_debug = _bdebug ;
1901 1913
 }
1902 1914
 
1903 1915
 static int yy_init_globals (void)
@@ -1906,10 +1918,10 @@ static int yy_init_globals (void)
1906 1918
      * This function is called from yylex_destroy(), so don't allocate here.
1907 1919
      */
1908 1920
 
1909
-    (yy_buffer_stack) = 0;
1921
+    (yy_buffer_stack) = NULL;
1910 1922
     (yy_buffer_stack_top) = 0;
1911 1923
     (yy_buffer_stack_max) = 0;
1912
-    (yy_c_buf_p) = (char *) 0;
1924
+    (yy_c_buf_p) = NULL;
1913 1925
     (yy_init) = 0;
1914 1926
     (yy_start) = 0;
1915 1927
 
@@ -1918,8 +1930,8 @@ static int yy_init_globals (void)
1918 1930
     yyin = stdin;
1919 1931
     yyout = stdout;
1920 1932
 #else
1921
-    yyin = (FILE *) 0;
1922
-    yyout = (FILE *) 0;
1933
+    yyin = NULL;
1934
+    yyout = NULL;
1923 1935
 #endif
1924 1936
 
1925 1937
     /* For future reference: Set errno on error, since we are called by
@@ -1957,7 +1969,8 @@ int yylex_destroy  (void)
1957 1969
 #ifndef yytext_ptr
1958 1970
 static void yy_flex_strncpy (char* s1, yyconst char * s2, int n )
1959 1971
 {
1960
-	register int i;
1972
+		
1973
+	int i;
1961 1974
 	for ( i = 0; i < n; ++i )
1962 1975
 		s1[i] = s2[i];
1963 1976
 }
@@ -1966,7 +1979,7 @@ static void yy_flex_strncpy (char* s1, yyconst char * s2, int n )
1966 1979
 #ifdef YY_NEED_STRLEN
1967 1980
 static int yy_flex_strlen (yyconst char * s )
1968 1981
 {
1969
-	register int n;
1982
+	int n;
1970 1983
 	for ( n = 0; s[n]; ++n )
1971 1984
 		;
1972 1985
 
@@ -1976,11 +1989,12 @@ static int yy_flex_strlen (yyconst char * s )
1976 1989
 
1977 1990
 void *yyalloc (yy_size_t  size )
1978 1991
 {
1979
-	return (void *) malloc( size );
1992
+			return malloc(size);
1980 1993
 }
1981 1994
 
1982 1995
 void *yyrealloc  (void * ptr, yy_size_t  size )
1983 1996
 {
1997
+		
1984 1998
 	/* The cast to (char *) in the following accommodates both
1985 1999
 	 * implementations that use char* generic pointers, and those
1986 2000
 	 * that use void* generic pointers.  It works with the latter
@@ -1988,12 +2002,12 @@ void *yyrealloc  (void * ptr, yy_size_t  size )
1988 2002
 	 * any pointer type to void*, and deal with argument conversions
1989 2003
 	 * as though doing an assignment.
1990 2004
 	 */
1991
-	return (void *) realloc( (char *) ptr, size );
2005
+	return realloc(ptr, size);
1992 2006
 }
1993 2007
 
1994 2008
 void yyfree (void * ptr )
1995 2009
 {
1996
-	free( (char *) ptr );	/* see yyrealloc() for (char *) cast */
2010
+			free( (char *) ptr );	/* see yyrealloc() for (char *) cast */
1997 2011
 }
1998 2012
 
1999 2013
 #define YYTABLES_NAME "yytables"

+ 8 - 0
tac/list.c

@@ -131,6 +131,14 @@ TAC_T* create_tac(int op, TOKEN* src, TOKEN* tgt, TOKEN* dst) {
131 131
   return new_t;
132 132
 }
133 133
 
134
+void append_tac(TLIST *head, TLIST *tac) {
135
+  TLIST *ptr = head;
136
+  while (ptr->next != NULL) {
137
+    ptr = ptr->next;
138
+  }
139
+  ptr->next = tac;
140
+}
141
+
134 142
 void add_tac(TLIST *head, int op, TOKEN* src, TOKEN* tgt, TOKEN* dst) {
135 143
   TLIST *ptr = head;
136 144
   while (ptr->next != NULL) {

+ 1 - 0
tac/list.h

@@ -9,6 +9,7 @@ BIND* find_name_in_list(TOKEN*, BLIST*);
9 9
 BIND* find_name_in_env(TOKEN*, ENV*);
10 10
 ENV* create_new_function_env(ENV*, ENV*);
11 11
 void add_tac(TLIST*, int, TOKEN*, TOKEN*, TOKEN*);
12
+void append_tac(TLIST*, TLIST*);
12 13
 TAC_T* create_tac(int, TOKEN*, TOKEN*, TOKEN*);
13 14
 TLIST* new_tac_list(TAC_T*, TLIST*);
14 15
 #endif

+ 24 - 18
tac/main.c

@@ -138,6 +138,7 @@ void print_tac_el(TAC_T* elem) {
138 138
     if (op == APPLY) printf("call %s, %s\n", stok(elem->dst), stok(elem->tgt));
139 139
     if (op == 278) printf("arg %s\n", stok(elem->dst));
140 140
     if (op == 279) printf("end %s\n\n", stok(elem->dst));
141
+    if (op == 280) printf("closure: %s\n", stok(elem->dst));
141 142
 }
142 143
 
143 144
 void print_tac(TLIST* tac_list) {
@@ -224,52 +225,57 @@ NODE** get_val_list(NODE *tree) {
224 225
   return arr;
225 226
 }
226 227
 
227
-TOKEN* build_tac(NODE *tree, TACS* tac) {
228
+TOKEN* build_tac(NODE *tree, TACS* tac, TACS* after_tac) {
228 229
   if (tree == NULL) return NULL;
229 230
   int type = tree->type;
230 231
   if (type == LEAF) {
231 232
     return (TOKEN *) tree->left;
232 233
   } else if (type == '=') {
233 234
     TOKEN* dst = (TOKEN*) tree->left->left;
234
-    TOKEN* result = build_tac(tree->right, tac);
235
+    TOKEN* result = build_tac(tree->right, tac, after_tac);
235 236
     new_tac(tac, dst, result, NULL, tree->type);
236 237
   } else if (type=='+' || type=='-' || type=='*' || type=='/' || type =='%') {
237 238
     TOKEN* dst = gen_tmp();
238
-    TOKEN* src = build_tac(tree->left, tac);
239
-    TOKEN* tgt = build_tac(tree->right, tac);
239
+    TOKEN* src = build_tac(tree->left, tac, after_tac);
240
+    TOKEN* tgt = build_tac(tree->right, tac, after_tac);
240 241
     new_tac(tac, dst, src, tgt, tree->type);
241 242
     return dst;
242 243
   } else if (type == IF) {
243 244
     int op = invert_op(tree->left->type);
244
-    TOKEN* lhs = build_tac(tree->left->left, tac);
245
-    TOKEN* rhs = build_tac(tree->left->right, tac);
245
+    TOKEN* lhs = build_tac(tree->left->left, tac, after_tac);
246
+    TOKEN* rhs = build_tac(tree->left->right, tac, after_tac);
246 247
     TOKEN* label = gen_label();
247 248
     new_tac(tac, label, lhs, rhs, op);
248 249
     if (tree->right->type == ELSE) {
249 250
       TOKEN* cont = gen_label();
250
-      build_tac(tree->right->left, tac);
251
+      build_tac(tree->right->left, tac, after_tac);
251 252
       new_tac(tac, cont, NULL, NULL, VOID);
252 253
       new_tac(tac, label, NULL, NULL, IDENTIFIER);
253
-      build_tac(tree->right->right, tac);
254
+      build_tac(tree->right->right, tac, after_tac);
254 255
       new_tac(tac, cont, NULL, NULL, IDENTIFIER);
255 256
     } else {
256
-      build_tac(tree->right, tac);
257
+      build_tac(tree->right, tac, after_tac);
257 258
       new_tac(tac, label, NULL, NULL, IDENTIFIER);
258 259
     }
259 260
   } else if (type == RETURN) {
260
-    TOKEN* src = build_tac(tree->left, tac);
261
+    TOKEN* src = build_tac(tree->left, tac, after_tac);
261 262
     new_tac(tac, NULL, src, NULL, RETURN);
262 263
   } else if (type == 'D') {
263
-    new_tac(tac, (TOKEN*) tree->left->right->left->left, NULL, NULL, 'D');
264
+    TACS* gen_tac = (TACS*) malloc(sizeof(TACS));
265
+    new_tac(after_tac, (TOKEN*) tree->left->right->left->left, NULL, NULL, 'D');
264 266
     if (tree->left->right->right != NULL) {
265 267
       TOKEN** arg_list = get_argument_list(tree);
266 268
       int arg_count = count_args(tree->left->right->right);
267 269
       for (int i = 0; i < arg_count; i++) {
268
-        new_tac(tac, arg_list[i], NULL, NULL, AUTO);
270
+        new_tac(after_tac, arg_list[i], NULL, NULL, AUTO);
269 271
       }
270 272
     }
271
-    build_tac(tree->right, tac);
272
-    new_tac(tac, (TOKEN*) tree->left->right->left->left, NULL, NULL, 279);
273
+    build_tac(tree->right, after_tac, gen_tac);
274
+    new_tac(after_tac, (TOKEN*) tree->left->right->left->left, NULL, NULL, 279);
275
+    if (tac != after_tac) {
276
+      new_tac(tac, (TOKEN*) tree->left->right->left->left, NULL, NULL, 280);
277
+    }
278
+    append_tac(tac->list, gen_tac->list);
273 279
   } else if (type == APPLY) {
274 280
     TOKEN* ret_val = gen_tmp();
275 281
     if (tree->right != NULL) {
@@ -279,7 +285,7 @@ TOKEN* build_tac(NODE *tree, TACS* tac) {
279 285
       val_list = get_val_list(tree->right);
280 286
       TOKEN* arg_tokens[num_args];
281 287
       for (int i = 0; i < num_args; i++) {
282
-        arg_tokens[i] = build_tac(val_list[i], tac);
288
+        arg_tokens[i] = build_tac(val_list[i], tac, after_tac);
283 289
       }
284 290
       for (int i = 0; i < num_args; i++) {
285 291
         new_tac(tac, arg_tokens[i], NULL, NULL, 278);
@@ -288,8 +294,8 @@ TOKEN* build_tac(NODE *tree, TACS* tac) {
288 294
     new_tac(tac, (TOKEN*) tree->left->left, NULL, ret_val, APPLY);
289 295
     return ret_val;
290 296
   } else {
291
-    build_tac(tree->left, tac);
292
-    build_tac(tree->right, tac);
297
+    build_tac(tree->left, tac, after_tac);
298
+    build_tac(tree->right, tac, after_tac);
293 299
     return NULL;
294 300
   }
295 301
   return NULL;
@@ -495,7 +501,7 @@ void compile_tac(TLIST* tacs) {
495 501
 
496 502
 void interpret_tree(NODE *tree) {
497 503
   TACS* gen_tac = (TACS*) malloc(sizeof(TACS));
498
-  build_tac(tree, gen_tac);
504
+  build_tac(tree, gen_tac, gen_tac);
499 505
   print_tac(gen_tac->list);
500 506
   compile_tac(gen_tac->list);
501 507
 }

+ 7 - 3
tac/simple.c

@@ -1,6 +1,10 @@
1
-int times(int x, int y) {
2
-  return x * y;
1
+int blah() {
2
+  int blah2() {
3
+    return 2;
4
+  }
5
+  return blah2();
3 6
 }
7
+
4 8
 int main() {
5
-  return times(4+5);
9
+  return blah();
6 10
 }

+ 14 - 0
tac/simple.c.orig

@@ -0,0 +1,14 @@
1
+int blah() {
2
+  int blah2() {
3
+    return 2;
4
+  }
5
+  return blah2();
6
+}
7
+
8
+int main() {
9
+<<<<<<< HEAD
10
+  return times(4+5);
11
+=======
12
+  return blah();
13
+>>>>>>> 87f65c41c69413a8cc3fe3da8b302ddb20630544
14
+}

+ 14 - 0
tac/simple_BACKUP_41992.c

@@ -0,0 +1,14 @@
1
+int blah() {
2
+  int blah2() {
3
+    return 2;
4
+  }
5
+  return blah2();
6
+}
7
+
8
+int main() {
9
+<<<<<<< HEAD
10
+  return times(4+5);
11
+=======
12
+  return blah();
13
+>>>>>>> 87f65c41c69413a8cc3fe3da8b302ddb20630544
14
+}

+ 6 - 0
tac/simple_BASE_41992.c

@@ -0,0 +1,6 @@
1
+int times(int x, int y) {
2
+  return x * y;
3
+}
4
+int main() {
5
+  return times(4+5, times(2, 4));
6
+}

+ 6 - 0
tac/simple_LOCAL_41992.c

@@ -0,0 +1,6 @@
1
+int times(int x, int y) {
2
+  return x * y;
3
+}
4
+int main() {
5
+  return times(4+5);
6
+}

+ 10 - 0
tac/simple_REMOTE_41992.c

@@ -0,0 +1,10 @@
1
+int blah() {
2
+  int blah2() {
3
+    return 2;
4
+  }
5
+  return blah2();
6
+}
7
+
8
+int main() {
9
+  return blah();
10
+}