chore(treewide): Move the trixy subcrates under one trixy crate

This commit is contained in:
Benedikt Peetz 2023-12-26 12:14:08 +01:00
parent 7d1a41aca9
commit 21e1b75193
Signed by: bpeetz
GPG Key ID: A5E94010C3A642AD
58 changed files with 204 additions and 193 deletions

View File

@ -23,11 +23,6 @@ version = "0.1.0"
edition = "2021"
[dependencies]
convert_case = "0.6.0"
log = "0.4.20"
proc-macro2 = "1.0.70"
quote = "1.0.33"
syn = { version = "2.0.41", features = ["extra-traits", "full", "parsing"] }
thiserror = "1.0.51"
# trixy-lang_parser = { path = "./trixy-lang_parser" }
# trixy-macros = { path = "./trixy-macros" }
trixy-parser = { path = "./trixy-parser" }
trixy-macros = { path = "./trixy-macros" }
trixy-types = { path = "./trixy-types" }

View File

@ -1,44 +1,7 @@
/*
* Copyright (C) 2023 The Trinitrix Project <soispha@vhack.eu, antifallobst@systemausfall.org>
*
* This file is part of the Trixy crate for Trinitrix.
*
* Trixy is free software: you can redistribute it and/or modify
* it under the terms of the Lesser 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
* and the Lesser GNU General Public License along with this program.
* If not, see <https://www.gnu.org/licenses/>.
*/
//! Trixy contains the types used by the [trixy-macros] crate to provide ffi safe types
use std::{ffi::c_char, ops::Deref};
use proc_macro2::TokenStream;
use quote::quote;
pub mod error;
pub mod traits;
// NOTE(@soispha): All types specified here *MUST* be include in the BASE_TYPES constant, otherwise
// they are not usable from Trixy code <2023-12-25>
#[repr(C)]
pub struct String(*const c_char);
/// These are the "primitive" types used in Trixy, you can use any of them to create new structures
pub const BASE_TYPES: [&'static str; 2] = ["String", "u8"];
pub fn to_c_name<T: Deref<Target = str>>(rust_type: T) -> TokenStream {
match &*rust_type {
"String" => quote!(const char*),
other => panic! {"'{}' is not a vaild type name!", other},
}
mod types {
pub use trixy_types::*;
}
mod macros {
pub use trixy_macros::*;
}

View File

@ -28,5 +28,5 @@ prettyplease = "0.2.15"
proc-macro2 = "1.0.70"
quote = "1.0.33"
syn = { version = "2.0.41", features = ["extra-traits", "full", "parsing"] }
trixy-lang_parser = { path = "../trixy-lang_parser" }
trixy = { path = "../../trixy" }
trixy-parser = { path = "../trixy-parser" }
trixy-types = { path = "../trixy-types" }

View File

@ -3,5 +3,9 @@
/result
/dist
# C stuff
*.d
*.o
# This crate is a library
Cargo.lock

View File

@ -23,13 +23,14 @@ version = "0.0.0"
publish = false
edition = "2021"
[lib]
crate-type = ["cdylib"]
# [lib]
# crate-type = ["cdylib"]
[dependencies]
trixy = { path = "../../../../trixy" }
env_logger = { version = "0.10.1" }
log = "0.4.20"
libloading = "0.8.1"
[build-dependencies]
trixy-macros = {path = "../../../trixy-macros"}

View File

@ -0,0 +1,35 @@
PREFIX := /usr/local
BINPREFIX := $(DESTDIR)$(PREFIX)/bin
MANPREFIX := $(DESTDIR)$(PREFIX)/share/man/man1
BIN_NAME := libmain.so
SRC := $(wildcard c_src/*.c)
OBJ := $(SRC:.c=.o)
DEP := $(OBJ:.o=.d)
LIBS := main-example
ALL_CFLAGS := -fPIC -O3 -MMD -Wall -Wextra -Wno-unused-parameter $(CFLAGS) $(CPPFLAGS)
ALL_LDFLAGS := -shared $(addprefix -l,$(LIBS)) -L $(LD_LIBRARY_PATH) $(CFLAGS) $(LDFLAGS)
$(BIN_NAME): $(OBJ)
$(CC) -o $@ $+ $(ALL_LDFLAGS)
.c.o:
$(CC) -o $@ $< -c $(ALL_CFLAGS)
.PHONY : clean options
options:
@echo "CC = $(CC)"
@echo "CFLAGS = $(ALL_CFLAGS)"
@echo "LDFLAGS = $(ALL_LDFLAGS)"
@echo "SRC = $(SRC)"
@echo "OBJ = $(OBJ)"
@echo "DEP = $(DEP)"
@echo ""
clean :
rm $(BIN_NAME) $(OBJ) $(DEP)

View File

@ -18,10 +18,10 @@
* If not, see <https://www.gnu.org/licenses/>.
*/
use trixy_macros::config::TrixyConfig;
fn main() {
println!("cargo:rustc-link-arg=--relocatable");
println!("cargo:rerun-if-changed=./src/api.tri");
TrixyConfig::new("callback")
.trixy_path("./src/api.tri")

View File

@ -1,35 +1,37 @@
/*
* Copyright (C) 2023 The Trinitrix Project <soispha@vhack.eu, antifallobst@systemausfall.org>
*
* This file is part of the Trixy crate for Trinitrix.
*
* Trixy is free software: you can redistribute it and/or modify
* it under the terms of the Lesser 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
* and the Lesser GNU General Public License along with this program.
* If not, see <https://www.gnu.org/licenses/>.
*/
* Copyright (C) 2023 The Trinitrix Project <soispha@vhack.eu,
* antifallobst@systemausfall.org>
*
* This file is part of the Trixy crate for Trinitrix.
*
* Trixy is free software: you can redistribute it and/or modify
* it under the terms of the Lesser 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
* and the Lesser GNU General Public License along with this program.
* If not, see <https://www.gnu.org/licenses/>.
*/
#include "../dist/interface.h"
#include <stdio.h>
#include <stdlib.h>
typedef struct {
int two;
} a_t;
int main(void) {
// You can simply call functions ..
fn_alone("hi");
// .. but they check their inputs:
// This call for example will fail, as a null pointer isn't supported.
//
// A error will be signaled by a 0 return code, then the error can be obtained
// with the `last_error_length` and `last_error_message` functions
if (!fn_alone(0x0)) {
int error_length = last_error_length();
char *error = malloc(error_length);

View File

@ -0,0 +1 @@
/home/soispha/repos/rust/trinitrix/trixy/trixy-lang_parser/example/full.tri

View File

@ -1,30 +0,0 @@
/*
* Copyright (C) 2023 The Trinitrix Project <soispha@vhack.eu, antifallobst@systemausfall.org>
*
* This file is part of the Trixy crate for Trinitrix.
*
* Trixy is free software: you can redistribute it and/or modify
* it under the terms of the Lesser 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
* and the Lesser GNU General Public License along with this program.
* If not, see <https://www.gnu.org/licenses/>.
*/
macro_rules! callback {
($cmd:expr) => {{
println!("{:#?}", $cmd);
}};
}
include!(concat!(env!("OUT_DIR"), "/api.rs"));

View File

@ -18,8 +18,21 @@
* If not, see <https://www.gnu.org/licenses/>.
*/
use std::ffi::c_int;
macro_rules! callback {
($cmd:expr) => {{
println!("{:#?}", $cmd);
}};
}
include!(concat!(env!("OUT_DIR"), "/api.rs"));
fn main() {
let input = include_str!(concat!(env!("OUT_DIR"), "/interface.h"));
println!("{}", input);
let out = unsafe {
let lib = libloading::Library::new("./libmain.so").unwrap();
let func: libloading::Symbol<unsafe extern "C" fn() -> c_int> = lib.get(b"main").unwrap();
func()
};
assert_eq!(out, 0);
}

View File

@ -18,9 +18,6 @@
* If not, see <https://www.gnu.org/licenses/>.
*/
//! This module is responsible for the config passed to trixy.
//! It works using the popular builder syntax:
//! ```no_run
@ -34,7 +31,7 @@
//!# }
//! ```
use std::path::{Path, PathBuf};
use std::path::PathBuf;
#[derive(Debug)]
pub enum Language {

View File

@ -18,14 +18,13 @@
* If not, see <https://www.gnu.org/licenses/>.
*/
//! This module generates the c header
//! It works by firstly listing the functions and then by grouping them into structures, effectively
//! simulating namespaces in c.
use proc_macro2::{Ident, Punct, Spacing, TokenStream as TokenStream2};
use proc_macro2::TokenStream as TokenStream2;
use quote::{format_ident, quote};
use trixy_lang_parser::command_spec::{
use trixy_parser::command_spec::{
Attribute, CommandSpec, Function, Identifier, NamedType, Namespace,
};
@ -122,7 +121,7 @@ pub fn generate(trixy: &CommandSpec, _config: &TrixyConfig) -> String {
format!(
"{}\n\n{}\n\n{}\n{}\n{}\n{}\n\n{}",
BEGIN_HEADER_GUARD,
trixy::traits::errno::ERROR_FUNCTIONS,
trixy_types::traits::errno::ERROR_FUNCTIONS,
functions,
namespaces,
type_defs,
@ -154,7 +153,7 @@ fn attribute_to_doc_comment(attribute: &Attribute) -> String {
fn named_type_to_c(named_type: &NamedType) -> TokenStream2 {
let ident = identifier_to_rust(&named_type.name);
let r#type = type_to_rust(&named_type.r#type);
let c_type = trixy::to_c_name(r#type.to_string());
let c_type = trixy_types::to_c_name(r#type.to_string());
quote! {
#c_type #ident
}

View File

@ -18,11 +18,10 @@
* If not, see <https://www.gnu.org/licenses/>.
*/
use convert_case::{Case, Casing};
use proc_macro2::TokenStream as TokenStream2;
use quote::{format_ident, quote};
use trixy_lang_parser::command_spec::{CommandSpec, Function, Identifier, NamedType, Namespace};
use trixy_parser::command_spec::{CommandSpec, Function, Identifier, NamedType, Namespace};
use crate::{
config::TrixyConfig,

View File

@ -18,10 +18,9 @@
* If not, see <https://www.gnu.org/licenses/>.
*/
use proc_macro2::Ident;
use quote::format_ident;
use trixy_lang_parser::command_spec::{Function, Identifier};
use trixy_parser::command_spec::{Function, Identifier};
pub mod header;
pub mod host;

View File

@ -18,9 +18,6 @@
* If not, see <https://www.gnu.org/licenses/>.
*/
//! This module is responsible for generating the rust code used to interface with the api.
//! That includes the structs and enums declared in the trixy file and the enum used to describe the
//! command being executed.
@ -30,7 +27,7 @@ use std::cell::OnceCell;
use convert_case::{Case, Casing};
use proc_macro2::TokenStream as TokenStream2;
use quote::{format_ident, quote};
use trixy_lang_parser::command_spec::{
use trixy_parser::command_spec::{
Attribute, CommandSpec, DocIdentifier, DocNamedType, Enumeration, Function, Namespace,
Structure,
};

View File

@ -18,12 +18,9 @@
* If not, see <https://www.gnu.org/licenses/>.
*/
use proc_macro2::TokenStream as TokenStream2;
use quote::{format_ident, quote};
use trixy_lang_parser::command_spec::{CommandSpec, Identifier, NamedType, Type};
use trixy_parser::command_spec::{CommandSpec, Identifier, NamedType, Type};
use crate::config::TrixyConfig;

View File

@ -18,12 +18,9 @@
* If not, see <https://www.gnu.org/licenses/>.
*/
use std::{env, fs, io::Write, path::PathBuf, process::Command};
use trixy_lang_parser::parse_trixy_lang;
use trixy_parser::parse_trixy_lang;
use crate::config::TrixyConfig;

View File

@ -18,7 +18,7 @@
[package]
name = "trixy-lang_parser"
name = "trixy-parser"
version = "0.1.0"
edition = "2021"
@ -28,7 +28,7 @@ edition = "2021"
clap = { version = "4.4.11", features = ["derive"], optional = true }
convert_case = "0.6.0"
thiserror = "1.0.50"
trixy = { path = "../../trixy" }
trixy-types = { path = "../trixy-types" }
[dev-dependencies]
pretty_assertions = "1.4.0"

View File

@ -23,5 +23,6 @@
// an empty comment:
//
//
// an empty doc comment:
///
nasp test {}

View File

@ -18,9 +18,6 @@
* If not, see <https://www.gnu.org/licenses/>.
*/
use std::{fs, process::exit};
use trixy_lang_parser::{lexing::TokenStream, parse_trixy_lang};

View File

@ -18,9 +18,6 @@
* If not, see <https://www.gnu.org/licenses/>.
*/
//! This module contains the already type checked types.
use std::fmt::{Display, Write};

View File

@ -18,9 +18,6 @@
* If not, see <https://www.gnu.org/licenses/>.
*/
pub mod checked;
pub mod unchecked;

View File

@ -18,9 +18,6 @@
* If not, see <https://www.gnu.org/licenses/>.
*/
//! This module contains the not type checked types.
//! These are generated on the first pass of the parser, to be later converted into the checked
//! ones.

View File

@ -18,9 +18,6 @@
* If not, see <https://www.gnu.org/licenses/>.
*/
use core::fmt;
use thiserror::Error;

View File

@ -18,9 +18,6 @@
* If not, see <https://www.gnu.org/licenses/>.
*/
use std::{error::Error, fmt::Display};
use thiserror::Error;

View File

@ -18,9 +18,6 @@
* If not, see <https://www.gnu.org/licenses/>.
*/
use std::fmt::Display;
use self::{error::SpannedLexingError, tokenizer::Tokenizer};

View File

@ -18,9 +18,6 @@
* If not, see <https://www.gnu.org/licenses/>.
*/
use crate::lexing::{Keyword, Token, TokenKind, TokenSpan};
use super::TokenStream;

View File

@ -18,9 +18,6 @@
* If not, see <https://www.gnu.org/licenses/>.
*/
// This code is heavily inspired by: https://michael-f-bryan.github.io/static-analyser-in-rust/book/lex.html
use crate::{
@ -170,10 +167,10 @@ fn tokenize_comment(text: &str) -> Result<(TokenKind, usize), LexingError> {
} else {
let text: &str = &text[2..];
if let Some('/') = text.chars().next() {
let text = &text[1..];
if end_of_line(&text) {
Ok((TokenKind::DocComment("".to_owned()), 1 + 3))
} else {
let text = &text[1..];
let (doc_comment, chars_read) = take_while(text, |ch| ch != '\n' && ch != '\r')?;
// trim whitespace

View File

@ -18,9 +18,6 @@
* If not, see <https://www.gnu.org/licenses/>.
*/
use error::TrixyError;
use crate::lexing::TokenStream;

View File

@ -18,9 +18,6 @@
* If not, see <https://www.gnu.org/licenses/>.
*/
use thiserror::Error;
use std::{error::Error, fmt::Display};

View File

@ -18,13 +18,10 @@
* If not, see <https://www.gnu.org/licenses/>.
*/
use std::mem;
use convert_case::{Case, Casing};
use trixy::BASE_TYPES;
use trixy_types::BASE_TYPES;
use crate::{
command_spec::{

View File

@ -18,9 +18,6 @@
* If not, see <https://www.gnu.org/licenses/>.
*/
use crate::command_spec::checked::{
Attribute, CommandSpec, DocIdentifier, DocNamedType, Enumeration, Function, Identifier,
NamedType, Namespace, Structure, Type,

View File

@ -18,8 +18,5 @@
* If not, see <https://www.gnu.org/licenses/>.
*/
pub mod checked;
pub mod unchecked;

View File

@ -18,9 +18,6 @@
* If not, see <https://www.gnu.org/licenses/>.
*/
use std::{error::Error, fmt::Display};
use thiserror::Error;

View File

@ -18,9 +18,6 @@
* If not, see <https://www.gnu.org/licenses/>.
*/
use std::mem;
use crate::{

View File

@ -18,9 +18,6 @@
* If not, see <https://www.gnu.org/licenses/>.
*/
use pretty_assertions::assert_eq;
use crate::{

6
trixy-types/.gitignore vendored Normal file
View File

@ -0,0 +1,6 @@
# build
/target
/result
# This crate is a library
Cargo.lock

31
trixy-types/Cargo.toml Normal file
View File

@ -0,0 +1,31 @@
# Copyright (C) 2023 The Trinitrix Project <soispha@vhack.eu, antifallobst@systemausfall.org>
#
# This file is part of the Trixy crate for Trinitrix.
#
# Trixy is free software: you can redistribute it and/or modify
# it under the terms of the Lesser 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
# and the Lesser GNU General Public License along with this program.
# If not, see <https://www.gnu.org/licenses/>.
[package]
name = "trixy-types"
version = "0.1.0"
edition = "2021"
[dependencies]
convert_case = "0.6.0"
log = "0.4.20"
proc-macro2 = "1.0.70"
quote = "1.0.33"
syn = { version = "2.0.41", features = ["extra-traits", "full", "parsing"] }
thiserror = "1.0.51"

55
trixy-types/src/lib.rs Normal file
View File

@ -0,0 +1,55 @@
/*
* Copyright (C) 2023 The Trinitrix Project <soispha@vhack.eu, antifallobst@systemausfall.org>
*
* This file is part of the Trixy crate for Trinitrix.
*
* Trixy is free software: you can redistribute it and/or modify
* it under the terms of the Lesser 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
* and the Lesser GNU General Public License along with this program.
* If not, see <https://www.gnu.org/licenses/>.
*/
//! Trixy contains the types used by the [trixy-macros] crate to provide ffi safe types
use std::{ffi::c_char, ops::Deref};
use proc_macro2::TokenStream;
use quote::quote;
pub mod error;
pub mod traits;
// NOTE(@soispha): All types specified here *MUST* be include in the BASE_TYPES constant, otherwise
// they are not usable from Trixy code <2023-12-25>
#[repr(C)]
pub struct String(*const c_char);
#[repr(C)]
pub struct Vec<T>(*const T);
#[repr(C)]
pub struct Function(*const usize);
pub type Option<T> = std::option::Option<T>;
/// These are the "primitive" types used in Trixy, you can use any of them to create new structures
pub const BASE_TYPES: [&'static str; 4] = ["String", "Vec", "Option", "Function"];
pub fn to_c_name<T: Deref<Target = str>>(rust_type: T) -> TokenStream {
match &*rust_type {
"String" => quote!(const char*),
"Vec" => quote!(const char**),
// TODO(@soispha): This should show that it's optional <2023-12-25>
"Option<String>" => quote!(const char*),
other => panic! {"'{}' is not a vaild type name!", other},
}
}