Skip to content

Commit

Permalink
switch tuple args to use D1/D2 types
Browse files Browse the repository at this point in the history
  • Loading branch information
cannadayr committed Jan 15, 2022
1 parent c91537d commit 9127bfb
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
4 changes: 2 additions & 2 deletions rs_src/ebqn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fn call1(m: V,f: V) -> Vs {
match m {
V::BlockInst(ref bl,_prim) => {
assert_eq!(1,bl.def.typ);
bl.call_md1(1,(Some(m.clone()),Some(f)))
bl.call_md1(1,D1::new(m.clone(),f))
},
V::R1(_,_prim) => Vs::V(V::D1(Cc::new(D1::new(m,f)),None)),
_ => panic!("call1 with invalid type"),
Expand All @@ -33,7 +33,7 @@ fn call2(m: V,f: V,g: V) -> Vs {
match m {
V::BlockInst(ref bl,_prim) => {
assert_eq!(2,bl.def.typ);
bl.call_md2(2,(Some(m.clone()),Some(f),Some(g)))
bl.call_md2(2,D2::new(m.clone(),f,g))
},
V::R2(_,_prim) => Vs::V(V::D2(Cc::new(D2::new(m,f,g)),None)),
_ => panic!("call2 with invalid type"),
Expand Down
8 changes: 4 additions & 4 deletions rs_src/prim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -520,8 +520,8 @@ pub fn decompose(arity:usize, x: Vn,_w: Vn) -> Vs {
let t = 3 + b.def.typ;
match t {
4 => {
let (f,g) = a.deref();
Vs::V(V::A(Cc::new(A::new(vec![V::Scalar(4.0),g.as_ref().unwrap().clone(),f.as_ref().unwrap().clone()],vec![3]))))
let D1(f,g) = a.deref();
Vs::V(V::A(Cc::new(A::new(vec![V::Scalar(4.0),g.clone(),f.clone()],vec![3]))))
},
_ => panic!("UserMd1 illegal decompose"),
}
Expand All @@ -530,8 +530,8 @@ pub fn decompose(arity:usize, x: Vn,_w: Vn) -> Vs {
let t = 3 + b.def.typ;
match t {
5 => {
let (f,g,h) = a.deref();
Vs::V(V::A(Cc::new(A::new(vec![V::Scalar(5.0),g.as_ref().unwrap().clone(),f.as_ref().unwrap().clone(),h.as_ref().unwrap().clone()],vec![4]))))
let D2(f,g,h) = a.deref();
Vs::V(V::A(Cc::new(A::new(vec![V::Scalar(5.0),g.clone(),f.clone(),h.clone()],vec![4]))))
},
_ => panic!("UserMd2 illegal decompose"),
}
Expand Down
28 changes: 14 additions & 14 deletions rs_src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ pub enum V {
Scalar(f64),
Char(char),
BlockInst(Cc<BlockInst>,Option<usize>),
UserMd1(Cc<BlockInst>,Box<(Vn,Vn)>,Option<usize>),
UserMd2(Cc<BlockInst>,Box<(Vn,Vn,Vn)>,Option<usize>),
UserMd1(Cc<BlockInst>,Cc<D1>,Option<usize>),
UserMd2(Cc<BlockInst>,Cc<D2>,Option<usize>),
Nothing,
A(Cc<A>),
Fn(fn(usize,Vn,Vn) -> Vs,Option<usize>), // X, W
Expand Down Expand Up @@ -102,15 +102,15 @@ impl Calleable for V {
fn call(&self,arity:usize,x: Vn,w: Vn) -> Vs {
match self.deref() {
V::UserMd1(b,mods,_prim) => {
let (m,f) = mods.deref();
let args = vec![Vh::V(self.clone()),none_or_clone(&x),none_or_clone(&w),Vh::V(m.as_ref().unwrap().clone()),Vh::V(f.as_ref().unwrap().clone())];
let D1(m,f) = mods.deref();
let args = vec![Vh::V(self.clone()),none_or_clone(&x),none_or_clone(&w),Vh::V(m.clone()),Vh::V(f.clone())];
let env = Env::new(Some(b.parent.clone()),&b.def,arity,Some(args));
let pos = body_pos(b,arity);
vm(&env,&b.def.code,pos,Vec::new())
},
V::UserMd2(b,mods,_prim) => {
let (m,f,g) = mods.deref();
let args = vec![Vh::V(self.clone()),none_or_clone(&x),none_or_clone(&w),Vh::V(m.as_ref().unwrap().clone()),Vh::V(f.as_ref().unwrap().clone()),Vh::V(g.as_ref().unwrap().clone())];
let D2(m,f,g) = mods.deref();
let args = vec![Vh::V(self.clone()),none_or_clone(&x),none_or_clone(&w),Vh::V(m.clone()),Vh::V(f.clone()),Vh::V(g.clone())];
let env = Env::new(Some(b.parent.clone()),&b.def,arity,Some(args));
let pos = body_pos(b,arity);
vm(&env,&b.def.code,pos,Vec::new())
Expand Down Expand Up @@ -323,10 +323,10 @@ impl BlockInst {
pub fn new(env: Env,block: Cc<Block>) -> Self {
Self {def: block, parent: env }
}
pub fn call_md1(&self,arity:usize,args: (Vn,Vn)) -> Vs {
pub fn call_md1(&self,arity:usize,args: D1) -> Vs {
match self.def.imm {
false => {
Vs::V(V::UserMd1(Cc::new(BlockInst::new(self.parent.clone(),self.def.clone())),Box::new(args),None))
Vs::V(V::UserMd1(Cc::new(BlockInst::new(self.parent.clone(),self.def.clone())),Cc::new(args),None))
},
true => {
let pos = match self.def.body {
Expand All @@ -336,16 +336,16 @@ impl BlockInst {
}
_ => panic!("body immediacy doesnt match block definition"),
};
let (m,f) = args;
let env = Env::new(Some(self.parent.clone()),&self.def,arity,Some(vec![Vh::V(m.unwrap().clone()),Vh::V(f.unwrap().clone())]));
let D1(m,f) = args;
let env = Env::new(Some(self.parent.clone()),&self.def,arity,Some(vec![Vh::V(m.clone()),Vh::V(f.clone())]));
vm(&env,&self.def.code,pos,Vec::new())
},
}
}
pub fn call_md2(&self,arity:usize,args: (Vn,Vn,Vn)) -> Vs {
pub fn call_md2(&self,arity:usize,args: D2) -> Vs {
match self.def.imm {
false => {
Vs::V(V::UserMd2(Cc::new(BlockInst::new(self.parent.clone(),self.def.clone())),Box::new(args),None))
Vs::V(V::UserMd2(Cc::new(BlockInst::new(self.parent.clone(),self.def.clone())),Cc::new(args),None))
},
true => {
let pos = match self.def.body {
Expand All @@ -355,8 +355,8 @@ impl BlockInst {
}
_ => panic!("body immediacy doesnt match block definition"),
};
let (m,f,g) = args;
let env = Env::new(Some(self.parent.clone()),&self.def,arity,Some(vec![Vh::V(m.unwrap().clone()),Vh::V(f.unwrap().clone()),Vh::V(g.unwrap().clone())]));
let D2(m,f,g) = args;
let env = Env::new(Some(self.parent.clone()),&self.def,arity,Some(vec![Vh::V(m.clone()),Vh::V(f.clone()),Vh::V(g.clone())]));
vm(&env,&self.def.code,pos,Vec::new())
},
}
Expand Down

0 comments on commit 9127bfb

Please sign in to comment.