rev 544 - in trunk: . include/prothon modules/Prosist pr/test src
SVN User <[email protected]> Mon, 24 May 2004 19:24:15 -0400
| Newsgroups | gmane.comp.lang.prothon.cvs |
|---|---|
| Message-ID | <[email protected]> |
Author: mark
Date: 2004-05-24 19:24:12 -0400 (Mon, 24 May 2004)
New Revision: 544
Added:
trunk/pr/test/plist.pr
trunk/pr/test/supercall.pr
Modified:
trunk/STATUS.txt
trunk/include/prothon/prothon.h
trunk/include/prothon/prothon_dll.h
trunk/modules/Prosist/Prosist.c
trunk/pr/test/test.pr
trunk/src/builtins-attrdict.c
trunk/src/builtins-core.c
trunk/src/interp.c
trunk/src/object.c
trunk/src/object.h
trunk/src/src.vcproj
Log:
attrs_ and protos_ are finished
Modified: trunk/STATUS.txt
===================================================================
--- trunk/STATUS.txt 2004-05-24 21:23:55 UTC (rev 543)
+++ trunk/STATUS.txt 2004-05-24 23:24:12 UTC (rev 544)
@@ -1,12 +1,12 @@
----------------------- TO-DO (highest priority first) ------------------------
+--- resolve binary vs. strings vs. unicode
+
--- allow strings to compare with symbols
--- Add properties methods: get_, set_, delete_, rename protoChain
---- Add attrs_ & protos_ functionality.
-
--- Auto-documenter app
--- networking code -- web access demonstration of security
Modified: trunk/include/prothon/prothon.h
===================================================================
--- trunk/include/prothon/prothon.h 2004-05-24 21:23:55 UTC (rev 543)
+++ trunk/include/prothon/prothon.h 2004-05-24 23:24:12 UTC (rev 544)
@@ -17,7 +17,7 @@
* HCA's notice of copyright, i.e., "Copyright (c) 2004 Hahn Creative
* Applications; All Rights Reserved" are retained in Prothon alone or
* in any derivative version prepared by Licensee.
- *
+ *
* 3. In the event Licensee prepares a derivative work that is based on or
* incorporates Prothon or any part thereof, and wants to make the
* derivative work available to others as provided herein, then Licensee
@@ -554,12 +554,11 @@
obj_p attr_value_by_key(isp ist, obj_p obj, attr_key_t key);
obj_p key_to_sym(isp ist, attr_key_t key);
-// INS_PROTO: Insert an object in the list of proto objects.
+// ADD_PROTO: Append an object to the list of proto objects.
// This is the immediate protos for an object, not the reachable.
-// Pos == 0 means head of list and pos >= len means append at end.
// Duplicates will be ignored. TRUE will be returned if the proto
-// was inserted, FALSE if not.
-int ins_proto(isp ist, obj_p obj, obj_p proto, int pos);
+// was appended, FALSE if not.
+int add_proto(isp ist, obj_p obj, obj_p proto);
// DEL_PROTO: Delete an object from the list of proto objects.
// This is from the immediate proto list for an object, not the reachable.
Modified: trunk/include/prothon/prothon_dll.h
===================================================================
--- trunk/include/prothon/prothon_dll.h 2004-05-24 21:23:55 UTC (rev 543)
+++ trunk/include/prothon/prothon_dll.h 2004-05-24 23:24:12 UTC (rev 544)
@@ -70,7 +70,7 @@
obj_p (*get_attr)(isp ist, obj_p obj, obj_p key);
void (*set_attr)(isp ist, obj_p object, obj_p key, obj_p value);
int (*del_attr)(isp ist, obj_p obj, obj_p key);
- int (*ins_proto)(isp ist, obj_p obj, obj_p proto, int pos);
+ int (*add_proto)(isp ist, obj_p obj, obj_p proto);
int (*del_proto)(isp ist, obj_p obj, obj_p proto);
int (*has_proto)(isp ist, obj_p obj, obj_p obj_proto);
void (*switch_proto)(isp ist, obj_p obj, obj_p new_proto);
@@ -270,9 +270,9 @@
#define get_attr (*services->get_attr)
#define set_attr (*services->set_attr)
#define del_attr (*services->del_attr)
-#define ins_proto (*services->ins_proto)
+#define add_proto (*services->add_proto)
#define del_proto (*services->del_proto)
-#define has_proto (*services->has_proto)
+#define has_proto (*services->has_proto)
#define switch_proto (*services->switch_proto)
#define list_append (*services->list_append)
#define list_item (*services->list_item)
Modified: trunk/modules/Prosist/Prosist.c
===================================================================
--- trunk/modules/Prosist/Prosist.c 2004-05-24 21:23:55 UTC (rev 543)
+++ trunk/modules/Prosist/Prosist.c 2004-05-24 23:24:12 UTC (rev 544)
@@ -588,7 +588,7 @@
if (first_proto)
switch_proto(ist, obj, proto);
else
- ins_proto(ist, obj, proto, 0x7fffffff);
+ add_proto(ist, obj, proto);
first_proto = FALSE;
}
break;
Added: trunk/pr/test/plist.pr
===================================================================
--- trunk/pr/test/plist.pr 2004-05-24 21:23:55 UTC (rev 543)
+++ trunk/pr/test/plist.pr 2004-05-24 23:24:12 UTC (rev 544)
@@ -0,0 +1,42 @@
+#!/usr/bin/env prothon
+
+def err(n):
+ print "failure number",n
+ Sys.exit(1)
+
+x = Object()
+x2 = x()
+x3 = x2()
+x4 = x3()
+object x5(x4,x3,x2,x): pass
+
+if Len(x5.protos_) != 4: err(-1)
+if x5.protos_[0] is not x4: err(0)
+if x5.protos_[1] is not x3: err(1)
+if x5.protos_[2] is not x2: err(2)
+if x5.protos_[3] is not x: err(3)
+
+y = Object()
+a=1
+b=2
+c=3
+y.protos_ = [a,b,c]
+if Len(y.protos_) != 3: err(4)
+if y.protos_[0] is not a: err(5)
+if y.protos_[1] is not b: err(6)
+if y.protos_[2] is not c: err(7)
+
+del y.protos_[1]
+if y.protos_ != [1,3]: err(8)
+if 1 not in y.protos_: err(9)
+if 3 not in y.protos_: err(10)
+y.protos_.insert!(1,2)
+if y.protos_ != [1,2,3]: err(11)
+y.protos_.append!(4)
+if y.protos_ != [1,2,3,4]: err(12)
+y.protos_.remove!(1)
+if y.protos_ != [2,3,4]: err(13)
+
+print """
+all tests passed
+"""
Added: trunk/pr/test/supercall.pr
===================================================================
--- trunk/pr/test/supercall.pr 2004-05-24 21:23:55 UTC (rev 543)
+++ trunk/pr/test/supercall.pr 2004-05-24 23:24:12 UTC (rev 544)
@@ -0,0 +1,16 @@
+#!/usr/bin/env prothon
+
+object X:
+ def call_():
+ if self.call_ is super.call_:
+ print "Error: self.call_ is super.call_"
+ Sys.exit(1)
+ return super.call_()
+
+Y = X()
+X()
+Y()
+
+print """
+test passed
+"""
Modified: trunk/pr/test/test.pr
===================================================================
--- trunk/pr/test/test.pr 2004-05-24 21:23:55 UTC (rev 543)
+++ trunk/pr/test/test.pr 2004-05-24 23:24:12 UTC (rev 544)
@@ -1,16 +1,6 @@
#!/usr/bin/env prothon
-object X:
- def call_():
- if self.call_ is super.call_:
- print "Error: self.call_ is super.call_"
- Sys.exit(1)
- return super.call_()
-
-Y = X()
-X()
-Y()
-
-print """
-test passed
-"""
+y = Object()
+y.protos_ = [1,3]
+print y.protos_
+print y.protos_ == [1,3]
\ No newline at end of file
Modified: trunk/src/builtins-attrdict.c
===================================================================
--- trunk/src/builtins-attrdict.c 2004-05-24 21:23:55 UTC (rev 543)
+++ trunk/src/builtins-attrdict.c 2004-05-24 23:24:12 UTC (rev 544)
@@ -99,8 +99,8 @@
return dict_obj;
}
-// ***************************** dict2attr ************************************
-void dict2attr(isp ist, obj_p dict, obj_p obj) {
+// ***************************** dict2attrs ************************************
+void dict2attrs(isp ist, obj_p dict, obj_p obj) {
obj_p dict_list = dict_keys_values(ist, dict, 2 /*list*/);
int i, llen = (int) list_len(ist, dict_list);
if_exc_return;
@@ -196,11 +196,6 @@
return res;
}
-DEF(AttrDict, objList_, FORM_RPARAM) {
- BIN_CONTENT_CHK(AttrDict);
- return parms[1];
-}
-
DEF(AttrDict, getItem_, FORM_RPARAM) {
obj_p res, index;
BIN_CONTENT_CHK(AttrDict);
@@ -301,6 +296,11 @@
return self;
}
+DEF(AttrDict, objList_, FORM_RPARAM) {
+ BIN_CONTENT_CHK(AttrDict);
+ return parms[1];
+}
+
MAIN_MODULE_INIT(AttrDict)
{
MODULE_SUB_INIT(AttrDict);
Modified: trunk/src/builtins-core.c
===================================================================
--- trunk/src/builtins-core.c 2004-05-24 21:23:55 UTC (rev 543)
+++ trunk/src/builtins-core.c 2004-05-24 23:24:12 UTC (rev 544)
@@ -134,7 +134,7 @@
}
new_obj = new_object(ist, list_item(ist, parms[1], 0));
for(i=1; i < llen; i++)
- ins_proto(ist, new_obj, list_item(ist, parms[1], i), 0x7fffffff);
+ add_proto(ist, new_obj, list_item(ist, parms[1], i));
return new_obj;
}
@@ -185,7 +185,7 @@
read_unlock(ist, self);
if((m = is_immutable(self)))
clr_immutable(self);
- ins_proto(ist, self, parms[1], 1000);
+ add_proto(ist, self, parms[1]);
if (m) set_immutable(self);
read_lock(ist, self);
return NULL;
Modified: trunk/src/interp.c
===================================================================
--- trunk/src/interp.c 2004-05-24 21:23:55 UTC (rev 543)
+++ trunk/src/interp.c 2004-05-24 23:24:12 UTC (rev 544)
@@ -247,7 +247,13 @@
raise_exception(ist, OBJ(TYPE_EXC), "attempt to replace attrs_ with non-dictionary");
return;
}
- dict2attr(ist, value, ref_self);
+ dict2attrs(ist, value, ref_self);
+ } else if (ref_key == SYM(PROTOS_)) {
+ if (!has_proto(ist, value, OBJ(LIST_PROTO))) {
+ raise_exception(ist, OBJ(TYPE_EXC), "attempt to replace protos_ with non-list");
+ return;
+ }
+ list2protos(ist, value, ref_self);
} else if (has_proto(ist, ref_key, OBJ(SYMBOL_PROTO))) {
if_exc_return;
set_attr(ist, ref_self, ref_key, value);
@@ -297,6 +303,9 @@
if (ref_key == SYM(ATTRS_)) {
raise_exception(ist, OBJ(TYPE_EXC), "attempt to del attrs_");
return;
+ } else if (ref_key == SYM(PROTOS_)) {
+ raise_exception(ist, OBJ(TYPE_EXC), "attempt to del protos_");
+ return;
} else if (has_proto(ist, ref_key, OBJ(SYMBOL_PROTO))) {
if_exc_return;
del_attr(ist, ref_self, ref_key);
@@ -946,6 +955,8 @@
key = fr_stack[fr_sp+1];
if (key == SYM(ATTRS_))
fr_push(new_attrdict_obj(ist, obj));
+ else if (key == SYM(PROTOS_))
+ fr_push(new_protolist_obj(ist, obj));
else {
att = get_item(ist, obj, key); IF_EXC_BREAK;
if (!att) {
@@ -1241,7 +1252,7 @@
raise_exception(ist, OBJ(NAME_EXC), "prototype %s not found", as_str(ist, psym));
goto end_op_obj;
}
- ins_proto(ist, new_obj, proto, 0x7fffffff);
+ add_proto(ist, new_obj, proto);
if (ist->exception_obj) goto end_op_obj;
}
key = fr_stack[fr_sp+1];
Modified: trunk/src/object.c
===================================================================
--- trunk/src/object.c 2004-05-24 21:23:55 UTC (rev 543)
+++ trunk/src/object.c 2004-05-24 23:24:12 UTC (rev 544)
@@ -127,9 +127,9 @@
dll_services.get_attr = get_attr;
dll_services.set_attr = set_attr;
dll_services.del_attr = del_attr;
- dll_services.ins_proto = ins_proto;
+ dll_services.add_proto = add_proto;
dll_services.del_proto = del_proto;
- dll_services.has_proto = has_proto;
+ dll_services.has_proto = has_proto;
dll_services.switch_proto = switch_proto;
dll_services.list_append = list_append;
dll_services.list_item = list_item;
@@ -245,6 +245,7 @@
BUILTIN_LOAD(Float);
BUILTIN_LOAD(Int);
BUILTIN_LOAD(List);
+ BUILTIN_LOAD(ProtoList);
BUILTIN_LOAD(String);
BUILTIN_LOAD(Thread);
BUILTIN_LOAD(Tuple);
@@ -694,8 +695,8 @@
return;
}
-//********************************* ins_proto **********************************
-int ins_proto(isp ist, obj_p obj, obj_p proto, int pos){
+//********************************* add_proto **********************************
+int add_proto(isp ist, obj_p obj, obj_p proto){
attr_p attrs;
i32_t i, len;
wrlock_rtrn(obj) FALSE;
@@ -711,14 +712,7 @@
attrs = attrs_realloc(obj, attrs);
len = attr_plen(attrs);
}
- if (pos >= len) {
- attr_proto_item(attrs, attr_plen(attrs)++) = proto;
- write_unlock(ist, obj);
- return TRUE;
- } else if (pos < 0) pos = 0;
- memmove(attr_pp(attrs,pos+1),attr_pp(attrs,pos),(len-pos)*sizeof(attr_t));
- attr_proto_item(attrs, pos) = proto;
- attr_plen(attrs)++;
+ attr_proto_item(attrs, attr_plen(attrs)++) = proto;
write_unlock(ist, obj);
return TRUE;
}
Modified: trunk/src/object.h
===================================================================
--- trunk/src/object.h 2004-05-24 21:23:55 UTC (rev 543)
+++ trunk/src/object.h 2004-05-24 23:24:12 UTC (rev 544)
@@ -138,10 +138,14 @@
void set_item(isp ist, obj_p ref_self, obj_p ref_key, obj_p value);
void del_item(isp ist, obj_p ref_self, obj_p ref_key);
+obj_p new_protolist_obj(isp ist, obj_p obj);
obj_p new_attrdict_obj(isp ist, obj_p obj);
obj_p new_float_obj(isp ist, double num);
obj_p new_hash_obj(isp ist, i32_t num);
-void dict2attr(isp ist, obj_p dict, obj_p obj);
+
+void dict2attrs(isp ist, obj_p dict, obj_p obj);
+void list2protos(isp ist, obj_p list, obj_p obj);
+
attr_p add_attrs(obj_p obj);
char* numonly(char* s, char* buf);
Modified: trunk/src/src.vcproj
===================================================================
--- trunk/src/src.vcproj 2004-05-24 21:23:55 UTC (rev 543)
+++ trunk/src/src.vcproj 2004-05-24 23:24:12 UTC (rev 544)
@@ -152,6 +152,9 @@
RelativePath=".\builtins-list.c">
</File>
<File
+ RelativePath=".\builtins-protolist.c">
+ </File>
+ <File
RelativePath=".\builtins-string.c">
</File>
<File