diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..0b76fe5 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/.idea/tyche.iml b/.idea/tyche.iml index bc2cd87..f08604b 100644 --- a/.idea/tyche.iml +++ b/.idea/tyche.iml @@ -1,8 +1,2 @@ - - - - - - - \ No newline at end of file + \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..2fac843 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,92 @@ +cmake_minimum_required (VERSION 3.24) + +project(tyche + VERSION 0.0.1 + DESCRIPTION "An embeddable/standalone programming language" + LANGUAGES C CXX ASM) + +# +# project options / configuration +# + +set(CMAKE_C_STANDARD 17) +set(CMAKE_CXX_STANDARD 23 CACHE STRING "C++ Standard") +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set_property(GLOBAL PROPERTY CXX_EXTENSIONS OFF) +set_property(GLOBAL PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE) +set_property(GLOBAL PROPERTY LINK_WHAT_YOU_USE TRUE) + +# warnings / flags +if(CMAKE_BUILD_TYPE STREQUAL "Debug") + set(warnings -Wall -Wextra -Wformat-nonliteral -Wundef -Wshadow -Wwrite-strings -Wfloat-equal -Wswitch-default -Wmissing-format-attribute -Wswitch-enum -Wmissing-noreturn -Wno-unused-parameter -Wno-unused) + if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + set(warnings ${warnings} -Wsuggest-attribute=pure -Wsuggest-attribute=const -Wsuggest-attribute=noreturn -Wsuggest-attribute=malloc -Wsuggest-attribute=format -Wsuggest-attribute=cold) + endif() +endif() + +# try to use ccache, if available +find_program(CCACHE_PROGRAM ccache) +if(CCACHE_PROGRAM) + set(CMAKE_CXX_COMPILER_LAUNCHER "${CCACHE_PROGRAM}") +endif() + +# ignore warnings in imported files +set_source_files_properties(${IMGUI_SRC} PROPERTIES COMPILE_FLAGS "-w") + +if(CMAKE_BUILD_TYPE STREQUAL "Debug") + add_compile_options(-ggdb -O0) +endif() + +if(CMAKE_BUILD_TYPE STREQUAL "Release") + set(DEF B_PRODUCTION_MODE=ON) + add_compile_options(-Ofast -flto) +endif() + +# +# libraries +# + +include(FetchContent) +FetchContent_Declare( + googletest + # Specify the commit you depend on and update it regularly. + URL https://github.com/google/googletest/releases/download/v1.17.0/googletest-1.17.0.tar.gz +) +FetchContent_MakeAvailable(googletest) + +# +# library +# + +add_library(lib${PROJECT_NAME} STATIC + src/bytecode/bytearray.hh + src/bytecode/bytearray.cc +) + +target_compile_options(lib${PROJECT_NAME} PRIVATE ${warnings}) + +# +# tests +# + +add_executable(${PROJECT_NAME}-bytecode-test src/bytecode/tests.cc) +target_link_libraries(${PROJECT_NAME}-bytecode-test lib${PROJECT_NAME} gtest_main) +add_test(NAME tyche_bytecode_test COMMAND ${PROJECT_NAME}-bytecode-test) + +# +# check for leaks +# + +add_custom_target(leaks) +add_custom_command(TARGET leaks + POST_BUILD + COMMENT "Check for leaks using valgrind." + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + COMMAND valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes --suppressions=${CMAKE_SOURCE_DIR}/valgrind.supp ./${PROJECT_NAME} +) + +# +# installation +# + +install(TARGETS lib${CMAKE_PROJECT_NAME} RUNTIME DESTINATION lib) \ No newline at end of file diff --git a/TODO.md b/TODO.md index 3581679..16ab05f 100644 --- a/TODO.md +++ b/TODO.md @@ -1,4 +1,4 @@ -## Chunk +## Bytecode - [ ] Byte array - Auto-expand diff --git a/doc/OPCODES b/doc/OPCODES index 76b3f1e..6476112 100644 --- a/doc/OPCODES +++ b/doc/OPCODES @@ -67,15 +67,15 @@ Other value operations: (0x80~0x8f) External code: (0x90~0x9f) cmpl Compile code to assembly - asmbl Assemble code to chunk format - load Load chunk as function (will place function on stack) + asmbl Assemble code to bytecode format + load Load bytecode as function (will place function on stack) Error handling: (0xa0~0xaf) ??? -Chunk format ------------- +Bytecode format +--------------- The bytecode file is composed of the following sections: diff --git a/src/bytecode/bytearray.cc b/src/bytecode/bytearray.cc new file mode 100644 index 0000000..c29cc85 --- /dev/null +++ b/src/bytecode/bytearray.cc @@ -0,0 +1 @@ +#include "bytearray.hh" diff --git a/src/bytecode/bytearray.hh b/src/bytecode/bytearray.hh new file mode 100644 index 0000000..a9e0778 --- /dev/null +++ b/src/bytecode/bytearray.hh @@ -0,0 +1,8 @@ +#ifndef TYCHE_BYTEARRAY_HH +#define TYCHE_BYTEARRAY_HH + +class ByteArray { + +}; + +#endif //TYCHE_BYTEARRAY_HH diff --git a/src/bytecode/tests.cc b/src/bytecode/tests.cc new file mode 100644 index 0000000..8bb1668 --- /dev/null +++ b/src/bytecode/tests.cc @@ -0,0 +1,12 @@ +#include "gtest/gtest.h" + +TEST(test, test) +{ + ASSERT_EQ(1, 1); +} + +int main(int argc, char** argv) +{ + testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} \ No newline at end of file