diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e2a2717 --- /dev/null +++ b/.gitignore @@ -0,0 +1,32 @@ +#Editor generated files +*.sln +*.vcproj +*.suo +*.ncb +*.user + +#Directories +Release/ +Debug/ +Out/ +Lib/ +release/ +debug/ +out/ +lib/ + +#Project generated files +*.db +*.o +*.a +*.exe +*.dll +*.meta +*.log +out +*.stackdump +*.tb + +#Shell files +*.bat +*.sh \ No newline at end of file diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..a6da6ec --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "Toy"] + path = Toy + url = https://github.com/Ratstail91/Toy diff --git a/Toy b/Toy new file mode 160000 index 0000000..c680427 --- /dev/null +++ b/Toy @@ -0,0 +1 @@ +Subproject commit c680427b1eabaeeb7ec10be2e9b1e3d48249b05d diff --git a/makefile b/makefile new file mode 100644 index 0000000..49a4ac5 --- /dev/null +++ b/makefile @@ -0,0 +1,44 @@ +export OUTDIR = out +export LIBDIR = lib +export TOY_OUTDIR = ../$(LIBDIR) + +all: $(OUTDIR) $(LIBDIR) toy + $(MAKE) -C source + cp $(LIBDIR)/*.dll $(OUTDIR) + +toy: $(LIBDIR) + $(MAKE) -C Toy/source + +$(OUTDIR): + mkdir $(OUTDIR) + +$(LIBDIR): + mkdir $(LIBDIR) + +.PHONY: clean + +clean: +ifeq ($(findstring CYGWIN, $(shell uname)),CYGWIN) + find . -type f -name '*.o' -exec rm -f -r -v {} \; + find . -type f -name '*.a' -exec rm -f -r -v {} \; + find . -type f -name '*.exe' -exec rm -f -r -v {} \; + find . -type f -name '*.dll' -exec rm -f -r -v {} \; + find . -type f -name '*.lib' -exec rm -f -r -v {} \; + find . -type f -name '*.so' -exec rm -f -r -v {} \; + find . -empty -type d -delete +else ifeq ($(shell uname),Linux) + find . -type f -name '*.o' -exec rm -f -r -v {} \; + find . -type f -name '*.a' -exec rm -f -r -v {} \; + find . -type f -name '*.exe' -exec rm -f -r -v {} \; + find . -type f -name '*.dll' -exec rm -f -r -v {} \; + find . -type f -name '*.lib' -exec rm -f -r -v {} \; + find . -type f -name '*.so' -exec rm -f -r -v {} \; + rm -rf out + find . -empty -type d -delete +else ifeq ($(OS),Windows_NT) + $(RM) *.o *.a *.exe +else + @echo "Deletion failed - what platform is this?" +endif + +rebuild: clean all diff --git a/source/main.c b/source/main.c new file mode 100644 index 0000000..917f684 --- /dev/null +++ b/source/main.c @@ -0,0 +1,79 @@ +//This "hello world" was borrowed from the net +//https://gist.github.com/fschr/92958222e35a823e738bb181fe045274 + +// SDL2 Hello, World! +// This should display a white screen for 2 seconds +// compile with: clang++ main.cpp -o hello_sdl2 -lSDL2 +// run with: ./hello_sdl2 +#include +#include + +#include "lexer.h" +#include "parser.h" +#include "compiler.h" +#include "interpreter.h" + +#define SCREEN_WIDTH 640 +#define SCREEN_HEIGHT 480 + +int main(int argc, char* args[]) { + SDL_Window* window = NULL; + SDL_Surface* screenSurface = NULL; + if (SDL_Init(SDL_INIT_VIDEO) < 0) { + fprintf(stderr, "could not initialize sdl2: %s\n", SDL_GetError()); + return 1; + } + window = SDL_CreateWindow( + "hello_sdl2", + SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, + SCREEN_WIDTH, SCREEN_HEIGHT, + SDL_WINDOW_SHOWN + ); + if (window == NULL) { + fprintf(stderr, "could not create window: %s\n", SDL_GetError()); + return 1; + } + screenSurface = SDL_GetWindowSurface(window); + SDL_FillRect(screenSurface, NULL, SDL_MapRGB(screenSurface->format, 0xFF, 0xFF, 0xFF)); + SDL_UpdateWindowSurface(window); + + //hacked in to test linking + { + //source + char* source = "print \"Hello world!\";"; + + //test basic compilation & collation + Lexer lexer; + Parser parser; + Compiler compiler; + Interpreter interpreter; + + initLexer(&lexer, source); + initParser(&parser, &lexer); + initCompiler(&compiler); + initInterpreter(&interpreter); + + Node* node = scanParser(&parser); + + //write + writeCompiler(&compiler, node); + + //collate + int size = 0; + unsigned char* bytecode = collateCompiler(&compiler, &size); + + //run + runInterpreter(&interpreter, bytecode, size); + + //cleanup + freeNode(node); + freeParser(&parser); + freeCompiler(&compiler); + freeInterpreter(&interpreter); + } + + SDL_Delay(2000); + SDL_DestroyWindow(window); + SDL_Quit(); + return 0; +} \ No newline at end of file diff --git a/source/makefile b/source/makefile new file mode 100644 index 0000000..c3746ac --- /dev/null +++ b/source/makefile @@ -0,0 +1,27 @@ +CC=gcc + +IDIR+=. ../Toy/source +CFLAGS+=$(addprefix -I,$(IDIR)) -DSDL_MAIN_HANDLED -g -Wall -W -pedantic -Wno-unused-parameter -Wno-unused-function -Wno-unused-variable +LIBS+=-lSDL2 -ltoy + +ODIR = obj +SRC = $(wildcard *.c) +OBJ = $(addprefix $(ODIR)/,$(SRC:.c=.o)) + +OUT=../$(OUTDIR)/airport + +all: $(OBJ) + $(CC) $(CFLAGS) -o $(OUT) $(OBJ) -L../$(LIBDIR) $(LIBS) + +$(OBJ): | $(ODIR) + +$(ODIR): + mkdir $(ODIR) + +$(ODIR)/%.o: %.c + $(CC) -c -o $@ $< $(CFLAGS) + +.PHONY: clean + +clean: + $(RM) $(ODIR)