diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md new file mode 100644 index 0000000..2a9084e --- /dev/null +++ b/.github/copilot-instructions.md @@ -0,0 +1,3 @@ +# C2 +C2 is a compiler for a new language. +See the README.md for information about this project. diff --git a/.github/skills/implement/SKILL.md b/.github/skills/implement/SKILL.md new file mode 100644 index 0000000..4ec1c4d --- /dev/null +++ b/.github/skills/implement/SKILL.md @@ -0,0 +1,6 @@ +--- +name: implement +description: 'Implement all @copilot annotations' +--- + +Find and implement all `@copilot` comments in the codebase. Only modify code related to those annotations. Skip e2e tests unless asked. \ No newline at end of file diff --git a/Makefile b/Makefile index ef0bd85..88d71fb 100644 --- a/Makefile +++ b/Makefile @@ -1,19 +1,8 @@ -.PHONY: all clean - -SRC := main.c -BINDIR := bin -OBJ := $(SRC:%.c=$(BINDIR)/%.o) +.PHONY: all test clean all: c2 -clean: - rm -rv bin +c2: v0/bin/c2 + # @copilot copy the compiler -c2: $(OBJ) - gcc -o $@ $< - -$(BINDIR)/%.o: %.c - gcc -c -o $@ $< - -$(BINDIR): - mkdir -p $(BINDIR) +include v0/include.mk \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..af4d241 --- /dev/null +++ b/README.md @@ -0,0 +1,17 @@ +# C2 +C2 is a programming language based on C. +It adds modern high-level features such as metaprogramming, generics, etc, +but compiles down to C89. + +## Building +To build the c2–compiler, simply run `make` or `make all`. +This will build the compiler and run the tests. + +In order to only build the compiler, run `make c2`. +In order to run the tests, run `make test`. + +## Versioning +The current version is v0. Its source code lives in the `v0` directory. + +## Languages Specifications +See the specs directory for information on the actual language syntax. \ No newline at end of file diff --git a/v0/include.mk b/v0/include.mk new file mode 100644 index 0000000..04f102e --- /dev/null +++ b/v0/include.mk @@ -0,0 +1,14 @@ +V0_SRC := # @copilot include everything in src +V0_TEST := # @copilot include everything in test + +V0_SRC_OBJ := # @copilot implement. exampleL v0/src/main.c -> v0/bin/src/main.o +V0_TEST_OBJ := # @copilot + +v0/bin/c2: $(V0_SRC OBJ) + # @copilot implement + +v0/bin/test: $(V0_SRC_TEST) + # @copilot implement + +# @copilot add target that builds each .c file into a .o file. +# Ensure header dependencies are tracked correctly. diff --git a/v0/tests/test.c b/v0/tests/test.c new file mode 100644 index 0000000..71053b3 --- /dev/null +++ b/v0/tests/test.c @@ -0,0 +1,24 @@ +#include "test.h" + +// @copilot implement fail() + +static int s_totalTests; +static int s_greenTests; + +static Test[] = { + // @copilot add all tests +}; + +int main(int argc, char** argv) { + /* + @copilot loop over each test. + If the test is good, count the test as part of green test. + Otherwise, go to the next one. + + The start of the test must log the name of the test method. + After the test, log either "[OK]" or "[FAIL]". + + At the very end, log the name of each failed test and the total + number of green tests compared to the total. + */ +} \ No newline at end of file diff --git a/v0/tests/test.h b/v0/tests/test.h new file mode 100644 index 0000000..095927a --- /dev/null +++ b/v0/tests/test.h @@ -0,0 +1,16 @@ +/** + * Contains test assertions routines. + */ +#ifndef TEST_H +#define TEST_H + +// @copilot fix the syntax. This is a typedef for any function taking a void and returning void. +typedef Test void(void); + +/** + * Fails a test. + * @param msg The message to print to the console. + */ +void fail(const char* msg); + +#endif