Skip to content

Commit

Permalink
Remove redundant index type from Expr::For (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
samestep authored Aug 7, 2023
1 parent bfd6253 commit e5a34e8
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 27 deletions.
4 changes: 1 addition & 3 deletions crates/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,7 @@ pub enum Expr {
args: Box<[id::Var]>,
},
For {
/// Must satisfy `Constraint::Index`.
index: id::Ty,
/// has type `index`.
/// Type must satisfy `Constraint::Index`.
arg: id::Var,
body: Box<[Instr]>,
/// Variable from `body` holding an array element.
Expand Down
1 change: 0 additions & 1 deletion crates/frontend/src/translate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,6 @@ impl<'input, 'a> BlockCtx<'input, 'a> {
Ok(self.instr(
v,
ir::Expr::For {
index: i,
arg,
body,
ret: elem,
Expand Down
9 changes: 2 additions & 7 deletions crates/interp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,13 +231,8 @@ impl<'a, F: FuncNode> Interpreter<'a, F> {
let vals = args.iter().map(|id| self.vars[id.var()].clone().unwrap());
call(self.f.get(*id).unwrap(), self.typemap, &resolved, vals)
}
Expr::For {
index,
arg,
body,
ret,
} => {
let n = match self.typemap[self.types[index.ty()].ty()] {
Expr::For { arg, body, ret } => {
let n = match self.typemap[self.types[self.f.def().vars[arg.var()].ty()].ty()] {
Ty::Fin { size } => size,
_ => unreachable!(),
};
Expand Down
24 changes: 8 additions & 16 deletions crates/web/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,13 @@ pub fn pprint(f: &Func) -> Result<String, JsError> {
print_elems(s, 'x', args.iter().map(|arg| arg.var()))?;
writeln!(&mut s, ")")?;
}
rose::Expr::For {
index,
arg,
body,
ret,
} => {
writeln!(&mut s, "for x{}: T{} {{", arg.var(), index.ty())?;
rose::Expr::For { arg, body, ret } => {
writeln!(
&mut s,
"for x{}: T{} {{",
arg.var(),
def.vars[arg.var()].ty()
)?;
print_block(s, def, spaces + 2, body, *ret)?;
for _ in 0..spaces {
write!(&mut s, " ")?;
Expand Down Expand Up @@ -768,22 +768,14 @@ impl Context {

// `rose::Expr::For`
#[wasm_bindgen]
pub fn arr(
&mut self,
b: &mut Block,
index: usize,
arg: usize,
body: Block,
out: usize,
) -> usize {
pub fn arr(&mut self, b: &mut Block, arg: usize, body: Block, out: usize) -> usize {
let arg = id::var(arg);
let ret = id::var(out);
let ty = self.ty(rose::Ty::Array {
index: self.get(arg),
elem: self.get(ret),
});
let expr = rose::Expr::For {
index: id::ty(index),
arg,
body: body.code.into(),
ret,
Expand Down

0 comments on commit e5a34e8

Please sign in to comment.