rev 509 - in trunk: include/prothon pr/test

SVN User <[email protected]> Wed, 19 May 2004 16:58:09 -0400
Newsgroups gmane.comp.lang.prothon.cvs
Message-ID <[email protected]>
Author: mark
Date: 2004-05-19 16:58:06 -0400 (Wed, 19 May 2004)
New Revision: 509

Modified:
   trunk/include/prothon/prothon.h
   trunk/pr/test/test.pr
Log:
touched prothon.h and changed test.pr

Modified: trunk/include/prothon/prothon.h
===================================================================
--- trunk/include/prothon/prothon.h	2004-05-19 05:20:40 UTC (rev 508)
+++ trunk/include/prothon/prothon.h	2004-05-19 20:58:06 UTC (rev 509)
@@ -77,7 +77,7 @@
 #ifdef __cplusplus
 extern "C" {
 #endif
-
+ 
 #define PROTHON_VERSION_NUMBER	"0.1"
 #define PROTHON_VERSION_BUILD   "$Rev$"  
 #define PROTHON_VERSION_DATE	__DATE__

Modified: trunk/pr/test/test.pr
===================================================================
--- trunk/pr/test/test.pr	2004-05-19 05:20:40 UTC (rev 508)
+++ trunk/pr/test/test.pr	2004-05-19 20:58:06 UTC (rev 509)
@@ -1,10 +1,47 @@
+def refer(start, attrname):
+    mro = self.protoList()
+    n = mro.len()
+    i = 0
+    while i < n:
+        if mro[i] is start:
+            break
+        i += 1
+    if i == n:
+        raise AttributeError
+    while True:
+        i += 1
+        if i == n:
+            break
+        o = mro[i]
+        attrs = o.attrs()
+        if attrname in attrs:
+            a = attrs[attrname]
+            if a.hasProto?(Func):
+                return a
+            return a
+    raise AttributeError
 
+print "# 1) Integers that support modular addition:"
+object ModInt(Int):
+    modulo = 10
+    def call_(i=0):
+        call = refer(ModInt, 'call_')
+        return call{self}(i % self.modulo)
+    def add_(other):
+        if self.modulo != other.modulo:
+            raise TypeError
+        proto = self.protoList()[1]
+        add = refer(ModInt, 'add_')
+        x =  proto(add{self}(other))
+        print "new", x
+        return x
 
-Rectangle = Object()
-with Rectangle:
-    width = 10
-    height = 10
-    def area():
-        return self.width * self.height
+object Mod8Int(ModInt):
+    modulo = 8
 
-
+m = Mod8Int(1)
+n = Mod8Int(1)
+print "%i, %s" % (m, m.protoList().str_())
+for i in 10:
+    m = m + n
+    print "%i, %s" % (m, m.protoList().str_())