rev 402 - in trunk: pr src
SVN User <[email protected]> Thu, 22 Apr 2004 21:23:19 -0400
| Newsgroups | gmane.comp.lang.prothon.cvs |
|---|---|
| Message-ID | <[email protected]> |
Author: mark
Date: 2004-04-22 21:23:16 -0400 (Thu, 22 Apr 2004)
New Revision: 402
Added:
trunk/pr/prosist.pr
Modified:
trunk/src/builtins-dict.c
trunk/src/builtins-list.c
trunk/src/builtins-tuple.c
Log:
added prosist.pr, prosist load/store mostly working, some type info being lost
Added: trunk/pr/prosist.pr
===================================================================
--- trunk/pr/prosist.pr 2004-04-22 23:29:54 UTC (rev 401)
+++ trunk/pr/prosist.pr 2004-04-23 01:23:16 UTC (rev 402)
@@ -0,0 +1,51 @@
+#!/usr/bin/env prothon
+
+# prosist.pr
+
+import Prosist
+#/*
+a = {1:(2,)}
+db = Prosist('test.pdb', root=a, mode=Prosist.RWTRUNCATE)
+db.close()
+db = Prosist('test.pdb')
+print db.root
+db.close()
+#*/
+
+/*
+b = 7.3
+
+c = "hello"
+
+d = ('i', 'am', 'a', 'tuple')
+
+e = 1234
+
+f = {"i":"am", "a":"dict"}
+
+g = Object()
+g.a = 1
+g.b = 2
+g.c = 3
+
+a = {1:b, 2:c, 3:[d,e], (4,5): f, 6:g}
+
+db = Prosist('test.pdb', root=a, mode=Prosist.RWTRUNCATE)
+db.close()
+
+db = Prosist('test.pdb')
+x = db.root
+db.close()
+
+print 'these two should match .. '
+print
+print a, a[6].a , a[6].b , a[6].c
+
+del g.a, g.b, g.c, g, d, c, b, e, f['i'], f['a'], f, a[1], a[2], a[3], a[(4,5)], a[6], a
+a = 1
+
+print
+print x
+#, x[6].a , x[6].b , x[6].c
+
+*/
\ No newline at end of file
Modified: trunk/src/builtins-dict.c
===================================================================
--- trunk/src/builtins-dict.c 2004-04-22 23:29:54 UTC (rev 401)
+++ trunk/src/builtins-dict.c 2004-04-23 01:23:16 UTC (rev 402)
@@ -106,8 +106,8 @@
if (has_proto_QUES(ist, key_in, OBJ(INT_PROTO)))
return ((i32_t) key_in->data.i64);
else {
- obj_p hash_obj = call_func(ist, key_in, SYM(__HASH__), 0, NULL, NULL);
- if (ist->exception_obj) return 0;
+ obj_p hash_obj = call_func0(ist, key_in, SYM(__HASH__));
+ if_exc_return 0;
return hash_obj->data.i32[0];
}
}
Modified: trunk/src/builtins-list.c
===================================================================
--- trunk/src/builtins-list.c 2004-04-22 23:29:54 UTC (rev 401)
+++ trunk/src/builtins-list.c 2004-04-23 01:23:16 UTC (rev 402)
@@ -125,7 +125,10 @@
size_t list_len(isp ist, obj_p list_obj){
size_t len;
rdlock_rtrn(list_obj) 0;
- len = listlen(list_obj);
+ if (list_obj->data.ptr)
+ len = listlen(list_obj);
+ else
+ len = 0;
read_unlock(ist, list_obj);
return len;
}
Modified: trunk/src/builtins-tuple.c
===================================================================
--- trunk/src/builtins-tuple.c 2004-04-22 23:29:54 UTC (rev 401)
+++ trunk/src/builtins-tuple.c 2004-04-23 01:23:16 UTC (rev 402)
@@ -300,7 +300,21 @@
return gen_obj;
}
+DEF(Tuple, __hash__, NULL) {
+ obj_p hash_obj;
+ i32_t hash=0x937456;
+ int i, llen;
+ llen = (int) list_len(ist, self);
+ for (i=0; i < llen; i++) {
+ hash_obj = call_func0(ist, list_item(ist, self, i), SYM(__HASH__));
+ if_exc_return NULL;
+ hash += hash_obj->data.i32[0];
+ }
+ return new_hash_obj(ist, hash);
+}
+
+
//*************************** TUPLE GENERATOR OBJECT **************************
MODULE_START(Tgen)
{
@@ -342,6 +356,7 @@
MODULE_ADD_SYM(Tuple, __iter__);
MODULE_ADD_SYM(Tuple, __setItem__);
MODULE_ADD_SYM(Tuple, __delItem__);
+ MODULE_ADD_SYM(Tuple, __hash__);
MODULE_ADD_SYM(Tuple, __objList__);
MODULE_ADD_SYM(Tuple, __cDataLen__);