rev 458 - in trunk: pr src

SVN User <[email protected]> Tue, 04 May 2004 18:37:03 -0400
Newsgroups gmane.comp.lang.prothon.cvs
Message-ID <[email protected]>
Author: mark
Date: 2004-05-04 18:37:01 -0400 (Tue, 04 May 2004)
New Revision: 458

Modified:
   trunk/pr/test.pr
   trunk/src/builtins-dict.c
   trunk/src/dict.h
   trunk/src/interp.c
Log:
added Dict.len() so Len(dict) will work

Modified: trunk/pr/test.pr
===================================================================
--- trunk/pr/test.pr	2004-05-04 19:38:37 UTC (rev 457)
+++ trunk/pr/test.pr	2004-05-04 22:37:01 UTC (rev 458)
@@ -1,4 +1,20 @@
-#!/usr/bin/env prothon
+d={}
+max = 51
 
-obj = Proto(String)
-print obj.protoList().__str__()
\ No newline at end of file
+def Key(n):
+    return "B%02i" % n
+
+print "Loading dictionary ..."
+for n in max:
+    d[Key(n)] = True
+    print Len(d), n+1
+
+print "Checking 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!()

Modified: trunk/src/builtins-dict.c
===================================================================
--- trunk/src/builtins-dict.c	2004-05-04 19:38:37 UTC (rev 457)
+++ trunk/src/builtins-dict.c	2004-05-04 22:37:01 UTC (rev 458)
@@ -452,6 +452,11 @@
 	return NULL;
 }
 
+DEF(Dict, len, NULL) {
+	BIN_CONTENT_CHK(Dict);
+	return NEW_INT(dict_len(ist, self));
+}
+
 DEF(Dict, items, NULL) {
 	BIN_CONTENT_CHK(Dict);
 	return dict_keys_values(ist, self, 3 /*tuples*/);
@@ -575,6 +580,7 @@
 	MODULE_ADD_SYM(Dict, __str__);
 	MODULE_ADD_SYM(Dict, hasKey_QUES);
 	MODULE_ADD_SYM(Dict, items);
+	MODULE_ADD_SYM(Dict, len);
 	MODULE_ADD_SYM(Dict, keys);
 	MODULE_ADD_SYM(Dict, values);
 	MODULE_ADD_SYM(Dict, get);

Modified: trunk/src/dict.h
===================================================================
--- trunk/src/dict.h	2004-05-04 19:38:37 UTC (rev 457)
+++ trunk/src/dict.h	2004-05-04 22:37:01 UTC (rev 458)
@@ -75,7 +75,7 @@
 
 typedef dict_t*		dict_p;
 
-#define dict_sizeof(n)			(((n)+DICT_OVERHEAD) * sizeof(dict_entry_t))
+#define dict_sizeof(n)			(((n)+DICT_OVERHEAD) * sizeof(dict_t))
 #define dict_size_bytes(dict)	(dict_sizeof(dictsize(dict)))
 
 #define DICT_HDR_INDEX		0

Modified: trunk/src/interp.c
===================================================================
--- trunk/src/interp.c	2004-05-04 19:38:37 UTC (rev 457)
+++ trunk/src/interp.c	2004-05-04 22:37:01 UTC (rev 458)
@@ -803,8 +803,7 @@
 				fr_push(sym); 
 			}	break;
 			case OP_DEREF: {
-				obj_p att;
-				fr_sp -= 2;
+				obj_p att;			fr_sp -= 2;
 				att = get_item(ist, fr_stack[fr_sp], fr_stack[fr_sp+1]);
 				if (att) {
 					su(i);