-
Notifications
You must be signed in to change notification settings - Fork 22
/
test.c
143 lines (107 loc) · 2.25 KB
/
test.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/**
MACROS
test.c
Purpose: This file demostrates examples usage of macros.h.
@author Shubham Ramdeo
@version 0.2
Released under MIT LICENSE (see LICENSE.txt)
*/
/* I believe we need a better example file...! */
/* MORE Comming soon... */
#include <stdio.h>
#include <time.h>
/* For ASSERT macro to work */
#define DEBUG
#include "macros.h"
/* If you compile this file with a C compiler, this will make it work*/
EXTERN_C_START
MAIN () {
int x = 0, a, b, ab;
/* Boolean */
while (TRUE) {
if( (x > 5) == FALSE ) break;
x ; printf("hi ");
}
/* Operators */
x = 5;
if( x EQUALS 0 OR x > 10 AND x NOTEQUALS 15)
{
x IS 1;
}
else if ( NOT (x > 0) ) {
x IS 0;
}
else x IS 100;
printf("\n%d\n",x);
/* Loops */
FOREVER{
if( x > 5 ) break;
x ;printf("hi ");
}
RANGE(x, 10, 20){
printf("%d ", x);
}
RANGE (x, 5, -5){
printf("%d ", x);
}
STRING A[] = {"apple", "banana", "orange", "grapes"};
FOREACH (STRING *si, A){
printf("I love %s\n", *si);
}
/* ARRAYS */
int arr[] = {1,2,3,4,5,6,7,8,9,10};
if(IS_ARRAY(arr)) {
SET(arr, ARRAY_SIZE(arr)-4, 10);
ZERO(arr, 3);
}
RANGE(x, 0, 9) printf("%d\n", arr[x]);
/* STRINGS */
STRING sss = "hello";
STRING list[] = {"book", "ball", "bucket"};
puts ( CAT ("PenPineapple", "ApplePen") );
puts ( STR (This is a fruit) );
/* TOKEN */
a = 10;
b = 20;
ab = 0;
x = PASTE(a,b);
PRINT_TOKEN( x );
/* STMT */
STMT (printf("it should be in a macro...\n"););
/*Saturating -- and */
a = 0, b = 7;
for(x=0; x<10; x ){
SATINC(a,7);
SATDEC(b,0);
printf("%d %d, ",a,b);
}
/* Once */
/* without ONCE */
a = 1;
RANGE(x,0,10) {
/*ONCE(*/
a ;
/*);*/
}
printf(" %d ", a);
/* With ONCE */
a = 1;
RANGE(x,0,10) {
ONCE(
a ;
);
}
printf(" %d ", a);
LOG(x=5,"Now square of x is %d", x*x);
TRY(0>10, "We already knew its an error\n");
/* DEFER */
DEFER(printf("Before DEFER. Already inside. ["), printf("] After DEFER. Still inside.\n")) {
printf("] Inside DEFER. [");
}
/* NOW */
printf("UNIX epoch: %lu\n", NOW);
/* ASSERT will return -1 therefore its intentionally placed at the end. */
ASSERT(1>2);
return 0;
}
EXTERN_C_END