From 3b80fa05a7b25f523a05558dbb6a550a0b955276 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20=C4=8Cert=C3=ADk?= Date: Fri, 25 Feb 2022 19:25:20 -0700 Subject: [PATCH] Implement i32, i64 in C interop and test it --- integration_tests/test_c_interop_01.py | 15 ++++++++++++++- src/runtime/ltypes/ltypes.py | 4 ++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/integration_tests/test_c_interop_01.py b/integration_tests/test_c_interop_01.py index 8b022bcfb3..20643d7641 100644 --- a/integration_tests/test_c_interop_01.py +++ b/integration_tests/test_c_interop_01.py @@ -1,4 +1,4 @@ -from ltypes import ccall, f64, f32 +from ltypes import ccall, f32, f64, i32, i64 from math import pi @ccall @@ -9,7 +9,20 @@ def _lfortran_dsin(x: f64) -> f64: def _lfortran_ssin(x: f32) -> f32: pass +@ccall +def _lfortran_bgt32(i: i32, j: i32) -> i32: + pass + +@ccall +def _lfortran_bgt64(i: i64, j: i64) -> i64: + pass + assert abs(_lfortran_dsin(pi) - 0) < 1e-12 assert abs(_lfortran_dsin(pi/2) - 1) < 1e-12 assert abs(_lfortran_ssin(pi) - 0) < 1e-6 assert abs(_lfortran_ssin(pi/2) - 1) < 1e-6 + +assert _lfortran_bgt32(3, 4) == 0 +assert _lfortran_bgt32(4, 3) == 1 +assert _lfortran_bgt64(3, 4) == 0 +assert _lfortran_bgt64(4, 3) == 1 diff --git a/src/runtime/ltypes/ltypes.py b/src/runtime/ltypes/ltypes.py index 71cf38d2da..a8aac2a5c5 100644 --- a/src/runtime/ltypes/ltypes.py +++ b/src/runtime/ltypes/ltypes.py @@ -89,6 +89,10 @@ def convert_type_to_ctype(arg): return ctypes.c_double elif arg == f32: return ctypes.c_float + elif arg == i64: + return ctypes.c_int64 + elif arg == i32: + return ctypes.c_int32 else: raise NotImplementedError("Type not implemented") def get_rtlib_dir():