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

[fud2] Additional Syntax to Rhai DSL #2203

Merged
merged 33 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
9f7782c
create function to begin listening for op body
jku20 Jul 9, 2024
1c9afbd
implement adding shells to builds
jku20 Jul 10, 2024
e9fe9e9
add function to emit built op
jku20 Jul 10, 2024
11d7efe
add custom syntax for defining op using shell
jku20 Jul 11, 2024
e0844a1
implement config and config_or
jku20 Jul 11, 2024
155412e
read configs from cli
jku20 Jul 11, 2024
b35bb30
change syntax for shell to #ident
jku20 Jul 11, 2024
4e791c6
Merge branch 'main' into fud2-rhai-rework
jku20 Jul 11, 2024
ed1e7e3
tiny bug fixes
jku20 Jul 12, 2024
71c122b
remove config_data field from driver
jku20 Jul 16, 2024
5ce36a3
use ninja varaibles for input/output files
jku20 Jul 16, 2024
ad8f279
rewrite axi and calyx scripts
jku20 Jul 16, 2024
58f0772
Merge branch 'fud2-rhai-rework' into rud2-rhai-scripts-rewrite
jku20 Jul 16, 2024
d155cd7
use variables instead of hardcoding names
jku20 Jul 18, 2024
34e38fc
factor out genation of ninja varaibles name
jku20 Jul 18, 2024
5611817
replace closure with struct
jku20 Jul 18, 2024
54ce0dc
name tuple fields
jku20 Jul 18, 2024
2e91948
rename OpSig
jku20 Jul 18, 2024
41c98af
improve docs
jku20 Jul 18, 2024
0475ce8
use Ninja variables for configs
jku20 Jul 19, 2024
18f2bba
revert rhai scripts
jku20 Jul 19, 2024
9206e32
revert calyx.rhai
jku20 Jul 25, 2024
2fc8e22
add function for testing rhai scripts
jku20 Jul 26, 2024
890d918
add enumerate planner
jku20 Jul 29, 2024
346bc26
bug fix and tests
jku20 Jul 29, 2024
838bcb6
add basic tests for config and config_or
jku20 Jul 29, 2024
6b03030
improve name and doc of struct for emiting ops
jku20 Aug 2, 2024
2e4e92d
being wishy-washy on names
jku20 Aug 2, 2024
be95dcf
name clarification and improved docs
jku20 Aug 2, 2024
b59bc02
improve docs for build_cmd_with_vars
jku20 Aug 2, 2024
4a24316
more name bikesheadding
jku20 Aug 2, 2024
5111ad6
more improvements to build_cmd_with_args
jku20 Aug 2, 2024
2e4357b
Merge branch 'main' into fud2-rhai-rework
jku20 Aug 5, 2024
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
36 changes: 22 additions & 14 deletions fud2/fud-core/src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::config;
use crate::exec::{
Driver, EnumeratePlanner, Request, SingleOpOutputPlanner, StateRef,
};
use crate::run::Run;
use crate::{config, DriverBuilder};
use anyhow::{anyhow, bail};
use argh::FromArgs;
use camino::Utf8PathBuf;
Expand Down Expand Up @@ -280,6 +280,27 @@ fn get_resource(driver: &Driver, cmd: GetResource) -> anyhow::Result<()> {
bail!("unknown resource file {}", cmd.filename);
}

pub fn override_config_from_cli(
mut builder: DriverBuilder,
) -> anyhow::Result<DriverBuilder> {
let args: FakeArgs = argh::from_env();

// Use `--set` arguments to override configuration values.
for set in args.set {
let mut parts = set.splitn(2, '=');
let key = parts.next().unwrap();
let value = parts
.next()
.ok_or(anyhow!("--set arguments must be in key=value form"))?;
let dict = figment::util::nest(key, value.into());
builder.config_data = builder
.config_data
.merge(figment::providers::Serialized::defaults(dict));
}

Ok(builder)
}

pub fn cli(driver: &Driver) -> anyhow::Result<()> {
let args: FakeArgs = argh::from_env();

Expand Down Expand Up @@ -321,19 +342,6 @@ pub fn cli(driver: &Driver) -> anyhow::Result<()> {
run.global_config.verbose = verbose;
}

// Use `--set` arguments to override configuration values.
for set in args.set {
let mut parts = set.splitn(2, '=');
let key = parts.next().unwrap();
let value = parts
.next()
.ok_or(anyhow!("--set arguments must be in key=value form"))?;
let dict = figment::util::nest(key, value.into());
run.config_data = run
.config_data
.merge(figment::providers::Serialized::defaults(dict));
}

// Execute.
match args.mode {
Mode::ShowPlan => run.show(),
Expand Down
4 changes: 4 additions & 0 deletions fud2/fud-core/src/exec/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub struct Driver {
pub ops: PrimaryMap<OpRef, Operation>,
pub rsrc_dir: Option<Utf8PathBuf>,
pub rsrc_files: Option<FileData>,
pub config_data: figment::Figment,
jku20 marked this conversation as resolved.
Show resolved Hide resolved
}

impl Driver {
Expand Down Expand Up @@ -271,6 +272,7 @@ pub struct DriverBuilder {
rsrc_files: Option<FileData>,
scripts_dir: Option<Utf8PathBuf>,
script_files: Option<FileData>,
pub config_data: figment::Figment,
}

#[derive(Debug)]
Expand Down Expand Up @@ -305,6 +307,7 @@ impl DriverBuilder {
rsrc_files: None,
scripts_dir: None,
script_files: None,
config_data: config::load_config(name),
}
}

Expand Down Expand Up @@ -465,6 +468,7 @@ impl DriverBuilder {
ops: self.ops,
rsrc_dir: self.rsrc_dir,
rsrc_files: self.rsrc_files,
config_data: self.config_data,
}
}
}
Expand Down
17 changes: 15 additions & 2 deletions fud2/fud-core/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,20 @@ impl EmitBuild for EmitBuildFn {
}
}

pub type EmitBuildClosure =
Box<dyn Fn(&mut StreamEmitter, &[&str], &[&str]) -> EmitResult>;
jku20 marked this conversation as resolved.
Show resolved Hide resolved

impl EmitBuild for EmitBuildClosure {
fn build(
&self,
emitter: &mut StreamEmitter,
input: &[&str],
output: &[&str],
) -> EmitResult {
self(emitter, input, output)
}
jku20 marked this conversation as resolved.
Show resolved Hide resolved
}

// TODO make this unnecessary...
/// A simple `build` emitter that just runs a Ninja rule.
pub struct EmitRuleBuild {
Expand Down Expand Up @@ -127,8 +141,7 @@ pub struct Run<'a> {

impl<'a> Run<'a> {
pub fn new(driver: &'a Driver, plan: Plan) -> Self {
let config_data = config::load_config(&driver.name);
Self::with_config(driver, plan, config_data)
Self::with_config(driver, plan, driver.config_data.clone())
jku20 marked this conversation as resolved.
Show resolved Hide resolved
}

pub fn with_config(
Expand Down
53 changes: 50 additions & 3 deletions fud2/fud-core/src/script/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,48 @@ pub(super) struct RhaiSystemError {

#[derive(Debug)]
pub(super) enum RhaiSystemErrorKind {
ErrorSetupRef(String),
SetupRef(String),
StateRef(String),
BeganOp(String, String),
NoOp,
ConfigNotFound(String),
}

impl RhaiSystemError {
pub(super) fn setup_ref(v: rhai::Dynamic) -> Self {
Self {
kind: RhaiSystemErrorKind::ErrorSetupRef(v.to_string()),
kind: RhaiSystemErrorKind::SetupRef(v.to_string()),
position: rhai::Position::NONE,
}
}

pub(super) fn state_ref(v: rhai::Dynamic) -> Self {
Self {
kind: RhaiSystemErrorKind::StateRef(v.to_string()),
position: rhai::Position::NONE,
}
}

pub(super) fn began_op(old_name: &str, new_name: &str) -> Self {
Self {
kind: RhaiSystemErrorKind::BeganOp(
old_name.to_string(),
new_name.to_string(),
),
position: rhai::Position::NONE,
}
}

pub(super) fn no_op() -> Self {
Self {
kind: RhaiSystemErrorKind::NoOp,
position: rhai::Position::NONE,
}
}

pub(super) fn config_not_found(key: &str) -> Self {
Self {
kind: RhaiSystemErrorKind::ConfigNotFound(key.to_string()),
position: rhai::Position::NONE,
}
}
Expand All @@ -30,9 +65,21 @@ impl RhaiSystemError {
impl Display for RhaiSystemError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match &self.kind {
RhaiSystemErrorKind::ErrorSetupRef(v) => {
RhaiSystemErrorKind::SetupRef(v) => {
write!(f, "Unable to construct SetupRef: `{v:?}`")
}
RhaiSystemErrorKind::StateRef(v) => {
write!(f, "Unable to construct StateRef: `{v:?}`")
}
RhaiSystemErrorKind::BeganOp(old_name, new_name) => {
write!(f, "Unable to build two ops at once: trying to build `{new_name:?}` but already building `{old_name:?}`")
}
RhaiSystemErrorKind::NoOp => {
write!(f, "Unable to find current op being built. Consider calling start_op_stmts earlier in the program.")
}
RhaiSystemErrorKind::ConfigNotFound(v) => {
write!(f, "Unable to find config value: `{v:?}`")
}
}
}
}
Expand Down
Loading
Loading