hachem.wtf
aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhachem <im@hachem.wtf>2026-09-19 10:16:12 +0200
committerhachem <im@hachem.wtf>2026-09-19 10:16:12 +0200
commit0393d0b61b44a2b4df77a36bc63d64c5842971f9 (patch)
treeec2a2124ce3294305046f1c6afa5630be38e08a4
init: makefile, readme and clang bs
-rw-r--r--.clang-format20
-rw-r--r--.clang-tidy9
-rw-r--r--.gitignore2
-rw-r--r--Makefile56
-rw-r--r--README17
5 files changed, 104 insertions, 0 deletions
diff --git a/.clang-format b/.clang-format
new file mode 100644
index 0000000..e7d632d
--- /dev/null
+++ b/.clang-format
@@ -0,0 +1,20 @@
+Language: Cpp
+BasedOnStyle: LLVM
+IndentWidth: 4
+TabWidth: 4
+UseTab: Never
+ContinuationIndentWidth: 8
+ColumnLimit: 100
+BreakBeforeBraces: Allman
+PointerAlignment: Left
+AllowShortFunctionsOnASingleLine: None
+AllowShortIfStatementsOnASingleLine: Never
+AllowShortLoopsOnASingleLine: false
+AllowShortBlocksOnASingleLine: Never
+AllowShortCaseLabelsOnASingleLine: true
+IndentCaseLabels: true
+SpaceBeforeParens: ControlStatements
+SortIncludes: false
+Cpp11BracedListStyle: false
+AlignOperands: DontAlign
+AlignAfterOpenBracket: Align
diff --git a/.clang-tidy b/.clang-tidy
new file mode 100644
index 0000000..49e2d00
--- /dev/null
+++ b/.clang-tidy
@@ -0,0 +1,9 @@
+Checks: '-*,readability-identifier-naming'
+WarningsAsErrors: 'readability-identifier-naming'
+CheckOptions:
+ readability-identifier-naming.StructCase: CamelCase
+ readability-identifier-naming.EnumCase: CamelCase
+ readability-identifier-naming.EnumConstantCase: UPPER_CASE
+ readability-identifier-naming.FunctionCase: lower_case
+ readability-identifier-naming.ParameterCase: lower_case
+ readability-identifier-naming.MacroDefinitionCase: UPPER_CASE
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..8d506d2
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+bin/
+sfinae
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..8d873b9
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,56 @@
+CC = cc
+YACC = bison
+CFLAGS = -std=c99 -Wall -Wextra -Werror -Wpedantic -O2 -Ibin
+SOURCES = ast.c ast.h eval.c eval.h lexer.c lexer.h main.c
+OBJECTS = bin/parser.o bin/lexer.o bin/ast.o bin/eval.o bin/main.o
+SANITIZE = -g -O0 -fsanitize=address,undefined
+
+.PHONY: all debug check format lint clean
+
+all: sfinae
+
+bin:
+ mkdir -p bin
+
+sfinae: $(OBJECTS)
+ $(CC) $(CFLAGS) -o $@ $(OBJECTS)
+
+bin/parser.c bin/parser.h: sfinae.y | bin
+ $(YACC) -d -o bin/parser.c sfinae.y
+
+bin/parser.o: bin/parser.c
+ $(CC) -std=c99 -w -I. -c -o $@ bin/parser.c
+
+bin/%.o: %.c | bin
+ $(CC) $(CFLAGS) -c -o $@ $<
+
+bin/lexer.o: bin/parser.h ast.h lexer.h
+bin/main.o: ast.h eval.h lexer.h
+bin/ast.o: ast.h lexer.h
+bin/eval.o: eval.h ast.h
+
+debug: CFLAGS += $(SANITIZE)
+debug: clean sfinae
+
+check: sfinae
+ @for example in examples/*.sfinae; do \
+ expected="$${example%.sfinae}.expected"; \
+ if ./sfinae "$$example" | diff -u "$$expected" - >/dev/null; then \
+ echo "ok $$example"; \
+ else \
+ echo "FAIL $$example"; ./sfinae "$$example" | diff -u "$$expected" -; exit 1; \
+ fi; \
+ done
+
+format:
+ clang-format -i $(SOURCES)
+
+LINT_FILTER = '[{"name":"parser.h","lines":[[1,1]]}, \
+ {"name":"ast.c"},{"name":"eval.c"},{"name":"lexer.c"},{"name":"main.c"}, \
+ {"name":"ast.h"},{"name":"eval.h"},{"name":"lexer.h"}]'
+
+lint: bin/parser.h
+ clang-tidy --line-filter=$(LINT_FILTER) ast.c eval.c lexer.c main.c -- -std=c99 -Ibin
+
+clean:
+ rm -rf bin sfinae
diff --git a/README b/README
new file mode 100644
index 0000000..b7e376f
--- /dev/null
+++ b/README
@@ -0,0 +1,17 @@
+# sfinae
+
+Substitution Failure Is Not An Error. Everything else is.
+A toy language which takes' C++ template metaprogramming to another level.
+
+## build
+
+ make release build, ./sfinae in the root, objects in bin/
+ make debug rebuild with address and undefined sanitizers
+ make check run examples/ against their .expected files
+ make format clang-format the sources
+ make lint clang-tidy naming check
+ make clean
+
+## run
+
+ ./sfinae examples/hello.sfinae