rev 685 - in trunk: include/prothon pr/test src

SVN User <[email protected]> Thu, 01 Jul 2004 01:44:42 -0400
Newsgroups gmane.comp.lang.prothon.cvs
Message-ID <[email protected]>
Author: mark
Date: 2004-07-01 01:44:39 -0400 (Thu, 01 Jul 2004)
New Revision: 685

Added:
   trunk/pr/test/assign.pr
   trunk/pr/test/prop.pr
   trunk/pr/test/weakref.pr
Modified:
   trunk/include/prothon/prothon.h
   trunk/pr/test/dict.pr
   trunk/pr/test/test.pr
   trunk/src/interp.c
Log:
working on dict.pr bug that only happens in uedit

Modified: trunk/include/prothon/prothon.h
===================================================================
--- trunk/include/prothon/prothon.h	2004-07-01 00:38:18 UTC (rev 684)
+++ trunk/include/prothon/prothon.h	2004-07-01 05:44:39 UTC (rev 685)
@@ -98,7 +98,7 @@
 #endif
 
 //************************* SOME APPLICATION TUNING ***************************
-#define AS_STR_MAX_DEPTH 10
+#define AS_STR_MAX_DEPTH 8
 
 
 //************************* BASIC TYPE DEFINITIONS ****************************

Added: trunk/pr/test/assign.pr
===================================================================
--- trunk/pr/test/assign.pr	2004-07-01 00:38:18 UTC (rev 684)
+++ trunk/pr/test/assign.pr	2004-07-01 05:44:39 UTC (rev 685)
@@ -0,0 +1,15 @@
+#!/usr/bin/env prothon
+
+for i in 5:
+	print i
+	
+a, b = (1,2)
+print a,b
+
+gen g():
+	for i in 3:
+		y = (2*i, 3*i)
+		yield y
+	
+for a, b in g():
+	print a,b


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

Modified: trunk/pr/test/dict.pr
===================================================================
--- trunk/pr/test/dict.pr	2004-07-01 00:38:18 UTC (rev 684)
+++ trunk/pr/test/dict.pr	2004-07-01 05:44:39 UTC (rev 685)
@@ -22,7 +22,7 @@
    
 if d.items() != e.items():
     err( 'error1' )
-    
+  
 if len(e.items()) != 2:
     err( 'error2' )
 

Added: trunk/pr/test/prop.pr
===================================================================
--- trunk/pr/test/prop.pr	2004-07-01 00:38:18 UTC (rev 684)
+++ trunk/pr/test/prop.pr	2004-07-01 05:44:39 UTC (rev 685)
@@ -0,0 +1,18 @@
+#!/usr/bin/env prothon
+
+object Proto1:
+	x_ = 6
+	prop x:
+		def get_():
+			return self.x_
+		def set_(v):
+			self.x_ = v
+			return v
+		def del_():
+			print "illegal delete operation"
+
+p = Proto1()
+p.x = 3
+print p.x
+del p.x
+


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

Modified: trunk/pr/test/test.pr
===================================================================
--- trunk/pr/test/test.pr	2004-07-01 00:38:18 UTC (rev 684)
+++ trunk/pr/test/test.pr	2004-07-01 05:44:39 UTC (rev 685)
@@ -1,3 +1,52 @@
 #!/usr/bin/env prothon
 
-print sys.stdIn.readLine()
\ No newline at end of file
+# dict.pr
+
+def err(str):
+    print str
+    sys.exit(1)
+
+d = {1:2}
+if d.keys()   != [1]  : err( 'error in keys' )
+if d.values() != [2]  : err( 'error in values' )
+if d.get(1)   !=  2   : err( 'error1 in get' )
+if d.get(2)   != None : err( 'error2 in get' )
+if d.get(3,4) !=  4   : err( 'error3 in get' )
+if d.get(3,5) !=  5   : err( 'error4 in get' )
+if d.setDefault!(3,4) !=  4   : err( 'error5 in setdefault' )
+if d.get(3,5) !=  4   : err( 'error6 in get' )
+if 3 not in d: err( 'error 7 in not in' )
+
+d = {1:2, 3:4}
+e = d.copy()
+   
+if d.items() != e.items():
+    err( 'error1' )
+  
+if len(e.items()) != 2:
+    err( 'error2' )
+
+d.clear!()
+
+d = {1:2}
+d.update!({3:4})
+if d.items() != e.items():
+    err( 'error3' )
+
+if not e.hasKey?(1) or e.hasKey?(2): err( 'error4' )
+
+dd = Dict(a=1)
+
+if $a  not in dd: err( 'error5' )
+if "a" not in dd: err( 'error6' )
+
+print 'all tests passed'
+
+print """
+The following should be:  
+1 (1, 2) 3 (3, 4)
+"""
+
+for i in e: print i, d.popItem!(),eol=' '
+
+print '\n'

Added: trunk/pr/test/weakref.pr
===================================================================
--- trunk/pr/test/weakref.pr	2004-07-01 00:38:18 UTC (rev 684)
+++ trunk/pr/test/weakref.pr	2004-07-01 05:44:39 UTC (rev 685)
@@ -0,0 +1,35 @@
+#!/usr/bin/env prothon
+
+x = []
+weakref = WeakRef(x)
+print WeakRef
+print weakref
+print weakref.ref()
+print weakref.exists?()
+print WeakRef.READ
+print WeakRef.WRITE
+print WeakRef.DELETE
+
+print "weakref.flags()", weakref.flags()
+
+def callbk(flgs):
+	if flgs & WeakRef.READ: print 'READ'
+	if flgs & WeakRef.WRITE: print 'WRITE'
+	if flgs & WeakRef.DELETE: print 'DELETE'
+cb = callbk{weakref}
+
+weakref.notify(cb, flags = WeakRef.READ | WeakRef.WRITE | WeakRef.DELETE)
+
+print "before print read test"
+print x
+
+print 'switching to write and del only'
+
+weakref.notify(cb, flags = WeakRef.WRITE | WeakRef.DELETE)
+print 'after switching to write and del only'
+
+print "before write test"
+x.append!(1)
+
+print "before delete test"
+del x


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

Modified: trunk/src/interp.c
===================================================================
--- trunk/src/interp.c	2004-07-01 00:38:18 UTC (rev 684)
+++ trunk/src/interp.c	2004-07-01 05:44:39 UTC (rev 685)
@@ -1792,8 +1792,6 @@
 		}
 		if (free_frame) {
 			// free_frame(tmp_frame);  XXX
-			str_chk_clr(ist, free_frame);
-			str_chk_clr(ist, free_frame);
 			if (!free_frame->do_not_free)
 				pr_free(free_frame);
 		}
@@ -1835,7 +1833,7 @@
 //******************************** call_func **********************************
 obj_p call_func( isp ist, obj_p cont_self, obj_p func_sym, obj_p self,
 				 int parm_cnt, obj_p* lbl_val_arr, obj_p super_obj ) {
-	obj_p func_obj;
+	obj_p func_obj, res;
 	frame_p new_frame;
 	if (!self) self = cont_self;
 	if (!self) self = NEW_OBJ(NULL);
@@ -1856,12 +1854,14 @@
 					new_frame = genp->frame;
 					if (!new_frame) {
 						raise_exception(ist, OBJ(STOP_ITERATION_EXC), NULL);
+						str_chk_clr(ist, ist->frame);
 						return NULL;
 					}
 					goto gotnewframe;
 			}
 			raise_exception(ist, OBJ(FUNCNOTFOUND_EXC), "Function not found: \"%s\"",
 					                                     as_str(ist, func_sym));
+			str_chk_clr(ist, ist->frame);
 			return NULL;
 		}
 	}
@@ -1870,13 +1870,14 @@
 		clist_p plist = get_func_params( ist, func_obj, parm_cnt, lbl_val_arr);
 		if (! (aself = get_attr(ist, func_obj, SYM(BINDOBJ_))) )
 			aself = self;     if_exc_return 0;
-		pre_call_lock(ist, aself, plist); if (intrp_exobj) return NULL;
+		pre_call_lock(ist, aself, plist); if (intrp_exobj) { str_chk_clr(ist, ist->frame); return NULL; }
 		res = ((pr_func*)(func_obj->data.ptr)) 
 								(ist, aself, (plist ? clist_len(plist) : 0), 
 								(plist ? (obj_p*)plist->items : NULL), super_obj);
 		post_call_unlock(ist, aself, plist);
 		free_clist(plist);
-		if (intrp_exobj) return NULL;
+		if (intrp_exobj) { str_chk_clr(ist, ist->frame); return NULL; }
+		str_chk_clr(ist, ist->frame);
 		return res;
 	} else if ( func_obj != OBJ(FUNC_PROTO) && 
 		        has_proto(ist, func_obj, OBJ(FUNC_PROTO)) ) {
@@ -1887,19 +1888,23 @@
 
 		if (!ist) {
 			raise_exception(ist, OBJ(INTERNAL_EXC), "Illegal function call to Prothon function");
+			str_chk_clr(ist, ist->frame);
 			return 0;
 		}
 		if (intrp_exobj) {
+			str_chk_clr(ist, ist->frame);
 			return 0;
 		}
 		frame = ist->frame;
 		if (intrp_exobj) {
+			str_chk_clr(ist, ist->frame);
 			return 0;
 		}
 		if (! (aself = get_attr(ist, func_obj, SYM(BINDOBJ_))) )
 			aself = self;   if_exc_return 0;
 		if (get_frame_params(ist, &idx, &fps, &new_locals, func_obj, parm_cnt, lbl_val_arr)) {
 			raise_exception(ist, OBJ(INTERNAL_EXC), "default values not allowed in call_func");
+			str_chk_clr(ist, ist->frame);
 			return NULL;
 		}
 		new_frame = create_frame( ist, aself, NULL, NULL, 
@@ -1911,11 +1916,15 @@
 		ist->frame = new_frame;
 		ist->frame->called_from_c = TRUE;
 		if (intrp_exobj) {
+			str_chk_clr(ist, ist->frame);
 			return 0;
 		}
-		return exec_loop(ist);
+		res = exec_loop(ist);
+		str_chk_clr(ist, ist->frame);
+		return res;
 	} else {
 		raise_exception(ist, OBJ(FUNCNOTFOUND_EXC), "Function not found");
+		str_chk_clr(ist, ist->frame);
 		return 0;
 	}
 }