From 4e2dd8e30ba928a63d6e7b384021d940677cf403 Mon Sep 17 00:00:00 2001 From: Michael Fabian 'Xaymar' Dirks Date: Thu, 6 Jun 2024 13:37:13 +0200 Subject: [PATCH] Update to modern standard i guess --- .gitignore | 10 + .gitmodules | 6 + CMakeLists.txt | 177 +++++++++++++++++- LICENSE | 165 ---------------- LICENSE.adoc | 9 + README.adoc | 2 + cmake/cmake-clang | 1 + cmake/cmake-version | 1 + .../CMakeLists.txt | 22 ++- code_compiler/source/ast/arithmetic.cpp | 22 +++ code_compiler/source/ast/arithmetic.hpp | 43 +++++ .../source/ast/ast.cpp | 17 +- .../source/ast/ast.hpp | 18 +- code_compiler/source/ast/binary.cpp | 0 code_compiler/source/ast/binary.hpp | 0 code_compiler/source/ast/function.cpp | 42 +++++ code_compiler/source/ast/function.hpp | 63 +++++++ code_compiler/source/ast/value.cpp | 59 ++++++ code_compiler/source/ast/value.hpp | 98 ++++++++++ code_compiler/source/compiler.cpp | 41 ++++ .../source/compiler.hpp | 2 +- .../source/lexer.cpp | 45 ++++- .../source/lexer.hpp | 26 ++- .../source/main.cpp | 5 +- code_compiler/source/parser.cpp | 125 +++++++++++++ code_compiler/source/parser.hpp | 52 +++++ .../templates/version.h | 0 projects/code_compiler/CMakeVersion.txt | 7 - projects/code_compiler/source/compiler.cpp | 148 --------------- 29 files changed, 828 insertions(+), 378 deletions(-) create mode 100644 .gitmodules delete mode 100644 LICENSE create mode 100644 LICENSE.adoc create mode 100644 README.adoc create mode 160000 cmake/cmake-clang create mode 160000 cmake/cmake-version rename {projects/code_compiler => code_compiler}/CMakeLists.txt (55%) create mode 100644 code_compiler/source/ast/arithmetic.cpp create mode 100644 code_compiler/source/ast/arithmetic.hpp rename projects/code_compiler/source/parser.hpp => code_compiler/source/ast/ast.cpp (80%) rename projects/code_compiler/source/parser.cpp => code_compiler/source/ast/ast.hpp (85%) create mode 100644 code_compiler/source/ast/binary.cpp create mode 100644 code_compiler/source/ast/binary.hpp create mode 100644 code_compiler/source/ast/function.cpp create mode 100644 code_compiler/source/ast/function.hpp create mode 100644 code_compiler/source/ast/value.cpp create mode 100644 code_compiler/source/ast/value.hpp create mode 100644 code_compiler/source/compiler.cpp rename {projects/code_compiler => code_compiler}/source/compiler.hpp (99%) rename {projects/code_compiler => code_compiler}/source/lexer.cpp (87%) rename {projects/code_compiler => code_compiler}/source/lexer.hpp (89%) rename {projects/code_compiler => code_compiler}/source/main.cpp (96%) create mode 100644 code_compiler/source/parser.cpp create mode 100644 code_compiler/source/parser.hpp rename {projects/code_compiler => code_compiler}/templates/version.h (100%) delete mode 100644 projects/code_compiler/CMakeVersion.txt delete mode 100644 projects/code_compiler/source/compiler.cpp diff --git a/.gitignore b/.gitignore index 04c0500..ab5cf1c 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,13 @@ /build /build32 /build64 +/tests/*.zip +/tests/*.jpg +/tests/*.jpeg +/tests/*.png +/tests/*.bmp +/tests/*.tga +/tests/*.exe +/tests/*.dll +/tests/*.bin +/tests/*.dat diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..3050801 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,6 @@ +[submodule "cmake/cmake-version"] + path = cmake/cmake-version + url = https://github.com/Xaymar/cmake-version.git +[submodule "cmake/cmake-clang"] + path = cmake/cmake-clang + url = https://github.com/Xaymar/cmake-clang.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 35ebfe0..6dcf8db 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,177 @@ -cmake_minimum_required(VERSION 2.8.12) +################################################################################ +# CMake Setup +################################################################################ +cmake_minimum_required(VERSION 3.26...) project(BlitzLLVM) +list(APPEND CMAKE_MESSAGE_INDENT "[${PROJECT_NAME}] ") -ADD_SUBDIRECTORY("projects/code_compiler") \ No newline at end of file +# Module Search Paths +list(APPEND CMAKE_MODULE_PATH + "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules" + "${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake-clang" + "${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake-version" + "${CMAKE_CURRENT_SOURCE_DIR}/cmake" +) + +# Include default modules +#- Interprocedural optimizations +include("CheckIPOSupported") + +#- CMake-based Versioning +include("version") + +#- CMake-based Clang integration +include("clang") + + +SET_PROPERTY( GLOBAL PROPERTY USE_FOLDERS ON) + +################################################################################ +# Versioning +################################################################################ + +version(GENERATE _VERSION COMPRESSED MAJOR 0 MINOR 0 PATCH 0 TWEAK 0 REQUIRE "PATCH;") +version(PARSE _VERSION "${_VERSION}" REQUIRE "PATCH;TWEAK") + +# If possible, automatically generate versions from git. +if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/.git") + find_program(GIT + NAMES + git + git.exe + ) + + if(EXISTS "${GIT}") + # Try and calculate the exist version using git. + execute_process(COMMAND "${GIT}" describe --tags --long --abbrev=8 HEAD WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} RESULT_VARIABLE GIT_RESULT OUTPUT_VARIABLE GIT_OUTPUT ERROR_VARIABLE GIT_ERROR OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_STRIP_TRAILING_WHITESPACE ERROR_QUIET) + if((GIT_RESULT EQUAL 0) AND (NOT "${GIT_OUTPUT}" STREQUAL "")) + # Result will be MAJOR.MINOR.PATCH-TWEAK-gHASH + string(REPLACE "-" ";" GIT_OUTPUT "${GIT_OUTPUT}") + string(REPLACE "." ";" GIT_OUTPUT "${GIT_OUTPUT}") + + # Split into components + list(GET GIT_OUTPUT 0 GIT_OUTPUT_MAJOR) + list(GET GIT_OUTPUT 1 GIT_OUTPUT_MINOR) + list(GET GIT_OUTPUT 2 GIT_OUTPUT_PATCH) + list(GET GIT_OUTPUT 3 GIT_OUTPUT_TWEAK) + list(GET GIT_OUTPUT 4 GIT_OUTPUT_BUILD) + + # Special case: Tag contains prerelease + if(GIT_OUTPUT_PATCH MATCHES "([0-9]+)([a-zA-Z]+)([0-9]*)") + # Patch requires special parsing. + set(GIT_OUTPUT_PATCH "${CMAKE_MATCH_1}") + if(CMAKE_MATCH_3 GREATER 0) + set(GIT_OUTPUT_PRERELEASE "${CMAKE_MATCH_2}") + else() + set(GIT_OUTPUT_PRERELEASE "a") + endif() + MATH(EXPR GIT_OUTPUT_TWEAK "${GIT_OUTPUT_TWEAK} + ${CMAKE_MATCH_3}") + + # Modify the global version + version(MODIFY _VERSION "${_VERSION}" COMPRESS + MAJOR "${GIT_OUTPUT_MAJOR}" + MINOR "${GIT_OUTPUT_MINOR}" + PATCH "${GIT_OUTPUT_PATCH}" + TWEAK "${GIT_OUTPUT_TWEAK}" + BUILD "${GIT_OUTPUT_BUILD}" + PRERELEASE "${GIT_OUTPUT_PRERELEASE}" + REQUIRE "PATCH;TWEAK" + ) + else() + # Modify the global version + version(MODIFY _VERSION "${_VERSION}" COMPRESS + MAJOR "${GIT_OUTPUT_MAJOR}" + MINOR "${GIT_OUTPUT_MINOR}" + PATCH "${GIT_OUTPUT_PATCH}" + TWEAK "${GIT_OUTPUT_TWEAK}" + BUILD "${GIT_OUTPUT_BUILD}" + PRERELEASE "a" + REQUIRE "PATCH;TWEAK" + ) + endif() + else() + execute_process(COMMAND "${GIT}" rev-list --count HEAD WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} RESULT_VARIABLE GIT_RESULT OUTPUT_VARIABLE GIT_OUTPUT ERROR_VARIABLE GIT_ERROR OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_STRIP_TRAILING_WHITESPACE ERROR_QUIET) + if((GIT_RESULT EQUAL 0) AND (NOT "${GIT_OUTPUT}" STREQUAL "")) + version(MODIFY _VERSION "${_VERSION}" COMPRESS + TWEAK "${GIT_OUTPUT}" + PRERELEASE "a" + REQUIRE "PATCH;TWEAK" + ) + + # Determine the build using git. + execute_process(COMMAND "${GIT}" log -1 "--pretty=format:g%h" --abbrev=8 HEAD WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} RESULT_VARIABLE GIT_RESULT OUTPUT_VARIABLE GIT_OUTPUT ERROR_VARIABLE GIT_ERROR OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_STRIP_TRAILING_WHITESPACE ERROR_QUIET) + if((GIT_RESULT EQUAL 0) AND (NOT "${GIT_OUTPUT}" STREQUAL "")) + version(MODIFY _VERSION "${_VERSION}" COMPRESS + BUILD "${GIT_OUTPUT}" + REQUIRE "PATCH;TWEAK" + ) + else() + message(WARNING "Failed to detect build version with 'git'.") + endif() + else() + message(WARNING "Failed to automatically detect version with 'git'.") + endif() + endif() + else() + message(WARNING "'git' not found, automatic version detection disabled.") + endif() +else() + message(STATUS "Not a git repository, automatic version detection disabled.") +endif() + +# Allow manual overrides of the detected version. +if(${PREFIX}VERSION) + version(PARSE _VERSION_CFG "${${PREFIX}VERSION}" REQUIRE "PATCH;TWEAK") + if("${_VERSION_CFG_BUILD}" STREQUAL "") + set(_VERSION_CFG_BUILD "${_VERSION_BUILD}") + endif() + version(GENERATE _VERSION COMPRESS + MAJOR "${_VERSION_CFG_MAJOR}" + MINOR "${_VERSION_CFG_MINOR}" + PATCH "${_VERSION_CFG_PATCH}" + TWEAK "${_VERSION_CFG_TWEAK}" + PRERELEASE "${_VERSION_CFG_PRERELEASE}" + BUILD "${_VERSION_CFG_BUILD}" + ) +endif() + +# Fix up missing parts of the Version +version(PARSE _VERSION "${_VERSION}" REQUIRE "PATCH;TWEAK") + +set(_VERSION_THIN "${_VERSION_MAJOR}.${_VERSION_MINOR}.${_VERSION_PATCH}") +if(NOT (_VERSION_PRERELEASE STREQUAL "")) + set(_VERSION_THIN "${_VERSION_THIN}${_VERSION_PRERELEASE}${_VERSION_TWEAK}") +endif() +if(NOT (VERSION_COMMIT STREQUAL "")) + set(_VERSION_THIN "${_VERSION_THIN}-${_VERSION_BUILD}") +endif() + +# Parse & Log the detected version. +message(STATUS "Version ${_VERSION_THIN}") + +################################################################################ +# Project +################################################################################ + +# Metadata +version(GENERATE PROJECT_VERSION + MAJOR "${_VERSION_MAJOR}" + MINOR "${_VERSION_MINOR}" + PATCH "${_VERSION_PATCH}" + TWEAK "${_VERSION_TWEAK}" + REQUIRE "PATCH;TWEAK" +) +project( + ${PROJECT_NAME} + VERSION ${PROJECT_VERSION} +) +set(PROJECT_IDENTIFER "com.xaymar.BlitzLLVM") +set(PROJECT_TITLE "BlitzLLVM") +set(PROJECT_AUTHORS "See AUTHORS file") +set(PROJECT_COPYRIGHT "All Rights Reserved. See LICENSE file for more information") +set(PROJECT_TRADEMARKS "") + +################################################################################ +# Sub-projects +################################################################################ +ADD_SUBDIRECTORY("code_compiler") diff --git a/LICENSE b/LICENSE deleted file mode 100644 index 65c5ca8..0000000 --- a/LICENSE +++ /dev/null @@ -1,165 +0,0 @@ - GNU LESSER GENERAL PUBLIC LICENSE - Version 3, 29 June 2007 - - Copyright (C) 2007 Free Software Foundation, Inc. - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - - This version of the GNU Lesser General Public License incorporates -the terms and conditions of version 3 of the GNU General Public -License, supplemented by the additional permissions listed below. - - 0. Additional Definitions. - - As used herein, "this License" refers to version 3 of the GNU Lesser -General Public License, and the "GNU GPL" refers to version 3 of the GNU -General Public License. - - "The Library" refers to a covered work governed by this License, -other than an Application or a Combined Work as defined below. - - An "Application" is any work that makes use of an interface provided -by the Library, but which is not otherwise based on the Library. -Defining a subclass of a class defined by the Library is deemed a mode -of using an interface provided by the Library. - - A "Combined Work" is a work produced by combining or linking an -Application with the Library. The particular version of the Library -with which the Combined Work was made is also called the "Linked -Version". - - The "Minimal Corresponding Source" for a Combined Work means the -Corresponding Source for the Combined Work, excluding any source code -for portions of the Combined Work that, considered in isolation, are -based on the Application, and not on the Linked Version. - - The "Corresponding Application Code" for a Combined Work means the -object code and/or source code for the Application, including any data -and utility programs needed for reproducing the Combined Work from the -Application, but excluding the System Libraries of the Combined Work. - - 1. Exception to Section 3 of the GNU GPL. - - You may convey a covered work under sections 3 and 4 of this License -without being bound by section 3 of the GNU GPL. - - 2. Conveying Modified Versions. - - If you modify a copy of the Library, and, in your modifications, a -facility refers to a function or data to be supplied by an Application -that uses the facility (other than as an argument passed when the -facility is invoked), then you may convey a copy of the modified -version: - - a) under this License, provided that you make a good faith effort to - ensure that, in the event an Application does not supply the - function or data, the facility still operates, and performs - whatever part of its purpose remains meaningful, or - - b) under the GNU GPL, with none of the additional permissions of - this License applicable to that copy. - - 3. Object Code Incorporating Material from Library Header Files. - - The object code form of an Application may incorporate material from -a header file that is part of the Library. You may convey such object -code under terms of your choice, provided that, if the incorporated -material is not limited to numerical parameters, data structure -layouts and accessors, or small macros, inline functions and templates -(ten or fewer lines in length), you do both of the following: - - a) Give prominent notice with each copy of the object code that the - Library is used in it and that the Library and its use are - covered by this License. - - b) Accompany the object code with a copy of the GNU GPL and this license - document. - - 4. Combined Works. - - You may convey a Combined Work under terms of your choice that, -taken together, effectively do not restrict modification of the -portions of the Library contained in the Combined Work and reverse -engineering for debugging such modifications, if you also do each of -the following: - - a) Give prominent notice with each copy of the Combined Work that - the Library is used in it and that the Library and its use are - covered by this License. - - b) Accompany the Combined Work with a copy of the GNU GPL and this license - document. - - c) For a Combined Work that displays copyright notices during - execution, include the copyright notice for the Library among - these notices, as well as a reference directing the user to the - copies of the GNU GPL and this license document. - - d) Do one of the following: - - 0) Convey the Minimal Corresponding Source under the terms of this - License, and the Corresponding Application Code in a form - suitable for, and under terms that permit, the user to - recombine or relink the Application with a modified version of - the Linked Version to produce a modified Combined Work, in the - manner specified by section 6 of the GNU GPL for conveying - Corresponding Source. - - 1) Use a suitable shared library mechanism for linking with the - Library. A suitable mechanism is one that (a) uses at run time - a copy of the Library already present on the user's computer - system, and (b) will operate properly with a modified version - of the Library that is interface-compatible with the Linked - Version. - - e) Provide Installation Information, but only if you would otherwise - be required to provide such information under section 6 of the - GNU GPL, and only to the extent that such information is - necessary to install and execute a modified version of the - Combined Work produced by recombining or relinking the - Application with a modified version of the Linked Version. (If - you use option 4d0, the Installation Information must accompany - the Minimal Corresponding Source and Corresponding Application - Code. If you use option 4d1, you must provide the Installation - Information in the manner specified by section 6 of the GNU GPL - for conveying Corresponding Source.) - - 5. Combined Libraries. - - You may place library facilities that are a work based on the -Library side by side in a single library together with other library -facilities that are not Applications and are not covered by this -License, and convey such a combined library under terms of your -choice, if you do both of the following: - - a) Accompany the combined library with a copy of the same work based - on the Library, uncombined with any other library facilities, - conveyed under the terms of this License. - - b) Give prominent notice with the combined library that part of it - is a work based on the Library, and explaining where to find the - accompanying uncombined form of the same work. - - 6. Revised Versions of the GNU Lesser General Public License. - - The Free Software Foundation may publish revised and/or new versions -of the GNU Lesser General Public License from time to time. Such new -versions will be similar in spirit to the present version, but may -differ in detail to address new problems or concerns. - - Each version is given a distinguishing version number. If the -Library as you received it specifies that a certain numbered version -of the GNU Lesser General Public License "or any later version" -applies to it, you have the option of following the terms and -conditions either of that published version or of any later version -published by the Free Software Foundation. If the Library as you -received it does not specify a version number of the GNU Lesser -General Public License, you may choose any version of the GNU Lesser -General Public License ever published by the Free Software Foundation. - - If the Library as you received it specifies that a proxy can decide -whether future versions of the GNU Lesser General Public License shall -apply, that proxy's public statement of acceptance of any version is -permanent authorization for you to choose that version for the -Library. diff --git a/LICENSE.adoc b/LICENSE.adoc new file mode 100644 index 0000000..1b8bcb6 --- /dev/null +++ b/LICENSE.adoc @@ -0,0 +1,9 @@ +Copyright 2014-2024 Michael Fabian 'Xaymar' Dirks + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. +2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. +3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file diff --git a/README.adoc b/README.adoc new file mode 100644 index 0000000..ce66455 --- /dev/null +++ b/README.adoc @@ -0,0 +1,2 @@ +== What is BlitzLLVM? +BlitzLLVM is an attempt at a functional transpiler for BlitzBasic (Blitz2D, Blitz3D, and BlitzPlus). diff --git a/cmake/cmake-clang b/cmake/cmake-clang new file mode 160000 index 0000000..654f2bc --- /dev/null +++ b/cmake/cmake-clang @@ -0,0 +1 @@ +Subproject commit 654f2bcc201e784ed0006d5d496ea012d40136cf diff --git a/cmake/cmake-version b/cmake/cmake-version new file mode 160000 index 0000000..3bef96b --- /dev/null +++ b/cmake/cmake-version @@ -0,0 +1 @@ +Subproject commit 3bef96bafab04161991c2cd98a1ed51f6362d670 diff --git a/projects/code_compiler/CMakeLists.txt b/code_compiler/CMakeLists.txt similarity index 55% rename from projects/code_compiler/CMakeLists.txt rename to code_compiler/CMakeLists.txt index 60f8dbb..7072c0b 100644 --- a/projects/code_compiler/CMakeLists.txt +++ b/code_compiler/CMakeLists.txt @@ -1,16 +1,17 @@ -cmake_minimum_required(VERSION 2.8.12) +cmake_minimum_required(VERSION 3.0.2) project(CodeCompiler) # Configuration ## Dependencies # LLVM -find_package(LLVM REQUIRED CONFIG) -llvm_map_components_to_libnames(llvm_libs support core irreader) +#find_package(LLVM REQUIRED CONFIG) +#llvm_map_components_to_libnames(llvm_libs support core irreader) # Boost -SET(Boost_USE_STATIC_LIBS ON) -find_package(Boost REQUIRED COMPONENTS program_options) +#SET(BOOST_ROOT "" CACHE PATH "Path to Boost") +#SET(Boost_USE_STATIC_LIBS ON) +#find_package(Boost REQUIRED COMPONENTS program_options) ## Version INCLUDE("CMakeVersion.txt") @@ -21,6 +22,14 @@ SET(SOURCE "source/main.cpp" "source/lexer.hpp" "source/lexer.cpp" + "source/ast/ast.hpp" + "source/ast/ast.cpp" + "source/ast/arithmetic.hpp" + "source/ast/arithmetic.cpp" + "source/ast/function.hpp" + "source/ast/function.cpp" + "source/ast/value.hpp" + "source/ast/value.cpp" "source/parser.hpp" "source/parser.cpp" "source/compiler.hpp" @@ -30,6 +39,9 @@ SET(DATA "CMakeVersion.txt" ) +# Source Grouping +SOURCE_GROUP(TREE ${PROJECT_SOURCE_DIR}/source PREFIX Source FILES ${SOURCE}) + # Definitions ADD_DEFINITIONS( ${LLVM_DEFINITIONS} diff --git a/code_compiler/source/ast/arithmetic.cpp b/code_compiler/source/ast/arithmetic.cpp new file mode 100644 index 0000000..c34b9ce --- /dev/null +++ b/code_compiler/source/ast/arithmetic.cpp @@ -0,0 +1,22 @@ +// Code Compiler for BlitzLLVM +// Copyright(C) 2017 Michael Fabian Dirks +// +// This program is free software : you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program.If not, see . + +#include "arithmetic.hpp" + +BlitzLLVM::AST::ArithmeticExpression::ArithmeticExpression(Operator op, std::unique_ptr left, std::unique_ptr right) + : m_operator(op), m_left(std::move(left)), m_right(std::move(right)) {} + +BlitzLLVM::AST::ArithmeticExpression::~ArithmeticExpression() {} diff --git a/code_compiler/source/ast/arithmetic.hpp b/code_compiler/source/ast/arithmetic.hpp new file mode 100644 index 0000000..a7795ba --- /dev/null +++ b/code_compiler/source/ast/arithmetic.hpp @@ -0,0 +1,43 @@ +// Code Compiler for BlitzLLVM +// Copyright(C) 2017 Michael Fabian Dirks +// +// This program is free software : you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program.If not, see . + +#pragma once +#include "ast.hpp" +#include "value.hpp" + +namespace BlitzLLVM { + namespace AST { + enum class Operator : int8_t { + Add, /*+*/ + Subtract, /*-*/ + Multiply, /***/ + Divide, /*/*/ + Invert, /*~*/ + Power, /*^*/ + Equal, /*=*/ + }; + + class ArithmeticExpression : public Expression { + public: + ArithmeticExpression(Operator op, std::unique_ptr left, std::unique_ptr right); + virtual ~ArithmeticExpression(); + + private: + Operator m_operator; + std::unique_ptr m_left, m_right; + }; + } +} \ No newline at end of file diff --git a/projects/code_compiler/source/parser.hpp b/code_compiler/source/ast/ast.cpp similarity index 80% rename from projects/code_compiler/source/parser.hpp rename to code_compiler/source/ast/ast.cpp index 050f63d..69a0ca4 100644 --- a/projects/code_compiler/source/parser.hpp +++ b/code_compiler/source/ast/ast.cpp @@ -14,19 +14,4 @@ // You should have received a copy of the GNU General Public License // along with this program.If not, see . -#pragma once -#include "lexer.hpp" -#include - -namespace BlitzLLVM { - class Parser { - public: - Parser(std::istream& in); - ~Parser(); - - - - private: - Lexer m_lexer; - }; -} \ No newline at end of file +#include "ast.hpp" \ No newline at end of file diff --git a/projects/code_compiler/source/parser.cpp b/code_compiler/source/ast/ast.hpp similarity index 85% rename from projects/code_compiler/source/parser.cpp rename to code_compiler/source/ast/ast.hpp index dec16db..bb7bc2e 100644 --- a/projects/code_compiler/source/parser.cpp +++ b/code_compiler/source/ast/ast.hpp @@ -14,13 +14,13 @@ // You should have received a copy of the GNU General Public License // along with this program.If not, see . -#include "parser.hpp" - -BlitzLLVM::Parser::Parser(std::istream& in) : m_lexer(in) { - -} - -BlitzLLVM::Parser::~Parser() { - -} +#pragma once +namespace BlitzLLVM { + namespace AST { + class Expression { + public: + virtual ~Expression() {}; + }; + } +} \ No newline at end of file diff --git a/code_compiler/source/ast/binary.cpp b/code_compiler/source/ast/binary.cpp new file mode 100644 index 0000000..e69de29 diff --git a/code_compiler/source/ast/binary.hpp b/code_compiler/source/ast/binary.hpp new file mode 100644 index 0000000..e69de29 diff --git a/code_compiler/source/ast/function.cpp b/code_compiler/source/ast/function.cpp new file mode 100644 index 0000000..339135d --- /dev/null +++ b/code_compiler/source/ast/function.cpp @@ -0,0 +1,42 @@ +// Code Compiler for BlitzLLVM +// Copyright(C) 2017 Michael Fabian Dirks +// +// This program is free software : you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program.If not, see . + +#include "function.hpp" + +BlitzLLVM::AST::ScopeExpression::ScopeExpression() {} + +BlitzLLVM::AST::ScopeExpression::~ScopeExpression() {} + +void BlitzLLVM::AST::ScopeExpression::AddExpression(std::unique_ptr ex) { + m_expressions.push_back(std::move(ex)); +} + +BlitzLLVM::AST::FunctionExpression::FunctionExpression(ValueType returnType, + std::string& m_name, + std::list> parameters, + std::unique_ptr scope) + : m_returnType(returnType), m_name(m_name), m_parameters(std::move(parameters)), m_content(std::move(scope)) { + +} + +BlitzLLVM::AST::FunctionExpression::~FunctionExpression() {} + +BlitzLLVM::AST::CallExpression::CallExpression(std::string& name, std::list> arguments) + : m_name(name), m_arguments(std::move(arguments)) { + +} + +BlitzLLVM::AST::CallExpression::~CallExpression() {} diff --git a/code_compiler/source/ast/function.hpp b/code_compiler/source/ast/function.hpp new file mode 100644 index 0000000..77157d2 --- /dev/null +++ b/code_compiler/source/ast/function.hpp @@ -0,0 +1,63 @@ +// Code Compiler for BlitzLLVM +// Copyright(C) 2017 Michael Fabian Dirks +// +// This program is free software : you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program.If not, see . + +#pragma once +#include "ast.hpp" +#include "value.hpp" +#include +#include +#include + +namespace BlitzLLVM { + namespace AST { + class ScopeExpression : public Expression { + public: + ScopeExpression(); + virtual ~ScopeExpression(); + + void AddExpression(std::unique_ptr ex); + + private: + std::list> m_expressions; + }; + + class FunctionExpression : public ScopeExpression { + public: + FunctionExpression(ValueType returnType, + std::string& m_name, + std::list> parameters, + std::unique_ptr scope); + virtual ~FunctionExpression(); + + private: + ValueType m_returnType; + std::string m_name; + std::list> m_parameters; + std::unique_ptr m_content; + }; + + class CallExpression : public Expression { + public: + CallExpression(std::string& name, std::list> arguments); + virtual ~CallExpression(); + + private: + std::string m_name; + std::list> m_arguments; + }; + + } +} diff --git a/code_compiler/source/ast/value.cpp b/code_compiler/source/ast/value.cpp new file mode 100644 index 0000000..d228ff2 --- /dev/null +++ b/code_compiler/source/ast/value.cpp @@ -0,0 +1,59 @@ +// Code Compiler for BlitzLLVM +// Copyright(C) 2017 Michael Fabian Dirks +// +// This program is free software : you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program.If not, see . + +#include "value.hpp" + +BlitzLLVM::AST::VariableExpression::VariableExpression(std::string& name, ValueType type /*= ValueType::Number*/) + : m_name(name), m_type(type) {} + +BlitzLLVM::AST::VariableExpression::~VariableExpression() {} + +BlitzLLVM::AST::ValueType BlitzLLVM::AST::VariableExpression::GetType() { + return m_type; +} + +BlitzLLVM::AST::NumberExpression::NumberExpression(int32_t value) : value(value) {} + +BlitzLLVM::AST::NumberExpression::~NumberExpression() {} + +BlitzLLVM::AST::ValueType BlitzLLVM::AST::NumberExpression::GetType() { + return ValueType::Number; +} + +BlitzLLVM::AST::DecimalExpression::DecimalExpression(float_t value) : value(value) {} + +BlitzLLVM::AST::DecimalExpression::~DecimalExpression() {} + +BlitzLLVM::AST::ValueType BlitzLLVM::AST::DecimalExpression::GetType() { + return ValueType::Decimal; +} + +BlitzLLVM::AST::StringExpression::StringExpression(std::string value) : value(value) {} + +BlitzLLVM::AST::StringExpression::~StringExpression() {} + +BlitzLLVM::AST::ValueType BlitzLLVM::AST::StringExpression::GetType() { + return ValueType::String; +} + +BlitzLLVM::AST::ConstExpression::ConstExpression(std::string& name, std::unique_ptr value) + : m_name(name), m_value(std::move(value)) {} + +BlitzLLVM::AST::ConstExpression::~ConstExpression() {} + +BlitzLLVM::AST::ValueType BlitzLLVM::AST::ConstExpression::GetType() { + return m_value->GetType(); +} diff --git a/code_compiler/source/ast/value.hpp b/code_compiler/source/ast/value.hpp new file mode 100644 index 0000000..493043f --- /dev/null +++ b/code_compiler/source/ast/value.hpp @@ -0,0 +1,98 @@ +// Code Compiler for BlitzLLVM +// Copyright(C) 2017 Michael Fabian Dirks +// +// This program is free software : you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program.If not, see . + +#pragma once +#include "ast.hpp" +#include "lexer.hpp" +#include +#include +#include +#include +#include + +namespace BlitzLLVM { + namespace AST { + enum class ValueType : int8_t { + Unknown, + Number, + Decimal, + String, + Type, + }; + + class ValueExpression : public Expression { + public: + virtual ValueType GetType() = 0; + }; + + class ConstExpression : public ValueExpression { + public: + ConstExpression(std::string& name, std::unique_ptr value); + virtual ~ConstExpression(); + + virtual ValueType GetType() override; + + private: + std::string m_name; + std::unique_ptr m_value; + }; + + class VariableExpression : public ValueExpression { + public: + VariableExpression(std::string& name, ValueType type = ValueType::Number); + virtual ~VariableExpression(); + + virtual ValueType GetType() override; + + private: + std::string m_name; + ValueType m_type; + }; + + class NumberExpression : public ValueExpression { + public: + NumberExpression(int32_t value); + virtual ~NumberExpression(); + + virtual ValueType GetType() override; + + private: + int32_t value; + }; + + class DecimalExpression : public ValueExpression { + public: + DecimalExpression(float_t value); + virtual ~DecimalExpression(); + + virtual ValueType GetType() override; + + private: + float_t value; + }; + + class StringExpression : public ValueExpression { + public: + StringExpression(std::string value); + virtual ~StringExpression(); + + virtual ValueType GetType() override; + + private: + std::string value; + }; + } +} \ No newline at end of file diff --git a/code_compiler/source/compiler.cpp b/code_compiler/source/compiler.cpp new file mode 100644 index 0000000..10b19e7 --- /dev/null +++ b/code_compiler/source/compiler.cpp @@ -0,0 +1,41 @@ +// Code Compiler for BlitzLLVM +// Copyright(C) 2017 Michael Fabian Dirks +// +// This program is free software : you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program.If not, see . + +#include "compiler.hpp" +#include "parser.hpp" +#include "lexer.hpp" +#include +#include + +BlitzLLVM::Compiler::Compiler() {} + +BlitzLLVM::Compiler::~Compiler() {} + +bool BlitzLLVM::Compiler::Compile(std::string in, std::string out) { + /*std::ifstream infile; + infile.open(in); + if (infile.bad() || !infile.good() || infile.eof()) { + std::cerr << "Failed to open file: " << in << std::endl; + return false; + }*/ + + Parser psr = Parser(in); + if (!psr.Parse()) { + + } + + return true; +} diff --git a/projects/code_compiler/source/compiler.hpp b/code_compiler/source/compiler.hpp similarity index 99% rename from projects/code_compiler/source/compiler.hpp rename to code_compiler/source/compiler.hpp index d7bc93f..e2b5f2f 100644 --- a/projects/code_compiler/source/compiler.hpp +++ b/code_compiler/source/compiler.hpp @@ -27,4 +27,4 @@ namespace BlitzLLVM { private: }; -} \ No newline at end of file +} diff --git a/projects/code_compiler/source/lexer.cpp b/code_compiler/source/lexer.cpp similarity index 87% rename from projects/code_compiler/source/lexer.cpp rename to code_compiler/source/lexer.cpp index e5d40ff..09a6ce7 100644 --- a/projects/code_compiler/source/lexer.cpp +++ b/code_compiler/source/lexer.cpp @@ -43,11 +43,15 @@ std::pair g_symbolCharacters[] = { { '~', BlitzLLVM::Lexer::Token::TokenBitNot }, }; -BlitzLLVM::Lexer::Lexer(std::istream& fs) : m_fileStream(fs) {} +BlitzLLVM::Lexer::Lexer() {} BlitzLLVM::Lexer::~Lexer() {} -std::pair BlitzLLVM::Lexer::GetNextToken() { +std::pair BlitzLLVM::Lexer::GetCurrentToken() { + return std::make_pair(m_currentToken, m_currentText); +} + +std::pair BlitzLLVM::Lexer::GetNextToken(std::shared_ptr fs) { std::string buf; Token tkn = Token::TokenEOF; bool haveResult = false; @@ -60,8 +64,13 @@ std::pair BlitzLLVM::Lexer::GetNextToken() haveResult = true; } - while (((m_fileStream.eof() == false) && (m_fileStream.good())) && !haveResult) { - char chr = m_fileStream.get(); + bool m_isTextMode = false; + bool m_isNumberMode = false; + bool m_isStringMode = false; + bool m_isCommentMode = false; + bool m_numberModeHasDecimal = false; + while (((fs->eof() == false) && (fs->good())) && !haveResult) { + char chr = fs->get(); if (chr == '\r' || chr == '\n') { if (tkn != Token::TokenEOF) { @@ -85,7 +94,7 @@ std::pair BlitzLLVM::Lexer::GetNextToken() tkn = Token::TokenQuotedText; break; } else if (iscntrl(chr) || !isprint(chr)) { - m_fileStream.putback(chr); + fs->putback(chr); m_isStringMode = false; break; } else { @@ -95,7 +104,7 @@ std::pair BlitzLLVM::Lexer::GetNextToken() if (isalnum(chr) || (chr == '_')) { buf += chr; } else { - m_fileStream.putback(chr); + fs->putback(chr); m_isTextMode = false; break; } @@ -108,12 +117,12 @@ std::pair BlitzLLVM::Lexer::GetNextToken() tkn = Token::TokenDecimal; buf += chr; } else { - m_fileStream.putback(chr); + fs->putback(chr); m_isNumberMode = false; break; } } else { - m_fileStream.putback(chr); + fs->putback(chr); m_isNumberMode = false; break; } @@ -131,6 +140,26 @@ std::pair BlitzLLVM::Lexer::GetNextToken() buf = chr; } + // Special handling for + and -, due to numbers and decimals. + if (chr == '+' || chr == '-') { + char chr2 = fs->get(); + if (isdigit(chr2)) { + m_isNumberMode = true; + m_numberModeHasDecimal = false; + tkn = Token::TokenNumber; + buf = chr + chr2; + break; + } else if (chr2 == '.') { + m_isNumberMode = true; + m_numberModeHasDecimal = true; + tkn = Token::TokenDecimal; + buf = chr + "0" + chr2; + break; + } else { + fs->putback(chr2); + } + } + // Symbol for (auto v : g_symbolCharacters) { if (v.first == chr) { diff --git a/projects/code_compiler/source/lexer.hpp b/code_compiler/source/lexer.hpp similarity index 89% rename from projects/code_compiler/source/lexer.hpp rename to code_compiler/source/lexer.hpp index 07de7ae..6b5cb84 100644 --- a/projects/code_compiler/source/lexer.hpp +++ b/code_compiler/source/lexer.hpp @@ -15,10 +15,11 @@ // along with this program.If not, see . #pragma once -#include -#include -#include #include +#include +#include +#include +#include namespace BlitzLLVM { class Lexer { @@ -104,28 +105,23 @@ namespace BlitzLLVM { TokenLocal, // Including files. - TokenInclude, + TokenInclude, }; public: - Lexer(std::istream& fs); + Lexer(); ~Lexer(); - std::pair GetNextToken(); + std::pair GetCurrentToken(); + std::pair GetNextToken(std::shared_ptr fs); private: BlitzLLVM::Lexer::Token ConvertTextToToken(Token in, std::string text); private: - std::istream& m_fileStream; - - bool m_isTextMode = false; - bool m_isNumberMode = false; - bool m_isStringMode = false; - bool m_isCommentMode = false; - bool m_numberModeHasDecimal = false; - + Token m_currentToken = Token::TokenUnknown; + std::string m_currentText = ""; Token m_overrideToken = Token::TokenUnknown; std::string m_overrideText = ""; }; -} \ No newline at end of file +} diff --git a/projects/code_compiler/source/main.cpp b/code_compiler/source/main.cpp similarity index 96% rename from projects/code_compiler/source/main.cpp rename to code_compiler/source/main.cpp index 42893d4..d953525 100644 --- a/projects/code_compiler/source/main.cpp +++ b/code_compiler/source/main.cpp @@ -20,7 +20,8 @@ #include "version.h" #define LICENSE "Copyright (C) 2017 Michael Fabian Dirks\n\ -This program comes with ABSOLUTELY NO WARRANTY, for details launch with `--warranty`. This is free software, and you are welcome to redistribute it under certain conditions." +This program comes with ABSOLUTELY NO WARRANTY, for details launch with `--warranty`.\n\ +This is free software, and you are welcome to redistribute it under certain conditions." #define WARRANTY "\ THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.EXCEPT WHEN OTHERWISE STATED IN \ @@ -106,4 +107,4 @@ int main(int argc, char** argv) { std::cin.get(); #endif return 0; -} \ No newline at end of file +} diff --git a/code_compiler/source/parser.cpp b/code_compiler/source/parser.cpp new file mode 100644 index 0000000..5e4c1a1 --- /dev/null +++ b/code_compiler/source/parser.cpp @@ -0,0 +1,125 @@ +// Code Compiler for BlitzLLVM +// Copyright(C) 2017 Michael Fabian Dirks +// +// This program is free software : you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program.If not, see . + +#include "parser.hpp" +#include "ast/function.hpp" +#include +#include +#include + +BlitzLLVM::Parser::Parser(std::string file) { + // Try and load the file + std::shared_ptr instream = std::make_shared(file); + if (instream->bad() || !instream->good()) { + throw std::ios_base::failure("Failed to open file."); + } + m_files.push(std::make_pair(file, instream)); +} + +BlitzLLVM::Parser::~Parser() { + while (m_files.size() > 0) { + std::shared_ptr file = std::dynamic_pointer_cast(m_files.top().second); + file->close(); + m_files.pop(); + } +} + +std::unique_ptr BlitzLLVM::Parser::Parse() { + std::unique_ptr scope = std::make_unique(); + + std::unique_ptr expr; + while ((expr = std::move(ParseExpression())) != nullptr) { + scope->AddExpression(std::move(expr)); + } + + return std::move(scope); +} + +void BlitzLLVM::Parser::LogMessage(const char* msg, ...) { + std::vector buf(65535); + va_list val; + va_start(val, msg); + int rval = vsnprintf(buf.data(), buf.size(), msg, val); + va_end(val); + std::cout << buf.data() << '\n'; +} + +void BlitzLLVM::Parser::LogError(const char* msg, ...) { + std::vector buf(65535); + va_list val; + va_start(val, msg); + int rval = vsnprintf(buf.data(), buf.size(), msg, val); + va_end(val); + std::cerr << buf.data() << '\n'; +} + +std::pair BlitzLLVM::Parser::GetNextToken() { + return m_lexer.GetNextToken(m_files.top().second); +} + +std::unique_ptr BlitzLLVM::Parser::ParseExpression() { + while (true) { + auto tkn = GetNextToken(); + + switch (tkn.first) { + case BlitzLLVM::Lexer::Token::TokenNewLine: + case BlitzLLVM::Lexer::Token::TokenComment: + // Skip Comments, since we don't really need them for the AST. + continue; + case BlitzLLVM::Lexer::Token::TokenPlus: + case BlitzLLVM::Lexer::Token::TokenMinus: + + + default: // End Of File / Unknown + case BlitzLLVM::Lexer::Token::TokenUnknown: + case BlitzLLVM::Lexer::Token::TokenEOF: + return nullptr; + break; + } + } +} + +std::unique_ptr BlitzLLVM::Parser::ParseNumber(BlitzLLVM::Lexer::Token token, std::string value) { + if (token != Lexer::Token::TokenNumber) { + LogError("Unexpected Token during parsing, expected number."); + return nullptr; + } + + char* endptr = const_cast(value.c_str() + value.size()); + int32_t parsed = strtol(value.c_str(), &endptr, 10); + if (errno == ERANGE) { + LogError("Number out of range."); + return nullptr; + } + + return std::make_unique(parsed); +} + +std::unique_ptr BlitzLLVM::Parser::ParseDecimal(BlitzLLVM::Lexer::Token token, std::string value) { + if (token != Lexer::Token::TokenNumber) { + LogError("Unexpected Token during parsing, expected number."); + return nullptr; + } + + char* endptr = const_cast(value.c_str() + value.size()); + float_t parsed = strtof(value.c_str(), &endptr); + if (errno == ERANGE) { + LogError("Number out of range."); + return nullptr; + } + + return std::make_unique(parsed); +} diff --git a/code_compiler/source/parser.hpp b/code_compiler/source/parser.hpp new file mode 100644 index 0000000..af99a0c --- /dev/null +++ b/code_compiler/source/parser.hpp @@ -0,0 +1,52 @@ +// Code Compiler for BlitzLLVM +// Copyright(C) 2017 Michael Fabian Dirks +// +// This program is free software : you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program.If not, see . + +#pragma once +#include "lexer.hpp" +#include "ast/ast.hpp" +#include "ast/value.hpp" +#include +#include +#include +#include +#include + +namespace BlitzLLVM { + class Parser { + public: + Parser(std::string file); + ~Parser(); + + std::unique_ptr Parse(); + + protected: + void LogMessage(const char* msg, ...); + void LogError(const char* msg, ...); + + private: + std::pair GetNextToken(); + + private: + std::unique_ptr ParseExpression(); + std::unique_ptr ParseNumber(BlitzLLVM::Lexer::Token token, std::string value); + std::unique_ptr ParseDecimal(BlitzLLVM::Lexer::Token token, std::string value); + + private: + Lexer m_lexer; + std::stack>> m_files; + + }; +} diff --git a/projects/code_compiler/templates/version.h b/code_compiler/templates/version.h similarity index 100% rename from projects/code_compiler/templates/version.h rename to code_compiler/templates/version.h diff --git a/projects/code_compiler/CMakeVersion.txt b/projects/code_compiler/CMakeVersion.txt deleted file mode 100644 index e6dce61..0000000 --- a/projects/code_compiler/CMakeVersion.txt +++ /dev/null @@ -1,7 +0,0 @@ -SET(VERSION_MAJOR 0) -SET(VERSION_MINOR 0) -SET(VERSION_PATCH 1) -configure_file( - "${PROJECT_SOURCE_DIR}/templates/version.h" - "${PROJECT_BINARY_DIR}/version.h" -) \ No newline at end of file diff --git a/projects/code_compiler/source/compiler.cpp b/projects/code_compiler/source/compiler.cpp deleted file mode 100644 index abced7a..0000000 --- a/projects/code_compiler/source/compiler.cpp +++ /dev/null @@ -1,148 +0,0 @@ -// Code Compiler for BlitzLLVM -// Copyright(C) 2017 Michael Fabian Dirks -// -// This program is free software : you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program.If not, see . - -#include "compiler.hpp" -#include "parser.hpp" -#include "lexer.hpp" -#include -#include - -BlitzLLVM::Compiler::Compiler() {} - -BlitzLLVM::Compiler::~Compiler() {} - -bool BlitzLLVM::Compiler::Compile(std::string in, std::string out) { - std::ifstream infile; - infile.open(in); - if (infile.bad() || !infile.good() || infile.eof()) { - std::cerr << "Failed to open file: " << in << std::endl; - return false; - } - - Lexer psr = { infile }; - for (auto tkn = psr.GetNextToken(); tkn.first != Lexer::Token::TokenEOF; tkn = psr.GetNextToken()) { - switch (tkn.first) { - case Lexer::Token::TokenEOF: - std::cout << "EOF" << std::endl; - break; - case Lexer::Token::TokenNewLine: - std::cout << "" << std::endl; - break; - case Lexer::Token::TokenPlus: - case Lexer::Token::TokenMinus: - case Lexer::Token::TokenSlashForward: - case Lexer::Token::TokenSlashBackward: - case Lexer::Token::TokenMultiply: - case Lexer::Token::TokenEqual: - case Lexer::Token::TokenOctothorp: - case Lexer::Token::TokenPercent: - case Lexer::Token::TokenDollar: - case Lexer::Token::TokenRoundBracketOpen: - case Lexer::Token::TokenRoundBracketClose: - case Lexer::Token::TokenSquareBracketOpen: - case Lexer::Token::TokenSquareBracketClose: - case Lexer::Token::TokenAngleBracketOpen: - case Lexer::Token::TokenAngleBracketClose: - case Lexer::Token::TokenDot: - case Lexer::Token::TokenColon: - case Lexer::Token::TokenComma: - case Lexer::Token::TokenSemicolon: - case Lexer::Token::TokenCaret: - case Lexer::Token::TokenBitNot: - case Lexer::Token::TokenDoubleQuote: - case Lexer::Token::TokenNot: - case Lexer::Token::TokenAnd: - case Lexer::Token::TokenOr: - case Lexer::Token::TokenXor: - case Lexer::Token::TokenShl: - case Lexer::Token::TokenShr: - case Lexer::Token::TokenSal: - case Lexer::Token::TokenFalse: - case Lexer::Token::TokenTrue: - case Lexer::Token::TokenFloat: - case Lexer::Token::TokenString: - case Lexer::Token::TokenHex: - case Lexer::Token::TokenInt: - case Lexer::Token::TokenIf: - case Lexer::Token::TokenThen: - case Lexer::Token::TokenElseIf: - case Lexer::Token::TokenElse: - case Lexer::Token::TokenEndIf: - case Lexer::Token::TokenSelect: - case Lexer::Token::TokenCase: - case Lexer::Token::TokenDefault: - case Lexer::Token::TokenGoto: - case Lexer::Token::TokenGosub: - case Lexer::Token::TokenReturn: - case Lexer::Token::TokenFunction: - case Lexer::Token::TokenEnd: - case Lexer::Token::TokenStop: - case Lexer::Token::TokenFor: - case Lexer::Token::TokenTo: - case Lexer::Token::TokenNext: - case Lexer::Token::TokenWhile: - case Lexer::Token::TokenWend: - case Lexer::Token::TokenRepeat: - case Lexer::Token::TokenUntil: - case Lexer::Token::TokenForever: - case Lexer::Token::TokenExit: - case Lexer::Token::TokenAbs: - case Lexer::Token::TokenSign: - case Lexer::Token::TokenCos: - case Lexer::Token::TokenSin: - case Lexer::Token::TokenTan: - case Lexer::Token::TokenACos: - case Lexer::Token::TokenASin: - case Lexer::Token::TokenATan: - case Lexer::Token::TokenATan2: - case Lexer::Token::TokenLog: - case Lexer::Token::TokenLog10: - case Lexer::Token::TokenCeil: - case Lexer::Token::TokenFloor: - case Lexer::Token::TokenMod: - case Lexer::Token::TokenPi: - case Lexer::Token::TokenExp: - case Lexer::Token::TokenSqr: - case Lexer::Token::TokenConst: - case Lexer::Token::TokenGlobal: - case Lexer::Token::TokenLocal: - case Lexer::Token::TokenInclude: - std::cout << tkn.second << ' '; - break; - case Lexer::Token::TokenText: - std::cout << "Text(" << tkn.second << ")" << ' '; - break; - case Lexer::Token::TokenNumber: - std::cout << "Number(" << tkn.second << ")" << ' '; - break; - case Lexer::Token::TokenDecimal: - std::cout << "Decimal(" << tkn.second << ")" << ' '; - break; - case Lexer::Token::TokenQuotedText: - std::cout << "QuotedText(" << tkn.second << ")" << ' '; - break; - case Lexer::Token::TokenComment: - std::cout << "Comment(" << tkn.second << ")" << ' '; - break; - case Lexer::Token::TokenUnknown: - default: - std::cout << "Unknown(" << tkn.second << ") "; - break; - } - } - - return true; -}