rev 583 - in trunk: pr/test src

SVN User <[email protected]> Mon, 07 Jun 2004 04:54:26 -0400
Newsgroups gmane.comp.lang.prothon.cvs
Message-ID <[email protected]>
Author: mark
Date: 2004-06-07 04:54:22 -0400 (Mon, 07 Jun 2004)
New Revision: 583

Added:
   trunk/pr/test/finally.pr
Modified:
   trunk/pr/test/test.pr
   trunk/src/interp.c
   trunk/src/parser_routines.c
Log:
fixed list comprehension on generators bug, 
added finally.pr (which fails right now)

Added: trunk/pr/test/finally.pr
===================================================================
--- trunk/pr/test/finally.pr	2004-06-07 05:27:07 UTC (rev 582)
+++ trunk/pr/test/finally.pr	2004-06-07 08:54:22 UTC (rev 583)
@@ -0,0 +1,33 @@
+#!/usr/bin/env prothon
+
+def f():
+    try:
+        return 9
+    finally:
+        print "Finally"
+
+print "-- The output should be --"
+print "Finally"
+print 9
+print "1)"
+print "Finally"
+print "2)"
+print "Finally"
+print "Name Error raised."
+print "--------------------------"
+print f()
+
+def f(doRaise):
+    try:
+        if doRaise:
+            raise NameError
+    finally:
+        print "Finally"
+
+try:
+    print "1)"
+    f(False)
+    print "2)"
+    f(True)
+except NameError:
+    print "Name Error raised."


Property changes on: trunk/pr/test/finally.pr
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: trunk/pr/test/test.pr
===================================================================
--- trunk/pr/test/test.pr	2004-06-07 05:27:07 UTC (rev 582)
+++ trunk/pr/test/test.pr	2004-06-07 08:54:22 UTC (rev 583)
@@ -1,54 +1,33 @@
 #!/usr/bin/env prothon
 
-def refer(start, attrname):
-    mro = self.protoChain()
-    n = mro.len()
-    i = 0
-    while i < n:
-        if mro[i] is start:
-            break
-        i = i+1
-    if i == n:
-        raise AttributeError
-    while True:
-        i = i+1
-        if i == n:
-            break
-        o = mro[i]
-        attrs = o.attrs_
-        if attrname in attrs:
-            a = attrs[attrname]
-            if a.hasProto?(Func):
-                return a 
-            print "not func:", a
-            return a
-    raise AttributeError
+def f():
+    try:
+        return 9
+    finally:
+        print "Finally"
 
-object ModInt(Int):
-    modulo = 10
-    def call_(i=0):
-        call = refer(ModInt, 'call_')
-        return call{self}(i % self.modulo)
+print "-- The output should be --"
+print "Finally"
+print 9
+print "1)"
+print "Finally"
+print "2)"
+print "Finally"
+print "Name Error raised."
+print "--------------------------"
+print f()
 
-    def add_(other):
-        if self.modulo != other.modulo:
-            raise TypeError
-        proto = self.protoChain()[1]
-        add = refer(ModInt, 'add_')
-        x =  proto(add{self}(other))
-        return x
+def f(doRaise):
+    try:
+        if doRaise:
+            raise NameError
+    finally:
+        print "Finally"
 
-object Mod8Int(ModInt):
-    modulo = 8
-
-m = Mod8Int(0)
-n = Mod8Int(1)
-for i in 100:
-    if m != i % 8:
-        print "test failed:",i
-        Sys.exit(1)
-    m = m + n
-
-print """
-All tests passed
-"""
+try:
+    print "1)"
+    f(False)
+    print "2)"
+    f(True)
+except NameError:
+    print "Name Error raised."

Modified: trunk/src/interp.c
===================================================================
--- trunk/src/interp.c	2004-06-07 05:27:07 UTC (rev 582)
+++ trunk/src/interp.c	2004-06-07 08:54:22 UTC (rev 583)
@@ -530,9 +530,12 @@
 
 //******************************** add_frame_to_exception *********************
 void add_frame_to_exception(isp ist, frame_p frame) {
-	int i, pc, line=0, col=0; 
+	int i, pc, line=0, col=0, save_access; 
 	clist_p srcmap;
 	obj_p fstk_obj, orig_excobj, str_obj=NULL;
+
+	su(save_access);
+
 	orig_excobj = intrp_exobj;
 	ist->exception_obj = 0;
 	fstk_obj = get_attr(ist, orig_excobj, sym(ist, "frame_stack"));
@@ -551,6 +554,8 @@
 	list_append(ist, fstk_obj, NEW_INT(line));
 	list_append(ist, fstk_obj, NEW_INT(col));
 	ist->exception_obj = orig_excobj;
+
+	un_su(save_access);
 }
 
 #ifdef WIN32
@@ -757,9 +762,10 @@
 		(*switch_frame)->next_frame = NULL;
 	} else
 		*switch_frame = DONE_FRAME_FLAG;
-	if (frame->gen_marker)
+	if (frame->gen_marker) {
+		if (frame->prev_frame) (frame->prev_frame->stack_ptr)--;
 		raise_exception(ist, OBJ(STOP_ITERATION_EXC), NULL);
-	else
+	} else
 		*free_frame = frame;
 	if (!res) res = return_value;
 	return res;

Modified: trunk/src/parser_routines.c
===================================================================
--- trunk/src/parser_routines.c	2004-06-07 05:27:07 UTC (rev 582)
+++ trunk/src/parser_routines.c	2004-06-07 08:54:22 UTC (rev 583)
@@ -1087,14 +1087,8 @@
 	int llen = clist_len(targets)-1, loop_loc, body_loc, els_loc, end_els_loc, end_loc;
 	code_p expr = clist_item(targets, llen);
 	patch_break_continues(clist_item(targets,0), body);
-	for (i=1; i < llen; i++){
-		obj_p s = clist_item(targets,i);
-		if ( !(*(pr_strptr(s)) >= 'a' && *(pr_strptr(s)) <= 'z') && ! *(pr_strptr(s)) == '_'){
-			printf("For variable not local: %s\n", (pr_strptr(s)));
-			pr_exit(1);
-		}
-		clist_item(targets,i) = sym(IST, (pr_strptr(s)));
-	}
+	for (i=1; i < llen; i++)
+		clist_item(targets, i) = sym(IST, pr_strptr((obj_p)clist_item(targets, i)));
 	calc_code(expr, &len, &stack_depth, &max_stack_depth); 
 	len += 5;			
 	loop_loc = len;