public inbox for frysk-cvs@sourceware.org
help / color / mirror / Atom feed
* [SCM]  master: Implement logical expressions for non-integer types; Simplify.
@ 2007-11-14 19:33 tthomas
  0 siblings, 0 replies; only message in thread
From: tthomas @ 2007-11-14 19:33 UTC (permalink / raw)
  To: frysk-cvs

The branch, master has been updated
       via  b8552bc35614296282376192e1057d0c4f2bd065 (commit)
      from  c51aa91611f6b182762c6e81f5684650ac0082ef (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email.

- Log -----------------------------------------------------------------
commit b8552bc35614296282376192e1057d0c4f2bd065
Author: Teresa Thomas <tthomas@redhat.com>
Date:   Wed Nov 14 14:23:42 2007 -0500

    Implement logical expressions for non-integer types; Simplify.
    
    frysk-core/frysk/value/ChangeLog
    2007-11-14  Teresa Thomas  <tthomas@redhat.com>
    
    	* ArithmeticUnit.java (logicalAnd): Implement here,
    	use getLogicalValue.
    	(logicalOr): Ditto.
    	(logicalNegation): Ditto.
    	(wordSize): New.
    	* AddressUnit.java: Update.
    	(getLogicalValue): New.
    	(wordSize): Delete.
    	* IntegerUnit.java: Update.
    	(getLogicalValue): New.
    	* FloatingPointUnit.java: Update.
    	(getLogicalValue): New.
    	* TestValue.java: Add tests for above.
    
    frysk-core/frysk/expr/ChangeLog
    2007-11-14  Teresa Thomas  <tthomas@redhat.com>
    
    	* CExprEvaluator.g: Give task memory to
    	all logical operators.

-----------------------------------------------------------------------

Summary of changes:
 frysk-core/frysk/expr/CExprEvaluator.g        |   13 +++----
 frysk-core/frysk/expr/ChangeLog               |    7 +++-
 frysk-core/frysk/value/AddressUnit.java       |   14 +++-----
 frysk-core/frysk/value/ArithmeticUnit.java    |   22 ++++++++++--
 frysk-core/frysk/value/ChangeLog              |   16 +++++++++
 frysk-core/frysk/value/FloatingPointUnit.java |   13 +++-----
 frysk-core/frysk/value/IntegerUnit.java       |   26 +++------------
 frysk-core/frysk/value/TestValue.java         |   42 ++++++++++++++++--------
 8 files changed, 89 insertions(+), 64 deletions(-)

First 500 lines of diff:
diff --git a/frysk-core/frysk/expr/CExprEvaluator.g b/frysk-core/frysk/expr/CExprEvaluator.g
index 4f06c19..2fb26a7 100644
--- a/frysk-core/frysk/expr/CExprEvaluator.g
+++ b/frysk-core/frysk/expr/CExprEvaluator.g
@@ -256,14 +256,12 @@ expr returns [Value returnVar=null]
                         .bitWiseOr(v1, v2); 
         }
     |   #(AND  v1=expr v2=expr) {
-            returnVar = v1.getType().getALU(v2.getType(), 
-                        exprSymTab.getWordSize())
-                        .logicalAnd(v1, v2); 
+            returnVar = v1.getType().getALU(exprSymTab.getWordSize())
+                        .logicalAnd(v1, v2, exprSymTab.taskMemory()); 
         }
     |   #(OR  v1=expr v2=expr) {
-            returnVar = v1.getType().getALU(v2.getType(), 
-                        exprSymTab.getWordSize())
-                        .logicalOr(v1, v2); 
+            returnVar = v1.getType().getALU(exprSymTab.getWordSize())
+                        .logicalOr(v1, v2,exprSymTab.taskMemory()); 
         }
     |   #(NOT  v1=expr) {
             // byte buffer needed for Pointer/Address types
@@ -277,7 +275,8 @@ expr returns [Value returnVar=null]
     |   #(COND_EXPR  log_expr=expr v1=expr v2=expr) {
             returnVar = ((log_expr.getType().getALU(log_expr.getType(), 
                         exprSymTab.getWordSize())
-                        .getLogicalValue(log_expr)) ? v1 : v2);
+                        .getLogicalValue(log_expr, exprSymTab.taskMemory())) 
+                        ? v1 : v2);
         }
     |   o:OCTALINT  {
     	    char c = o.getText().charAt(o.getText().length() - 1);
diff --git a/frysk-core/frysk/expr/ChangeLog b/frysk-core/frysk/expr/ChangeLog
index 4d06e8a..f4519d1 100644
--- a/frysk-core/frysk/expr/ChangeLog
+++ b/frysk-core/frysk/expr/ChangeLog
@@ -1,5 +1,10 @@
+2007-11-14  Teresa Thomas  <tthomas@redhat.com>
+	
+	* CExprEvaluator.g: Give task memory to 
+	all logical operators.
+
 2007-11-13  Teresa Thomas  <tthomas@redhat.com>
-		
+
 	* CExprEvaluator.g: Update.
 	
 2007-11-09  Teresa Thomas  <tthomas@redhat.com>
diff --git a/frysk-core/frysk/value/AddressUnit.java b/frysk-core/frysk/value/AddressUnit.java
index 8917459..32b7503 100644
--- a/frysk-core/frysk/value/AddressUnit.java
+++ b/frysk-core/frysk/value/AddressUnit.java
@@ -41,25 +41,22 @@ package frysk.value;
 
 import inua.eio.ByteOrder;
 import inua.eio.ByteBuffer;
+
 /**
  * Operation handling for pointers and addresses.
  */
 public class AddressUnit
 extends ArithmeticUnit
-{
-    private final int wordSize; 
-    
+{   
     public AddressUnit (ArrayType t, int wordSize) {
 	super (wordSize);
 	retType = new PointerType(t.getName(), ByteOrder.BIG_ENDIAN, 
 		                  wordSize, t.getType());
-	this.wordSize = wordSize; 
     }
     
     public AddressUnit (PointerType t, int wordSize) {
 	super (wordSize);
 	retType = t;
-	this.wordSize = wordSize; 
     }
     
     /**
@@ -124,9 +121,8 @@ extends ArithmeticUnit
 	Value v2Neg = new Value (v2.getType(), l);
 	return add (v1, v2Neg);
     }
-    
-    public Value logicalNegation(Value v1, ByteBuffer mem) {
-	return intType.createValue
-	               (v1.toPrint(Format.NATURAL, mem).equals("0x0")? 1:0);
+
+    public boolean getLogicalValue (Value v1, ByteBuffer mem) {
+	return (v1.toPrint(Format.NATURAL, mem).equals("0x0")? false:true);
     }      
 }
\ No newline at end of file
diff --git a/frysk-core/frysk/value/ArithmeticUnit.java b/frysk-core/frysk/value/ArithmeticUnit.java
index acfe985..5bfaea7 100644
--- a/frysk-core/frysk/value/ArithmeticUnit.java
+++ b/frysk-core/frysk/value/ArithmeticUnit.java
@@ -55,6 +55,8 @@ public abstract class ArithmeticUnit
     // Integer return type for relational, equality
     // and logical operations.
     protected IntegerType intType;
+
+    protected int wordSize;
     
     protected ArithmeticUnit(int wordSize) {
 	// XXX: Is endianness okay?
@@ -62,6 +64,7 @@ public abstract class ArithmeticUnit
 	// size of machine.
 	intType = new UnsignedType ("int", ByteOrder.LITTLE_ENDIAN, 
 		                    wordSize);
+	this.wordSize = wordSize;
     }
     
     // Multiplicative and Additive expressions
@@ -145,17 +148,28 @@ public abstract class ArithmeticUnit
         throw new InvalidOperatorException
                   (v1.getType(), v2.getType(), "&&");
     }
+    // Logical expressions - valid for any scalar types.
+    public Value logicalAnd (Value v1, Value v2, ByteBuffer mem) {
+	boolean op1 = v1.getType().getALU(wordSize).getLogicalValue(v1, mem);
+	boolean op2 = v2.getType().getALU(wordSize).getLogicalValue(v2, mem);
+	return intType.createValue( (op1 && op2) ? 1:0);
+    }
     public Value logicalOr (Value v1, Value v2) {
         throw new InvalidOperatorException
                   (v1.getType(), v2.getType(), "||");
     }
+    public Value logicalOr (Value v1, Value v2, ByteBuffer mem) {
+	boolean op1 = v1.getType().getALU(wordSize).getLogicalValue(v1, mem);
+	boolean op2 = v2.getType().getALU(wordSize).getLogicalValue(v2, mem);
+	return intType.createValue( op1 || op2 ? 1:0);
+    }
     public Value logicalNegation(Value v1, ByteBuffer mem) {
-        throw new InvalidOperatorException
-                  (v1.getType(), "!");
+	boolean op1 = v1.getType().getALU(wordSize).getLogicalValue(v1, mem);
+	return intType.createValue( op1 ? 0:1);
     }     
-    public boolean getLogicalValue (Value v1) {
+    public boolean getLogicalValue (Value v1, ByteBuffer mem) {
         throw new InvalidOperatorException
-                  (v1.getType(), "bool");
+                  (v1.getType(), "getLogicalValue");
     }  
     
     // Assigment expressions.
diff --git a/frysk-core/frysk/value/ChangeLog b/frysk-core/frysk/value/ChangeLog
index 43d1291..037936f 100644
--- a/frysk-core/frysk/value/ChangeLog
+++ b/frysk-core/frysk/value/ChangeLog
@@ -1,3 +1,19 @@
+2007-11-14  Teresa Thomas  <tthomas@redhat.com>
+	
+	* ArithmeticUnit.java (logicalAnd): Implement here, 
+	use getLogicalValue.
+	(logicalOr): Ditto.
+	(logicalNegation): Ditto.
+	(wordSize): New.
+	* AddressUnit.java: Update.
+	(getLogicalValue): New.	
+	(wordSize): Delete.
+	* IntegerUnit.java: Update. 
+	(getLogicalValue): New.
+	* FloatingPointUnit.java: Update. 
+	(getLogicalValue): New.
+	* TestValue.java: Add tests for above.
+
 2007-11-13  Teresa Thomas  <tthomas@redhat.com>
 	
 	* ArithmeticUnit.java (logicalNegation): Add task mem to
diff --git a/frysk-core/frysk/value/FloatingPointUnit.java b/frysk-core/frysk/value/FloatingPointUnit.java
index 3e1ff5e..6b57434 100644
--- a/frysk-core/frysk/value/FloatingPointUnit.java
+++ b/frysk-core/frysk/value/FloatingPointUnit.java
@@ -38,6 +38,7 @@
 // exception.
 
 package frysk.value;
+
 import inua.eio.ByteBuffer;
 
 /**
@@ -102,13 +103,9 @@ public class FloatingPointUnit
     public Value notEqual (Value v1, Value v2) {
 	return retType.createValue
 	       (v1.doubleValue() != v2.doubleValue() ? 1:0);
-    }   
+    }
     
-    /**
-     * @param mem - unused here.
-     */
-    public Value logicalNegation(Value v1, ByteBuffer mem) {
-	return intType.createValue
-               (v1.doubleValue() == 0.0? 1 : 0);
-    }     
+    public boolean getLogicalValue (Value v1, ByteBuffer mem) {
+	return ((v1.doubleValue() == 0.0) ? false : true);
+    }   
 }    
\ No newline at end of file
diff --git a/frysk-core/frysk/value/IntegerUnit.java b/frysk-core/frysk/value/IntegerUnit.java
index e43adbd..ce3f505 100644
--- a/frysk-core/frysk/value/IntegerUnit.java
+++ b/frysk-core/frysk/value/IntegerUnit.java
@@ -133,26 +133,10 @@ public class IntegerUnit
     public Value bitWiseComplement(Value v1) {
 	return retType.createValue
 	       (v1.asBigInteger().not());
-    } 
-
-    public Value logicalAnd(Value v1, Value v2) {
-	return retType.createValue
-	       ((v1.asBigInteger().compareTo(BigInteger.ZERO) == 0 ? false : true)
-             && (v2.asBigInteger().compareTo(BigInteger.ZERO) == 0 ? false : true) ? 1 : 0);
-    }    
-    public Value logicalOr(Value v1, Value v2) {
-	return retType.createValue
-	       ((v1.asBigInteger().compareTo(BigInteger.ZERO) == 0 ? false : true)
-	     || (v1.asBigInteger().compareTo(BigInteger.ZERO) == 0 ? false : true) ? 1 : 0);
-    }  
-    /**
-     * @ param mem - unused here.
-     */
-    public Value logicalNegation(Value v1, ByteBuffer mem) {
-	return retType.createValue
-               (v1.asBigInteger().compareTo(BigInteger.ZERO) == 0 ? 1 : 0);
-    }    
-    public boolean getLogicalValue (Value v1) {
-	return ((v1.asBigInteger().compareTo(BigInteger.ZERO) == 0) ? false : true);
+    }
+    
+    public boolean getLogicalValue (Value v1, ByteBuffer mem) {
+	return ((v1.asBigInteger().compareTo(BigInteger.ZERO) == 0) 
+		 ? false : true);
     }    
 }
\ No newline at end of file
diff --git a/frysk-core/frysk/value/TestValue.java b/frysk-core/frysk/value/TestValue.java
index d8c8289..30507f5 100644
--- a/frysk-core/frysk/value/TestValue.java
+++ b/frysk-core/frysk/value/TestValue.java
@@ -41,6 +41,7 @@ package frysk.value;
 
 import inua.eio.ArrayByteBuffer;
 import inua.eio.ByteOrder;
+import frysk.Config;
 import frysk.junit.TestCase;
 
 public class TestValue
@@ -57,6 +58,9 @@ public class TestValue
     private ArithmeticType byteType = new SignedType("byte", ByteOrder.LITTLE_ENDIAN, 1);
     private ArithmeticType floatType = new FloatingPointType("float", ByteOrder.LITTLE_ENDIAN, 4);
     private ArithmeticType doubleType = new FloatingPointType("double", ByteOrder.LITTLE_ENDIAN, 8);
+    
+    private int wordSize = Config.getWordSize();
+    
     public void testNumber ()
     {
 	Value v1 = byteType.createValue(1);
@@ -137,13 +141,13 @@ public class TestValue
 	assertEquals ("9 ^ 4", 9 ^ 4, v3.asLong());
 	v3 = v1.getType().getALU(v2.getType(), 0).bitWiseComplement(v1);
 	assertEquals ("~4", ~4, v3.asLong());
-	v3 = v1.getType().getALU(v2.getType(), 0).logicalAnd(v2, v1);
-	assertEquals ("9 & 4", 1, v3.asLong());
-	v3 = v1.getType().getALU(v2.getType(), 0).logicalOr(v2, v1);
-	assertEquals ("9 | 4", 1, v3.asLong());	
-	v3 = v1.getType().getALU(v1.getType(), 0).logicalNegation(v1, null);
+	v3 = v1.getType().getALU(wordSize).logicalAnd(v2, v1, null);
+	assertEquals ("9 && 4", 1, v3.asLong());
+	v3 = v1.getType().getALU(wordSize).logicalOr(v2, v1, null);
+	assertEquals ("9 || 4", 1, v3.asLong());	
+	v3 = v1.getType().getALU(wordSize).logicalNegation(v1, null);
 	assertEquals ("!4", 0, v3.asLong());		
-	bool = v2.getType().getALU(v2.getType(), 0).getLogicalValue(v2);
+	bool = v2.getType().getALU(wordSize).getLogicalValue(v2, null);
 	assertEquals ("bool(9)", true, bool);		
 	v3 = v3.assign(v1);	
 	assertEquals ("v3 = 4", 4, v3.asLong());
@@ -162,11 +166,11 @@ public class TestValue
 	v3 = v1.getType().getALU(v2.getType(), 0).shiftRightEqual(v3, v1);
 	assertEquals ("v3 >>= 4", 0, v3.asLong());
 	v3 = v1.getType().getALU(v2.getType(), 0).bitWiseOrEqual(v3, v1);
-	assertEquals ("v3 ||= 4", 4, v3.asLong());
+	assertEquals ("v3 |= 4", 4, v3.asLong());
 	v3 = v1.getType().getALU(v2.getType(), 0).bitWiseXorEqual(v3, v1);
 	assertEquals ("v3 ^= 4", 0, v3.asLong());
 	v3 =v1.getType().getALU(v2.getType(), 0).bitWiseAndEqual(v3, v1);
-	assertEquals ("v3 &&= 4", 0, v3.asLong());
+	assertEquals ("v3 &= 4", 0, v3.asLong());
     }
 
     public void testFloatOps ()
@@ -207,11 +211,16 @@ public class TestValue
 	v3 = v3.getType().getALU(v1.getType(), 0).modEqual(v3, v1);
 	assertEquals ("v3 %= 4", 0, v3.doubleValue(), 0);
 	// Note: Return type of logical expression is int.
-	v3 = v1.getType().getALU(v1.getType(), 0).logicalNegation(v1, null);
+	v3 = v1.getType().getALU(wordSize).logicalAnd(v2, v1, null);
+	assertEquals ("9 && 4", 1, v3.asLong());
+	v3 = v1.getType().getALU(wordSize).logicalOr(v2, v1, null);
+	assertEquals ("9 || 4", 1, v3.asLong());			
+	v3 = v1.getType().getALU(wordSize).logicalNegation(v1, null);
 	assertEquals ("!4", 0, v3.asLong());		
     }
     
-    public void testAddressOps() {
+    public void testAddressOps() 
+    {
 	// Construct a buffer with a string in it.
 	ArrayByteBuffer memory
 	= new ArrayByteBuffer("0123Hello World\0>>>".getBytes());
@@ -220,9 +229,14 @@ public class TestValue
 			       1, true));
 	// Construct the pointer to it.
 	Location l = new ScratchLocation(new byte[] { 4 });
-	Value string = new Value (t, l);
-        
-	Value v =  t.getALU(8).logicalNegation(string, memory);
-	assertEquals("!string", 0, v.asLong());
+	Value ptr = new Value (t, l);
+	Value v1 = intType.createValue(4);
+
+	Value v = v1.getType().getALU(wordSize).logicalAnd(v1, ptr, memory);
+	assertEquals ("ptr && 4", 1, v.asLong());
+	v = v1.getType().getALU(wordSize).logicalOr(v1, ptr, memory);
+	assertEquals ("ptr || 4", 1, v.asLong());	
+	v =  t.getALU(8).logicalNegation(ptr, memory);
+	assertEquals("!ptr", 0, v.asLong());
     }  
 }


hooks/post-receive
--
frysk system monitor/debugger


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2007-11-14 19:33 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-11-14 19:33 [SCM] master: Implement logical expressions for non-integer types; Simplify tthomas

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).