@@ -20,8 +20,8 @@ use crate::{
2020 traverse:: { Traverse as _, TraverseOrder } ,
2121 typ:: Type ,
2222} ;
23- use nickel_lang_vector:: Slice ;
2423use malachite:: base:: num:: conversion:: traits:: ToSci as _;
24+ use nickel_lang_vector:: Slice ;
2525use std:: {
2626 alloc:: { Layout , alloc, dealloc} ,
2727 cmp:: max,
@@ -978,29 +978,48 @@ impl NickelValue {
978978 /// class is less precise than the type and indicates the general shape of the term: `Record`
979979 /// for records, `Array` for arrays, etc. If the term is not a WHNF, `None` is returned.
980980 pub fn type_of ( & self ) -> Option < & ' static str > {
981- match self . tag ( ) {
982- ValueTag :: Pointer => match self . body_tag ( ) . unwrap ( ) {
983- BodyTag :: Number => Some ( "Number" ) ,
984- BodyTag :: Array => Some ( "Array" ) ,
985- BodyTag :: Record => Some ( "Record" ) ,
986- BodyTag :: String => Some ( "String" ) ,
987- BodyTag :: Label => Some ( "Label" ) ,
988- BodyTag :: EnumVariant => {
989- let variant = self . as_value_body :: < EnumVariantBody > ( ) . unwrap ( ) ;
990- if variant. arg . is_some ( ) {
991- Some ( "EnumVariant" )
992- } else {
993- Some ( "EnumTag" )
994- }
995- }
996- BodyTag :: ForeignId => Some ( "ForeignId" ) ,
997- BodyTag :: SealingKey => Some ( "SealingKey" ) ,
998- BodyTag :: CustomContract => Some ( "CustomContract" ) ,
999- BodyTag :: Type => Some ( "Type" ) ,
1000- BodyTag :: Thunk | BodyTag :: Term => None ,
981+ match self . content_ref ( ) {
982+ ValueContentRef :: Inline ( inline) => match inline {
983+ InlineValue :: True | InlineValue :: False => Some ( "Bool" ) ,
984+ InlineValue :: Null => Some ( "Other" ) ,
985+ InlineValue :: EmptyArray => Some ( "Array" ) ,
986+ InlineValue :: EmptyRecord => Some ( "Record" ) ,
1001987 } ,
1002- // Safety: `self.tag()` is `ValueTag::Inline`
1003- ValueTag :: Inline => unsafe { self . as_inline_unchecked ( ) . type_of ( ) } ,
988+ ValueContentRef :: Number ( _) => Some ( "Number" ) ,
989+ ValueContentRef :: Array ( _) => Some ( "Array" ) ,
990+ ValueContentRef :: Record ( _) => Some ( "Record" ) ,
991+ ValueContentRef :: String ( _) => Some ( "String" ) ,
992+ ValueContentRef :: Term ( term_body) => match & term_body. 0 {
993+ Term :: Value ( v) | Term :: Closurize ( v) => v. type_of ( ) ,
994+ Term :: RecRecord ( ..) => Some ( "Record" ) ,
995+ Term :: Fun ( ..) | Term :: FunPattern ( ..) => Some ( "Function" ) ,
996+ Term :: Match { .. } => Some ( "MatchExpression" ) ,
997+ Term :: Sealed ( ..) => Some ( "Sealed" ) ,
998+ Term :: Annotated ( ..) => Some ( "Annotated" ) ,
999+ Term :: Let ( ..)
1000+ | Term :: LetPattern ( ..)
1001+ | Term :: App ( _, _)
1002+ | Term :: Var ( _)
1003+ | Term :: Op1 ( _, _)
1004+ | Term :: Op2 ( _, _, _)
1005+ | Term :: OpN ( ..)
1006+ | Term :: Import ( _)
1007+ | Term :: ResolvedImport ( _)
1008+ | Term :: StrChunks ( _)
1009+ | Term :: ParseError ( _)
1010+ | Term :: RuntimeError ( _) => None ,
1011+ } ,
1012+ ValueContentRef :: Label ( _) => Some ( "Label" ) ,
1013+ ValueContentRef :: EnumVariant ( EnumVariantBody { arg : None , tag : _ } ) => Some ( "EnumTag" ) ,
1014+ ValueContentRef :: EnumVariant ( EnumVariantBody {
1015+ arg : Some ( _) ,
1016+ tag : _,
1017+ } ) => Some ( "EnumVariant" ) ,
1018+ ValueContentRef :: ForeignId ( _) => Some ( "ForeignId" ) ,
1019+ ValueContentRef :: SealingKey ( _) => Some ( "SealingKey" ) ,
1020+ ValueContentRef :: CustomContract ( _) => Some ( "CustomContract" ) ,
1021+ ValueContentRef :: Type ( _) => Some ( "Type" ) ,
1022+ _ => None ,
10041023 }
10051024 }
10061025
0 commit comments