diff --git a/Makefile b/Makefile deleted file mode 100644 index b89dd4b..0000000 --- a/Makefile +++ /dev/null @@ -1,42 +0,0 @@ -# Aux functions -rwildcard = $(foreach d, $(wildcard $(1:=/*)), $(call rwildcard ,$d, $2) $(filter $(subst *, %, $2), $d)) - -# Compiler -CXX = gcc -CC = $(CROSS_COMPILE)$(CXX) - -# Compiler flags -CFLAGS = -O3 -Wall -Wextra -g -LFLAGS = -lm - -# Files and directories -SRCDIR = src -OBJDIR = temp -BINDIR = build -OUTFILE = noja - -# Find all files -SRC = $(call rwildcard, $(SRCDIR), *.c) -OBJS = $(patsubst $(SRCDIR)/%.c, $(OBJDIR)/%.o, $(SRC)) - - -# Compile everything to object files -$(OBJDIR)/%.o: $(SRCDIR)/%.c - @ echo $(shell tput setaf 3) [C] $(shell tput setaf 5) [SRC] $(shell tput setaf 7) $^ - @ mkdir -p $(@D) - @ $(CC) $(CFLAGS) -c $^ -o $@ - - - -# Clean all artifacts and rebuild the whole thing -all: clean $(OBJS) build - -# Link all object files -build: - @ echo !==== LINKING - @ mkdir -p $(BINDIR) - @ $(CC) -o $(BINDIR)/$(OUTFILE) $(OBJS) $(LFLAGS) - -clean: - @ rm -rf $(BINDIR) - @ rm -rf $(OBJDIR) diff --git a/assembler.o b/assembler.o new file mode 100644 index 0000000..d5bebef Binary files /dev/null and b/assembler.o differ diff --git a/cache/cli/main.o b/cache/cli/main.o new file mode 100644 index 0000000..c8a6f46 Binary files /dev/null and b/cache/cli/main.o differ diff --git a/cache/noja/assembler/assembler.o b/cache/noja/assembler/assembler.o new file mode 100644 index 0000000..d5bebef Binary files /dev/null and b/cache/noja/assembler/assembler.o differ diff --git a/cache/noja/builtins/basic.o b/cache/noja/builtins/basic.o new file mode 100644 index 0000000..8813ca9 Binary files /dev/null and b/cache/noja/builtins/basic.o differ diff --git a/cache/noja/builtins/files.o b/cache/noja/builtins/files.o new file mode 100644 index 0000000..76903e5 Binary files /dev/null and b/cache/noja/builtins/files.o differ diff --git a/cache/noja/builtins/math.o b/cache/noja/builtins/math.o new file mode 100644 index 0000000..54dd9e1 Binary files /dev/null and b/cache/noja/builtins/math.o differ diff --git a/cache/noja/common/executable.o b/cache/noja/common/executable.o new file mode 100644 index 0000000..4ae94db Binary files /dev/null and b/cache/noja/common/executable.o differ diff --git a/cache/noja/compiler/compile.o b/cache/noja/compiler/compile.o new file mode 100644 index 0000000..e5cfaf8 Binary files /dev/null and b/cache/noja/compiler/compile.o differ diff --git a/cache/noja/compiler/parse.o b/cache/noja/compiler/parse.o new file mode 100644 index 0000000..f666502 Binary files /dev/null and b/cache/noja/compiler/parse.o differ diff --git a/cache/noja/noja.o b/cache/noja/noja.o new file mode 100644 index 0000000..c333c9a Binary files /dev/null and b/cache/noja/noja.o differ diff --git a/cache/noja/noja_internals.o b/cache/noja/noja_internals.o new file mode 100644 index 0000000..b47f6a2 Binary files /dev/null and b/cache/noja/noja_internals.o differ diff --git a/cache/noja/objects/heap.o b/cache/noja/objects/heap.o new file mode 100644 index 0000000..05df075 Binary files /dev/null and b/cache/noja/objects/heap.o differ diff --git a/cache/noja/objects/o_bool.o b/cache/noja/objects/o_bool.o new file mode 100644 index 0000000..34772b9 Binary files /dev/null and b/cache/noja/objects/o_bool.o differ diff --git a/cache/noja/objects/o_buffer.o b/cache/noja/objects/o_buffer.o new file mode 100644 index 0000000..e664c23 Binary files /dev/null and b/cache/noja/objects/o_buffer.o differ diff --git a/cache/noja/objects/o_closure.o b/cache/noja/objects/o_closure.o new file mode 100644 index 0000000..dfe03bf Binary files /dev/null and b/cache/noja/objects/o_closure.o differ diff --git a/cache/noja/objects/o_dir.o b/cache/noja/objects/o_dir.o new file mode 100644 index 0000000..b1a64bc Binary files /dev/null and b/cache/noja/objects/o_dir.o differ diff --git a/cache/noja/objects/o_file.o b/cache/noja/objects/o_file.o new file mode 100644 index 0000000..4fde6af Binary files /dev/null and b/cache/noja/objects/o_file.o differ diff --git a/cache/noja/objects/o_float.o b/cache/noja/objects/o_float.o new file mode 100644 index 0000000..b78dba4 Binary files /dev/null and b/cache/noja/objects/o_float.o differ diff --git a/cache/noja/objects/o_int.o b/cache/noja/objects/o_int.o new file mode 100644 index 0000000..e5974f7 Binary files /dev/null and b/cache/noja/objects/o_int.o differ diff --git a/cache/noja/objects/o_list.o b/cache/noja/objects/o_list.o new file mode 100644 index 0000000..8b88e6a Binary files /dev/null and b/cache/noja/objects/o_list.o differ diff --git a/cache/noja/objects/o_map.o b/cache/noja/objects/o_map.o new file mode 100644 index 0000000..6ede682 Binary files /dev/null and b/cache/noja/objects/o_map.o differ diff --git a/cache/noja/objects/o_none.o b/cache/noja/objects/o_none.o new file mode 100644 index 0000000..192315c Binary files /dev/null and b/cache/noja/objects/o_none.o differ diff --git a/cache/noja/objects/o_string.o b/cache/noja/objects/o_string.o new file mode 100644 index 0000000..ed8c221 Binary files /dev/null and b/cache/noja/objects/o_string.o differ diff --git a/cache/noja/objects/objects.o b/cache/noja/objects/objects.o new file mode 100644 index 0000000..41a5862 Binary files /dev/null and b/cache/noja/objects/objects.o differ diff --git a/cache/noja/runtime/o_func.o b/cache/noja/runtime/o_func.o new file mode 100644 index 0000000..f3358e0 Binary files /dev/null and b/cache/noja/runtime/o_func.o differ diff --git a/cache/noja/runtime/o_nfunc.o b/cache/noja/runtime/o_nfunc.o new file mode 100644 index 0000000..50c7602 Binary files /dev/null and b/cache/noja/runtime/o_nfunc.o differ diff --git a/cache/noja/runtime/o_staticmap.o b/cache/noja/runtime/o_staticmap.o new file mode 100644 index 0000000..2100579 Binary files /dev/null and b/cache/noja/runtime/o_staticmap.o differ diff --git a/cache/noja/runtime/runtime.o b/cache/noja/runtime/runtime.o new file mode 100644 index 0000000..a2d5d86 Binary files /dev/null and b/cache/noja/runtime/runtime.o differ diff --git a/cache/noja/runtime/runtime_error.o b/cache/noja/runtime/runtime_error.o new file mode 100644 index 0000000..5ececc7 Binary files /dev/null and b/cache/noja/runtime/runtime_error.o differ diff --git a/cache/noja/utils/bpalloc.o b/cache/noja/utils/bpalloc.o new file mode 100644 index 0000000..6fc8ac7 Binary files /dev/null and b/cache/noja/utils/bpalloc.o differ diff --git a/cache/noja/utils/bucketlist.o b/cache/noja/utils/bucketlist.o new file mode 100644 index 0000000..6da73b6 Binary files /dev/null and b/cache/noja/utils/bucketlist.o differ diff --git a/cache/noja/utils/error.o b/cache/noja/utils/error.o new file mode 100644 index 0000000..a017996 Binary files /dev/null and b/cache/noja/utils/error.o differ diff --git a/cache/noja/utils/hash.o b/cache/noja/utils/hash.o new file mode 100644 index 0000000..3922670 Binary files /dev/null and b/cache/noja/utils/hash.o differ diff --git a/cache/noja/utils/labellist.o b/cache/noja/utils/labellist.o new file mode 100644 index 0000000..b6a361b Binary files /dev/null and b/cache/noja/utils/labellist.o differ diff --git a/cache/noja/utils/promise.o b/cache/noja/utils/promise.o new file mode 100644 index 0000000..292a849 Binary files /dev/null and b/cache/noja/utils/promise.o differ diff --git a/cache/noja/utils/source.o b/cache/noja/utils/source.o new file mode 100644 index 0000000..a6f3594 Binary files /dev/null and b/cache/noja/utils/source.o differ diff --git a/cache/noja/utils/stack.o b/cache/noja/utils/stack.o new file mode 100644 index 0000000..e4def38 Binary files /dev/null and b/cache/noja/utils/stack.o differ diff --git a/cache/noja/utils/utf8.o b/cache/noja/utils/utf8.o new file mode 100644 index 0000000..04e0b97 Binary files /dev/null and b/cache/noja/utils/utf8.o differ diff --git a/libnoja.a b/libnoja.a new file mode 100644 index 0000000..c1c9a62 Binary files /dev/null and b/libnoja.a differ diff --git a/makefile b/makefile new file mode 100644 index 0000000..83f6c44 --- /dev/null +++ b/makefile @@ -0,0 +1,87 @@ + +# ===================== # +# === Configuration === # +# ===================== # + +# Destination folder of the final artifacts +# (it must exist beforehand) +OUTDIR = . + +# Base folder of the source tree +SRCDIR = src + +# Temporary directory where all intermediary +# artifacts will be stored (if it doesn't exist, +# it will be created). It's important that this +# folder isn't used for something other than +# holding object files since it will be deleted +# when doing `make clean`. +OBJDIR = cache + +# Source directory for each program to be build +# They are relative to the SRCDIR folder. +LIB_SUBDIR = noja +CLI_SUBDIR = cli + +# Resulting file names +LIB_FNAME = libnoja.a +CLI_FNAME = noja + +# Default programs +CC = gcc +AR = ar + +# Program flags +CFLAGS = -Wall -Wextra +LFLAGS = -lm + +# ===================== # +# === Variables ======= # +# ===================== # + +# Auxiliary function +rwildcard = $(foreach d, $(wildcard $(1:=/*)), $(call rwildcard ,$d, $2) $(filter $(subst *, %, $2), $d)) + +# Absolute path of each program's source tree +LIB_SRCDIR = $(SRCDIR)/$(LIB_SUBDIR) +CLI_SRCDIR = $(SRCDIR)/$(CLI_SUBDIR) + +# Each program that is being build uses as object +# cache a subfolder of OBJDIR called like the it's +# source tree base folder in SRCDIR. +LIB_OBJDIR = $(OBJDIR)/$(LIB_SUBDIR) +CLI_OBJDIR = $(OBJDIR)/$(CLI_SUBDIR) + +LIB_CFILES = $(call rwildcard, $(LIB_SRCDIR), *.c) +LIB_HFILES = $(call rwildcard, $(LIB_SRCDIR), *.h) +LIB_OFILES = $(patsubst $(LIB_SRCDIR)/%.c, $(LIB_OBJDIR)/%.o, $(LIB_CFILES)) + +CLI_CFILES = $(call rwildcard, $(CLI_SRCDIR), *.c) +CLI_HFILES = $(call rwildcard, $(CLI_SRCDIR), *.h) +CLI_OFILES = $(patsubst $(CLI_SRCDIR)/%.c, $(CLI_OBJDIR)/%.o, $(CLI_CFILES)) + +# Useful abbreviations +LIB = $(OUTDIR)/$(LIB_FNAME) +CLI = $(OUTDIR)/$(CLI_FNAME) + +# ===================== # +# === Rules =========== # +# ===================== # + +all: $(LIB) $(CLI) + +$(OBJDIR)/%.o: $(SRCDIR)/%.c + @ mkdir -p $(@D) + $(CC) $(CFLAGS) -c $^ -o $@ + +$(LIB): $(LIB_OFILES) + @ echo $(AR) rcs $@ ... + @ $(AR) rcs $@ $(LIB_OFILES) + +$(CLI): $(CLI_OFILES) $(LIB) + $(CC) $^ -o $@ $(LFLAGS) + +clean: + rm -rf $(OBJDIR) + rm -f $(LIB) + rm -f $(CLI) \ No newline at end of file diff --git a/noja b/noja new file mode 100755 index 0000000..db82667 Binary files /dev/null and b/noja differ diff --git a/src/main.c b/src/cli/main.c similarity index 99% rename from src/main.c rename to src/cli/main.c index 2bf53e7..42bb96b 100644 --- a/src/main.c +++ b/src/cli/main.c @@ -32,7 +32,7 @@ #include #include #include -#include "libnoja/noja.h" +#include "../noja/noja.h" static const char usage[] = "Usage patterns:\n" diff --git a/src/README.md b/src/noja/README.md similarity index 100% rename from src/README.md rename to src/noja/README.md diff --git a/src/libnoja/assembler/assembler.c b/src/noja/assembler/assembler.c similarity index 100% rename from src/libnoja/assembler/assembler.c rename to src/noja/assembler/assembler.c diff --git a/src/libnoja/assembler/assembler.h b/src/noja/assembler/assembler.h similarity index 100% rename from src/libnoja/assembler/assembler.h rename to src/noja/assembler/assembler.h diff --git a/src/libnoja/builtins/README.md b/src/noja/builtins/README.md similarity index 100% rename from src/libnoja/builtins/README.md rename to src/noja/builtins/README.md diff --git a/src/libnoja/builtins/basic.c b/src/noja/builtins/basic.c similarity index 100% rename from src/libnoja/builtins/basic.c rename to src/noja/builtins/basic.c diff --git a/src/libnoja/builtins/basic.h b/src/noja/builtins/basic.h similarity index 100% rename from src/libnoja/builtins/basic.h rename to src/noja/builtins/basic.h diff --git a/src/libnoja/builtins/files.c b/src/noja/builtins/files.c similarity index 100% rename from src/libnoja/builtins/files.c rename to src/noja/builtins/files.c diff --git a/src/libnoja/builtins/files.h b/src/noja/builtins/files.h similarity index 100% rename from src/libnoja/builtins/files.h rename to src/noja/builtins/files.h diff --git a/src/libnoja/builtins/math.c b/src/noja/builtins/math.c similarity index 100% rename from src/libnoja/builtins/math.c rename to src/noja/builtins/math.c diff --git a/src/libnoja/builtins/math.h b/src/noja/builtins/math.h similarity index 100% rename from src/libnoja/builtins/math.h rename to src/noja/builtins/math.h diff --git a/src/libnoja/common/executable.c b/src/noja/common/executable.c similarity index 100% rename from src/libnoja/common/executable.c rename to src/noja/common/executable.c diff --git a/src/libnoja/common/executable.h b/src/noja/common/executable.h similarity index 100% rename from src/libnoja/common/executable.h rename to src/noja/common/executable.h diff --git a/src/libnoja/compiler/AST.h b/src/noja/compiler/AST.h similarity index 100% rename from src/libnoja/compiler/AST.h rename to src/noja/compiler/AST.h diff --git a/src/libnoja/compiler/ASTi.h b/src/noja/compiler/ASTi.h similarity index 100% rename from src/libnoja/compiler/ASTi.h rename to src/noja/compiler/ASTi.h diff --git a/src/libnoja/compiler/compile.c b/src/noja/compiler/compile.c similarity index 100% rename from src/libnoja/compiler/compile.c rename to src/noja/compiler/compile.c diff --git a/src/libnoja/compiler/compile.h b/src/noja/compiler/compile.h similarity index 100% rename from src/libnoja/compiler/compile.h rename to src/noja/compiler/compile.h diff --git a/src/libnoja/compiler/parse.c b/src/noja/compiler/parse.c similarity index 100% rename from src/libnoja/compiler/parse.c rename to src/noja/compiler/parse.c diff --git a/src/libnoja/compiler/parse.h b/src/noja/compiler/parse.h similarity index 100% rename from src/libnoja/compiler/parse.h rename to src/noja/compiler/parse.h diff --git a/src/libnoja/noja.c b/src/noja/noja.c similarity index 100% rename from src/libnoja/noja.c rename to src/noja/noja.c diff --git a/src/libnoja/noja.h b/src/noja/noja.h similarity index 100% rename from src/libnoja/noja.h rename to src/noja/noja.h diff --git a/src/noja/noja_internals.c b/src/noja/noja_internals.c new file mode 100644 index 0000000..e69de29 diff --git a/src/noja/noja_internals.h b/src/noja/noja_internals.h new file mode 100644 index 0000000..30f0417 --- /dev/null +++ b/src/noja/noja_internals.h @@ -0,0 +1,8 @@ + +typedef struct NOJA_Executable NOJA_Executable; +char *NOJA_disassemble(NOJA_Executable *exe); +NOJA_Executable *NOJA_assembleString(const char *str); +NOJA_Executable *NOJA_assembleFile(const char *file); +NOJA_Executable *NOJA_compileString(const char *str); +NOJA_Executable *NOJA_compileFile(const char *file); +bool NOJA_compareExecutables(NOJA_Executable *exe1, NOJA_Executable *exe2); diff --git a/src/libnoja/objects/heap.c b/src/noja/objects/heap.c similarity index 100% rename from src/libnoja/objects/heap.c rename to src/noja/objects/heap.c diff --git a/src/libnoja/objects/o_bool.c b/src/noja/objects/o_bool.c similarity index 100% rename from src/libnoja/objects/o_bool.c rename to src/noja/objects/o_bool.c diff --git a/src/libnoja/objects/o_buffer.c b/src/noja/objects/o_buffer.c similarity index 100% rename from src/libnoja/objects/o_buffer.c rename to src/noja/objects/o_buffer.c diff --git a/src/libnoja/objects/o_closure.c b/src/noja/objects/o_closure.c similarity index 100% rename from src/libnoja/objects/o_closure.c rename to src/noja/objects/o_closure.c diff --git a/src/libnoja/objects/o_dir.c b/src/noja/objects/o_dir.c similarity index 100% rename from src/libnoja/objects/o_dir.c rename to src/noja/objects/o_dir.c diff --git a/src/libnoja/objects/o_file.c b/src/noja/objects/o_file.c similarity index 100% rename from src/libnoja/objects/o_file.c rename to src/noja/objects/o_file.c diff --git a/src/libnoja/objects/o_float.c b/src/noja/objects/o_float.c similarity index 100% rename from src/libnoja/objects/o_float.c rename to src/noja/objects/o_float.c diff --git a/src/libnoja/objects/o_int.c b/src/noja/objects/o_int.c similarity index 100% rename from src/libnoja/objects/o_int.c rename to src/noja/objects/o_int.c diff --git a/src/libnoja/objects/o_list.c b/src/noja/objects/o_list.c similarity index 100% rename from src/libnoja/objects/o_list.c rename to src/noja/objects/o_list.c diff --git a/src/libnoja/objects/o_map.c b/src/noja/objects/o_map.c similarity index 100% rename from src/libnoja/objects/o_map.c rename to src/noja/objects/o_map.c diff --git a/src/libnoja/objects/o_none.c b/src/noja/objects/o_none.c similarity index 100% rename from src/libnoja/objects/o_none.c rename to src/noja/objects/o_none.c diff --git a/src/libnoja/objects/o_string.c b/src/noja/objects/o_string.c similarity index 100% rename from src/libnoja/objects/o_string.c rename to src/noja/objects/o_string.c diff --git a/src/libnoja/objects/objects.c b/src/noja/objects/objects.c similarity index 100% rename from src/libnoja/objects/objects.c rename to src/noja/objects/objects.c diff --git a/src/libnoja/objects/objects.h b/src/noja/objects/objects.h similarity index 100% rename from src/libnoja/objects/objects.h rename to src/noja/objects/objects.h diff --git a/src/libnoja/runtime/o_func.c b/src/noja/runtime/o_func.c similarity index 100% rename from src/libnoja/runtime/o_func.c rename to src/noja/runtime/o_func.c diff --git a/src/libnoja/runtime/o_nfunc.c b/src/noja/runtime/o_nfunc.c similarity index 100% rename from src/libnoja/runtime/o_nfunc.c rename to src/noja/runtime/o_nfunc.c diff --git a/src/libnoja/runtime/o_staticmap.c b/src/noja/runtime/o_staticmap.c similarity index 100% rename from src/libnoja/runtime/o_staticmap.c rename to src/noja/runtime/o_staticmap.c diff --git a/src/libnoja/runtime/runtime.c b/src/noja/runtime/runtime.c similarity index 100% rename from src/libnoja/runtime/runtime.c rename to src/noja/runtime/runtime.c diff --git a/src/libnoja/runtime/runtime.h b/src/noja/runtime/runtime.h similarity index 100% rename from src/libnoja/runtime/runtime.h rename to src/noja/runtime/runtime.h diff --git a/src/libnoja/runtime/runtime_error.c b/src/noja/runtime/runtime_error.c similarity index 100% rename from src/libnoja/runtime/runtime_error.c rename to src/noja/runtime/runtime_error.c diff --git a/src/libnoja/utils/bpalloc.c b/src/noja/utils/bpalloc.c similarity index 100% rename from src/libnoja/utils/bpalloc.c rename to src/noja/utils/bpalloc.c diff --git a/src/libnoja/utils/bpalloc.h b/src/noja/utils/bpalloc.h similarity index 100% rename from src/libnoja/utils/bpalloc.h rename to src/noja/utils/bpalloc.h diff --git a/src/libnoja/utils/bucketlist.c b/src/noja/utils/bucketlist.c similarity index 100% rename from src/libnoja/utils/bucketlist.c rename to src/noja/utils/bucketlist.c diff --git a/src/libnoja/utils/bucketlist.h b/src/noja/utils/bucketlist.h similarity index 100% rename from src/libnoja/utils/bucketlist.h rename to src/noja/utils/bucketlist.h diff --git a/src/libnoja/utils/defs.h b/src/noja/utils/defs.h similarity index 100% rename from src/libnoja/utils/defs.h rename to src/noja/utils/defs.h diff --git a/src/libnoja/utils/error.c b/src/noja/utils/error.c similarity index 100% rename from src/libnoja/utils/error.c rename to src/noja/utils/error.c diff --git a/src/libnoja/utils/error.h b/src/noja/utils/error.h similarity index 100% rename from src/libnoja/utils/error.h rename to src/noja/utils/error.h diff --git a/src/libnoja/utils/hash.c b/src/noja/utils/hash.c similarity index 100% rename from src/libnoja/utils/hash.c rename to src/noja/utils/hash.c diff --git a/src/libnoja/utils/hash.h b/src/noja/utils/hash.h similarity index 100% rename from src/libnoja/utils/hash.h rename to src/noja/utils/hash.h diff --git a/src/libnoja/utils/labellist.c b/src/noja/utils/labellist.c similarity index 100% rename from src/libnoja/utils/labellist.c rename to src/noja/utils/labellist.c diff --git a/src/libnoja/utils/labellist.h b/src/noja/utils/labellist.h similarity index 100% rename from src/libnoja/utils/labellist.h rename to src/noja/utils/labellist.h diff --git a/src/libnoja/utils/promise.c b/src/noja/utils/promise.c similarity index 100% rename from src/libnoja/utils/promise.c rename to src/noja/utils/promise.c diff --git a/src/libnoja/utils/promise.h b/src/noja/utils/promise.h similarity index 100% rename from src/libnoja/utils/promise.h rename to src/noja/utils/promise.h diff --git a/src/libnoja/utils/source.c b/src/noja/utils/source.c similarity index 100% rename from src/libnoja/utils/source.c rename to src/noja/utils/source.c diff --git a/src/libnoja/utils/source.h b/src/noja/utils/source.h similarity index 100% rename from src/libnoja/utils/source.h rename to src/noja/utils/source.h diff --git a/src/libnoja/utils/stack.c b/src/noja/utils/stack.c similarity index 100% rename from src/libnoja/utils/stack.c rename to src/noja/utils/stack.c diff --git a/src/libnoja/utils/stack.h b/src/noja/utils/stack.h similarity index 100% rename from src/libnoja/utils/stack.h rename to src/noja/utils/stack.h diff --git a/src/libnoja/utils/utf8.c b/src/noja/utils/utf8.c similarity index 100% rename from src/libnoja/utils/utf8.c rename to src/noja/utils/utf8.c diff --git a/src/libnoja/utils/utf8.h b/src/noja/utils/utf8.h similarity index 100% rename from src/libnoja/utils/utf8.h rename to src/noja/utils/utf8.h