rev 588 - in trunk: . pr/test src

SVN User <[email protected]> Wed, 09 Jun 2004 19:35:52 -0400
Newsgroups gmane.comp.lang.prothon.cvs
Message-ID <[email protected]>
Author: mark
Date: 2004-06-09 19:35:48 -0400 (Wed, 09 Jun 2004)
New Revision: 588

Modified:
   trunk/STATUS.txt
   trunk/pr/test/file.pr
   trunk/pr/test/test.pr
   trunk/src/builtins-dict.c
   trunk/src/parser_routines.c
   trunk/src/prlist.h
Log:
fixed big bug in list

Modified: trunk/STATUS.txt
===================================================================
--- trunk/STATUS.txt	2004-06-09 21:40:50 UTC (rev 587)
+++ trunk/STATUS.txt	2004-06-09 23:35:48 UTC (rev 588)
@@ -2,6 +2,7 @@
 ----------------------- TO-DO (highest priority first) ------------------------
 
 --- binaryObj = Bytes("Hello world", "ascii") (or "latin-1") exception to tell "latin-1"
+--- allow lists of ints in Bytes constructor
 
 --- allow tracebacks in the constructors to exception objects or raise command
 
@@ -19,12 +20,6 @@
 
 --- getAttr(name), setAttr(name, value), delAttr(name)
 
---- has_proto should return true for self
-
---- Strings -> 24-bit ords
---- resolve binary vs. strings vs. unicode----- code in binary string (all binary data in binary string?)
---- new integrated binary obj_malloc?
-
 --- import (string variable)
 
 --- support long ints in prosist

Modified: trunk/pr/test/file.pr
===================================================================
--- trunk/pr/test/file.pr	2004-06-09 21:40:50 UTC (rev 587)
+++ trunk/pr/test/file.pr	2004-06-09 23:35:48 UTC (rev 588)
@@ -1,11 +1,9 @@
 #!/usr/bin/env prothon
 
-import File
-
 f = File("test.txt", 'w+')
 for i in 5:
 	f.write("line "+i+'\n')
-f.writeLines( ['line 5\n','line 6\n','line 7\n','line 8\n','line 9\n',])
+f.writeLines( ['line 5\n', 'line 6\n','line 7\n','line 8\n','line 9\n',])
 f.close()
 
 ref =  ['line 0\n','line 1\n','line 2\n','line 3\n','line 4\n',]

Modified: trunk/pr/test/test.pr
===================================================================
--- trunk/pr/test/test.pr	2004-06-09 21:40:50 UTC (rev 587)
+++ trunk/pr/test/test.pr	2004-06-09 23:35:48 UTC (rev 588)
@@ -1,33 +1,57 @@
 #!/usr/bin/env prothon
 
-def f():
-    try:
-        return 9
-    finally:
-        print "Finally"
+# dict.pr
 
-print "-- The output should be --"
-print "Finally"
-print 9
-print "1)"
-print "Finally"
-print "2)"
-print "Finally"
-print "Name Error raised."
-print "--------------------------"
-print f()
+def err(str):
+    print str
+    Sys.exit(1)
 
-def f(doRaise):
-    try:
-        if doRaise:
-            raise NameError
-    finally:
-        print "Finally"
+d = {1:2}
+if d.keys()   != [1]  : err( 'error in keys' )
+if d.values() != [2]  : err( 'error in values' )
+if d.get(1)   !=  2   : err( 'error1 in get' )
+if d.get(2)   != None : err( 'error2 in get' )
+if d.get(3,4) !=  4   : err( 'error3 in get' )
+if d.get(3,5) !=  5   : err( 'error4 in get' )
+if d.setDefault!(3,4) !=  4   : err( 'error5 in setdefault' )
+if d.get(3,5) !=  4   : err( 'error6 in get' )
+if 3 not in d: err( 'error 7 in not in' )
 
-try:
-    print "1)"
-    f(False)
-    print "2)"
-    f(True)
-except NameError:
-    print "Name Error raised."
+d = {1:2, 3:4}
+e = d.copy()
+   
+if d.items() != e.items():
+    err( 'error1' )
+    
+if Len(e.items()) != 2:
+    err( 'error2' )
+
+d.clear!()
+
+d = {1:2}
+d.update!({3:4})
+if d.items() != e.items():
+    err( 'error3' )
+
+if not e.hasKey?(1) or e.hasKey?(2): err( 'error4' )
+
+dd = Dict(a=1)
+
+if `a  not in dd: err( 'error5' )
+if "a" not in dd: err( 'error6' )
+
+print 'all tests passed'
+
+print """
+The following should be:  
+1 (1, 2) 3 (3, 4).
+"""
+print 'before...\n', d, e
+
+for i in e:
+	print i
+	print i, d.popItem!(),
+
+print 'after...\n'
+
+print 'done...\n'

Modified: trunk/src/builtins-dict.c
===================================================================
--- trunk/src/builtins-dict.c	2004-06-09 21:40:50 UTC (rev 587)
+++ trunk/src/builtins-dict.c	2004-06-09 23:35:48 UTC (rev 588)
@@ -540,17 +540,6 @@
 	return dict_keys_values(ist, self, 4 /*tuple*/);
 }
 
-DEF(Dict, iter_, NULL) {
-	obj_p list_obj, gen_obj = NEW_OBJ(DictGen_OBJ);
-
-	BIN_CONTENT_CHK(Dict);
-	SET_TYPE_IF_EXC(DictGen_OBJ, gen_obj, DATA_TYPE_DATAPTR) return NULL;
-	gen_obj->data.ptr = list_obj = dict_keys(ist, self);
-
-	listlen(list_obj) = 0;
-	return gen_obj;
-}
-
 DEF(Dict, toStorProxy_, NULL) {
 	obj_p proxy_obj = dict_keys_values(ist, self, 2 /*list*/);
 	BIN_CONTENT_CHK(Dict);
@@ -579,6 +568,17 @@
 	set_obj_id(DictGen_OBJ, *, DictGen);
 }
 
+DEF(Dict, iter_, NULL) {
+	obj_p list_obj, gen_obj = NEW_OBJ(DictGen_OBJ);
+
+	BIN_CONTENT_CHK(Dict);
+	SET_TYPE_IF_EXC(DictGen_OBJ, gen_obj, DATA_TYPE_DATAPTR) return NULL;
+	gen_obj->data.ptr = list_obj = dict_keys(ist, self);
+
+	listlen(list_obj) = 0;
+	return gen_obj;
+}
+
 DEF(DictGen, next, NULL) {
 	obj_p res, list_obj = self->data.ptr;
 

Modified: trunk/src/parser_routines.c
===================================================================
--- trunk/src/parser_routines.c	2004-06-09 21:40:50 UTC (rev 587)
+++ trunk/src/parser_routines.c	2004-06-09 23:35:48 UTC (rev 588)
@@ -181,6 +181,8 @@
 code_p new_code(void* param, int size, int stk, int max_stk, opcode_t opcode) {
 	data_size_t data_size = sizeof(code)+size*sizeof(code_t);
 	code_p p = pr_malloc(data_size);
+	if (p == (void*) 0xa189c8)
+		p->size = 0;
 	memset(p, 0, data_size);
 	p->size            = data_size;
 	p->len             = size;
@@ -201,7 +203,7 @@
 	clist_p srcmap = src->srcmap;
 	for (i=0; i < clist_len(srcmap); i+=3) {
 		int pc = ofs + clist_num(srcmap, i);
-		int dlen = clist_len(dst);
+		int dlen = clist_len(dstmap);
 		if (dlen > 2 && clist_num(dstmap, dlen-3) == pc) {
 			clist_num(dstmap, dlen-2) = clist_num(srcmap, i+1);
 			clist_num(dstmap, dlen-1) = clist_num(srcmap, i+2);

Modified: trunk/src/prlist.h
===================================================================
--- trunk/src/prlist.h	2004-06-09 21:40:50 UTC (rev 587)
+++ trunk/src/prlist.h	2004-06-09 23:35:48 UTC (rev 588)
@@ -71,7 +71,7 @@
 typedef list_t* list_p;
 
 #define lstpsetsize(list_ptr,n) ((((list_p)(list_ptr))->hdr.size)=list_sizeof(n))
-#define lstpsize(list_ptr)		(((((list_p)(list_ptr))->hdr.size)-sizeof(list_hdr_t))/sizeof(obj_t))
+#define lstpsize(list_ptr)		(((((list_p)(list_ptr))->hdr.size)-sizeof(list_hdr_t))/sizeof(obj_p))
 #define lstplen(list_ptr)		(((list_p)(list_ptr))->hdr.len)
 #define lstpitem(list_ptr,i)	(((list_p)(list_ptr))->item[i])