Skip to content

Commit a303130

Browse files
committed
destination first
1 parent 4eb0c0b commit a303130

3 files changed

Lines changed: 122 additions & 123 deletions

File tree

src/pipelines/analyzer.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -305,11 +305,10 @@ impl<'i> Analyze<'i> for Operand<'i> {
305305
let index: u8 = index.parse().map_err(|err| {
306306
LexerError::RegisterIndexNonDecimal(span.to_src(), err, index)
307307
})?;
308-
let index = u5::try_from(index)
309-
.unwrap_or_else(|_| {
310-
issues.push_error(SyntaxError::RegisterIndexOutOfRange(index), &span);
311-
u5::with(0)
312-
});
308+
let index = u5::try_from(index).unwrap_or_else(|_| {
309+
issues.push_error(SyntaxError::RegisterIndexOutOfRange(index), &span);
310+
u5::with(0)
311+
});
313312
let set = match family.as_rule() {
314313
Rule::reg_a => {
315314
let a = RegA::with(member).unwrap_or_else(|| {

src/pipelines/compiler.rs

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -677,15 +677,15 @@ impl<'i> Statement<'i> {
677677
RegAFR::F(f) => Instr::Put(PutOp::ClrF(f, idx! {0})),
678678
RegAFR::R(r) => Instr::Put(PutOp::ClrR(r, idx! {0})),
679679
},
680-
Operator::put => match reg! {1} {
681-
RegAll::A(a) => Instr::Put(PutOp::PutA(a, idx! {1}, num! {0, a})),
682-
RegAll::F(f) => Instr::Put(PutOp::PutF(f, idx! {1}, num! {0, f})),
683-
RegAll::R(r) => Instr::Put(PutOp::PutR(r, idx! {1}, num! {0, r})),
684-
RegAll::S => Instr::Bytes(BytesOp::Put(str! {0}, idx! {1}, false)),
680+
Operator::put => match reg! {0} {
681+
RegAll::A(a) => Instr::Put(PutOp::PutA(a, idx! {0}, num! {1, a})),
682+
RegAll::F(f) => Instr::Put(PutOp::PutF(f, idx! {0}, num! {1, f})),
683+
RegAll::R(r) => Instr::Put(PutOp::PutR(r, idx! {0}, num! {1, r})),
684+
RegAll::S => Instr::Bytes(BytesOp::Put(idx! {0}, str! {1}, false)),
685685
},
686-
Operator::putif => match reg! {1} {
687-
RegAR::A(a) => Instr::Put(PutOp::PutIfA(a, idx! {1}, num! {0, a})),
688-
RegAR::R(r) => Instr::Put(PutOp::PutIfR(r, idx! {1}, num! {0, r})),
686+
Operator::putif => match reg! {0} {
687+
RegAR::A(a) => Instr::Put(PutOp::PutIfA(a, idx! {0}, num! {1, a})),
688+
RegAR::R(r) => Instr::Put(PutOp::PutIfR(r, idx! {0}, num! {1, r})),
689689
},
690690

691691
// *** Move operations
@@ -698,9 +698,9 @@ impl<'i> Statement<'i> {
698698
);
699699
}
700700
match reg {
701-
RegAFR::A(a) => Instr::Move(MoveOp::DupA(a, idx! {0}, idx! {1})),
702-
RegAFR::F(f) => Instr::Move(MoveOp::DupF(f, idx! {0}, idx! {1})),
703-
RegAFR::R(r) => Instr::Move(MoveOp::DupR(r, idx! {0}, idx! {1})),
701+
RegAFR::A(a) => Instr::Move(MoveOp::DupA(a, idx! {1}, idx! {0})),
702+
RegAFR::F(f) => Instr::Move(MoveOp::DupF(f, idx! {1}, idx! {0})),
703+
RegAFR::R(r) => Instr::Move(MoveOp::DupR(r, idx! {1}, idx! {0})),
704704
}
705705
}
706706
Operator::mov => {
@@ -712,27 +712,27 @@ impl<'i> Statement<'i> {
712712
);
713713
}
714714
match reg {
715-
RegAll::A(a) => Instr::Move(MoveOp::MovA(a, idx! {0}, idx! {1})),
716-
RegAll::F(f) => Instr::Move(MoveOp::MovF(f, idx! {0}, idx! {1})),
717-
RegAll::R(r) => Instr::Move(MoveOp::MovR(r, idx! {0}, idx! {1})),
718-
RegAll::S => Instr::Bytes(BytesOp::Mov(idx! {0}, idx! {1})),
715+
RegAll::A(a) => Instr::Move(MoveOp::MovA(a, idx! {1}, idx! {0})),
716+
RegAll::F(f) => Instr::Move(MoveOp::MovF(f, idx! {1}, idx! {0})),
717+
RegAll::R(r) => Instr::Move(MoveOp::MovR(r, idx! {1}, idx! {0})),
718+
RegAll::S => Instr::Bytes(BytesOp::Mov(idx! {1}, idx! {0})),
719719
}
720720
}
721-
Operator::cnv => match (reg! {0}, reg! {1}) {
721+
Operator::cnv => match (reg! {1}, reg! {0}) {
722722
(RegAF::A(a1), RegAF::A(a2)) => {
723-
Instr::Move(MoveOp::CnvA(a1, idx! {0}, a2, idx! {1}))
723+
Instr::Move(MoveOp::CnvA(a1, idx! {1}, a2, idx! {0}))
724724
}
725725
(RegAF::F(f1), RegAF::F(f2)) => {
726-
Instr::Move(MoveOp::CnvF(f1, idx! {0}, f2, idx! {1}))
726+
Instr::Move(MoveOp::CnvF(f1, idx! {1}, f2, idx! {0}))
727727
}
728-
(RegAF::A(a), RegAF::F(f)) => Instr::Move(MoveOp::CnvAF(a, idx! {0}, f, idx! {1})),
729-
(RegAF::F(f), RegAF::A(a)) => Instr::Move(MoveOp::CnvFA(f, idx! {0}, a, idx! {1})),
728+
(RegAF::A(a), RegAF::F(f)) => Instr::Move(MoveOp::CnvAF(a, idx! {1}, f, idx! {0})),
729+
(RegAF::F(f), RegAF::A(a)) => Instr::Move(MoveOp::CnvFA(f, idx! {1}, a, idx! {0})),
730730
},
731-
Operator::cpy => match reg! {0} {
732-
RegAR::A(a) => Instr::Move(MoveOp::CpyA(a, idx! {0}, reg! {1}, idx! {1})),
733-
RegAR::R(r) => Instr::Move(MoveOp::CpyR(r, idx! {0}, reg! {1}, idx! {1})),
731+
Operator::cpy => match reg! {1} {
732+
RegAR::A(a) => Instr::Move(MoveOp::CpyA(a, idx! {1}, reg! {0}, idx! {0})),
733+
RegAR::R(r) => Instr::Move(MoveOp::CpyR(r, idx! {1}, reg! {0}, idx! {0})),
734734
},
735-
Operator::spy => Instr::Move(MoveOp::SpyAR(reg! {0}, idx! {0}, reg! {1}, idx! {1})),
735+
Operator::spy => Instr::Move(MoveOp::SpyAR(reg! {1}, idx! {1}, reg! {0}, idx! {0})),
736736
Operator::swp => {
737737
let reg = reg! {0};
738738
if reg != reg! {1} {
@@ -826,14 +826,14 @@ impl<'i> Statement<'i> {
826826
Instr::Arithmetic(ArithmeticOp::Stp(reg! {0}, idx! {0}, Step::with(-1)))
827827
}
828828
Operator::add => {
829-
if let Some(Operand::Lit(Literal::Int(mut step, _), span)) = self.operands.get(0) {
829+
if let Some(Operand::Lit(Literal::Int(mut step, _), span)) = self.operands.get(1) {
830830
if step > u1024::from(i8::MAX as u8) {
831831
step = u1024::from(1u64);
832832
issues.push_error(SemanticError::StepTooLarge(self.operator.0), span);
833833
}
834834
Instr::Arithmetic(ArithmeticOp::Stp(
835-
reg! {1},
836-
idx! {1},
835+
reg! {0},
836+
idx! {0},
837837
Step::with(step.low_u32() as i8),
838838
))
839839
} else {
@@ -846,23 +846,23 @@ impl<'i> Statement<'i> {
846846
}
847847
match reg {
848848
RegAF::A(a) => {
849-
Instr::Arithmetic(ArithmeticOp::AddA(flags!(), a, idx! {0}, idx! {1}))
849+
Instr::Arithmetic(ArithmeticOp::AddA(flags!(), a, idx! {1}, idx! {0}))
850850
}
851851
RegAF::F(f) => {
852-
Instr::Arithmetic(ArithmeticOp::AddF(flags!(), f, idx! {0}, idx! {1}))
852+
Instr::Arithmetic(ArithmeticOp::AddF(flags!(), f, idx! {1}, idx! {0}))
853853
}
854854
}
855855
}
856856
}
857857
Operator::sub => {
858-
if let Some(Operand::Lit(Literal::Int(mut step, _), span)) = self.operands.get(0) {
858+
if let Some(Operand::Lit(Literal::Int(mut step, _), span)) = self.operands.get(1) {
859859
if step > u1024::from(i8::MAX as u8) {
860860
step = u1024::from(1u64);
861861
issues.push_error(SemanticError::StepTooLarge(self.operator.0), span);
862862
}
863863
Instr::Arithmetic(ArithmeticOp::Stp(
864-
reg! {1},
865-
idx! {1},
864+
reg! {0},
865+
idx! {0},
866866
Step::with(-(step.low_u32() as i8)),
867867
))
868868
} else {
@@ -1105,8 +1105,8 @@ impl<'i> Statement<'i> {
11051105
Instr::Bytes(BytesOp::Find(idx! {0}, idx! {1}))
11061106
}
11071107
Operator::extr => {
1108-
let _: RegS = reg! {0};
1109-
Instr::Bytes(BytesOp::Extr(idx! {0}, reg! {1}, idx! {1}, idx! {2}))
1108+
let _: RegS = reg! {1};
1109+
Instr::Bytes(BytesOp::Extr(idx! {1}, reg! {0}, idx! {0}, idx! {2}))
11101110
}
11111111
Operator::inj => {
11121112
let _: RegS = reg! {0};

0 commit comments

Comments
 (0)