@@ -820,143 +820,65 @@ impl<'arena, 'env> ElimContext<'arena, 'env> {
820820
821821 /// Find the representation type of a format description.
822822 pub fn format_repr ( & self , format : & ArcValue < ' arena > ) -> ArcValue < ' arena > {
823- match format. as_ref ( ) {
823+ let value = match format. as_ref ( ) {
824824 Value :: FormatRecord ( labels, formats) | Value :: FormatOverlap ( labels, formats) => {
825- Spanned :: new (
826- format. span ( ) ,
827- Arc :: new ( Value :: RecordType ( labels, formats. clone ( ) . apply_repr ( ) ) ) ,
828- )
825+ Value :: RecordType ( labels, formats. clone ( ) . apply_repr ( ) )
829826 }
830- Value :: FormatCond ( _, format, _) => self . format_repr ( format) ,
827+ Value :: FormatCond ( _, format, _) => return self . format_repr ( format) ,
831828 Value :: Stuck ( Head :: Prim ( prim) , spine) => match ( prim, & spine[ ..] ) {
832- ( Prim :: FormatU8 , [ ] ) => {
833- Spanned :: new ( format. span ( ) , Arc :: new ( Value :: prim ( Prim :: U8Type , [ ] ) ) )
834- }
835- ( Prim :: FormatU16Be , [ ] ) => {
836- Spanned :: new ( format. span ( ) , Arc :: new ( Value :: prim ( Prim :: U16Type , [ ] ) ) )
837- }
838- ( Prim :: FormatU16Le , [ ] ) => {
839- Spanned :: new ( format. span ( ) , Arc :: new ( Value :: prim ( Prim :: U16Type , [ ] ) ) )
840- }
841- ( Prim :: FormatU32Be , [ ] ) => {
842- Spanned :: new ( format. span ( ) , Arc :: new ( Value :: prim ( Prim :: U32Type , [ ] ) ) )
843- }
844- ( Prim :: FormatU32Le , [ ] ) => {
845- Spanned :: new ( format. span ( ) , Arc :: new ( Value :: prim ( Prim :: U32Type , [ ] ) ) )
846- }
847- ( Prim :: FormatU64Be , [ ] ) => {
848- Spanned :: new ( format. span ( ) , Arc :: new ( Value :: prim ( Prim :: U64Type , [ ] ) ) )
849- }
850- ( Prim :: FormatU64Le , [ ] ) => {
851- Spanned :: new ( format. span ( ) , Arc :: new ( Value :: prim ( Prim :: U64Type , [ ] ) ) )
852- }
853- ( Prim :: FormatS8 , [ ] ) => {
854- Spanned :: new ( format. span ( ) , Arc :: new ( Value :: prim ( Prim :: S8Type , [ ] ) ) )
855- }
856- ( Prim :: FormatS16Be , [ ] ) => {
857- Spanned :: new ( format. span ( ) , Arc :: new ( Value :: prim ( Prim :: S16Type , [ ] ) ) )
858- }
859- ( Prim :: FormatS16Le , [ ] ) => {
860- Spanned :: new ( format. span ( ) , Arc :: new ( Value :: prim ( Prim :: S16Type , [ ] ) ) )
861- }
862- ( Prim :: FormatS32Be , [ ] ) => {
863- Spanned :: new ( format. span ( ) , Arc :: new ( Value :: prim ( Prim :: S32Type , [ ] ) ) )
864- }
865- ( Prim :: FormatS32Le , [ ] ) => {
866- Spanned :: new ( format. span ( ) , Arc :: new ( Value :: prim ( Prim :: S32Type , [ ] ) ) )
829+ ( Prim :: FormatU8 , [ ] ) => Value :: prim ( Prim :: U8Type , [ ] ) ,
830+ ( Prim :: FormatU16Be , [ ] ) => Value :: prim ( Prim :: U16Type , [ ] ) ,
831+ ( Prim :: FormatU16Le , [ ] ) => Value :: prim ( Prim :: U16Type , [ ] ) ,
832+ ( Prim :: FormatU32Be , [ ] ) => Value :: prim ( Prim :: U32Type , [ ] ) ,
833+ ( Prim :: FormatU32Le , [ ] ) => Value :: prim ( Prim :: U32Type , [ ] ) ,
834+ ( Prim :: FormatU64Be , [ ] ) => Value :: prim ( Prim :: U64Type , [ ] ) ,
835+ ( Prim :: FormatU64Le , [ ] ) => Value :: prim ( Prim :: U64Type , [ ] ) ,
836+ ( Prim :: FormatS8 , [ ] ) => Value :: prim ( Prim :: S8Type , [ ] ) ,
837+ ( Prim :: FormatS16Be , [ ] ) => Value :: prim ( Prim :: S16Type , [ ] ) ,
838+ ( Prim :: FormatS16Le , [ ] ) => Value :: prim ( Prim :: S16Type , [ ] ) ,
839+ ( Prim :: FormatS32Be , [ ] ) => Value :: prim ( Prim :: S32Type , [ ] ) ,
840+ ( Prim :: FormatS32Le , [ ] ) => Value :: prim ( Prim :: S32Type , [ ] ) ,
841+ ( Prim :: FormatS64Be , [ ] ) => Value :: prim ( Prim :: S64Type , [ ] ) ,
842+ ( Prim :: FormatS64Le , [ ] ) => Value :: prim ( Prim :: S64Type , [ ] ) ,
843+ ( Prim :: FormatF32Be , [ ] ) => Value :: prim ( Prim :: F32Type , [ ] ) ,
844+ ( Prim :: FormatF32Le , [ ] ) => Value :: prim ( Prim :: F32Type , [ ] ) ,
845+ ( Prim :: FormatF64Be , [ ] ) => Value :: prim ( Prim :: F64Type , [ ] ) ,
846+ ( Prim :: FormatF64Le , [ ] ) => Value :: prim ( Prim :: F64Type , [ ] ) ,
847+ ( Prim :: FormatArray8 , [ Elim :: FunApp ( len) , Elim :: FunApp ( elem) ] ) => {
848+ Value :: prim ( Prim :: Array8Type , [ len. clone ( ) , self . format_repr ( elem) ] )
867849 }
868- ( Prim :: FormatS64Be , [ ] ) => {
869- Spanned :: new ( format . span ( ) , Arc :: new ( Value :: prim ( Prim :: S64Type , [ ] ) ) )
850+ ( Prim :: FormatArray16 , [ Elim :: FunApp ( len ) , Elim :: FunApp ( elem ) ] ) => {
851+ Value :: prim ( Prim :: Array16Type , [ len . clone ( ) , self . format_repr ( elem ) ] )
870852 }
871- ( Prim :: FormatS64Le , [ ] ) => {
872- Spanned :: new ( format . span ( ) , Arc :: new ( Value :: prim ( Prim :: S64Type , [ ] ) ) )
853+ ( Prim :: FormatArray32 , [ Elim :: FunApp ( len ) , Elim :: FunApp ( elem ) ] ) => {
854+ Value :: prim ( Prim :: Array32Type , [ len . clone ( ) , self . format_repr ( elem ) ] )
873855 }
874- ( Prim :: FormatF32Be , [ ] ) => {
875- Spanned :: new ( format . span ( ) , Arc :: new ( Value :: prim ( Prim :: F32Type , [ ] ) ) )
856+ ( Prim :: FormatArray64 , [ Elim :: FunApp ( len ) , Elim :: FunApp ( elem ) ] ) => {
857+ Value :: prim ( Prim :: Array64Type , [ len . clone ( ) , self . format_repr ( elem ) ] )
876858 }
877- ( Prim :: FormatF32Le , [ ] ) => {
878- Spanned :: new ( format. span ( ) , Arc :: new ( Value :: prim ( Prim :: F32Type , [ ] ) ) )
859+ ( Prim :: FormatLimit8 , [ _, Elim :: FunApp ( elem) ] ) => return self . format_repr ( elem) ,
860+ ( Prim :: FormatLimit16 , [ _, Elim :: FunApp ( elem) ] ) => return self . format_repr ( elem) ,
861+ ( Prim :: FormatLimit32 , [ _, Elim :: FunApp ( elem) ] ) => return self . format_repr ( elem) ,
862+ ( Prim :: FormatLimit64 , [ _, Elim :: FunApp ( elem) ] ) => return self . format_repr ( elem) ,
863+ ( Prim :: FormatRepeatUntilEnd , [ Elim :: FunApp ( elem) ] ) => {
864+ Value :: prim ( Prim :: ArrayType , [ self . format_repr ( elem) ] )
879865 }
880- ( Prim :: FormatF64Be , [ ] ) => {
881- Spanned :: new ( format . span ( ) , Arc :: new ( Value :: prim ( Prim :: F64Type , [ ] ) ) )
866+ ( Prim :: FormatLink , [ _ , Elim :: FunApp ( elem ) ] ) => {
867+ Value :: prim ( Prim :: RefType , [ elem . clone ( ) ] )
882868 }
883- ( Prim :: FormatF64Le , [ ] ) => {
884- Spanned :: new ( format. span ( ) , Arc :: new ( Value :: prim ( Prim :: F64Type , [ ] ) ) )
885- }
886- ( Prim :: FormatArray8 , [ Elim :: FunApp ( len) , Elim :: FunApp ( elem) ] ) => Spanned :: new (
887- format. span ( ) ,
888- Arc :: new ( Value :: prim (
889- Prim :: Array8Type ,
890- [ len. clone ( ) , self . format_repr ( elem) ] ,
891- ) ) ,
892- ) ,
893- ( Prim :: FormatArray16 , [ Elim :: FunApp ( len) , Elim :: FunApp ( elem) ] ) => Spanned :: new (
894- format. span ( ) ,
895- Arc :: new ( Value :: prim (
896- Prim :: Array16Type ,
897- [ len. clone ( ) , self . format_repr ( elem) ] ,
898- ) ) ,
899- ) ,
900- ( Prim :: FormatArray32 , [ Elim :: FunApp ( len) , Elim :: FunApp ( elem) ] ) => Spanned :: new (
901- format. span ( ) ,
902- Arc :: new ( Value :: prim (
903- Prim :: Array32Type ,
904- [ len. clone ( ) , self . format_repr ( elem) ] ,
905- ) ) ,
906- ) ,
907- ( Prim :: FormatArray64 , [ Elim :: FunApp ( len) , Elim :: FunApp ( elem) ] ) => Spanned :: new (
908- format. span ( ) ,
909- Arc :: new ( Value :: prim (
910- Prim :: Array64Type ,
911- [ len. clone ( ) , self . format_repr ( elem) ] ,
912- ) ) ,
913- ) ,
914- ( Prim :: FormatLimit8 , [ Elim :: FunApp ( _) , Elim :: FunApp ( elem) ] ) => {
915- self . format_repr ( elem)
916- }
917- ( Prim :: FormatLimit16 , [ Elim :: FunApp ( _) , Elim :: FunApp ( elem) ] ) => {
918- self . format_repr ( elem)
919- }
920- ( Prim :: FormatLimit32 , [ Elim :: FunApp ( _) , Elim :: FunApp ( elem) ] ) => {
921- self . format_repr ( elem)
922- }
923- ( Prim :: FormatLimit64 , [ Elim :: FunApp ( _) , Elim :: FunApp ( elem) ] ) => {
924- self . format_repr ( elem)
925- }
926- ( Prim :: FormatRepeatUntilEnd , [ Elim :: FunApp ( elem) ] ) => Spanned :: new (
927- format. span ( ) ,
928- Arc :: new ( Value :: prim ( Prim :: ArrayType , [ self . format_repr ( elem) ] ) ) ,
929- ) ,
930- ( Prim :: FormatLink , [ Elim :: FunApp ( _) , Elim :: FunApp ( elem) ] ) => Spanned :: new (
931- format. span ( ) ,
932- Arc :: new ( Value :: prim ( Prim :: RefType , [ elem. clone ( ) ] ) ) ,
933- ) ,
934- ( Prim :: FormatDeref , [ Elim :: FunApp ( elem) , Elim :: FunApp ( _) ] ) => {
935- self . format_repr ( elem)
936- }
937- ( Prim :: FormatStreamPos , [ ] ) => {
938- Spanned :: new ( format. span ( ) , Arc :: new ( Value :: prim ( Prim :: PosType , [ ] ) ) )
939- }
940- ( Prim :: FormatSucceed , [ Elim :: FunApp ( elem) , _] ) => elem. clone ( ) ,
941- ( Prim :: FormatFail , [ ] ) => {
942- Spanned :: new ( format. span ( ) , Arc :: new ( Value :: prim ( Prim :: VoidType , [ ] ) ) )
943- }
944- ( Prim :: FormatUnwrap , [ Elim :: FunApp ( elem) , _] ) => elem. clone ( ) ,
945- ( Prim :: ReportedError , [ ] ) => Spanned :: new (
946- format. span ( ) ,
947- Arc :: new ( Value :: prim ( Prim :: ReportedError , [ ] ) ) ,
948- ) ,
949- _ => Spanned :: new (
950- format. span ( ) ,
951- Arc :: new ( Value :: prim ( Prim :: FormatRepr , [ format. clone ( ) ] ) ) ,
952- ) ,
869+ ( Prim :: FormatDeref , [ Elim :: FunApp ( elem) , _] ) => return self . format_repr ( elem) ,
870+ ( Prim :: FormatStreamPos , [ ] ) => Value :: prim ( Prim :: PosType , [ ] ) ,
871+ ( Prim :: FormatSucceed , [ Elim :: FunApp ( elem) , _] ) => return elem. clone ( ) ,
872+ ( Prim :: FormatFail , [ ] ) => Value :: prim ( Prim :: VoidType , [ ] ) ,
873+ ( Prim :: FormatUnwrap , [ Elim :: FunApp ( elem) , _] ) => return elem. clone ( ) ,
874+ ( Prim :: ReportedError , [ ] ) => Value :: prim ( Prim :: ReportedError , [ ] ) ,
875+ _ => Value :: prim ( Prim :: FormatRepr , [ format. clone ( ) ] ) ,
953876 } ,
954- Value :: Stuck ( _, _) => Spanned :: new (
955- format. span ( ) ,
956- Arc :: new ( Value :: prim ( Prim :: FormatRepr , [ format. clone ( ) ] ) ) ,
957- ) ,
877+ Value :: Stuck ( _, _) => Value :: prim ( Prim :: FormatRepr , [ format. clone ( ) ] ) ,
958878 _ => panic_any ( Error :: InvalidFormatRepr ) ,
959- }
879+ } ;
880+
881+ Spanned :: new ( format. span ( ) , Arc :: new ( value) )
960882 }
961883}
962884
0 commit comments