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

SVN User <[email protected]> Tue, 29 Jun 2004 00:52:10 -0400
Newsgroups gmane.comp.lang.prothon.cvs
Message-ID <[email protected]>
Author: mark
Date: 2004-06-29 00:52:08 -0400 (Tue, 29 Jun 2004)
New Revision: 674

Modified:
   trunk/STATUS.txt
   trunk/include/prothon/prothon.h
   trunk/pr/test/test.pr
   trunk/src/builtins-core.c
   trunk/src/builtins-list.c
   trunk/src/interp.c
Log:
removed init_ return value feature

Modified: trunk/STATUS.txt
===================================================================
--- trunk/STATUS.txt	2004-06-28 20:01:26 UTC (rev 673)
+++ trunk/STATUS.txt	2004-06-29 04:52:08 UTC (rev 674)
@@ -1,14 +1,10 @@
 
 ----------------------- TO-DO (highest priority first) ------------------------
 
---- kill init_ return?
-
 --- Add properties methods: prop keyword, get_,  set_, delete_, wildcards
 
 --- change file.setStdout to property
 
---- weak references, WeakRef.ref property is reference (stored in data), init_(obj)
-
 --- OSThread, Thread, and Gate
 		http://www.prothon.org/pipermail/prothon-user/2004-June/002124.html
 --- lock keyword?
@@ -142,6 +138,10 @@
 ------------------------ OPTIMIZATION TO_DO -----------------------------------
 
 --- Lazy string concatenation
+--- Improve garbage collector cache behavior
+--- combine pr_malloc/garbage collector, remove obj_t linked list
+		http://www.cs.kent.ac.uk/people/staff/rej/gc.html#Book
+		http://www.prothon.org/pipermail/prothon-user/2004-June/002534.html
 
 ---------------- Ideas to consider for inclusion ------------------------------
 

Modified: trunk/include/prothon/prothon.h
===================================================================
--- trunk/include/prothon/prothon.h	2004-06-28 20:01:26 UTC (rev 673)
+++ trunk/include/prothon/prothon.h	2004-06-29 04:52:08 UTC (rev 674)
@@ -325,10 +325,10 @@
 	METHOD_PROTO,		// 20 Method
 	HASH_PROTO,			// 21 Hash
 	SLICE_PROTO,		// 22 Slice
-	LOCAL_PROTO,		//  
-	OUTER_PROTO,		//  
-	SUPER_PROTO,		// 
-	GEN_PROTO,			//  
+	LOCAL_PROTO,		// 23
+	OUTER_PROTO,		// 24
+	SUPER_PROTO,		// 25
+	GEN_PROTO,			// 26
 	ITER_PROTO,			// 
 	THREAD_PROTO,		//   Thread
 	MUTEX_PROTO,		//   Mutex

Modified: trunk/pr/test/test.pr
===================================================================
--- trunk/pr/test/test.pr	2004-06-28 20:01:26 UTC (rev 673)
+++ trunk/pr/test/test.pr	2004-06-29 04:52:08 UTC (rev 674)
@@ -1,36 +1,8 @@
 #!/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
-Sleep(2.0)
+gen f(x):
+	for i in x:
+		yield i
+		
+list = List(f(10))
+print list

Modified: trunk/src/builtins-core.c
===================================================================
--- trunk/src/builtins-core.c	2004-06-28 20:01:26 UTC (rev 673)
+++ trunk/src/builtins-core.c	2004-06-29 04:52:08 UTC (rev 674)
@@ -111,9 +111,8 @@
 	obj_p new_obj, init_obj;
 	parms[0] = OBJ(PARAM_STAR);  parms[2] = OBJ(PARAM_STAR_STAR);
 	new_obj = new_object(ist, self);
-	init_obj = call_func(ist, new_obj, SYM(INIT_), 4, parms, NULL); if_exc_return NULL;
-	if (init_obj == OBJ(NONE)) return new_obj;
-	return init_obj;
+	call_func(ist, new_obj, SYM(INIT_), 4, parms, NULL);
+	return new_obj;
 }
 
 DEF(Object, init_, FORM_STAR3_PARAM) {
@@ -438,11 +437,9 @@
 	set_obj_id(Symbol_OBJ, *, Symbol);
 }
 
-DEF(Symbol, init_,  FORM_RPARAM) {
+DEF(Symbol, call_,  FORM_RPARAM) {
 	char* str;
-	BIN_EMPTY_CHK();
 	STRING_PARAM(1, str);
-	del_unlock(self);
 	return sym(ist, str); 
 }
 
@@ -986,8 +983,7 @@
 	set_obj_doc(Slice_OBJ, "Slice object prototype");
 }
 
-DEF(Slice, init_, FPARM3(idx1, NEW_INT(0), idx2, SLICEPARAM_MISSING, idx3, SLICEPARAM_MISSING)) { 
-	BIN_EMPTY_CHK();
+DEF(Slice, call_, FPARM3(idx1, NEW_INT(0), idx2, SLICEPARAM_MISSING, idx3, SLICEPARAM_MISSING)) { 
 	return new_slice_obj(ist, parms[1], parms[3], parms[5]);
 }
 
@@ -1273,7 +1269,7 @@
 
 
 	MODULE_SUB_INIT(Symbol);
-	MODULE_ADD_SYM(Symbol, init_);
+	MODULE_ADD_SYM(Symbol, call_);
 	MODULE_ADD_SYM(Symbol, str_);
 
 	MODULE_SUB_INIT(Seq);
@@ -1320,7 +1316,7 @@
 	MODULE_ADD_SYM(RangeGen, next);
 
 	MODULE_SUB_INIT(Slice);
-	MODULE_ADD_SYM(Slice, init_);
+	MODULE_ADD_SYM(Slice, call_);
 	MODULE_ADD_SYM(Slice, str_);
 
 	MODULE_SUB_INIT(WeakRef);

Modified: trunk/src/builtins-list.c
===================================================================
--- trunk/src/builtins-list.c	2004-06-28 20:01:26 UTC (rev 673)
+++ trunk/src/builtins-list.c	2004-06-29 04:52:08 UTC (rev 674)
@@ -343,18 +343,27 @@
 }
 
 DEF(List, init_, FORM_STAR_PARAM) {
+	list_p lstp;
 	BIN_EMPTY_OR_NOT_CHK(List);
 	if (list_len(ist, parms[1])) {
 		obj_p item = list_item(ist, parms[1], 0);
 		if (has_proto(ist, item, OBJ(ITER_PROTO))) {
-			obj_p new_list = new_list_obj(ist, 10);
+			def_write_lock(self);
+			SET_TYPE_IF_EXC(List_OBJ, self, DATA_TYPE_DATAPTR) {
+				def_write_unlock(self); return NULL; }
+			lstp = self->data.ptr = pr_malloc(list_sizeof(2));
+			lstpsetsize(lstp, 2);
+			lstplen(lstp)  = 0;
+			def_write_unlock(self);
+			read_unlock(ist, self);
 			while (TRUE) {
 				obj_p new_item = call_func0(ist, item, SYM(NEXT));
 				if (catch_exception(ist, OBJ(STOP_ITERATION_EXC), NULL)) break;
-				if_exc_return NULL;
-				list_append(ist, new_list, new_item);
+				if (ist->exception_obj) { read_lock(ist, self); return NULL; }
+				list_append(ist, self, new_item);
 			}
-			return new_list;
+			read_lock(ist, self);
+			return OBJ(NONE);
 		}
 	}
 	read_unlock(ist, self);

Modified: trunk/src/interp.c
===================================================================
--- trunk/src/interp.c	2004-06-28 20:01:26 UTC (rev 673)
+++ trunk/src/interp.c	2004-06-29 04:52:08 UTC (rev 674)
@@ -759,10 +759,9 @@
 			res = fr_tos;
 		*switch_frame = DONE_FRAME_FLAG;
 	}
-	if (frame->gen_marker) {
-		if (frame->prev_frame) (frame->prev_frame->stack_ptr)--;
+	if (frame->gen_marker)
 		raise_exception(ist, OBJ(STOP_ITERATION_EXC), NULL);
-	} else
+	else
 		*free_frame = frame;
 	if (!res) res = return_value;
 	return res;
@@ -1283,7 +1282,6 @@
 					genp->frame = create_frame( ist, NULL, NULL, frame->locals,
 												frame->new_locals, func_obj, codep, NULL );
 					genp->frame->gen_marker = func_obj;
-					frame->next_frame = genp->frame;
 					fr_push(func_obj);
 				} else {
 					memmove(fr_stack+fr_sp+2, fr_stack+fr_sp+1, (param*2+1) * sizeof(obj_p));
@@ -1540,8 +1538,9 @@
 				else {
 					switch_frame = fp->prev_frame;
 					switch_frame->next_frame = NULL;
-					switch_frame->stack[switch_frame->stack_ptr-1] = fr_pop;
+					switch_frame->stack[switch_frame->stack_ptr-1] = return_value = fr_pop;
 				}
+				return_flag = fr_ccall;
 			}	break;
 			case OP_RETURN:
 				return_value = do_return(ist, frame, &switch_frame, &free_frame, return_value);
@@ -1730,6 +1729,7 @@
 obj_p call_func( isp ist, obj_p self, obj_p func_sym, 
 				 int parm_cnt, obj_p* lbl_val_arr, obj_p super_obj ) {
 	obj_p func_obj;
+	frame_p new_frame;
 	if (!self) {
 		func_obj = func_sym; 
 		self = NEW_OBJ(NULL);
@@ -1741,6 +1741,15 @@
 					                                             as_str(ist, func_sym));
 				pr_exit(1);
 			}
+			if (func_sym == SYM(NEXT) && has_proto(ist, self, OBJ(GEN_PROTO))) {
+					gen_p genp = self->data.ptr;
+					new_frame = genp->frame;
+					if (!new_frame) {
+						raise_exception(ist, OBJ(STOP_ITERATION_EXC), NULL);
+						return NULL;
+					}
+					goto gotnewframe;
+			}
 			raise_exception(ist, OBJ(FUNCNOTFOUND_EXC), "Function not found: \"%s\"",
 					                                     as_str(ist, func_sym));
 			return NULL;
@@ -1762,7 +1771,7 @@
 		return res;
 	} else if ( func_obj != OBJ(FUNC_PROTO) && 
 		        has_proto(ist, func_obj, OBJ(FUNC_PROTO)) ) {
-		frame_p frame, new_frame;
+		frame_p frame;
 		obj_p new_locals, aself; 
 		int idx = -1;
 		fparam_proc_state_t fps;
@@ -1789,10 +1798,12 @@
 		}
 		new_frame = create_frame( ist, aself, NULL, NULL, 
 			                      new_locals, func_obj, NULL, NULL );
+gotnewframe:
 		new_frame->called_from_c = TRUE;
 		ist->frame->next_frame = new_frame;
 		new_frame->prev_frame = ist->frame;
 		ist->frame = new_frame;
+		ist->frame->called_from_c = TRUE;
 		if (intrp_exobj) {
 			if (!func_sym) del_unlock(self);
 			return 0;