rev 239 - in trunk: . include/prothon modules/Re pr src

SVN User <[email protected]>
Newsgroups gmane.comp.lang.prothon.cvs
Message-ID <[email protected]>
Author: mark
Date: 2004-03-31 17:36:04 -0500 (Wed, 31 Mar 2004)
New Revision: 239

Modified:
   trunk/STATUS.txt
   trunk/include/prothon/prothon.h
   trunk/modules/Re/Re.c
   trunk/pr/re_test.pr
   trunk/src/builtins.c
   trunk/src/init.pth
   trunk/src/interp.c
Log:
fixed exceptions occuring in prothon code called from C code

Modified: trunk/STATUS.txt
===================================================================
--- trunk/STATUS.txt	2004-03-31 19:43:45 UTC (rev 238)
+++ trunk/STATUS.txt	2004-03-31 22:36:04 UTC (rev 239)
@@ -41,6 +41,8 @@
 
 ----------------------- TO-DO (highest priority first) ------------------------
 
+--- catch exceptions during module loading
+
 --- smarter continuation - remove \
 
 --- make print a function

Modified: trunk/include/prothon/prothon.h
===================================================================
--- trunk/include/prothon/prothon.h	2004-03-31 19:43:45 UTC (rev 238)
+++ trunk/include/prothon/prothon.h	2004-03-31 22:36:04 UTC (rev 239)
@@ -90,7 +90,7 @@
 //#define DEBUG_THREADS
 //#define DEBUG_MEM_MGR
 //#define TRACE_PARSER
-//#define TRACE_INTERPRETER
+#define TRACE_INTERPRETER
 //#define DUMP_MODULE_CODE
 //#define DUMP_OBJECTS_AT_END
 

Modified: trunk/modules/Re/Re.c
===================================================================
--- trunk/modules/Re/Re.c	2004-03-31 19:43:45 UTC (rev 238)
+++ trunk/modules/Re/Re.c	2004-03-31 22:36:04 UTC (rev 239)
@@ -466,8 +466,9 @@
 		lastindex_obj->data.i64 = last_index;
 		if (repl_is_func) {
 			read_unlock(ist, parms[1]);
-			repl_obj = call_func(ist, parms[1], NULL, 2, arr, NULL); if_exc_return NULL;
+			repl_obj = call_func(ist, parms[1], NULL, 2, arr, NULL); 
 			read_lock(ist, parms[1]);
+			if_exc_return NULL;
 			if (repl_obj == OBJ(NONE)) repl = "";
 			else {
 				if (!has_proto_QUES(ist, repl_obj, OBJ(STRING_PROTO))) {

Modified: trunk/pr/re_test.pr
===================================================================
--- trunk/pr/re_test.pr	2004-03-31 19:43:45 UTC (rev 238)
+++ trunk/pr/re_test.pr	2004-03-31 22:36:04 UTC (rev 239)
@@ -1,6 +1,6 @@
 #!/usr/local/bin/prothon
 
-import Re, List
+import Re
 
 def findall(r,s):
 	result=[]
@@ -37,3 +37,5 @@
 print "['this ', ' likes to ', ' around in minks']"
 print "mark ('mark')"
 print " mark like (' mark like', 'mark', 'like') grp1:<mark> grp2:<like>"
+
+print [1,2] + [3,4]

Modified: trunk/src/builtins.c
===================================================================
--- trunk/src/builtins.c	2004-03-31 19:43:45 UTC (rev 238)
+++ trunk/src/builtins.c	2004-03-31 22:36:04 UTC (rev 239)
@@ -886,7 +886,6 @@
 	lstp = Tuple_OBJ->data.ptr = pr_malloc((LIST_OVERHEAD+2) * sizeof(list_t));
 	lstpsize(lstp) = 2;
 	lstplen(lstp)  = 0;
-	set_immutable(Tuple_OBJ);
 }
 
 DEF(Tuple, __str__, NULL) {
@@ -926,7 +925,6 @@
 	lstp = List_OBJ->data.ptr = pr_malloc((LIST_OVERHEAD+2) * sizeof(list_t));
 	lstpsize(lstp) = 2;
 	lstplen(lstp)  = 0;
-	set_immutable(List_OBJ);
 }
 
 DEF(List, __str__, NULL) {
@@ -1164,7 +1162,6 @@
         dict = obj_malloc(Dict_OBJ, (DICT_OVERHEAD+DEFAULT_INITIAL_DICT_SIZE)*sizeof(dict_t));
         memset(dict, 0, (DICT_OVERHEAD+DEFAULT_INITIAL_DICT_SIZE)*sizeof(dict_t));
         dictsize(dict) = DEFAULT_INITIAL_DICT_SIZE;
-	set_immutable(Dict_OBJ);
 }
 
 DEF(Dict, __str__, NULL) {

Modified: trunk/src/init.pth
===================================================================
--- trunk/src/init.pth	2004-03-31 19:43:45 UTC (rev 238)
+++ trunk/src/init.pth	2004-03-31 22:36:04 UTC (rev 239)
@@ -14,5 +14,5 @@
 
 # this is executed before Main as module PthMod1
 
-import Float, String, File, Re, List, Tuple
+import Float, String, File, Re, Tuple
 
Modified: trunk/src/interp.c
===================================================================
--- trunk/src/interp.c	2004-03-31 19:43:45 UTC (rev 238)
+++ trunk/src/interp.c	2004-03-31 22:36:04 UTC (rev 239)
@@ -559,6 +559,12 @@
 	int exc_final=0, exc_final_return=0, stack_lim = frame->code->max_stack_depth;
 	obj_p exc_waiting=NULL, return_value = 0;
 
+#ifdef TRACE_INTERPRETER
+	if (!tfout) tfout = fopen("code_trace.txt", "w");
+	fprintf(tfout, "--- starting exec_loop at frame %8x, pc: %d\n", (intptr_t) frame, frame->pc);
+	fflush(tfout);
+#endif
+
 	have_exstk = (fr_exstk && clist_len(fr_exstk));
 	if (have_exstk) {
 		exception_entry_t* p = (exception_entry_t*)(clist_tos(fr_exstk));
@@ -581,6 +587,10 @@
 			} else have_exstk = FALSE;
 		}
 		if (fr_pc >= fr_code->len){
+#ifdef TRACE_INTERPRETER
+			fprintf(tfout, "--- ran off end of code at pc: %d\n", (intptr_t) frame->pc);
+			fflush(tfout);
+#endif
 			return_value = do_return(ist, frame, &switch_frame, &free_frame, return_value);
 			if (intrp_exobj) goto endop;
 			return_flag = fr_ccall;
@@ -938,6 +948,7 @@
 								frame->dyn_locals);
 					post_call_unlock(slf, plist);
 					free_clist(plist);
+					if (intrp_exobj) break;
 					fr_push(res);
 				} else if (has_proto_QUES(ist, func_obj, OBJ(FUNC_PROTO))) {
 					obj_p new_locals;
@@ -1070,20 +1081,29 @@
 endop:
 		if (intrp_exobj) {
 			int frame_chg = FALSE;
+			int last_called_from_c = FALSE;
 
 #ifdef TRACE_INTERPRETER
 			fprintf(tfout, "---exception---\n");
+			fflush(tfout);
 #endif
 
 			fr_sp = 0;
 			add_frame_to_exception(ist, frame);
-			while (!have_exstk && frame->prev_frame ) {
+			while (!have_exstk && frame->prev_frame && !last_called_from_c) {
 				exec_frame_t* tmp_frame = frame;
+				last_called_from_c = frame->called_from_c;
 				frame = ist->frame = frame->prev_frame;
+#ifdef TRACE_INTERPRETER
+				fprintf(tfout, "--- delete top frame %8x\n", (intptr_t) tmp_frame);
+				fprintf(tfout, "--- new top frame is %8x\n", (intptr_t) frame);
+				fflush(tfout);
+#endif
 				stack_lim = frame->code->max_stack_depth;
 				// free_frame(tmp_frame);  XXX
 				if (!tmp_frame->do_not_free)
 					pr_free(tmp_frame);
+				frame->next_frame = NULL;
 				have_exstk = (fr_exstk && clist_len(fr_exstk));
 				frame_chg = TRUE;
 				add_frame_to_exception(ist, frame);
@@ -1117,7 +1137,12 @@
 			while(switch_frame != DONE_FRAME_FLAG && switch_frame->next_frame) 
 				switch_frame = switch_frame->next_frame;
 			frame = ist->frame = switch_frame;
+#ifdef TRACE_INTERPRETER
 			if (frame != DONE_FRAME_FLAG)
+				fprintf(tfout, "--- switch to frame %8x\n", (intptr_t) frame);
+			fflush(tfout);
+#endif
+			if (frame != DONE_FRAME_FLAG)
 				stack_lim = frame->code->max_stack_depth;
 			if ((have_exstk = (frame != DONE_FRAME_FLAG && fr_exstk && clist_len(fr_exstk)))) {
 				exception_entry_t* p = (exception_entry_t*)(clist_tos(fr_exstk));
@@ -1127,6 +1152,10 @@
 			}
 		}
 		if (return_flag || frame == DONE_FRAME_FLAG) {
+#ifdef TRACE_INTERPRETER
+			fprintf(tfout, "--- exiting exec_loop, value: %8x\n", (intptr_t) return_value);
+			fflush(tfout);
+#endif
 			if (frame == DONE_FRAME_FLAG) frame = ist->frame = NULL;
 			return return_value;
 		}
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.