Skip to content

Commit fc08c06

Browse files
authored
Merge pull request #1216 from Smit-create/c3
Enable more C tests
2 parents a31b213 + 2e87b99 commit fc08c06

File tree

5 files changed

+16
-6
lines changed

5 files changed

+16
-6
lines changed

integration_tests/CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,15 +165,15 @@ RUN(NAME expr_05 LABELS cpython llvm c)
165165
RUN(NAME expr_06 LABELS cpython llvm c)
166166
RUN(NAME expr_07 LABELS cpython llvm c)
167167
RUN(NAME expr_08 LABELS llvm c)
168-
RUN(NAME expr_09 LABELS cpython llvm)
168+
RUN(NAME expr_09 LABELS cpython llvm c)
169169
RUN(NAME expr_10 LABELS cpython llvm c)
170170
RUN(NAME expr_11 LABELS cpython llvm c wasm)
171171
RUN(NAME expr_12 LABELS llvm c)
172172
RUN(NAME expr_13 LABELS llvm c
173173
EXTRAFILES expr_13b.c)
174174
RUN(NAME loop_01 LABELS cpython llvm c)
175175
RUN(NAME print_02 LABELS cpython llvm)
176-
RUN(NAME test_types_01 LABELS cpython llvm)
176+
RUN(NAME test_types_01 LABELS cpython llvm c)
177177
RUN(NAME test_str_01 LABELS cpython llvm c)
178178
RUN(NAME test_str_02 LABELS cpython llvm c)
179179
RUN(NAME test_str_03 LABELS cpython llvm c)
@@ -222,7 +222,7 @@ RUN(NAME test_builtin_abs LABELS cpython llvm c)
222222
RUN(NAME test_builtin_bool LABELS cpython llvm c)
223223
RUN(NAME test_builtin_pow LABELS cpython llvm)
224224
RUN(NAME test_builtin_int LABELS cpython llvm c)
225-
RUN(NAME test_builtin_len LABELS cpython llvm)
225+
RUN(NAME test_builtin_len LABELS cpython llvm c)
226226
RUN(NAME test_builtin_str LABELS cpython llvm c)
227227
RUN(NAME test_builtin_oct LABELS cpython llvm c)
228228
RUN(NAME test_builtin_hex LABELS cpython llvm c)
@@ -293,7 +293,7 @@ RUN(NAME generics_array_02 LABELS cpython llvm)
293293
RUN(NAME generics_array_03 LABELS cpython llvm)
294294
RUN(NAME generics_list_01 LABELS cpython llvm)
295295
RUN(NAME test_statistics LABELS cpython llvm)
296-
RUN(NAME test_str_attributes LABELS cpython llvm)
296+
RUN(NAME test_str_attributes LABELS cpython llvm c)
297297
RUN(NAME kwargs_01 LABELS cpython llvm)
298298
RUN(NAME test_01_goto LABELS cpython llvm c)
299299

src/libasr/codegen/asr_to_c_cpp.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,11 @@ R"(#include <stdio.h>
582582

583583
void visit_StringOrd(const ASR::StringOrd_t& x) {
584584
self().visit_expr(*x.m_arg);
585-
src = "(int)" + src + "[0]";
585+
if (ASR::is_a<ASR::StringConstant_t>(*x.m_arg)) {
586+
src = "(int)" + src + "[0]";
587+
} else {
588+
src = "_lfortran_str_ord_c(" + src + ")";
589+
}
586590
}
587591

588592
void visit_StringRepeat(const ASR::StringRepeat_t &x) {

src/libasr/runtime/lfortran_intrinsics.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -873,6 +873,11 @@ LFORTRAN_API int _lfortran_str_ord(char** s)
873873
return (*s)[0];
874874
}
875875

876+
LFORTRAN_API int _lfortran_str_ord_c(char* s)
877+
{
878+
return s[0];
879+
}
880+
876881
LFORTRAN_API char* _lfortran_str_chr(int val)
877882
{
878883
char* dest_char = (char*)malloc(2);

src/libasr/runtime/lfortran_intrinsics.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ LFORTRAN_API char* _lfortran_strrepeat_c(char* s, int32_t n);
159159
LFORTRAN_API void _lfortran_strcat(char** s1, char** s2, char** dest);
160160
LFORTRAN_API int _lfortran_str_len(char** s);
161161
LFORTRAN_API int _lfortran_str_ord(char** s);
162+
LFORTRAN_API int _lfortran_str_ord_c(char* s);
162163
LFORTRAN_API char* _lfortran_str_chr(int c);
163164
LFORTRAN_API int _lfortran_str_to_int(char** s);
164165
LFORTRAN_API char* _lfortran_malloc(int size);

src/runtime/lpython_builtin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ def _lpython_str_lower(x: str) -> str:
641641
def _lpython_str_find(s: str, sub: str) -> i32:
642642
s_len :i32; sub_len :i32; flag: bool; _len: i32;
643643
res: i32; i: i32;
644-
lps: list[i32]
644+
lps: list[i32] = []
645645
s_len = len(s)
646646
sub_len = len(sub)
647647
flag = False

0 commit comments

Comments
 (0)