Hello world is working
This commit is contained in:
32
.gitignore
vendored
Normal file
32
.gitignore
vendored
Normal file
@@ -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
|
||||||
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
[submodule "Toy"]
|
||||||
|
path = Toy
|
||||||
|
url = https://github.com/Ratstail91/Toy
|
||||||
1
Toy
Submodule
1
Toy
Submodule
Submodule Toy added at c680427b1e
44
makefile
Normal file
44
makefile
Normal file
@@ -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
|
||||||
79
source/main.c
Normal file
79
source/main.c
Normal file
@@ -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 <SDL2/SDL.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#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;
|
||||||
|
}
|
||||||
27
source/makefile
Normal file
27
source/makefile
Normal file
@@ -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)
|
||||||
Reference in New Issue
Block a user