typeGenType :: Type -> [GenType]
/**
- * Return the kind of the type
+ * Return an approximation of the kind of the type given all the constructors
*/
:: Kind = KStar | (KArrow) infixr 1 Kind Kind
-genTypeKind :: GenType -> Kind
+genTypeKind :: [GenType] -> Kind
+instance toString Kind
/**
* Predicate whether the outer type is a builtin type
typeGenType (TyRecord i _) = [i.grd_type]
typeGenType (TyObject _ fs) = [c.gcd_type\\(c, _)<-fs]
-genTypeKind :: GenType -> Kind
-genTypeKind (GenTypeCons _) = KStar
-genTypeKind (GenTypeVar _) = KStar
-genTypeKind (GenTypeArrow l r) = genTypeKind l KArrow genTypeKind r
-genTypeKind (GenTypeApp l r) = genTypeKind l KArrow genTypeKind r
+genTypeKind :: [GenType] -> Kind
+genTypeKind ts = foldr (KArrow) KStar $ map snd $ sortBy ((<) `on` fst) $ foldr (\t->gt t id) [] ts
+where
+ gt :: GenType (Kind -> Kind) [(Int, Kind)] -> [(Int, Kind)]
+ gt (GenTypeCons _) c ks = ks
+ gt (GenTypeVar i) c ks = case lookup i ks of
+ Nothing = [(i, c KStar):ks]
+ Just KStar = [(i, c KStar):filter ((<>)i o fst) ks]
+ Just _ = ks
+ gt (GenTypeArrow l r) c ks = gt l id $ gt r id ks
+ gt (GenTypeApp l r) c ks = gt l ((KArrow) KStar o c) $ gt r id ks
+instance toString Kind where toString k = concat $ print k []
+instance print Kind
+where
+ print KStar c = ["*":c]
+ print (l KArrow r) c = ["(":print l ["->":print r [")":c]]]
instance isBuiltin String
where
parsedef :: Type [String] -> [String]
parsedef t c
- # (pt, _) = trace_stdout (parsefun t, map genTypeKind $ typeGenType t)
+ # (pt, _) = trace_stdout (parsefun t, toString $ genTypeKind $ typeGenType t)
= ctypename t [" *", /*parsefun */pt, "(uint8_t (*get)()",pd t, ")":c]
where
pd (TyBasic s) = ""
import Data.GenType.CParser
import Text
-derive gType Either, T, R, Frac, Tr, Fix, Odd, Even, SR, List, Enum, NT, Blurp, EnumList, ER, CP, RA, Nest, MR
+derive gType Either, T, R, Frac, Tr, Fix, Odd, Even, SR, List, Enum, NT, Blurp, EnumList, ER, CP, RA, Nest, MR, P
+
+:: P m = P (Tr m Int) | P2 (m Bool Bool)
:: T a = T2 a Char
:: NT =: NT Int
, genFiles "lmint" lmInt
, genFiles "trEitherInt" trEitherInt
, genFiles "mrMaybe" mrMaybe
+ , genFiles "pEither" pEither
]
// ( flatTypedef $ gTypeToType $ unBox t
// , typedefs $ map (map gTypeToType) $ map (filter (not o isBasic)) $ flattenGType $ unBox t
mrMaybe :: Box GType (MR ?)
mrMaybe = gType{|*|}
+ pEither :: Box GType (P Either)
+ pEither = gType{|*|}
+
//Start = typedefs //$ (\x->[[gTypeToType x]])
// $ map (/*filter (not o isBuiltin) o*/ catMaybes o map gTypeToType)
// $ (\x->[[x]])