This repository has been archived by the owner on Nov 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improved makefile and added some tests
- Loading branch information
1 parent
1e80e4c
commit 53c9790
Showing
11 changed files
with
130 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,5 +12,7 @@ Peregrine/test | |
*.so | ||
*.o | ||
temp | ||
__pycache__ | ||
/Peregrine/peregrine | ||
/objs | ||
*.elf | ||
doctest.h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
CC := g++ | ||
CFLAGS := -Wall | ||
|
||
OUTPUT := peregrine.elf | ||
|
||
SRC := $(shell find -name '*.cpp' ! -path './tests/*') | ||
OBJS := $(subst .cpp,.o,$(subst Peregrine,objs,$(SRC))) | ||
|
||
.PHONY: clean all dirs | ||
|
||
all: $(OUTPUT) | ||
./$(OUTPUT) | ||
|
||
$(OUTPUT): $(OBJS) | ||
$(CC) -o $(OUTPUT) $(OBJS) | ||
|
||
objs/%.o: Peregrine/%.cpp | dirs | ||
$(CC) -c $< -o $@ | ||
|
||
dirs: | ||
mkdir -p $(shell dirname $(OBJS)) | ||
|
||
clean: | ||
rm -rf ./objs | ||
rm -f $(OUTPUT) |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#include <iostream> | ||
#include <vector> | ||
#include "lexer/lexer.hpp" | ||
#include "lexer/tokens.hpp" | ||
|
||
int main() { | ||
std::vector<Token> res = lexer("\"Hello, world!\"", ""); | ||
|
||
for (auto& tok : res) { | ||
std::cout << "Statement: " << tok.statement << " | Keyword: " << tok.keyword << " | Type: " << tok.tk_type << "\n"; | ||
} | ||
|
||
return 0; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
CC := g++ | ||
|
||
TEST_OUTPUT := compiler_test.elf | ||
|
||
DOCTEST := compiler/doctest.h | ||
|
||
TEST_SRC := $(shell find -name '*.cpp') | ||
TEST_OBJS := $(subst .cpp,.o,$(TEST_SRC)) | ||
|
||
OBJS := $(shell find .. -path '../objs/*.o' ! -name 'main.o') | ||
|
||
.PHONY: clean all | ||
|
||
all: $(TEST_OUTPUT) | ||
./$(TEST_OUTPUT) | ||
|
||
$(TEST_OUTPUT): $(DOCTEST) $(TEST_OBJS) $(OBJS) | ||
$(CC) -o $(TEST_OUTPUT) $(TEST_OBJS) $(OBJS) | ||
|
||
$(DOCTEST): | ||
wget https://raw.githubusercontent.com/onqtam/doctest/master/doctest/doctest.h | ||
mv doctest.h compiler/doctest.h | ||
|
||
%.o: %.cpp | ||
$(CC) -I ../Peregrine -c $< -o $@ | ||
|
||
clean: | ||
rm -f *.o | ||
rm -f $(TEST_OUTPUT) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#include "doctest.h" | ||
|
||
#include <vector> | ||
#include <lexer/lexer.hpp> | ||
#include <lexer/tokens.hpp> | ||
|
||
TEST_CASE("Tokenize basic primitives") { | ||
std::vector<Token> res; | ||
|
||
res = lexer("69420", ""); | ||
CHECK(res[0].tk_type == tk_integer); | ||
CHECK(res[0].keyword == "69420"); | ||
|
||
res = lexer("5.32006", ""); | ||
CHECK(res[0].tk_type == tk_decimal); | ||
CHECK(res[0].keyword == "5.32006"); | ||
|
||
res = lexer("\"A blazing fast language\"", ""); | ||
CHECK(res[0].tk_type == tk_string); | ||
CHECK(res[0].keyword == std::string("A blazing fast language")); | ||
|
||
res = lexer("True", ""); | ||
CHECK(res[0].tk_type == tk_true); | ||
} | ||
|
||
TEST_CASE("Tokenize variable declarations") { | ||
std::vector<Token> res = lexer("int test = 23", ""); | ||
|
||
REQUIRE(res.size() == 5); | ||
|
||
CHECK(res[0].tk_type == tk_identifier); | ||
CHECK(res[1].tk_type == tk_identifier); | ||
CHECK(res[2].tk_type == tk_assign); | ||
CHECK(res[3].tk_type == tk_integer); | ||
CHECK(res[4].tk_type == tk_eof); | ||
} | ||
|
||
TEST_CASE("Tokenize if-else statements") { | ||
std::vector<Token> res = lexer("if test:\n print(\"true!\")\nelse:\n print(\"false!\")", ""); | ||
|
||
REQUIRE(res.size() == 18); | ||
|
||
SUBCASE("Emit ident and dedent tokens") { | ||
CHECK(res[3].tk_type == tk_ident); | ||
CHECK(res[8].tk_type == tk_dedent); | ||
CHECK(res[11].tk_type == tk_ident); | ||
CHECK(res[16].tk_type == tk_dedent); | ||
} | ||
|
||
SUBCASE("Emit if and else tokens") { | ||
CHECK(res[0].tk_type == tk_if); | ||
CHECK(res[2].tk_type == tk_colon); | ||
|
||
CHECK(res[9].tk_type == tk_else); | ||
CHECK(res[10].tk_type == tk_colon); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN | ||
#include "doctest.h" |