Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support _Bool as primitive type #47

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/internals-target.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ A machine target is specified by filling in a '''machine_spec''' structure, defi
* machine_name: name of the target
* 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).
* big_endian: must be true for big-endian targets, false for little-endian ones
* tptr, tfloat, tdouble, tlong_double, tshort, tint, tlong, tlong_long: size and alignment of the corresponding C types.
* tptr, tfloat, tdouble, tlong_double, tshort, tint, tlong, tlong_long, t_Bool: size and alignment of the corresponding C types.
* 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...
* wchar_t_size: size of the wchar_t type
* size_t_size: size of the size_t type (actually this should be the C type, knowing just the size can cause problems)
Expand Down
4 changes: 4 additions & 0 deletions nregress/c99c11/boolarg/BoolTest.nc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
interface BoolTest {
command void test(const char *test_name, const _Bool arg);
event void testDone(const char *test_name, _Bool result, _Bool arg);
}
8 changes: 8 additions & 0 deletions nregress/c99c11/boolarg/BoolTestM.nc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module BoolTestM {
provides interface BoolTest;
}
implementation {
command void BoolTest.test(const char *test_name, const _Bool arg) {
signal BoolTest.testDone(test_name, !arg, arg);
}
}
45 changes: 45 additions & 0 deletions nregress/c99c11/boolarg/TestP.nc
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
extern int printf(const char *__restrict format, ...);

typedef struct {
_Bool a;
} bool_test_args;

nx_struct nx_header {
nx_uint32_t src;
nx_uint32_t dst;
};

module TestP {
uses interface BoolTest;
}
implementation {
int main() @C() @spontaneous() {
#define do_test(test_name, bool_expr) call BoolTest.test(#test_name, bool_expr)

do_test(TrueConst, 1);
do_test(TrueExpr, 1 == 1 && 0 < 1);
do_test(TrueExprSC, 0 == 0 || 0 > 1);
do_test(IntTrue, 1234);
do_test(FloatTrue, 1.23);
do_test(String, "string");

do_test(FalseConst, 0);
do_test(FalseExpr, 0 == 1 || 0 > 1);
do_test(FalseExprSC, 1 == 0 && 0 < 1);
do_test(IntZero, 0);
do_test(FloatZero, 0.0);
do_test(NullVoid, (const void *)0);
do_test(NullULL, (unsigned long long *)0);
do_test(NullStruct, (const bool_test_args *const __restrict)0);
do_test(NullFnP, (int (*)(char[], double))0);
do_test(Network, (nx_uint32_t *)0);
do_test(NetworkStruct, (nx_struct nx_header *)0);
#undef do_test

return 0;
}

event void BoolTest.testDone(const char *test_name, _Bool result, _Bool arg) {
printf("%15s: %d -> %d\n", test_name, arg, result);
}
}
7 changes: 7 additions & 0 deletions nregress/c99c11/boolarg/test.nc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
configuration test {
}
implementation {
components TestP, BoolTestM;

TestP.BoolTest -> BoolTestM;
}
11 changes: 11 additions & 0 deletions nregress/c99c11/boolgeneric/BoolTest.nc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
typedef struct {
_Bool a:1;
_Bool b;
} bool_test_args;

interface BoolTest {
command void unary(const _Bool a);
command void binary(const bool_test_args args);
event void unaryDone(const char *test_name, _Bool result, _Bool arg);
event void binaryDone(const char *test_name, _Bool result, bool_test_args args);
}
15 changes: 15 additions & 0 deletions nregress/c99c11/boolgeneric/BoolTestM.nc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
generic module BoolTestM(_Bool val, char test_name[]) {
provides interface BoolTest;
}
implementation {
command void BoolTest.unary(const _Bool a) {
const _Bool result = val ? a : !a;
signal BoolTest.unaryDone(test_name, result, a);
}

command void BoolTest.binary(const bool_test_args args) {
const _Bool xor = args.a ^ args.b;
const _Bool result = val ? xor : !xor;
signal BoolTest.binaryDone(test_name, result, args);
}
}
31 changes: 31 additions & 0 deletions nregress/c99c11/boolgeneric/TestP.nc
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
extern int printf(const char *__restrict format, ...);

module TestP {
uses interface BoolTest;
}
implementation {
int main() @C() @spontaneous() {
bool_test_args args;

call BoolTest.unary(0);
call BoolTest.unary(1);
args.a = args.b = 0;
call BoolTest.binary(args);
args.b = 1;
call BoolTest.binary(args);
args.a = 1; args.b = 0;
call BoolTest.binary(args);
args.a = args.b = 1;
call BoolTest.binary(args);

return 0;
}

event void BoolTest.unaryDone(const char *test_name, _Bool result, _Bool arg) {
printf("%15s: %d -> %d\n", test_name, arg, result);
}

event void BoolTest.binaryDone(const char *test_name, _Bool result, bool_test_args args) {
printf("%15s: %d, %d -> %d\n", test_name, args.a, args.b, result);
}
}
34 changes: 34 additions & 0 deletions nregress/c99c11/boolgeneric/test.nc
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
nx_struct nx_header {
nx_uint32_t src;
nx_uint32_t dst;
};

configuration test {
}
implementation {
components TestP;
#define define_test(test_name, bool_expr) \
components new BoolTestM(bool_expr, #test_name) as Test##test_name; \
Test##test_name <- TestP.BoolTest

define_test(TrueConst, 1);
define_test(TrueExpr, 1 == 1 && 0 < 1);
define_test(TrueExprSC, 0 == 0 || 0 > 1);
define_test(IntTrue, 1234);
define_test(FloatTrue, 1.23);
define_test(String, "string");

define_test(FalseConst, 0);
define_test(FalseExpr, 0 == 1 || 0 > 1);
define_test(FalseExprSC, 1 == 0 && 0 < 1);
define_test(IntZero, 0);
define_test(FloatZero, 0.0);
define_test(NullVoid, (const void *)0);
define_test(NullULL, (unsigned long long *)0);
define_test(NullStruct, (const bool_test_args *const __restrict)0);
define_test(NullFnP, (int (*)(char[], double))0);
define_test(Network, (nx_uint32_t *)0);
define_test(NetworkStruct, (nx_struct nx_header *)0);

#undef define_test
}
4 changes: 4 additions & 0 deletions nregress/c99c11/boolinit/BoolInit.nc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
interface BoolInit {
command void test();
event void testDone(const char *test_name, _Bool value);
}
3 changes: 3 additions & 0 deletions nregress/c99c11/boolinit/BoolReturn.nc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
interface BoolReturn {
command _Bool get();
}
17 changes: 17 additions & 0 deletions nregress/c99c11/boolinit/NegativeIntM.nc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module NegativeIntM {
provides {
interface BoolInit;
interface BoolReturn;
}
}
implementation {
_Bool value = -9876;

command void BoolInit.test() {
signal BoolInit.testDone("NegativeInt", value);
}

command _Bool BoolReturn.get() {
return -9876;
}
}
17 changes: 17 additions & 0 deletions nregress/c99c11/boolinit/NoneZeroFloatM.nc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module NoneZeroFloatM {
provides {
interface BoolInit;
interface BoolReturn;
}
}
implementation {
_Bool value = 3.456;

command void BoolInit.test() {
signal BoolInit.testDone("NonZeroFloat", value);
}

command _Bool BoolReturn.get() {
return 3.456;
}
}
17 changes: 17 additions & 0 deletions nregress/c99c11/boolinit/NullM.nc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module NullM {
provides {
interface BoolInit;
interface BoolReturn;
}
}
implementation {
_Bool value = (void *)0;

command void BoolInit.test() {
signal BoolInit.testDone("Null", value);
}

command _Bool BoolReturn.get() {
return (void *)0;
}
}
17 changes: 17 additions & 0 deletions nregress/c99c11/boolinit/PositiveIntM.nc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module PositiveIntM {
provides {
interface BoolInit;
interface BoolReturn;
}
}
implementation {
_Bool value = (unsigned int)1234;

command void BoolInit.test() {
signal BoolInit.testDone("PositiveInt", value);
}

command _Bool BoolReturn.get() {
return (unsigned int)1234;
}
}
18 changes: 18 additions & 0 deletions nregress/c99c11/boolinit/StringM.nc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module StringM {
provides {
interface BoolInit;
interface BoolReturn;
}
}
implementation {
static const char string[] = "string";
_Bool value = &string;

command void BoolInit.test() {
signal BoolInit.testDone("String", value);
}

command _Bool BoolReturn.get() {
return "string";
}
}
45 changes: 45 additions & 0 deletions nregress/c99c11/boolinit/TestP.nc
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
extern int printf(const char *__restrict __format, ...);

module TestP {
uses {
interface BoolInit;
interface BoolReturn as ZeroInt;
interface BoolReturn as PositiveInt;
interface BoolReturn as NegativeInt;
interface BoolReturn as ZeroFloat;
interface BoolReturn as NoneZeroFloat;
interface BoolReturn as String;
interface BoolReturn as Null;
}
}
implementation {
static void testDone(const char *test_name, _Bool value) {
printf("%15s: %d\n", test_name, value);
}

int main() @C() @spontaneous() {
printf("===== BoolInit =====\n");
call BoolInit.test();

#define do_test(test_name) \
testDone(#test_name, call test_name.get())

printf("===== BoolReturn =====\n");
do_test(ZeroInt);
do_test(ZeroFloat);
do_test(Null);

do_test(PositiveInt);
do_test(NegativeInt);
do_test(NoneZeroFloat);
do_test(String);

#undef do_test

return 0;
}

event void BoolInit.testDone(const char *test_name, _Bool value) {
testDone(test_name, value);
}
}
17 changes: 17 additions & 0 deletions nregress/c99c11/boolinit/ZeroFloatM.nc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module ZeroFloatM {
provides {
interface BoolInit;
interface BoolReturn;
}
}
implementation {
_Bool value = 0.00;

command void BoolInit.test() {
signal BoolInit.testDone("ZeroFloat", value);
}

command _Bool BoolReturn.get() {
return 0.00;
}
}
17 changes: 17 additions & 0 deletions nregress/c99c11/boolinit/ZeroIntM.nc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module ZeroIntM {
provides {
interface BoolInit;
interface BoolReturn;
}
}
implementation {
_Bool value = 0;

command void BoolInit.test() {
signal BoolInit.testDone("ZeroInt", value);
}

command _Bool BoolReturn.get() {
return 0;
}
}
21 changes: 21 additions & 0 deletions nregress/c99c11/boolinit/test.nc
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
configuration test {
}
implementation {
components TestP;

#define define_test(test_name) \
components test_name##M; \
test_name##M <- TestP.BoolInit; \
test_name##M <- TestP.test_name

define_test(ZeroInt);
define_test(ZeroFloat);
define_test(Null);

define_test(PositiveInt);
define_test(NegativeInt);
define_test(NoneZeroFloat);
define_test(String);

#undef define_test
}
11 changes: 5 additions & 6 deletions nregress/c99c11/run1
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
keep=
if [ -z "$NESC1" ]; then
NESC1=../../../src/nesc1
keep=1
fi
[ -z "$NESC1" ] && keep=1
: ${NESC:=../../..}
: ${TOOLS:=$NESC/tools}
: ${NESC1:=../../../src/nesc1}
cd $1
cfile=/tmp/c99c11.$$.c
exe=/tmp/c99c11.out.$$
$NESC1 -fnesc-separator=__ test.nc -o $cfile && \
$NESC1 -fnesc-separator=__ -I$TOOLS -fnesc-include=deputy_nodeputy -fnesc-include=nesc_nx test.nc -o $cfile && \
gcc -Wall -g -o $exe $cfile && \
$exe
ok=$?
Expand Down
Loading