Skip to content

Commit

Permalink
Add tuples
Browse files Browse the repository at this point in the history
  • Loading branch information
nezuo committed Nov 24, 2024
1 parent 93543cc commit 7e4e936
Show file tree
Hide file tree
Showing 12 changed files with 357 additions and 140 deletions.
6 changes: 3 additions & 3 deletions zap/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ impl std::fmt::Display for YieldType {
pub struct FnDecl<'src> {
pub name: &'src str,
pub call: FnCall,
pub args: Option<Ty<'src>>,
pub rets: Option<Ty<'src>>,
pub args: Option<Vec<Ty<'src>>>,
pub rets: Option<Vec<Ty<'src>>>,
pub id: usize,
}

Expand All @@ -93,7 +93,7 @@ pub struct EvDecl<'src> {
pub from: EvSource,
pub evty: EvType,
pub call: EvCall,
pub data: Option<Ty<'src>>,
pub data: Option<Vec<Ty<'src>>>,
pub id: usize,
}

Expand Down
20 changes: 16 additions & 4 deletions zap/src/irgen/des.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,20 @@ impl Gen for Des {
self.buf.push(stmt);
}

fn gen(mut self, var: Var, ty: &Ty) -> Vec<Stmt> {
self.push_ty(ty, var);
fn gen(mut self, var: Var, types: &[Ty]) -> Vec<Stmt> {
for (i, ty) in types.iter().enumerate() {
let var = if i > 0 {
Var::Name(match &var {
Var::Name(name) => format!("{name}{}", i + 1),
_ => unreachable!(),
})
} else {
var.clone()
};

self.push_ty(ty, var);
}

self.buf
}

Expand Down Expand Up @@ -419,11 +431,11 @@ impl Des {
}
}

pub fn gen(ty: &Ty, var: &str, checks: bool) -> Vec<Stmt> {
pub fn gen(types: &[Ty], var: &str, checks: bool) -> Vec<Stmt> {
Des {
checks,
buf: vec![],
var_occurrences: HashMap::new(),
}
.gen(var.into(), ty)
.gen(var.into(), types)
}
2 changes: 1 addition & 1 deletion zap/src/irgen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub mod ser;

pub trait Gen {
fn push_stmt(&mut self, stmt: Stmt);
fn gen(self, var: Var, ty: &Ty<'_>) -> Vec<Stmt>;
fn gen(self, var: Var, types: &[Ty]) -> Vec<Stmt>;

fn push_local(&mut self, name: String, expr: Option<Expr>) {
self.push_stmt(Stmt::Local(name, expr))
Expand Down
20 changes: 16 additions & 4 deletions zap/src/irgen/ser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,20 @@ impl Gen for Ser {
self.buf.push(stmt);
}

fn gen(mut self, var: Var, ty: &Ty) -> Vec<Stmt> {
self.push_ty(ty, var);
fn gen(mut self, var: Var, types: &[Ty]) -> Vec<Stmt> {
for (i, ty) in types.iter().enumerate() {
let var = if i > 0 {
Var::Name(match &var {
Var::Name(name) => format!("{name}{}", i + 1),
_ => unreachable!(),
})
} else {
var.clone()
};

self.push_ty(ty, var);
}

self.buf
}

Expand Down Expand Up @@ -357,11 +369,11 @@ impl Ser {
}
}

pub fn gen(ty: &Ty, var: &str, checks: bool) -> Vec<Stmt> {
pub fn gen(types: &[Ty], var: &str, checks: bool) -> Vec<Stmt> {
Ser {
checks,
buf: vec![],
var_occurrences: HashMap::new(),
}
.gen(var.into(), ty)
.gen(var.into(), types)
}
Loading

0 comments on commit 7e4e936

Please sign in to comment.