rev 468 - in trunk: pr src

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

Modified:
   trunk/pr/test.pr
   trunk/src/interp.c
Log:
added proper exception when local var lookup fails

Modified: trunk/pr/test.pr
===================================================================
--- trunk/pr/test.pr	2004-05-12 19:18:37 UTC (rev 467)
+++ trunk/pr/test.pr	2004-05-12 19:42:34 UTC (rev 468)
@@ -1,13 +1,31 @@
-object proto1:
-    def init_():
-        print 1
+#!/usr/bin/env prothon
 
-object proto2(proto1):
-    def init_():  
-        proto1.init_()
+# bin.pr
 
-object proto3(proto2):  
-		pass
+x = Exception
 
-print 'xx'
-proto3()
+object obj(String, Int):
+        Int.init_{obj}(99)      # inits using second proto
+        print Int.str_{obj}()   # prints 99
+        
+try:
+    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
+except x,e: print e     # throws "object has binary data, expected none"
+
+L = Proto(List) # L is uninitialized list
+
+L.init_(1,2,3)
+print L             # prints [1, 2, 3] 
+
+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')
+print d             # prints {f:'g', c:'d'} 
\ No newline at end of file

Modified: trunk/src/interp.c
===================================================================
--- trunk/src/interp.c	2004-05-12 19:18:37 UTC (rev 467)
+++ trunk/src/interp.c	2004-05-12 19:42:34 UTC (rev 468)
@@ -831,6 +831,12 @@
 				obj_p att;			
 				fr_sp -= 2;
 				att = get_item(ist, fr_stack[fr_sp], fr_stack[fr_sp+1]);
+				if (!att) {
+					raise_exception( ist, OBJ(INTERPRETER_EXC), 
+										  "attribute %s not found", 
+									      as_str(ist, fr_stack[fr_sp+1]) );
+					break;
+				}
 				fr_push(att);
 			}   break;
 			case OP_ASSIGN: {