|
2 | 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this
|
3 | 3 | // file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
4 | 4 |
|
| 5 | +mod assignment; |
5 | 6 | mod block_declaration_instantiation;
|
6 | 7 | mod class_definition_evaluation;
|
7 | 8 | mod for_in_of_statement;
|
@@ -770,160 +771,6 @@ impl CompileEvaluation for ast::LogicalExpression<'_> {
|
770 | 771 | }
|
771 | 772 | }
|
772 | 773 |
|
773 |
| -impl CompileEvaluation for ast::AssignmentExpression<'_> { |
774 |
| - fn compile(&self, ctx: &mut CompileContext) { |
775 |
| - // 1. Let lref be ? Evaluation of LeftHandSideExpression. |
776 |
| - let is_identifier_ref = match &self.left { |
777 |
| - ast::AssignmentTarget::ArrayAssignmentTarget(_) => todo!(), |
778 |
| - ast::AssignmentTarget::AssignmentTargetIdentifier(identifier) => { |
779 |
| - identifier.compile(ctx); |
780 |
| - true |
781 |
| - } |
782 |
| - ast::AssignmentTarget::ComputedMemberExpression(expression) => { |
783 |
| - expression.compile(ctx); |
784 |
| - false |
785 |
| - } |
786 |
| - ast::AssignmentTarget::ObjectAssignmentTarget(_) => todo!(), |
787 |
| - ast::AssignmentTarget::PrivateFieldExpression(_) => todo!(), |
788 |
| - ast::AssignmentTarget::StaticMemberExpression(expression) => { |
789 |
| - expression.compile(ctx); |
790 |
| - false |
791 |
| - } |
792 |
| - ast::AssignmentTarget::TSAsExpression(_) |
793 |
| - | ast::AssignmentTarget::TSSatisfiesExpression(_) |
794 |
| - | ast::AssignmentTarget::TSNonNullExpression(_) |
795 |
| - | ast::AssignmentTarget::TSTypeAssertion(_) |
796 |
| - | ast::AssignmentTarget::TSInstantiationExpression(_) => unreachable!(), |
797 |
| - }; |
798 |
| - |
799 |
| - if self.operator == oxc_syntax::operator::AssignmentOperator::Assign { |
800 |
| - ctx.add_instruction(Instruction::PushReference); |
801 |
| - self.right.compile(ctx); |
802 |
| - |
803 |
| - if is_reference(&self.right) { |
804 |
| - ctx.add_instruction(Instruction::GetValue); |
805 |
| - } |
806 |
| - |
807 |
| - ctx.add_instruction(Instruction::LoadCopy); |
808 |
| - ctx.add_instruction(Instruction::PopReference); |
809 |
| - ctx.add_instruction(Instruction::PutValue); |
810 |
| - |
811 |
| - // ... Return rval. |
812 |
| - ctx.add_instruction(Instruction::Store); |
813 |
| - } else if matches!( |
814 |
| - self.operator, |
815 |
| - oxc_syntax::operator::AssignmentOperator::LogicalAnd |
816 |
| - | oxc_syntax::operator::AssignmentOperator::LogicalNullish |
817 |
| - | oxc_syntax::operator::AssignmentOperator::LogicalOr |
818 |
| - ) { |
819 |
| - // 2. Let lval be ? GetValue(lref). |
820 |
| - ctx.add_instruction(Instruction::GetValueKeepReference); |
821 |
| - ctx.add_instruction(Instruction::PushReference); |
822 |
| - // We store the left value on the stack, because we'll need to |
823 |
| - // restore it later. |
824 |
| - ctx.add_instruction(Instruction::LoadCopy); |
825 |
| - |
826 |
| - match self.operator { |
827 |
| - oxc_syntax::operator::AssignmentOperator::LogicalAnd => { |
828 |
| - // 3. Let lbool be ToBoolean(lval). |
829 |
| - // Note: We do not directly call ToBoolean: JumpIfNot does. |
830 |
| - // 4. If lbool is false, return lval. |
831 |
| - } |
832 |
| - oxc_syntax::operator::AssignmentOperator::LogicalOr => { |
833 |
| - // 3. Let lbool be ToBoolean(lval). |
834 |
| - // Note: We do not directly call ToBoolean: JumpIfNot does. |
835 |
| - // 4. If lbool is true, return lval. |
836 |
| - ctx.add_instruction(Instruction::LogicalNot); |
837 |
| - } |
838 |
| - oxc_syntax::operator::AssignmentOperator::LogicalNullish => { |
839 |
| - // 3. If lval is neither undefined nor null, return lval. |
840 |
| - ctx.add_instruction(Instruction::IsNullOrUndefined); |
841 |
| - } |
842 |
| - _ => unreachable!(), |
843 |
| - } |
844 |
| - |
845 |
| - let jump_to_end = ctx.add_instruction_with_jump_slot(Instruction::JumpIfNot); |
846 |
| - |
847 |
| - // We're returning the right expression, so we discard the left |
848 |
| - // value at the top of the stack. |
849 |
| - ctx.add_instruction(Instruction::Store); |
850 |
| - |
851 |
| - // 5. If IsAnonymousFunctionDefinition(AssignmentExpression) |
852 |
| - // is true and IsIdentifierRef of LeftHandSideExpression is true, |
853 |
| - // then |
854 |
| - if is_identifier_ref && is_anonymous_function_definition(&self.right) { |
855 |
| - // a. Let lhs be the StringValue of LeftHandSideExpression. |
856 |
| - // b. Let rval be ? NamedEvaluation of AssignmentExpression with argument lhs. |
857 |
| - ctx.name_identifier = Some(NamedEvaluationParameter::ReferenceStack); |
858 |
| - self.right.compile(ctx); |
859 |
| - } else { |
860 |
| - // 6. Else |
861 |
| - // a. Let rref be ? Evaluation of AssignmentExpression. |
862 |
| - self.right.compile(ctx); |
863 |
| - // b. Let rval be ? GetValue(rref). |
864 |
| - if is_reference(&self.right) { |
865 |
| - ctx.add_instruction(Instruction::GetValue); |
866 |
| - } |
867 |
| - } |
868 |
| - |
869 |
| - // 7. Perform ? PutValue(lref, rval). |
870 |
| - ctx.add_instruction(Instruction::LoadCopy); |
871 |
| - ctx.add_instruction(Instruction::PopReference); |
872 |
| - ctx.add_instruction(Instruction::PutValue); |
873 |
| - |
874 |
| - // 4. ... return lval. |
875 |
| - ctx.set_jump_target_here(jump_to_end); |
876 |
| - ctx.add_instruction(Instruction::Store); |
877 |
| - } else { |
878 |
| - // 2. let lval be ? GetValue(lref). |
879 |
| - ctx.add_instruction(Instruction::GetValueKeepReference); |
880 |
| - ctx.add_instruction(Instruction::Load); |
881 |
| - ctx.add_instruction(Instruction::PushReference); |
882 |
| - // 3. Let rref be ? Evaluation of AssignmentExpression. |
883 |
| - self.right.compile(ctx); |
884 |
| - |
885 |
| - // 4. Let rval be ? GetValue(rref). |
886 |
| - if is_reference(&self.right) { |
887 |
| - ctx.add_instruction(Instruction::GetValue); |
888 |
| - } |
889 |
| - |
890 |
| - // 5. Let assignmentOpText be the source text matched by AssignmentOperator. |
891 |
| - // 6. Let opText be the sequence of Unicode code points associated with assignmentOpText in the following table: |
892 |
| - let op_text = match self.operator { |
893 |
| - oxc_syntax::operator::AssignmentOperator::Addition => BinaryOperator::Addition, |
894 |
| - oxc_syntax::operator::AssignmentOperator::Subtraction => { |
895 |
| - BinaryOperator::Subtraction |
896 |
| - } |
897 |
| - oxc_syntax::operator::AssignmentOperator::Multiplication => { |
898 |
| - BinaryOperator::Multiplication |
899 |
| - } |
900 |
| - oxc_syntax::operator::AssignmentOperator::Division => BinaryOperator::Division, |
901 |
| - oxc_syntax::operator::AssignmentOperator::Remainder => BinaryOperator::Remainder, |
902 |
| - oxc_syntax::operator::AssignmentOperator::ShiftLeft => BinaryOperator::ShiftLeft, |
903 |
| - oxc_syntax::operator::AssignmentOperator::ShiftRight => BinaryOperator::ShiftRight, |
904 |
| - oxc_syntax::operator::AssignmentOperator::ShiftRightZeroFill => { |
905 |
| - BinaryOperator::ShiftRightZeroFill |
906 |
| - } |
907 |
| - oxc_syntax::operator::AssignmentOperator::BitwiseOR => BinaryOperator::BitwiseOR, |
908 |
| - oxc_syntax::operator::AssignmentOperator::BitwiseXOR => BinaryOperator::BitwiseXOR, |
909 |
| - oxc_syntax::operator::AssignmentOperator::BitwiseAnd => BinaryOperator::BitwiseAnd, |
910 |
| - oxc_syntax::operator::AssignmentOperator::Exponential => { |
911 |
| - BinaryOperator::Exponential |
912 |
| - } |
913 |
| - _ => unreachable!(), |
914 |
| - }; |
915 |
| - // 7. Let r be ? ApplyStringOrNumericBinaryOperator(lval, opText, rval). |
916 |
| - ctx.add_instruction(Instruction::ApplyStringOrNumericBinaryOperator(op_text)); |
917 |
| - ctx.add_instruction(Instruction::LoadCopy); |
918 |
| - // 8. Perform ? PutValue(lref, r). |
919 |
| - ctx.add_instruction(Instruction::PopReference); |
920 |
| - ctx.add_instruction(Instruction::PutValue); |
921 |
| - // 9. Return r. |
922 |
| - ctx.add_instruction(Instruction::Store); |
923 |
| - } |
924 |
| - } |
925 |
| -} |
926 |
| - |
927 | 774 | impl CompileEvaluation for ast::ParenthesizedExpression<'_> {
|
928 | 775 | fn compile(&self, ctx: &mut CompileContext) {
|
929 | 776 | self.expression.compile(ctx);
|
|
0 commit comments