rev 225 - in trunk: . modules/Tuple src
SVN User <[email protected]>
| Newsgroups | gmane.comp.lang.prothon.cvs |
|---|---|
| Message-ID | <[email protected]> |
Author: mark
Date: 2004-03-31 02:44:50 -0500 (Wed, 31 Mar 2004)
New Revision: 225
Modified:
trunk/STATUS.txt
trunk/modules/Tuple/Tuple.c
trunk/src/builtins.c
trunk/src/parser_routines.c
Log:
added cmp of lists and tuples
Modified: trunk/STATUS.txt
===================================================================
--- trunk/STATUS.txt 2004-03-31 06:14:45 UTC (rev 224)
+++ trunk/STATUS.txt 2004-03-31 07:44:50 UTC (rev 225)
@@ -31,14 +31,18 @@
add/replace int and float single decimal type with bounded precision and floating point.
http://www.python.org/peps/pep-0327.html
-Full unicode support like Java
+Full unicode support like Java -- store compressed ucs4 ?
Syntax extension modifier -- language spec?
make := work like = but usable as an expr
+sets and other zephyr email items -- use <> ?
+
----------------------- TO-DO (highest priority first) ------------------------
+--- smarter continuation - remove \
+
--- make print a function
--- write and publish prothon directives
@@ -50,7 +54,7 @@
--- memory bounds -> mem-mgr priorities
--- -i interactive console needs globals and locals from main1 module
---- flesh out dlls, list.sort!(), dict stuff, string %, built-in funcs
+--- flesh out dlls, list.sort!(), dict stuff, string %
--- higher level pseudo classes, bases, meta-class replacements etc. (oops.pr)
@@ -76,7 +80,6 @@
--- thread monitor function
---- convert all to apr_snprintf()
------------------------------ bugs -------------------------------------------
parser
Modified: trunk/modules/Tuple/Tuple.c
===================================================================
--- trunk/modules/Tuple/Tuple.c 2004-03-31 06:14:45 UTC (rev 224)
+++ trunk/modules/Tuple/Tuple.c 2004-03-31 07:44:50 UTC (rev 225)
@@ -61,11 +61,54 @@
MODULE_DECLARE(Tgen);
MODULE_DECLARE(Tuple);
+//******************************** TUPLE OBJECT *******************************
MODULE_START(Tuple)
{
Tuple_OBJ = OBJ(TUPLE_PROTO);
}
+DEF(Tuple, cmp, FORM_RPARAM) {
+ int i, llen, tlen, mlen;
+ obj_p res;
+ obj_p self_item, tgt_item, tgt_list;
+ if (!has_proto_QUES(ist, parms[1], OBJ(SEQ_PROTO))) {
+ raise_exception(ist, OBJ(TYPE_EXC), "sequence can only be compared to a sequence");
+ return NULL;
+ }
+ llen = list_len(ist, self);
+ tgt_list = parms[1];
+ tlen = list_len(ist, tgt_list);
+ mlen = min(llen, tlen);
+ for(i=0; i < mlen; i++) {
+ self_item = list_item(ist, self, i);
+ tgt_item = list_item(ist, tgt_list, i);
+ res = call_func1(ist, self_item, SYM(CMP), tgt_item); if_exc_return NULL;
+ if (res->data.i64)
+ return new_int_obj(res->data.i64);
+ }
+ if (llen < tlen) return new_int_obj(-1);
+ if (llen > tlen) return new_int_obj(+1);
+ return OBJ(ZERO_INT);
+}
+
+DEF(Tuple, __eq__QUES, FORM_RPARAM) {
+ int i, llen, tlen;
+ obj_p self_item, tgt_item, tgt_list, false_obj = OBJ(PR_FALSE);
+ if (!has_proto_QUES(ist, parms[1], OBJ(SEQ_PROTO))) return false_obj;
+ llen = list_len(ist, self);
+ tgt_list = parms[1];
+ tlen = list_len(ist, tgt_list);
+ if (llen != tlen) return false_obj;
+ for(i=0; i < llen; i++) {
+ self_item = list_item(ist, self, i);
+ tgt_item = list_item(ist, tgt_list, i);
+ if (call_func1(ist, self_item, SYM(__EQ__QUES), tgt_item) == false_obj)
+ return false_obj;
+ else if_exc_return NULL;
+ }
+ return OBJ(PR_TRUE);
+}
+
DEF(Tuple, __rin__QUES, FORM_RPARAM) {
int i, llen = list_len(ist, self);
obj_p item, tgt = parms[1];
@@ -197,6 +240,7 @@
MODULE_END(Tuple);
+//*************************** TUPLE GENERATOR OBJECT **************************
MODULE_START(Tgen)
{
Tgen_OBJ = new_object(NULL);
@@ -217,6 +261,7 @@
MODULE_END(Tgen);
+//********************************* INITIALIZATION ****************************
MAIN_MODULE_INIT(Tuple)
{
MODULE_SUB_INIT(Tuple);
Modified: trunk/src/builtins.c
===================================================================
--- trunk/src/builtins.c 2004-03-31 06:14:45 UTC (rev 224)
+++ trunk/src/builtins.c 2004-03-31 07:44:50 UTC (rev 225)
@@ -1290,7 +1290,7 @@
OBJ(MODULES) = new_object(NULL);
OBJ(PR_FALSE) = new_object(NULL);
OBJ(PR_TRUE) = new_object(NULL);
- OBJ(NONE) = new_object(NULL);
+ OBJ(NONE) = new_object(NULL);
OBJ(EXCEPTION) = new_object(NULL);
OBJ(GEN_PROTO) = new_object(NULL);
OBJ(INT_PROTO) = new_object(NULL);
Modified: trunk/src/parser_routines.c
===================================================================
--- trunk/src/parser_routines.c 2004-03-31 06:14:45 UTC (rev 224)
+++ trunk/src/parser_routines.c 2004-03-31 07:44:50 UTC (rev 225)
@@ -974,7 +974,7 @@
return debug_retrn(__LINE__, res);
}
code* new_tuple_list(void* param, clist_p lst, int tuple_flag){
- int i, k=0, len=1, stack_depth=1, max_stack_depth=0;
+ int i, k=0, len=1, stack_depth=1, max_stack_depth=1;
code* res;
for(i=0; i < clist_len(lst); i++)
calc_code((code*)clist_item(lst,i), &len, &stack_depth, &max_stack_depth);