Index: /cpp/frams/vm/framscript.y
===================================================================
--- /cpp/frams/vm/framscript.y	(revision 845)
+++ /cpp/frams/vm/framscript.y	(revision 846)
@@ -479,4 +479,5 @@
 			   }
 		   }
+	   $$.stack=trstack.currentPos();
 	   }
            expr_or_objname ')'
@@ -506,7 +507,10 @@
 	   trctx.out->printf(":_loop_end_%d\n",$1.counter);
 	   trstack.loops.drop();
-	   if ($1.stack != trstack.currentPos())
-		   trctx.out->printf("add %d,m0\n",$1.stack-trstack.currentPos());
-	   trstack.adjust($1.stack-trstack.currentPos());
+	   if ($4.constant)
+		   trstack.adjust($3.stack-trstack.currentPos());
+	   int adj=$1.stack-trstack.currentPos();
+	   trstack.adjust(adj);
+	   if (adj!=0)
+		   trctx.out->printf("add %d,m0\n",adj);
 	   }
 	   
@@ -769,5 +773,5 @@
  //     pop; goto and_b
  //   else
- //     pop; push 0; goto and_end
+ //     goto and_end
  // and_b:
  //   push b
@@ -776,5 +780,5 @@
 // trctx.out->printf("\n####### logic AND\n");
  int c=trctx.labelcounter++;
- $$.setInt(c);
+ $$.counter=c;
  if ($1.constant)
 	 {
@@ -783,6 +787,5 @@
 		 {
 		 $1.counter=0;
-		 // no stack adjust - next tokens are processed in a different context
-		 trctx.out->printf("push 0\njump :_and_end_%d\n",c);
+		 trctx.out->printf("jump :_and_end_%d\n",c);
 		 }
 	 else
@@ -791,7 +794,5 @@
  else
 	 {
-	 trstack.adjust(+1); // stack as if (a==true), b expr is processed
-	 trctx.out->printf("if !~,m[m0++],:_and_b_%d\n"
-			   "push 0\n"
+	 trctx.out->printf("if !~,m[m0],:_and_b_%d\n" // skip to b if a!~=false, "a" stays on top
 			   "jump :_and_end_%d\n"
 			   ":_and_b_%d\n"
@@ -801,17 +802,32 @@
          expr
  {
- $$.ident=false;
- $$.constant=0;
- if ($4.constant)
+ if ($1.constant)
 	 {
-	 if (!($1.constant && $1.counter==0))
+	 if ($1.counter==0)
 		 {
-		 ExtValue::CompareResult  cond=$4.compare(ExtValue::zero());
-		 bool value=!resultIsRelaxedEqual(cond);
-		 trstack.adjust(-1);
-		 trctx.out->printf("push %d\n",value);
+		 $$=$1;
+		 if (!$4.constant)
+			 trstack.adjust(+1);
+		 }
+	 else
+		 $$=$4;
+	 }
+ else
+	 {
+	 $$.ident=false;
+	 $$.constant=0;
+	 if ($4.constant)
+		 {
+		 trctx.out->printf("inc m0\n"
+				   "push %s\n",litstr($4));
+		 }
+	 else
+		 {
+		 trstack.adjust(+1);
+		 trctx.out->printf("move m[m0],m[m0+1]\n"
+				   "inc m0\n"); //drop "a"
 		 }
 	 }
- trctx.out->printf(":_and_end_%d\n",$3.getInt());
+ trctx.out->printf(":_and_end_%d\n",$3.counter);
 // trctx.out->printf("#################\n\n");
  }
@@ -822,14 +838,14 @@
  //   push a
  //   if (!a)
- //     pop; goto and_b
+ //     pop; goto or_b
  //   else
- //     pop; push 1; goto and_end
- // and_b:
+ //     goto or_end
+ // or_b:
  //   push b
- // and_end:
+ // or_end:
  trctx.emitLine();
-// trctx.out->printf("\n####### logic AND\n");
+// trctx.out->printf("\n####### logic OR\n");
  int c=trctx.labelcounter++;
- $$.setInt(c);
+ $$.counter=c;
  if ($1.constant)
 	 {
@@ -838,6 +854,5 @@
 		 {
 		 $1.counter=1;
-		 // no stack adjust - next tokens are processed in a different context
-		 trctx.out->printf("push 1\njump :_or_end_%d\n",c);
+		 trctx.out->printf("jump :_or_end_%d\n",c);
 		 }
 	 else
@@ -846,7 +861,5 @@
  else
 	 {
-	 trstack.adjust(+1); // stack for (a==false)
-	 trctx.out->printf("if ~=,m[m0++],:_or_b_%d\n"
-			   "push 1\n"
+	 trctx.out->printf("if ~=,m[m0],:_or_b_%d\n" // skip to b if a~=false, "a" stays on top
 			   "jump :_or_end_%d\n"
 			   ":_or_b_%d\n"
@@ -856,17 +869,32 @@
          expr
  {
- $$.ident=false;
- $$.constant=0;
- if ($4.constant)
+ if ($1.constant)
 	 {
-	 if (!($1.constant && $1.counter==1))
+	 if ($1.counter==1)
 		 {
-		 ExtValue::CompareResult cond=$4.compare(ExtValue::zero());
-		 bool value=!resultIsRelaxedEqual(cond);
-		 trstack.adjust(-1);
-		 trctx.out->printf("push %d\n",value);
+		 $$=$1;
+		 if (!$4.constant)
+			 trstack.adjust(+1);
+		 }
+	 else
+		 $$=$4;
+	 }
+ else
+	 {
+	 $$.ident=false;
+	 $$.constant=0;
+	 if ($4.constant)
+		 {
+		 trctx.out->printf("inc m0\n"
+				   "push %s\n",litstr($4));
+		 }
+	 else
+		 {
+		 trstack.adjust(+1);
+		 trctx.out->printf("move m[m0],m[m0+1]\n"
+				   "inc m0\n"); //drop "a"
 		 }
 	 }
- trctx.out->printf(":_or_end_%d\n",$3.getInt());
+ trctx.out->printf(":_or_end_%d\n",$3.counter);
 // trctx.out->printf("#################\n\n");
  }
