.
[clean-tests.git] / structs / GenC.dcl
1 definition module GenC
2
3 import StdGeneric
4 from Data.Either import :: Either
5 from StdOverloaded import class zero
6
7 /**
8 * Helper types for @ style types
9 */
10 :: Box b a =: Box b
11 derive bimap Box
12 unBox (Box b) :== b
13 box b :== Box b
14 reBox x :== box (unBox x)
15
16 /**
17 * Calculate whether a type has a potentially infinite size
18 */
19 potInf :: Box Bool a | gPotInf{|*|} a
20 generic gPotInf a :: [String] -> Box Bool a
21 derive gPotInf Int, Bool, Char, Real, World, Dynamic, UNIT, CONS, FIELD, EITHER, PAIR, OBJECT of {gtd_name}, RECORD of {grd_name}
22
23 /**
24 * Calculate the ctype representation of a type
25 */
26 toStruct :: Box GTSState a | gToStruct{|*|} a
27 :: GTSResult
28 :: GTSState
29 instance zero GTSState
30 generic gToStruct a | gPotInf a :: GTSState -> (GTSResult, Box GTSState a)
31 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}
32
33 /**
34 * Given a GTSState, generate typedefinitions
35 */
36 toCType :: GTSState -> [String]
37
38 /**
39 * Given a GTSState, generate a parser
40 * @result Function signatures
41 * @result Function
42 */
43 toCParser :: GTSState -> ([String], [String])
44 /**
45 * Given a GTSState, generate a printer
46 * @result Function signatures
47 * @result Function
48 */
49 toCPrinter :: GTSState -> ([String], [String])
50
51 /**
52 * Generate a serialized value for the given type
53 * @param value
54 * @param continuation list
55 * @result Bytes
56 */
57 toCValue :: a [Char] -> [Char] | gToCValue{|*|} a
58 generic gToCValue a :: a [Char] -> [Char]
59 derive gToCValue Int, Bool, Char, UNIT, EITHER, PAIR, CONS of {gcd_index}, FIELD, RECORD, OBJECT
60
61 /**
62 * Parse a value from the serializized value
63 * @param bytes
64 * @result Either an error or a value
65 */
66 :: FromCValueError = CVEUnknownConstructor | CVEInputExhausted
67 fromCValue :: [Char] -> Either FromCValueError (a, [Char]) | gFromCValue{|*|} a
68 generic gFromCValue a :: ([Char] -> Either FromCValueError (a, [Char]))
69 derive gFromCValue Int, Bool, Char, UNIT, EITHER, PAIR, CONS of {gcd_index}, FIELD, RECORD, OBJECT
70
71 /**
72 * @param type in a box with a filename
73 * @param .h file
74 * @param .c file
75 */
76 toCFiles :: (Box String a) -> ([String], [String]) | gToStruct{|*|} a