rev 298 - in trunk: . pr src
SVN User <[email protected]>
| Newsgroups | gmane.comp.lang.prothon.cvs |
|---|---|
| Message-ID | <[email protected]> |
Author: mark
Date: 2004-04-07 21:17:15 -0400 (Wed, 07 Apr 2004)
New Revision: 298
Modified:
trunk/STATUS.txt
trunk/pr/meow.pr
trunk/src/bytecodes.h
trunk/src/interp.c
trunk/src/parser.h
trunk/src/parser_routines.c
trunk/src/prothon.y
Log:
next (and hopefully final) implementation of super is finished, Mammal^describe() is now supported.
Modified: trunk/STATUS.txt
===================================================================
--- trunk/STATUS.txt 2004-04-07 18:11:48 UTC (rev 297)
+++ trunk/STATUS.txt 2004-04-08 01:17:15 UTC (rev 298)
@@ -1,6 +1,8 @@
----------------------- TO-DO (highest priority first) ------------------------
+--- add new obj^method() syntax
+
--- add list comprehension
--- a < b < c
@@ -30,6 +32,8 @@
--- Does simple 1+2 expr evaluation create objects? If so, need shortcuts to speed it up
+--- clean up prt_code_line mess with some cleaner coding technique
+
--- reduce array of act params passed to function to only odd entries
--- thread monitor function
@@ -38,6 +42,8 @@
---------------- Ideas to consider for inclusion ------------------------------
+How do we add "properties"?
+
Python add-on C module adapter for Prothon
Guido's regret list for Python
@@ -87,17 +93,20 @@
sets and other zephyr email items -- use <> ?
-Allow obj^attr ?
-Super start at function closure object?
-Use self for any obj.func() when obj is proto of self?
-Give new syntax for binding function call to object?
-
remove \ continuation ?
--- make print a function ?
+------------------------------ speedups ---------------------------------------
+
+Inline asm for lock code up to wrlock acquire and access check
+
+Global prototype lookup cache
+
+Copy garbage collection good for small objects
+
------------------------------ bugs -------------------------------------------
parser
bison warnings
Modified: trunk/pr/meow.pr
===================================================================
--- trunk/pr/meow.pr 2004-04-07 18:11:48 UTC (rev 297)
+++ trunk/pr/meow.pr 2004-04-08 01:17:15 UTC (rev 298)
@@ -12,10 +12,10 @@
with Mammal:
def .describe():
print "I am a mammal."
- f = Animal.describe # any of these will work
- f() # super call type 1
- (Animal.describe)() # super call type 2
- ^describe() # super call type 3
+# f = Animal.describe # any of these will work
+# f() # super call type 1
+ Animal^describe() # super call type 2
+# ^describe() # super call type 3
.make_noise()
def .make_noise():
print "I make mammal noise."
@@ -26,8 +26,8 @@
print "I am a cat."
f = Mammal.describe # any of these will work
f() # super call type 1
- (Mammal.describe)() # super call type 2
- ^describe() # super call type 3
+# Mammal^describe() # super call type 2
+# ^describe() # super call type 3
.make_noise()
def .make_noise():
print "meow"
Modified: trunk/src/bytecodes.h
===================================================================
--- trunk/src/bytecodes.h 2004-04-07 18:11:48 UTC (rev 297)
+++ trunk/src/bytecodes.h 2004-04-08 01:17:15 UTC (rev 298)
@@ -264,6 +264,18 @@
// |opcode|
OP_OBJCALL,
+// SUPERCALL(object, func, params)
+// call function using object, func-symbol, & params on stack
+// get function by looking up func-symbol in object's attributes
+// call function using current self
+// params are in pairs of optional-label/value
+// label is symbol-obj, PARAM_NORMAL, PARAM_STAR, or PARAM_STAR_STAR
+// pop all and leave result on stack
+// stack: object,func-symbol,label,value,label,value,... -> result
+// param: num param pairs on stack
+// |opcode|
+OP_SUPERCALL,
+
// CALL(self, func, params)
// call function with self-obj, func-symbol, & params on stack
// params are in pairs of optional-label/value
Modified: trunk/src/interp.c
===================================================================
--- trunk/src/interp.c 2004-04-07 18:11:48 UTC (rev 297)
+++ trunk/src/interp.c 2004-04-08 01:17:15 UTC (rev 298)
@@ -560,7 +560,7 @@
obj_p exec_loop(isp ist){
obj_p func_obj, temp = NULL;
opcode_t op;
- int i, param;
+ int i, param, super_flag;
exec_frame_t *switch_frame = NULL, *free_frame = NULL;
exec_frame_t* frame = ist->frame;
int have_exstk, exc_try_loc = 0, exc_exc_loc = 0, return_flag = FALSE;
@@ -869,7 +869,7 @@
if (intrp_exobj) break;
new_locals = new_object(ist, NULL);
syn_self = get_attr(ist, func_obj, SYM(__SELF__)); if (intrp_exobj) break;
- new_frame = new_exec_frame( ist, syn_self, frame->self, NULL, NULL,
+ new_frame = new_exec_frame( ist, syn_self, NULL, NULL, NULL,
frame->locals, new_locals, func_obj, NULL );
fr_next = new_frame;
new_frame->prev_frame = frame;
@@ -891,6 +891,7 @@
fr_stack[fr_sp+2] = SYM(__INIT__);
fr_sp++;
frame->calling_init = TRUE;
+ super_flag = FALSE;
goto get_func;
}
} break;
@@ -901,7 +902,12 @@
switch_frame->prev_frame = frame;
frame->next_frame = switch_frame;
break;
+ case OP_SUPERCALL:
+ super_flag = TRUE;
+ goto op_call;
case OP_CALL: {
+ super_flag = FALSE;
+op_call:
fr_sp -= 2+(2*param);
if (has_proto_QUES(ist, fr_stack[fr_sp+1], OBJ(SUPER_PROTO))) {
func_obj = get_proto_attr(ist, fr_stack[fr_sp], fr_stack[fr_sp+1]->data.ptr, NULL, frame->syn_self);
@@ -924,6 +930,10 @@
}
if (intrp_exobj) break;
get_func:
+ if (!fr_stack[fr_sp]) {
+ raise_exception(ist, OBJ(INTERPRETER_EXC), "reference to non-existant self object");
+ break;
+ }
func_obj = get_proto_attr(ist, fr_stack[fr_sp], fr_stack[fr_sp+1], NULL, NULL);
got_func:
if (intrp_exobj) break;
@@ -934,7 +944,7 @@
break;
}
if (func_obj->data_type == OBJ_TYPE_FUNCPTR){
- obj_p res, slf = fr_stack[fr_sp];
+ obj_p res, slf = super_flag? frame->self : fr_stack[fr_sp];
clist_p plist = get_func_params(ist, func_obj, param*2, fr_stack+fr_sp+2);
if (intrp_exobj) break;
pre_call_lock(slf, plist); if (intrp_exobj) break;
@@ -956,7 +966,7 @@
if (intrp_exobj) break;
new_locals = new_object(ist, NULL);
syn_self = get_attr(ist, func_obj, SYM(__SELF__)); if (intrp_exobj) break;
- new_frame = new_exec_frame( ist, syn_self, fr_stack[fr_sp], NULL, NULL,
+ new_frame = new_exec_frame( ist, syn_self, super_flag? frame->self : fr_stack[fr_sp], NULL, NULL,
frame->locals, new_locals, func_obj, NULL );
fr_next = new_frame;
new_frame->prev_frame = frame;
@@ -1534,6 +1544,8 @@
break;
case OP_OBJCALL: fprintf(fout,"%4d %20s(%4d) %s", pc, "OP_OBJCALL", param, codedata(str, code, op, param, pc));
break;
+ case OP_SUPERCALL: fprintf(fout,"%4d %20s(%4d) %s", pc, "OP_SUPERCALL", 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_ASSIGN: fprintf(fout,"%4d %20s(%4d) %s", pc, "OP_ASSIGN", param, codedata(str, code, op, param, pc));
Modified: trunk/src/parser.h
===================================================================
--- trunk/src/parser.h 2004-04-07 18:11:48 UTC (rev 297)
+++ trunk/src/parser.h 2004-04-08 01:17:15 UTC (rev 298)
@@ -183,6 +183,7 @@
code* return_expr(void* param, code* expr);
code* self_func_params(void* param, code* attr_ref, clist_p parms);
code* unbound_func_params(void* param, code* attr_ref, clist_p parms);
+code* obj_super_label_func_params(void* param, code* attr_ref, char* label, clist_p parms);
code* sparms_to_slice(void* param, code* p1, code* p2, code* p3, int parm_cnt);
code* stack_check(void* param, code* stmt);
code* star_ref_to_formparm(void* param, char* label);
Modified: trunk/src/parser_routines.c
===================================================================
--- trunk/src/parser_routines.c 2004-04-07 18:11:48 UTC (rev 297)
+++ trunk/src/parser_routines.c 2004-04-08 01:17:15 UTC (rev 298)
@@ -455,6 +455,28 @@
assert(k==res->len);
return debug_retrn(__LINE__, res);
}
+code* obj_super_label_func_params(void* param, code* obj, char* label, clist_p parms) {
+ code* res;
+ int i, k=0;
+ int len = obj->len+2;
+ int stack_depth = obj->stack_depth+1;
+ int max_stack_depth = obj->max_stack_depth;
+ int llen = clist_len(parms);
+ for(i=0; i < llen; i++)
+ calc_code(clist_item(parms,i), &len, &stack_depth, &max_stack_depth);
+ res = new_code(param, len+1, stack_depth, max_stack_depth, 0);
+ add_code_to(obj, res, &k);
+ res->code_data[k ].bytecode.opcode = OP_PUSH;
+ res->code_data[k++].bytecode.param = 2;
+ res->code_data[k++].data = sym(INTRP, label);
+ for(i=0; i < llen; i++)
+ add_code_to(clist_item(parms,i), res, &k);
+ res->code_data[k ].bytecode.opcode = OP_SUPERCALL;
+ res->code_data[k++].bytecode.param = clist_len(parms);
+ res->stack_depth -= 1+(2*llen);
+ assert(k==res->len);
+ return debug_retrn(__LINE__, res);
+}
code* label_to_formparm(void* param, char* label){
code* res = new_code(param, 3, 2, 2, OP_PUSH);
res->code_data[0].bytecode.param = 3;
Modified: trunk/src/prothon.y
===================================================================
--- trunk/src/prothon.y 2004-04-07 18:11:48 UTC (rev 297)
+++ trunk/src/prothon.y 2004-04-08 01:17:15 UTC (rev 298)
@@ -519,6 +519,7 @@
| obj '(' function_params ')' { $$ = obj_func_params(yylex_param, $1, $3); }
| attr_ref '(' function_params ')' { $$ = self_func_params(yylex_param, $1, $3); }
| unbound_ref '(' function_params ')' { $$ = unbound_func_params(yylex_param, $1, $3); }
+ | obj '^' LABEL '(' function_params ')' { $$ = obj_super_label_func_params(yylex_param, $1, $3, $5); }
;
target:
target_params