shithub: scc

Download patch

ref: a8b9e699e5f953f3521cbe2e3e9ad431f307823c
parent: 2c5658c7d684eef9de76ff7715f7da6debb69d8f
author: Roberto E. Vargas Caballero <[email protected]>
date: Tue Mar 25 09:54:43 EDT 2014

This commit is a shit

I have commit a lot of different things not directly related between
them.

--- a/code.c
+++ b/code.c
@@ -18,4 +18,22 @@
 	else
 		c = 'A';
 	printf("\t%c%d", c, sym->id);
-}
\ No newline at end of file
+}
+
+void
+emitfun(struct symbol *sym)
+{
+	printf("X%s\n", sym->name);
+}
+
+void
+emitframe(struct symbol *sym)
+{
+	puts("{");
+}
+
+void
+emitret(struct symbol *sym)
+{
+	puts("}");
+}
--- /dev/null
+++ b/code.h
@@ -1,0 +1,10 @@
+
+#ifndef CODE_H_
+#define CODE_H_
+
+struct symbol;
+
+extern void emitsym(struct symbol *sym),  emitfun(struct symbol *sym),
+	emitframe(struct symbol *sym), emitret(struct symbol *sym);
+
+#endif
--- a/decl.c
+++ b/decl.c
@@ -6,7 +6,6 @@
 #include "sizes.h"
 #include "cc.h"
 #include "tokens.h"
-#include "syntax.h"
 #include "symbol.h"
 #include "machine.h"
 
@@ -56,6 +55,7 @@
 newiden(uint8_t ns)
 {
 	struct symbol *sym;
+	extern uint8_t curctx;
 
 	if (yylval.sym && yylval.sym->ctx == curctx)
 		error("redeclaration of '%s'", yytext);
@@ -492,14 +492,15 @@
 
 	if (yytoken != ';') {
 		do {
-			extern void printtype(struct ctype *tp);
 			sym = declarator(tp, NS_IDEN, ID_EXPECTED);
-			printtype(sym->type);
 			if (!(sclass & STATIC))
 				sym->s.isglobal = 1;
 			if (ISFUN(sym->type)) {
+				emitfun(sym);
 				if (yytoken == '{') {
+					emitframe(sym);
 					context(compound);
+					emitret(sym);
 					freesyms(NS_LABEL);
 					return;
 				}
--- a/expr.c
+++ b/expr.c
@@ -32,11 +32,19 @@
 		expect(')');
 		break;
 	default:
-		tp = NULL;
+		error("unexpected '%s'", yytoken);
 	}
 	return tp;
 }
 
+static struct ctype *
+postfix(void)
+{
+	struct ctype * tp;
+
+	tp = primary();
+}
+
 struct ctype *
 expr(void)
 {
@@ -43,7 +51,7 @@
 	register struct ctype *tp;
 
 	do
-		tp = primary();
+		tp = postfix();
 	while (yytoken == ',');
 
 	return tp;
--- /dev/null
+++ b/stmt.c
@@ -1,0 +1,25 @@
+
+#include <stdint.h>
+
+#include "symbol.h"
+#include "tokens.h"
+
+
+void
+compound(void)
+{
+	extern struct ctype *expr(void);
+	extern void decl(void);
+
+	expect('{');
+	while (!accept('}')) {
+		switch (yytoken) {
+		case TYPE: case SCLASS: case TQUALIFIER:
+			decl();
+			break;
+		default:
+			expr();
+		}
+		expect(';');
+	}
+}
\ No newline at end of file