rev 693 - in trunk: pr/test src

SVN User <[email protected]> Fri, 02 Jul 2004 02:49:44 -0400
Newsgroups gmane.comp.lang.prothon.cvs
Message-ID <[email protected]>
Author: mark
Date: 2004-07-02 02:49:41 -0400 (Fri, 02 Jul 2004)
New Revision: 693

Modified:
   trunk/pr/test/default.pr
   trunk/pr/test/int.pr
   trunk/pr/test/modint.pr
   trunk/src/builtins-dict.c
   trunk/src/parser_routines.c
Log:
working on attrs_ problem

Modified: trunk/pr/test/default.pr
===================================================================
--- trunk/pr/test/default.pr	2004-07-02 02:25:48 UTC (rev 692)
+++ trunk/pr/test/default.pr	2004-07-02 06:49:41 UTC (rev 693)
@@ -5,8 +5,11 @@
 	sys.exit(1)
 
 z=0
+y=0
+done = False
 def f(x=y):
 	outer.z = x
+	outer.done = True
 	
 y=1
 f(0)
@@ -28,8 +31,10 @@
 
 n.g()
 y=5
-t = Thread(f)
-Sleep(1.0)
+done = False
+Thread(f)
+while not done:
+	Sleep(0.1)
 if z != 5: err(5)
 
 print """

Modified: trunk/pr/test/int.pr
===================================================================
--- trunk/pr/test/int.pr	2004-07-02 02:25:48 UTC (rev 692)
+++ trunk/pr/test/int.pr	2004-07-02 06:49:41 UTC (rev 693)
@@ -34,7 +34,7 @@
 				-1747783760583674902504339775785929746473575241492788:
 	err(5)
 	
-if 016 != 0c20 or 0C20 != 0x10: err(6)
+if 016 != 0o20 or 0o20 != 0x10: err(6)
 
 y = 1002003004005006007008009000100200300400500600700800900
 print """

Modified: trunk/pr/test/modint.pr
===================================================================
--- trunk/pr/test/modint.pr	2004-07-02 02:25:48 UTC (rev 692)
+++ trunk/pr/test/modint.pr	2004-07-02 06:49:41 UTC (rev 693)
@@ -7,34 +7,38 @@
     def add_(other):
         if self.modulo != other.modulo: 
             raise TypeError 
-        return (self.protoChain()[1])(Int.add_{self}(other) % self.modulo) 
+        return (self.protos_[0])(Int.add_{self}(other) % self.modulo) 
 
 object Mod16Int(ModInt):
     modulo = 16
 
-object Mod16IntC(Mod16Int):     
-    cache = {}                 
-    def init_(i):            
-        i = i % self.modulo         
-        if i in cache:       
-            print  cache[i] , 'from cache' 
-            return cache[i]    
-        obj = Mod16Int(i)       
-        cache[i] = obj   
-        print obj, 'new'      
-        return obj              
+object Mod16IntC(Mod16Int):
+    cache = {}
+    def call_(i):
+        i = i % self.modulo
+        if i in cache:
+            print  cache[i] , 'from cache'
+            return cache[i]
+        obj = super.call_(i)
+        #obj = Object.call_{self}(i)
+        cache[i] = obj
+        print obj, 'new'
+        return obj
+    def init_(i):
+        return Mod16Int.init_{self}(i)
 
 print """
 
 Should print
-
-11 new 
-8 new 
-8 from cache 
-11 + 8 + 8 = 11 
+11 new
+8 new
+8 from cache
+3 new
+11 from cache
+11 + 8 + 8 = 11
 """
 
 i = Mod16IntC(27)
 j = Mod16IntC(8)    
 k = Mod16IntC(8)    
-print "%i + %i + %i = %02i" % (i, j, k, (i + j + k))
+print "{0} + {1} + {2} = {3:02}".fmt(i, j, k, (i + j + k))

Modified: trunk/src/builtins-dict.c
===================================================================
--- trunk/src/builtins-dict.c	2004-07-02 02:25:48 UTC (rev 692)
+++ trunk/src/builtins-dict.c	2004-07-02 06:49:41 UTC (rev 693)
@@ -339,22 +339,28 @@
 	obj_p res_obj, keys, vals;
 
 	BIN_STR_CHK(Dict);
-		
+
 	len = dict_len(ist, self);
 	keys = dict_keys(ist, self);
 	vals = dict_values(ist, self);
+	pr_assert(list_len(ist, keys) == list_len(ist, vals));
 
 	res = pr_malloc(3);
-
 	strcpy(res, "{");
 	for (i=0; i < (int) len; i++) {
-		obj_p item1 = list_item(ist, keys,i);
-		obj_p item2 = list_item(ist, vals,i);
-		char* str1 = as_str(ist, item1);
-		char* str2 = as_str(ist, item2);
-		int is_str1 = has_proto(ist, item1, OBJ(STRING_PROTO));
-		int is_str2 = has_proto(ist, item2, OBJ(STRING_PROTO));
+		obj_p   item1,   item2;
+		char    *str1,   *str2;
+		int   is_str1, is_str2;
 
+		item1 = list_item(ist, keys,i);
+		item2 = list_item(ist, vals,i);
+		pr_assert (item2);
+
+		str1 = as_str(ist, item1);
+		str2 = as_str(ist, item2);
+		is_str1 = has_proto(ist, item1, OBJ(STRING_PROTO));
+		is_str2 = has_proto(ist, item2, OBJ(STRING_PROTO));
+
 		if (str1 == NULL)
 			str1 = "(null)";
 		if (str2 == NULL)

Modified: trunk/src/parser_routines.c
===================================================================
--- trunk/src/parser_routines.c	2004-07-02 02:25:48 UTC (rev 692)
+++ trunk/src/parser_routines.c	2004-07-02 06:49:41 UTC (rev 693)
@@ -903,7 +903,7 @@
 }
 void patch_break_continues(void* param, obj_p label, code_p body) {
 	int p=0;
-	while(p < body->len){
+	while(p < body->len-1){
 		int opcode = body->code_data[p].bytecode.opcode;
 		int parm   = body->code_data[p].bytecode.param;
 		char* pstr = body->code_data[p+1].pstr;