Skip to content

Commit 90716e9

Browse files
committed
Format C sources
Format not yet formatted C sources using `clang-format`.
1 parent f2258ad commit 90716e9

File tree

19 files changed

+87
-94
lines changed

19 files changed

+87
-94
lines changed

src/libAtomVM/bitstring.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,12 @@ union maybe_unsigned_int64
114114
};
115115

116116
bool bitstring_extract_any_integer(const uint8_t *src, size_t offset, avm_int_t n,
117-
enum BitstringFlags bs_flags, union maybe_unsigned_int64 *dst);
117+
enum BitstringFlags bs_flags, union maybe_unsigned_int64 *dst);
118118

119119
bool bitstring_insert_any_integer(uint8_t *dst, avm_int_t offset, avm_int64_t value, size_t n, enum BitstringFlags bs_flags);
120120

121121
static inline bool bitstring_extract_integer(term src_bin, size_t offset, avm_int_t n,
122-
enum BitstringFlags bs_flags, union maybe_unsigned_int64 *dst)
122+
enum BitstringFlags bs_flags, union maybe_unsigned_int64 *dst)
123123
{
124124
unsigned long capacity = term_binary_size(src_bin);
125125
if (8 * capacity - offset < (unsigned long) n) {
@@ -202,7 +202,6 @@ static inline bool bitstring_extract_integer(term src_bin, size_t offset, avm_in
202202
return false;
203203
}
204204

205-
206205
static inline bool bitstring_insert_integer(term dst_bin, size_t offset, avm_int64_t value, size_t n, enum BitstringFlags bs_flags)
207206
{
208207
unsigned long capacity = term_binary_size(dst_bin);

src/libAtomVM/context.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ static void context_monitors_handle_terminate(Context *ctx)
155155
{
156156
struct ListHead *item;
157157
struct ListHead *tmp;
158-
MUTABLE_LIST_FOR_EACH(item, tmp, &ctx->monitors_head) {
158+
MUTABLE_LIST_FOR_EACH (item, tmp, &ctx->monitors_head) {
159159
struct Monitor *monitor = GET_LIST_ENTRY(item, struct Monitor, monitor_list_head);
160160
int local_process_id = term_to_local_process_id(monitor->monitor_pid);
161161
Context *target = globalcontext_get_process(ctx->global, local_process_id);

src/libAtomVM/externalterm.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ static term parse_external_terms(const uint8_t *external_term_buf, int *eterm_si
452452
uint32_t size = READ_32_UNALIGNED(external_term_buf + 1);
453453
term map = term_alloc_map(ctx, size);
454454
int buf_pos = 5;
455-
for (uint32_t i = 0; i < size; ++i) {
455+
for (uint32_t i = 0; i < size; ++i) {
456456
int key_size;
457457
term key = parse_external_terms(external_term_buf + buf_pos, &key_size, ctx, copy);
458458
if (term_is_invalid_term(key)) {
@@ -488,7 +488,6 @@ static term parse_external_terms(const uint8_t *external_term_buf, int *eterm_si
488488
}
489489
}
490490

491-
492491
static int calculate_heap_usage(const uint8_t *external_term_buf, int *eterm_size, bool copy, Context *ctx)
493492
{
494493
switch (external_term_buf[0]) {
@@ -619,7 +618,7 @@ static int calculate_heap_usage(const uint8_t *external_term_buf, int *eterm_siz
619618
uint32_t size = READ_32_UNALIGNED(external_term_buf + 1);
620619
int heap_usage = 1;
621620
int buf_pos = 5;
622-
for (uint32_t i = 0; i < size; ++i) {
621+
for (uint32_t i = 0; i < size; ++i) {
623622
int key_size;
624623
int u = calculate_heap_usage(external_term_buf + buf_pos, &key_size, copy, ctx) + 1;
625624
if (u == INVALID_TERM_SIZE) {

src/libAtomVM/memory.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ static void memory_scan_and_copy(term *mem_start, const term *mem_end, term **ne
389389
size_t value_offset = term_get_map_value_offset();
390390
TRACE("-- Map keys: %lx\n", ptr[keys_offset]);
391391
ptr[keys_offset] = memory_shallow_copy_term(ptr[keys_offset], &new_heap, move);
392-
for (size_t i = value_offset; i < value_offset + map_size; ++i) {
392+
for (size_t i = value_offset; i < value_offset + map_size; ++i) {
393393
TRACE("-- Map Value: %lx\n", ptr[i]);
394394
ptr[i] = memory_shallow_copy_term(ptr[i], &new_heap, move);
395395
}

src/libAtomVM/module.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
#ifdef WITH_ZLIB
4242
static void *module_uncompress_literals(const uint8_t *litT, int size);
4343
#endif
44-
static void const* *module_build_literals_table(const void *literalsBuf);
44+
static void const **module_build_literals_table(const void *literalsBuf);
4545
static void module_add_label(Module *mod, int index, void *ptr);
4646
static enum ModuleLoadResult module_build_imported_functions_table(Module *this_module, uint8_t *table_data);
4747
static void module_add_label(Module *mod, int index, void *ptr);
@@ -287,13 +287,13 @@ static void *module_uncompress_literals(const uint8_t *litT, int size)
287287
}
288288
#endif
289289

290-
static void const* *module_build_literals_table(const void *literalsBuf)
290+
static void const **module_build_literals_table(const void *literalsBuf)
291291
{
292292
uint32_t terms_count = READ_32_ALIGNED(literalsBuf);
293293

294294
const uint8_t *pos = (const uint8_t *) literalsBuf + sizeof(uint32_t);
295295

296-
void const* *literals_table = calloc(terms_count, sizeof(void *const));
296+
void const **literals_table = calloc(terms_count, sizeof(void *const));
297297
if (IS_NULL_PTR(literals_table)) {
298298
fprintf(stderr, "Failed to allocate memory: %s:%i.\n", __FILE__, __LINE__);
299299
return NULL;

src/libAtomVM/module.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ struct Module
7070
void **labels;
7171

7272
void *literals_data;
73-
void const* *literals_table;
73+
void const **literals_table;
7474

7575
int *local_atoms_to_global_table;
7676

src/libAtomVM/nifs.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,17 @@
4949

5050
#define VALIDATE_VALUE(value, verify_function) \
5151
if (UNLIKELY(!verify_function((value)))) { \
52-
argv[0] = ERROR_ATOM; \
53-
argv[1] = BADARG_ATOM; \
54-
return term_invalid_term(); \
55-
} \
52+
argv[0] = ERROR_ATOM; \
53+
argv[1] = BADARG_ATOM; \
54+
return term_invalid_term(); \
55+
}
5656

5757
#define RAISE_ERROR(error_type_atom) \
58-
ctx->x[0] = ERROR_ATOM; \
59-
ctx->x[1] = (error_type_atom); \
58+
ctx->x[0] = ERROR_ATOM; \
59+
ctx->x[1] = (error_type_atom); \
6060
return term_invalid_term();
6161

62-
#define RAISE(a, b) \
62+
#define RAISE(a, b) \
6363
ctx->x[0] = (a); \
6464
ctx->x[1] = (b); \
6565
return term_invalid_term();
@@ -75,7 +75,6 @@ static const char *const trace_send_atom = "\xA" "trace_send";
7575
static const char *const trace_receive_atom = "\xD" "trace_receive";
7676
#endif
7777

78-
7978
static void process_echo_mailbox(Context *ctx);
8079
static void process_console_mailbox(Context *ctx);
8180

@@ -2181,7 +2180,7 @@ static void *nif_cons_context(Context *ctx, void *p)
21812180
static void *nif_iterate_processes(GlobalContext *glb, context_iterator fun, void *accum)
21822181
{
21832182
struct ListHead *item;
2184-
LIST_FOR_EACH(item, &glb->processes_table) {
2183+
LIST_FOR_EACH (item, &glb->processes_table) {
21852184
Context *p = GET_LIST_ENTRY(item, Context, processes_table_head);
21862185
accum = fun(p, accum);
21872186
}

src/libAtomVM/opcodesswitch.h

Lines changed: 46 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@
2727
#include "debug.h"
2828
#include "defaultatoms.h"
2929
#include "exportedfunction.h"
30-
#include "utils.h"
31-
#include "scheduler.h"
3230
#include "nifs.h"
3331
#include "opcodes.h"
32+
#include "scheduler.h"
33+
#include "utils.h"
3434

3535
#ifdef IMPL_EXECUTE_LOOP
3636
#include "bitstring.h"
@@ -71,9 +71,9 @@ typedef union
7171
} dreg_type_t;
7272

7373
#ifdef IMPL_EXECUTE_LOOP
74-
#define RAISE_ERROR(error_type_atom) \
75-
ctx->x[0] = ERROR_ATOM; \
76-
ctx->x[1] = error_type_atom; \
74+
#define RAISE_ERROR(error_type_atom) \
75+
ctx->x[0] = ERROR_ATOM; \
76+
ctx->x[1] = error_type_atom; \
7777
goto handle_error;
7878

7979
#define VM_ABORT() \
@@ -316,7 +316,7 @@ typedef union
316316
} \
317317
}
318318

319-
#define READ_DEST_REGISTER(dreg_type, dreg) \
319+
#define READ_DEST_REGISTER(dreg_type, dreg) \
320320
*(*((dreg_type).ptr) + (dreg));
321321

322322

@@ -451,9 +451,9 @@ typedef union
451451
#define INSTRUCTION_POINTER() \
452452
((const void *) &code[i])
453453

454-
#define DO_RETURN() \
454+
#define DO_RETURN() \
455455
mod = mod->global->modules_by_index[ctx->cp >> 24]; \
456-
code = mod->code->code; \
456+
code = mod->code->code; \
457457
i = (ctx->cp & 0xFFFFFF) >> 2;
458458

459459
#define POINTER_TO_II(instruction_pointer) \
@@ -462,37 +462,36 @@ typedef union
462462
#define HANDLE_ERROR() \
463463
goto handle_error;
464464

465-
#define VERIFY_IS_INTEGER(t, opcode_name) \
466-
if (UNLIKELY(!term_is_integer(t))) { \
467-
TRACE(opcode_name ": " #t " is not an integer\n"); \
468-
RAISE_ERROR(BADARG_ATOM); \
469-
}
465+
#define VERIFY_IS_INTEGER(t, opcode_name) \
466+
if (UNLIKELY(!term_is_integer(t))) { \
467+
TRACE(opcode_name ": " #t " is not an integer\n"); \
468+
RAISE_ERROR(BADARG_ATOM); \
469+
}
470470

471-
#define VERIFY_IS_ANY_INTEGER(t, opcode_name) \
472-
if (UNLIKELY(!term_is_any_integer(t))) { \
473-
TRACE(opcode_name ": " #t " is not any integer\n"); \
474-
RAISE_ERROR(BADARG_ATOM); \
475-
}
471+
#define VERIFY_IS_ANY_INTEGER(t, opcode_name) \
472+
if (UNLIKELY(!term_is_any_integer(t))) { \
473+
TRACE(opcode_name ": " #t " is not any integer\n"); \
474+
RAISE_ERROR(BADARG_ATOM); \
475+
}
476476

477-
#define VERIFY_IS_BINARY(t, opcode_name) \
478-
if (UNLIKELY(!term_is_binary(t))) { \
479-
TRACE(opcode_name ": " #t " is not a binary\n"); \
480-
RAISE_ERROR(BADARG_ATOM); \
481-
}
477+
#define VERIFY_IS_BINARY(t, opcode_name) \
478+
if (UNLIKELY(!term_is_binary(t))) { \
479+
TRACE(opcode_name ": " #t " is not a binary\n"); \
480+
RAISE_ERROR(BADARG_ATOM); \
481+
}
482482

483-
#define VERIFY_IS_MATCH_STATE(t, opcode_name) \
484-
if (UNLIKELY(!term_is_match_state(t))) { \
483+
#define VERIFY_IS_MATCH_STATE(t, opcode_name) \
484+
if (UNLIKELY(!term_is_match_state(t))) { \
485485
TRACE(opcode_name ": " #t " is not a match context.\n"); \
486-
RAISE_ERROR(BADARG_ATOM); \
486+
RAISE_ERROR(BADARG_ATOM); \
487487
}
488488

489-
#define VERIFY_IS_MATCH_OR_BINARY(t, opcode_name) \
490-
if (UNLIKELY(!(term_is_binary(t) || term_is_match_state(t)))) { \
489+
#define VERIFY_IS_MATCH_OR_BINARY(t, opcode_name) \
490+
if (UNLIKELY(!(term_is_binary(t) || term_is_match_state(t)))) { \
491491
TRACE(opcode_name ": " #t " is not a binary or match context.\n"); \
492-
RAISE_ERROR(BADARG_ATOM); \
492+
RAISE_ERROR(BADARG_ATOM); \
493493
}
494494

495-
496495
#define MIN(X, Y) ((X) < (Y) ? (X) : (Y))
497496

498497
#ifdef IMPL_EXECUTE_LOOP
@@ -516,11 +515,12 @@ struct Int56
516515
int64_t val56 : 56;
517516
};
518517

519-
#define SWAP_KV_PAIR(I, J) { \
520-
struct kv_pair tmp = kv[(I)]; \
521-
kv[(I)] = kv[(J)]; \
522-
kv[(J)] = tmp; \
523-
}
518+
#define SWAP_KV_PAIR(I, J) \
519+
{ \
520+
struct kv_pair tmp = kv[(I)]; \
521+
kv[(I)] = kv[(J)]; \
522+
kv[(J)] = tmp; \
523+
}
524524

525525
struct kv_pair
526526
{
@@ -618,7 +618,7 @@ COLD_FUNC static void dump(Context *ctx)
618618
int offset;
619619
cp_to_mod_lbl_off(ctx->cp, ctx, &cp_mod, &label, &offset);
620620
fprintf(stderr, "cp: #CP<module: %i, label: %i, offset: %i>\n\n",
621-
cp_mod->module_index, label, offset);
621+
cp_mod->module_index, label, offset);
622622
}
623623

624624
fprintf(stderr, "x[0]: ");
@@ -659,7 +659,7 @@ COLD_FUNC static void dump(Context *ctx)
659659

660660
fprintf(stderr, "\n\nMailbox\n--------\n");
661661
struct ListHead *item;
662-
LIST_FOR_EACH(item, &ctx->mailbox) {
662+
LIST_FOR_EACH (item, &ctx->mailbox) {
663663
Message *msg = GET_LIST_ENTRY(item, Message, mailbox_list_head);
664664
term_display(stderr, msg->message, ctx);
665665
fprintf(stderr, "\n");
@@ -802,7 +802,7 @@ term make_fun(Context *ctx, const Module *mod, int fun_index)
802802
}
803803

804804
static bool maybe_call_native(Context *ctx, AtomString module_name, AtomString function_name, int arity,
805-
term *return_value)
805+
term *return_value)
806806
{
807807
BifImpl bif = bif_registry_get_handler(module_name, function_name, arity);
808808
if (bif) {
@@ -999,7 +999,7 @@ static bool maybe_call_native(Context *ctx, AtomString module_name, AtomString f
999999
int remaining_reductions = DEFAULT_REDUCTIONS_AMOUNT;
10001000
#endif
10011001

1002-
while(1) {
1002+
while (1) {
10031003

10041004
switch (code[i]) {
10051005
case OP_LABEL: {
@@ -1802,7 +1802,6 @@ static bool maybe_call_native(Context *ctx, AtomString module_name, AtomString f
18021802
break;
18031803
}
18041804

1805-
18061805
case OP_IS_LT: {
18071806
int next_off = 1;
18081807
int label;
@@ -1978,9 +1977,9 @@ static bool maybe_call_native(Context *ctx, AtomString module_name, AtomString f
19781977
#endif
19791978

19801979
break;
1981-
}
1980+
}
19821981

1983-
case OP_IS_INTEGER: {
1982+
case OP_IS_INTEGER: {
19841983
int next_off = 1;
19851984
int label;
19861985
DECODE_LABEL(label, code, i, next_off, next_off)
@@ -2007,7 +2006,6 @@ static bool maybe_call_native(Context *ctx, AtomString module_name, AtomString f
20072006
break;
20082007
}
20092008

2010-
20112009
case OP_IS_FLOAT: {
20122010
int next_off = 1;
20132011
int label;
@@ -2281,9 +2279,9 @@ static bool maybe_call_native(Context *ctx, AtomString module_name, AtomString f
22812279
#endif
22822280

22832281
break;
2284-
}
2282+
}
22852283

2286-
case OP_IS_TUPLE: {
2284+
case OP_IS_TUPLE: {
22872285
int next_off = 1;
22882286
int label;
22892287
DECODE_LABEL(label, code, i, next_off, next_off)
@@ -2310,7 +2308,7 @@ static bool maybe_call_native(Context *ctx, AtomString module_name, AtomString f
23102308
break;
23112309
}
23122310

2313-
case OP_TEST_ARITY: {
2311+
case OP_TEST_ARITY: {
23142312
int next_off = 1;
23152313
int label;
23162314
DECODE_LABEL(label, code, i, next_off, next_off);
@@ -2955,7 +2953,6 @@ static bool maybe_call_native(Context *ctx, AtomString module_name, AtomString f
29552953

29562954
NEXT_INSTRUCTION(next_off);
29572955
break;
2958-
29592956
}
29602957

29612958
case OP_TRY: {
@@ -4074,7 +4071,7 @@ static bool maybe_call_native(Context *ctx, AtomString module_name, AtomString f
40744071
DECODE_INTEGER(arity, code, i, next_off, next_off)
40754072
#ifdef IMPL_EXECUTE_LOOP
40764073
term module = ctx->x[arity];
4077-
term function = ctx->x[arity+1];
4074+
term function = ctx->x[arity + 1];
40784075
TRACE("apply/1, module=%lu, function=%lu arity=%i\n", module, function, arity);
40794076

40804077
remaining_reductions--;
@@ -4130,7 +4127,7 @@ static bool maybe_call_native(Context *ctx, AtomString module_name, AtomString f
41304127
DECODE_INTEGER(n_words, code, i, next_off, next_off);
41314128
#ifdef IMPL_EXECUTE_LOOP
41324129
term module = ctx->x[arity];
4133-
term function = ctx->x[arity+1];
4130+
term function = ctx->x[arity + 1];
41344131
TRACE("apply_last/1, module=%lu, function=%lu arity=%i deallocate=%i\n", module, function, arity, n_words);
41354132

41364133
remaining_reductions--;

src/libAtomVM/overflow_helpers.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@
6060
#define BUILTIN_ADD_OVERFLOW_INT atomvm_add_overflow_int
6161
#define BUILTIN_ADD_OVERFLOW_INT64 atomvm_add_overflow_int64
6262

63-
#include <stdint.h>
6463
#include "term.h"
64+
#include <stdint.h>
6565

6666
static inline int atomvm_add_overflow(avm_int_t a, avm_int_t b, avm_int_t *res)
6767
{
@@ -120,8 +120,8 @@ static inline int atomvm_sub_overflow_int64(avm_int64_t a, avm_int64_t b, avm_in
120120
#define BUILTIN_MUL_OVERFLOW_INT atomvm_mul_overflow_int
121121
#define BUILTIN_MUL_OVERFLOW_INT64 atomvm_mul_overflow_int64
122122

123-
#include <stdint.h>
124123
#include "term.h"
124+
#include <stdint.h>
125125

126126
static inline int atomvm_mul_overflow_int(avm_int_t a, avm_int_t b, avm_int_t *res)
127127
{

0 commit comments

Comments
 (0)