Skip to content

Commit 963e6e6

Browse files
committed
Support _Bool as primitive type
1 parent 7ae9c0e commit 963e6e6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+584
-24
lines changed

doc/internals-target.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ A machine target is specified by filling in a '''machine_spec''' structure, defi
99
* machine_name: name of the target
1010
* handle_option: a function that gets to inspect options passed to nesc1 and take appropriate action (example: the '''self''' target adjusts double alignment based on the -malign-double gcc flag).
1111
* big_endian: must be true for big-endian targets, false for little-endian ones
12-
* tptr, tfloat, tdouble, tlong_double, tshort, tint, tlong, tlong_long: size and alignment of the corresponding C types.
12+
* tptr, tfloat, tdouble, tlong_double, tshort, tint, tlong, tlong_long, t_Bool: size and alignment of the corresponding C types.
1313
* int1_align, int2_align, int4_align, int8_align: with gcc, you can ask for specific size ints (see gcc's mode attribute, and the '''type_for_mode''' function in types.c). On some platforms, some of these sizes may not correspond to any of the normal basic C types, so you get to specify the alignments for those missing sizes here...
1414
* wchar_t_size: size of the wchar_t type
1515
* size_t_size: size of the size_t type (actually this should be the C type, knowing just the size can cause problems)

nregress/c99c11/boolarg/BoolTest.nc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
interface BoolTest {
2+
command void test(const char *test_name, const _Bool arg);
3+
event void testDone(const char *test_name, _Bool result, _Bool arg);
4+
}

nregress/c99c11/boolarg/BoolTestM.nc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module BoolTestM {
2+
provides interface BoolTest;
3+
}
4+
implementation {
5+
command void BoolTest.test(const char *test_name, const _Bool arg) {
6+
signal BoolTest.testDone(test_name, !arg, arg);
7+
}
8+
}

nregress/c99c11/boolarg/TestP.nc

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
extern int printf(const char *__restrict format, ...);
2+
3+
typedef struct {
4+
_Bool a;
5+
} bool_test_args;
6+
7+
nx_struct nx_header {
8+
nx_uint32_t src;
9+
nx_uint32_t dst;
10+
};
11+
12+
module TestP {
13+
uses interface BoolTest;
14+
}
15+
implementation {
16+
int main() @C() @spontaneous() {
17+
#define do_test(test_name, bool_expr) call BoolTest.test(#test_name, bool_expr)
18+
19+
do_test(TrueConst, 1);
20+
do_test(TrueExpr, 1 == 1 && 0 < 1);
21+
do_test(TrueExprSC, 0 == 0 || 0 > 1);
22+
do_test(IntTrue, 1234);
23+
do_test(FloatTrue, 1.23);
24+
do_test(String, "string");
25+
26+
do_test(FalseConst, 0);
27+
do_test(FalseExpr, 0 == 1 || 0 > 1);
28+
do_test(FalseExprSC, 1 == 0 && 0 < 1);
29+
do_test(IntZero, 0);
30+
do_test(FloatZero, 0.0);
31+
do_test(NullVoid, (const void *)0);
32+
do_test(NullULL, (unsigned long long *)0);
33+
do_test(NullStruct, (const bool_test_args *const __restrict)0);
34+
do_test(NullFnP, (int (*)(char[], double))0);
35+
do_test(Network, (nx_uint32_t *)0);
36+
do_test(NetworkStruct, (nx_struct nx_header *)0);
37+
#undef do_test
38+
39+
return 0;
40+
}
41+
42+
event void BoolTest.testDone(const char *test_name, _Bool result, _Bool arg) {
43+
printf("%15s: %d -> %d\n", test_name, arg, result);
44+
}
45+
}

nregress/c99c11/boolarg/test.nc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
configuration test {
2+
}
3+
implementation {
4+
components TestP, BoolTestM;
5+
6+
TestP.BoolTest -> BoolTestM;
7+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
typedef struct {
2+
_Bool a:1;
3+
_Bool b;
4+
} bool_test_args;
5+
6+
interface BoolTest {
7+
command void unary(const _Bool a);
8+
command void binary(const bool_test_args args);
9+
event void unaryDone(const char *test_name, _Bool result, _Bool arg);
10+
event void binaryDone(const char *test_name, _Bool result, bool_test_args args);
11+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
generic module BoolTestM(_Bool val, char test_name[]) {
2+
provides interface BoolTest;
3+
}
4+
implementation {
5+
command void BoolTest.unary(const _Bool a) {
6+
const _Bool result = val ? a : !a;
7+
signal BoolTest.unaryDone(test_name, result, a);
8+
}
9+
10+
command void BoolTest.binary(const bool_test_args args) {
11+
const _Bool xor = args.a ^ args.b;
12+
const _Bool result = val ? xor : !xor;
13+
signal BoolTest.binaryDone(test_name, result, args);
14+
}
15+
}

nregress/c99c11/boolgeneric/TestP.nc

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
extern int printf(const char *__restrict format, ...);
2+
3+
module TestP {
4+
uses interface BoolTest;
5+
}
6+
implementation {
7+
int main() @C() @spontaneous() {
8+
bool_test_args args;
9+
10+
call BoolTest.unary(0);
11+
call BoolTest.unary(1);
12+
args.a = args.b = 0;
13+
call BoolTest.binary(args);
14+
args.b = 1;
15+
call BoolTest.binary(args);
16+
args.a = 1; args.b = 0;
17+
call BoolTest.binary(args);
18+
args.a = args.b = 1;
19+
call BoolTest.binary(args);
20+
21+
return 0;
22+
}
23+
24+
event void BoolTest.unaryDone(const char *test_name, _Bool result, _Bool arg) {
25+
printf("%15s: %d -> %d\n", test_name, arg, result);
26+
}
27+
28+
event void BoolTest.binaryDone(const char *test_name, _Bool result, bool_test_args args) {
29+
printf("%15s: %d, %d -> %d\n", test_name, args.a, args.b, result);
30+
}
31+
}

nregress/c99c11/boolgeneric/test.nc

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
nx_struct nx_header {
2+
nx_uint32_t src;
3+
nx_uint32_t dst;
4+
};
5+
6+
configuration test {
7+
}
8+
implementation {
9+
components TestP;
10+
#define define_test(test_name, bool_expr) \
11+
components new BoolTestM(bool_expr, #test_name) as Test##test_name; \
12+
Test##test_name <- TestP.BoolTest
13+
14+
define_test(TrueConst, 1);
15+
define_test(TrueExpr, 1 == 1 && 0 < 1);
16+
define_test(TrueExprSC, 0 == 0 || 0 > 1);
17+
define_test(IntTrue, 1234);
18+
define_test(FloatTrue, 1.23);
19+
define_test(String, "string");
20+
21+
define_test(FalseConst, 0);
22+
define_test(FalseExpr, 0 == 1 || 0 > 1);
23+
define_test(FalseExprSC, 1 == 0 && 0 < 1);
24+
define_test(IntZero, 0);
25+
define_test(FloatZero, 0.0);
26+
define_test(NullVoid, (const void *)0);
27+
define_test(NullULL, (unsigned long long *)0);
28+
define_test(NullStruct, (const bool_test_args *const __restrict)0);
29+
define_test(NullFnP, (int (*)(char[], double))0);
30+
define_test(Network, (nx_uint32_t *)0);
31+
define_test(NetworkStruct, (nx_struct nx_header *)0);
32+
33+
#undef define_test
34+
}

nregress/c99c11/boolinit/BoolInit.nc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
interface BoolInit {
2+
command void test();
3+
event void testDone(const char *test_name, _Bool value);
4+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
interface BoolReturn {
2+
command _Bool get();
3+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module NegativeIntM {
2+
provides {
3+
interface BoolInit;
4+
interface BoolReturn;
5+
}
6+
}
7+
implementation {
8+
_Bool value = -9876;
9+
10+
command void BoolInit.test() {
11+
signal BoolInit.testDone("NegativeInt", value);
12+
}
13+
14+
command _Bool BoolReturn.get() {
15+
return -9876;
16+
}
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module NoneZeroFloatM {
2+
provides {
3+
interface BoolInit;
4+
interface BoolReturn;
5+
}
6+
}
7+
implementation {
8+
_Bool value = 3.456;
9+
10+
command void BoolInit.test() {
11+
signal BoolInit.testDone("NonZeroFloat", value);
12+
}
13+
14+
command _Bool BoolReturn.get() {
15+
return 3.456;
16+
}
17+
}

nregress/c99c11/boolinit/NullM.nc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module NullM {
2+
provides {
3+
interface BoolInit;
4+
interface BoolReturn;
5+
}
6+
}
7+
implementation {
8+
_Bool value = (void *)0;
9+
10+
command void BoolInit.test() {
11+
signal BoolInit.testDone("Null", value);
12+
}
13+
14+
command _Bool BoolReturn.get() {
15+
return (void *)0;
16+
}
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module PositiveIntM {
2+
provides {
3+
interface BoolInit;
4+
interface BoolReturn;
5+
}
6+
}
7+
implementation {
8+
_Bool value = (unsigned int)1234;
9+
10+
command void BoolInit.test() {
11+
signal BoolInit.testDone("PositiveInt", value);
12+
}
13+
14+
command _Bool BoolReturn.get() {
15+
return (unsigned int)1234;
16+
}
17+
}

nregress/c99c11/boolinit/StringM.nc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
module StringM {
2+
provides {
3+
interface BoolInit;
4+
interface BoolReturn;
5+
}
6+
}
7+
implementation {
8+
static const char string[] = "string";
9+
_Bool value = &string;
10+
11+
command void BoolInit.test() {
12+
signal BoolInit.testDone("String", value);
13+
}
14+
15+
command _Bool BoolReturn.get() {
16+
return "string";
17+
}
18+
}

nregress/c99c11/boolinit/TestP.nc

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
extern int printf(const char *__restrict __format, ...);
2+
3+
module TestP {
4+
uses {
5+
interface BoolInit;
6+
interface BoolReturn as ZeroInt;
7+
interface BoolReturn as PositiveInt;
8+
interface BoolReturn as NegativeInt;
9+
interface BoolReturn as ZeroFloat;
10+
interface BoolReturn as NoneZeroFloat;
11+
interface BoolReturn as String;
12+
interface BoolReturn as Null;
13+
}
14+
}
15+
implementation {
16+
static void testDone(const char *test_name, _Bool value) {
17+
printf("%15s: %d\n", test_name, value);
18+
}
19+
20+
int main() @C() @spontaneous() {
21+
printf("===== BoolInit =====\n");
22+
call BoolInit.test();
23+
24+
#define do_test(test_name) \
25+
testDone(#test_name, call test_name.get())
26+
27+
printf("===== BoolReturn =====\n");
28+
do_test(ZeroInt);
29+
do_test(ZeroFloat);
30+
do_test(Null);
31+
32+
do_test(PositiveInt);
33+
do_test(NegativeInt);
34+
do_test(NoneZeroFloat);
35+
do_test(String);
36+
37+
#undef do_test
38+
39+
return 0;
40+
}
41+
42+
event void BoolInit.testDone(const char *test_name, _Bool value) {
43+
testDone(test_name, value);
44+
}
45+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module ZeroFloatM {
2+
provides {
3+
interface BoolInit;
4+
interface BoolReturn;
5+
}
6+
}
7+
implementation {
8+
_Bool value = 0.00;
9+
10+
command void BoolInit.test() {
11+
signal BoolInit.testDone("ZeroFloat", value);
12+
}
13+
14+
command _Bool BoolReturn.get() {
15+
return 0.00;
16+
}
17+
}

nregress/c99c11/boolinit/ZeroIntM.nc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module ZeroIntM {
2+
provides {
3+
interface BoolInit;
4+
interface BoolReturn;
5+
}
6+
}
7+
implementation {
8+
_Bool value = 0;
9+
10+
command void BoolInit.test() {
11+
signal BoolInit.testDone("ZeroInt", value);
12+
}
13+
14+
command _Bool BoolReturn.get() {
15+
return 0;
16+
}
17+
}

nregress/c99c11/boolinit/test.nc

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
configuration test {
2+
}
3+
implementation {
4+
components TestP;
5+
6+
#define define_test(test_name) \
7+
components test_name##M; \
8+
test_name##M <- TestP.BoolInit; \
9+
test_name##M <- TestP.test_name
10+
11+
define_test(ZeroInt);
12+
define_test(ZeroFloat);
13+
define_test(Null);
14+
15+
define_test(PositiveInt);
16+
define_test(NegativeInt);
17+
define_test(NoneZeroFloat);
18+
define_test(String);
19+
20+
#undef define_test
21+
}

nregress/c99c11/run1

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
keep=
2-
if [ -z "$NESC1" ]; then
3-
NESC1=../../../src/nesc1
4-
keep=1
5-
fi
1+
[ -z "$NESC1" ] && keep=1
2+
: ${NESC:=../../..}
3+
: ${TOOLS:=$NESC/tools}
4+
: ${NESC1:=../../../src/nesc1}
65
cd $1
76
cfile=/tmp/c99c11.$$.c
87
exe=/tmp/c99c11.out.$$
9-
$NESC1 -fnesc-separator=__ test.nc -o $cfile && \
8+
$NESC1 -fnesc-separator=__ -I$TOOLS -fnesc-include=deputy_nodeputy -fnesc-include=nesc_nx test.nc -o $cfile && \
109
gcc -Wall -g -o $exe $cfile && \
1110
$exe
1211
ok=$?

0 commit comments

Comments
 (0)