[SCM] Lisaac compiler branch, master, updated. 1765d04ddce38149baca412b457311dfda61c60e

Jeremy Cowgar jeremy at cowgar.com
Thu Mar 26 07:28:48 UTC 2009


The following commit has been merged in the master branch:
commit 1765d04ddce38149baca412b457311dfda61c60e
Author: Jeremy Cowgar <jeremy at cowgar.com>
Date:   Thu Mar 26 03:24:54 2009 -0400

    * Added is_binary to ABSTRACT_STRING.
    * Fixed bug in is_real_16_16: During the overflow check, it was
      making a decision based on if the number was negative or not,
      however, the number (if negated) was never actually negated
      until the end of the routine. This now causes all current
      unit tests to pass for ABSTRACT_STRING.
    * Added tests for is_binary.

diff --git a/lib/string/abstract_string.li b/lib/string/abstract_string.li
index 79e1ea2..e6ad6c9 100644
--- a/lib/string/abstract_string.li
+++ b/lib/string/abstract_string.li
@@ -540,6 +540,22 @@ Section Public
     result
   );
 
+  - is_binary :BOOLEAN <-
+  ( + result:BOOLEAN;
+    + j:INTEGER;
+
+    (is_empty).if_false {
+      j := lower;
+      { (j > upper) || {! item j.is_binary_digit} }.until_do {
+        j := j + 1;
+      };
+
+      result := j > upper;
+    };
+
+    result
+  );
+
   - to_binary :INTEGER_64 <-
   ( + result:INTEGER_64;
     ? {is_bit};
@@ -590,54 +606,53 @@ Section Public
     { (state = 5) || {i > count}}.until_do {
       cc := item i;
       ( state = 0).if {
-	cc.is_separator.if {
-	}.elseif {cc = '+'} then {
-	  state := 1;
-	}.elseif {cc = '-'} then {
-	  negative := TRUE;
-	  state := 1;
-	}.elseif {cc.is_digit} then {
-	  value_int := cc.decimal_value;
-	  state := 2;
-	} else {
-	  state := 5;
-	};
+        cc.is_separator.if {
+        }.elseif {cc = '+'} then {
+          state := 1;
+        }.elseif {cc = '-'} then {
+          negative := TRUE;
+          state := 1;
+        }.elseif {cc.is_digit} then {
+          value_int := cc.decimal_value;
+          state := 2;
+        } else {
+          state := 5;
+        };
       }.elseif { state = 1} then {
-	cc.is_digit.if {
-	  value_int := cc.decimal_value;
-	  state := 2;
-	} else {
-	  state := 5;
-	};
+        cc.is_digit.if {
+          value_int := cc.decimal_value;
+          state := 2;
+        } else {
+          state := 5;
+        };
       }.elseif { state = 2 } then {
-	cc.is_digit.if {
-	  value_int := 10 * value_int + cc.decimal_value;
-	  // over/underflow check here
-	  ((negative && {value_int > 0}) || { ! negative && {value_int < 0}}).if {
-	    state := 5;
-	  };
-	}.elseif { cc = '.' } then {
-	  state := 3;	
-	  value := value_int.to_real_16_16;
-	}.elseif {cc.is_separator} then {
-	  state := 4;
-	} else {
-	  state := 5;
-	};
+        cc.is_digit.if {
+          value_int := 10 * value_int + cc.decimal_value;
+          (value_int < 0).if {
+            state := 5;
+          };
+        }.elseif { cc = '.' } then {
+          state := 3;
+          value := value_int.to_real_16_16;
+        }.elseif {cc.is_separator} then {
+          state := 4;
+        } else {
+          state := 5;
+        };
       }.elseif { state = 3 } then {
-	cc.is_digit.if {
-	  d := d * 10;
-	  value := value + (cc.decimal_value.to_real_16_16) /# d;
-	}.elseif {cc.is_separator} then {
-	  state := 4;
-	} else {
-	  state := 5;
-	};
+        cc.is_digit.if {
+          d := d * 10;
+          value := value + (cc.decimal_value.to_real_16_16) /# d;
+        }.elseif {cc.is_separator} then {
+          state := 4;
+        } else {
+          state := 5;
+        };
       }.elseif { state = 4 } then {
-	cc.is_separator.if {
-	} else {	    
-	  state := 5;
-	};
+        cc.is_separator.if {
+        } else {
+          state := 5;
+        };
       };
       
       i := i + 1;
diff --git a/tests/abstract_string_test.li b/tests/abstract_string_test.li
index 5f25f2f..3c1043d 100644
--- a/tests/abstract_string_test.li
+++ b/tests/abstract_string_test.li
@@ -121,7 +121,10 @@ Section Public
     UNIT_TEST.test "is_octal #4" boolean ("Jack".is_octal) equals FALSE;
     UNIT_TEST.test "to_octal #1" integer ("5".to_octal) equals 5;
     UNIT_TEST.test "to_octal #2" integer ("25".to_octal) equals 21;
-    // TODO: Where is is_binary ?
+    UNIT_TEST.test "is_binary #1" boolean ("101".is_binary) equals TRUE;
+    UNIT_TEST.test "is_binary #2" boolean ("101.1".is_binary) equals FALSE;
+    UNIT_TEST.test "is_binary #3" boolean ("1013".is_binary) equals FALSE;
+    UNIT_TEST.test "is_binary #4" boolean ("".is_binary) equals FALSE;
     UNIT_TEST.test "to_binary #1" integer ("101".to_binary) equals 5;
     UNIT_TEST.test "to_binary #2" integer ("10000000101".to_binary) equals 1029;
     UNIT_TEST.test "is_real_16_16 #1" boolean ("10".is_real_16_16) equals TRUE;

-- 
Lisaac compiler



More information about the Lisaac-commits mailing list