The unified diff between revisions [76aea49e..] and [9a6e8df1..] is displayed below. It can also be downloaded as a raw diff.

This diff has been restricted to the following files: 'src/lsc/codegen.c'

#
# old_revision [76aea49e8393c839b573eaac31eb8e2fb218d2d6]
# new_revision [9a6e8df1d6b102f467702e274d53d90f9151e2c8]
#
# patch "src/lsc/codegen.c"
#  from [54841dc0395a35f38eeef2e81231366c4fed3015]
#    to [3f17dcc09e552288f4a68b0ac58692cffd524364]
#
============================================================
--- src/lsc/codegen.c	54841dc0395a35f38eeef2e81231366c4fed3015
+++ src/lsc/codegen.c	3f17dcc09e552288f4a68b0ac58692cffd524364
@@ -6,6 +6,7 @@
 #include <assert.h>
 #include <err.h>
 #include <limits.h>
+#include <stdarg.h>
 #include "types.h"
 #include "ast.h"
 #include "codegen.h"
@@ -37,6 +38,7 @@ struct label {
 
 #define MAX_LABELS 4096
 #define MAX_CONSTS 4096
+#define ERROR_MAXLEN 1024
 
 struct label *labels = NULL;
 int nlabels = 0;
@@ -104,6 +106,8 @@ int constant_count = -1;
 int function_count = -1;
 int constant_count = -1;
 
+int lineno;
+
 #define HASHSIZE 512
 #define HASHMASK (HASHSIZE - 1)
 
@@ -111,9 +115,16 @@ struct hashentry *constanthash[HASHSIZE]
 struct hashentry *fnhash[HASHSIZE];
 struct hashentry *constanthash[HASHSIZE];
 
-void compiler_error(char *str)
+void compiler_error(char *str, ...)
 {
-	errx(1, str);
+	char buf[ERROR_MAXLEN];
+	va_list args;
+
+	snprintf(buf, ERROR_MAXLEN, "%d: %s", lineno, str);
+
+	va_start(args, str);
+	verrx(1, buf, args);
+	va_end(args); /* Not really necessary if errx exits */
 }
 
 int count_local_variables(void)
@@ -140,7 +151,7 @@ void output_functions_action(struct hash
 		pad = (4 - (len % 4)) % 4;
 		output_int(len+pad);
 		output_int(0);	/* type */
-		output_int(get_label(ptr->value) + 8);
+		output_int(get_label(ptr->value) + 28);
 		output_int(0);	/* nargs */
 		output_string(ptr->name);
 		output_byte(0);	/* terminator */
@@ -533,12 +544,16 @@ void codegen(ast *node)
 	int stackfixlabel;
 	int hasdefault;
 	int i;
+	int savedlineno;
 
 	union {
 		int i;
 		float f;
 	} conv;
 
+	savedlineno = lineno;
+
+	lineno = node->lineno;
 #if DEBUG
 	printf("entering codegen with node %p, sp = %d, tag = %d\n", node, sp, node->tag);
 	if (node->tag == node_ast)
@@ -582,9 +597,8 @@ void codegen(ast *node)
 				real = (*node->info.string == '%');
 				break;
 			}
-			printf("error: variable '%s' used before assignment\n",
+			compiler_error("variable '%s' used before assignment",
 			    var.name);
-			exit(EXIT_FAILURE);
 		}
 //		printf("sp = %d\n", sp);
 		if (var.flags & VAR_REAL)
@@ -1267,6 +1281,7 @@ void output_code(void)
 		if (!lookup_constant_string(x, &abiver))	\
 			printf("%s not defined\n", x);		\
 		output_int(abiver);				\
+		printf("ABIVERSION(%s) = %x\n", x, abiver);				\
 	} while (0)
 
 	pc = (pc + 3) & ~3;	/* Align table */