diff --git a/.dir-locals.el b/.dir-locals.el index 477c21e..506354d 100644 --- a/.dir-locals.el +++ b/.dir-locals.el @@ -3,5 +3,4 @@ ((nil . ((compile-command . "make MODE=debug -B -k") (+license/license-choice . "MIT License"))) - (c-mode . ((mode . clang-format))) - (c++-mode . ((mode . clang-format)))) + (c-mode . ((mode . clang-format)))) diff --git a/Makefile b/Makefile index 8fd88f3..dd198e2 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,10 @@ -CXX=c++ +CC=cc DIST=build OUT=$(DIST)/main.out LDFLAGS= -GFLAGS=-Wall -Wextra -Wpedantic -std=c++23 +GFLAGS=-Wall -Wextra -Wpedantic -std=c23 DFLAGS=-ggdb -fsanitize=address -fsanitize=undefined RFLAGS=-O3 @@ -16,10 +16,10 @@ CFLAGS=$(GFLAGS) $(DFLAGS) endif $(OUT): $(DIST)/main.o | $(DIST) - $(CXX) $(CFLAGS) -o $@ $^ $(LDFLAGS) + $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) -$(DIST)/main.o: main.cpp | $(DIST) - $(CXX) $(CFLAGS) -c -o $@ $^ +$(DIST)/main.o: main.c | $(DIST) + $(CC) $(CFLAGS) -c -o $@ $^ $(DIST): mkdir -p $(DIST) diff --git a/examples/hello-world.arl b/examples/hello-world.arl new file mode 100644 index 0000000..22d3740 --- /dev/null +++ b/examples/hello-world.arl @@ -0,0 +1 @@ +"Hello, world! println \ No newline at end of file diff --git a/main.c b/main.c new file mode 100644 index 0000000..f0d00aa --- /dev/null +++ b/main.c @@ -0,0 +1,56 @@ +/* main.cpp: + * Created: 2026-01-22 + * Author: Aryadev Chavali + * License: See end of file + * Commentary: + */ + +#include +#include +#include + +#define FAIL(...) \ + do \ + { \ + fprintf(stderr, "FAIL: "); \ + fprintf(stderr, __VA_ARGS__); \ + abort(); \ + } while (0) + +char *read_file(const char *filename) +{ + FILE *fp = fopen(filename, "rb"); + if (!fp) + FAIL("File `%s` does not exist\n", filename); + + fseek(fp, 0, SEEK_END); + long size = ftell(fp); + fseek(fp, 0, SEEK_SET); + char *buffer = calloc(1, size + 1); + fread(buffer, size, 1, fp); + fclose(fp); + + buffer[size] = '\0'; + return buffer; +} + +int main(void) +{ + const char *filename = "./examples/hello-world.arl"; + char *buffer = read_file(filename); + printf("%s => %s\n", filename, buffer); + free(buffer); + return 0; +} + +/* Copyright (C) 2026 Aryadev Chavali + + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the MIT License for details. + + * You may distribute and modify this code under the terms of the MIT License, + * which you should have received a copy of along with this program. If not, + * please go to . + + */ diff --git a/main.cpp b/main.cpp deleted file mode 100644 index 99ef05e..0000000 --- a/main.cpp +++ /dev/null @@ -1,26 +0,0 @@ -/* main.cpp: - * Created: 2026-01-22 - * Author: Aryadev Chavali - * License: See end of file - * Commentary: - */ - -#include - -int main(void) -{ - puts("Hello, world!"); - return 0; -} - -/* Copyright (C) 2026 Aryadev Chavali - - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the MIT License for details. - - * You may distribute and modify this code under the terms of the MIT License, - * which you should have received a copy of along with this program. If not, - * please go to . - - */