rev 424 - in trunk: . include/prothon pr src
SVN User <[email protected]> Wed, 28 Apr 2004 03:18:03 -0400
| Newsgroups | gmane.comp.lang.prothon.cvs |
|---|---|
| Message-ID | <[email protected]> |
Author: mark
Date: 2004-04-28 03:18:01 -0400 (Wed, 28 Apr 2004)
New Revision: 424
Modified:
trunk/STATUS.txt
trunk/include/prothon/prothon.h
trunk/pr/test.pr
trunk/src/builtins-core.c
trunk/src/interp.c
trunk/src/interp.h
trunk/src/symbol.c
Log:
fixed bug in __init__
Modified: trunk/STATUS.txt
===================================================================
--- trunk/STATUS.txt 2004-04-28 05:16:10 UTC (rev 423)
+++ trunk/STATUS.txt 2004-04-28 07:18:01 UTC (rev 424)
@@ -1,15 +1,11 @@
----------------------- TO-DO (highest priority first) ------------------------
---- Change self to $
+--- Extend closures to all enclosing functions
---- new object creation -- __call__
---- undo "no self" in obj call
-
--- New delgation
--- Bound methods - binding - calling
---- Extend closures to all enclosing functions
--- Add missing string functions
Modified: trunk/include/prothon/prothon.h
===================================================================
--- trunk/include/prothon/prothon.h 2004-04-28 05:16:10 UTC (rev 423)
+++ trunk/include/prothon/prothon.h 2004-04-28 07:18:01 UTC (rev 424)
@@ -48,7 +48,7 @@
* 8. By copying, installing or otherwise using Prothon, Licensee agrees
* to be bound by the terms and conditions of this License Agreement.
* ====================================================================
- */
+ */
// Prothon.h
@@ -63,7 +63,6 @@
//#define DUMP_MODULE_CODE
//#define TRACE_INTERPRETER
//#define DUMP_OBJECTS_AT_END
-
//#define PROSIST_DEBUG
@@ -376,7 +375,8 @@
RPARAM,
PARAM1,
PARAM2,
- __POSLIST__,
+ ARGS,
+ KWARGS,
__NEW__,
__COPY__,
__COVERS__,
@@ -395,6 +395,7 @@
COPY,
__TOSTORPROXY__,
__FROMSTORPROXY__,
+ __CALL__,
SYM_ENUM_COUNT
} sym_enum_t;
@@ -911,9 +912,12 @@
// example: Cmp(a,b)
#define FORM_PARAM2 (list4(ist, SYM(PARAM1), NULL, SYM(PARAM2), NULL))
-// FORM_STAR_PARAM: convenience macro for variable number of formal right parameters
-// equivalent to func(*poslist)
-#define FORM_STAR_PARAM (list2(ist, PARAM_STAR,SYM(__POSLIST__)))
+// FORM_STARn_PARAM: convenience macros for variable number of formal right parameters
+// equivalent to func(*args), func(**kwargs), and func(*args, **kwargs)
+#define FORM_STAR_PARAM (list2(ist, PARAM_STAR, SYM(ARGS)))
+#define FORM_STAR2_PARAM (list2(ist, PARAM_STAR_STAR, SYM(KWARGS)))
+#define FORM_STAR3_PARAM (list4(ist, PARAM_STAR, SYM(ARGS), \
+ PARAM_STAR_STAR, SYM(KWARGS) ))
// CALL_FUNC: Call a function, either Prothon or C based
// This C function provides a way to call any Prothon or C function from C.
Modified: trunk/pr/test.pr
===================================================================
--- trunk/pr/test.pr 2004-04-28 05:16:10 UTC (rev 423)
+++ trunk/pr/test.pr 2004-04-28 07:18:01 UTC (rev 424)
@@ -1,12 +1,21 @@
#!/usr/bin/env prothon
-x = Object()
-with x:
- $a = 0
- def $__init__(a):
- $a = a
+def New(proto, *args, **kwargs):
+ newObj = Proto(proto)
+ []
+ newObj.__init__(*args, **kwargs)
+ return newObj
+
+p = Object()
+with p:
+ $x = None
+ def $__init__(x):
+ $x = x
def $__str__():
- return '*'+$a+'*'
+ return '*'+$x+'*'
-y = x(1)
+x = New(p, 1)
+print x
+
+y = New(p, 'a')
print y
Modified: trunk/src/builtins-core.c
===================================================================
--- trunk/src/builtins-core.c 2004-04-28 05:16:10 UTC (rev 423)
+++ trunk/src/builtins-core.c 2004-04-28 07:18:01 UTC (rev 424)
@@ -94,10 +94,35 @@
set_attr(ist, OBJ(OBJECT), sym(ist, "Object"), OBJ(OBJECT));
}
-DEF(Object, __init__, NULL) {
+DEF(Object, __call__, FORM_STAR3_PARAM) {
+ obj_p new_obj;
+ parms[0] = PARAM_STAR; parms[2] = PARAM_STAR_STAR;
+ new_obj = call_func(ist, self, SYM(__NEW__), 4, parms, NULL); if_exc_return NULL;
+ call_func(ist, new_obj, SYM(__INIT__), 4, parms, NULL);
+ return new_obj;
+}
+
+DEF(Object, __new__, FORM_STAR3_PARAM) {
+ return new_object(ist, self);
+}
+
+DEF(Object, __init__, FORM_STAR3_PARAM) {
return OBJ(NONE);
}
+DEF(Object, Proto, FORM_STAR_PARAM) {
+ int i, llen = (int) list_len(ist, parms[1]);
+ obj_p new_obj;
+ if (!llen) {
+ raise_exception(ist, OBJ(INTERNAL_EXC), "proto() must have one param");
+ return NULL;
+ }
+ new_obj = new_object(ist, list_item(ist, parms[1], 0));
+ for(i=1; i < llen; i++)
+ ins_proto(ist, new_obj, list_item(ist, parms[1], i), 0x7fffffff);
+ return new_obj;
+}
+
DEF(Object, copy, NULL) {
obj_p copy;
size_t cdata_size = 0;
@@ -666,7 +691,10 @@
MAIN_MODULE_INIT(Core)
{
MODULE_SUB_INIT(Object);
+ MODULE_ADD_SYM(Object, __call__);
+ MODULE_ADD_SYM(Object, __new__);
MODULE_ADD_SYM(Object, __init__);
+ MODULE_ADD_SYM(Object, Proto);
MODULE_ADD_SYM(Object, copy);
MODULE_ADD_SYM(Object, setReadAccess);
MODULE_ADD_SYM(Object, readAccess);
Modified: trunk/src/interp.c
===================================================================
--- trunk/src/interp.c 2004-04-28 05:16:10 UTC (rev 423)
+++ trunk/src/interp.c 2004-04-28 07:18:01 UTC (rev 424)
@@ -96,8 +96,8 @@
//******************************** create_frame *****************************
frame_p create_frame( isp ist, obj_p syn_self, obj_p self, obj_p globals,
- obj_p syn_locals, obj_p dyn_locals, obj_p locals,
- obj_p func_obj, code_p code_in ) {
+ obj_p syn_locals, obj_p dyn_locals, obj_p locals,
+ obj_p func_obj, code_p code_in ) {
frame_p frame;
code_p code = NULL;
size_t flen;
@@ -250,8 +250,7 @@
}
if (!state->free_label_list_obj)
return ERR;
- list_append(ist, state->free_label_list_obj, label);
- list_append(ist, state->free_label_list_obj, param);
+ dict_add(ist, state->free_label_list_obj, label, param);
return OK;
}
@@ -276,7 +275,7 @@
} else if (label == PARAM_STAR_STAR) {
pstate = 3;
fparam_proc_state->free_label_list_key = value;
- fparam_proc_state->free_label_list_obj = NEW_LIST(10);
+ fparam_proc_state->free_label_list_obj = NEW_DICT(10);
} else {
if (value) pstate = 1;
clist_append(fparam_proc_state->lbl_val_list, label);
@@ -294,16 +293,16 @@
if (add_pos_param(ist, fparam_proc_state, value)) goto paramerr;
break;
case (uintptr_t)PARAM_STAR: {
- clist_p plist = obj_data_p(value);
- for(j=0; j < clist_len(plist); j++)
- if (add_pos_param(ist, fparam_proc_state, clist_item(plist, j))) goto paramerr;
+ int llen = (int) list_len(ist, value);
+ for(j=0; j < llen; j++)
+ if (add_pos_param(ist, fparam_proc_state, list_item(ist, value, j))) goto paramerr;
break;
}
case (uintptr_t)PARAM_STAR_STAR: {
clist_p plist = obj_data_p(value);
for(j=0; j < clist_len(plist); j+=2)
if ( add_label_param(ist, fparam_proc_state, clist_item(plist, j),
- clist_item(plist, j+1)) ) goto paramerr;
+ clist_item(plist, j+1)) ) goto paramerr;
break;
}
default:
@@ -782,7 +781,7 @@
break;
case OP_PUSH_SYN_REF:
if (!frame->syn_locals) {
- raise_exception(ist, OBJ(INTERPRETER_EXC), "Syntactic access (^x) not available here");
+ raise_exception(ist, OBJ(INTERPRETER_EXC), "Syntactic access (&x) not available here");
break;
}
fr_push(frame->syn_locals);
@@ -858,17 +857,20 @@
case OP_GEN:
case OP_DEF: {
int fparams_len = fr_data_int(1)*2;
- obj_p func = call_func0(ist, fr_data(2), SYM(COPY));
- obj_p fparams_obj = NEW_LIST(fparams_len);
+ obj_p func = copy_object(ist, fr_data(2));
fr_sp -= fparams_len+2;
- assert(sizeof(obj_p) == sizeof(obj_p));
- memcpy( ((list_p)(obj_data_p(fparams_obj)))->item,
- fr_stack+fr_sp+2, fparams_len*sizeof(obj_p) );
- listlen(fparams_obj) = fparams_len;
- set_attr(ist, func, SYM(__SELF__), frame->self);
- set_attr(ist, func, SYM(__FPARAMS__), fparams_obj);
- set_attr(ist, func, SYM(__GLOBALS__), frame->globals);
+ if (fparams_len) {
+ obj_p fparams_obj = NEW_LIST(fparams_len);
+ assert(sizeof(obj_p) == sizeof(obj_p));
+ memcpy( ((list_p)(obj_data_p(fparams_obj)))->item,
+ fr_stack+fr_sp+2, fparams_len*sizeof(obj_p) );
+ listlen(fparams_obj) = fparams_len;
+ set_attr(ist, func, SYM(__FPARAMS__), fparams_obj);
+ }
+ set_attr(ist, func, SYM(__SELF__), frame->self);
+ set_attr(ist, func, SYM(__GLOBALS__), frame->globals);
set_attr(ist, func, SYM(__SYN_LOCALS__), frame->locals);
+ //set_attr(ist, func, SYM(__SYN_FUNC__), frame->func);
#ifdef DUMP_MODULE_CODE
{
char dump_name[256];
@@ -993,8 +995,8 @@
if (intrp_exobj) break;
new_locals = NEW_OBJ(NULL);
syn_self = get_attr(ist, func_obj, SYM(__SELF__)); if (intrp_exobj) break;
- new_frame = create_frame( ist, syn_self, NULL, NULL, NULL,
- frame->locals, new_locals, func_obj, NULL );
+ new_frame = create_frame( ist, syn_self, frame->self, NULL, NULL,
+ frame->locals, new_locals, func_obj, NULL );
fr_next = new_frame;
new_frame->prev_frame = frame;
load_frame_params(ist, new_locals, func_obj, param*2, fr_stack+fr_sp+1);
@@ -1009,12 +1011,8 @@
if (intrp_exobj) break;
fr_push(func_obj);
} else {
- memmove(fr_stack+fr_sp+3, fr_stack+fr_sp+1, (param*2) * sizeof(obj_p));
- fr_stack[fr_sp] = NEW_OBJ(fr_stack[fr_sp]);
- fr_stack[fr_sp+1] = fr_stack[fr_sp];
- fr_stack[fr_sp+2] = SYM(__INIT__);
- fr_sp++;
- frame->calling_init = TRUE;
+ memmove(fr_stack+fr_sp+2, fr_stack+fr_sp+1, (param*2) * sizeof(obj_p));
+ fr_stack[fr_sp+1] = SYM(__CALL__);
super_flag = FALSE;
goto get_func;
}
@@ -1030,7 +1028,7 @@
super_flag = TRUE;
goto op_call;
case OP_CALL: {
- super_flag = FALSE;
+ super_flag = FALSE; // p 0x09ab660 newObj 0x09ab7a0 -> 0x009ab780 (wrong proto)
op_call:
fr_sp -= 2+(2*param);
if (has_proto_QUES(ist, fr_stack[fr_sp+1], OBJ(SUPER_PROTO))) {
@@ -1081,10 +1079,7 @@
post_call_unlock(ist, slf, plist);
free_clist(plist);
if (intrp_exobj) break;
- if (frame->calling_init)
- frame->calling_init = FALSE;
- else
- fr_push(res);
+ fr_push(res);
} else if (has_proto_QUES(ist, func_obj, OBJ(FUNC_PROTO))) {
obj_p new_locals, syn_self;
frame_p new_frame;
@@ -1108,17 +1103,13 @@
fr_push(func_obj);
} else {
obj_p value;
- if (fr_stack[fr_sp+1] != SYM(__INIT__)) {
+ if (fr_stack[fr_sp+1] != SYM(__CALL__)) {
value = get_proto_attr(ist, fr_stack[fr_sp],
fr_stack[fr_sp+1], NULL, NULL);
if (intrp_exobj) break;
if (value) {
- memmove(&fr_stack[fr_sp+3], &fr_stack[fr_sp+2], param*2*sizeof(obj_p));
- fr_stack[fr_sp] = NEW_OBJ(value);
- fr_stack[fr_sp+1] = fr_stack[fr_sp];
- fr_stack[fr_sp+2] = SYM(__INIT__);
- fr_sp++;
- frame->calling_init = TRUE;
+ fr_stack[fr_sp] = value;
+ fr_stack[fr_sp+1] = SYM(__CALL__);
goto get_func;
}
}
@@ -1286,10 +1277,6 @@
exc_try_loc = p->try_loc;
exc_exc_loc = p->exc_loc;
}
- if (frame != DONE_FRAME_FLAG && frame->calling_init) {
- frame->calling_init = FALSE;
- fr_sp--;
- }
}
if (return_flag || frame == DONE_FRAME_FLAG) {
#ifdef TRACE_INTERPRETER
@@ -1575,7 +1562,7 @@
ist = get_ist(ACC_USER2);
set_attr(ist, module, sym(ist, "Argv"), (obj_p) argv);
if (!load_module(ist, main_sym, NULL, NULL, NULL, filename,
- ": a top-level module", module, NULL)) {
+ ":a top-level module", module, NULL)) {
if (!intrp_exobj) {
printf("File %s not found, execution aborted\n", filename);
pr_unlock(&start_main_lock);
Modified: trunk/src/interp.h
===================================================================
--- trunk/src/interp.h 2004-04-28 05:16:10 UTC (rev 423)
+++ trunk/src/interp.h 2004-04-28 07:18:01 UTC (rev 424)
@@ -73,7 +73,6 @@
frame_p next_frame;
frame_p prev_frame;
int called_from_c;
- int calling_init;
int do_not_free;
int gen_marker;
obj_p syn_self;
Modified: trunk/src/symbol.c
===================================================================
--- trunk/src/symbol.c 2004-04-28 05:16:10 UTC (rev 423)
+++ trunk/src/symbol.c 2004-04-28 07:18:01 UTC (rev 424)
@@ -131,7 +131,8 @@
{ "rparam", 0 },
{ "param1", 0 },
{ "param2", 0 },
- { "__poslist__", 0 },
+ { "args", 0 },
+ { "kwargs", 0 },
{ "__new__", 0 },
{ "__copy__", 0 },
{ "__covers__QUES", 0 },
@@ -149,7 +150,8 @@
{ "min", 0 },
{ "copy", 0 },
{ "__toStorProxy__", 0 },
- { "__fromStorProxy__", 0}
+ { "__fromStorProxy__", 0},
+ { "__call__", 0}
};
typedef struct trie_node_s* trie_p;