Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Team 4 shadowdash new language design #22

Open
wants to merge 1 commit into
base: team-4-language
Choose a base branch
from
Open
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
76 changes: 76 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@

version: 2.1
jobs:
build-test:
docker:
- image: cimg/base:current
steps:
# Checkout the code as the first step.
- checkout
- run:
name: InstallPreq
command: |
echo "Installing clang-tidy"
sudo apt-get update && sudo apt-get install -y clang-tidy
echo "Installed"
- run:
name: Build
command: |
echo "Building"
mkdir build && cd build
cmake -S ..
make -j $(nproc)
cd ../
echo "Built"
- run:
name: ninjaTest
command: |
cd build
./ninja_test --gtest_output=XML
echo "Testing Done"
- store_test_results:
path: build
- run:
name: ctest
command: |
echo "Start Testing"
cd build
ctest --output-junit results.xml
echo "Testing Done"
- store_test_results:
path: build/results.xml
- run:
name: Run Performance Tests
command: |
cd build
for test in build_log_perftest canon_perftest clparser_perftest elide_middle_perftest hash_collision_bench; do
echo "Running $test"
./$test
done
- run:
name: Run Compile .o and .so Tests
command: |
check_success() {
if [ $? -eq 0 ]; then
echo "$1"
else
echo "$1"
exit 1
fi
}

cd src/shadowdash

g++ -w -std=c++17 -fPIC -c manifest.cc manifest.h
check_success ".o compiled successfully"

g++ -w -shared -o manifest.so manifest.o
check_success ".so compiled successfully"

cd ../..


workflows:
build-test-workflow:
jobs:
- build-test
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,8 @@
# Visual Studio files
/.vs/
/out/

# New Language files
src/shadowdash/manifest.o
src/shadowdash/manifest.so
src/shadowdash/manifest.h.gch
17 changes: 17 additions & 0 deletions commands.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
mkdir build && cd build
cmake -S ..
make -j $(nproc)
ls
ctest
sudo cp ninja /usr/local/bin/ (move nin to local/bin)
ninja --version

(cd ..)
git clone https://github.com/llvm/llvm-project.git
cd llvm-project
mkdir build
cd build
cmake -G "Ninja" -DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra" -DCMAKE_BUILD_TYPE=Release ../llvm
ninja clang-tidy
export PATH=$PATH:/home/yuwei/Documents/llvm-project/build/bin
clang-tidy --version
51 changes: 51 additions & 0 deletions src/shadowdash/manifest.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#include "manifest.h"

using namespace shadowdash;

void manifest() {
let(flags, "-O3");

let(pool_depth, "4");

auto heavy_object_pool = pool_(bind(depth, "pool_depth"_v));

auto compile = rule( {
bind(command, "g++", "flags"_v, "-c", in, "-o", out),
bind(pool, "heavy_object_pool"_v)
} );

auto link = rule( {
bind(command, "g++", in, "-o", out),
} );

auto build_c = build(list{ str{ "hello.o" } },
{},
compile,
list{ str{ "hello.cc" } },
{},
{},
{ bind(flags, "-O2"),
bind(pool, "console"_v) }
);

auto build_l = build(list{ str{ "hello" } },
{},
link,
list{ str{ "hello.o" } },
{},
{},
{}
);

auto build_p = build(list{ str{ "dummy" } },
{},
phony,
{},
{},
{},
{}
);

default_(str{ "hello" });
default_(list{ str{ "foo1" }, str{ "foo2" } });
}
135 changes: 135 additions & 0 deletions src/shadowdash/manifest.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
#pragma once

#include <initializer_list>
#include <string_view>
#include <string>
#include <vector>

namespace shadowdash {

class Token {
public:
enum Type { LITERAL, VAR};

constexpr Token(Type type, std::string_view value) : type_(type), value_(value) {}

constexpr Token(std::string_view value) : Token(Token::LITERAL, value) {}

constexpr Token(const char* value) : Token(Token::LITERAL, value) {}

Type type_;
std::string_view value_;
};

constexpr Token operator"" _l(const char* value, std::size_t len) {
return Token(Token::Type::LITERAL, { value, len });
}

constexpr Token operator"" _v(const char* value, std::size_t len) {
return Token(Token::Type::VAR, { value, len });
}

class str {
public:
str(std::initializer_list<Token> tokens) : tokens_(tokens) {}
std::initializer_list<Token> tokens_;
};

using binding = std::pair<std::string_view, str>;
using map = std::initializer_list<binding>;

class list {
public:
list(std::initializer_list<str> values) : values_(values) {}
constexpr size_t size() const {return values_.size();}
str operator[] (size_t i) const {return *(values_.begin() + i);}

private:
std::initializer_list<str> values_;
};

class var {
private:
const char* name_;
str value_;
public:
var(const char* name, str value): name_(name), value_(value) {}
};

class rule {
private:
map bindings_;
public:
rule(map bindings): bindings_(bindings) {}
};

class pool_ {
private:
binding depth_;
public:
pool_(binding depth): depth_(depth) {}
};

class build {
private:
list outputs_;
list implicit_outputs_;
rule& rule_;
list inputs_;
list implicit_inputs_;
list order_only_inputs_;
map bindings_;

public:
build(
list outputs,
list implicit_outputs,
rule& rule,
list inputs,
list implicit_inputs,
list order_only_inputs,
map bindings
) : outputs_(outputs),
implicit_outputs_(implicit_outputs),
rule_(rule),
inputs_(inputs),
implicit_inputs_(implicit_inputs),
order_only_inputs_(order_only_inputs),
bindings_(bindings) {}
};

class default_{
public:
default_(list addedList){
for (size_t i = 0; i < addedList.size(); i++) targets_.push_back(addedList[i]);
}

default_(str addedTarget) {
targets_.push_back(addedTarget);
}

static std::vector<str> targets_;
};

std::vector<str> default_::targets_;

static constexpr auto in = "in"_v;
static constexpr auto out = "out"_v;
static auto phony = rule{{}};
static auto console = pool_(binding("depth", str{ {"1"} }));

}

#define let(name, ...) \
var name { \
#name, str { \
__VA_ARGS__ \
} \
}

#define bind(name, ...) \
{ \
#name, str { \
__VA_ARGS__ \
} \
}