New type GenericParam represents a generic parameter.

This commit is contained in:
Jason Orendorff
2022-05-07 16:16:42 -05:00
committed by Emilio Cobos Álvarez
parent 13c0a4a2e8
commit c732069b2e
28 changed files with 462 additions and 103 deletions
+17
View File
@@ -0,0 +1,17 @@
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#define TITLE_SIZE 80
typedef int8_t CArrayString_TITLE_SIZE[TITLE_SIZE];
typedef int8_t CArrayString_40[40];
typedef struct Book {
CArrayString_TITLE_SIZE title;
CArrayString_40 author;
} Book;
void root(struct Book *a);
@@ -0,0 +1,25 @@
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#define TITLE_SIZE 80
typedef int8_t CArrayString_TITLE_SIZE[TITLE_SIZE];
typedef int8_t CArrayString_40[40];
typedef struct Book {
CArrayString_TITLE_SIZE title;
CArrayString_40 author;
} Book;
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
void root(struct Book *a);
#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus
+17
View File
@@ -0,0 +1,17 @@
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#define TITLE_SIZE 80
typedef int8_t CArrayString_TITLE_SIZE[TITLE_SIZE];
typedef int8_t CArrayString_40[40];
typedef struct {
CArrayString_TITLE_SIZE title;
CArrayString_40 author;
} Book;
void root(Book *a);
@@ -0,0 +1,25 @@
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#define TITLE_SIZE 80
typedef int8_t CArrayString_TITLE_SIZE[TITLE_SIZE];
typedef int8_t CArrayString_40[40];
typedef struct {
CArrayString_TITLE_SIZE title;
CArrayString_40 author;
} Book;
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
void root(Book *a);
#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus
+21
View File
@@ -0,0 +1,21 @@
#include <cstdarg>
#include <cstdint>
#include <cstdlib>
#include <ostream>
#include <new>
constexpr static const uintptr_t TITLE_SIZE = 80;
template<uintptr_t CAP>
using CArrayString = int8_t[CAP];
struct Book {
CArrayString<TITLE_SIZE> title;
CArrayString<40> author;
};
extern "C" {
void root(Book *a);
} // extern "C"
+19
View File
@@ -0,0 +1,19 @@
from libc.stdint cimport int8_t, int16_t, int32_t, int64_t, intptr_t
from libc.stdint cimport uint8_t, uint16_t, uint32_t, uint64_t, uintptr_t
cdef extern from *:
ctypedef bint bool
ctypedef struct va_list
cdef extern from *:
const uintptr_t TITLE_SIZE # = 80
ctypedef int8_t CArrayString_TITLE_SIZE[TITLE_SIZE];
ctypedef int8_t CArrayString_40[40];
ctypedef struct Book:
CArrayString_TITLE_SIZE title;
CArrayString_40 author;
void root(Book *a);
+17
View File
@@ -0,0 +1,17 @@
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#define TITLE_SIZE 80
typedef int8_t CArrayString_TITLE_SIZE[TITLE_SIZE];
typedef int8_t CArrayString_40[40];
struct Book {
CArrayString_TITLE_SIZE title;
CArrayString_40 author;
};
void root(struct Book *a);
@@ -0,0 +1,25 @@
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#define TITLE_SIZE 80
typedef int8_t CArrayString_TITLE_SIZE[TITLE_SIZE];
typedef int8_t CArrayString_40[40];
struct Book {
CArrayString_TITLE_SIZE title;
CArrayString_40 author;
};
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
void root(struct Book *a);
#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus
+19
View File
@@ -0,0 +1,19 @@
from libc.stdint cimport int8_t, int16_t, int32_t, int64_t, intptr_t
from libc.stdint cimport uint8_t, uint16_t, uint32_t, uint64_t, uintptr_t
cdef extern from *:
ctypedef bint bool
ctypedef struct va_list
cdef extern from *:
const uintptr_t TITLE_SIZE # = 80
ctypedef int8_t CArrayString_TITLE_SIZE[TITLE_SIZE];
ctypedef int8_t CArrayString_40[40];
cdef struct Book:
CArrayString_TITLE_SIZE title;
CArrayString_40 author;
void root(Book *a);
@@ -0,0 +1,11 @@
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
typedef struct ArrayVec_____u8__100 {
uint8_t *xs[100];
uint32_t len;
} ArrayVec_____u8__100;
int32_t push(struct ArrayVec_____u8__100 *v, uint8_t *elem);
@@ -0,0 +1,19 @@
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
typedef struct ArrayVec_____u8__100 {
uint8_t *xs[100];
uint32_t len;
} ArrayVec_____u8__100;
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
int32_t push(struct ArrayVec_____u8__100 *v, uint8_t *elem);
#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus
@@ -0,0 +1,11 @@
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
typedef struct {
uint8_t *xs[100];
uint32_t len;
} ArrayVec_____u8__100;
int32_t push(ArrayVec_____u8__100 *v, uint8_t *elem);
@@ -0,0 +1,19 @@
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
typedef struct {
uint8_t *xs[100];
uint32_t len;
} ArrayVec_____u8__100;
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
int32_t push(ArrayVec_____u8__100 *v, uint8_t *elem);
#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus
@@ -0,0 +1,17 @@
#include <cstdarg>
#include <cstdint>
#include <cstdlib>
#include <ostream>
#include <new>
template<typename T, uintptr_t CAP>
struct ArrayVec {
T xs[CAP];
uint32_t len;
};
extern "C" {
int32_t push(ArrayVec<uint8_t*, 100> *v, uint8_t *elem);
} // extern "C"
@@ -0,0 +1,13 @@
from libc.stdint cimport int8_t, int16_t, int32_t, int64_t, intptr_t
from libc.stdint cimport uint8_t, uint16_t, uint32_t, uint64_t, uintptr_t
cdef extern from *:
ctypedef bint bool
ctypedef struct va_list
cdef extern from *:
ctypedef struct ArrayVec_____u8__100:
uint8_t *xs[100];
uint32_t len;
int32_t push(ArrayVec_____u8__100 *v, uint8_t *elem);
@@ -0,0 +1,11 @@
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
struct ArrayVec_____u8__100 {
uint8_t *xs[100];
uint32_t len;
};
int32_t push(struct ArrayVec_____u8__100 *v, uint8_t *elem);
@@ -0,0 +1,19 @@
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
struct ArrayVec_____u8__100 {
uint8_t *xs[100];
uint32_t len;
};
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
int32_t push(struct ArrayVec_____u8__100 *v, uint8_t *elem);
#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus
@@ -0,0 +1,13 @@
from libc.stdint cimport int8_t, int16_t, int32_t, int64_t, intptr_t
from libc.stdint cimport uint8_t, uint16_t, uint32_t, uint64_t, uintptr_t
cdef extern from *:
ctypedef bint bool
ctypedef struct va_list
cdef extern from *:
cdef struct ArrayVec_____u8__100:
uint8_t *xs[100];
uint32_t len;
int32_t push(ArrayVec_____u8__100 *v, uint8_t *elem);
+15
View File
@@ -0,0 +1,15 @@
#[repr(transparent)]
pub struct CArrayString<const CAP: usize> {
pub chars: [i8; CAP],
}
pub const TITLE_SIZE: usize = 80;
#[repr(C)]
pub struct Book {
pub title: CArrayString<TITLE_SIZE>,
pub author: CArrayString<40>,
}
#[no_mangle]
pub extern "C" fn root(a: *mut Book) {}
+17
View File
@@ -0,0 +1,17 @@
#[repr(C)]
pub struct ArrayVec<T, const CAP: usize> {
// the `len` first elements of the array are initialized
xs: [T; CAP],
len: u32,
}
#[no_mangle]
pub unsafe extern "C" fn push(v: *mut ArrayVec<*mut u8, 100>, elem: *mut u8) -> i32 {
if (*v).len < 100 {
(*v).xs[(*v).len] = elem;
(*v).len += 1;
1
} else {
0
}
}