extern variables and object-like macro consts

This commit is contained in:
2026-06-17 21:52:05 +02:00
parent f5605fd3ec
commit 19e9fbdd4b
33 changed files with 3136 additions and 116 deletions
+34
View File
@@ -21,6 +21,37 @@ main :: func() void {
_ = native.imported_apply(double_value, 21)
_ = call_mapper(double_value)
_ = native.configured_value(9)
_ = native.IMPORTED_SHADOW_OBJECT
_ = native.IMPORTED_SHADOW_FUNCTION
native.imported_global = native.IMPORTED_MAGIC
native.imported_record_global.value = native.IMPORTED_MAGIC
color native.Imported_Color :: native.IMPORTED_COLOR
_ = native.imported_check_state(
color,
native.IMPORTED_MAGIC,
native.imported_const_global,
native.imported_global,
native.imported_record_global.value,
native.IMPORTED_OCTAL,
native.IMPORTED_UINT,
native.IMPORTED_REDEFINED,
native.IMPORTED_ACTIVE_AFTER_INACTIVE_UNDEF,
native.IMPORTED_REPEAT,
native.IMPORTED_HEX_E,
native.IMPORTED_NEG_DECIMAL,
native.IMPORTED_NEG_HEX,
native.IMPORTED_NEG_UINT,
native.IMPORTED_FLOAT,
native.IMPORTED_DOUBLE,
)
partial native.Imported_Color :: native.IMPORTED_PARTIAL_COLOR
nested native.Imported_Zero_Outer :: native.IMPORTED_ZERO_NESTED
first_union native.Imported_Zero_Union :: native.IMPORTED_FIRST_UNION
_ = native.imported_check_zero_state(partial, nested, first_union)
native.imported_mutable_array_record.values[0] = 42
_ = native.imported_check_array_record()
conversions native.Imported_Conversions :: native.IMPORTED_CONVERSIONS
_ = native.imported_check_conversions(conversions)
signed i8 :: -2
unsigned u16 :: 3
float_value f32 :: 4.0
@@ -28,4 +59,7 @@ main :: func() void {
pointer *u8 :: "ok".ptr
nullable ?*u8 :: pointer
_ = native.imported_variadic(7, signed, unsigned, float_value, c_float_value, pointer, nullable)
inline_scalar c_int :: native.imported_inline(5)
inline_record native.Imported_Value :: native.imported_inline_record(native.Imported_Value { value = 7 })
_ = native.imported_check_inline(inline_scalar, inline_record.value)
}
+1
View File
@@ -2,5 +2,6 @@
#define BROLANG_CHILD_H
int child_value(int value);
extern int child_shared_global;
#endif
@@ -0,0 +1,6 @@
#ifndef BROLANG_GUARDED_H
#define BROLANG_GUARDED_H
#define IMPORTED_GUARDED 321
#endif
+133 -1
View File
@@ -2,6 +2,15 @@
#define BROLANG_NATIVE_H
#include <child.h>
#include "repeat.h"
#undef IMPORTED_REPEAT
#include "repeat.h"
#include "guarded.h"
#undef IMPORTED_GUARDED
#include "guarded.h"
#include "once.h"
#undef IMPORTED_ONCE
#include "once.h"
typedef int imported_int;
typedef imported_int imported_int_alias;
@@ -11,9 +20,43 @@ typedef int (*Imported_Mapper)(int value);
typedef struct Imported_Value {
int value;
} Imported_Value;
typedef struct Imported_Color {
unsigned char r;
unsigned char g;
unsigned char b;
unsigned char a;
} Imported_Color;
typedef struct Imported_Zero_Inner {
float weight;
int values[2];
const char *label;
} Imported_Zero_Inner;
typedef union Imported_Zero_Union {
int integer;
double decimal;
} Imported_Zero_Union;
typedef struct Imported_Zero_Outer {
int head;
Imported_Zero_Inner inner;
Imported_Zero_Union choice;
} Imported_Zero_Outer;
typedef struct Imported_Array_Record {
int values[2];
} Imported_Array_Record;
typedef struct Imported_Conversions {
unsigned char wrapped;
int truncated;
float from_integer;
double from_float;
const char *pointer;
} Imported_Conversions;
typedef struct Imported_Signed_Narrow {
signed char value;
} Imported_Signed_Narrow;
typedef union Imported_Union {
int value;
} Imported_Union;
typedef int Imported_Const_Array[2];
typedef struct Imported_Bitfield {
unsigned value : 1;
} Imported_Bitfield;
@@ -47,14 +90,103 @@ int imported_read(const Imported_Handle *handle);
int imported_string(const char *value);
int imported_apply(Imported_Mapper mapper, int value);
Imported_Value imported_by_value(Imported_Value value);
int imported_check_state(
Imported_Color color,
int macro_value,
int const_value,
int global_value,
int record_value,
int octal_value,
unsigned int uint_value,
int redefined_value,
int inactive_undef_value,
int repeated_value,
unsigned int hex_e_value,
long negative_decimal_value,
unsigned int negative_hex_value,
unsigned int negative_uint_value,
float float_value,
double double_value
);
int imported_check_zero_state(
Imported_Color partial,
Imported_Zero_Outer nested,
Imported_Zero_Union first_union
);
int imported_check_array_record(void);
int imported_check_conversions(Imported_Conversions value);
int imported_volatile(volatile int *value);
_Bool imported_bool(_Bool value);
extern int imported_global;
extern const int imported_const_global;
extern const int imported_const_array[2];
extern const Imported_Const_Array imported_typedef_const_array;
extern int imported_redeclared_array[];
extern int imported_redeclared_array[4];
extern Imported_Value imported_record_global;
extern const Imported_Array_Record imported_const_array_record;
extern Imported_Array_Record imported_mutable_array_record;
extern _Thread_local int imported_tls_global;
extern int IMPORTED_SHADOW_OBJECT;
int IMPORTED_SHADOW_FUNCTION(void);
extern int IMPORTED_SHADOW_UNSUPPORTED;
extern int IMPORTED_EMPTY_SHADOW;
#define CLITERAL(type) (type)
#define IMPORTED_SHADOW_OBJECT 71
#define IMPORTED_SHADOW_FUNCTION 72
#define IMPORTED_SHADOW_UNSUPPORTED (1 + 2)
#define IMPORTED_MAGIC 42
#define IMPORTED_COLOR CLITERAL(Imported_Color){ 255, 255, 255, 255 }
#define IMPORTED_PARTIAL_COLOR CLITERAL(Imported_Color){ 7 }
#define IMPORTED_ZERO_NESTED CLITERAL(Imported_Zero_Outer){ 5 }
#define IMPORTED_FIRST_UNION CLITERAL(Imported_Zero_Union){ 9 }
#define IMPORTED_CONVERSIONS CLITERAL(Imported_Conversions){ -1, 3.75, 42, 16777217.0f, 0 }
#define IMPORTED_SIGNED_NARROW_BAD CLITERAL(Imported_Signed_Narrow){ 128 }
#define IMPORTED_TOO_MANY_COLOR CLITERAL(Imported_Color){ 1, 2, 3, 4, 5 }
#define IMPORTED_BAD_EXPR (1 + 2)
#define IMPORTED_OCTAL 010
#define IMPORTED_UINT 4294967295U
#define IMPORTED_HEX_E 0xDEADBEEF
#define IMPORTED_NEG_DECIMAL -2147483648
#define IMPORTED_NEG_HEX -0x80000000
#define IMPORTED_NEG_UINT -1U
#define IMPORTED_FLOAT 2.5f
#define IMPORTED_DOUBLE 6.25
#define IMPORTED_FLOAT_OVERFLOW 1e40f
#define IMPORTED_EMPTY_SHADOW
#define IMPORTED_REDEFINED 1
#undef IMPORTED_REDEFINED
#define IMPORTED_REDEFINED 2
#define IMPORTED_GONE 3
#undef IMPORTED_GONE
#define IMPORTED_REDEFINED_BAD 1
#undef IMPORTED_REDEFINED_BAD
#define IMPORTED_REDEFINED_BAD (1 + 2)
#define IMPORTED_ACTIVE_AFTER_INACTIVE_UNDEF 77
#if 0
#undef IMPORTED_ACTIVE_AFTER_INACTIVE_UNDEF
#endif
static inline int imported_inline(int value) {
return value;
return value + 1;
}
static inline Imported_Value imported_inline_record(Imported_Value value) {
Imported_Value result = { value.value * 2 };
return result;
}
static inline int imported_inline_bad_layout(Imported_Packed value) {
return value.first;
}
static inline int imported_inline_variadic(int marker, ...) {
return marker;
}
int imported_check_inline(int scalar, int record);
#ifdef BROLANG_FEATURE
int configured_value(int value);
#endif
+3
View File
@@ -0,0 +1,3 @@
#pragma once
#define IMPORTED_ONCE 456
+1
View File
@@ -0,0 +1 @@
#define IMPORTED_REPEAT 123
+100
View File
@@ -8,6 +8,15 @@ struct Imported_Handle {
};
static struct Imported_Handle handle = {7};
int imported_global = 0;
const int imported_const_global = 9;
const int imported_const_array[2] = {10, 20};
const Imported_Const_Array imported_typedef_const_array = {11, 12};
int imported_redeclared_array[4] = {13, 14, 15, 16};
Imported_Value imported_record_global = {40};
const Imported_Array_Record imported_const_array_record = {{20, 21}};
Imported_Array_Record imported_mutable_array_record = {{0, 1}};
int child_shared_global = 0;
int child_value(int value) {
return value;
@@ -47,6 +56,97 @@ int imported_apply(Imported_Mapper mapper, int value) {
return result;
}
int imported_check_state(
Imported_Color color,
int macro_value,
int const_value,
int global_value,
int record_value,
int octal_value,
unsigned int uint_value,
int redefined_value,
int inactive_undef_value,
int repeated_value,
unsigned int hex_e_value,
long negative_decimal_value,
unsigned int negative_hex_value,
unsigned int negative_uint_value,
float float_value,
double double_value
) {
if (!(color.r == 255 &&
color.g == 255 &&
color.b == 255 &&
color.a == 255 &&
macro_value == 42 &&
const_value == 9 &&
global_value == 42 &&
record_value == 42 &&
octal_value == 8 &&
uint_value == 4294967295U &&
redefined_value == 2 &&
inactive_undef_value == 77 &&
repeated_value == 123 &&
hex_e_value == 0xDEADBEEF &&
negative_decimal_value == -2147483648L &&
negative_hex_value == 0x80000000U &&
negative_uint_value == 0xFFFFFFFFU &&
float_value == 2.5f &&
double_value == 6.25)) {
abort();
}
return 0;
}
int imported_check_zero_state(
Imported_Color partial,
Imported_Zero_Outer nested,
Imported_Zero_Union first_union
) {
if (!(partial.r == 7 &&
partial.g == 0 &&
partial.b == 0 &&
partial.a == 0 &&
nested.head == 5 &&
nested.inner.weight == 0.0f &&
nested.inner.values[0] == 0 &&
nested.inner.values[1] == 0 &&
nested.inner.label == NULL &&
nested.choice.integer == 0 &&
first_union.integer == 9)) {
abort();
}
return 0;
}
int imported_check_array_record(void) {
if (!(imported_const_array_record.values[0] == 20 &&
imported_const_array_record.values[1] == 21 &&
imported_mutable_array_record.values[0] == 42 &&
imported_mutable_array_record.values[1] == 1)) {
abort();
}
return 0;
}
int imported_check_conversions(Imported_Conversions value) {
if (!(value.wrapped == 255 &&
value.truncated == 3 &&
value.from_integer == 42.0f &&
value.from_float == 16777216.0 &&
value.pointer == NULL)) {
abort();
}
return 0;
}
int imported_check_inline(int scalar, int record) {
if (!(scalar == 6 && record == 14)) {
abort();
}
return 0;
}
int imported_variadic(int marker, ...) {
va_list args;
va_start(args, marker);