rev 679 - in trunk: . include/prothon pr/test src

SVN User <[email protected]> Tue, 29 Jun 2004 23:20:39 -0400
Newsgroups gmane.comp.lang.prothon.cvs
Message-ID <[email protected]>
Author: mark
Date: 2004-06-29 23:20:36 -0400 (Tue, 29 Jun 2004)
New Revision: 679

Modified:
   trunk/STATUS.txt
   trunk/include/prothon/prothon.h
   trunk/pr/test/bin.pr
   trunk/pr/test/chained.pr
   trunk/pr/test/closure.pr
   trunk/pr/test/dict.pr
   trunk/pr/test/test.pr
   trunk/src/clist.c
   trunk/src/clist.h
   trunk/src/interp.c
   trunk/src/lock.h
Log:
set limit to as_str recursion depth

Modified: trunk/STATUS.txt
===================================================================
--- trunk/STATUS.txt	2004-06-29 22:43:01 UTC (rev 678)
+++ trunk/STATUS.txt	2004-06-30 03:20:36 UTC (rev 679)
@@ -1,8 +1,6 @@
 
 ----------------------- TO-DO (highest priority first) ------------------------
 
---- Add properties methods: prop keyword, get_,  set_, delete_, wildcards
-
 --- change file.setStdout to property
 
 --- OSThread, Thread, and Gate

Modified: trunk/include/prothon/prothon.h
===================================================================
--- trunk/include/prothon/prothon.h	2004-06-29 22:43:01 UTC (rev 678)
+++ trunk/include/prothon/prothon.h	2004-06-30 03:20:36 UTC (rev 679)
@@ -97,8 +97,12 @@
 #define PR_DECLARE_EXPORT
 #endif
 
-//************************* BASIC TYPE DEFINITIONS ********************************
+//************************* SOME APPLICATION TUNING ***************************
+#define AS_STR_MAX_DEPTH 10
 
+
+//************************* BASIC TYPE DEFINITIONS ****************************
+
 typedef signed char			i8_t;
 typedef apr_int16_t			i16_t;
 typedef apr_int32_t			i32_t;
@@ -526,6 +530,7 @@
 	frame_p		frame;
 	int			in_console;
 	int			notify_flags;
+	void*		as_str_stack;
 	obj_p		exception_obj;
 } interp_state_t;
  
@@ -1144,10 +1149,10 @@
 
 // COVERS: Macro to determine if a type can be coerced to another type
 // Returns true if data type of o1 can represent all data that type of o2 can
-// represent.  For example, float type "covers" int type and long type "covers"
-// int type.  Covering a value does not mean that some precision will not be lost.
+// represent.  For example, float type "covers" int type.
+// Covering a value may mean that some precision will be lost.
 // This test determines when coercion is allowed.  It is up to the prototype
-// objects to decide which objects they cover by offering the covers__QUES function.
+// objects to decide which objects they cover by offering the covers_ function.
 #define covers(o1, o2) (call_func1((ist), (o1), SYM(COVERS_), (o2)) == OBJ(PR_TRUE))
 
 

Modified: trunk/pr/test/bin.pr
===================================================================
--- trunk/pr/test/bin.pr	2004-06-29 22:43:01 UTC (rev 678)
+++ trunk/pr/test/bin.pr	2004-06-30 03:20:36 UTC (rev 679)
@@ -10,11 +10,11 @@
         
 try:
     with obj: Int.init_{obj}(99)   # init Int a second time
-except x,e: print e    # throws "object has binary data, expected none"
+except x as e: print e    # throws "object has binary data, expected none"
 
 try:
     obj.init_('abc') # init as String
-except x,e: print e     # throws "object has binary data, expected none"
+except x as e: print e     # throws "object has binary data, expected none"
 
 L = newObject(List) # L is uninitialized list
 

Modified: trunk/pr/test/chained.pr
===================================================================
--- trunk/pr/test/chained.pr	2004-06-29 22:43:01 UTC (rev 678)
+++ trunk/pr/test/chained.pr	2004-06-30 03:20:36 UTC (rev 679)
@@ -21,7 +21,7 @@
 print 1 >= 1 == 2 != 2 == 2 > 1 <= 1 <= 2
 
 def f(i):
-	print i,
+	print i, eol=' '
 	return i
 	
 print "\n\nThis should print 0 1 2\n"

Modified: trunk/pr/test/closure.pr
===================================================================
--- trunk/pr/test/closure.pr	2004-06-29 22:43:01 UTC (rev 678)
+++ trunk/pr/test/closure.pr	2004-06-30 03:20:36 UTC (rev 679)
@@ -18,7 +18,7 @@
 			def f4():
 				g=7
 				def count():
-					print outer.a,outer.b,outer.c,outer.d,outer.e,outer.f,outer.g,outer.h,
+					print outer.a,outer.b,outer.c,outer.d,outer.e,outer.f,outer.g,outer.h, eol=' '
 					outer.c = outer.a+outer.b
 					outer.e = outer.c+outer.d
 					outer.g = outer.e+outer.f

Modified: trunk/pr/test/dict.pr
===================================================================
--- trunk/pr/test/dict.pr	2004-06-29 22:43:01 UTC (rev 678)
+++ trunk/pr/test/dict.pr	2004-06-30 03:20:36 UTC (rev 679)
@@ -47,6 +47,6 @@
 1 (1, 2) 3 (3, 4)
 """
 
-for i in e: print i, d.popItem!(),
+for i in e: print i, d.popItem!(),eol=' '
 
 print '\n'

Modified: trunk/pr/test/test.pr
===================================================================
--- trunk/pr/test/test.pr	2004-06-29 22:43:01 UTC (rev 678)
+++ trunk/pr/test/test.pr	2004-06-30 03:20:36 UTC (rev 679)
@@ -1,18 +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"
+object k:
+	def init_(obj):
+		self.obj = obj
+		
+	def str_():
+		return '<k:'+self.obj.str_()+'>'
+		
+kk = [k(99)]
+print kk
 
-p = Proto1()
-p.x = 3
-print p.x
-del p.x
+x = []
+a = k(x)
+print a
 
+x +! [a,kk,a,kk,a,kk]
+print x

Modified: trunk/src/clist.c
===================================================================
--- trunk/src/clist.c	2004-06-29 22:43:01 UTC (rev 678)
+++ trunk/src/clist.c	2004-06-30 03:20:36 UTC (rev 679)
@@ -161,6 +161,16 @@
 	return TRUE;
 }
 
+//********************************* clist_pop_to ******************************
+void clist_pop_to(clist_p list, void* item) {
+	int i;
+	for(i=0; i < list->len; i++)
+		if (list->items[i].ptr == item) {
+			list->len = i;
+			break;
+		}
+}
+
 //********************************* clist_pop_dups ****************************
 void* clist_pop_dups(clist_p list) {
 	void* item = list->items[--(list->len)].ptr;

Modified: trunk/src/clist.h
===================================================================
--- trunk/src/clist.h	2004-06-29 22:43:01 UTC (rev 678)
+++ trunk/src/clist.h	2004-06-30 03:20:36 UTC (rev 679)
@@ -87,6 +87,7 @@
 int clist_in(clist_p list, void* item);
 int clist_in_cnt(clist_p list, void* item);
 int clist_pop_item(clist_p list, void* item);
+void clist_pop_to(clist_p list, void* item);
 void* clist_pop_dups(clist_p list);
 
 #define new_clist_1(item)				ins_clist(new_clist(2), (item), 0)

Modified: trunk/src/interp.c
===================================================================
--- trunk/src/interp.c	2004-06-29 22:43:01 UTC (rev 678)
+++ trunk/src/interp.c	2004-06-30 03:20:36 UTC (rev 679)
@@ -84,7 +84,8 @@
 isp new_ist(access_t access) {
 	isp ist = pr_malloc(sizeof(interp_state_t));
 	memset(ist, 0, sizeof(interp_state_t));
-	ist->lock_stack = new_clist(20);
+	ist->lock_stack   = new_clist(20);
+	ist->as_str_stack = new_clist(20);
 	ist->access = access;
 	return ist;
 }
@@ -100,6 +101,20 @@
 	fflush(tfout);
 }
 
+//******************************** as_str_chk *********************************
+int as_str_chk(isp ist, obj_p sym) {
+	if (sym != SYM(STR_)) return FALSE;
+	if (clist_len(astrstack) >= AS_STR_MAX_DEPTH)
+		return TRUE;
+	clist_append(astrstack, ist->frame);
+	return FALSE;
+}
+
+//******************************** str_chk_clr ********************************
+void str_chk_clr(isp ist, frame_p frame) {
+	clist_pop_to(astrstack, frame);
+}
+
 //******************************** new_parmptr_obj ****************************
 obj_p new_parmptr_obj(isp ist, int ofs) {
 	obj_p new_obj = new_object(ist, OBJ(PARMPTR_PROTO));
@@ -1242,6 +1257,10 @@
 				}
 				fr_sp -= 2+2*param;
 				func_obj = fr_stack[fr_sp];
+				if (as_str_chk(ist, fr_stack[fr_sp+1])) {
+					fr_push(NEW_STRING("..."));
+					goto break_loc;
+				}
 				if (cmd_flag && !get_attr(ist, func_obj, SYM(COMMAND_))) {
 					if (param == 0) {
 						fr_sp++;
@@ -1417,6 +1436,10 @@
 				}
 				fr_sp -= 3+(2*param);
 				name_obj = fr_stack[fr_sp+1];
+				if (as_str_chk(ist, name_obj)) {
+					fr_push(NEW_STRING("..."));
+					goto break_loc;
+				}
 				if (has_proto(ist, name_obj, OBJ(SUPER_PROTO))) {
 					obj_p cont = get_attr(ist, name_obj, SYM(CONT_));
 					name_obj = name_obj->data.ptr;
@@ -1741,10 +1764,13 @@
 		}
 		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);
 		}
 		if (switch_frame) {
+			str_chk_clr(ist, switch_frame);
 			while(switch_frame != DONE_FRAME_FLAG && switch_frame->next_frame) 
 				switch_frame = switch_frame->next_frame;
 			frame = ist->frame = switch_frame;
@@ -1788,6 +1814,8 @@
 	if (!cont_self) {
 		func_obj = func_sym; 
 	} else {
+		if (as_str_chk(ist, func_sym))
+			return NEW_STRING("...");
 		func_obj = get_proto_attr(ist, cont_self, func_sym, NULL, super_obj); if_exc_return NULL;
 		if (!func_obj) {
 			if (!ist) {

Modified: trunk/src/lock.h
===================================================================
--- trunk/src/lock.h	2004-06-29 22:43:01 UTC (rev 678)
+++ trunk/src/lock.h	2004-06-30 03:20:36 UTC (rev 679)
@@ -72,6 +72,7 @@
 #endif
 
 #define lockstack	((clist_p)(ist->lock_stack))
+#define astrstack	((clist_p)(ist->as_str_stack))
 
 typedef struct {
 	int					waiting;