-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit ebdbd05
Showing
214 changed files
with
17,957 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,101 @@ | ||
# Created by https://www.toptal.com/developers/gitignore/api/visualstudiocode,macos,windows,linux | ||
# Edit at https://www.toptal.com/developers/gitignore?templates=visualstudiocode,macos,windows,linux | ||
|
||
### Linux ### | ||
*~ | ||
|
||
# temporary files which can be created if a process still has a handle open of a deleted file | ||
.fuse_hidden* | ||
|
||
# KDE directory preferences | ||
.directory | ||
|
||
# Linux trash folder which might appear on any partition or disk | ||
.Trash-* | ||
|
||
# .nfs files are created when an open file is removed but is still being accessed | ||
.nfs* | ||
|
||
### macOS ### | ||
# General | ||
.DS_Store | ||
.AppleDouble | ||
.LSOverride | ||
|
||
# Icon must end with two \r | ||
Icon | ||
|
||
|
||
# Thumbnails | ||
._* | ||
|
||
# Files that might appear in the root of a volume | ||
.DocumentRevisions-V100 | ||
.fseventsd | ||
.Spotlight-V100 | ||
.TemporaryItems | ||
.Trashes | ||
.VolumeIcon.icns | ||
.com.apple.timemachine.donotpresent | ||
|
||
# Directories potentially created on remote AFP share | ||
.AppleDB | ||
.AppleDesktop | ||
Network Trash Folder | ||
Temporary Items | ||
.apdisk | ||
|
||
### macOS Patch ### | ||
# iCloud generated files | ||
*.icloud | ||
|
||
### VisualStudioCode ### | ||
.vscode/* | ||
!.vscode/settings.json | ||
!.vscode/tasks.json | ||
!.vscode/launch.json | ||
!.vscode/extensions.json | ||
!.vscode/*.code-snippets | ||
|
||
# Local History for Visual Studio Code | ||
.history/ | ||
|
||
# Built Visual Studio Code Extensions | ||
*.vsix | ||
|
||
### VisualStudioCode Patch ### | ||
# Ignore all local history of files | ||
.history | ||
.ionide | ||
|
||
### Windows ### | ||
# Windows thumbnail cache files | ||
Thumbs.db | ||
Thumbs.db:encryptable | ||
ehthumbs.db | ||
ehthumbs_vista.db | ||
|
||
# Dump file | ||
*.stackdump | ||
|
||
# Folder config file | ||
[Dd]esktop.ini | ||
|
||
# Recycle Bin used on file shares | ||
$RECYCLE.BIN/ | ||
|
||
# Windows Installer files | ||
*.cab | ||
*.msi | ||
*.msix | ||
*.msm | ||
*.msp | ||
|
||
# Windows shortcuts | ||
*.lnk | ||
|
||
# Environment variables | ||
.env | ||
.venv | ||
|
||
# End of https://www.toptal.com/developers/gitignore/api/visualstudiocode,macos,windows,linux |
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,3 @@ | ||
# Gloo lang | ||
|
||
A DSL for AI |
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,20 @@ | ||
# Created by https://www.toptal.com/developers/gitignore/api/rust | ||
# Edit at https://www.toptal.com/developers/gitignore?templates=rust | ||
|
||
### Rust ### | ||
# Generated by Cargo | ||
# will have compiled files and executables | ||
debug/ | ||
target/ | ||
|
||
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries | ||
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html | ||
Cargo.lock | ||
|
||
# These are backup files generated by rustfmt | ||
**/*.rs.bk | ||
|
||
# MSVC Windows builds of rustc generate these, which store debugging information | ||
*.pdb | ||
|
||
# End of https://www.toptal.com/developers/gitignore/api/rust |
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,22 @@ | ||
[package] | ||
name = "gloo" | ||
version = "0.2.4" | ||
edition = "2021" | ||
build = "build.rs" | ||
|
||
[dependencies] | ||
walkdir = "2" | ||
libc = "0.2" | ||
clap = "2.33" | ||
log = "0.4" | ||
env_logger = "0.9" | ||
thiserror = "1.0" | ||
colored = "2.0" | ||
pretty_env_logger = "0.5" | ||
yaml-rust = "*" | ||
semver = "1.0.18" | ||
|
||
[build-dependencies] | ||
cc = "1.0" | ||
walkdir = "2" | ||
which = "4.0" |
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 @@ | ||
extern crate cc; | ||
extern crate which; | ||
|
||
use std::env; | ||
use std::path::Path; | ||
use walkdir::WalkDir; | ||
use which::which; | ||
|
||
// Build the C++ code into a static library | ||
fn main() { | ||
// Check if ccache is available on the system | ||
if let Ok(ccache_path) = which("ccache") { | ||
env::set_var("CC", &ccache_path); | ||
// print out the path to ccache | ||
println!("cargo:warning=Using ccache at {}", ccache_path.display()); | ||
} | ||
|
||
let mut build = cc::Build::new(); | ||
build.cpp(true).warnings(true); | ||
|
||
let cpp_path = Path::new("cpp_src"); | ||
if cpp_path.exists() && cpp_path.is_dir() { | ||
for entry in WalkDir::new(cpp_path) { | ||
let entry = entry.unwrap(); | ||
let path = entry.path(); | ||
if path.is_file() && path.extension().unwrap_or_default() == "cc" { | ||
build.file(path); | ||
} | ||
} | ||
} | ||
|
||
#[cfg(debug_assertions)] | ||
build.flag_if_supported("-O0").flag_if_supported("-g"); | ||
|
||
#[cfg(not(debug_assertions))] | ||
build.flag_if_supported("-O2"); | ||
|
||
build.include(cpp_path); | ||
|
||
// Determine if we're targeting MSVC | ||
let target = env::var("TARGET").unwrap(); | ||
if target.contains("msvc") { | ||
// Flags for MSVC | ||
build.flag("/W4").flag("/WX").flag("/std:c++20").flag("/EHsc"); | ||
} else { | ||
// If mac, set MACOSX_DEPLOYMENT_TARGET: 11.0 | ||
if target.contains("apple") { | ||
println!("cargo:rustc-env=MACOSX_DEPLOYMENT_TARGET=11.0"); | ||
} | ||
// Flags for GCC/Clang | ||
build.flag("-Wall").flag("-Wextra").flag("-Werror").flag("-std=c++2a"); | ||
} | ||
|
||
build.compile("program"); | ||
|
||
println!("cargo:rerun-if-changed=cpp_src/"); | ||
} |
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,113 @@ | ||
#include <cstring> | ||
#include <fstream> | ||
#include <iostream> | ||
#include <map> | ||
#include <string> | ||
|
||
#include "variant/ast/ast.h" | ||
#include "variant/ast/utils.h" | ||
#include "variant/error.h" | ||
#include "variant/generate/dir_writer.h" | ||
#include "variant/post_process/dependency_graph.h" | ||
#include "variant/post_process/validate.h" | ||
#include "variant/tokenizer/tokenizer.h" | ||
|
||
void generate(const std::string &out_dir, | ||
const std::map<std::string, std::string> &file_map) { | ||
std::unordered_map<std::string, gloo::AST::Nodes> file_nodes; | ||
for (const auto &pair : file_map) { | ||
auto tokens = gloo::Tokenizer::Tokenize(pair.first, pair.second); | ||
auto nodes = gloo::AST::Parser(tokens); | ||
file_nodes[pair.first] = nodes; | ||
} | ||
|
||
// Combine all the nodes into one AST | ||
gloo::AST::Nodes nodes; | ||
for (auto pair : file_nodes) { | ||
for (auto &item : pair.second.enums) { | ||
nodes.enums.push_back(item); | ||
} | ||
|
||
for (auto &item : pair.second.classes) { | ||
nodes.classes.push_back(item); | ||
} | ||
|
||
for (auto &item : pair.second.functions) { | ||
nodes.functions.push_back(item); | ||
} | ||
|
||
for (auto &[func, group] : pair.second.function_test_groups) { | ||
nodes.function_test_groups[func].insert( | ||
nodes.function_test_groups[func].end(), group.begin(), group.end()); | ||
} | ||
|
||
for (auto &[func, variants] : pair.second.function_variants) { | ||
nodes.function_variants[func].insert(nodes.function_variants[func].end(), | ||
variants.begin(), variants.end()); | ||
} | ||
for (auto &item : pair.second.clients) { | ||
nodes.clients.push_back(item); | ||
} | ||
} | ||
|
||
gloo::PostProcess::Validate(nodes); | ||
|
||
auto [order, deps] = gloo::PostProcess::BuildDependencyGraph(nodes); | ||
|
||
// Print the nodes in the order they should be processed | ||
for (const auto &node : order) { | ||
node->toPython(deps.at(node->uniqueName())); | ||
} | ||
|
||
// Write the __init__.py files | ||
gloo::DirectoryWriter::get().file("__init__.py"); | ||
gloo::DirectoryWriter::get().flush(out_dir); | ||
} | ||
|
||
extern "C" { | ||
int receive_data(const char *out_dir, const char **filenames, | ||
const char **contents, int len, char *error_msg) { | ||
std::map<std::string, std::string> file_map; | ||
for (int i = 0; i < len; i++) { | ||
file_map[filenames[i]] = contents[i]; | ||
} | ||
|
||
try { | ||
generate(out_dir, file_map); | ||
return 0; | ||
} catch (const gloo::GlooError &e) { | ||
if (error_msg) { | ||
// Copy the exception's error message to the provided buffer | ||
#ifdef _WIN32 | ||
strncpy_s(error_msg, 255, e.what().data(), 255); | ||
#else | ||
strncpy(error_msg, e.what().data(), 255); | ||
#endif | ||
error_msg[255] = '\0'; // Null-terminate just to be sure | ||
} | ||
return 1; // Error | ||
} catch (const std::exception &e) { | ||
if (error_msg) { | ||
// Copy the exception's error message to the provided buffer | ||
#ifdef _WIN32 | ||
strncpy_s(error_msg, 255, e.what(), 255); | ||
#else | ||
strncpy(error_msg, e.what(), 255); | ||
#endif | ||
error_msg[255] = '\0'; // Null-terminate just to be sure | ||
} | ||
return 2; // Error | ||
} catch (...) { | ||
if (error_msg) { | ||
// Copy the exception's error message to the provided buffer | ||
#ifdef _WIN32 | ||
strncpy_s(error_msg, 255, "Unknown error", sizeof("Unknown error")); | ||
#else | ||
strncpy(error_msg, "Unknown error", 255); | ||
#endif | ||
error_msg[255] = '\0'; // Null-terminate just to be sure | ||
} | ||
return 3; // Error | ||
} | ||
} | ||
} |
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,51 @@ | ||
#include "variant/ast/ast.h" | ||
|
||
#include <iostream> | ||
#include <ostream> | ||
|
||
#include "variant/ast/utils.h" | ||
|
||
namespace gloo::AST { | ||
using namespace Tokenizer; | ||
|
||
Nodes Parser(const std::vector<Token> &tokens) { | ||
Nodes nodes; | ||
|
||
auto it = tokens.begin(); | ||
while (it->kind == TokenKind::AtSymbol) { | ||
++it; | ||
// Parse the tokens | ||
switch (it->kind) { | ||
case TokenKind::EnumKeyword: | ||
nodes.enums.push_back(EnumNode::Parser(it)); | ||
break; | ||
case TokenKind::ClassKeyword: | ||
nodes.classes.push_back(ClassNode::Parser(it)); | ||
break; | ||
case TokenKind::FunctionKeyword: | ||
nodes.functions.push_back(FunctionNode::Parser(it)); | ||
break; | ||
case TokenKind::VariantKeyword: { | ||
for (auto res : VariantBaseNode::Parser(it)) { | ||
nodes.function_variants[res->functionName].push_back(res); | ||
} | ||
break; | ||
} | ||
case TokenKind::TestGroupKeyword: { | ||
auto res = TestGroupNode::Parser(it); | ||
nodes.function_test_groups[res->functionName].push_back(res); | ||
break; | ||
} | ||
case TokenKind::ClientKeyword: | ||
nodes.clients.push_back(LLMClientNode::Parser(it)); | ||
break; | ||
default: | ||
throw SyntaxError(*it, "Unexpected token: " + it->value); | ||
} | ||
} | ||
if (it->kind != TokenKind::Eof) { | ||
throw SyntaxError(*it, "Did you forget @? Got: " + it->value); | ||
} | ||
return nodes; | ||
} | ||
} // namespace gloo::AST |
Oops, something went wrong.