shithub: scc

Download patch

ref: b1bd61b5a79e46e298759723f528a4e025a5c6f5
parent: e8eef01cc0830c227e5e55788f90e2dc52c64116
author: Roberto E. Vargas Caballero <[email protected]>
date: Wed Apr 23 12:28:06 EDT 2014

Add break, continue and switch parameters to context

Context is going to be called every time a new variable
context is created, so it is a good idea to add where
the break, continue jumps are going to go, and
also was it the last switch

--- a/cc1.h
+++ b/cc1.h
@@ -124,8 +124,12 @@
 	*lookup(char *s, unsigned char ns),
 	*install(char *s, unsigned char ns);
 
-extern void context(void (*fun)(void));
+typedef void Ctxfun(Symbol *, Symbol *, Symbol *);
 
+extern Ctxfun compound;
+extern void context(Ctxfun *fun,
+                    Symbol *lbreak, Symbol *lcont, Symbol *lswitch);
+
 extern Type *typename(void);
 
 extern Type *voidtype, *pvoidtype, *booltype,
@@ -243,6 +247,6 @@
 #define ISNODECMP(n) (ISNODEBIN(n) && (n)->u.op & 0x40)
 
 extern Node *expr(void);
-extern void extdecl(void), decl(void), compound(void);
+extern void extdecl(void), decl(void);
 
 #endif
--- a/decl.c
+++ b/decl.c
@@ -504,7 +504,7 @@
 					curfun = sym;
 					emitfun(sym);
 					emitsframe(sym);
-					context(compound);
+					context(compound, NULL, NULL, NULL);
 					emiteframe(sym); /* FIX: sym is not used */
 					freesyms(NS_LABEL);
 					return;
--- a/stmt.c
+++ b/stmt.c
@@ -27,7 +27,7 @@
 }
 
 void
-compound(void)
+compound(Symbol *lbreak, Symbol *lcont, Symbol *lswitch)
 {
 	expect('{');
 	while (!accept('}')) {
--- a/symbol.c
+++ b/symbol.c
@@ -44,13 +44,13 @@
 }
 
 void
-context(void (*fun)(void))
+context(Ctxfun *fun, Symbol *lbreak, Symbol *lcont, Symbol *lswitch)
 {
 	uint8_t ns;
 
 	ns = namespace;
 	++curctx;
-	fun();
+	(*fun)(lbreak, lcont, lswitch);
 	--curctx;
 	namespace = ns;