~dvko/pepper-lang

37bbd03a2167fe60e93d1dfd4c7bef9d8d216740 — Danny van Kooten 3 months ago 32d8ac4
compile with -std=c11 and add some additional compiler flags
5 files changed, 17 insertions(+), 8 deletions(-)

M .clangd
M Makefile
M src/lexer.h
M src/parser.c
M tests/vm_test.c
M .clangd => .clangd +1 -1
@@ 1,2 1,2 @@
CompileFlags:
  Add: [-std=c99, -Wall, -Wextra, -Wpedantic ]
  Add: [-std=c11, -Wall, -Wextra, -Wpedantic ]

M Makefile => Makefile +9 -4
@@ 1,6 1,6 @@
CFLAGS+= -Werror -Wall -Isrc/ -g 
CFLAGS+= -std=c11 -Wall -Wpedantic -Wstringop-overflow=3 -Wvla -Wundef -Wextra -Isrc/ -g
VPATH= src
TESTS= bin/lexer_test bin/parser_test bin/opcode_test bin/compiler_test bin/vm_test bin/symbol_table_test 
TESTS= bin/lexer_test bin/parser_test bin/opcode_test bin/compiler_test bin/vm_test bin/symbol_table_test

# disable crossjumping when using gcc so it doesn't optimize away our (optimized) dispatch table
ifeq "$(CC)" "gcc"


@@ 13,7 13,7 @@ bin/:
	mkdir -p bin/

bin/pepper: pepper.c lexer.c parser.c opcode.c compiler.c object.c symbol_table.c builtins.c vm.c gc.c | bin/
	$(CC) $(CFLAGS) $^ -Ofast -o $@ 
	$(CC) $(CFLAGS) $^ -O2 -march=native -mtune=native -flto -o $@

# tests
bin/lexer_test: tests/lexer_test.c lexer.c | bin/


@@ 22,13 22,18 @@ bin/opcode_test: tests/opcode_test.c opcode.c | bin/
bin/compiler_test: tests/compiler_test.c lexer.c parser.c opcode.c compiler.c object.c symbol_table.c builtins.c | bin/
bin/vm_test: tests/vm_test.c lexer.c parser.c opcode.c compiler.c object.c symbol_table.c builtins.c vm.c gc.c | bin/
bin/symbol_table_test: tests/symbol_table_test.c symbol_table.c | bin/
bin/%_test: CFLAGS+=-fstack-protector-strong -fstrict-aliasing -O2 -D_FORTIFY_SOURCE=2 -DTEST_MODE
bin/%_test: 
	$(CC) $(CFLAGS) -DTEST_MODE $^ -o $@
	$(CC) $(CFLAGS) $^ -o $@

.PHONY: check
check: $(TESTS)
	for test in $^; do $$test || exit 1; done

.PHONY: sanitizers
sanitizers: CFLAGS+=-fsanitize=address,undefined
sanitizers: check

.PHONY: memcheck
memcheck: $(TESTS)
	for test in $^; do valgrind $$test || exit 1; done

M src/lexer.h => src/lexer.h +1 -1
@@ 73,4 73,4 @@ struct lexer {

int gettoken(struct lexer *l, struct token *t);
struct lexer new_lexer(const char *input);
const char *token_type_to_str(enum token_type type);
\ No newline at end of file
const char *token_type_to_str(enum token_type type);

M src/parser.c => src/parser.c +4 -1
@@ 113,7 113,10 @@ add_parsing_error(struct parser *p, const char *_format, ...)
static void
next_token(struct parser * p) {
    p->current_token = p->next_token;
    gettoken(p->lexer, &p->next_token);

    if (p->current_token.type != TOKEN_EOF) {
        gettoken(p->lexer, &p->next_token);
    }
}

static bool 

M tests/vm_test.c => tests/vm_test.c +2 -1
@@ 1,5 1,6 @@
#include <stdbool.h>
#include <stdint.h>
#include <strings.h>
#include "test_helpers.h"
#include "../src/vm.h"
#include "../src/compiler.h"


@@ 879,4 880,4 @@ int main(int argc, const char *argv[]) {
    TEST(string_slices);
    TEST(builtin_str_contains);
    TEST(copies);
}
\ No newline at end of file
}