rev 212 - trunk/src

SVN User <[email protected]>
Newsgroups gmane.comp.lang.prothon.cvs
Message-ID <[email protected]>
Author: bcollins
Date: 2004-03-30 12:33:25 -0500 (Tue, 30 Mar 2004)
New Revision: 212

Modified:
   trunk/src/interp.c
   trunk/src/prothon.y
Log:
Fix getch. When it would pull from the old_chars, it would not check to
see if that char was a newline, which would need to increment line, and
reset columns. This fixes bug #8, for when there's an exception, the
line/col would be printed incorrectly.


Modified: trunk/src/interp.c
===================================================================
--- trunk/src/interp.c	2004-03-30 16:49:03 UTC (rev 211)
+++ trunk/src/interp.c	2004-03-30 17:33:25 UTC (rev 212)
@@ -294,7 +294,7 @@
 	if (!fstk_obj)
 		set_attr(ist, orig_excobj, sym(ist, "frame_stack"), (fstk_obj = new_list_obj(10)));
 	srcmap = frame->code->srcmap;
-	for (i=0; i < clist_len(srcmap); i+=3){
+	for (i = 0; i < clist_len(srcmap); i += 3) {
 		pc = clist_num(srcmap, i);
 		if (fr_pc < pc) break;
 		line = clist_num(srcmap, i+1);
@@ -1191,35 +1191,44 @@
 }
 
 //******************************** check_exceptions ***************************
-obj_p check_exceptions(isp ist){
-	if (intrp_exobj){
-		int i;
-		obj_p bl, fstk_obj, orig_excobj = intrp_exobj;
-		ist->exception_obj = 0;
-		bl = proto_list(ist, orig_excobj);
-		printf("\nUncaught exception:\n");
-		if ((fstk_obj = get_attr(ist, orig_excobj, sym(ist, "frame_stack")))) {
-			for (i=list_len(ist, fstk_obj)-3; i >= 0; i -= 3)
-				printf( "--- File: %s, line: "LONG_LONG_FMT", char: "LONG_LONG_FMT"\n",
-					strch(list_item(ist, fstk_obj, i  )), 
-					*((LONG_LONG_CAST *)obj_data_p(list_item(ist, fstk_obj, i+1))), 
-					*((LONG_LONG_CAST *)obj_data_p(list_item(ist, fstk_obj, i+2))) );
+obj_p check_exceptions(isp ist)
+{
+	int i;
+	obj_p bl, fstk_obj, orig_excobj = intrp_exobj;
+
+	if (!intrp_exobj)
+		return NULL;
+
+	ist->exception_obj = 0;
+	bl = proto_list(ist, orig_excobj);
+
+	printf("\nUncaught exception:\n");
+
+	if ((fstk_obj = get_attr(ist, orig_excobj, sym(ist, "frame_stack")))) {
+		for (i = list_len(ist, fstk_obj) - 3; i >= 0; i -= 3) {
+			printf( "--- File: %s, line: "LONG_LONG_FMT", char: "LONG_LONG_FMT"\n",
+				strch(list_item(ist, fstk_obj, i  )), 
+				*((LONG_LONG_CAST *)obj_data_p(list_item(ist, fstk_obj, i+1))), 
+				*((LONG_LONG_CAST *)obj_data_p(list_item(ist, fstk_obj, i+2))) );
 		}
-		if (bl)
-			for (i=list_len(ist, bl)-1; i >= 0; i--){
-				obj_p exc = list_item(ist, bl, i);
-				if ( exc && exc != OBJ(EXCEPTION) && 
-					 has_proto(ist, exc, OBJ(EXCEPTION)) ) {
-					obj_p doc = get_attr(ist, exc, SYM(__DOC__));
-					if (doc && exc != orig_excobj)
-						printf("%s, ", strch(doc));
-					else if (doc)
-						printf("%s.\n\n", strch(doc));
-				}
+	}
+
+	if (bl) {
+		for (i = list_len(ist, bl) - 1; i >= 0; i--){
+			obj_p exc = list_item(ist, bl, i);
+
+			if (exc && exc != OBJ(EXCEPTION) && has_proto(ist, exc, OBJ(EXCEPTION))) {
+				obj_p doc = get_attr(ist, exc, SYM(__DOC__));
+
+				if (doc && exc != orig_excobj)
+					printf("%s, ", strch(doc));
+				else if (doc)
+					printf("%s.\n\n", strch(doc));
 			}
-		return orig_excobj;
+		}
 	}
-	return NULL;
+
+	return orig_excobj;
 }
 
 //******************************** exec_string ********************************

Modified: trunk/src/prothon.y
===================================================================
--- trunk/src/prothon.y	2004-03-30 16:49:03 UTC (rev 211)
+++ trunk/src/prothon.y	2004-03-30 17:33:25 UTC (rev 212)
@@ -629,9 +629,15 @@
 // increment lines and columns for YYLTYPE in parser
 char getch(parse_state* stat){
 	char c;
-	if (stat->char_ptr)
+	if (stat->char_ptr) {
 		c = stat->old_chars[--stat->char_ptr];
-	else if (stat->stream) {
+		if (c == '\n') {
+			stat->line++;
+			stat->old_column = stat->column;
+			stat->column = 1;
+			return '\n';
+		}
+	} else if (stat->stream) {
 		c = fgetc(stat->stream);
 		if (c == '\r' || c == '\n'){
 			if (c == '\r' && (c = fgetc(stat->stream)) != '\n')
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.