9578896df9c4 — Leonard Ritter tip 19 days ago
* compiler.bridge: fixed int and float globals being translated to purecast nodes rather than true constants
2 files changed, 13 insertions(+), 16 deletions(-)

M lib/scopes/compiler/bridge.sc
M testing/test_bridge.sc
M lib/scopes/compiler/bridge.sc +8 -14
@@ 641,22 641,16 @@ struct CVisitor
             switch (clang_EvalResult_getKind result)
             case CXEval_Int
                 result := clang_EvalResult_getAsLongLong result
-                result := if (ST < integer)
-                    switch ('bitcount ST)
-                    case 8 `[(itrunc result i8)]
-                    case 16 `[(itrunc result i16)]
-                    case 32 `[(itrunc result i32)]
-                    default `result
-                else `result
-                sc_pure_cast_new T result
+                if (ST < integer)
+                    sc_const_int_new T (bitcast result u64)
+                else
+                    fail 'could-not-translate-int-initializer
             case CXEval_Float
                 result := clang_EvalResult_getAsDouble result
-                result := if (ST < real)
-                    switch ('bitcount ST)
-                    case 32 `[(fptrunc result f32)]
-                    default `result
-                else `result
-                sc_pure_cast_new T result
+                if (ST < real)
+                    sc_const_real_new T result
+                else
+                    fail 'could-not-translate-real-initializer
             default
                 fail 'could-not-evaluate-initializer
         default

          
M testing/test_bridge.sc +5 -2
@@ 84,6 84,8 @@ include
         const static float c_hawk_tuah_f = 333.0;
         //const static PT c_m_init = { 23, 42 };
 
+        const static kawonz c_hawk_tuah_k = Uher;
+
 print "define:"
 for k v in lib.define
     print k v

          
@@ 108,8 110,9 @@ test (lib.typedef.kawonz.Uher == 1)
 test (lib.extern.hawk_tuah_i == 303)
 test (lib.extern.hawk_tuah_f == 333.0)
 
+test (lib.extern.c_hawk_tuah_k == lib.typedef.kawonz.Uher)
+test (constant? (lib.extern.c_hawk_tuah_k == lib.typedef.kawonz.Uher))
+
 print "ok."
 
-#print lib.extern.blah
-
 ;