rev 553 - in trunk: . pr/test src
SVN User <[email protected]> Tue, 25 May 2004 19:03:59 -0400
| Newsgroups | gmane.comp.lang.prothon.cvs |
|---|---|
| Message-ID | <[email protected]> |
Author: mark
Date: 2004-05-25 19:03:57 -0400 (Tue, 25 May 2004)
New Revision: 553
Modified:
trunk/STATUS.txt
trunk/pr/test/test.pr
trunk/src/parser_routines.c
Log:
fixed bug in and/or that kept last example in sect 5.5 of tutorial from working.
Modified: trunk/STATUS.txt
===================================================================
--- trunk/STATUS.txt 2004-05-25 19:41:18 UTC (rev 552)
+++ trunk/STATUS.txt 2004-05-25 23:03:57 UTC (rev 553)
@@ -57,6 +57,7 @@
----------------------- TUTORIAL TO-DO ------------------------
+ sel(a,b,c) doesn't exactly work like a?b:c
iter_ (for loop)
attrs_
protos_
Modified: trunk/pr/test/test.pr
===================================================================
--- trunk/pr/test/test.pr 2004-05-25 19:41:18 UTC (rev 552)
+++ trunk/pr/test/test.pr 2004-05-25 23:03:57 UTC (rev 553)
@@ -1,6 +1,7 @@
#!/usr/bin/env prothon
-y = Object()
-y.protos_ = [1,3]
-print y.protos_
-print y.protos_ == [1,3]
\ No newline at end of file
+def sel(q, a, b):
+ return (q and a) or ((not q) and b)
+
+print sel(True, 1, 2)
+print sel(False, 1, 2)
Modified: trunk/src/parser_routines.c
===================================================================
--- trunk/src/parser_routines.c 2004-05-25 19:41:18 UTC (rev 552)
+++ trunk/src/parser_routines.c 2004-05-25 23:03:57 UTC (rev 553)
@@ -752,10 +752,13 @@
return debug_retrn(__LINE__, res);
}
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 + 2, 3,
- max( max( lparm->max_stack_depth,
- lparm->stack_depth+2+rparm->max_stack_depth ), 4 ), 0 );
+ code_p res;
+ int k=0, len=0, stack_depth=0, max_stack_depth=0;
+ calc_code(lparm, &len, &stack_depth, &max_stack_depth);
+ len += 8;
+ calc_code(rparm, &len, &stack_depth, &max_stack_depth);
+ len += 2;
+ res = new_code(param, len, stack_depth, max_stack_depth, 0);
add_code(lparm, res, &k);
res->code_data[k ].bytecode.opcode = OP_DUPLICATE;
res->code_data[k++].bytecode.param = -1;
@@ -768,7 +771,7 @@
res->code_data[k ].bytecode.opcode = OP_BEQ;
res->code_data[k++].bytecode.param = rparm->len+4;
res->code_data[k++].data =
- (andor_flg == OR_FLAG? OBJ(PR_TRUE) : OBJ(PR_FALSE));
+ (andor_flg == OR_FLAG? OBJ(PR_TRUE) : OBJ(PR_FALSE));
res->code_data[k ].bytecode.opcode = OP_POP;
res->code_data[k++].bytecode.param = 2;
add_code(rparm, res, &k);
@@ -776,6 +779,8 @@
res->code_data[k++].bytecode.param = 2;
res->code_data[k ].bytecode.opcode = OP_POP;
res->code_data[k++].bytecode.param = 1;
+ pr_assert(k == res->len);
+ res->stack_depth = 1;
return debug_retrn(__LINE__, res);
}
#define SKIP_CODE1_LEN 7