rev 472 - in trunk: pr src
SVN User <[email protected]> Wed, 12 May 2004 17:34:42 -0400
| Newsgroups | gmane.comp.lang.prothon.cvs |
|---|---|
| Message-ID | <[email protected]> |
Author: mark
Date: 2004-05-12 17:34:39 -0400 (Wed, 12 May 2004)
New Revision: 472
Added:
trunk/pr/fixed.pr
trunk/pr/gen.pr
trunk/pr/scope.pr
Modified:
trunk/src/interp.c
trunk/src/parser_routines.c
Log:
added some tests
Added: trunk/pr/fixed.pr
===================================================================
--- trunk/pr/fixed.pr 2004-05-12 21:23:06 UTC (rev 471)
+++ trunk/pr/fixed.pr 2004-05-12 21:34:39 UTC (rev 472)
@@ -0,0 +1,36 @@
+#!/usr/bin/env prothon
+
+object Fixed(Int):
+ dp = 2
+ divisor = 100
+
+ def call_(n=0, decimalplaces=2):
+ obj = Proto(self)
+ obj.dp = decimalplaces
+ obj.divisor = 10
+ obj.init_(n) # binary data init here
+ return obj
+
+object PrettyPrintFixed(Fixed):
+
+ def init_(n):
+ Int.init_(n)
+ # Set default print format width.
+ self.setPrintWidth(self.dp+5)
+
+ def setPrintWidth(wid):
+ # Create string comprehension "%W.Pf"
+ # where W is wid and P is selfdp
+ self.pattern = "%%%i.%if" % (wid, self.dp)
+ print self.pattern
+
+ def str_():
+ return self.pattern % (self / self.divisor)
+
+print """
+This should print
+
+%6.1f
+123456.7
+"""
+print PrettyPrintFixed(1234567, 1)
Added: trunk/pr/gen.pr
===================================================================
--- trunk/pr/gen.pr 2004-05-12 21:23:06 UTC (rev 471)
+++ trunk/pr/gen.pr 2004-05-12 21:34:39 UTC (rev 472)
@@ -0,0 +1,14 @@
+gen outer(n)
+ x = -1
+ def inner()
+ return &x
+ yield inner
+ for x in range(n)
+ yield x
+
+iter = outer(10)
+inner = iter.next()
+
+print inner()
+for x in iter
+ print x, inner()
Added: trunk/pr/scope.pr
===================================================================
--- trunk/pr/scope.pr 2004-05-12 21:23:06 UTC (rev 471)
+++ trunk/pr/scope.pr 2004-05-12 21:34:39 UTC (rev 472)
@@ -0,0 +1,24 @@
+#!/usr/bin/env prothon
+
+print """
+This should print
+1 2 3 4 5 6
+"""
+
+a = 1
+B = 2
+def f1():
+ c = 3
+ d = 99
+ def f2():
+ c = 99
+ d = 4
+ print a, B, outer.c, d, self.x, caller.x
+ return f2
+
+object obj:
+ x = 5
+ f = f1()
+
+x=6
+obj.f()
Modified: trunk/src/interp.c
===================================================================
--- trunk/src/interp.c 2004-05-12 21:23:06 UTC (rev 471)
+++ trunk/src/interp.c 2004-05-12 21:34:39 UTC (rev 472)
@@ -1936,6 +1936,7 @@
default:
break;
}
+ fflush(fout);
if (op < OP_PARAM_WORDS_BOUNDARY)
return pc + param;
else if (op < OP_TWO_WORDS_BOUNDARY)
Modified: trunk/src/parser_routines.c
===================================================================
--- trunk/src/parser_routines.c 2004-05-12 21:23:06 UTC (rev 471)
+++ trunk/src/parser_routines.c 2004-05-12 21:34:39 UTC (rev 472)
@@ -763,7 +763,7 @@
}
code_p expr_andor_expr(void* param, code_p lparm, code_p rparm, int andor_flg){
int k=0;
- code_p res = new_code( param, lparm->len + 8 + rparm->len + 3, 3,
+ code_p res = new_code( param, lparm->len + 8 + rparm->len + 2, 3,
max( max( lparm->max_stack_depth,
lparm->stack_depth+2+rparm->max_stack_depth ), 4 ), 0 );
add_code(lparm, res, &k);
@@ -1129,7 +1129,7 @@
res->code_data[k ].bytecode.opcode = OP_DUPLICATE;
res->code_data[k++].bytecode.param = -1;
res->code_data[k ].bytecode.opcode = OP_PUSH;
- res->code_data[k++].bytecode.param = 2;
+ res->code_data[k++].bytecode.param = 3;
res->code_data[k++].data = SYM(NEXT);
res->code_data[k++].data = NULL;
res->code_data[k ].bytecode.opcode = OP_CALL;