-
Notifications
You must be signed in to change notification settings - Fork 2
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
Showing
8 changed files
with
258 additions
and
313 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,25 @@ | ||
// Permutation | ||
|
||
struct Human { | ||
actions: Vec<Action> | ||
} | ||
|
||
enum Action { | ||
Eat(Food), | ||
Sleep, | ||
Code, | ||
} | ||
|
||
/* VS */ | ||
|
||
// Combination | ||
|
||
struct Human { | ||
actions: HumanActions | ||
} | ||
|
||
struct HumanActions { | ||
eat: Food, | ||
sleep: bool, | ||
code: bool, | ||
} |
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 |
---|---|---|
@@ -1,29 +1,28 @@ | ||
macro_rules! generate_backends { | ||
($($name:ident),*) => { | ||
struct Backends { | ||
$( | ||
pub $name: bool, | ||
)* | ||
} | ||
}; | ||
($($name:ident),*,) => { | ||
generate_backends!($($name),*); | ||
}; | ||
() => { | ||
compile_error!("This macro requires at least one argument") | ||
}; | ||
} | ||
|
||
/// SPM backends | ||
generate_backends!( | ||
brew, | ||
choco, | ||
dpkg, | ||
flatpak, | ||
pacman, | ||
rpm, | ||
scoop, | ||
snap, | ||
zypper, | ||
); | ||
// macro_rules! generate_backends { | ||
// ($($name:ident),*) => { | ||
// struct Backends { | ||
// $( | ||
// pub $name: bool, | ||
// )* | ||
// } | ||
// }; | ||
// ($($name:ident),*,) => { | ||
// generate_backends!($($name),*); | ||
// }; | ||
// () => { | ||
// compile_error!("This macro requires at least one argument") | ||
// }; | ||
// } | ||
|
||
// /// SPM backends | ||
// generate_backends!( | ||
// brew, | ||
// choco, | ||
// dpkg, | ||
// flatpak, | ||
// pacman, | ||
// rpm, | ||
// scoop, | ||
// snap, | ||
// zypper, | ||
// ); |
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 |
---|---|---|
@@ -1,19 +1,5 @@ | ||
pub mod pm; | ||
pub mod spm; | ||
pub mod error; | ||
pub mod mir; | ||
pub mod pm; | ||
pub mod raw_args; | ||
|
||
pub fn add(left: usize, right: usize) -> usize { | ||
left + right | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[test] | ||
fn it_works() { | ||
let result = add(2, 2); | ||
assert_eq!(result, 4); | ||
} | ||
} | ||
pub mod spm; |
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,42 @@ | ||
use crate::pm::PackageManager; | ||
|
||
/// List of actions that GENE can infer | ||
#[derive(Debug, Clone, Copy)] | ||
pub enum GeneMIRActions { | ||
Install, | ||
Remove, | ||
Query, | ||
Update, | ||
} | ||
|
||
/// GENE Middle Intermediate Representation | ||
/// | ||
/// Abstraction to make it easier to transpile between different package managers. | ||
/// Just like how LLVM IR works but dead simple. | ||
pub struct GeneMIR<'a> { | ||
/// Package Manager backend to use | ||
package_manager: PackageManager, | ||
/// Options that get transpiled | ||
actions: Vec<GeneMIRActions>, | ||
/// Non-transpiled Options | ||
raw_actions: Vec<&'a str>, | ||
} | ||
|
||
impl<'a> GeneMIR<'a> { | ||
pub fn new(package_manager: PackageManager) -> Self { | ||
GeneMIR { | ||
package_manager, | ||
actions: Default::default(), | ||
raw_actions: Default::default(), | ||
} | ||
} | ||
pub fn actions(mut self, actions: Vec<GeneMIRActions>) -> Self { | ||
self.actions.extend(actions); | ||
self | ||
} | ||
|
||
pub fn raw_actions(mut self, raw_actions: Vec<&'a str>) -> Self { | ||
self.raw_actions.extend(raw_actions); | ||
self | ||
} | ||
} |
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 |
---|---|---|
@@ -1,6 +1,47 @@ | ||
use gene_utils::args::GeneArgs; | ||
use std::mem::size_of_val; | ||
|
||
pub trait PackageManager<'a>: TryFrom<&'a GeneArgs> { | ||
/// Convert Middle Representation (Self) to String | ||
fn compile(&'a self) -> String; | ||
} | ||
pub struct PackageManagerArgs<'a> { | ||
package_manager: &'a str, | ||
args: &'a [&'a str], | ||
} | ||
|
||
/// List of supported package manager backends | ||
pub enum PackageManager { | ||
APT, | ||
Pacman, | ||
} | ||
|
||
impl ToString for PackageManager { | ||
fn to_string(&self) -> String { | ||
use PackageManager::*; | ||
|
||
let pm_name = match self { | ||
APT => "apt", | ||
Pacman => "pacman", | ||
}; | ||
|
||
pm_name.to_string() | ||
} | ||
} | ||
|
||
impl<'a> PackageManagerArgs<'a> { | ||
pub fn new(package_manager: &'a str, args: &'a [&'a str]) -> Self { | ||
Self { | ||
package_manager, | ||
args, | ||
} | ||
} | ||
} | ||
|
||
impl ToString for PackageManagerArgs<'_> { | ||
fn to_string(&self) -> String { | ||
let mut cmd: Vec<&str> = Vec::with_capacity( | ||
size_of_val(self.args) + size_of_val(self.package_manager) + self.args.len(), // allocate enough memory to fit package manager name, arguments and spaces between both of them. | ||
); | ||
|
||
cmd.push(self.package_manager); | ||
cmd.extend_from_slice(self.args); | ||
|
||
cmd.join(" ") | ||
} | ||
} |
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 |
---|---|---|
@@ -1,19 +1 @@ | ||
/// Read-only wrapper for the raw arguments passed to the program. | ||
#[derive(Debug)] | ||
pub struct RawArgs<'a> { | ||
pub args: &'a Vec<String>, | ||
} | ||
|
||
impl<'a> From<&'a Vec<String>> for RawArgs<'a> { | ||
#[inline(always)] | ||
fn from(args: &'a Vec<String>) -> Self { | ||
Self { args } | ||
} | ||
} | ||
|
||
impl ToString for RawArgs<'_> { | ||
#[inline(always)] | ||
fn to_string(&self) -> String { | ||
self.args.join(" ") | ||
} | ||
} |
Oops, something went wrong.