rev 467 - in trunk: pr src

SVN User <[email protected]> Wed, 12 May 2004 15:18:40 -0400
Newsgroups gmane.comp.lang.prothon.cvs
Message-ID <[email protected]>
Author: mark
Date: 2004-05-12 15:18:37 -0400 (Wed, 12 May 2004)
New Revision: 467

Modified:
   trunk/pr/bin.pr
   trunk/pr/bind.pr
   trunk/pr/func.pr
   trunk/pr/modint.pr
   trunk/pr/new.pr
   trunk/pr/object.pr
   trunk/pr/oops.pr
   trunk/pr/test.pr
   trunk/src/builtins-core.c
   trunk/src/interp.c
   trunk/src/parser_routines.c
Log:
fixed bug that caused param mismatch with (*l, **d) and ()

Modified: trunk/pr/bin.pr
===================================================================
--- trunk/pr/bin.pr	2004-05-12 16:52:02 UTC (rev 466)
+++ trunk/pr/bin.pr	2004-05-12 19:18:37 UTC (rev 467)
@@ -5,27 +5,27 @@
 x = Exception
 
 object obj(String, Int):
-        Int.__init__{local.obj}(99)      # inits using second proto
-        print Int.__str__{local.obj}()   # prints 99
+        Int.init_{obj}(99)      # inits using second proto
+        print Int.str_{obj}()   # prints 99
         
 try:
-    with obj: Int.__init__{local.obj}(99)   # init Int a second time
+    with obj: Int.init_{obj}(99)   # init Int a second time
 except x,e: print e    # throws "object has binary data, expected none"
 
 try:
-    obj.__init__('abc') # init as String
+    obj.init_('abc') # init as String
 except x,e: print e     # throws "object has binary data, expected none"
 
 L = Proto(List) # L is uninitialized list
 
-L.__init__(1,2,3)
+L.init_(1,2,3)
 print L             # prints [1, 2, 3] 
 
-L.__init__(4,5,6)
+L.init_(4,5,6)
 print L             # prints [4, 5, 6] 
 
 d = {1:2, 'a':'b'}
 print d             # prints {1:2, 'a':'b'}
 
-d.__init__(c = 'd', f = 'g')
+d.init_(c = 'd', f = 'g')
 print d             # prints {f:'g', c:'d'} 
\ No newline at end of file

Modified: trunk/pr/bind.pr
===================================================================
--- trunk/pr/bind.pr	2004-05-12 16:52:02 UTC (rev 466)
+++ trunk/pr/bind.pr	2004-05-12 19:18:37 UTC (rev 467)
@@ -14,6 +14,6 @@
 bf66{88}()				# 88
 
 print bf33				#   <func:93b7c0:bound:33>
-print bf33.__bindObj__	#	33
-del bf33.__bindObj__
+print bf33.bindObj_		#	33
+del bf33.bindObj_
 print bf33				#  <func:93b7c0>
Modified: trunk/pr/func.pr
===================================================================
--- trunk/pr/func.pr	2004-05-12 16:52:02 UTC (rev 466)
+++ trunk/pr/func.pr	2004-05-12 19:18:37 UTC (rev 467)
@@ -15,7 +15,7 @@
 	print 'f2 '+y
 	
 f = Proto(f1)
-f.__init__(f2)
+f.init_(f2)
 
 f1('a')
 f2('b')
Modified: trunk/pr/modint.pr
===================================================================
--- trunk/pr/modint.pr	2004-05-12 16:52:02 UTC (rev 466)
+++ trunk/pr/modint.pr	2004-05-12 19:18:37 UTC (rev 467)
@@ -2,19 +2,19 @@
 
 object ModInt(Int): 
     $modulo = 10
-    def $__init__(i=0): 
-        ^__init__(i % $modulo)
-    def $__add__(other):
+    def $init_(i=0): 
+        ^init_(i % $modulo)
+    def $add_(other):
         if $modulo != other.modulo: 
             raise TypeError 
-        return ^(^__add__(other) % $modulo) 
+        return ^(^add_(other) % $modulo) 
 
 object Mod16Int(ModInt):
     $modulo = 16
 
 object Mod16IntC(Mod16Int):     
     $cache = {}                 
-    def $__init__(i):            
+    def $init_(i):            
         i = i % $modulo         
         if i in $cache:       
             print  $cache[i] , 'from cache' 

Modified: trunk/pr/new.pr
===================================================================
--- trunk/pr/new.pr	2004-05-12 16:52:02 UTC (rev 466)
+++ trunk/pr/new.pr	2004-05-12 19:18:37 UTC (rev 467)
@@ -2,15 +2,15 @@
 
 def New(proto, *args, **kwargs):
     newObj = Proto(proto)
-    newObj.__init__(*args, **kwargs)
+    newObj.init_(*args, **kwargs)
     return newObj
 
 p = Object()
 with p:
     $x = None
-    def $__init__(x):
+    def $init_(x):
         $x = x
-    def $__str__():
+    def $str_():
         return '*'+$x+'*'
 
 print
Modified: trunk/pr/object.pr
===================================================================
--- trunk/pr/object.pr	2004-05-12 16:52:02 UTC (rev 466)
+++ trunk/pr/object.pr	2004-05-12 19:18:37 UTC (rev 467)
@@ -4,12 +4,12 @@
 
 object Point(Object):
 	self.x = 0; self.y = 0
-	def self.__init__(x, y):
+	def self.init_(x, y):
 		self.x=x; self.y=y
 	def self.move(xofs, yofs):
 		self.x += xofs; self.y += yofs
 		print self.
-	def self.__str__():
+	def self.str_():
 		return '<'+self.x+':'+self.y+'>'
 		
 print
Modified: trunk/pr/oops.pr
===================================================================
--- trunk/pr/oops.pr	2004-05-12 16:52:02 UTC (rev 466)
+++ trunk/pr/oops.pr	2004-05-12 19:18:37 UTC (rev 467)
@@ -6,7 +6,7 @@
 
 	$name = "<proto name>"
 	
-	def $__init__(name):
+	def $init_(name):
 		$name = name
 		$hello()
 		return $

Modified: trunk/pr/test.pr
===================================================================
--- trunk/pr/test.pr	2004-05-12 16:52:02 UTC (rev 466)
+++ trunk/pr/test.pr	2004-05-12 19:18:37 UTC (rev 467)
@@ -1,20 +1,13 @@
-#!/usr/bin/env prothon
+object proto1:
+    def init_():
+        print 1
 
-x = 1
-object obj(Object):
-	print x
-	y = 4
+object proto2(proto1):
+    def init_():  
+        proto1.init_()
 
-	def init_(x):
-		self.x = x
+object proto3(proto2):  
+		pass
 
-	def func():
-		print 'x1',x
-		outer.x = 2
-		print 'x2',x
-		print 'self.x', self.x
-		print 'outer.y', outer.y
-
-z = obj(3)
-z.func()
-
+print 'xx'
+proto3()

Modified: trunk/src/builtins-core.c
===================================================================
--- trunk/src/builtins-core.c	2004-05-12 16:52:02 UTC (rev 466)
+++ trunk/src/builtins-core.c	2004-05-12 19:18:37 UTC (rev 467)
@@ -70,6 +70,7 @@
 MODULE_DECLARE(None);
 MODULE_DECLARE(Exception);
 MODULE_DECLARE(Gen);
+MODULE_DECLARE(Local);
 MODULE_DECLARE(Seq);
 MODULE_DECLARE(Func);
 MODULE_DECLARE(Method);
@@ -500,6 +501,19 @@
 	return self; 
 }
 
+// ***************************** LOCAL ******************************************
+MODULE_START(Local)
+{
+	Local_OBJ = OBJ(LOCAL_PROTO);
+	MODULE_SET_DOC(Local, "local object prototype");
+	set_attr(ist, OBJ(OBJECT), sym(ist, "Local"), Local_OBJ);
+	set_obj_id(Local_OBJ, *, Local);
+}
+
+DEF(Local, str_, NULL) {
+	return call_func0(ist, self->data.ptr, SYM(STR_));
+}
+
 // ***************************** SEQUENCE *************************************
 
 MODULE_START(Seq)
@@ -812,6 +826,9 @@
 	MODULE_SUB_INIT(Gen);
 	MODULE_ADD_SYM(Gen, iter_);
 
+	MODULE_SUB_INIT(Local);
+	MODULE_ADD_SYM(Local, str_);
+
 	MODULE_SUB_INIT(Func);
 	MODULE_ADD_SYM(Func, init_);
 	MODULE_ADD_SYM(Func, str_);

Modified: trunk/src/interp.c
===================================================================
--- trunk/src/interp.c	2004-05-12 16:52:02 UTC (rev 466)
+++ trunk/src/interp.c	2004-05-12 19:18:37 UTC (rev 467)
@@ -85,7 +85,7 @@
 
 void trace_step(frame_p frame) {
 	int i;
-	if (!tfout) tfout = fopen("code_trace.txt", "w");
+	if (!tfout) tfout = fopen("!code_trace.txt", "w");
 	prt_code_line(frame, fr_code, fr_pc, tfout);
 	fprintf(tfout,"%6d>>>", fr_sp);
 	for(i=0; i <  fr_sp; i++) 
@@ -338,8 +338,23 @@
 				break;
 			}
 		}
-	} else if (parm_cnt)
-		goto paramerr;
+	} else {
+		int i;
+		for (i=0; i < parm_cnt; ) {
+			label = act_params[i++];
+			value = act_params[i++];
+			switch ((uintptr_t)label){
+			case (uintptr_t)PARAM_STAR:
+				if (list_len(ist, value)) goto paramerr;
+				break;
+			case (uintptr_t)PARAM_STAR_STAR:
+				if (dict_len(ist, value)) goto paramerr;
+				break;
+			default:
+				goto paramerr;
+			}
+		}
+	} 
 	return OK;
 fparmerr:
 	return 1;
@@ -699,8 +714,11 @@
 	int exc_final=0, exc_final_return=0, stack_lim = frame->code->max_stack_depth;
 	obj_p exc_waiting=NULL, return_value = 0;
 
+#ifdef DUMP_MODULE_CODE
+	obj_p dump_code_key;
+#endif
 #ifdef TRACE_INTERPRETER
-	if (!tfout) tfout = fopen("code_trace.txt", "w");
+	if (!tfout) tfout = fopen("!code_trace.txt", "w");
 	fprintf(tfout, "--- starting exec_loop at frame %8x, pc: %d\n", (intptr_t) frame, frame->pc);
 	fflush(tfout);
 #endif
@@ -892,9 +910,10 @@
 #ifdef DUMP_MODULE_CODE
 				{
 					char dump_name[256];
+					static int cntr = 1;
 					apr_snprintf(dump_name, sizeof(dump_name),
-						     "%s_def_dump.txt",
-						     symch(ist, fr_stack[fr_sp+1]));
+						     "!def_code_%s_%d.txt",
+						     as_str(ist, fr_stack[fr_sp+1]), cntr++);
 					dump_code(ist, func, func->data.ptr, dump_name);
 				}
 #endif
@@ -1067,6 +1086,9 @@
 				int i, num_protos = (int)(intptr_t) fr_data(2);
 				obj_p new_obj, key;
 				fr_sp -= (num_protos+1)*2;
+#ifdef DUMP_MODULE_CODE
+				dump_code_key = fr_stack[fr_sp+1];
+#endif
 				if (num_protos == 0) new_obj = new_object(ist, NULL);
 				else {
 					obj_p psym = fr_stack[fr_sp+3];
@@ -1096,8 +1118,27 @@
 				set_attr(ist, fr_stack[fr_sp], key, new_obj); IF_EXC_BREAK;
 				del_unlock(new_obj);
 				fr_push(new_obj);
-			} // fall into OP_WITH
+				goto op_with;
+			}
 			case OP_WITH:
+#ifdef DUMP_MODULE_CODE
+				dump_code_key = NULL;
+op_with:		{
+					char dump_name[256];
+					static int with_num = 1;
+					obj_p func = fr_data(1);
+					if (dump_code_key)
+						apr_snprintf( dump_name, sizeof(dump_name),
+									  "!object_code_%s_%d.txt", 
+									  as_str(ist, dump_code_key), with_num++ );
+					else
+						apr_snprintf( dump_name, sizeof(dump_name),
+									"!with_code_%d.txt", with_num++ );
+					dump_code(ist, func, func->data.ptr, dump_name);
+				}
+#else
+op_with:		
+#endif
 				fr_sp--;
 				switch_frame = create_frame( ist, frame->self, frame->locals, frame->dyn_locals, 
 					                              fr_stack[fr_sp], fr_data(1), NULL );
@@ -1520,13 +1561,13 @@
 
 #ifdef DUMP_MODULE_CODE
 	{
-		char name[256], *p, *d;
-		for (p = str, d = name; *p && (strlen(d) < 64); p++) {
+		char name[256], buf[65], *p, *d, *e = buf+64;
+		for (p = str, d = buf; *p && d < e; p++) {
 			if (*p >= 'A' && *p <= 'Z') *(d++) = *p;
 			if (*p >= 'a' && *p <= 'z') *(d++) = *p;
 		}
 		*d = 0;
-		strcat(name, "_execstr_code.txt");
+		apr_snprintf(name, sizeof(name), "!exec_code_%s.txt", buf);
 		dump_code(ist, NULL, code, name);
 	}
 #endif
@@ -1590,7 +1631,7 @@
 #ifdef DUMP_MODULE_CODE
 	{
 		char dump_name[256];
-		apr_snprintf(dump_name, sizeof(dump_name), "%s_module_dump.txt", name);
+		apr_snprintf(dump_name, sizeof(dump_name), "!module_code_%s.txt", name);
 		dump_code(ist, NULL, code, dump_name);
 	}
 #endif

Modified: trunk/src/parser_routines.c
===================================================================
--- trunk/src/parser_routines.c	2004-05-12 16:52:02 UTC (rev 466)
+++ trunk/src/parser_routines.c	2004-05-12 19:18:37 UTC (rev 467)
@@ -125,7 +125,7 @@
 		strcat(dfname, ".txt");
 		{	size_t len = strlen(dfname);
 			char* dbg_filename = pr_malloc(len+15);
-			strcpy(dbg_filename, "parse_trace-");
+			strcpy(dbg_filename, "!parse_trace-");
 			strcat(dbg_filename, dfname);
 			parse_debug_fout = fopen(dbg_filename, "w");
 			parse_state->debug_stream = parse_debug_fout;