]> git.mdlowis.com Git - proto/cerise-c.git/commitdiff
fixed boolean operators
authorMike Lowis <mike.lowis@gentex.com>
Mon, 3 Jun 2024 18:48:20 +0000 (14:48 -0400)
committerMike Lowis <mike.lowis@gentex.com>
Mon, 3 Jun 2024 18:48:20 +0000 (14:48 -0400)
cerise-c.m
cerise-c.rb
runtime.h

index 54064a21d45dddd2381e210f7cae1d96e938cf62..1bd5c13311c230652325bae16cb94e2147862df9 100644 (file)
@@ -19,6 +19,7 @@ TestBoolOps() {
 }
 
 init() {
-    TestLiterals()
-    return 42.0
+    assert TestLiterals()
+    assert TestBoolOps()
+    return true
 }
index f7f904ec81d66696a0a7906d82c0b3731b00b5e2..775c73a8ee213ce078da923173027105a9615c73 100755 (executable)
@@ -1196,6 +1196,11 @@ module Codegen
   end
 end
 
+##
+# Add Builtin Functions
+##
+
+
 
 ##
 # Emit the Code
index 62aa67158aa77d0a373cf933a68a11b9f172f692..c32d62dd68c8c73af2e2be8a89d793bb3d8d35f8 100644 (file)
--- a/runtime.h
+++ b/runtime.h
@@ -97,9 +97,9 @@ static inline bool IsString(Value val) {
 /* C Type Conversions
  *************************************************/
 
-static inline int32_t ValueAsBool(Value val) {
+static inline bool ValueAsBool(Value val) {
     assert(IsBool(val));
-    return (bool)val.as_uint64;
+    return (bool)(val.as_uint64 == VALUE_TRUE);
 }
 
 static inline int32_t ValueAsInt(Value val) {
@@ -149,7 +149,7 @@ static inline Value MakeNil(void) {
 }
 
 static inline Value MakeBool(bool b) {
-    return (Value){ .as_uint64 = b ? VALUE_TRUE : VALUE_FALSE };
+    return (Value){ .as_uint64 = (b ? VALUE_TRUE : VALUE_FALSE) };
 }
 
 static inline Value MakeInt(int32_t i) {
@@ -258,13 +258,28 @@ static inline Value OpGt(Value left, Value right) {
 }
 
 static inline Value OpGtEq(Value left, Value right) {
-    return MakeNil();
+    Value result;
+    result = MakeBool(false);
+    return result;
 }
 
 static inline Value OpEq(Value left, Value right) {
-    return MakeNil();
+    Value result;
+    if (IsBool(left)) {
+        result = MakeBool(ValueAsBool(left) == ValueAsBool(right));
+    } else {
+        result = MakeBool(false);
+    }
+    return result;
 }
 
 static inline Value OpNeq(Value left, Value right) {
-    return MakeNil();
+    Value result;
+    if (IsBool(left)) {
+        printf("%d != %d\n", ValueAsBool(left), ValueAsBool(right));
+        result = MakeBool(ValueAsBool(left) != ValueAsBool(right));
+    } else {
+        result = MakeBool(false);
+    }
+    return result;
 }