rev 207 - in trunk: include/prothon modules/Dict modules/File modules/Float modules/List modules/Re modules/String modules/Tuple src

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

Modified:
   trunk/include/prothon/prothon.h
   trunk/include/prothon/prothon_dll.h
   trunk/modules/Dict/Dict.c
   trunk/modules/File/File.c
   trunk/modules/Float/Float.c
   trunk/modules/List/List.c
   trunk/modules/Re/Re.c
   trunk/modules/String/String.c
   trunk/modules/Tuple/Tuple.c
   trunk/src/builtins.c
Log:
Fixup changes for modules. Still need to cleanup prothon_dll.h.

This should compile on win32 again.


Modified: trunk/include/prothon/prothon.h
===================================================================
--- trunk/include/prothon/prothon.h	2004-03-30 13:43:41 UTC (rev 206)
+++ trunk/include/prothon/prothon.h	2004-03-30 13:46:08 UTC (rev 207)
@@ -73,14 +73,13 @@
 
 #ifdef WIN32
 #define PR_DECLARE_EXPORT		__declspec(dllexport)
-#define PR_DECLARE_SECTION(name)	#pragma section(name)
+#pragma section("._objinit",read)
 #define PR_PLACE_IN_SECTION(type,name,sect) \
 	__declspec(allocate(sect)) type name
 #define LONG_LONG_FMT			"%I64d"
 #define LONG_LONG_CAST			i64_t
 #else
 #define PR_DECLARE_EXPORT
-#define PR_DECLARE_SECTION(name)
 #define PR_PLACE_IN_SECTION(type,name,sect) \
 	type name __attribute__((section(sect), unused))
 #define LONG_LONG_FMT			"%lld"
@@ -712,16 +711,17 @@
 
 typedef void (* mod_initcall_t)(void);
 
+#define MODULE_DECLARE(name)	\
+static isp ist;			\
+static pr_services_t *services;	\
+static obj_p name##_OBJ;
+
 /* Declare the start of a new module */
 #define MODULE_START(name)					\
-static isp ist;							\
-static pr_services_t *services;					\
-static obj_p name##_OBJ;					\
-PR_DECLARE_SECTION("._objinit_" #name)				\
-PR_PLACE_IN_SECTION(static mod_initcall_t,initcalls_##name,"._objinit_" #name) = NULL
+PR_PLACE_IN_SECTION(static mod_initcall_t,initcalls_##name,"._objinit") = NULL
 
 #define MODULE_END(name)					\
-PR_PLACE_IN_SECTION(static mod_initcall_t,initcalls_##name##_end,"._objinit_" #name) = NULL
+PR_PLACE_IN_SECTION(static mod_initcall_t,initcalls_##name##_end,"._objinit") = NULL
 
 
 // DEF: convenience C macro equivalent of Prothon DEF statement
@@ -730,12 +730,11 @@
 // on every call.
 // see Int.c for example of usage
 #define DEF(slf, func, fparam_list) \
-static obj_p slf##func(isp ist, obj_p self, int pcnt, obj_p* parms, obj_p dlocals); \
-static void slf##func##init(void) {						\
-	set_attr(ist, slf##_OBJ, sym(ist, #func), 				\
-		 new_func_obj(ist, slf##func, fparam_list));			\
-}										\
-PR_PLACE_IN_SECTION(static mod_initcall_t,slf##func##init_ptr, "._objinit_" #slf) = slf##func##init; \
+static obj_p slf##func(isp ist, obj_p self, int pcnt, obj_p* parms, obj_p dlocals); 		\
+static void slf##func##init(void) {								\
+	set_attr(ist, slf##_OBJ, sym(ist, #func), new_func_obj(ist, slf##func, fparam_list));	\
+}												\
+PR_PLACE_IN_SECTION(static mod_initcall_t,slf##func##init_ptr, "._objinit") = slf##func##init; \
 static obj_p slf##func(isp ist, obj_p self, int pcnt, obj_p* parms, obj_p dlocals)
 
 

Modified: trunk/include/prothon/prothon_dll.h
===================================================================
--- trunk/include/prothon/prothon_dll.h	2004-03-30 13:43:41 UTC (rev 206)
+++ trunk/include/prothon/prothon_dll.h	2004-03-30 13:46:08 UTC (rev 207)
@@ -120,6 +120,10 @@
 
 typedef void (* dll_initcall_t)(pr_services_t *);
 
+#ifdef WIN32
+#pragma section("._module_init",read)
+#endif
+
 #define MAIN_MODULE_INIT(name)								\
 static void name##_module_install(void);						\
 PR_DECLARE_EXPORT void name##_dll_entry(pr_services_t* srvcs)				\
@@ -128,25 +132,33 @@
 	ist = get_ist();								\
 	name##_module_install();							\
 }											\
-PR_DECLARE_SECTION("._module_init")							\
 PR_PLACE_IN_SECTION(static dll_initcall_t,name##dll_entry_ptr, "._module_init") =	\
 	name##_dll_entry;								\
 static void name##_module_install(void)
 
-#define MODULE_SUB_INIT(name, proto)			\
-do {							\
-	mod_initcall_t *initcalls = &initcalls_##name;	\
-	if (proto != NO_PROTO)				\
-		name##_OBJ = OBJ(proto);		\
-	else						\
-		name##_OBJ = new_object(NULL);		\
-	initcalls++;					\
-	while (*initcalls) {				\
-		(*initcalls)();				\
-		initcalls++;				\
-	}						\
+#define MODULE_SUB_INIT(name, proto, add_to_base)		\
+do {								\
+	mod_initcall_t *initcalls = &initcalls_##name;		\
+	if (proto != NO_PROTO)					\
+		name##_OBJ = OBJ(proto);			\
+	else							\
+		name##_OBJ = new_object(NULL);			\
+	if (add_to_base) {					\
+		set_attr(ist, OBJ(MODULES),			\
+			sym(ist, #name), name##_OBJ);		\
+		set_attr(ist, OBJ(OBJECT),			\
+			sym(ist, #name), name##_OBJ);		\
+	}							\
+	initcalls++;						\
+	while (*initcalls) {					\
+		(*initcalls)();					\
+		initcalls++;					\
+	}							\
 } while(0)
 
+#define MODULE_SET_DOC(name, docstr) \
+	add_doc_to_obj(ist, name##_OBJ, #name ": " docstr)
+
 #ifndef OBJECT_H
 
 #define get_ist				(*services->get_ist)

Modified: trunk/modules/Dict/Dict.c
===================================================================
--- trunk/modules/Dict/Dict.c	2004-03-30 13:43:41 UTC (rev 206)
+++ trunk/modules/Dict/Dict.c	2004-03-30 13:46:08 UTC (rev 207)
@@ -56,10 +56,12 @@
 #include <stdio.h>
 #include <string.h> 
 
+MODULE_DECLARE(Dict);
+
 MODULE_START(Dict);
 MODULE_END(Dict);
 
 MAIN_MODULE_INIT(Dict)
 {
-	MODULE_SUB_INIT(Dict, DICT_PROTO);
+	MODULE_SUB_INIT(Dict, DICT_PROTO, 0);
 }

Modified: trunk/modules/File/File.c
===================================================================
--- trunk/modules/File/File.c	2004-03-30 13:43:41 UTC (rev 206)
+++ trunk/modules/File/File.c	2004-03-30 13:46:08 UTC (rev 207)
@@ -77,9 +77,10 @@
 #define FLAGS(obj)   (((pr_file_p)((obj)->data.ptr))->flags)
 #define OPEN(obj)    (((obj) != File_OBJ) && STREAM(obj))
 
-MODULE_START(File);
-MODULE_START(Dir);
+MODULE_DECLARE(File);
+MODULE_DECLARE(Dir);
 
+
 static obj_p new_file_object(obj_p filename, obj_p mode,
 			     apr_file_t *fp, int bufsize,
 			     apr_int32_t flags)
@@ -107,6 +108,8 @@
 	return file_obj;
 }
 
+MODULE_START(File);
+
 DEF(File, __init__, list6( sym(ist, "path"),    NULL, 
                                   sym(ist, "mode"),    new_string_obj("r"),
                                   sym(ist, "bufsize"), new_int_obj(-1) ) ) {
@@ -648,6 +651,10 @@
 	return parms[1];
 }
 
+MODULE_END(File);
+
+MODULE_START(Dir);
+
 DEF(Dir, __init__, list2(sym(ist, "path"), NULL)) {
 	obj_p file_obj = new_string_obj(strch(parms[1]));
 	switch_proto_to(ist, file_obj, Dir_OBJ);
@@ -658,6 +665,8 @@
 	return parms[1];
 }
 
+MODULE_END(Dir);
+
 #define __STDIN		0
 #define __STDOUT	1
 #define __STDERR	2
@@ -701,20 +710,14 @@
 	return new_file_object(file, mode, fp, MIN_BUFSIZE, flags);
 }
 
-MODULE_END(File);
-MODULE_END(Dict);
-
 MAIN_MODULE_INIT(File) {
 	apr_pool_t *std_pool;
 	apr_status_t aprerr;
 	obj_p file_obj;
 
-	MODULE_SUB_INIT(File, NO_PROTO);
-	MODULE_SUB_INIT(Dir, NO_PROTO);
+	MODULE_SUB_INIT(File, NO_PROTO, 1);
+	MODULE_SUB_INIT(Dir, NO_PROTO, 0);
 
-	set_attr(ist, OBJ(OBJECT),	sym(ist, "File"), File_OBJ);
-	set_attr(ist, OBJ(OBJECT),	sym(ist, "Dir"),  Dir_OBJ);
-
 	/* Create base file objects for std{in,out,err} */
 	aprerr = apr_pool_create(&std_pool, get_pr_head_pool());
 	/* Need some kind of error return! */

Modified: trunk/modules/Float/Float.c
===================================================================
--- trunk/modules/Float/Float.c	2004-03-30 13:43:41 UTC (rev 206)
+++ trunk/modules/Float/Float.c	2004-03-30 13:46:08 UTC (rev 207)
@@ -65,6 +65,9 @@
 #define is_Float(objid)		(has_proto(ist, objid, Float_OBJ))
 #define Float_value(objid)	(objid->data.f64)
 
+MODULE_DECLARE(Float);
+
+
 MODULE_START(Float);
 
 DEF(Float, __bool__, NULL) { 
@@ -319,5 +322,5 @@
 
 MAIN_MODULE_INIT(Float)
 {
-	MODULE_SUB_INIT(Float, FLOAT_PROTO);
+	MODULE_SUB_INIT(Float, FLOAT_PROTO, 0);
 }

Modified: trunk/modules/List/List.c
===================================================================
--- trunk/modules/List/List.c	2004-03-30 13:43:41 UTC (rev 206)
+++ trunk/modules/List/List.c	2004-03-30 13:46:08 UTC (rev 207)
@@ -58,6 +58,8 @@
 #include <stdio.h>
 #include <string.h> 
 
+MODULE_DECLARE(List);
+
 MODULE_START(List);
 
 DEF(List, __add__, FORM_RPARAM) { 
@@ -238,5 +240,5 @@
 
 MAIN_MODULE_INIT(List)
 {
-	MODULE_SUB_INIT(List, LIST_PROTO);
+	MODULE_SUB_INIT(List, LIST_PROTO, 0);
 }

Modified: trunk/modules/Re/Re.c
===================================================================
--- trunk/modules/Re/Re.c	2004-03-30 13:43:41 UTC (rev 206)
+++ trunk/modules/Re/Re.c	2004-03-30 13:46:08 UTC (rev 207)
@@ -63,15 +63,15 @@
 
 #define numgrps(re_obj) (((regex_t*)((re_obj)->data.ptr))->re_nsub)
 
-MODULE_START(Re);
-MODULE_START(ReCompiled);
-MODULE_START(ReMatch);
-
-
 static obj_p RE_EXC; 
 static obj_p i_flg, s_flg;
 
+MODULE_DECLARE(Re);
+MODULE_DECLARE(ReCompiled);
+MODULE_DECLARE(ReMatch);
 
+MODULE_START(Re);
+
 DEF( Re, compile, list4( sym(ist, "pattern"), NULL, 
 								sym(ist, "flags"),   OBJ(ZERO_INT) ) ) {
 	obj_p re_obj;
@@ -113,6 +113,10 @@
 	return re_obj;
 }
 
+MODULE_END(Re);
+
+MODULE_START(ReCompiled);
+
 DEF(ReCompiled, findall, FORM_RPARAM) {
 	char* s;
 	regmatch_t* m;
@@ -484,6 +488,10 @@
 	return OBJ(NONE);
 }
 
+MODULE_END(ReCompiled);
+
+MODULE_START(ReMatch);
+
 DEF(ReMatch, __objlist__, FORM_RPARAM) {
 	return parms[1];
 }
@@ -624,31 +632,24 @@
 	return res;
 }
 
-MODULE_END(Re);
-MODULE_END(ReCompiled);
 MODULE_END(ReMatch);
 
 MAIN_MODULE_INIT(Re)
 {
-	MODULE_SUB_INIT(Re, NO_PROTO);
-	MODULE_SUB_INIT(ReCompiled, NO_PROTO);
-	MODULE_SUB_INIT(ReMatch, NO_PROTO);
+	MODULE_SUB_INIT(Re, NO_PROTO, 1);
+	MODULE_SUB_INIT(ReCompiled, NO_PROTO, 0);
+	MODULE_SUB_INIT(ReMatch, NO_PROTO, 0);
 
+	MODULE_SET_DOC(Re, "module for regular expressions");
+	MODULE_SET_DOC(ReCompiled, "prototype for compiled regular expressions");
+	MODULE_SET_DOC(ReMatch, "prototype for regular expression match objects");
+
+	set_attr(ist, Re_OBJ, sym(ist, "Re"), ReCompiled_OBJ);
+	set_attr(ist, Re_OBJ, sym(ist, "Match"), ReMatch_OBJ);
+
 	RE_EXC = new_object(OBJ(EXCEPTION));
-
 	add_doc_to_obj(ist, RE_EXC,
 			"Re module error");
-	add_doc_to_obj(ist, Re_OBJ,
-			"Re: module for regular expressions");
-	add_doc_to_obj(ist, ReCompiled_OBJ,
-			"ReCompiled: prototype for compiled regular expressions");
-	add_doc_to_obj(ist, ReMatch_OBJ,
-			"Match_proto: prototype for regular expression match objects");
-
-	set_attr(ist, OBJ(MODULES), sym(ist, "Re"),	Re_OBJ);
-	set_attr(ist, OBJ(OBJECT),  sym(ist, "Re"),	Re_OBJ);
-	set_attr(ist, Re_OBJ,    sym(ist, "Re"),		ReCompiled_OBJ);
-	set_attr(ist, Re_OBJ,    sym(ist, "Match"),		ReMatch_OBJ);
 	set_attr(ist, Re_OBJ,    sym(ist, "ReException"),	RE_EXC);
 
 	i_flg = new_int_obj(REG_ICASE);

Modified: trunk/modules/String/String.c
===================================================================
--- trunk/modules/String/String.c	2004-03-30 13:43:41 UTC (rev 206)
+++ trunk/modules/String/String.c	2004-03-30 13:46:08 UTC (rev 207)
@@ -57,11 +57,13 @@
 #include <string.h>
 #include <prothon/prothon_dll.h>
 
+#define is_String(objid)	(has_proto(ist, objid, String_OBJ))
+
+MODULE_DECLARE(String);
+MODULE_DECLARE(StringGen);
+
 MODULE_START(String);
-MODULE_START(StringGen);
 
-#define is_String(objid)	(has_proto(ist, objid, String_OBJ))
-
 DEF(String, cmp, FORM_RPARAM){
 	obj_p other = parms[1];
 	if (self == other)
@@ -140,23 +142,6 @@
 	return gen_obj;
 }
 
-DEF(StringGen, next, NULL) {
-	int ch;
-	obj_p res = NULL;
-	char* res_str;
-	write_lock(ist, self);
-	if ((ch = *strch(self))) {
-		((char*)(self->data.ptr))++;
-		res = new_object(String_OBJ);
-		res_str = (char*)obj_malloc(res, 2);
-		res_str[0] = ch; 
-		res_str[1] = 0; 
-	} else
-		raise_exception(ist, OBJ(END_OF_GEN_EXC), NULL);
-	write_unlock(ist, self);
-	return res;
-}
-
 DEF(String, ord, NULL) {
 	return new_int_obj((int)(*strch(self)));
 }
@@ -233,10 +218,28 @@
 }
 
 MODULE_END(String);
+
+MODULE_START(StringGen);
+DEF(StringGen, next, NULL) {
+        int ch;
+        obj_p res = NULL;
+        char* res_str;
+        write_lock(ist, self);
+        if ((ch = *strch(self))) {
+                ((char*)(self->data.ptr))++;
+                res = new_object(String_OBJ);
+                res_str = (char*)obj_malloc(res, 2);
+                res_str[0] = ch;
+                res_str[1] = 0;
+        } else
+                raise_exception(ist, OBJ(END_OF_GEN_EXC), NULL);
+        write_unlock(ist, self);
+        return res;
+}
 MODULE_END(StringGen);
 
 MAIN_MODULE_INIT(String)
 {
-	MODULE_SUB_INIT(String, STRING_PROTO);
-	MODULE_SUB_INIT(StringGen, NO_PROTO);
+	MODULE_SUB_INIT(String, STRING_PROTO, 0);
+	MODULE_SUB_INIT(StringGen, NO_PROTO, 0);
 }

Modified: trunk/modules/Tuple/Tuple.c
===================================================================
--- trunk/modules/Tuple/Tuple.c	2004-03-30 13:43:41 UTC (rev 206)
+++ trunk/modules/Tuple/Tuple.c	2004-03-30 13:46:08 UTC (rev 207)
@@ -58,6 +58,8 @@
 #include <stdio.h>
 #include <string.h>
 
+MODULE_DECLARE(Tuple);
+
 MODULE_START(Tuple);
 
 DEF(Tuple, __rin__, FORM_RPARAM) { 
@@ -185,5 +187,5 @@
 
 MAIN_MODULE_INIT(Tuple)
 {
-	MODULE_SUB_INIT(Tuple, TUPLE_PROTO);
+	MODULE_SUB_INIT(Tuple, TUPLE_PROTO, 0);
 }

Modified: trunk/src/builtins.c
===================================================================
--- trunk/src/builtins.c	2004-03-30 13:43:41 UTC (rev 206)
+++ trunk/src/builtins.c	2004-03-30 13:46:08 UTC (rev 207)
@@ -63,6 +63,21 @@
 #include "object.h"
 #include <prothon/prothon_dll.h>
 
+MODULE_DECLARE(Object);
+MODULE_DECLARE(False);
+MODULE_DECLARE(True);
+MODULE_DECLARE(None);
+MODULE_DECLARE(Exception);
+MODULE_DECLARE(Gen);
+MODULE_DECLARE(String);
+MODULE_DECLARE(Tuple);
+MODULE_DECLARE(List);
+MODULE_DECLARE(Dict);
+MODULE_DECLARE(Seq);
+MODULE_DECLARE(Func);
+MODULE_DECLARE(Int);
+MODULE_DECLARE(IntGen);
+
 // ***************************** Object *********************************
 
 MODULE_START(Object);
@@ -1095,22 +1110,21 @@
 
 MAIN_MODULE_INIT(Builtins)
 {
-	MODULE_SUB_INIT(Object, OBJECT);
-	MODULE_SUB_INIT(False, PR_FALSE);
-	MODULE_SUB_INIT(True, PR_TRUE);
-	MODULE_SUB_INIT(None, NONE);
-	MODULE_SUB_INIT(Exception, EXCEPTION);
-	MODULE_SUB_INIT(Gen, GEN_PROTO);
-	MODULE_SUB_INIT(String, STRING_PROTO);
-	MODULE_SUB_INIT(Tuple, TUPLE_PROTO);
-	MODULE_SUB_INIT(List, LIST_PROTO);
-	MODULE_SUB_INIT(Dict, DICT_PROTO);
-	MODULE_SUB_INIT(Seq, SEQ_PROTO);
-	MODULE_SUB_INIT(Func, FUNC_PROTO);
-	CALL_INIT(OBJECT_OBJ, attrs);
+	MODULE_SUB_INIT(Object, OBJECT, 0);
+	MODULE_SUB_INIT(False, PR_FALSE, 0);
+	MODULE_SUB_INIT(True, PR_TRUE, 0);
+	MODULE_SUB_INIT(None, NONE, 0);
+	MODULE_SUB_INIT(Exception, EXCEPTION, 0);
+	MODULE_SUB_INIT(Gen, GEN_PROTO, 0);
+	MODULE_SUB_INIT(String, STRING_PROTO, 0);
+	MODULE_SUB_INIT(Tuple, TUPLE_PROTO, 0);
+	MODULE_SUB_INIT(List, LIST_PROTO, 0);
+	MODULE_SUB_INIT(Dict, DICT_PROTO, 0);
+	MODULE_SUB_INIT(Seq, SEQ_PROTO, 0);
+	MODULE_SUB_INIT(Func, FUNC_PROTO, 0);
 
 	SYM_LIMIT = sym(ist, "limit");
 
-	MODULE_SUB_INIT(Int, INT_PROTO);
-	MODULE_SUB_INIT(IntGen, NO_PROTO);
+	MODULE_SUB_INIT(Int, INT_PROTO, 0);
+	MODULE_SUB_INIT(IntGen, NO_PROTO, 0);
 }
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.