rev 445 - in trunk: . include/prothon modules/File pr src

SVN User <[email protected]> Sun, 02 May 2004 15:12:55 -0400
Newsgroups gmane.comp.lang.prothon.cvs
Message-ID <[email protected]>
Author: mark
Date: 2004-05-02 15:12:53 -0400 (Sun, 02 May 2004)
New Revision: 445

Modified:
   trunk/STATUS.txt
   trunk/include/prothon/prothon.h
   trunk/modules/File/File.c
   trunk/pr/modint.pr
   trunk/pr/test.pr
   trunk/src/builtins-core.c
   trunk/src/object.c
   trunk/src/symbol.c
Log:
implemented new __call__ that allows __init__ to return
new object, also removed __new__ altogether, 
new modint.pr test file

Modified: trunk/STATUS.txt
===================================================================
--- trunk/STATUS.txt	2004-05-02 08:41:20 UTC (rev 444)
+++ trunk/STATUS.txt	2004-05-02 19:12:53 UTC (rev 445)
@@ -1,17 +1,22 @@
 
 ----------------------- TO-DO (highest priority first) ------------------------
 
---- netowrking code -- web access demonstration of security
+--- Add missing string functions
 
 --- def _call_(*args, **kwds):
-	    obj = $_init_(*args, **kwds):
-	    if obj is None:  return $
-	    return obj
+		newObj = Proto($)
+	    initObj = newObj._init_(*args, **kwds):
+	    if initObj is None:  return newObj
+	    return initObj
 
 --- add obj.bind(obj.func)
 
 --- fix str-to-obj in parser for '\000abc'.len()
 
+--- 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)
@@ -20,10 +25,6 @@
 
 --- How do we add "properties", "descriptors"?
 
---- binary space registering in object (1-double use of data, 2-wrong use of data)
-
---- Add missing string functions
-
 --- help() in interactive console()
 
 --- -d -m -l cmd-line options missing

Modified: trunk/include/prothon/prothon.h
===================================================================
--- trunk/include/prothon/prothon.h	2004-05-02 08:41:20 UTC (rev 444)
+++ trunk/include/prothon/prothon.h	2004-05-02 19:12:53 UTC (rev 445)
@@ -389,7 +389,6 @@
 	PARAM2,
 	ARGS,
 	KWARGS,
-	__NEW__,
 	__COPY__,
 	__COVERS__,
 	__COERCE__,

Modified: trunk/modules/File/File.c
===================================================================
--- trunk/modules/File/File.c	2004-05-02 08:41:20 UTC (rev 444)
+++ trunk/modules/File/File.c	2004-05-02 19:12:53 UTC (rev 445)
@@ -181,7 +181,7 @@
 	set_file_obj(self, parms[1], parms[3], f, bufsize, flags);
 	read_lock(ist, self);
 	self->unclonable = TRUE;
-	return NULL;
+	return OBJ(NONE);
 }
 
 DEF(File, __objList__, FORM_RPARAM) {

Modified: trunk/pr/modint.pr
===================================================================
--- trunk/pr/modint.pr	2004-05-02 08:41:20 UTC (rev 444)
+++ trunk/pr/modint.pr	2004-05-02 19:12:53 UTC (rev 445)
@@ -1,23 +1,40 @@
 #!/usr/bin/env prothon
 
-object ModInt(Int):
+object ModInt(Int): 
     $modulo = 10
-    def $__init__(i=0):
-        return ^__init__(i % $modulo)
+    def $__init__(i=0): 
+        ^__init__(i % $modulo)
     def $__add__(other):
-        if $modulo != other.modulo:
-            raise TypeError
-        return ^__call__(^__add__(other) % $modulo)
+        if $modulo != other.modulo: 
+            raise TypeError 
+        return ^__call__(^__add__(other) % $modulo) 
 
 object Mod16Int(ModInt):
     $modulo = 16
 
-i = Mod16Int(27)
-j = Mod16Int(8)
+object Mod16IntC(Mod16Int):     
+    $cache = {}                 
+    def $__init__(i):            
+        i = i % $modulo         
+        if i in $cache:       
+            print  $cache[i] , 'from cache' 
+            return $cache[i]    
+        obj = Mod16Int(i)       
+        $cache[i] = obj   
+        print obj, 'new'      
+        return obj              
+
 print """
 
-should print
+Should print
 
-11 + 8 = 03
+11 new 
+8 new 
+8 from cache 
+11 + 8 + 8 = 11 
 """
-print "%i + %i = %02i" % (i, j, (i + j))
+
+i = Mod16IntC(27)
+j = Mod16IntC(8)    
+k = Mod16IntC(8)    
+print "%i + %i + %i = %02i" % (i, j, k, (i + j + k))

Modified: trunk/pr/test.pr
===================================================================
--- trunk/pr/test.pr	2004-05-02 08:41:20 UTC (rev 444)
+++ trunk/pr/test.pr	2004-05-02 19:12:53 UTC (rev 445)
@@ -1,15 +1 @@
 #!/usr/bin/env prothon
-
-# cache.pr
-
-> # 2) Add caching to Mod16Int:
-> object Mod16IntC(Mod16Int):
->     $cache = {}
->     def $__new__(i):
->         i = i % $modulo
->         if i in $cache:
->             return $cache[i]
->         obj = ^__new__(i)
->         $cache[i] = obj
->         return obj
-

Modified: trunk/src/builtins-core.c
===================================================================
--- trunk/src/builtins-core.c	2004-05-02 08:41:20 UTC (rev 444)
+++ trunk/src/builtins-core.c	2004-05-02 19:12:53 UTC (rev 445)
@@ -95,17 +95,14 @@
 }
 
 DEF(Object, __call__, FORM_STAR3_PARAM) {
-	obj_p new_obj;
+	obj_p new_obj, init_obj;
 	parms[0] = PARAM_STAR;  parms[2] = PARAM_STAR_STAR;
-	new_obj = call_func(ist, self, SYM(__NEW__), 4, parms, NULL); if_exc_return NULL;
-	call_func(ist, new_obj, SYM(__INIT__), 4, parms, NULL);
-	return new_obj;
+	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;
 }
 
-DEF(Object, __new__, FORM_STAR3_PARAM) {
-	return new_object(ist, self);
-}
-
 DEF(Object, __init__, FORM_STAR3_PARAM) {
 	return OBJ(NONE);
 }
@@ -692,7 +689,6 @@
 {
 	MODULE_SUB_INIT(Object);
 	MODULE_ADD_SYM(Object, __call__);
-	MODULE_ADD_SYM(Object, __new__);
 	MODULE_ADD_SYM(Object, __init__);
 	MODULE_ADD_SYM(Object, Proto);
 	MODULE_ADD_SYM(Object, copy);

Modified: trunk/src/object.c
===================================================================
--- trunk/src/object.c	2004-05-02 08:41:20 UTC (rev 444)
+++ trunk/src/object.c	2004-05-02 19:12:53 UTC (rev 445)
@@ -314,9 +314,11 @@
 	if (obj == owner || !obj->has_attrs) return;
 	attrp = obj->attr_proto.attrs;
 	numprotos = attr_plen(attrp);
-	for (i=0; i < numprotos; i++)
-		owner_set |= (attr_pp(attrp, i)->proto.owns_binary = 
-				                   (attr_proto_item(attrp, i) == owner));
+	for (i=0; i < numprotos; i++) {
+		obj_p proto = attr_proto_item(attrp, i);
+		owner_set |= ( attr_pp(attrp, i)->proto.owns_binary = 
+					  ((proto == owner) || has_proto_QUES(ist, proto, owner)) );
+	}
 	if (!owner_set)
 		raise_exception(ist, OBJ(INTERNAL_EXC), "obj_set_data_owner error");
 }

Modified: trunk/src/symbol.c
===================================================================
--- trunk/src/symbol.c	2004-05-02 08:41:20 UTC (rev 444)
+++ trunk/src/symbol.c	2004-05-02 19:12:53 UTC (rev 445)
@@ -134,7 +134,6 @@
 	{ "param2",			0 },
 	{ "args",	        0 },
 	{ "kwargs",	        0 },
-	{ "__new__",		0 },
 	{ "__copy__",		0 },
 	{ "__covers__QUES",	0 },
 	{ "__coerce__",		0 },