rev 461 - in trunk: include/prothon pr src

SVN User <[email protected]> Thu, 06 May 2004 02:54:31 -0400
Newsgroups gmane.comp.lang.prothon.cvs
Message-ID <[email protected]>
Author: mark
Date: 2004-05-06 02:54:28 -0400 (Thu, 06 May 2004)
New Revision: 461

Added:
   trunk/pr/dictadd.pr
Modified:
   trunk/include/prothon/prothon.h
   trunk/include/prothon/prothon_dll.h
   trunk/pr/test.pr
   trunk/src/builtins-core.c
   trunk/src/dict.h
Log:
fixed bug in function when used as prototype

Modified: trunk/include/prothon/prothon.h
===================================================================
--- trunk/include/prothon/prothon.h	2004-05-06 01:04:44 UTC (rev 460)
+++ trunk/include/prothon/prothon.h	2004-05-06 06:54:28 UTC (rev 461)
@@ -851,7 +851,7 @@
 // The function must always return an object-id (OBJ(NONE) if nothing else).
 typedef obj_p (pr_func)( isp ist, obj_p self, 
 						 int parm_cnt, obj_p* lbl_parm_arr, obj_p dyn_locals ); 
-
+ 
 #define PARAM_NORMAL		((obj_p)0)
 #define PARAM_STAR			((obj_p)1)
 #define PARAM_STAR_STAR		((obj_p)2)

Modified: trunk/include/prothon/prothon_dll.h
===================================================================
--- trunk/include/prothon/prothon_dll.h	2004-05-06 01:04:44 UTC (rev 460)
+++ trunk/include/prothon/prothon_dll.h	2004-05-06 06:54:28 UTC (rev 461)
@@ -146,6 +146,7 @@
 	void		(*set_obj_rdacc)(obj_p obj, int access);
 	void		(*set_obj_wracc)(obj_p obj, int access);
 	int			(*get_obj_rdacc)(obj_p obj);
+
 	int			(*get_obj_wracc)(obj_p obj);
 				
 	obj_p* 				OBJ;

Added: trunk/pr/dictadd.pr
===================================================================
--- trunk/pr/dictadd.pr	2004-05-06 01:04:44 UTC (rev 460)
+++ trunk/pr/dictadd.pr	2004-05-06 06:54:28 UTC (rev 461)
@@ -0,0 +1,22 @@
+d={}
+max = 50
+
+def Key(n):
+    return "B%02i" % n
+
+print "Loading dictionary ..."
+
+for n in max:
+    d[Key(n)] = True
+
+print "\nChecking dictionary ..."
+lost = False
+for n in max:
+    if Key(n) not in d:
+        lost = True
+        print "Key %s not found" % Key(n)
+
+if lost:
+    print d.keys().sort!()
+else:
+	print "\ntest passed"
Modified: trunk/pr/test.pr
===================================================================
--- trunk/pr/test.pr	2004-05-06 01:04:44 UTC (rev 460)
+++ trunk/pr/test.pr	2004-05-06 06:54:28 UTC (rev 461)
@@ -1,20 +1,15 @@
-d={}
-max = 50
 
-def Key(n):
-    return "B%02i" % n
-
-print "Loading dictionary ..."
-
-for n in max:
-    d[Key(n)] = True
-
-print "\nChecking dictionary ..."
-lost = False
-for n in max:
-    if Key(n) not in d:
-        lost = True
-        print "Key %s not found" % Key(n)
-
-if lost:
-    print d.keys().sort!()
+def f1():
+	print 'f1'
+def f2():
+	print 'f2'
+print f1
+print f2
+f = Proto(f1)
+print f
+f.__init__(f2)
+print f
+f1()
+f2()
+x = ^
+f()
\ No newline at end of file

Modified: trunk/src/builtins-core.c
===================================================================
--- trunk/src/builtins-core.c	2004-05-06 01:04:44 UTC (rev 460)
+++ trunk/src/builtins-core.c	2004-05-06 06:54:28 UTC (rev 461)
@@ -683,9 +683,53 @@
 	set_obj_id(Method_OBJ, *, Method);
 }
 
+DEF(Func, __init__, FORM_RPARAM) {
+	obj_p other, fparms, globals, syn_locals, obj;
+	code_p optr;
+	int size;
+	
+	BIN_EMPTY_CHK();
+	FUNC___PARAM(1, other);
+	optr = other->data.ptr;
+	if (!optr) {
+		raise_exception(ist, OBJ(INTERNAL_EXC), "Func __init__ param not initialized");
+		return NULL;
+	}
+	self->data_type = other->data_type;
+	if (self->data_type == DATA_TYPE_DATAPTR) {
+		if (!(globals = get_attr(ist,  other, SYM(__GLOBALS__)))) {
+			raise_exception(ist, OBJ(INTERNAL_EXC), "Func __init__ global specifier missing");
+			return NULL;
+		}
+		if (!(syn_locals = get_attr(ist,  other, SYM(__SYN_LOCALS__)))) {
+			raise_exception(ist, OBJ(INTERNAL_EXC), "Func __init__ syn_locals specifier missing");
+			return NULL;
+		}
+		read_unlock(ist, self);
+		size = (int) (sizeof(code) + optr->len * sizeof(code_t));
+		self->data.ptr = pr_malloc(size);
+		memcpy(self->data.ptr, other->data.ptr, size);
+		set_attr(ist, self,    SYM(__GLOBALS__),    globals);
+		set_attr(ist, self, SYM(__SYN_LOCALS__), syn_locals);
+		if (obj = get_attr(ist,  other, SYM(__SYN_SELF__)))
+			set_attr(ist, self, SYM(__SYN_SELF__), obj);
+		if (obj = get_attr(ist,  other, SYM(__SYN_FUNC__)))
+			set_attr(ist, self, SYM(__SYN_FUNC__), obj);
+		read_lock(ist, self);
+	} else 
+		self->data.ptr = other->data.ptr;
+	read_unlock(ist, self);
+	if (fparms = get_attr(ist,  other, SYM(__FPARAMS__)))
+		 set_attr(ist, self, SYM(__FPARAMS__), copy_list_obj(ist, fparms));
+	read_lock(ist, self);
+	return OBJ(NONE);
+}
+
 DEF(Func, __str__, NULL) {
 	obj_p bobj;
 	char str[128];
+
+	BIN_STR_CHK(Func);
 	apr_snprintf(str, sizeof(str), "<func:%x", (unsigned long)(intptr_t) self);
 	if (self->data_type == DATA_TYPE_FUNCPTR)
 		strcat(str, ":c");
@@ -699,6 +743,9 @@
 
 DEF(Func, bind, FPARM1(obj, OBJ(NONE))) {
 	obj_p bindee, bind_obj = copy_object(ist, self);
+
+	BIN_CONTENT_CHK(Func);
+
 	if (parms[1] == OBJ(NONE)) {
 		if (!(bindee = get_attr(ist, self, SYM(__CONTAINER__)))) {
 			raise_exception(ist, OBJ(INTERPRETER_EXC), "no default object found for bind method");		
@@ -711,6 +758,7 @@
 }
 
 DEF(Func, unbind, NULL) {
+	BIN_CONTENT_CHK(Func);
 	read_unlock(ist, self);
 	del_attr(ist, self, SYM(__BINDOBJ__));
 	read_lock(ist, self);
@@ -718,6 +766,7 @@
 }
 
 DEF(Func, __cDataLen__, NULL) {
+	BIN_CONTENT_CHK(Func);
 	return NEW_INT(sizeof(code) + ((code_p)(self->data.ptr))->len * sizeof(code_t));
 }
 
@@ -795,6 +844,7 @@
 	MODULE_ADD_SYM(Gen, __iter__);
 
 	MODULE_SUB_INIT(Func);
+	MODULE_ADD_SYM(Func, __init__);
 	MODULE_ADD_SYM(Func, __str__);
 	MODULE_ADD_SYM(Func, bind);
 	MODULE_ADD_SYM(Func, unbind);

Modified: trunk/src/dict.h
===================================================================
--- trunk/src/dict.h	2004-05-06 01:04:44 UTC (rev 460)
+++ trunk/src/dict.h	2004-05-06 06:54:28 UTC (rev 461)
@@ -73,7 +73,7 @@
 	dict_entry_t 	entry;
 } dict_t;
 
-typedef dict_t*		dict_p;
+typedef dict_t*  dict_p;
 
 #define dict_sizeof(n)			(((n)+DICT_OVERHEAD) * sizeof(dict_t))
 #define dict_size_bytes(dict)	(dict_sizeof(dictsize(dict)))