restricted c header imports
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
native :: import "../include/native.h"
|
||||
|
||||
pass_alias :: func(value native.imported_int_alias) native.imported_int {
|
||||
return value
|
||||
}
|
||||
|
||||
main :: func() void {
|
||||
_ = native.imported_add(pass_alias(20), 22)
|
||||
_ = native.imported_scalar(3, 4)
|
||||
_ = native.child_value(7)
|
||||
_ = native.imported_read(native.imported_handle()?)
|
||||
_ = native.configured_value(9)
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
#ifndef BROLANG_CHILD_H
|
||||
#define BROLANG_CHILD_H
|
||||
|
||||
int child_value(int value);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,40 @@
|
||||
#ifndef BROLANG_NATIVE_H
|
||||
#define BROLANG_NATIVE_H
|
||||
|
||||
#include <child.h>
|
||||
|
||||
typedef int imported_int;
|
||||
typedef imported_int imported_int_alias;
|
||||
typedef struct Imported_Handle Imported_Handle;
|
||||
typedef void (*Imported_Callback)(int value);
|
||||
typedef struct Imported_Value {
|
||||
int value;
|
||||
} Imported_Value;
|
||||
typedef union Imported_Union {
|
||||
int value;
|
||||
} Imported_Union;
|
||||
typedef enum Imported_Enum {
|
||||
IMPORTED_ENUM_VALUE,
|
||||
} Imported_Enum;
|
||||
|
||||
int imported_add(imported_int_alias left, int right);
|
||||
unsigned long imported_scalar(unsigned char value, unsigned long extra);
|
||||
Imported_Handle *imported_handle(void);
|
||||
int imported_read(const Imported_Handle *handle);
|
||||
Imported_Value imported_by_value(Imported_Value value);
|
||||
int imported_volatile(volatile int *value);
|
||||
_Bool imported_bool(_Bool value);
|
||||
extern int imported_global;
|
||||
|
||||
static inline int imported_inline(int value) {
|
||||
return value;
|
||||
}
|
||||
|
||||
#ifdef BROLANG_FEATURE
|
||||
int configured_value(int value);
|
||||
#endif
|
||||
|
||||
#define IMPORTED_MACRO 42
|
||||
int imported_variadic(const char *format, ...);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,33 @@
|
||||
#include "include/native.h"
|
||||
|
||||
struct Imported_Handle {
|
||||
int value;
|
||||
};
|
||||
|
||||
static struct Imported_Handle handle = {7};
|
||||
|
||||
int child_value(int value) {
|
||||
return value;
|
||||
}
|
||||
|
||||
int imported_add(imported_int left, int right) {
|
||||
return left + right;
|
||||
}
|
||||
|
||||
unsigned long imported_scalar(unsigned char value, unsigned long extra) {
|
||||
return value + extra;
|
||||
}
|
||||
|
||||
Imported_Handle *imported_handle(void) {
|
||||
return &handle;
|
||||
}
|
||||
|
||||
int imported_read(const Imported_Handle *value) {
|
||||
return value->value;
|
||||
}
|
||||
|
||||
#ifdef BROLANG_FEATURE
|
||||
int configured_value(int value) {
|
||||
return value;
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,4 @@
|
||||
first :: import "../header/include/native.h"
|
||||
second :: import "../header/include/native.h"
|
||||
|
||||
main :: func() void {}
|
||||
@@ -0,0 +1,7 @@
|
||||
native :: import "../header/include/native.h"
|
||||
child :: import "../header/include/child.h"
|
||||
|
||||
main :: func() void {
|
||||
_ = native.child_value(1)
|
||||
_ = child.child_value(2)
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
native :: import "../header/include/native.h"
|
||||
|
||||
use_callback :: c_func(value native.Imported_Callback) void
|
||||
use_union :: c_func(value native.Imported_Union) void
|
||||
use_enum :: c_func(value native.Imported_Enum) void
|
||||
|
||||
main :: func() void {
|
||||
_ = native.imported_variadic("value")
|
||||
_ = native.IMPORTED_MACRO
|
||||
_ = native.imported_by_value()
|
||||
_ = native.imported_volatile()
|
||||
_ = native.imported_bool()
|
||||
_ = native.imported_global
|
||||
_ = native.imported_inline(1)
|
||||
}
|
||||
Reference in New Issue
Block a user