Skip to content
This repository has been archived by the owner on Dec 31, 2024. It is now read-only.

AST reprogramming #5

Draft
wants to merge 15 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,20 @@
!src/*/**/*.cc
!src/*/**/*.h
!src/*/**/*.hh
!src/*.proj
!src/lsproj.cc
!src/ls*.cc

!scripts
!scripts/common.mak
!scripts/lsproj.mak
!scripts/ls.mak
!scripts/install.bat
!scripts/uninstall.bat

!deps
!deps/*

!LICENSE
!CONTRIBUTING.md
!Makefile
!README.md
!.gitignore
!.gitignore
!.clang-format
20 changes: 10 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export MAKEFLAGS += --silent -r -j
export flags=-std=c++17 -Wall -Wno-main -Wno-trigraphs -Wno-missing-braces -Wno-stringop-overflow -DPROFILE_$(profile) -fdiagnostics-color=always
export ldflags=-L$(bin)/$(profile) -Wl,-rpath=bin/$(profile)
export lib=ppc$(version-major)-
export lib=ppc-$(version-major).$(version-minor)-
export profile=release

############# SETTINGS ############
Expand All @@ -12,6 +12,7 @@ export output = ppc
export mainmodule = main
export version-major=0
export version-minor=0
export version-build=1
###################################

ifeq ($(OS),Windows_NT)
Expand Down Expand Up @@ -43,8 +44,8 @@ export exe=.exe
export CC=gcc
export CXX=g++

export version-build=$(if $(wildcard build.version),$(shell type build.version),0)
export binary = $(bin)/$(output)$(version-major)-windows.exe
# export version-build=$(if $(wildcard build.version),$(shell type build.version),0)
export binary = $(bin)/$(output)-$(version-major).$(version-minor)-windows.exe

build: version
echo ======================== Compiling =========================
Expand All @@ -60,11 +61,10 @@ cleartmp:
.ONESHELL:
install: build
powershell -Command "start-process cmd -verb runas -args '/K pushd %CD%&set bin=$(bin)&set output=$(output)&.\scripts\install.bat&exit'"
# .\scripts\install.bat
uninstall:
.\scripts\uninstall.bat
version:
cmd /c "set /a $(version-build) + 1 > build.version"
# version:
# cmd /c "set /a $(version-build) + 1 > build.version"

else

Expand All @@ -74,8 +74,8 @@ export mkdir=mkdir -p $$1
export rmdir=rm -rf $$1
export echo=echo "$$1"
export so=.so
export version-build=$(if $(wildcard build.version),$(shell cat build.version),0)
export binary = $(bin)/$(output)$(version-major)-linux
# export version-build=$(if $(wildcard build.version),$(shell cat build.version),0)
export binary = $(bin)/$(output)-$(version-major).$(version-minor)-linux

build: version
echo ======================== Compiling =========================
Expand All @@ -98,8 +98,8 @@ uninstall:
echo Uninstalling ++C compiler from your system...
sudo rm $(patsubst $(bin)/%.so,/usr/lib/%*.so,$(bin)/*.so)
sudo rm /usr/bin/$(output)
version:
echo $$(($(version-build) + 1)) > build.version
# version:
# echo $$(($(version-build) + 1)) > build.version

leak: build
echo ====================== Leak scanning =======================
Expand Down
File renamed without changes.
3 changes: 3 additions & 0 deletions deps/main
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
utils
treeifier
lang
2 changes: 2 additions & 0 deletions deps/treeifier
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
utils
lang
File renamed without changes.
2 changes: 1 addition & 1 deletion include/compiler.hh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#ifndef PPC_COMPILER_H
#define PPC_COMPILER_H 1

#include "compiler/treeifier.hh"
#include "treeifier.hh"

#endif
11 changes: 0 additions & 11 deletions include/compiler/treeifier.hh

This file was deleted.

82 changes: 0 additions & 82 deletions include/compiler/treeifier/ast.hh

This file was deleted.

89 changes: 41 additions & 48 deletions include/lang/common.hh
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,29 @@
#include <string>

namespace ppc::lang {
struct namespace_name_t : public std::vector<std::string> {
struct nmsp_t: public std::vector<std::string> {
using base = std::vector<std::string>;

int compare(const namespace_name_t &other) const;
int compare(const nmsp_t &other) const;

bool operator==(const namespace_name_t &other) const { return compare(other) == 0; }
bool operator!=(const namespace_name_t &other) const { return compare(other) != 0; }
bool operator<(const namespace_name_t &other) const { return compare(other) < 0; }
bool operator<=(const namespace_name_t &other) const { return compare(other) <= 0; }
bool operator>(const namespace_name_t &other) const { return compare(other) > 0; }
bool operator>=(const namespace_name_t &other) const { return compare(other) >= 0; }
bool operator==(const nmsp_t &other) const { return compare(other) == 0; }
bool operator!=(const nmsp_t &other) const { return compare(other) != 0; }
bool operator<(const nmsp_t &other) const { return compare(other) < 0; }
bool operator<=(const nmsp_t &other) const { return compare(other) <= 0; }
bool operator>(const nmsp_t &other) const { return compare(other) > 0; }
bool operator>=(const nmsp_t &other) const { return compare(other) >= 0; }

operator std::string() const { return to_string(); }
std::string to_string() const;

namespace_name_t() { }
namespace_name_t(std::initializer_list<std::string> segments): base(segments.begin(), segments.end()) { }
nmsp_t() { }
nmsp_t(std::initializer_list<std::string> segments): base(segments.begin(), segments.end()) { }
};
}

template <>
struct std::hash<ppc::lang::namespace_name_t> {
std::size_t operator()(const ppc::lang::namespace_name_t& k) const {
struct std::hash<ppc::lang::nmsp_t> {
std::size_t operator()(const ppc::lang::nmsp_t& k) const {
size_t res = 0;

for (auto &el : k) {
Expand All @@ -41,55 +41,48 @@ struct std::hash<ppc::lang::namespace_name_t> {
#include "utils/location.hh"

namespace ppc::lang {
template <class T>
struct located_t : T {
template <class ParserT>
struct located_t: ParserT {
location_t location;

located_t(location_t loc, const T &val): T(val), location(loc) { }
located_t(const T &val): T(val), location(location_t::NONE) { }
located_t(location_t loc, const ParserT &val): ParserT(val), location(loc) { }
located_t(const ParserT &val): ParserT(val), location(location_t::NONE) { }
located_t() { }
};
template <class T>
struct slocated_t {
T value;
location_t location;

bool operator ==(const slocated_t<T> &other) {
return value == other.value && location == other.location;
}
bool operator !=(const slocated_t<T> &other) {
return !(*this == other);
}

slocated_t(location_t loc, const T &val): value(val), location(loc) { }
slocated_t(const T &val): value(val), location(location_t::NONE) { }
slocated_t() { }
};

struct loc_namespace_name_t : public std::vector<located_t<std::string>> {
struct loc_nmsp_t: public std::vector<located_t<std::string>> {
using base = std::vector<located_t<std::string>>;

int compare(const loc_namespace_name_t &other) const;
int compare(const loc_nmsp_t &other) const;

bool operator==(const loc_namespace_name_t &other) const { return compare(other) == 0; }
bool operator!=(const loc_namespace_name_t &other) const { return compare(other) != 0; }
bool operator<(const loc_namespace_name_t &other) const { return compare(other) < 0; }
bool operator<=(const loc_namespace_name_t &other) const { return compare(other) <= 0; }
bool operator>(const loc_namespace_name_t &other) const { return compare(other) > 0; }
bool operator>=(const loc_namespace_name_t &other) const { return compare(other) >= 0; }
bool operator==(const loc_nmsp_t &other) const { return compare(other) == 0; }
bool operator!=(const loc_nmsp_t &other) const { return compare(other) != 0; }
bool operator<(const loc_nmsp_t &other) const { return compare(other) < 0; }
bool operator<=(const loc_nmsp_t &other) const { return compare(other) <= 0; }
bool operator>(const loc_nmsp_t &other) const { return compare(other) > 0; }
bool operator>=(const loc_nmsp_t &other) const { return compare(other) >= 0; }

namespace_name_t strip_location() const;
nmsp_t strip_location() const;
std::string to_string() const;

operator nmsp_t() const { return strip_location(); }
operator std::string() const { return to_string(); }
std::string to_string() const;

loc_namespace_name_t() { }
loc_namespace_name_t(std::initializer_list<located_t<std::string>> segments): base(segments.begin(), segments.end()) { }
loc_nmsp_t() { }
loc_nmsp_t(std::initializer_list<located_t<std::string>> segments): base(segments.begin(), segments.end()) { }
};

bool is_identifier_valid(messages::msg_stack_t &msg_stack, ppc::location_t location, const std::string &name);
inline bool is_identifier_valid(const std::string &name) {
messages::msg_stack_t ms;
return is_identifier_valid(ms, { }, name);
template <class SetT>
bool resolve_name(const SetT &defs, const nmsp_t &src, const nmsp_t &target) {
if (src == target) return true;

for (auto it : defs) {
nmsp_t val = (nmsp_t)(it);
val.insert(val.end(), src.begin(), src.end());

if (val == target) return true;
}

return false;
}
}
Loading