Skip to content

Commit

Permalink
feat: implement :comp columns
Browse files Browse the repository at this point in the history
  • Loading branch information
delehef committed Nov 17, 2023
1 parent 65e2008 commit 1660b55
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/compiler/definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ fn reduce(e: &AstNode, ctx: &mut Scope) -> Result<()> {
.kind(match kind {
Kind::Atomic => Kind::Atomic,
Kind::Phantom => Kind::Phantom,
Kind::Composite(_) => Kind::Phantom,
Kind::Computed(_) => Kind::Phantom,
})
.and_padding_value(*padding_value)
.t(t.m())
Expand Down
7 changes: 4 additions & 3 deletions src/compiler/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,8 @@ impl ConstraintSet {
{
match c {
Computation::Interleaved { target, .. }
| Computation::CyclicFrom { target, .. } => {
| Computation::CyclicFrom { target, .. }
| Computation::Composite { target, .. } => {
let col = self.columns.column(&target).unwrap();
let reg = self.columns.new_register(col.handle.clone(), col.t);
self.columns.assign_register(&target, reg).unwrap();
Expand Down Expand Up @@ -1511,11 +1512,11 @@ pub fn reduce(e: &AstNode, ctx: &mut Scope, settings: &CompileSettings) -> Resul
kind: k,
..
} => match k {
Kind::Composite(e) => {
Kind::Computed(e) => {
let n = reduce(e, ctx, settings)?.unwrap();
ctx.edit_symbol(name, &|x| {
if let Expression::Column { kind, .. } = x {
*kind = Kind::Composite(Box::new(n.clone()))
*kind = Kind::Computed(Box::new(n.clone()))
}
})?;
Ok(None)
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ pub fn make<S1: AsRef<str>, S2: AsRef<str>>(
let id = columns.insert_column(column)?;
match k {
Kind::Atomic | Kind::Phantom => (),
Kind::Composite(e) => computations
Kind::Computed(e) => computations
.insert(
&id,
Computation::Composite {
Expand Down
15 changes: 11 additions & 4 deletions src/compiler/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,14 @@ pub enum Kind<T> {
Phantom,
/// a composite column is similar to a phantom column, but the expression
/// computing it is known
Composite(Box<T>),
Computed(Box<T>),
}
impl<T> Kind<T> {
pub fn to_nil(&self) -> Kind<()> {
match self {
Kind::Atomic => Kind::Atomic,
Kind::Phantom => Kind::Phantom,
Kind::Composite(_) => Kind::Composite(Box::new(())),
Kind::Computed(_) => Kind::Computed(Box::new(())),
}
}
}
Expand Down Expand Up @@ -618,6 +618,7 @@ struct ColumnAttributes {
range: OnceCell<Domain>,
padding_value: OnceCell<i64>,
base: OnceCell<Base>,
computation: Option<AstNode>,
}

impl std::convert::TryInto<DisplayableColumn> for ColumnAttributes {
Expand Down Expand Up @@ -731,7 +732,10 @@ fn parse_column_attributes(source: AstNode) -> Result<ColumnAttributes> {
})?;
ColumnParser::Begin
}
ColumnParser::Computation => todo!(),
ColumnParser::Computation => {
attributes.computation = Some(x);
ColumnParser::Begin
}
ColumnParser::PaddingValue => {
attributes.padding_value.set(x.as_i64()?).map_err(|_| {
anyhow!(
Expand Down Expand Up @@ -808,7 +812,10 @@ fn parse_defcolumns<I: Iterator<Item = Result<AstNode>>>(
.cloned()
.unwrap_or(Magma::native()),
),
kind: Kind::Atomic,
kind: column_attributes
.computation
.map(|c| Kind::Computed(Box::new(c)))
.unwrap_or(Kind::Atomic),
padding_value: column_attributes.padding_value.get().cloned(),
base,
}
Expand Down
2 changes: 1 addition & 1 deletion src/transformer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ fn validate_computation(cs: &mut Vec<Node>, x_expr: &Node, x_col: &Handle) {
x_expr.clone(),
Node::column()
.handle(x_col.to_owned())
.kind(Kind::Composite(Box::new(x_expr.clone())))
.kind(Kind::Computed(Box::new(x_expr.clone())))
.t(Magma::native())
.build(),
])
Expand Down
2 changes: 1 addition & 1 deletion src/transformer/inverses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ impl ConstraintSet {
let inverted_id = self.columns.insert_column_and_register(
Column::builder()
.handle(inverted_handle.clone())
.kind(Kind::Composite(Box::new(())))
.kind(Kind::Computed(Box::new(())))
.build(),
)?;

Expand Down
2 changes: 1 addition & 1 deletion src/transformer/splatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ impl ConstraintSet {
.handle(new_handle.to_owned())
.t(new_magma)
.base(Base::Hex)
.kind(Kind::Composite(Box::new(())))
.kind(Kind::Computed(Box::new(())))
.build(),
)
.unwrap();
Expand Down

0 comments on commit 1660b55

Please sign in to comment.