rev 222 - in trunk: . include/prothon modules/File modules/List modules/String modules/Tuple src
SVN User <[email protected]>
| Newsgroups | gmane.comp.lang.prothon.cvs |
|---|---|
| Message-ID | <[email protected]> |
Author: mark
Date: 2004-03-30 21:03:35 -0500 (Tue, 30 Mar 2004)
New Revision: 222
Modified:
trunk/STATUS.txt
trunk/include/prothon/prothon.h
trunk/modules/File/File.c
trunk/modules/List/List.c
trunk/modules/String/String.c
trunk/modules/Tuple/Tuple.c
trunk/src/builtins.c
trunk/src/interp.c
trunk/src/object.c
trunk/src/parser_routines.c
Log:
added generators for tuples and lists so you can now
do for i in [1,2,3] and for i in (1,2,3)
Modified: trunk/STATUS.txt
===================================================================
--- trunk/STATUS.txt 2004-03-30 23:51:20 UTC (rev 221)
+++ trunk/STATUS.txt 2004-03-31 02:03:35 UTC (rev 222)
@@ -35,16 +35,16 @@
Syntax extension modifier -- language spec?
+make := work like = but usable as an expr
+
----------------------- TO-DO (highest priority first) ------------------------
--- implement new space/tab indent scheme
--- add var? form to lexer
---- fix bugs from bugzilla
+--- make print a function
---- make print a function, support stdin, out, & err
-
--- write and publish prothon directives
--- credit Ruby
Modified: trunk/include/prothon/prothon.h
===================================================================
--- trunk/include/prothon/prothon.h 2004-03-30 23:51:20 UTC (rev 221)
+++ trunk/include/prothon/prothon.h 2004-03-31 02:03:35 UTC (rev 222)
@@ -252,7 +252,7 @@
IOEXCEPTION, //
FUNCNOTFOUND_EXC, //
FILENOTFOUND_EXC, //
- END_OF_GEN_EXC, //
+ STOP_ITERATION_EXC, //
LOCK_EXC, //
// constants
Modified: trunk/modules/File/File.c
===================================================================
--- trunk/modules/File/File.c 2004-03-30 23:51:20 UTC (rev 221)
+++ trunk/modules/File/File.c 2004-03-31 02:03:35 UTC (rev 222)
@@ -716,7 +716,7 @@
obj_p file_obj;
MODULE_SUB_INIT(File, NO_PROTO, 1);
- MODULE_SUB_INIT(Dir, NO_PROTO, 0);
+ MODULE_SUB_INIT(Dir, NO_PROTO, 0);
/* Create base file objects for std{in,out,err} */
aprerr = apr_pool_create(&std_pool, get_pr_head_pool());
Modified: trunk/modules/List/List.c
===================================================================
--- trunk/modules/List/List.c 2004-03-30 23:51:20 UTC (rev 221)
+++ trunk/modules/List/List.c 2004-03-31 02:03:35 UTC (rev 222)
@@ -238,6 +238,7 @@
MODULE_END(List);
+
MAIN_MODULE_INIT(List)
{
MODULE_SUB_INIT(List, LIST_PROTO, 0);
Modified: trunk/modules/String/String.c
===================================================================
--- trunk/modules/String/String.c 2004-03-30 23:51:20 UTC (rev 221)
+++ trunk/modules/String/String.c 2004-03-31 02:03:35 UTC (rev 222)
@@ -232,7 +232,7 @@
res_str[0] = ch;
res_str[1] = 0;
} else
- raise_exception(ist, OBJ(END_OF_GEN_EXC), NULL);
+ raise_exception(ist, OBJ(STOP_ITERATION_EXC), NULL);
write_unlock(ist, self);
return res;
}
Modified: trunk/modules/Tuple/Tuple.c
===================================================================
--- trunk/modules/Tuple/Tuple.c 2004-03-30 23:51:20 UTC (rev 221)
+++ trunk/modules/Tuple/Tuple.c 2004-03-31 02:03:35 UTC (rev 222)
@@ -58,6 +58,7 @@
#include <stdio.h>
#include <string.h>
+MODULE_DECLARE(Tgen);
MODULE_DECLARE(Tuple);
MODULE_START(Tuple);
@@ -183,9 +184,35 @@
return NULL;
}
+DEF(Tuple, __gen__, NULL) {
+ obj_p list_obj, gen_obj = new_object(Tgen_OBJ);
+ gen_obj->data_type = OBJ_TYPE_DATAPTR;
+ gen_obj->data.ptr = list_obj = clone_list_obj(ist, self);
+ listlen(list_obj) = 0;
+ return gen_obj;
+}
+
MODULE_END(Tuple);
+MODULE_START(Tgen);
+
+DEF(Tgen, next, NULL) {
+ obj_p res, list_obj = self->data.ptr;
+ size_t lsiz = listsize(list_obj);
+ size_t llen = listlen(list_obj);
+ if (llen == lsiz) {
+ raise_exception(ist, OBJ(STOP_ITERATION_EXC), NULL);
+ return NULL;
+ }
+ res = listitem(list_obj, llen);
+ listlen(list_obj)++;
+ return res;
+}
+
+MODULE_END(Tgen);
+
MAIN_MODULE_INIT(Tuple)
{
+ MODULE_SUB_INIT(Tgen, NO_PROTO, 1);
MODULE_SUB_INIT(Tuple, TUPLE_PROTO, 0);
}
Modified: trunk/src/builtins.c
===================================================================
--- trunk/src/builtins.c 2004-03-30 23:51:20 UTC (rev 221)
+++ trunk/src/builtins.c 2004-03-31 02:03:35 UTC (rev 222)
@@ -707,7 +707,7 @@
del_attr(ist, self, SYM_LIMIT);
read_lock(ist, self);
}
- raise_exception(ist, OBJ(END_OF_GEN_EXC), NULL);
+ raise_exception(ist, OBJ(STOP_ITERATION_EXC), NULL);
return NULL;
}
res = new_int_obj(Int_value(self));
Modified: trunk/src/interp.c
===================================================================
--- trunk/src/interp.c 2004-03-30 23:51:20 UTC (rev 221)
+++ trunk/src/interp.c 2004-03-31 02:03:35 UTC (rev 222)
@@ -513,7 +513,7 @@
} else
*switch_frame = DONE_FRAME_FLAG;
if (fr_gen)
- raise_exception(ist, OBJ(END_OF_GEN_EXC), NULL);
+ raise_exception(ist, OBJ(STOP_ITERATION_EXC), NULL);
else
*free_frame = frame;
if (!res) res = return_value;
@@ -904,7 +904,7 @@
if (fr_stack[fr_sp+1] == SYM(NEXT) && has_proto(ist, fr_stack[fr_sp], OBJ(GEN_PROTO))) {
exec_frame_t* new_frame=(exec_frame_t*)(fr_stack[fr_sp]->data.ptr);
if (!new_frame) {
- raise_exception(ist, OBJ(END_OF_GEN_EXC), NULL);
+ raise_exception(ist, OBJ(STOP_ITERATION_EXC), NULL);
break;
}
new_frame->prev_frame = frame;
Modified: trunk/src/object.c
===================================================================
--- trunk/src/object.c 2004-03-30 23:51:20 UTC (rev 221)
+++ trunk/src/object.c 2004-03-31 02:03:35 UTC (rev 222)
@@ -171,7 +171,7 @@
OBJ(OUTOFMEMORY_EXC) = new_object(OBJ(EXCEPTION));
OBJ(IOEXCEPTION) = new_object(OBJ(EXCEPTION));
OBJ(FILENOTFOUND_EXC) = new_object(OBJ(IOEXCEPTION));
- OBJ(END_OF_GEN_EXC) = new_object(OBJ(EXCEPTION));
+ OBJ(STOP_ITERATION_EXC) = new_object(OBJ(EXCEPTION));
OBJ(LOCK_EXC) = new_object(OBJ(EXCEPTION));
OBJ(ZERO_INT) = new_int_obj(0);
@@ -215,7 +215,7 @@
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(END_OF_GEN_EXC), "End Of Generated Sequence (not an error)");
+ add_doc_to_obj(ist, OBJ(STOP_ITERATION_EXC), "StopIteration Exception (not an error)");
add_doc_to_obj(ist, OBJ(LOCK_EXC), "Locking Error");
add_doc_to_obj(ist, OBJ(ROOT_GLOBALS), "Root_Globals: recursive container of all objects");
Modified: trunk/src/parser_routines.c
===================================================================
--- trunk/src/parser_routines.c 2004-03-30 23:51:20 UTC (rev 221)
+++ trunk/src/parser_routines.c 2004-03-31 02:03:35 UTC (rev 222)
@@ -730,7 +730,7 @@
assert(els_loc == k);
res->code_data[k ].bytecode.opcode = OP_PUSH;
res->code_data[k++].bytecode.param = 3;
- res->code_data[k++].data = OBJ(END_OF_GEN_EXC);
+ res->code_data[k++].data = OBJ(STOP_ITERATION_EXC);
res->code_data[k++].data = NULL;
res->code_data[k ].bytecode.opcode = OP_EXCEPT;
res->code_data[k ].bytecode.param = end_els_loc - k;