Initial version

This commit is contained in:
Ganesh Viswanathan 2018-11-20 03:01:04 -06:00
commit 9787797d15
14 changed files with 826 additions and 0 deletions

33
tests/include/test.c Normal file
View file

@ -0,0 +1,33 @@
#include "test.h"
int test_call_int() {
return 5;
}
struct STRUCT1 test_call_int_param(int param1) {
struct STRUCT1 s;
s.field1 = param1;
return s;
}
STRUCT2 test_call_int_param2(int param1, STRUCT2 param2) {
STRUCT2 s;
s.field1 = param1 + param2.field1;
return s;
}
STRUCT2 test_call_int_param3(int param1, struct STRUCT1 param2) {
STRUCT2 s;
s.field1 = param1 + param2.field1;
return s;
}
ENUM2 test_call_int_param4(enum ENUM param1) {
return enum4;
}

36
tests/include/test.h Normal file
View file

@ -0,0 +1,36 @@
#include <stdint.h>
#define TEST_INT 512
#define TEST_FLOAT 5.12
#define TEST_HEX 0x512
typedef uint8_t PRIMTYPE;
typedef PRIMTYPE CUSTTYPE;
struct STRUCT1 {
int field1;
};
typedef struct STRUCT1 STRUCT2;
typedef struct {
int field1;
} STRUCT3;
enum ENUM {
enum1,
enum2,
enum3
};
typedef enum {
enum4 = 3,
enum5,
enum6
} ENUM2;
int test_call_int();
struct STRUCT1 test_call_int_param(int param1);
STRUCT2 test_call_int_param2(int param1, STRUCT2 param2);
STRUCT2 test_call_int_param3(int param1, struct STRUCT1 param2);
ENUM2 test_call_int_param4(enum ENUM param1);

39
tests/tnimterop.nim Normal file
View file

@ -0,0 +1,39 @@
import nimterop/cimport
import macros
cDebug()
cIncludeDir("include")
cCompile("test.c")
cImport("test.h")
assert TEST_INT == 512
assert TEST_FLOAT == 5.12
assert TEST_HEX == 0x512
var
pt: PRIMTYPE
ct: CUSTTYPE
s: STRUCT1
s2: STRUCT2
s3: STRUCT3
e: ENUM
e2: ENUM2 = enum5
pt = 3
ct = 4
s.field1 = 5
s2.field1 = 6
s3.field1 = 7
e = enum1
e2 = enum4
assert test_call_int() == 5
assert test_call_int_param(5).field1 == 5
assert test_call_int_param2(5, s2).field1 == 11
assert test_call_int_param3(5, s).field1 == 10
assert test_call_int_param4(e) == e2