rev 662 - in trunk: . include/prothon src
SVN User <[email protected]> Thu, 24 Jun 2004 23:43:51 -0400
| Newsgroups | gmane.comp.lang.prothon.cvs |
|---|---|
| Message-ID | <[email protected]> |
Author: mark
Date: 2004-06-24 23:43:48 -0400 (Thu, 24 Jun 2004)
New Revision: 662
Modified:
trunk/STATUS.txt
trunk/include/prothon/prothon.h
trunk/include/prothon/prothon_dll.h
trunk/src/builtins-core.c
trunk/src/bytecodes.h
trunk/src/interp.c
trunk/src/parser.h
trunk/src/parser_routines.c
trunk/src/prothon.y
trunk/src/symbol.c
Log:
added function-as-command feature, print is now command
Modified: trunk/STATUS.txt
===================================================================
--- trunk/STATUS.txt 2004-06-25 02:12:32 UTC (rev 661)
+++ trunk/STATUS.txt 2004-06-25 03:43:48 UTC (rev 662)
@@ -1,6 +1,8 @@
----------------------- TO-DO (highest priority first) ------------------------
+--- function-as-command
+
--- OSThread, Thread, and Gate
--- lock keyword?
Modified: trunk/include/prothon/prothon.h
===================================================================
--- trunk/include/prothon/prothon.h 2004-06-25 02:12:32 UTC (rev 661)
+++ trunk/include/prothon/prothon.h 2004-06-25 03:43:48 UTC (rev 662)
@@ -471,6 +471,7 @@
NAME_,
ATTRS_,
PROTOS_,
+ COMMAND_,
SYM_ENUM_COUNT
} sym_enum_t;
Modified: trunk/include/prothon/prothon_dll.h
===================================================================
--- trunk/include/prothon/prothon_dll.h 2004-06-25 02:12:32 UTC (rev 661)
+++ trunk/include/prothon/prothon_dll.h 2004-06-25 03:43:48 UTC (rev 662)
@@ -171,20 +171,21 @@
#define MODULE_DECLARE(name) \
static isp ist; \
static pr_services_t *services; \
-static obj_p name##_OBJ;
+static obj_p name##_OBJ; \
+static obj_p _ncfo_;
/* Should be used to initialize the name##_OBJ */
#define MODULE_START(name) \
static void name##_initialize_module(void)
-#define DEF(slf, func, fparam_list) \
-static obj_p slf##func(isp ist, obj_p self, int pcnt, \
- obj_p* parms, obj_p dlocals); \
-static void slf##func##init(void) { \
- set_attr(ist, slf##_OBJ, sym(ist, #func), \
- new_C_func_obj(ist, slf##func, fparam_list)); \
-} \
-static obj_p slf##func(isp ist, obj_p self, int pcnt, \
+#define DEF(slf, func, fparam_list) \
+static obj_p slf##func(isp ist, obj_p self, int pcnt, \
+ obj_p* parms, obj_p dlocals); \
+static void slf##func##init(void) { \
+ set_attr(ist, slf##_OBJ, sym(ist, #func), \
+ _ncfo_ = new_C_func_obj(ist, slf##func, fparam_list)); \
+} \
+static obj_p slf##func(isp ist, obj_p self, int pcnt, \
obj_p* parms, obj_p dlocals)
#define BIN_EMPTY_CHK() \
@@ -276,6 +277,7 @@
name##__sym##init(); \
check_exceptions(ist);
+#define MARK_AS_COMMAND set_attr(ist, _ncfo_, SYM(COMMAND_), OBJ(PR_TRUE));
#define MODULE_SET_DOC(name, docstr) \
set_obj_doc(name##_OBJ, #name ": " docstr); \
Modified: trunk/src/builtins-core.c
===================================================================
--- trunk/src/builtins-core.c 2004-06-25 02:12:32 UTC (rev 661)
+++ trunk/src/builtins-core.c 2004-06-25 03:43:48 UTC (rev 662)
@@ -1073,8 +1073,9 @@
MODULE_ADD_SYM(Object, range);
MODULE_ADD_SYM(Object, toStorProxy_);
MODULE_ADD_SYM(Object, fromStorProxy_);
- MODULE_ADD_SYM(Object, print);
+ MODULE_ADD_SYM(Object, print); MARK_AS_COMMAND;
+
MODULE_SUB_INIT(Symbol);
MODULE_ADD_SYM(Symbol, init_);
MODULE_ADD_SYM(Symbol, str_);
Modified: trunk/src/bytecodes.h
===================================================================
--- trunk/src/bytecodes.h 2004-06-25 02:12:32 UTC (rev 661)
+++ trunk/src/bytecodes.h 2004-06-25 03:43:48 UTC (rev 662)
@@ -160,6 +160,13 @@
//*** The combined obj/reference represents attributes or data
//*** contained in the object that can be read from or written to.
+// COMMAND(label)
+// call function as a command, label is name of function in local scope
+// stack: arg1-key, arg1-value, arg2-key, arg2-value, ... -> result
+// param: number of arguments on stack
+// |opcode|label|
+OP_COMMAND,
+
// PUSH_LOCAL_REF(symbol)
// push local reference (local-obj/ref) onto stack
// stack: -> local-scope,symbol
@@ -305,6 +312,10 @@
// |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 02:12:32 UTC (rev 661)
+++ trunk/src/interp.c 2004-06-25 03:43:48 UTC (rev 662)
@@ -822,7 +822,7 @@
int have_exstk, exc_try_loc = 0, exc_exc_loc = 0, return_flag = FALSE;
int exc_final=0, exc_final_return=0;
frame_p exc_free_frame = NULL, exc_switch_frame = NULL;
- int stack_lim = frame->code->max_stack_depth;
+ int stack_lim = frame->code->max_stack_depth, cmd_flag;
obj_p exc_waiting=NULL, return_value = 0;
#ifdef DUMP_MODULE_CODE
@@ -1191,13 +1191,22 @@
IF_EXC_BREAK;
fr_push(bound_meth);
} break;
+ case OP_CMDCALL:
+ cmd_flag = 1;
+ goto got_cmd_flag;
case OP_OBJCALL: {
+ cmd_flag = 0;
+got_cmd_flag:
if (frame->fparam_proc_state_idx >= 0) {
clist_item( frame->fparam_proc_state.lbl_val_list,
(frame->fparam_proc_state_idx*2)+1 ) = fr_pop;
}
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");
+ break;
+ }
if (func_obj->data_type == DATA_TYPE_EXTPTR) {
obj_p res, self;
clist_p plist;
@@ -2162,6 +2171,8 @@
break;
case OP_OBJCALL: fprintf(fout,"%4d %20s(%4d) %s", pc, "OP_OBJCALL", param, codedata(str, code, op, param, pc));
break;
+ case OP_CMDCALL: fprintf(fout,"%4d %20s(%4d) %s", pc, "OP_CMDCALL", param, codedata(str, code, op, param, pc));
+ break;
case OP_CALL: fprintf(fout,"%4d %20s(%4d) %s", pc, "OP_CALL", param, codedata(str, code, op, param, pc));
break;
case OP_OBJBIND: fprintf(fout,"%4d %20s(%4d) %s", pc, "OP_OBJBIND", param, codedata(str, code, op, param, pc));
Modified: trunk/src/parser.h
===================================================================
--- trunk/src/parser.h 2004-06-25 02:12:32 UTC (rev 661)
+++ trunk/src/parser.h 2004-06-25 03:43:48 UTC (rev 662)
@@ -134,6 +134,8 @@
#define GEN_FLG 1
#define WTH_FLG 2
+#define CMD_FLAG 1
+
clist_p append_import_param(void* param, clist_p list, clist_p iparam);
clist_p append_label_to_import_path(void* param, clist_p list, obj_p label);
clist_p append_list(void* param, clist_p list, code_p item);
@@ -198,7 +200,7 @@
code_p bound_bind_params(void* param, code_p attr_ref, code_p obj);
code_p unbound_bind_params(void* param, code_p attr_ref, code_p obj);
code_p bound_func_params(void* param, code_p attr_ref, clist_p parms);
-code_p unbound_func_params(void* param, code_p attr_ref, clist_p parms);
+code_p unbound_func_params(void* param, code_p attr_ref, clist_p parms, int cmd_flag);
code_p bound_bind_func_params(void* param, code_p attr_ref, code_p obj, clist_p parms);
code_p unbound_bind_func_params(void* param, code_p attr_ref, code_p obj, clist_p parms);
code_p sparms_to_slice(void* param, code_p p1, code_p p2, code_p p3, int parm_cnt);
Modified: trunk/src/parser_routines.c
===================================================================
--- trunk/src/parser_routines.c 2004-06-25 02:12:32 UTC (rev 661)
+++ trunk/src/parser_routines.c 2004-06-25 03:43:48 UTC (rev 662)
@@ -522,7 +522,7 @@
pr_assert(k==res->len);
return debug_retrn(__LINE__, res);
}
-code_p unbound_func_params(void* param, code_p attr_ref, clist_p parms) {
+code_p unbound_func_params(void* param, code_p attr_ref, clist_p parms, int cmd_flag) {
code_p res, nul = push_null(param);
int i, k=0, len = 0, stack_depth = 0, max_stack_depth = 0;
int llen = clist_len(parms);
@@ -536,7 +536,10 @@
add_code(nul, res, &k);
for(i=0; i < llen; i++)
add_code(clist_item(parms,i), res, &k);
- res->code_data[k ].bytecode.opcode = OP_OBJCALL;
+ if (cmd_flag = CMD_FLAG)
+ res->code_data[k ].bytecode.opcode = OP_CMDCALL;
+ else
+ res->code_data[k ].bytecode.opcode = OP_OBJCALL;
res->code_data[k++].bytecode.param = clist_len(parms);
res->stack_depth -= 2+(2*llen);
pr_assert(k==res->len);
Modified: trunk/src/prothon.y
===================================================================
--- trunk/src/prothon.y 2004-06-25 02:12:32 UTC (rev 661)
+++ trunk/src/prothon.y 2004-06-25 03:43:48 UTC (rev 662)
@@ -244,7 +244,7 @@
function_param break_statement return_statement
yield_statement with_statement continue_statement
del_statement exec_statement attr_ref def_ref gen_ref obj_ref
- raise_statement obj_statement list_comp
+ raise_statement obj_statement command_statement list_comp
/* Grammar */
%%
@@ -273,7 +273,6 @@
try_except_statement | try_finally_statement | for_statement | obj_statement
;
small_statement:
- expr |
assignment_statement | assert_statement | import_statement |
ass_add_statement | ass_sub_statement | ass_mul_statement |
ass_div_statement | ass_tdv_statement | ass_rem_statement |
@@ -281,9 +280,12 @@
ass_shr_statement | ass_shl_statement | ass_exp_statement |
break_statement | continue_statement| del_statement |
exec_statement | raise_statement | return_statement |
- yield_statement |
+ 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); }
;
@@ -555,7 +557,7 @@
| bound_ref '{' obj_or_empty '}' '(' func_params ')' { $$ = bound_bind_func_params(yylex_param, $1, $3, $6); }
| unbound_ref '{' obj_or_empty '}' '(' func_params ')' { $$ = unbound_bind_func_params(yylex_param, $1, $3, $6); }
| bound_ref '(' func_params ')' { $$ = bound_func_params(yylex_param, $1, $3); }
- | unbound_ref '(' func_params ')' { $$ = unbound_func_params(yylex_param, $1, $3); }
+ | unbound_ref '(' func_params ')' { $$ = unbound_func_params(yylex_param, $1, $3, 0); }
;
obj_or_empty:
/* empty string */ { $$ = push_null(yylex_param); }
Modified: trunk/src/symbol.c
===================================================================
--- trunk/src/symbol.c 2004-06-25 02:12:32 UTC (rev 661)
+++ trunk/src/symbol.c 2004-06-25 03:43:48 UTC (rev 662)
@@ -155,7 +155,8 @@
{ "cont_", 0},
{ "name_", 0},
{ "attrs_", 0},
- { "protos_", 0}
+ { "protos_", 0},
+ { "command_", 0}
};
typedef struct trie_node_s* trie_p;