rev 371 - in trunk: include/prothon modules/File modules/OS modules/Prosist modules/SQLite src
SVN User <[email protected]>
| Newsgroups | gmane.comp.lang.prothon.cvs |
|---|---|
| Message-ID | <[email protected]> |
Author: mark
Date: 2004-04-16 22:29:24 -0400 (Fri, 16 Apr 2004)
New Revision: 371
Modified:
trunk/include/prothon/prothon.h
trunk/include/prothon/prothon_dll.h
trunk/modules/File/File.c
trunk/modules/OS/OS.c
trunk/modules/Prosist/Prosist.c
trunk/modules/SQLite/SQLite.c
trunk/src/builtins-core.c
trunk/src/builtins-float.c
trunk/src/builtins-int.c
trunk/src/interp.c
trunk/src/object.c
trunk/src/symbol.c
trunk/src/sys.c
Log:
renamed add_doc_to_obj to doc_obj,
more work on prosist
Modified: trunk/include/prothon/prothon.h
===================================================================
--- trunk/include/prothon/prothon.h 2004-04-16 18:36:00 UTC (rev 370)
+++ trunk/include/prothon/prothon.h 2004-04-17 02:29:24 UTC (rev 371)
@@ -376,6 +376,7 @@
__GETCMP__,
__CMPVALOBJ__,
__ITER__,
+ __NAME__,
__DOC__,
__HASH__,
__FPARAMS__,
@@ -403,6 +404,9 @@
MAX,
MIN,
COPY,
+ __CREATOR__,
+ __STORPROXY__,
+ __NEWVIASTORPROXY__,
SYM_ENUM_COUNT
} sym_enum_t;
@@ -677,10 +681,22 @@
// HASH_VALUE: Integer value of a hash object returned by __hash__ function.
#define hash_value(hash_obj) (hash_obj->data.i32[0])
-// ADD_DOC_TO_OBJ: Add document string (__doc__) to object
+// NAME_OBJ: Add name string (__name__) to object
+// this is used by Prosist, the persistence engine and other documentation,
+// such as the exception stack function names. This function is somewhat
+// of a replacement for Prothon's lack of class names also. All Prototypes
+// should be named with this.
+// WARNING: There should not be more than one object with the same name in
+// one namespace. Names are meant for singleton objects like prototypes and
+// functions. You will get an exception if you try certain operations on
+// objects that have identical names.
+#define name_obj(ist, obj, name) \
+ set_attr(ist, (obj), SYM(__NAME__), new_string_obj(ist, (name)));
+
+// DOC_OBJ: Add document string (__doc__) to object
// This can be used on any object. It is recommended that it be used
// liberally to make browsing objects easier and to make dumps readable.
-void add_doc_to_obj(isp ist, obj_p obj, char* str);
+void doc_obj(isp ist, obj_p obj, char* str);
#ifndef NO_APR
// NEW_THREAD_OBJ: Create a new thread object and start the thread
Modified: trunk/include/prothon/prothon_dll.h
===================================================================
--- trunk/include/prothon/prothon_dll.h 2004-04-16 18:36:00 UTC (rev 370)
+++ trunk/include/prothon/prothon_dll.h 2004-04-17 02:29:24 UTC (rev 371)
@@ -97,7 +97,7 @@
obj_p (*call_func1_f)(isp ist, obj_p self, obj_p sym, obj_p parm);
obj_p (*sym)(isp ist, char* symbol);
obj_p (*new_object)(isp ist, obj_p proto);
- void (*add_doc_to_obj)(isp ist, obj_p obj, char* str);
+ void (*doc_obj)(isp ist, obj_p obj, char* str);
obj_p (*dict_keys_values)(isp ist, obj_p dict_obj, int key_flg);
obj_p (*check_exceptions)(isp ist);
@@ -197,7 +197,7 @@
#define MODULE_SET_DOC(name, docstr) \
- add_doc_to_obj(ist, name##_OBJ, #name ": " docstr); \
+ doc_obj(ist, name##_OBJ, #name ": " docstr); \
check_exceptions(ist);
#ifndef OBJECT_H
@@ -234,7 +234,7 @@
#define list8 (*services->list8)
#define raise_exception (*services->raise_exception)
#define new_object (*services->new_object)
-#define add_doc_to_obj (*services->add_doc_to_obj)
+#define doc_obj (*services->doc_obj)
#define pr_malloc (*services->pr_malloc)
#define pr_realloc (*services->pr_realloc)
#define pr_free (*services->pr_free)
Modified: trunk/modules/File/File.c
===================================================================
--- trunk/modules/File/File.c 2004-04-16 18:36:00 UTC (rev 370)
+++ trunk/modules/File/File.c 2004-04-17 02:29:24 UTC (rev 371)
@@ -121,7 +121,7 @@
MODULE_START(File)
{
File_OBJ = new_object(ist, NULL);
- add_doc_to_obj(ist, File_OBJ, "File object prototype");
+ doc_obj(ist, File_OBJ, "File object prototype");
MODULE_ADD_TO_BASE(File);
File_OBJ->unclonable = TRUE;
}
Modified: trunk/modules/OS/OS.c
===================================================================
--- trunk/modules/OS/OS.c 2004-04-16 18:36:00 UTC (rev 370)
+++ trunk/modules/OS/OS.c 2004-04-17 02:29:24 UTC (rev 371)
@@ -70,7 +70,7 @@
if (!has_proto_QUES(ist, parms[1], OBJ(STRING_PROTO))) {
ist->exception_obj = new_object(ist, OBJ(TYPE_EXC));
ist->exception_obj->wr_access = ACC_GUEST;
- add_doc_to_obj(ist, ist->exception_obj, "object is not of type string");
+ doc_obj(ist, ist->exception_obj, "object is not of type string");
return NULL;
}
return new_int_obj(ist, system(strch(parms[1])));
Modified: trunk/modules/Prosist/Prosist.c
===================================================================
--- trunk/modules/Prosist/Prosist.c 2004-04-16 18:36:00 UTC (rev 370)
+++ trunk/modules/Prosist/Prosist.c 2004-04-17 02:29:24 UTC (rev 371)
@@ -167,7 +167,7 @@
read_unlock(ist, self);
set_obj_rdacc(self, ACC_USER1);
- add_doc_to_obj(ist, self, "Prosist DataBase");
+ doc_obj(ist, self, "Prosist DataBase");
set_attr(ist, self, sym(ist, "filename"), parms[1]);
set_attr(ist, self, sym(ist, "root"), root_obj);
read_lock(ist, self);
Modified: trunk/modules/SQLite/SQLite.c
===================================================================
--- trunk/modules/SQLite/SQLite.c 2004-04-16 18:36:00 UTC (rev 370)
+++ trunk/modules/SQLite/SQLite.c 2004-04-17 02:29:24 UTC (rev 371)
@@ -107,7 +107,7 @@
CHECK_TYPE_EXC(parms[1], OBJ(STRING_PROTO), "string");
filename = strch(parms[1]);
conn_obj = new_object(ist, Connection_OBJ);
- add_doc_to_obj(ist, conn_obj, "SQLite connection");
+ doc_obj(ist, conn_obj, "SQLite connection");
conn_obj->unclonable = TRUE;
set_obj_rdacc(conn_obj, ACC_USER1);
conn_obj->data_type = DATA_TYPE_DATAPTR;
@@ -123,7 +123,7 @@
if (self->data.ptr) {
cursor_p cursorp;
obj_p curs_obj = new_object(ist, Cursor_OBJ);
- add_doc_to_obj(ist, curs_obj, "SQLite cursor");
+ doc_obj(ist, curs_obj, "SQLite cursor");
curs_obj->data_type = DATA_TYPE_DATAPTR;
cursorp = curs_obj->data.ptr = pr_malloc(sizeof(cursor_t));
cursorp->ist = ist;
Modified: trunk/src/builtins-core.c
===================================================================
--- trunk/src/builtins-core.c 2004-04-16 18:36:00 UTC (rev 370)
+++ trunk/src/builtins-core.c 2004-04-17 02:29:24 UTC (rev 371)
@@ -80,12 +80,12 @@
Object_OBJ = OBJ(OBJECT);
MODULE_SET_DOC(Object, "prototype base for all objects");
- add_doc_to_obj(ist, OBJ(SYMBOL_PROTO), "Symbol object prototype");
- add_doc_to_obj(ist, OBJ(HASH_PROTO), "Hash object prototype");
- add_doc_to_obj(ist, OBJ(SLICE_PROTO), "Slice object prototype");
- add_doc_to_obj(ist, OBJ(SUPER_PROTO), "Super object prototype");
- add_doc_to_obj(ist, OBJ(ROOT_GLOBALS), "Root_Globals: recursive container of all objects");
- add_doc_to_obj(ist, OBJ(MODULES), "Modules: container of all modules");
+ doc_obj(ist, OBJ(SYMBOL_PROTO), "Symbol object prototype");
+ doc_obj(ist, OBJ(HASH_PROTO), "Hash object prototype");
+ doc_obj(ist, OBJ(SLICE_PROTO), "Slice object prototype");
+ doc_obj(ist, OBJ(SUPER_PROTO), "Super object prototype");
+ doc_obj(ist, OBJ(ROOT_GLOBALS), "Root_Globals: recursive container of all objects");
+ doc_obj(ist, OBJ(MODULES), "Modules: container of all modules");
set_attr(ist, OBJ(OBJECT), sym(ist, "Root_Globals"), OBJ(ROOT_GLOBALS));
set_attr(ist, OBJ(OBJECT), sym(ist, "Modules"), OBJ(MODULES));
@@ -336,6 +336,26 @@
return parms[1];
}
+DEF(Object, __creator__, NULL) {
+ obj_p name;
+ char buf[512];
+ if (name = get_attr(ist, self, SYM(__NAME__))) {
+ apr_snprintf(buf, sizeof(buf), "1:%s", strch(name));
+ del_unlock(name);
+ return list3(ist, OBJ(NONE), new_string_obj(ist, "Object"), new_string_obj(ist, buf));
+ }
+ return list3(ist, OBJ(NONE), OBJ(NONE), new_string_obj(ist, "Object"));
+}
+
+DEF(Object, __storProxy__, NULL) {
+ return self;
+}
+
+DEF(Object, __newViaStorProxy__, FORM_RPARAM) {
+ return parms[1];
+}
+
+
// ***************************** PR_FALSE *****************************************
MODULE_START(False)
@@ -343,6 +363,7 @@
False_OBJ = OBJ(PR_FALSE);
MODULE_SET_DOC(False, "boolean false singleton value");
set_attr(ist, OBJ(OBJECT), sym(ist, "False"), False_OBJ);
+ name_obj(ist, False_OBJ, "False");
}
DEF(False, __str__, NULL) { return new_string_obj(ist, "False"); }
@@ -354,7 +375,6 @@
return new_int_obj(ist, -1);
}
-
// ***************************** PR_TRUE *****************************************
MODULE_START(True)
@@ -362,6 +382,7 @@
True_OBJ = OBJ(PR_TRUE);
MODULE_SET_DOC(True, "boolean true singleton value");
set_attr(ist, OBJ(OBJECT), sym(ist, "True"), True_OBJ);
+ name_obj(ist, True_OBJ, "True");
}
DEF(True, __str__, NULL) { return new_string_obj(ist, "True"); }
@@ -385,6 +406,7 @@
None_OBJ = OBJ(NONE);
MODULE_SET_DOC(None, "represents empty set");
set_attr(ist, OBJ(OBJECT), sym(ist, "None"), None_OBJ);
+ name_obj(ist, None_OBJ, "None");
}
DEF(None, __str__, NULL) {
@@ -400,59 +422,45 @@
else return OBJ(PR_FALSE);
}
-
// ***************************** EXCEPTION ************************************
MODULE_START(Exception)
{
Exception_OBJ = OBJ(EXCEPTION);
- MODULE_SET_DOC(Exception, "root for all exception objects");
+ MODULE_SET_DOC(Exception, "prototype of all exception objects");
set_attr(ist, OBJ(OBJECT), sym(ist, "Exception"), Exception_OBJ);
- /* Other exception objects dependent on this one */
- OBJ(INTERNAL_EXC) = new_object(ist, Exception_OBJ);
- OBJ(PARSEERROR_EXC) = new_object(ist, Exception_OBJ);
- OBJ(INTERPRETER_EXC) = new_object(ist, Exception_OBJ);
- OBJ(ASSERTION_EXC) = new_object(ist, Exception_OBJ);
- OBJ(NAME_EXC) = new_object(ist, Exception_OBJ);
- OBJ(INDEX_EXC) = new_object(ist, Exception_OBJ);
- OBJ(FUNCNOTFOUND_EXC) = new_object(ist, Exception_OBJ);
- OBJ(TYPE_EXC) = new_object(ist, Exception_OBJ);
- OBJ(MUTABLE_EXC) = new_object(ist, Exception_OBJ);
- OBJ(DIVIDEZERO_EXC) = new_object(ist, Exception_OBJ);
- OBJ(OUTOFMEMORY_EXC) = new_object(ist, Exception_OBJ);
- OBJ(IOEXCEPTION) = new_object(ist, Exception_OBJ);
- OBJ(FILENOTFOUND_EXC) = new_object(ist, OBJ(IOEXCEPTION));
- OBJ(STOP_ITERATION_EXC) = new_object(ist, Exception_OBJ);
- OBJ(LOCK_EXC) = new_object(ist, Exception_OBJ);
- OBJ(PERMISSION_EXC) = new_object(ist, Exception_OBJ);
+#define EXCEPTION_DECLARE(proto, exc_const, name, desc_str) \
+ OBJ(exc_const) = new_object(ist, proto); \
+ doc_obj( ist, OBJ(exc_const), desc_str); \
+ name_obj(ist, OBJ(exc_const), #name); \
+ set_attr(ist, OBJ(OBJECT), sym(ist, #name), OBJ(exc_const))
- /* And their doc entries */
- add_doc_to_obj(ist, OBJ(INTERNAL_EXC), "Internal Prothon Error");
- add_doc_to_obj(ist, OBJ(PARSEERROR_EXC), "Parse Error");
- add_doc_to_obj(ist, OBJ(INTERPRETER_EXC), "Program Error");
- add_doc_to_obj(ist, OBJ(ASSERTION_EXC), "Assertion Error");
- add_doc_to_obj(ist, OBJ(NAME_EXC), "Name Error");
- add_doc_to_obj(ist, OBJ(INDEX_EXC), "Index Error");
- add_doc_to_obj(ist, OBJ(TYPE_EXC), "Type Error");
- add_doc_to_obj(ist, OBJ(MUTABLE_EXC), "Mutable Error");
- add_doc_to_obj(ist, OBJ(DIVIDEZERO_EXC), "Divide by zero error");
- add_doc_to_obj(ist, OBJ(OUTOFMEMORY_EXC), "Out Of Memory Error");
- add_doc_to_obj(ist, OBJ(IOEXCEPTION), "IO Error");
- add_doc_to_obj(ist, OBJ(FILENOTFOUND_EXC), "File Not Found");
- add_doc_to_obj(ist, OBJ(STOP_ITERATION_EXC), "End Of Generated Sequence (no error)");
- add_doc_to_obj(ist, OBJ(LOCK_EXC), "Locking Error");
- add_doc_to_obj(ist, OBJ(PERMISSION_EXC), "Permission Error");
+/* Other exception objects dependent on this one */
+EXCEPTION_DECLARE(Exception_OBJ, INTERNAL_EXC, InternalError, "Internal Prothon Error");
+EXCEPTION_DECLARE(Exception_OBJ, PARSEERROR_EXC, ParseError, "Parse Error");
+EXCEPTION_DECLARE(Exception_OBJ, INTERPRETER_EXC, ProgramError, "Program Error");
+EXCEPTION_DECLARE(Exception_OBJ, ASSERTION_EXC, AssertionError, "Assertion Error");
+EXCEPTION_DECLARE(Exception_OBJ, NAME_EXC, NameError, "Name Error");
+EXCEPTION_DECLARE(Exception_OBJ, INDEX_EXC, IndexError, "Index Error");
+EXCEPTION_DECLARE(Exception_OBJ, FUNCNOTFOUND_EXC, FunctionNotFound, "Function not found Error");
+EXCEPTION_DECLARE(Exception_OBJ, TYPE_EXC, TypeError, "Type Error");
+EXCEPTION_DECLARE(Exception_OBJ, MUTABLE_EXC, MutableError, "Mutable Error");
+EXCEPTION_DECLARE(Exception_OBJ, DIVIDEZERO_EXC, DivideByZero, "Divide by zero Error");
+EXCEPTION_DECLARE(Exception_OBJ, OUTOFMEMORY_EXC, OutOfMemoryError, "Out of memory Error");
+EXCEPTION_DECLARE(Exception_OBJ, IOEXCEPTION, IOError, "IO Error");
+EXCEPTION_DECLARE(OBJ(IOEXCEPTION), FILENOTFOUND_EXC, FileNotFound, "File not found Error");
+EXCEPTION_DECLARE(Exception_OBJ, STOP_ITERATION_EXC, StopIteration, "Stop iteration (not an error)");
+EXCEPTION_DECLARE(Exception_OBJ, LOCK_EXC, LockError, "Locking Error");
+EXCEPTION_DECLARE(Exception_OBJ, PERMISSION_EXC, PermissionError, "Permission Error");
}
DEF(Exception, __init__, FORM_STAR_PARAM) {
- obj_p res;
- if (list_len(ist, parms[1]) > 0)
- raise_exception(ist, self, "%s", as_str(ist, list_item(ist, parms[1], 0)));
- else
- raise_exception(ist, self, NULL);
- res = ist->exception_obj;
- ist->exception_obj = 0;
- return res;
+ char buf[512];
+ if (list_len(ist, parms[1]) > 0) {
+ apr_snprintf(buf, sizeof(buf), "%s", as_str(ist, list_item(ist, parms[1], 0)));
+ doc_obj(ist, self, buf);
+ }
+ return OBJ(NONE);
}
// ***************************** GEN ******************************************
@@ -685,6 +693,9 @@
MODULE_ADD_SYM(Object, attrs);
MODULE_ADD_SYM(Object, CurrentThread);
MODULE_ADD_SYM(Object, Sleep);
+ MODULE_ADD_SYM(Object, __creator__);
+ MODULE_ADD_SYM(Object, __storProxy__);
+ MODULE_ADD_SYM(Object, __newViaStorProxy__);
MODULE_SUB_INIT(Seq);
Modified: trunk/src/builtins-float.c
===================================================================
--- trunk/src/builtins-float.c 2004-04-16 18:36:00 UTC (rev 370)
+++ trunk/src/builtins-float.c 2004-04-17 02:29:24 UTC (rev 371)
@@ -91,8 +91,8 @@
// Imag_OBJ = OBJ(IMAG_PROTO) = new_object(ist, NULL);
OBJ(IMAG_PROTO) = new_object(ist, NULL);
- add_doc_to_obj(ist, OBJ(FLOAT_PROTO), "Float number object prototype");
- add_doc_to_obj(ist, OBJ(IMAG_PROTO), "Imaginary number object prototype");
+ doc_obj(ist, OBJ(FLOAT_PROTO), "Float number object prototype");
+ doc_obj(ist, OBJ(IMAG_PROTO), "Imaginary number object prototype");
set_attr(ist, OBJ(OBJECT), sym(ist, "Float"), OBJ(FLOAT_PROTO));
set_attr(ist, OBJ(OBJECT), sym(ist, "Imaginary"), OBJ(IMAG_PROTO));
Modified: trunk/src/builtins-int.c
===================================================================
--- trunk/src/builtins-int.c 2004-04-16 18:36:00 UTC (rev 370)
+++ trunk/src/builtins-int.c 2004-04-17 02:29:24 UTC (rev 371)
@@ -98,7 +98,7 @@
OBJ(MAX_INT) = new_int_obj(ist, MAX_INT_VAL);
OBJ(LONG_PROTO) = new_string_obj(ist, "0");
clr_immutable(OBJ(LONG_PROTO));
- add_doc_to_obj(ist, OBJ(LONG_PROTO), "Long integer number object prototype");
+ doc_obj(ist, OBJ(LONG_PROTO), "Long integer number object prototype");
set_immutable(OBJ(LONG_PROTO));
Int_OBJ->data_type = DATA_TYPE_IMMDATA;
Modified: trunk/src/interp.c
===================================================================
--- trunk/src/interp.c 2004-04-16 18:36:00 UTC (rev 370)
+++ trunk/src/interp.c 2004-04-17 02:29:24 UTC (rev 371)
@@ -1502,7 +1502,7 @@
}
#endif
apr_snprintf(full_doc, sizeof(full_doc), "%s%s", name, comment);
- add_doc_to_obj(ist, module, full_doc);
+ doc_obj(ist, module, full_doc);
frame = ist->frame;
new_locals = new_object(ist, NULL);
set_attr(ist, module, SYM(__LOCALS__), new_locals);
Modified: trunk/src/object.c
===================================================================
--- trunk/src/object.c 2004-04-16 18:36:00 UTC (rev 370)
+++ trunk/src/object.c 2004-04-17 02:29:24 UTC (rev 371)
@@ -154,7 +154,7 @@
dll_services.list6 = list6;
dll_services.raise_exception = raise_exception;
dll_services.new_object = new_object;
- dll_services.add_doc_to_obj = add_doc_to_obj;
+ dll_services.doc_obj = doc_obj;
dll_services.obj_malloc = obj_malloc;
dll_services.obj_realloc = obj_realloc;
dll_services.obj_free = obj_free;
@@ -209,7 +209,7 @@
init_symbol(ist);
- add_doc_to_obj(ist, OBJ(SYMBOLS), "Symbols: list of all symbol objects");
+ doc_obj(ist, OBJ(SYMBOLS), "Symbols: list of all symbol objects");
/* Now load the actual modules for the builtin prototypes */
BUILTIN_LOAD(Core);
@@ -339,7 +339,7 @@
p = err_buf + strlen(err_buf) - 1;
while (*p == '.' || *p == ' ' || *p == '\t') { *p = 0; p--; }
- add_doc_to_obj(ist, ist->exception_obj, err_buf);
+ doc_obj(ist, ist->exception_obj, err_buf);
}
}
@@ -836,8 +836,8 @@
}
-//********************************* add_doc_to_obj ***********************************
-void add_doc_to_obj(isp ist, obj_p obj, char* str){
+//********************************* doc_obj ***********************************
+void doc_obj(isp ist, obj_p obj, char* str){
if (str[strlen(str)-1] == '\n') {
char* ns = pr_malloc(strlen(str)+1);
strcpy(ns, str);
Modified: trunk/src/symbol.c
===================================================================
--- trunk/src/symbol.c 2004-04-16 18:36:00 UTC (rev 370)
+++ trunk/src/symbol.c 2004-04-17 02:29:24 UTC (rev 371)
@@ -120,6 +120,7 @@
{ "__getCmp__", 0 },
{ "__cmpvalobj__", 0 },
{ "__iter__", 0 },
+ { "__name__", 0 },
{ "__doc__", 0 },
{ "__hash__", 0 },
{ "__fparams__", 0 },
@@ -146,7 +147,10 @@
{ "len", 0 },
{ "max", 0 },
{ "min", 0 },
- { "copy", 0 }
+ { "copy", 0 },
+ { "__creator__", 0 },
+ { "__storProxy__", 0 },
+ { "__newViaStorProxy__", 0}
};
typedef struct trie_node_s* trie_p;
Modified: trunk/src/sys.c
===================================================================
--- trunk/src/sys.c 2004-04-16 18:36:00 UTC (rev 370)
+++ trunk/src/sys.c 2004-04-17 02:29:24 UTC (rev 371)
@@ -147,7 +147,7 @@
sys_module = new_object(ist, OBJ(OBJECT));
set_attr(ist, OBJ(MODULES),sym(ist, "Sys"), sys_module);
set_attr(ist, OBJ(OBJECT), sym(ist, "Sys"), sys_module);
- add_doc_to_obj(ist, sys_module, "Sys: a built-in module of system attributes");
+ doc_obj(ist, sys_module, "Sys: a built-in module of system attributes");
add_path(ist, sys_path, "."); if_exc_return NULL;
#ifdef PROTHON_DEFAULT_MODDIR
add_path(ist, sys_path, PROTHON_DEFAULT_MODDIR); if_exc_return NULL;
@@ -162,7 +162,7 @@
if (!*s++) break;
}
}
- add_doc_to_obj(ist, sys_path, "path: list of paths to search for modules");
+ doc_obj(ist, sys_path, "path: list of paths to search for modules");
set_attr(ist, sys_module, sym(ist, "path"), sys_path);
if ((s = getenv("PROTHONHOME"))) {
for (d=path; *s && *s!=';'; s++, d++) *d = *s;