From 9127bfb65f633649f24361b0270279eba7f16521 Mon Sep 17 00:00:00 2001 From: Rowan Cannaday Date: Fri, 14 Jan 2022 22:48:36 -0500 Subject: [PATCH] switch tuple args to use D1/D2 types --- rs_src/ebqn.rs | 4 ++-- rs_src/prim.rs | 8 ++++---- rs_src/schema.rs | 28 ++++++++++++++-------------- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/rs_src/ebqn.rs b/rs_src/ebqn.rs index 628ad7f..2e540bc 100644 --- a/rs_src/ebqn.rs +++ b/rs_src/ebqn.rs @@ -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"), @@ -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"), diff --git a/rs_src/prim.rs b/rs_src/prim.rs index f4bbf3a..c355718 100644 --- a/rs_src/prim.rs +++ b/rs_src/prim.rs @@ -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"), } @@ -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"), } diff --git a/rs_src/schema.rs b/rs_src/schema.rs index 2429372..98baf59 100644 --- a/rs_src/schema.rs +++ b/rs_src/schema.rs @@ -24,8 +24,8 @@ pub enum V { Scalar(f64), Char(char), BlockInst(Cc,Option), - UserMd1(Cc,Box<(Vn,Vn)>,Option), - UserMd2(Cc,Box<(Vn,Vn,Vn)>,Option), + UserMd1(Cc,Cc,Option), + UserMd2(Cc,Cc,Option), Nothing, A(Cc), Fn(fn(usize,Vn,Vn) -> Vs,Option), // X, W @@ -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()) @@ -323,10 +323,10 @@ impl BlockInst { pub fn new(env: Env,block: Cc) -> 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 { @@ -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 { @@ -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()) }, }