Prothon bug: strange interaction between self and add_

Lenard Lindstrom <[email protected]> Wed, 19 May 2004 11:16:59 -0700 (Pacific Daylight Time)
Newsgroups gmane.comp.lang.prothon.devel
Message-ID <Mahogany-0.66.0-4294894389-20040519-112537.00@pop3.norton.antivirus>
Here is something that has me completely confused. Each time I
run this program I get a different result. The only guess I can
make is that "self" is getting clobbered in "add_" somehow.

--------------------------------------------------------------
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

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_())
---------------------------------------------------------

Some different results:

-----------------
# 1) Integers that support modular addition:
1, [1, <Int:Uninitialized>, <Int:Uninitialized>, <Object:89d260:Int: integer obj
ect prototype>, <Object:89d020:Object: prototype base for all objects>]

Uncaught exception:
--- File: \user\projects\prothon\example1_v1.pr, line: 47, char: 46
--- File: \user\projects\prothon\example1_v1.pr, line: 46, char: 14
Function not found Error, Function add_ not found.
------------------
# 1) Integers that support modular addition:
1, [1, <Int:Uninitialized>, <Int:Uninitialized>, <Object:89d260:Int: integer obj
ect prototype>, <Object:89d020:Object: prototype base for all objects>]
new 2
2, [2, <Int:Uninitialized>, <Int:Uninitialized>, <Object:89d260:Int: integer obj
ect prototype>, <Object:89d020:Object: prototype base for all objects>]

Uncaught exception:
--- File: \user\projects\prothon\example1_v1.pr, line: 47, char: 46
--- File: \user\projects\prothon\example1_v1.pr, line: 46, char: 14
Function not found Error, Function add_ not found.
-------------------
# 1) Integers that support modular addition:
1, [1, <Int:Uninitialized>, <Int:Uninitialized>, <Object:89d260:Int: integer obj
ect prototype>, <Object:89d020:Object: prototype base for all objects>]
new 2
2, [2, <Int:Uninitialized>, <Int:Uninitialized>, <Object:89d260:Int: integer obj
ect prototype>, <Object:89d020:Object: prototype base for all objects>]
3, [3, <Object:89d260:Int: integer object prototype>, <Object:89d020:Object: pro
totype base for all objects>]
4, [4, <Object:89d260:Int: integer object prototype>, <Object:89d020:Object: pro
totype base for all objects>]
5, [5, <Object:89d260:Int: integer object prototype>, <Object:89d020:Object: pro
totype base for all objects>]
6, [6, <Object:89d260:Int: integer object prototype>, <Object:89d020:Object: pro
totype base for all objects>]
7, [7, <Object:89d260:Int: integer object prototype>, <Object:89d020:Object: pro
totype base for all objects>]
8, [8, <Object:89d260:Int: integer object prototype>, <Object:89d020:Object: pro
totype base for all objects>]
9, [9, <Object:89d260:Int: integer object prototype>, <Object:89d020:Object: pro
totype base for all objects>]
10, [10, <Object:89d260:Int: integer object prototype>, <Object:89d020:Object: p
rototype base for all objects>]
11, [11, <Object:89d260:Int: integer object prototype>, <Object:89d020:Object: p
rototype base for all objects>]
--------------------

Or even a page fault in one case.

Does the prothon interpreter remember anything between command line runs?
A particular output will appear several times in a row before changing to
something else.

Lenard Lindstrom
<[email protected]>