definition module GenC import StdGeneric from Data.Either import :: Either from StdOverloaded import class zero /** * Helper types for @ style types */ :: Box b a =: Box b derive bimap Box unBox (Box b) :== b box b :== Box b reBox x :== box (unBox x) /** * Calculate whether a type has a potentially infinite size */ potInf :: Box Bool a | gPotInf{|*|} a generic gPotInf a :: [String] -> Box Bool a derive gPotInf Int, Bool, Char, Real, World, Dynamic, UNIT, CONS, FIELD, EITHER, PAIR, OBJECT of {gtd_name}, RECORD of {grd_name} /** * Calculate the ctype representation of a type */ toStruct :: Box GTSState a | gToStruct{|*|} a :: GTSResult :: GTSState instance zero GTSState generic gToStruct a | gPotInf a :: GTSState -> (GTSResult, Box GTSState a) derive gToStruct Int, Bool, Char, Real, UNIT, CONS of {gcd_type}, FIELD, EITHER, PAIR, OBJECT of {gtd_arity,gtd_name,gtd_conses,gtd_num_conses}, RECORD of {grd_arity,grd_name,grd_fields} /** * Given a GTSState, generate typedefinitions */ toCType :: GTSState -> [String] /** * Given a GTSState, generate a parser * @result Function signatures * @result Function */ toCParser :: GTSState -> ([String], [String]) /** * Given a GTSState, generate a printer * @result Function signatures * @result Function */ toCPrinter :: GTSState -> ([String], [String]) /** * Generate a serialized value for the given type * @param value * @param continuation list * @result Bytes */ toCValue :: a [Char] -> [Char] | gToCValue{|*|} a generic gToCValue a :: a [Char] -> [Char] derive gToCValue Int, Bool, Char, UNIT, EITHER, PAIR, CONS of {gcd_index}, FIELD, RECORD, OBJECT /** * Parse a value from the serializized value * @param bytes * @result Either an error or a value */ :: FromCValueError = CVEUnknownConstructor | CVEInputExhausted fromCValue :: [Char] -> Either FromCValueError (a, [Char]) | gFromCValue{|*|} a generic gFromCValue a :: ([Char] -> Either FromCValueError (a, [Char])) derive gFromCValue Int, Bool, Char, UNIT, EITHER, PAIR, CONS of {gcd_index}, FIELD, RECORD, OBJECT /** * @param type in a box with a filename * @param .h file * @param .c file */ toCFiles :: (Box String a) -> ([String], [String]) | gToStruct{|*|} a