rev 680 - in trunk: pr/test src

SVN User <[email protected]> Wed, 30 Jun 2004 02:57:03 -0400
Newsgroups gmane.comp.lang.prothon.cvs
Message-ID <[email protected]>
Author: mark
Date: 2004-06-30 02:57:00 -0400 (Wed, 30 Jun 2004)
New Revision: 680

Modified:
   trunk/pr/test/test.pr
   trunk/src/bytecodes.h
   trunk/src/interp.c
   trunk/src/main.c
   trunk/src/parser_routines.c
Log:
fixed assignment from tuple to arg list

Modified: trunk/pr/test/test.pr
===================================================================
--- trunk/pr/test/test.pr	2004-06-30 03:20:36 UTC (rev 679)
+++ trunk/pr/test/test.pr	2004-06-30 06:57:00 UTC (rev 680)
@@ -1,18 +1,15 @@
 #!/usr/bin/env prothon
 
-object k:
-	def init_(obj):
-		self.obj = obj
-		
-	def str_():
-		return '<k:'+self.obj.str_()+'>'
-		
-kk = [k(99)]
-print kk
+for i in 5:
+	print i
+	
+a, b = (1,2)
+print a,b
 
-x = []
-a = k(x)
-print a
-
-x +! [a,kk,a,kk,a,kk]
-print x
+gen g():
+	for i in 3:
+		y = (2*i, 3*i)
+		yield y
+	
+for a, b in g():
+	print a,b

Modified: trunk/src/bytecodes.h
===================================================================
--- trunk/src/bytecodes.h	2004-06-30 03:20:36 UTC (rev 679)
+++ trunk/src/bytecodes.h	2004-06-30 06:57:00 UTC (rev 680)
@@ -355,6 +355,7 @@
 
 // OP_SEQ_ASSIGN(sequence, symbol refs)
 // assign values in sequence on stack to local references on stack
+// each local reference is a single symbol object
 // if not a sequence treat as sequence of one object
 // sequence length must match param length or error
 // pop obj and references when done
@@ -364,6 +365,17 @@
 // |opcode|
 OP_SEQ_ASSIGN,
 
+// OP_SEQ_ASSIGN(sequence, attr refs)
+// assign values in sequence on stack to attr references on stack
+// if not a sequence treat as sequence of one object
+// sequence length must match param length or error
+// pop obj and references when done
+// used in exapanding assignment from sequence to arg list
+// stack: sequence-obj, attr-reference, attr-reference, ...  ->  <empty>
+// param: number of references
+// |opcode|
+OP_ASSIGN_EXP,
+
 // BR
 // branch relative param words in code unconditionally
 // PC += param

Modified: trunk/src/interp.c
===================================================================
--- trunk/src/interp.c	2004-06-30 03:20:36 UTC (rev 679)
+++ trunk/src/interp.c	2004-06-30 06:57:00 UTC (rev 680)
@@ -1039,10 +1039,37 @@
 				for(i=0; i < param; i++, sp1++, sp2+=2)
 					set_item(ist, fr_stack[sp2], fr_stack[sp2+1], fr_stack[sp1], TRUE);
 			}	break;
+			case OP_ASSIGN_EXP: {
+				obj_p list;
+				fr_sp -= param*2;
+				list=fr_tos;
+				if (has_proto(ist, list, OBJ(TUPLE_PROTO))){
+					if (list_len(ist, list) != param){
+						raise_exception(ist, OBJ(INTERPRETER_EXC), "right side sequence length doesn't match left side");
+						break;
+					}
+					for(i=0; i < param; i++) {
+						obj_p key = fr_stack[fr_sp+i*2+1];
+						if (has_proto(ist, key, OBJ(LOCAL_PROTO)))
+							key = key->data.ptr;
+						set_attr(ist, fr_stack[fr_sp+i*2], key, list_item(ist, list, i));
+					}
+				} else {
+					obj_p key;
+					if (param != 1){
+						raise_exception(ist, OBJ(INTERPRETER_EXC), "only one object on right side and multiple on left");
+						break;
+					}
+					key = fr_stack[fr_sp+1];
+					if (has_proto(ist, key, OBJ(LOCAL_PROTO)))
+						key = key->data.ptr;
+					set_attr(ist, fr_stack[fr_sp], key, fr_stack[fr_sp]);
+				}
+			}	break;
 			case OP_SEQ_ASSIGN: {
 				obj_p list;
 				fr_sp -= param+1;
-				if (has_proto(ist, list=fr_stack[fr_sp], OBJ(LIST_PROTO))){
+				if (has_proto(ist, list=fr_stack[fr_sp], OBJ(TUPLE_PROTO))){
 					if (list_len(ist, list) != param){
 						raise_exception(ist, OBJ(INTERPRETER_EXC), "For param list length doesn't match sequence length");
 						break;
@@ -1469,7 +1496,7 @@
 					gen_p genp = fr_stack[fr_sp]->data.ptr;
 					frame_p new_frame = genp->frame;
 					if (!new_frame) {
-						raise_exception(ist, OBJ(STOP_ITERATION_EXC), NULL);
+						raise_exception(ist, OBJ(TYPE_EXC), "iterator not initialized");
 						break;
 					}
 					new_frame->prev_frame = frame;
@@ -2275,6 +2302,8 @@
 		break;
 	case OP_ASSIGN: fprintf(fout,"%4d %20s(%4d) %s", pc, "OP_ASSIGN", param, codedata(str, code, op, param, pc));
 		break;
+	case OP_ASSIGN_EXP: fprintf(fout,"%4d %20s(%4d) %s", pc, "OP_ASSIGN_EXP", param, codedata(str, code, op, param, pc));
+		break;
 	case OP_SEQ_ASSIGN: fprintf(fout,"%4d %20s(%4d) %s", pc, "OP_SEQ_ASSIGN", param, codedata(str, code, op, param, pc));
 		break;
 	case OP_BR: fprintf(fout,"%4d %20s(%4d) %s", pc, "OP_BR", param, codedata(str, code, op, param, pc));

Modified: trunk/src/main.c
===================================================================
--- trunk/src/main.c	2004-06-30 03:20:36 UTC (rev 679)
+++ trunk/src/main.c	2004-06-30 06:57:00 UTC (rev 680)
@@ -228,5 +228,7 @@
 
 // common exit point for debug breakpoints
 void pr_exit(int n){
+
+
 	exit(n);
 }

Modified: trunk/src/parser_routines.c
===================================================================
--- trunk/src/parser_routines.c	2004-06-30 03:20:36 UTC (rev 679)
+++ trunk/src/parser_routines.c	2004-06-30 06:57:00 UTC (rev 680)
@@ -1565,7 +1565,7 @@
 	res->assign_parm_cnt = rlen;
 	for(i=0; i < llen; i++)
 		add_code(clist_item(left,i), res, &k);
-	res->code_data[k  ].bytecode.opcode = (seq_expand ? OP_SEQ_ASSIGN : OP_ASSIGN);
+	res->code_data[k  ].bytecode.opcode = (seq_expand ? OP_ASSIGN_EXP : OP_ASSIGN);
 	res->code_data[k++].bytecode.param  = llen;
 	res->stack_depth -= llen*2;
 	pr_assert(k==res->len);