Skip to content

Commit 3aa240b

Browse files
committed
use an attached style
1 parent 8d1a779 commit 3aa240b

14 files changed

Lines changed: 300 additions & 628 deletions

.clang-format

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ UseTab: Never
55
AllowShortIfStatementsOnASingleLine: true
66
AllowShortLoopsOnASingleLine: true
77
AllowShortFunctionsOnASingleLine: Empty
8-
BreakBeforeBraces: Allman
8+
BreakBeforeBraces: Attach
99
SpaceBeforeParens: ControlStatements

examples/add.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44

55
typedef int (*add_fn)(int);
66

7-
int main(void)
8-
{
7+
int main(void) {
98
cj_ctx *cj = create_cj_ctx();
109

1110
#ifdef __aarch64__

examples/fibonacci.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,18 @@
2525
typedef int (*fib_fn)(int);
2626

2727
// Reference implementation for comparison
28-
int fib_c(int n)
29-
{
28+
int fib_c(int n) {
3029
if (n <= 1) return n;
3130
int a = 0, b = 1;
32-
for (int i = 2; i <= n; i++)
33-
{
31+
for (int i = 2; i <= n; i++) {
3432
int temp = a + b;
3533
a = b;
3634
b = temp;
3735
}
3836
return b;
3937
}
4038

41-
int main(void)
42-
{
39+
int main(void) {
4340
// Create JIT context
4441
cj_ctx *cj = create_cj_ctx();
4542

@@ -172,8 +169,7 @@ int main(void)
172169

173170
// Test the JIT-compiled function
174171
int all_pass = 1;
175-
for (int i = 0; i <= 15; i++)
176-
{
172+
for (int i = 0; i <= 15; i++) {
177173
int result = fib_jit(i);
178174
int expected = fib_c(i);
179175
int pass = (result == expected);

examples/hl_fibonacci.c

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,19 @@
44

55
typedef int (*fib_fn)(int);
66

7-
static int fib_c(int n)
8-
{
7+
static int fib_c(int n) {
98
if (n <= 1) return n;
109
int a = 0;
1110
int b = 1;
12-
for (int i = 2; i <= n; ++i)
13-
{
11+
for (int i = 2; i <= n; ++i) {
1412
int tmp = a + b;
1513
a = b;
1614
b = tmp;
1715
}
1816
return b;
1917
}
2018

21-
int main(void)
22-
{
19+
int main(void) {
2320
cj_ctx *cj = create_cj_ctx();
2421

2522
cj_builder_frame frame;
@@ -52,16 +49,14 @@ int main(void)
5249
cj_builder_return_value(cj, &frame, acc_b);
5350

5451
fib_fn fib_jit = (fib_fn)create_cj_fn(cj);
55-
if (!fib_jit)
56-
{
52+
if (!fib_jit) {
5753
puts("failed to create jit function");
5854
destroy_cj_ctx(cj);
5955
return 1;
6056
}
6157

6258
int all_pass = 1;
63-
for (int idx = 0; idx <= 15; ++idx)
64-
{
59+
for (int idx = 0; idx <= 15; ++idx) {
6560
int result = fib_jit(idx);
6661
int expected = fib_c(idx);
6762
int pass = (result == expected);

0 commit comments

Comments
 (0)