rev 475 - in trunk: pr src
SVN User <[email protected]> Wed, 12 May 2004 18:40:28 -0400
| Newsgroups | gmane.comp.lang.prothon.cvs |
|---|---|
| Message-ID | <[email protected]> |
Author: mark
Date: 2004-05-12 18:40:25 -0400 (Wed, 12 May 2004)
New Revision: 475
Modified:
trunk/pr/dict.pr
trunk/pr/fixed.pr
trunk/pr/gen.pr
trunk/pr/meow.pr
trunk/pr/modint.pr
trunk/pr/test.pr
trunk/src/parser_routines.c
Log:
fixed bug in call_()
Modified: trunk/pr/dict.pr
===================================================================
--- trunk/pr/dict.pr 2004-05-12 22:16:41 UTC (rev 474)
+++ trunk/pr/dict.pr 2004-05-12 22:40:25 UTC (rev 475)
@@ -33,7 +33,10 @@
print 'all tests passed'
-print '\nfollowing should be: 1 (1, 2) 3 (3, 4)\n'
+print """
+The following should be:
+1 (1, 2) 3 (3, 4)
+"""
for i in e: print i, d.popItem!(),
Modified: trunk/pr/fixed.pr
===================================================================
--- trunk/pr/fixed.pr 2004-05-12 22:16:41 UTC (rev 474)
+++ trunk/pr/fixed.pr 2004-05-12 22:40:25 UTC (rev 475)
@@ -14,7 +14,7 @@
object PrettyPrintFixed(Fixed):
def init_(n):
- Int.init_(n)
+ Int.init_{self}(n)
# Set default print format width.
self.setPrintWidth(self.dp+5)
Modified: trunk/pr/gen.pr
===================================================================
--- trunk/pr/gen.pr 2004-05-12 22:16:41 UTC (rev 474)
+++ trunk/pr/gen.pr 2004-05-12 22:40:25 UTC (rev 475)
@@ -1,16 +1,16 @@
#!/usr/bin/env prothon
-gen outer(n)
+gen _outer(n):
x = -1
- def inner()
- return &x
+ def inner():
+ return outer.x
yield inner
- for x in range(n)
+ for x in n:
yield x
-iter = outer(10)
+iter = _outer(10)
inner = iter.next()
print inner()
-for x in iter
+for x in iter:
print x, inner()
Modified: trunk/pr/meow.pr
===================================================================
--- trunk/pr/meow.pr 2004-05-12 22:16:41 UTC (rev 474)
+++ trunk/pr/meow.pr 2004-05-12 22:40:25 UTC (rev 475)
@@ -2,28 +2,28 @@
Animal = Object()
with Animal:
- def $describe():
+ def describe():
print "I am an animal."
- $make_noise()
- def $make_noise():
+ self.make_noise()
+ def make_noise():
print "I make animal noise."
Mammal = Animal()
with Mammal:
- def $describe():
+ def describe():
print "I am a mammal."
- Animal$describe() # directed super call
- $make_noise()
- def $make_noise():
+ Animal.describe{self}()
+ self.make_noise()
+ def make_noise():
print "I make mammal noise."
Cat = Mammal()
with Cat:
- def $describe():
+ def describe():
print "I am a cat."
- ^describe() # non-directed super call
- $make_noise()
- def $make_noise():
+ Mammal.describe{self}()
+ self.make_noise()
+ def make_noise():
print "meow"
c = Cat()
Modified: trunk/pr/modint.pr
===================================================================
--- trunk/pr/modint.pr 2004-05-12 22:16:41 UTC (rev 474)
+++ trunk/pr/modint.pr 2004-05-12 22:40:25 UTC (rev 475)
@@ -1,26 +1,26 @@
#!/usr/bin/env prothon
object ModInt(Int):
- $modulo = 10
- def $init_(i=0):
- ^init_(i % $modulo)
- def $add_(other):
- if $modulo != other.modulo:
+ modulo = 10
+ def init_(i=0):
+ Int.init_{self}(i % self.modulo)
+ def add_(other):
+ if self.modulo != other.modulo:
raise TypeError
- return ^(^add_(other) % $modulo)
+ return (self.protoList()[1])(Int.add_{self}(other) % self.modulo)
object Mod16Int(ModInt):
- $modulo = 16
+ modulo = 16
object Mod16IntC(Mod16Int):
- $cache = {}
- def $init_(i):
- i = i % $modulo
- if i in $cache:
- print $cache[i] , 'from cache'
- return $cache[i]
+ cache = {}
+ def init_(i):
+ i = i % self.modulo
+ if i in cache:
+ print cache[i] , 'from cache'
+ return cache[i]
obj = Mod16Int(i)
- $cache[i] = obj
+ cache[i] = obj
print obj, 'new'
return obj
Modified: trunk/pr/test.pr
===================================================================
--- trunk/pr/test.pr 2004-05-12 22:16:41 UTC (rev 474)
+++ trunk/pr/test.pr 2004-05-12 22:40:25 UTC (rev 475)
@@ -1,3 +1,40 @@
+#!/usr/bin/env prothon
-for i in j:
- pass
\ No newline at end of file
+object ModInt(Int):
+ modulo = 10
+ def init_(i=0):
+ Int.init_{self}(i % self.modulo)
+ def add_(other):
+ if self.modulo != other.modulo:
+ raise TypeError
+ return (self.protoList()[1])(Int.add_{self}(other) % self.modulo)
+
+object Mod16Int(ModInt):
+ modulo = 16
+
+object Mod16IntC(Mod16Int):
+ cache = {}
+ def init_(i):
+ i = i % self.modulo
+ if i in cache:
+ print cache[i] , 'from cache'
+ return cache[i]
+ obj = Mod16Int(i)
+ cache[i] = obj
+ print obj, 'new'
+ return obj
+
+print """
+
+Should print
+
+11 new
+8 new
+8 from cache
+11 + 8 + 8 = 11
+"""
+
+i = Mod16IntC(27)
+j = Mod16IntC(8)
+k = Mod16IntC(8)
+print "%i + %i + %i = %02i" % (i, j, k, (i + j + k))
Modified: trunk/src/parser_routines.c
===================================================================
--- trunk/src/parser_routines.c 2004-05-12 22:16:41 UTC (rev 474)
+++ trunk/src/parser_routines.c 2004-05-12 22:40:25 UTC (rev 475)
@@ -431,19 +431,22 @@
code_p obj_func_params(void* param, code_p obj, clist_p parms){
code_p res;
int i, k=0;
- int len = obj->len;
- int stack_depth = obj->stack_depth;
- int max_stack_depth = obj->max_stack_depth;
+ int len = obj->len+3;
+ int stack_depth = obj->stack_depth+1;
+ int max_stack_depth = obj->max_stack_depth+1;
int llen = clist_len(parms);
for(i=0; i < llen; i++)
calc_code(clist_item(parms,i), &len, &stack_depth, &max_stack_depth);
- res = new_code(param, len+1, stack_depth, max_stack_depth, 0);
+ res = new_code(param, len, stack_depth, max_stack_depth, 0);
add_code(obj, res, &k);
+ res->code_data[k ].bytecode.opcode = OP_PUSH;
+ res->code_data[k++].bytecode.param = 2;
+ res->code_data[k++].data = NULL;
for(i=0; i < llen; i++)
add_code(clist_item(parms,i), res, &k);
- res->code_data[k].bytecode.opcode = OP_OBJCALL;
+ res->code_data[k ].bytecode.opcode = OP_OBJCALL;
res->code_data[k++].bytecode.param = clist_len(parms);
- res->stack_depth -= 2*llen;
+ res->stack_depth -= 1+(2*llen);
pr_assert(k==res->len);
return debug_retrn(__LINE__, res);
}
@@ -553,30 +556,6 @@
pr_assert(k==res->len);
return debug_retrn(__LINE__, res);
}
-/*
-code_p obj_ds_label_func_params(void* param, code_p obj, obj_p label, clist_p parms) {
- code_p res;
- int i, k=0;
- int len = obj->len+2;
- int stack_depth = obj->stack_depth+1;
- int max_stack_depth = obj->max_stack_depth;
- int llen = clist_len(parms);
- for(i=0; i < llen; i++)
- calc_code(clist_item(parms,i), &len, &stack_depth, &max_stack_depth);
- res = new_code(param, len+1, stack_depth, max_stack_depth, 0);
- add_code(obj, res, &k);
- res->code_data[k ].bytecode.opcode = OP_PUSH;
- res->code_data[k++].bytecode.param = 2;
- res->code_data[k++].data = sym(IST, pr_strptr(label));
- for(i=0; i < llen; i++)
- add_code(clist_item(parms,i), res, &k);
- res->code_data[k ].bytecode.opcode = OP_SUPERCALL;
- res->code_data[k++].bytecode.param = clist_len(parms);
- res->stack_depth -= 1+(2*llen);
- pr_assert(k==res->len);
- return debug_retrn(__LINE__, res);
-}
-*/
code_p label_to_formparm(void* param, obj_p label){
code_p res = new_code(param, 3, 2, 2, OP_PUSH);
res->code_data[0].bytecode.param = 3;