rev 457 - in trunk: . include/prothon pr src

SVN User <[email protected]> Tue, 04 May 2004 15:38:40 -0400
Newsgroups gmane.comp.lang.prothon.cvs
Message-ID <[email protected]>
Author: mark
Date: 2004-05-04 15:38:37 -0400 (Tue, 04 May 2004)
New Revision: 457

Added:
   trunk/pr/bind2.pr
Removed:
   trunk/pr/bug.pr
   trunk/pr/bug2.pr
Modified:
   trunk/STATUS.txt
   trunk/include/prothon/prothon.h
   trunk/include/prothon/prothon_dll.h
   trunk/pr/test.pr
   trunk/src/builtins-dict.c
   trunk/src/builtins-float.c
   trunk/src/builtins-int.c
   trunk/src/builtins-list.c
   trunk/src/builtins-string.c
   trunk/src/builtins-thread.c
   trunk/src/builtins-tuple.c
   trunk/src/interp.c
Log:
added proper __str__ printing for uninitialized immutables
and for prototypes, fixed many bugs

Modified: trunk/STATUS.txt
===================================================================
--- trunk/STATUS.txt	2004-05-04 06:48:34 UTC (rev 456)
+++ trunk/STATUS.txt	2004-05-04 19:38:37 UTC (rev 457)
@@ -1,18 +1,14 @@
 
 ----------------------- TO-DO (highest priority first) ------------------------
 
---- what C standard should project use?
+--- Auto-documenter app
 
---- fix bug1.pr and bug2.pr
-
 --- networking code -- web access demonstration of security
 
 --- Complete File/Dir objects
 --- add support for APR_BINARY in File.c ('b' flag)
 --- support any object that supports file methods in stdxxx (duck std)
 
---- Auto-documenter app
-
 --- How do we add "properties", "descriptors"?
 
 --- help() in interactive console()

Modified: trunk/include/prothon/prothon.h
===================================================================
--- trunk/include/prothon/prothon.h	2004-05-04 06:48:34 UTC (rev 456)
+++ trunk/include/prothon/prothon.h	2004-05-04 19:38:37 UTC (rev 457)
@@ -478,7 +478,9 @@
           "object binary data overwrite attempt");		\
 	else { (obj)->data_type = (type);					\
 		    obj_set_data_owner(ist, obj, owner);		\
-	} if (ist->exception_obj)
+	} if (ist->exception_obj)							\
+			(obj)->data_type = DATA_TYPE_NONE;			\
+	if (ist->exception_obj) 
   
 // PROTO_OWNS_BINARY: Prototype owns binary data in obj
 // for example, if proto is Int, then binary data is in Int format
@@ -504,8 +506,8 @@
 // inheritance is solved.  When it returns an attr you need to check *proto_pp
 // to see which object the attr actually came from.  If proto_pp is NULL then this 
 // info is not returned.
-// When "second" is set, the search returns the second attribute found in the list
-// of prototypes.  This is used for "super" searches.
+// When super_obj is set, the search starts after the object super_obj in the 
+// prototype chain.
 // The ist param may return an exception object if proto pointers are missing 
 // or have a circular reference.  See section "INTERPRETER STATE".
 obj_p get_proto_attr(isp ist, obj_p object, obj_p key, obj_p *proto_pp, obj_p super_obj);
@@ -978,7 +980,8 @@
 // putting PARAM_STAR or PARAM_STAR_STAR in the label (even) position and the list or 
 // dictionary object in the value (odd) position.  parm_cnt is the length of the array,
 // (2 times the number of actual parameters).
-// You may pass a dyn_locals object to simulate the Prothon dynamic scoping behaviour.  
+// When super_obj is set, the search for the function starts after the object super_obj
+// in the prototype chain.
 // An object if always returned, at least OBJ(NONE) if nothing else.  This object will 
 // usually have the del_locked bit set so call del_unlock(obj) after you are done with
 // the object (see OBJECT LOCKING section below).
@@ -988,7 +991,7 @@
 // Example: "sum=x+y"  =>  sum = call_func(ist, x, sym(ist, "__add__"), 2, y_arr, NULL);
 //         where y_arr =>  obj_p y_arr[2] = {NULL, y};
 obj_p call_func( isp ist, obj_p self, obj_p func_sym, 
-				 int parm_cnt, obj_p* lbl_val_arr, obj_p dyn_locals );
+				 int parm_cnt, obj_p* lbl_val_arr, obj_p super_obj );
 
 
 //********************** CONVENIENT FUNCTION CALLS ****************************

Modified: trunk/include/prothon/prothon_dll.h
===================================================================
--- trunk/include/prothon/prothon_dll.h	2004-05-04 06:48:34 UTC (rev 456)
+++ trunk/include/prothon/prothon_dll.h	2004-05-04 19:38:37 UTC (rev 457)
@@ -180,6 +180,14 @@
 			"object has binary data, expected none");	\
 		return NULL; }									
 
+#define BIN_STR_CHK(slf)													\
+	if (self == slf##_OBJ)												\
+		return call_func(ist, self, SYM(__STR__), 0, NULL, slf##_OBJ);	\
+	if (self->data_type == DATA_TYPE_NONE) {							\
+		char msg[80];													\
+		apr_snprintf(msg, sizeof(msg), "<%s:Uninitialized>", #slf);		\
+		return NEW_STRING(msg); }										
+
 #define BIN_EMPTY_OR_NOT_CHK(slf)								\
 	if (self->data_type != DATA_TYPE_NONE) {					\
 		if (!proto_owns_binary(ist, slf##_OBJ, self) ) {		\

Added: trunk/pr/bind2.pr
===================================================================
--- trunk/pr/bind2.pr	2004-05-04 06:48:34 UTC (rev 456)
+++ trunk/pr/bind2.pr	2004-05-04 19:38:37 UTC (rev 457)
@@ -0,0 +1,35 @@
+#!/usr/bin/env prothon
+
+
+object obj:
+    def $__str__():
+        return 'test obj'
+    def $func():
+        print '$:',$
+
+object self(obj):
+    def $__str__():
+        return 'self'
+    print obj                   # test obj 
+    print obj.func              # <func:93d7c0>
+    print obj.func.bind()       # <func:93d860:bound:test obj>
+    print obj.func.bind($)      # <func:93d920:bound:self>
+    print obj.func.bind(^)      # <func:93d9e0:bound:test obj> 
+    x=obj.func
+    x()                 # $: self
+    x=obj.func.bind()
+    x()                 # $: test obj
+    x=obj.func.bind($)
+    x()                 # $: self
+    x=obj.func.bind(^)
+    x()                 # $: test obj
+    x=obj.func.bind($)
+    x()                 # $: self
+    obj.func()          # $: test obj
+    obj$func()          # $: self
+    with ^: obj$func()  # $: test obj
+
+x = obj.func.bind()
+print x                 # <func:93dd20:bound:test obj>
+x.unbind()
+print x                 # <func:93dd20>
\ No newline at end of file

Deleted: trunk/pr/bug.pr
===================================================================
--- trunk/pr/bug.pr	2004-05-04 06:48:34 UTC (rev 456)
+++ trunk/pr/bug.pr	2004-05-04 19:38:37 UTC (rev 457)
@@ -1,21 +0,0 @@
-#!/usr/bin/env prothon
-
-# bin.pr
-
-x = Exception
-
-object obj(String, Int):
-        Int$__init__(99)      
-        print Int$__str__()   
-        
-try:
-	Int$__init__(99)   # exception leaves module read-locked
-except x,e: print e	   
-
-try:
-	obj.__init__('abc')
-except x,e: print e	
-
-L = Proto(List)
-
-print L
Deleted: trunk/pr/bug2.pr
===================================================================
--- trunk/pr/bug2.pr	2004-05-04 06:48:34 UTC (rev 456)
+++ trunk/pr/bug2.pr	2004-05-04 19:38:37 UTC (rev 457)
@@ -1,40 +0,0 @@
-#!/usr/bin/env prothon
-
-# cache.pr
-
-#!/usr/bin/env prothon
-
-object ModInt(Int):	
-	$modulo	= 10
-	def	$__init__(i=0):	
-		return ^__init__(i % $modulo)
-	def	$__add__(other):
-		if $modulo != other.modulo:	
-			raise TypeError	
-		return ^__call__(^__add__(other) % $modulo)	
-
-object Mod16Int(ModInt):
-	$modulo	= 16
-
-object Mod16IntC(Mod16Int):	
-	$cache = {}	
-	def	$__init__(i):
-		i =	i %	$modulo	
-		if i in	$cache:	
-			print 'cache obj', $cache[i], $cache[i].protoList()
-			return $cache[i]
-		obj	= Mod16Int(i)
-		print 'new obj', obj, obj.protoList()
-		$cache[i] =	obj	
-		return obj
-
-i =	Mod16IntC(27)
-j =	Mod16IntC(8)
-k =	Mod16IntC(8)
-print """
-
-should print
-
-11 + 8 = 03	
-"""	
-print "%i +	%i + %i	= %02i"	% (i, j, k,	(i + j + k))
Modified: trunk/pr/test.pr
===================================================================
--- trunk/pr/test.pr	2004-05-04 06:48:34 UTC (rev 456)
+++ trunk/pr/test.pr	2004-05-04 19:38:37 UTC (rev 457)
@@ -1,31 +1,4 @@
 #!/usr/bin/env prothon
 
-
-object obj:
-	def $__str__():
-		return 'test obj'
-	def $func():
-		print '$:',$
-
-object self(obj):
-	def $__str__():
-		return 'self'
-	print obj
-	print obj.func
-	print obj.func.bind()
-	print obj.func.bind($)
-	print obj.func.bind(^)
-	x=obj.func
-	x()
-	x=obj.func.bind()
-	x()
-	x=obj.func.bind($)
-	x()
-	x=obj.func.bind(^)
-	x()
-	x=obj$func
-	x()
-	x=obj.func.bind($)
-	x()
-	with ^: x = obj$func
-	x()
\ No newline at end of file
+obj = Proto(String)
+print obj.protoList().__str__()
\ No newline at end of file

Modified: trunk/src/builtins-dict.c
===================================================================
--- trunk/src/builtins-dict.c	2004-05-04 06:48:34 UTC (rev 456)
+++ trunk/src/builtins-dict.c	2004-05-04 19:38:37 UTC (rev 457)
@@ -296,7 +296,7 @@
 	char* res;
 	obj_p res_obj, keys, vals;
 
-	BIN_CONTENT_CHK(Dict);
+	BIN_STR_CHK(Dict);
 		
 	len = dict_len(ist, self);
 	keys = dict_keys(ist, self);

Modified: trunk/src/builtins-float.c
===================================================================
--- trunk/src/builtins-float.c	2004-05-04 06:48:34 UTC (rev 456)
+++ trunk/src/builtins-float.c	2004-05-04 19:38:37 UTC (rev 457)
@@ -363,7 +363,7 @@
 
 DEF(Float, __str__, NULL){
 	char str[1024];
-	BIN_CONTENT_CHK(Float);
+	BIN_STR_CHK(Float);
 	apr_snprintf(str, sizeof(str), "%g", Float_value(self));
 	return NEW_STRING(str);
 }

Modified: trunk/src/builtins-int.c
===================================================================
--- trunk/src/builtins-int.c	2004-05-04 06:48:34 UTC (rev 456)
+++ trunk/src/builtins-int.c	2004-05-04 19:38:37 UTC (rev 457)
@@ -121,7 +121,7 @@
 
 DEF(Int, __str__, NULL){
 	char str[24];
-	BIN_CONTENT_CHK(Int);
+	BIN_STR_CHK(Int);
 	apr_snprintf(str, sizeof(str), "%"APR_INT64_T_FMT, (i64_t)Int_value(self));
 	return NEW_STRING(str);
 }

Modified: trunk/src/builtins-list.c
===================================================================
--- trunk/src/builtins-list.c	2004-05-04 06:48:34 UTC (rev 456)
+++ trunk/src/builtins-list.c	2004-05-04 19:38:37 UTC (rev 457)
@@ -323,7 +323,7 @@
 }
 
 DEF(List, __str__, NULL) {
-	BIN_CONTENT_CHK(List);
+	BIN_STR_CHK(List);
 	return str_tuple_list(ist, self, "[", "]");
 }
 

Modified: trunk/src/builtins-string.c
===================================================================
--- trunk/src/builtins-string.c	2004-05-04 06:48:34 UTC (rev 456)
+++ trunk/src/builtins-string.c	2004-05-04 19:38:37 UTC (rev 457)
@@ -234,7 +234,7 @@
 }
 
 DEF(String, __str__, NULL) {
-	BIN_CONTENT_CHK(String);
+	BIN_STR_CHK(String);
 	return self;
 }
 

Modified: trunk/src/builtins-thread.c
===================================================================
--- trunk/src/builtins-thread.c	2004-05-04 06:48:34 UTC (rev 456)
+++ trunk/src/builtins-thread.c	2004-05-04 19:38:37 UTC (rev 457)
@@ -246,7 +246,7 @@
 DEF(Thread, __str__, NULL) {
 	obj_p name_obj;
 	char name[80];
-	BIN_CONTENT_CHK(Thread);
+	BIN_STR_CHK(Thread);
 	if ((name_obj = get_attr(ist, self, sym(ist, "name"))))
 		apr_snprintf(name, sizeof(name), "<Thread:%s>", pr_strptr(name_obj));
 	else 

Modified: trunk/src/builtins-tuple.c
===================================================================
--- trunk/src/builtins-tuple.c	2004-05-04 06:48:34 UTC (rev 456)
+++ trunk/src/builtins-tuple.c	2004-05-04 19:38:37 UTC (rev 457)
@@ -106,7 +106,7 @@
 }
 
 DEF(Tuple, __str__, NULL) {
-	BIN_CONTENT_CHK(Tuple);
+	BIN_STR_CHK(Tuple);
 	return str_tuple_list(ist, self, "(", ")");
 }
 

Modified: trunk/src/interp.c
===================================================================
--- trunk/src/interp.c	2004-05-04 06:48:34 UTC (rev 456)
+++ trunk/src/interp.c	2004-05-04 19:38:37 UTC (rev 457)
@@ -806,8 +806,12 @@
 				obj_p att;
 				fr_sp -= 2;
 				att = get_item(ist, fr_stack[fr_sp], fr_stack[fr_sp+1]);
-				if(has_proto_QUES(ist, att, OBJ(FUNC_PROTO)))
-					set_attr(ist, att, SYM(__CONTAINER__), fr_stack[fr_sp]);
+				if (att) {
+					su(i);
+					if(has_proto_QUES(ist, att, OBJ(FUNC_PROTO)))
+						set_attr(ist, att, SYM(__CONTAINER__), fr_stack[fr_sp]);
+					un_su(i);
+				}
 				fr_push(att);
 				break;
 			}
@@ -1005,9 +1009,9 @@
 								(plist ? clist_len(plist) : 0), 
 								(plist ? (obj_p*)plist->items : NULL),
 								frame->locals);
-					IF_EXC_BREAK;
 					post_call_unlock(ist, self, plist);
 					free_clist(plist);
+					IF_EXC_BREAK;
 					fr_push(res);
 				} else if (has_proto_QUES(ist, func_obj, OBJ(FUNC_PROTO))) {
 					obj_p new_locals, syn_self, self;
@@ -1129,7 +1133,6 @@
 								(plist ? clist_len(plist) : 0), 
 								(plist ? (obj_p*)plist->items : NULL),
 								frame->dyn_locals);
-					IF_EXC_BREAK;
 					post_call_unlock(ist, self, plist);
 					free_clist(plist);
 					IF_EXC_BREAK;
@@ -1348,13 +1351,13 @@
 
 //******************************** call_func **********************************
 obj_p call_func( isp ist, obj_p self, obj_p func_sym, 
-				 int parm_cnt, obj_p* lbl_val_arr, obj_p dyn_locals ) {
+				 int parm_cnt, obj_p* lbl_val_arr, obj_p super_obj ) {
 	obj_p func_obj;
 	if (!self) {
 		func_obj = func_sym; 
 		self = NEW_OBJ(NULL);
 	} else {
-		func_obj = get_proto_attr(ist, self, func_sym, NULL, NULL); if_exc_return NULL;
+		func_obj = get_proto_attr(ist, self, func_sym, NULL, super_obj); if_exc_return NULL;
 		if (!func_obj) {
 			if (!ist) {
 				printf("Internal error with exceptions disabled: Function not found: \"%s\"", as_str(ist, func_sym));
@@ -1373,10 +1376,10 @@
 		pre_call_lock(ist, aself, plist); if (intrp_exobj) return NULL;
 		res = ((pr_func*)(func_obj->data.ptr)) 
 								(ist, aself, (plist ? clist_len(plist) : 0), 
-								(plist ? (obj_p*)plist->items : NULL), dyn_locals);
-		if (intrp_exobj) return NULL;
+								(plist ? (obj_p*)plist->items : NULL), super_obj);
 		post_call_unlock(ist, aself, plist);
 		free_clist(plist);
+		if (intrp_exobj) return NULL;
 		if (!func_sym) del_unlock(self);
 		return res;
 	} else if (has_proto_QUES(ist, func_obj, OBJ(FUNC_PROTO))) {
@@ -1400,7 +1403,7 @@
 		}
 		if (! (aself = get_attr(ist, func_obj, SYM(__BINDOBJ__))) )
 			aself = self;   if_exc_return 0;
-		new_frame = create_frame(	ist, syn_self, aself, NULL, NULL, dyn_locals, 
+		new_frame = create_frame(	ist, syn_self, aself, NULL, NULL, NULL, 
 			                        new_locals, func_obj, NULL );
 		new_frame->called_from_c = TRUE;
 		ist->frame->next_frame = new_frame;