rev 663 - trunk/src
SVN User <[email protected]> Fri, 25 Jun 2004 01:57:26 -0400
| Newsgroups | gmane.comp.lang.prothon.cvs |
|---|---|
| Message-ID | <[email protected]> |
Author: mark
Date: 2004-06-25 01:57:23 -0400 (Fri, 25 Jun 2004)
New Revision: 663
Modified:
trunk/src/bytecodes.h
trunk/src/interp.c
trunk/src/parser_routines.c
trunk/src/prothon.y
Log:
improved error reporting for invalid commands
Modified: trunk/src/bytecodes.h
===================================================================
--- trunk/src/bytecodes.h 2004-06-25 03:43:48 UTC (rev 662)
+++ trunk/src/bytecodes.h 2004-06-25 05:57:23 UTC (rev 663)
@@ -226,6 +226,19 @@
// |opcode|(char*) label|
OP_CONTINUE,
+// CMDCALL(func_obj, params)
+// (almost same as OP_OBJCALL)
+// call function as a command, with unbound function object, bind target, & params on stack
+// use locals container for self
+// params are in pairs of optional-label/value
+// pop all and leave result on stack
+// if bind-tgt is NULL, use current self as bind-tgt
+// symbol is provided for error message
+// stack: func-object,bind-tgt,label,value,label,value,... -> result
+// param: num param pairs on stack
+// |opcode|symbol|
+OP_CMDCALL,
+
/********/ OP_TWO_WORDS_BOUNDARY, /********/
// CLRSP
@@ -312,10 +325,6 @@
// |opcode|
OP_OBJCALL,
-// CMDCALL(func_obj, params)
-// same as objcall but for command version without parens only
-OP_CMDCALL,
-
// CALL(self, func, params)
// call function, with self-obj, func-symbol, bind target, & params on stack
// params are in pairs of optional-label/value
Modified: trunk/src/interp.c
===================================================================
--- trunk/src/interp.c 2004-06-25 03:43:48 UTC (rev 662)
+++ trunk/src/interp.c 2004-06-25 05:57:23 UTC (rev 663)
@@ -1204,7 +1204,8 @@
fr_sp -= 2+2*param;
func_obj = fr_stack[fr_sp];
if (cmd_flag && !get_attr(ist, func_obj, SYM(COMMAND_))) {
- raise_exception(ist, OBJ(INTERPRETER_EXC), "invalid command");
+ raise_exception( ist, OBJ(INTERPRETER_EXC), "invalid command: %s",
+ symch(ist, fr_data(1)) );
break;
}
if (func_obj->data_type == DATA_TYPE_EXTPTR) {
Modified: trunk/src/parser_routines.c
===================================================================
--- trunk/src/parser_routines.c 2004-06-25 03:43:48 UTC (rev 662)
+++ trunk/src/parser_routines.c 2004-06-25 05:57:23 UTC (rev 663)
@@ -530,17 +530,20 @@
calc_code(nul, &len, &stack_depth, &max_stack_depth);
for(i=0; i < llen; i++)
calc_code(clist_item(parms,i), &len, &stack_depth, &max_stack_depth);
- res = new_code(param, len+2, stack_depth, max_stack_depth, 0);
+ res = new_code(param, len+2+cmd_flag, stack_depth, max_stack_depth, 0);
add_code(attr_ref, res, &k);
res->code_data[k++].bytecode.opcode = OP_DEREF;
add_code(nul, res, &k);
for(i=0; i < llen; i++)
add_code(clist_item(parms,i), res, &k);
- if (cmd_flag = CMD_FLAG)
+ if (cmd_flag == 1) {
res->code_data[k ].bytecode.opcode = OP_CMDCALL;
- else
+ res->code_data[k++].bytecode.param = clist_len(parms);
+ res->code_data[k++].data = attr_ref->code_data[1].data;
+ } else {
res->code_data[k ].bytecode.opcode = OP_OBJCALL;
- res->code_data[k++].bytecode.param = clist_len(parms);
+ res->code_data[k++].bytecode.param = clist_len(parms);
+ }
res->stack_depth -= 2+(2*llen);
pr_assert(k==res->len);
return debug_retrn(__LINE__, res);
Modified: trunk/src/prothon.y
===================================================================
--- trunk/src/prothon.y 2004-06-25 03:43:48 UTC (rev 662)
+++ trunk/src/prothon.y 2004-06-25 05:57:23 UTC (rev 663)
@@ -283,9 +283,6 @@
yield_statement | command_statement | expr
PASS { $$ = none(yylex_param); }
;
-command_statement:
- LABEL func_params { $$ = unbound_func_params(yylex_param, label_to_attrref(yylex_param, $1), $2, CMD_FLAG); }
- ;
if_statement:
if_lc_clause compound_body mul_elif else { $$ = if_expr_body_elif_else(yylex_param, $1, $2, $3, $4); }
;
@@ -654,6 +651,9 @@
expr { $$ = new_list(yylex_param, $1); }
| list_params2 ',' expr { $$ = append_list(yylex_param, $1, $3); }
;
+command_statement:
+ LABEL func_params { $$ = unbound_func_params(yylex_param, label_to_attrref(yylex_param, $1), $2, CMD_FLAG); }
+ ;
%%
// **************************************************************************************************