@@ -63,24 +63,123 @@ TEST_F(LLVMCodeBuilderTest, ConstCasting)
6363{
6464 m_builder->addConstValue (5.2 );
6565 m_builder->addFunctionCall (" test_print_number" , Compiler::StaticType::Void, { Compiler::StaticType::Number });
66+ m_builder->addConstValue (" -24.156" );
67+ m_builder->addFunctionCall (" test_print_number" , Compiler::StaticType::Void, { Compiler::StaticType::Number });
68+
69+ m_builder->addConstValue (true );
70+ m_builder->addFunctionCall (" test_print_bool" , Compiler::StaticType::Void, { Compiler::StaticType::Bool });
71+
72+ m_builder->addConstValue (0 );
73+ m_builder->addFunctionCall (" test_print_bool" , Compiler::StaticType::Void, { Compiler::StaticType::Bool });
74+
75+ m_builder->addConstValue (" false" );
76+ m_builder->addFunctionCall (" test_print_bool" , Compiler::StaticType::Void, { Compiler::StaticType::Bool });
77+
78+ m_builder->addConstValue (" 123" );
79+ m_builder->addFunctionCall (" test_print_string" , Compiler::StaticType::Void, { Compiler::StaticType::String });
80+
81+ m_builder->addConstValue (" hello world" );
82+ m_builder->addFunctionCall (" test_print_string" , Compiler::StaticType::Void, { Compiler::StaticType::String });
83+
84+ auto code = m_builder->finalize ();
85+ auto ctx = code->createExecutionContext (&m_target);
86+
87+ static const std::string expected =
88+ " 5.2\n "
89+ " -24.156\n "
90+ " 1\n "
91+ " 0\n "
92+ " 0\n "
93+ " 123\n "
94+ " hello world\n " ;
95+
96+ testing::internal::CaptureStdout ();
97+ code->run (ctx.get ());
98+ ASSERT_EQ (testing::internal::GetCapturedStdout (), expected);
99+ }
100+
101+ TEST_F (LLVMCodeBuilderTest, RawValueCasting)
102+ {
103+ // Number -> number
104+ m_builder->addConstValue (5.2 );
105+ m_builder->addFunctionCall (" test_const_number" , Compiler::StaticType::Number, { Compiler::StaticType::Number });
106+ m_builder->addFunctionCall (" test_print_number" , Compiler::StaticType::Void, { Compiler::StaticType::Number });
107+
108+ // Number -> bool
66109 m_builder->addConstValue (-24.156 );
110+ m_builder->addFunctionCall (" test_const_number" , Compiler::StaticType::Number, { Compiler::StaticType::Number });
111+ m_builder->addFunctionCall (" test_print_bool" , Compiler::StaticType::Void, { Compiler::StaticType::Bool });
112+
113+ m_builder->addConstValue (0 );
114+ m_builder->addFunctionCall (" test_const_number" , Compiler::StaticType::Number, { Compiler::StaticType::Number });
115+ m_builder->addFunctionCall (" test_print_bool" , Compiler::StaticType::Void, { Compiler::StaticType::Bool });
116+
117+ // Number -> string
118+ m_builder->addConstValue (59.8 );
119+ m_builder->addFunctionCall (" test_const_number" , Compiler::StaticType::Number, { Compiler::StaticType::Number });
120+ m_builder->addFunctionCall (" test_print_string" , Compiler::StaticType::Void, { Compiler::StaticType::String });
121+
122+ // Bool -> number
123+ m_builder->addConstValue (true );
124+ m_builder->addFunctionCall (" test_const_bool" , Compiler::StaticType::Bool, { Compiler::StaticType::Bool });
125+ m_builder->addFunctionCall (" test_print_number" , Compiler::StaticType::Void, { Compiler::StaticType::Number });
126+
127+ m_builder->addConstValue (false );
128+ m_builder->addFunctionCall (" test_const_bool" , Compiler::StaticType::Bool, { Compiler::StaticType::Bool });
67129 m_builder->addFunctionCall (" test_print_number" , Compiler::StaticType::Void, { Compiler::StaticType::Number });
68130
131+ // Bool -> bool
69132 m_builder->addConstValue (true );
133+ m_builder->addFunctionCall (" test_const_bool" , Compiler::StaticType::Bool, { Compiler::StaticType::Bool });
70134 m_builder->addFunctionCall (" test_print_bool" , Compiler::StaticType::Void, { Compiler::StaticType::Bool });
71135
72136 m_builder->addConstValue (false );
137+ m_builder->addFunctionCall (" test_const_bool" , Compiler::StaticType::Bool, { Compiler::StaticType::Bool });
138+ m_builder->addFunctionCall (" test_print_bool" , Compiler::StaticType::Void, { Compiler::StaticType::Bool });
139+
140+ // Bool -> string
141+ m_builder->addConstValue (true );
142+ m_builder->addFunctionCall (" test_const_bool" , Compiler::StaticType::Bool, { Compiler::StaticType::Bool });
143+ m_builder->addFunctionCall (" test_print_string" , Compiler::StaticType::Void, { Compiler::StaticType::String });
144+
145+ m_builder->addConstValue (false );
146+ m_builder->addFunctionCall (" test_const_bool" , Compiler::StaticType::Bool, { Compiler::StaticType::Bool });
147+ m_builder->addFunctionCall (" test_print_string" , Compiler::StaticType::Void, { Compiler::StaticType::String });
148+
149+ // String -> number
150+ m_builder->addConstValue (" 5.2" );
151+ m_builder->addFunctionCall (" test_const_string" , Compiler::StaticType::String, { Compiler::StaticType::String });
152+ m_builder->addFunctionCall (" test_print_number" , Compiler::StaticType::Void, { Compiler::StaticType::Number });
153+
154+ // String -> bool
155+ m_builder->addConstValue (" abc" );
156+ m_builder->addFunctionCall (" test_const_string" , Compiler::StaticType::String, { Compiler::StaticType::String });
157+ m_builder->addFunctionCall (" test_print_bool" , Compiler::StaticType::Void, { Compiler::StaticType::Bool });
158+
159+ m_builder->addConstValue (" false" );
160+ m_builder->addFunctionCall (" test_const_string" , Compiler::StaticType::String, { Compiler::StaticType::String });
73161 m_builder->addFunctionCall (" test_print_bool" , Compiler::StaticType::Void, { Compiler::StaticType::Bool });
74162
163+ // String -> string
75164 m_builder->addConstValue (" hello world" );
165+ m_builder->addFunctionCall (" test_const_string" , Compiler::StaticType::String, { Compiler::StaticType::String });
76166 m_builder->addFunctionCall (" test_print_string" , Compiler::StaticType::Void, { Compiler::StaticType::String });
77167
78168 auto code = m_builder->finalize ();
79169 auto ctx = code->createExecutionContext (&m_target);
80170
81171 static const std::string expected =
82172 " 5.2\n "
83- " -24.156\n "
173+ " 1\n "
174+ " 0\n "
175+ " 59.8\n "
176+ " 1\n "
177+ " 0\n "
178+ " 1\n "
179+ " 0\n "
180+ " true\n "
181+ " false\n "
182+ " 5.2\n "
84183 " 1\n "
85184 " 0\n "
86185 " hello world\n " ;
@@ -332,7 +431,7 @@ TEST_F(LLVMCodeBuilderTest, RepeatLoop)
332431
333432 // Count returned by function
334433 m_builder->addConstValue (2 );
335- m_builder->addFunctionCall (" test_const " , Compiler::StaticType::Number, { Compiler::StaticType::Number });
434+ m_builder->addFunctionCall (" test_const_number " , Compiler::StaticType::Number, { Compiler::StaticType::Number });
336435 m_builder->beginRepeatLoop ();
337436 m_builder->addFunctionCall (" test_function_no_args" , Compiler::StaticType::Void, {});
338437 m_builder->endLoop ();
0 commit comments