Enable more pedantic compiler flags
This commit is contained in:
@@ -142,7 +142,7 @@ class BuildVariant:
|
|||||||
self.env.Alias(self.variant_name, self.variant_dir)
|
self.env.Alias(self.variant_name, self.variant_dir)
|
||||||
|
|
||||||
|
|
||||||
base_ccflags = ["-Werror", "-Wall", "-Wextra", "-Wno-unused-parameter"]
|
base_ccflags = ["-Werror", "-Wall", "-Wextra", "-Wpedantic"]
|
||||||
debug_ccflags = ["-ggdb", "-O0"]
|
debug_ccflags = ["-ggdb", "-O0"]
|
||||||
release_ccflags = [
|
release_ccflags = [
|
||||||
"-Oz",
|
"-Oz",
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ void ucl_arena_map(struct ucl_arena *arena, void (*map_function)(struct ucl_aren
|
|||||||
while (map) {
|
while (map) {
|
||||||
int bit_index = __builtin_ffs(map) - 1;
|
int bit_index = __builtin_ffs(map) - 1;
|
||||||
int index = bit_index + INT_BITS * i;
|
int index = bit_index + INT_BITS * i;
|
||||||
void *obj = arena->objects + (index * arena->object_size);
|
void *obj = (char *) arena->objects + (index * arena->object_size);
|
||||||
map_function(arena, obj);
|
map_function(arena, obj);
|
||||||
map &= ~(1 << bit_index);
|
map &= ~(1 << bit_index);
|
||||||
}
|
}
|
||||||
@@ -68,7 +68,7 @@ void *ucl_arena_get(struct ucl_arena *arena) {
|
|||||||
}
|
}
|
||||||
arena->used_map[i] |= 1 << bit_index;
|
arena->used_map[i] |= 1 << bit_index;
|
||||||
total_arena_gets++;
|
total_arena_gets++;
|
||||||
return arena->objects + (index * arena->object_size);
|
return (char *) arena->objects + (index * arena->object_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -82,7 +82,7 @@ void ucl_arena_put(struct ucl_arena *arena, void *object) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ptrdiff_t offset = object - arena->objects;
|
ptrdiff_t offset = (char *) object - (char *) arena->objects;
|
||||||
unsigned int index = offset / arena->object_size;
|
unsigned int index = offset / arena->object_size;
|
||||||
unsigned int int_index = index / INT_BITS;
|
unsigned int int_index = index / INT_BITS;
|
||||||
unsigned int bit_index = index % INT_BITS;
|
unsigned int bit_index = index % INT_BITS;
|
||||||
|
|||||||
@@ -177,7 +177,7 @@ LISP_FUNC_1(ucl_builtin_printl, state, scope, arg0) {
|
|||||||
return ucl_nil_create(state);
|
return ucl_nil_create(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ucl_object *ucl_builtin_list(struct ucl *state, struct ucl_scope *scope, struct ucl_object *args) {
|
struct ucl_object *ucl_builtin_list(struct ucl *state, UNUSED struct ucl_scope *scope, struct ucl_object *args) {
|
||||||
struct ucl_object *head = ucl_nil_create(state);
|
struct ucl_object *head = ucl_nil_create(state);
|
||||||
FOREACH_LIST(args, iter, item) {
|
FOREACH_LIST(args, iter, item) {
|
||||||
ucl_list_append(state, head, item);
|
ucl_list_append(state, head, item);
|
||||||
|
|||||||
10
src/lisp.h
10
src/lisp.h
@@ -3,6 +3,8 @@
|
|||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
|
||||||
|
#define UNUSED __attribute__((unused))
|
||||||
|
|
||||||
#define LISP_FUNC_0(func_name, ucl_name, scope_name) \
|
#define LISP_FUNC_0(func_name, ucl_name, scope_name) \
|
||||||
static struct ucl_object *func_name##_impl(struct ucl* ucl, struct ucl_scope *scope); \
|
static struct ucl_object *func_name##_impl(struct ucl* ucl, struct ucl_scope *scope); \
|
||||||
struct ucl_object *func_name(struct ucl* ucl, struct ucl_scope *scope, struct ucl_object *args) { \
|
struct ucl_object *func_name(struct ucl* ucl, struct ucl_scope *scope, struct ucl_object *args) { \
|
||||||
@@ -11,7 +13,7 @@
|
|||||||
} \
|
} \
|
||||||
return func_name##_impl(ucl, scope); \
|
return func_name##_impl(ucl, scope); \
|
||||||
} \
|
} \
|
||||||
static struct ucl_object *func_name##_impl(struct ucl *ucl_name, struct ucl_scope *scope)
|
static struct ucl_object *func_name##_impl(UNUSED struct ucl *ucl_name, UNUSED struct ucl_scope *scope)
|
||||||
|
|
||||||
#define LISP_FUNC_1(func_name, ucl_name, scope_name, arg0_name) \
|
#define LISP_FUNC_1(func_name, ucl_name, scope_name, arg0_name) \
|
||||||
static struct ucl_object *func_name##_impl(struct ucl* ucl, struct ucl_scope *scope, struct ucl_object *arg0_name); \
|
static struct ucl_object *func_name##_impl(struct ucl* ucl, struct ucl_scope *scope, struct ucl_object *arg0_name); \
|
||||||
@@ -26,7 +28,7 @@
|
|||||||
struct ucl_object *arg0 = ucl_car(ucl, args); \
|
struct ucl_object *arg0 = ucl_car(ucl, args); \
|
||||||
return func_name##_impl(ucl, scope_name, arg0); \
|
return func_name##_impl(ucl, scope_name, arg0); \
|
||||||
} \
|
} \
|
||||||
static struct ucl_object *func_name##_impl(struct ucl* ucl_name, struct ucl_scope *scope, struct ucl_object *arg0_name)
|
static struct ucl_object *func_name##_impl(UNUSED struct ucl* ucl_name, UNUSED struct ucl_scope *scope_name, struct ucl_object *arg0_name)
|
||||||
|
|
||||||
// TODO: Unroll the args more efficiently, this is O(n^2)
|
// TODO: Unroll the args more efficiently, this is O(n^2)
|
||||||
#define LISP_FUNC_2(func_name, ucl_name, scope_name, arg0_name, arg1_name) \
|
#define LISP_FUNC_2(func_name, ucl_name, scope_name, arg0_name, arg1_name) \
|
||||||
@@ -43,7 +45,7 @@
|
|||||||
struct ucl_object *arg1 = ucl_list_nth(ucl, args, 1); \
|
struct ucl_object *arg1 = ucl_list_nth(ucl, args, 1); \
|
||||||
return func_name##_impl(ucl, scope, arg0, arg1); \
|
return func_name##_impl(ucl, scope, arg0, arg1); \
|
||||||
} \
|
} \
|
||||||
static struct ucl_object *func_name##_impl(struct ucl *ucl_name, struct ucl_scope *scope, struct ucl_object *arg0_name, struct ucl_object *arg1_name)
|
static struct ucl_object *func_name##_impl(UNUSED struct ucl *ucl_name, UNUSED struct ucl_scope *scope, struct ucl_object *arg0_name, struct ucl_object *arg1_name)
|
||||||
|
|
||||||
// TODO: Unroll the args more efficiently, this is O(n^2)
|
// TODO: Unroll the args more efficiently, this is O(n^2)
|
||||||
#define LISP_FUNC_3(func_name, ucl_name, scope_name, arg0_name, arg1_name, arg2_name) \
|
#define LISP_FUNC_3(func_name, ucl_name, scope_name, arg0_name, arg1_name, arg2_name) \
|
||||||
@@ -61,7 +63,7 @@
|
|||||||
struct ucl_object *arg2 = ucl_list_nth(ucl, args, 2); \
|
struct ucl_object *arg2 = ucl_list_nth(ucl, args, 2); \
|
||||||
return func_name##_impl(ucl, scope, arg0, arg1, arg2); \
|
return func_name##_impl(ucl, scope, arg0, arg1, arg2); \
|
||||||
} \
|
} \
|
||||||
static struct ucl_object *func_name##_impl(struct ucl* ucl_name, struct ucl_scope *scope_name, struct ucl_object *arg0_name, struct ucl_object *arg1_name, struct ucl_object *arg2_name)
|
static struct ucl_object *func_name##_impl(UNUSED struct ucl* ucl_name, UNUSED struct ucl_scope *scope_name, struct ucl_object *arg0_name, struct ucl_object *arg1_name, struct ucl_object *arg2_name)
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
16
src/memory.c
16
src/memory.c
@@ -19,11 +19,11 @@
|
|||||||
#define UCL_OBJECT_ARENA_SIZE (1 << 14)
|
#define UCL_OBJECT_ARENA_SIZE (1 << 14)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static struct ucl_object *ucl_object_alloc();
|
static struct ucl_object *ucl_object_alloc(struct ucl *ucl);
|
||||||
|
|
||||||
struct ucl_object *ucl_cell_create(struct ucl *ucl, struct ucl_object *car, struct ucl_object *cdr)
|
struct ucl_object *ucl_cell_create(struct ucl *ucl, struct ucl_object *car, struct ucl_object *cdr)
|
||||||
{
|
{
|
||||||
struct ucl_object* obj = ucl_object_alloc();
|
struct ucl_object* obj = ucl_object_alloc(ucl);
|
||||||
obj->type = UCL_TYPE_CELL;
|
obj->type = UCL_TYPE_CELL;
|
||||||
obj->cell.car = car;
|
obj->cell.car = car;
|
||||||
obj->cell.cdr = cdr;
|
obj->cell.cdr = cdr;
|
||||||
@@ -32,7 +32,7 @@ struct ucl_object *ucl_cell_create(struct ucl *ucl, struct ucl_object *car, stru
|
|||||||
|
|
||||||
struct ucl_object *ucl_int_create(struct ucl *ucl, int integer)
|
struct ucl_object *ucl_int_create(struct ucl *ucl, int integer)
|
||||||
{
|
{
|
||||||
struct ucl_object* obj = ucl_object_alloc();
|
struct ucl_object* obj = ucl_object_alloc(ucl);
|
||||||
obj->type = UCL_TYPE_INT;
|
obj->type = UCL_TYPE_INT;
|
||||||
obj->integer = integer;
|
obj->integer = integer;
|
||||||
return obj;
|
return obj;
|
||||||
@@ -40,7 +40,7 @@ struct ucl_object *ucl_int_create(struct ucl *ucl, int integer)
|
|||||||
|
|
||||||
struct ucl_object *ucl_symbol_create(struct ucl* ucl, const char *symbol)
|
struct ucl_object *ucl_symbol_create(struct ucl* ucl, const char *symbol)
|
||||||
{
|
{
|
||||||
struct ucl_object* obj = ucl_object_alloc();
|
struct ucl_object* obj = ucl_object_alloc(ucl);
|
||||||
obj->type = UCL_TYPE_SYMBOL;
|
obj->type = UCL_TYPE_SYMBOL;
|
||||||
obj->symbol = strdup(symbol);
|
obj->symbol = strdup(symbol);
|
||||||
return obj;
|
return obj;
|
||||||
@@ -48,7 +48,7 @@ struct ucl_object *ucl_symbol_create(struct ucl* ucl, const char *symbol)
|
|||||||
|
|
||||||
struct ucl_object *ucl_string_create(struct ucl* ucl, const char *string)
|
struct ucl_object *ucl_string_create(struct ucl* ucl, const char *string)
|
||||||
{
|
{
|
||||||
struct ucl_object* obj = ucl_object_alloc();
|
struct ucl_object* obj = ucl_object_alloc(ucl);
|
||||||
obj->type = UCL_TYPE_STRING;
|
obj->type = UCL_TYPE_STRING;
|
||||||
obj->string = strdup(string);
|
obj->string = strdup(string);
|
||||||
return obj;
|
return obj;
|
||||||
@@ -56,7 +56,7 @@ struct ucl_object *ucl_string_create(struct ucl* ucl, const char *string)
|
|||||||
|
|
||||||
struct ucl_object *ucl_error_create(struct ucl* ucl, const char *error)
|
struct ucl_object *ucl_error_create(struct ucl* ucl, const char *error)
|
||||||
{
|
{
|
||||||
struct ucl_object* obj = ucl_object_alloc();
|
struct ucl_object* obj = ucl_object_alloc(ucl);
|
||||||
obj->type = UCL_TYPE_ERROR;
|
obj->type = UCL_TYPE_ERROR;
|
||||||
obj->error = strdup(error);
|
obj->error = strdup(error);
|
||||||
return obj;
|
return obj;
|
||||||
@@ -65,7 +65,7 @@ struct ucl_object *ucl_error_create(struct ucl* ucl, const char *error)
|
|||||||
|
|
||||||
struct ucl_object *ucl_builtin_create(struct ucl* ucl, ucl_lisp builtin)
|
struct ucl_object *ucl_builtin_create(struct ucl* ucl, ucl_lisp builtin)
|
||||||
{
|
{
|
||||||
struct ucl_object* obj = ucl_object_alloc();
|
struct ucl_object* obj = ucl_object_alloc(ucl);
|
||||||
obj->type = UCL_TYPE_BUILTIN;
|
obj->type = UCL_TYPE_BUILTIN;
|
||||||
obj->builtin = builtin;
|
obj->builtin = builtin;
|
||||||
return obj;
|
return obj;
|
||||||
@@ -73,7 +73,7 @@ struct ucl_object *ucl_builtin_create(struct ucl* ucl, ucl_lisp builtin)
|
|||||||
|
|
||||||
struct ucl_object *ucl_special_create(struct ucl* ucl, ucl_lisp special)
|
struct ucl_object *ucl_special_create(struct ucl* ucl, ucl_lisp special)
|
||||||
{
|
{
|
||||||
struct ucl_object* obj = ucl_object_alloc();
|
struct ucl_object* obj = ucl_object_alloc(ucl);
|
||||||
obj->type = UCL_TYPE_SPECIAL;
|
obj->type = UCL_TYPE_SPECIAL;
|
||||||
obj->special = special;
|
obj->special = special;
|
||||||
return obj;
|
return obj;
|
||||||
|
|||||||
11
src/parse.c
11
src/parse.c
@@ -73,7 +73,16 @@ struct ucl_object *ucl_token_next(struct ucl* state, const char **curr_src) {
|
|||||||
return ucl_string_create(state, str);
|
return ucl_string_create(state, str);
|
||||||
case '-':
|
case '-':
|
||||||
case '+':
|
case '+':
|
||||||
case '0'...'9': {
|
case '0':
|
||||||
|
case '1':
|
||||||
|
case '2':
|
||||||
|
case '3':
|
||||||
|
case '4':
|
||||||
|
case '5':
|
||||||
|
case '6':
|
||||||
|
case '7':
|
||||||
|
case '8':
|
||||||
|
case '9': {
|
||||||
char *end = NULL;
|
char *end = NULL;
|
||||||
errno = 0;
|
errno = 0;
|
||||||
long value = strtol(*curr_src, &end, 0);
|
long value = strtol(*curr_src, &end, 0);
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ struct ucl_object *ucl_special_defun(struct ucl *state, struct ucl_scope *scope,
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ucl_object *ucl_special_lambda(struct ucl *state, struct ucl_scope *scope, struct ucl_object *args) {
|
struct ucl_object *ucl_special_lambda(struct ucl *state, UNUSED struct ucl_scope *scope, struct ucl_object *args) {
|
||||||
// TODO: Check arguments
|
// TODO: Check arguments
|
||||||
struct ucl_object *fun_args = ucl_list_nth(state, args, 0);
|
struct ucl_object *fun_args = ucl_list_nth(state, args, 0);
|
||||||
if (fun_args->type != UCL_TYPE_CELL) {
|
if (fun_args->type != UCL_TYPE_CELL) {
|
||||||
@@ -167,7 +167,7 @@ struct ucl_object *ucl_special_progn(struct ucl *state, struct ucl_scope *scope,
|
|||||||
return ucl_progn(state, scope, args);
|
return ucl_progn(state, scope, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ucl_object *ucl_special_quote(struct ucl *state, struct ucl_scope *scope, struct ucl_object *args) {
|
struct ucl_object *ucl_special_quote(struct ucl *state, UNUSED struct ucl_scope *scope, struct ucl_object *args) {
|
||||||
return ucl_car(state, args);
|
return ucl_car(state, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
#include "uclisp.h"
|
#include "uclisp.h"
|
||||||
#include "lisp.h"
|
#include "lisp.h"
|
||||||
@@ -142,10 +143,12 @@ void ucl_print_obj(struct ucl_object *obj) {
|
|||||||
printf("(error \"%s\")", obj->error);
|
printf("(error \"%s\")", obj->error);
|
||||||
break;
|
break;
|
||||||
case UCL_TYPE_BUILTIN:
|
case UCL_TYPE_BUILTIN:
|
||||||
printf("<builtin %p>", obj->builtin);
|
// TODO: Hack to work around -pedantic temporarily
|
||||||
|
printf("<builtin %p>", (void *)(uintptr_t) obj->builtin);
|
||||||
break;
|
break;
|
||||||
case UCL_TYPE_SPECIAL:
|
case UCL_TYPE_SPECIAL:
|
||||||
printf("<special %p>", obj->special);
|
// TODO: Hack to work around -pedantic temporarily
|
||||||
|
printf("<special %p>", (void *)(uintptr_t) obj->special);
|
||||||
break;
|
break;
|
||||||
case UCL_TYPE_CELL: {
|
case UCL_TYPE_CELL: {
|
||||||
int first = true;
|
int first = true;
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ static void test_arena_single(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void test_arena_get_all(void) {
|
static void test_arena_get_all(void) {
|
||||||
struct test_5 *objects[NUM_OBJECTS] = {};
|
struct test_5 *objects[NUM_OBJECTS] = { NULL };
|
||||||
for (int i = 0; i < NUM_OBJECTS; i++) {
|
for (int i = 0; i < NUM_OBJECTS; i++) {
|
||||||
objects[i] = ucl_arena_get(arena);
|
objects[i] = ucl_arena_get(arena);
|
||||||
TEST_ASSERT_NOT_NULL(objects[i]);
|
TEST_ASSERT_NOT_NULL(objects[i]);
|
||||||
@@ -38,7 +38,7 @@ static void test_arena_get_all(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void test_arena_get_put_limit(void) {
|
static void test_arena_get_put_limit(void) {
|
||||||
struct test_5 *objects[NUM_OBJECTS] = {};
|
struct test_5 *objects[NUM_OBJECTS] = { NULL };
|
||||||
|
|
||||||
for (int i = 0; i < NUM_OBJECTS; i++) {
|
for (int i = 0; i < NUM_OBJECTS; i++) {
|
||||||
objects[i] = ucl_arena_get(arena);
|
objects[i] = ucl_arena_get(arena);
|
||||||
@@ -51,8 +51,7 @@ static void test_arena_get_put_limit(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void test_arena_get_over_limit(void) {
|
static void test_arena_get_over_limit(void) {
|
||||||
struct test_5 *objects[NUM_OBJECTS + 1] = {};
|
struct test_5 *objects[NUM_OBJECTS + 1] = { NULL };
|
||||||
|
|
||||||
for (int i = 0; i < NUM_OBJECTS + 1; i++) {
|
for (int i = 0; i < NUM_OBJECTS + 1; i++) {
|
||||||
objects[i] = ucl_arena_get(arena);
|
objects[i] = ucl_arena_get(arena);
|
||||||
if (i < NUM_OBJECTS) {
|
if (i < NUM_OBJECTS) {
|
||||||
|
|||||||
Reference in New Issue
Block a user