d90e07b618b7 — Leonard Ritter 9 months ago
* uvm: float-to-float conversion, float comparisons
3 files changed, 26 insertions(+), 3 deletions(-)

M lib/scopes/compiler/target/UVM/init.sc
M src/uvm/uvm.cpp
M testing/test_uvm.sc
M lib/scopes/compiler/target/UVM/init.sc +1 -1
@@ 977,7 977,7 @@ struct UVMGenerator
                 uvm.comment (text = "--- label body starts here")
             rtype := 'qualified-typeof instr
             level := 'top ctx
-            assert (not level.label)
+            #assert (not level.label)
             level.label = instr
             'push ctx self.vm
                 alias = instr

          
M src/uvm/uvm.cpp +21 -0
@@ 3156,6 3156,12 @@ inline void uvm_eval(UVM &vm, uvm_ref ip
             int8_t, int16_t, int32_t, int64_t, __int128_t, \
             CLASS>(vm, uvm_deref(vm, v.a, Weak), uvm_deref(vm, v.b, Weak)); \
     UVM_CASE_END()
+#define UVM_BFOP2(NAME, CLASS) \
+    UVM_CASE_BEGIN(NAME) \
+        result = &uvm_apply_bool_op2< \
+            float, float, float, double, double, \
+            CLASS>(vm, uvm_deref(vm, v.a, Weak), uvm_deref(vm, v.b, Weak)); \
+    UVM_CASE_END()
 #define UVM_BUOP2(NAME, CLASS) \
     UVM_CASE_BEGIN(NAME) \
         result = &uvm_apply_bool_op2< \

          
@@ 3259,6 3265,13 @@ inline void uvm_eval(UVM &vm, uvm_ref ip
     UVM_BUOP2(ugt, IGt)
     UVM_BUOP2(uge, IGe)
 
+    UVM_BFOP2(foeq, IEq)
+    UVM_BFOP2(fune, INe)
+    UVM_BFOP2(folt, ILt)
+    UVM_BFOP2(fole, ILe)
+    UVM_BFOP2(fogt, IGt)
+    UVM_BFOP2(foge, IGe)
+
     UVM_CASE_BEGIN(slice)
         result = &uvm_apply_slice(vm,
             uvm_deref(vm, v.value, Weak),

          
@@ 3303,6 3316,14 @@ inline void uvm_eval(UVM &vm, uvm_ref ip
                 uvm_deref(vm, v.value, Weak),
                 v.stride);
     UVM_CASE_END()
+    UVM_CASE_BEGIN(ftof)
+        result = &uvm_apply_convert<
+            float, float, float, double, double,
+            float, float, float, double, double,
+            IConvert>(vm,
+                uvm_deref(vm, v.value, Weak),
+                v.stride);
+    UVM_CASE_END()
 
 #if 0
     UVM_CASE_BEGIN0(membaseaddr)

          
M testing/test_uvm.sc +4 -2
@@ 248,12 248,14 @@ fn ()
 
 @@ uvm-test #'execution
 fn ()
-    # float arithmetic
+    # simple float arithmetic
+    using import print
     fn unconst (x) x
     a := unconst 3.5
     b := unconst 1.5
     c := unconst 7.1
-    printf "%f\n"
+    #printf "%f\n"
+    print
         a * b + c
     ;