rev 226 - trunk/src

SVN User <[email protected]>
Newsgroups gmane.comp.lang.prothon.cvs
Message-ID <[email protected]>
Author: bcollins
Date: 2004-03-31 08:11:30 -0500 (Wed, 31 Mar 2004)
New Revision: 226

Modified:
   trunk/src/builtins.c
Log:
Proper initializers for the Dict, Tuple and List proto's.


Modified: trunk/src/builtins.c
===================================================================
--- trunk/src/builtins.c	2004-03-31 07:44:50 UTC (rev 225)
+++ trunk/src/builtins.c	2004-03-31 13:11:30 UTC (rev 226)
@@ -59,6 +59,7 @@
 #include <apr_strings.h>
 
 #include <prothon/prothon.h>
+#include <prothon/dict.h>
 #include "parser.h"
 #include "object.h"
 #include <prothon/prothon_dll.h>
@@ -878,14 +879,19 @@
 
 MODULE_START(Tuple)
 {
+	list_p lstp;
+
 	Tuple_OBJ = OBJ(TUPLE_PROTO);
 	MODULE_SET_DOC(Tuple,   "object prototype");
 	set_attr(ist, OBJ(OBJECT), sym(ist, "Tuple"), Tuple_OBJ);
+
+	lstp = Tuple_OBJ->data.ptr = pr_malloc((LIST_OVERHEAD+2) * sizeof(list_t));
+	lstpsize(lstp) = 2;
+	lstplen(lstp)  = 0;
+	set_immutable(Tuple_OBJ);
 }
 
 DEF(Tuple, __str__, NULL) {
-	if (self == Tuple_OBJ)
-		return new_string_obj("()");
 	return str_tuple_list(ist, self, "(", ")");
 }
 
@@ -913,14 +919,19 @@
 
 MODULE_START(List)
 {
+	list_p lstp;
+
 	List_OBJ = OBJ(LIST_PROTO);
 	MODULE_SET_DOC(List, "object prototype");
 	set_attr(ist, OBJ(OBJECT), sym(ist, "List"), List_OBJ);
+
+	lstp = List_OBJ->data.ptr = pr_malloc((LIST_OVERHEAD+2) * sizeof(list_t));
+	lstpsize(lstp) = 2;
+	lstplen(lstp)  = 0;
+	set_immutable(List_OBJ);
 }
 
 DEF(List, __str__, NULL) {
-	if (self == List_OBJ)
-		return new_string_obj("[]");
 	return str_tuple_list(ist, self, "[", "]");
 }
 
@@ -1146,9 +1157,16 @@
 
 MODULE_START(Dict)
 {
+	dict_p dict;
+
 	Dict_OBJ = OBJ(DICT_PROTO);
 	MODULE_SET_DOC(Dict, "dictionary object prototype");
 	set_attr(ist, OBJ(OBJECT), sym(ist, "Dict"), Dict_OBJ);
+
+        dict = obj_malloc(Dict_OBJ, (DICT_OVERHEAD+DEFAULT_INITIAL_DICT_SIZE)*sizeof(dict_t));
+        memset(dict, 0, (DICT_OVERHEAD+DEFAULT_INITIAL_DICT_SIZE)*sizeof(dict_t));
+        dictsize(dict) = DEFAULT_INITIAL_DICT_SIZE;
+	set_immutable(Dict_OBJ);
 }
 
 DEF(Dict, __str__, NULL) {
@@ -1157,9 +1175,6 @@
 	char* res;
 	obj_p res_obj, keys, vals;
 
-	if (self == Dict_OBJ)
-		return new_string_obj("{}");
-
 	len = dict_len(ist, self);
 	keys = dict_keys(ist, self);
 	vals = dict_values(ist, self);
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.