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

Remove redundant index type from Expr::For #66

Merged
merged 1 commit into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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