rev 652 - in trunk: . src

SVN User <[email protected]> Wed, 23 Jun 2004 01:31:54 -0400
Newsgroups gmane.comp.lang.prothon.cvs
Message-ID <[email protected]>
Author: mark
Date: 2004-06-23 01:31:51 -0400 (Wed, 23 Jun 2004)
New Revision: 652

Modified:
   trunk/STATUS.txt
   trunk/src/interp.c
   trunk/src/parser.h
   trunk/src/parser_routines.c
   trunk/src/prothon.y
Log:
Fixed raise keyword

Modified: trunk/STATUS.txt
===================================================================
--- trunk/STATUS.txt	2004-06-23 04:55:43 UTC (rev 651)
+++ trunk/STATUS.txt	2004-06-23 05:31:51 UTC (rev 652)
@@ -1,8 +1,6 @@
 
 ----------------------- TO-DO (highest priority first) ------------------------
 
---- finish live formal param defaults, bugs, and easy changes
-
 --- fix raise command
 --- change proto() to newObject() 
 --- *args should be a tuple

Modified: trunk/src/interp.c
===================================================================
--- trunk/src/interp.c	2004-06-23 04:55:43 UTC (rev 651)
+++ trunk/src/interp.c	2004-06-23 05:31:51 UTC (rev 652)
@@ -1524,9 +1524,18 @@
 			}	break;
 no_func_ptr2:	raise_exception(ist, OBJ(INTERNAL_EXC), "attempt to call an uninitialized function");
 				break;
-			case OP_RAISE:
-				ist->exception_obj = fr_pop;
-				break;
+			case OP_RAISE: {
+				obj_p param2  = fr_pop;
+				obj_p exc_obj = fr_pop;
+				if (param2 != OBJ(NONE)) {
+					int i;
+					exc_obj = new_object(ist, exc_obj);
+					su(i);
+					set_attr(ist, exc_obj, SYM(DOC_), call_func0(ist, param2, SYM(STR_)));
+					un_su(i);
+				}
+				ist->exception_obj = exc_obj;
+			}	break;
 			case OP_YIELD: {
 				frame_p fp;
 				for (fp=frame; fp && !(fp->gen_marker); fp=fp->prev_frame);

Modified: trunk/src/parser.h
===================================================================
--- trunk/src/parser.h	2004-06-23 04:55:43 UTC (rev 651)
+++ trunk/src/parser.h	2004-06-23 05:31:51 UTC (rev 652)
@@ -191,7 +191,7 @@
 code_p op_expr(int op, code_p expr, int size);
 code_p print_arglist(void* param, clist_p list);
 code_p push_null(void* param);
-code_p raise_expr(void* param, code_p expr);
+code_p raise_expr(void* param, code_p expr1,  code_p expr2);
 code_p ref_expr_to_ass_op(void* param, code_p ref, code_p rparm, int iop, int op);
 code_p ref_parm_body_to_def(void* param, code_p name, clist_p params, code_p self, code_p body, int flg) ;
 code_p return_expr(void* param, code_p expr);

Modified: trunk/src/parser_routines.c
===================================================================
--- trunk/src/parser_routines.c	2004-06-23 04:55:43 UTC (rev 651)
+++ trunk/src/parser_routines.c	2004-06-23 05:31:51 UTC (rev 652)
@@ -1458,6 +1458,27 @@
 	pr_assert(res->len == k);
 	return debug_retrn(__LINE__, res);
 }
+code_p raise_expr(void* param, code_p expr1,  code_p expr2) {
+	int k=0, len=0, stack_depth=0, max_stack_depth=0;
+	code_p res;
+	calc_code(expr1, &len, &stack_depth, &max_stack_depth);
+	if (expr2)
+		calc_code(expr2, &len, &stack_depth, &max_stack_depth);
+	else { len += 2; stack_depth += 1; }
+	res = new_code(param, len+1, stack_depth, max_stack_depth, 0);
+	add_code(expr1, res, &k);
+	if (expr2)
+		add_code(expr2, res, &k);
+	else {
+		res->code_data[k  ].bytecode.opcode = OP_PUSH;
+		res->code_data[k++].bytecode.param  = 2;
+		res->code_data[k++].data            = OBJ(NONE);
+	}
+	res->code_data[k++].bytecode.opcode = OP_RAISE;
+	res->stack_depth = 0;
+	pr_assert(res->len == k);
+	return debug_retrn(__LINE__, res);
+}
 code_p word_expr_to_param(void* param, obj_p word, code_p expr){
 	int k=0, len=2, stack_depth=1, max_stack_depth=1;
 	code_p res;
@@ -1660,9 +1681,6 @@
 code_p tgtparm_to_obj(void* param, code_p expr){
 	return debug_retrn(__LINE__, op_expr(OP_DEREF, expr, 1));
 }
-code_p raise_expr(void* param, code_p expr){
-	return debug_retrn(__LINE__, op_expr(OP_RAISE, expr, 1));
-}
 code_p del_ref(void* param, code_p expr){
 	return debug_retrn(__LINE__, op_expr(OP_DEL, expr, 2));
 }

Modified: trunk/src/prothon.y
===================================================================
--- trunk/src/prothon.y	2004-06-23 04:55:43 UTC (rev 651)
+++ trunk/src/prothon.y	2004-06-23 05:31:51 UTC (rev 652)
@@ -355,7 +355,8 @@
 		ASSERT expr ',' expr										{ $$ = cond_exc_to_assert(yylex_param, $2, $4); }
 	;
 raise_statement: 
-		RAISE expr													{ $$ = raise_expr(yylex_param, $2); }
+		RAISE expr													{ $$ = raise_expr(yylex_param, $2, NULL); }
+	|	RAISE expr ',' expr											{ $$ = raise_expr(yylex_param, $2, $4); }
 	; 
 return_statement: 
 		RETURN expr													{ $$ = return_expr(yylex_param, $2); }