Skip to content

Commit 59384a9

Browse files
committed
Support _Bool as primitive type
1 parent 7ae9c0e commit 59384a9

26 files changed

+202
-10
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/bool/BoolDone.nc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include "BoolTest.h"
2+
3+
interface BoolDone {
4+
event void unaryDone(bool result, bool arg);
5+
event void binaryDone(bool result, bool_test_args args);
6+
}

nregress/c99c11/bool/BoolDoneM.nc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include <stdio.h>
2+
3+
#include "BoolTest.h"
4+
5+
generic module BoolDoneM(const char testName[]) {
6+
uses interface BoolDone;
7+
}
8+
implementation {
9+
event void BoolDone.unaryDone(bool result, bool arg) {
10+
printf("%10s: %d -> %d\n", testName, arg, result);
11+
}
12+
13+
event void BoolDone.binaryDone(bool result, bool_test_args args) {
14+
printf("%10s: %d, %d -> %d\n", testName, args.a, args.b, result);
15+
}
16+
}

nregress/c99c11/bool/BoolTest.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#ifndef __BOOL_TEST_H__
2+
#define __BOOL_TEST_H__
3+
4+
#include <stdbool.h>
5+
6+
typedef struct {
7+
bool a:1;
8+
bool b;
9+
} bool_test_args;
10+
11+
#endif

nregress/c99c11/bool/BoolTest.nc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include "BoolTest.h"
2+
3+
interface BoolTest {
4+
command void unary(const bool a);
5+
command void binary(const bool_test_args args);
6+
}

nregress/c99c11/bool/BoolTestM.nc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#include "BoolTest.h"
2+
3+
generic module BoolTestM(bool val) {
4+
provides interface BoolTest;
5+
provides interface BoolDone;
6+
}
7+
implementation {
8+
command void BoolTest.unary(const bool a) {
9+
const bool result = val ? a : !a;
10+
signal BoolDone.unaryDone(result, a);
11+
}
12+
13+
command void BoolTest.binary(const bool_test_args args) {
14+
const bool result = val ? args.a ^ args.b
15+
: !(args.a ^ args.b);
16+
signal BoolDone.binaryDone(result, args);
17+
}
18+
}

nregress/c99c11/bool/TestP.nc

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include <stdio.h>
2+
3+
#include "BoolTest.h"
4+
5+
module TestP {
6+
uses interface BoolTest;
7+
}
8+
implementation {
9+
int main() @C() @spontaneous() {
10+
bool_test_args args;
11+
12+
call BoolTest.unary(false);
13+
call BoolTest.unary(true);
14+
args.a = args.b = false;
15+
call BoolTest.binary(args);
16+
args.b = true;
17+
call BoolTest.binary(args);
18+
args.a = true; args.b = false;
19+
call BoolTest.binary(args);
20+
args.a = args.b = true;
21+
call BoolTest.binary(args);
22+
23+
return 0;
24+
}
25+
}

nregress/c99c11/bool/test.nc

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include "BoolTest.h"
2+
3+
#include <stddef.h>
4+
5+
configuration test {
6+
}
7+
implementation {
8+
components TestP;
9+
#define define_test(test_name, bool_expr) \
10+
components new BoolTestM(bool_expr) as Test##test_name; \
11+
components new BoolDoneM(#test_name) as Done##test_name; \
12+
Test##test_name <- TestP.BoolTest; \
13+
Test##test_name <- Done##test_name.BoolDone
14+
15+
define_test(True, 1 == 1 && 0 < 1);
16+
define_test(False, 0 == 1 || 0 > 1);
17+
define_test(Null, NULL);
18+
define_test(IntTrue, 1234);
19+
define_test(IntZero, 0);
20+
define_test(FloatTrue, 1.23);
21+
define_test(FloatZero, 0.0);
22+
23+
#undef define_test
24+
}

nregress/ok/c99c11.bool.1

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
True: 0 -> 0
2+
False: 0 -> 1
3+
Null: 0 -> 1
4+
IntTrue: 0 -> 0
5+
IntZero: 0 -> 1
6+
FloatTrue: 0 -> 0
7+
FloatZero: 0 -> 1
8+
True: 1 -> 1
9+
False: 1 -> 0
10+
Null: 1 -> 0
11+
IntTrue: 1 -> 1
12+
IntZero: 1 -> 0
13+
FloatTrue: 1 -> 1
14+
FloatZero: 1 -> 0
15+
True: 0, 0 -> 0
16+
False: 0, 0 -> 1
17+
Null: 0, 0 -> 1
18+
IntTrue: 0, 0 -> 0
19+
IntZero: 0, 0 -> 1
20+
FloatTrue: 0, 0 -> 0
21+
FloatZero: 0, 0 -> 1
22+
True: 0, 1 -> 1
23+
False: 0, 1 -> 0
24+
Null: 0, 1 -> 0
25+
IntTrue: 0, 1 -> 1
26+
IntZero: 0, 1 -> 0
27+
FloatTrue: 0, 1 -> 1
28+
FloatZero: 0, 1 -> 0
29+
True: 1, 0 -> 1
30+
False: 1, 0 -> 0
31+
Null: 1, 0 -> 0
32+
IntTrue: 1, 0 -> 1
33+
IntZero: 1, 0 -> 0
34+
FloatTrue: 1, 0 -> 1
35+
FloatZero: 1, 0 -> 0
36+
True: 1, 1 -> 0
37+
False: 1, 1 -> 1
38+
Null: 1, 1 -> 1
39+
IntTrue: 1, 1 -> 0
40+
IntZero: 1, 1 -> 1
41+
FloatTrue: 1, 1 -> 0
42+
FloatZero: 1, 1 -> 1

nregress/ok/c99c11.bool.2

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
In component `test':
2+
test.nc:17: warning: passing argument 1 of `TestNull' makes integer from pointer without a cast

0 commit comments

Comments
 (0)