forked from lcompilers/lpython
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix passing
ArrayItem
, StructInstanceMember
to BindC functions (
- Loading branch information
Showing
6 changed files
with
64 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from ltypes import i32, f64, ccall, dataclass | ||
from numpy import empty, int32, float64 | ||
|
||
@dataclass | ||
class CompareOperator: | ||
op_code: i32 | ||
op_name: str | ||
|
||
@ccall | ||
def compare_array_element(value1: i32, value2: f64, op: i32) -> i32: | ||
pass | ||
|
||
def test_arrays(): | ||
array1: i32[40] = empty(40, dtype=int32) | ||
array2: f64[40] = empty(40, dtype=float64) | ||
compare_operator: CompareOperator = CompareOperator(0, "<") | ||
i: i32 | ||
|
||
for i in range(40): | ||
array1[i] = i + 1 | ||
array2[i] = float(2*i + 1) | ||
|
||
is_small: bool = True | ||
for i in range(40): | ||
is_small = is_small and bool(compare_array_element(array1[i], array2[i], compare_operator.op_code)) | ||
|
||
print(is_small) | ||
assert is_small == True | ||
|
||
test_arrays() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#include "bindc_06b.h" | ||
|
||
int32_t compare_array_element(int32_t value1, double value2, int32_t code) { | ||
switch( code ) { | ||
case 0: | ||
return value1 <= value2; | ||
case 1: | ||
return value1 >= value2; | ||
default: | ||
return 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#include <inttypes.h> | ||
|
||
int32_t compare_array_element(int32_t value1, double value2, int32_t code); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters