diff --git a/compiler/generator/rust/rust_code_container.cpp b/compiler/generator/rust/rust_code_container.cpp index 095e2d78c7..63ceb85999 100644 --- a/compiler/generator/rust/rust_code_container.cpp +++ b/compiler/generator/rust/rust_code_container.cpp @@ -238,6 +238,8 @@ void RustCodeContainer::produceClass() tab(n, *fOut); *fOut << "use std::convert::TryInto;"; + tab(n, *fOut); + *fOut << "use std::borrow;"; // Generate gub containers generateSubContainers(); @@ -527,7 +529,6 @@ void RustCodeContainer::produceClass() generateComputeFrame(n + 1); } else { generateCompute(n + 1); - generateComputeInterface(n + 1); } tab(n, *fOut); @@ -627,18 +628,24 @@ void RustCodeContainer::generateComputeHeader(int n, std::ostream* fOut, int fNu { // Compute "compute" declaration tab(n, *fOut); - *fOut << "pub fn compute_arrays(" - << "&mut self, " << fFullCount << ": usize, inputs: &[&[FaustFloat] ; " << fNumInputs - << "]" - << ", outputs: &mut [&mut [FaustFloat] ; " << fNumOutputs << "]) {"; -} - -void RustCodeContainer::generateComputeInterfaceHeader(int n, std::ostream* fOut, int fNumInputs, - int fNumOutputs) -{ - *fOut << "pub fn compute(" - << "&mut self, " << fFullCount << ": usize, inputs: & [& [FaustFloat] ]" - << ", outputs: & mut[& mut[FaustFloat] ]) {"; + tab(n, *fOut); + *fOut << "pub fn compute("; + tab(n + 1, *fOut); + *fOut << "&mut self,"; + tab(n + 1, *fOut); + *fOut << "count: usize,"; + tab(n + 1, *fOut); + *fOut << "inputs: impl borrow::Borrow<[InType]>,"; + tab(n + 1, *fOut); + *fOut << "mut outputs: impl borrow::BorrowMut<[OutType]>,"; + tab(n, *fOut); + *fOut << ") where"; + tab(n + 1, *fOut); + *fOut << "InType: borrow::Borrow<[FaustFloat]>,"; + tab(n + 1, *fOut); + *fOut << "OutType: borrow::BorrowMut<[FaustFloat]>,"; + tab(n, *fOut); + *fOut << "{"; tab(n + 1, *fOut); } @@ -684,23 +691,6 @@ void RustCodeContainer::generateComputeFrame(int n) tab(n, *fOut); } -void RustCodeContainer::generateComputeInterface(int n) -{ - // Generates declaration - tab(n, *fOut); - generateComputeInterfaceHeader(n, fOut, fNumInputs, fNumOutputs); - - *fOut << "let input_array = inputs.split_at(" << fNumInputs - << ").0.try_into().expect(\"too few input buffers\");"; - tab(n + 1, *fOut); - *fOut << "let output_array = outputs.split_at_mut(" << fNumOutputs - << ").0.try_into().expect(\"too few output buffers\");"; - tab(n + 1, *fOut); - *fOut << "self.compute_arrays(count, input_array, output_array);"; - tab(n, *fOut); - *fOut << "}" << endl; -} - // Scalar RustScalarCodeContainer::RustScalarCodeContainer(const string& name, int numInputs, int numOutputs, std::ostream* out, int sub_container_type) diff --git a/compiler/generator/rust/rust_code_container.hh b/compiler/generator/rust/rust_code_container.hh index d82c962f08..a48c1d72c5 100644 --- a/compiler/generator/rust/rust_code_container.hh +++ b/compiler/generator/rust/rust_code_container.hh @@ -55,8 +55,6 @@ class RustCodeContainer : public virtual CodeContainer { virtual void produceClass(); void generateComputeHeader(int n, std::ostream* fOut, int fNumInputs, int fNumOutputs); - void generateComputeInterfaceHeader(int n, std::ostream* fOut, int fNumInputs, int fNumOutputs); - void generateComputeInterface(int tab); void generateComputeFrame(int tab); virtual void generateCompute(int tab) = 0; void produceInternal(); diff --git a/compiler/generator/rust/rust_instructions.hh b/compiler/generator/rust/rust_instructions.hh index f4fdcea518..6d67c7294e 100644 --- a/compiler/generator/rust/rust_instructions.hh +++ b/compiler/generator/rust/rust_instructions.hh @@ -225,9 +225,9 @@ class RustInstVisitor : public TextInstVisitor { virtual void visit(DeclareBufferIterators* inst) { /* Generates an expression like: - let [outputs0, outputs1, ..] = outputs; - let outputs0 = outputs0[..count].iter_mut(); - let outputs1 = outputs1[..count].iter_mut(); + let [outputs0, outputs1] = outputs.borrow_mut() else { panic!(\"wrong number of outputs\"); };"; + let outputs0 = outputs0.borrow_mut[..count].iter_mut(); + let outputs1 = outputs1.borrow_mut[..count].iter_mut(); */ // Don't generate if no channels or onesample mode @@ -241,23 +241,29 @@ class RustInstVisitor : public TextInstVisitor { for (int i = 0; i < inst->fChannels; ++i) { *fOut << name << i << ", "; } - *fOut << "] = " << name << ";"; + *fOut << "] = " << name; + if (inst->fMutable) { + *fOut << ".borrow_mut() else { panic!(\"wrong number of outputs\"); };"; + } else { + *fOut << ".borrow() else { panic!(\"wrong number of inputs\"); };"; + } // Build fixed size iterator variables for (int i = 0; i < inst->fChannels; ++i) { tab(fTab, *fOut); - *fOut << "let " << name << i << " = " << name << i << "[..count]"; + *fOut << "let " << name << i << " = " << name << i; + ; if (inst->fMutable) { if (inst->fChunk) { - *fOut << ".chunks_mut(vsize as usize);"; + *fOut << ".borrow_mut()[..count].chunks_mut(vsize as usize);"; } else { - *fOut << ".iter_mut();"; + *fOut << ".borrow_mut()[..count].iter_mut();"; } } else { if (inst->fChunk) { - *fOut << ".chunks(vsize as usize);"; + *fOut << ".borrow()[..count].chunks(vsize as usize);"; } else { - *fOut << ".iter();"; + *fOut << ".borrow()[..count].iter();"; } } } diff --git a/tests/impulse-tests/Makefile b/tests/impulse-tests/Makefile index a46313c05b..a475f19510 100644 --- a/tests/impulse-tests/Makefile +++ b/tests/impulse-tests/Makefile @@ -122,10 +122,7 @@ travis: ######################################################################### # automatic github action test github_action: - $(MAKE) -f Make.rust outdir=rust/osec CARGOOPTIONS="" FAUSTOPTIONS="-I ../../libraries/ -double -os -ec -rnt -a archs/rust/architecture_osecrnt.rs" - $(MAKE) -f Make.rust outdir=rust/os CARGOOPTIONS="" FAUSTOPTIONS="-I ../../libraries/ -double -os -rnt -a archs/rust/architecture_osrnt.rs" $(MAKE) -f Make.rust outdir=rust/no CARGOOPTIONS="" FAUSTOPTIONS="-I ../../libraries/ -double -a archs/rust/architecture_trait.rs" - $(MAKE) -f Make.gcc outdir=cpp/double/os lang=cpp arch=impulsearch7ter.cpp FAUSTOPTIONS="-I dsp -double -os" $(MAKE) -f Make.gcc outdir=cpp/double lang=cpp arch=impulsearch.cpp FAUSTOPTIONS="-I ../../libraries/ -I dsp -double" #########################################################################