Browse Source

fixed C89 incompatibilities, added the check to CMake

main
Ludovic 'Archivist' Lagouardette 5 months ago
parent
commit
06dd262d05
2 changed files with 15 additions and 12 deletions
  1. +6
    -0
      CMakeLists.txt
  2. +9
    -12
      lib.c

+ 6
- 0
CMakeLists.txt View File

@ -18,6 +18,12 @@ add_executable(ink_exe main.c)
target_link_libraries(ink_exe PUBLIC ink) target_link_libraries(ink_exe PUBLIC ink)
target_include_directories(ink PUBLIC include) target_include_directories(ink PUBLIC include)
if(MSVC)
target_compile_options(ink PRIVATE /W4 /WX)
else()
target_compile_options(ink PRIVATE -Wall -Wextra -Wpedantic -Werror)
endif()
# Benchmark is broken since the addition to coroutines # Benchmark is broken since the addition to coroutines
# add_executable(ink_bench bench.c) # add_executable(ink_bench bench.c)
# target_link_libraries(ink_bench PUBLIC ink) # target_link_libraries(ink_bench PUBLIC ink)

+ 9
- 12
lib.c View File

@ -355,7 +355,7 @@ struct context* ink_make_default_context(void) {
} }
#endif #endif
static int ink_consume_one(int* end, struct context* pContext, char** buffer, char* r) {
static int ink_consume_one(int* end, struct context* pContext, char* r) {
int i; int i;
int done; int done;
struct elem value; struct elem value;
@ -471,7 +471,7 @@ restart_after_comment:
end = 0; end = 0;
goto restart_after_comment; goto restart_after_comment;
} }
err = ink_consume_one(&end, pContext, o">&buffer, r);
err = ink_consume_one(&end, pContext, r);
if(err < 0) { if(err < 0) {
pContext->panic = 1; pContext->panic = 1;
return -8; return -8;
@ -482,7 +482,7 @@ restart_after_comment:
} }
++buffer; ++buffer;
} }
err = ink_consume_one(&end, pContext, o">&buffer, r);
err = ink_consume_one(&end, pContext, r);
if(err < 0) { if(err < 0) {
pContext->panic = 1; pContext->panic = 1;
return -9; return -9;
@ -1328,7 +1328,7 @@ static void lte_int(struct context* ctx) {
currentRoutine->stack[currentRoutine->top-1].value = b.value <= a.value; currentRoutine->stack[currentRoutine->top-1].value = b.value <= a.value;
} }
#endif p">// NOEXTRAARITHMETIC
#endif m">/* NOEXTRAARITHMETIC */
static void lt_int(struct context* ctx) { static void lt_int(struct context* ctx) {
struct ink_routine* currentRoutine; struct ink_routine* currentRoutine;
@ -1559,9 +1559,9 @@ static void dump_stack(struct context* ctx) {
return; return;
} }
static void collect_noop(k">struct context* _1, void* _2) {}
static void collect_noop() {}
static struct ink_collection_list gc_noop(k">struct context* _1, void* _2) {
static struct ink_collection_list gc_noop() {
struct ink_collection_list c; struct ink_collection_list c;
c.elements = NULL; c.elements = NULL;
c.count = 0; c.count = 0;
@ -1674,7 +1674,6 @@ static void push_delimited_array(struct context* ctx) {
ary= ink_get_value(ctx, a); ary= ink_get_value(ctx, a);
for(idx = 1; idx <= currentRoutine->top; ++idx) { for(idx = 1; idx <= currentRoutine->top; ++idx) {
struct elem maybe_delim;
if(currentRoutine->stack[currentRoutine->top-idx].type == tid) { if(currentRoutine->stack[currentRoutine->top-idx].type == tid) {
break; break;
} }
@ -1822,7 +1821,6 @@ static void is_array(struct context* ctx) {
} }
static void is_int(struct context* ctx) { static void is_int(struct context* ctx) {
int tid;
struct ink_routine *currentRoutine; struct ink_routine *currentRoutine;
struct elem a; struct elem a;
@ -1843,7 +1841,6 @@ static void print_array_of_codepoints(struct context* ctx) {
struct ink_routine *currentRoutine; struct ink_routine *currentRoutine;
struct elem a; struct elem a;
struct ink_array *ary; struct ink_array *ary;
struct elem idx;
tid = get_type_by_name(ctx, "array"); tid = get_type_by_name(ctx, "array");
currentRoutine = ctx->routines + ctx->routine_current; currentRoutine = ctx->routines + ctx->routine_current;
@ -1892,7 +1889,7 @@ static void arrayify_stack(struct context* ctx) {
return; return;
} }
#endif p">// NOARRAYLIB
#endif m">/* NOARRAYLIB */
int ink_std_library(struct context* ctx) { int ink_std_library(struct context* ctx) {
int v; int v;
@ -1923,7 +1920,7 @@ int ink_std_library(struct context* ctx) {
v += ink_add_native(ctx, "=<", lte_int); v += ink_add_native(ctx, "=<", lte_int);
v += ink_add_native(ctx, "%", rem_int); v += ink_add_native(ctx, "%", rem_int);
v += ink_add_native(ctx, "int.xor", xor_int); v += ink_add_native(ctx, "int.xor", xor_int);
#endif p">// NOEXTRAARITHMETIC
#endif m">/* NOEXTRAARITHMETIC */
#ifndef NOARRAYLIB #ifndef NOARRAYLIB
ink_new_type(ctx, "array", sizeof(struct ink_array), collect_array, gc_array); ink_new_type(ctx, "array", sizeof(struct ink_array), collect_array, gc_array);
ink_new_type(ctx, "array_marker", 0, collect_noop, gc_noop); ink_new_type(ctx, "array_marker", 0, collect_noop, gc_noop);
@ -1937,7 +1934,7 @@ int ink_std_library(struct context* ctx) {
v += ink_add_native(ctx, "array.print_utf8", print_array_of_codepoints); v += ink_add_native(ctx, "array.print_utf8", print_array_of_codepoints);
v += ink_add_native(ctx, "is.array", is_array); v += ink_add_native(ctx, "is.array", is_array);
v += ink_add_native(ctx, "stack.to_array", arrayify_stack); v += ink_add_native(ctx, "stack.to_array", arrayify_stack);
#endif p">// NOARRAYLIB
#endif m">/* NOARRAYLIB */
return v; return v;
} }

Loading…
Cancel
Save