mirror of
https://github.com/Ed94/metadesk.git
synced 2026-06-12 23:51:37 -07:00
[examples] input for types example that generates errors
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
** Example: type metadata
|
||||
**
|
||||
** This input for the type_metadata.c metaprogram is here to exercise some of
|
||||
** the error checks in the example.
|
||||
*/
|
||||
|
||||
|
||||
@type(basic) U32: 4;
|
||||
|
||||
|
||||
// What is a type?
|
||||
@type JustAType;
|
||||
|
||||
|
||||
// Really promising: infinite precision 2D points. Just need to figure
|
||||
// out how to implement the MagicInt now.
|
||||
@type(struct)
|
||||
MagicalPoint2D:
|
||||
{
|
||||
x: MagicInt;
|
||||
y: MagicInt;
|
||||
}
|
||||
|
||||
|
||||
// If we serialize the count of an array after the array, how do we find the
|
||||
// count?
|
||||
@type(struct)
|
||||
BackwardsArray:
|
||||
{
|
||||
vals: @array(count) U32;
|
||||
count: U32;
|
||||
}
|
||||
|
||||
|
||||
// These two just won't play nice together.
|
||||
@type(basic) TwinType: 4;
|
||||
@type(struct)
|
||||
TwinType:
|
||||
{
|
||||
val: U32;
|
||||
}
|
||||
@@ -1,81 +1,22 @@
|
||||
// generated by W:/metadesk/examples/type_metadata/type_metadata.c:949
|
||||
TypeInfoMember Circle_members[2] = {
|
||||
{"r", 1, -1, &F32_type_info},
|
||||
{"pos", 3, -1, &V2F32_type_info},
|
||||
TypeInfoMember MagicalPoint2D_members[0] = {
|
||||
};
|
||||
TypeInfoMember RoundedSegment_members[3] = {
|
||||
{"r", 1, -1, &F32_type_info},
|
||||
{"p1", 2, -1, &V2F32_type_info},
|
||||
{"p2", 2, -1, &V2F32_type_info},
|
||||
};
|
||||
TypeInfoMember RoundedPolygon_members[3] = {
|
||||
{"r", 1, -1, &F32_type_info},
|
||||
TypeInfoMember BackwardsArray_members[2] = {
|
||||
{"vals", 4, -1, &U32_type_info},
|
||||
{"count", 5, -1, &U32_type_info},
|
||||
{"p", 1, 1, &V2F32_type_info},
|
||||
};
|
||||
TypeInfoMember TwinType_members[1] = {
|
||||
{"val", 3, -1, &U32_type_info},
|
||||
};
|
||||
|
||||
// generated by W:/metadesk/examples/type_metadata/type_metadata.c:988
|
||||
TypeInfoEnumerant Shape_members[3] = {
|
||||
{"Circle", 6, 1},
|
||||
{"Segment", 7, 2},
|
||||
{"Polygon", 7, 3},
|
||||
};
|
||||
|
||||
// generated by W:/metadesk/examples/type_metadata/type_metadata.c:1024
|
||||
TypeInfo U32_type_info = {TypeKind_Basic, "U32", 3, 4, 0, 0};
|
||||
TypeInfo F32_type_info = {TypeKind_Basic, "F32", 3, 4, 0, 0};
|
||||
TypeInfo V2F32_type_info = {TypeKind_Basic, "V2F32", 5, 8, 0, 0};
|
||||
TypeInfo Circle_type_info = {TypeKind_Struct, "Circle", 6, 2, Circle_members, 0};
|
||||
TypeInfo RoundedSegment_type_info = {TypeKind_Struct, "RoundedSegment", 14, 3, RoundedSegment_members, 0};
|
||||
TypeInfo RoundedPolygon_type_info = {TypeKind_Struct, "RoundedPolygon", 14, 3, RoundedPolygon_members, 0};
|
||||
TypeInfo Shape_type_info = {TypeKind_Enum, "Shape", 5, 3, Shape_members, &U32_type_info};
|
||||
TypeInfo MagicalPoint2D_type_info = {TypeKind_Struct, "MagicalPoint2D", 14, 0, MagicalPoint2D_members, 0};
|
||||
TypeInfo BackwardsArray_type_info = {TypeKind_Struct, "BackwardsArray", 14, 2, BackwardsArray_members, 0};
|
||||
TypeInfo TwinType_type_info = {TypeKind_Basic, "TwinType", 8, 4, 0, 0};
|
||||
TypeInfo TwinType_type_info = {TypeKind_Struct, "TwinType", 8, 1, TwinType_members, 0};
|
||||
|
||||
// generated by W:/metadesk/examples/type_metadata/type_metadata.c:1084
|
||||
TypeInfo*
|
||||
type_info_from_shape(Shape v)
|
||||
{
|
||||
TypeInfo* result;
|
||||
switch (v)
|
||||
{
|
||||
default:
|
||||
{
|
||||
result = 0;
|
||||
}break;
|
||||
case Shape_Circle:
|
||||
{
|
||||
result = &Circle_type_info;
|
||||
}break;
|
||||
case Shape_Segment:
|
||||
{
|
||||
result = &RoundedSegment_type_info;
|
||||
}break;
|
||||
case Shape_Polygon:
|
||||
{
|
||||
result = &RoundedPolygon_type_info;
|
||||
}break;
|
||||
}
|
||||
return(result);
|
||||
}
|
||||
U32
|
||||
max_slot_from_shape(Shape v)
|
||||
{
|
||||
U32 result;
|
||||
switch (v)
|
||||
{
|
||||
default:
|
||||
{
|
||||
result = 0;
|
||||
}break;
|
||||
case Shape_Circle:
|
||||
case Shape_Segment:
|
||||
{
|
||||
result = 64;
|
||||
}break;
|
||||
case Shape_Polygon:
|
||||
{
|
||||
result = 12;
|
||||
}break;
|
||||
}
|
||||
return(result);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,45 +1,29 @@
|
||||
#if !defined(META_TYPES_H)
|
||||
#define META_TYPES_H
|
||||
// generated by W:/metadesk/examples/type_metadata/type_metadata.c:826
|
||||
typedef struct Circle Circle;
|
||||
struct Circle
|
||||
typedef struct MagicalPoint2D MagicalPoint2D;
|
||||
struct MagicalPoint2D
|
||||
{
|
||||
F32 r;
|
||||
V2F32 pos;
|
||||
};
|
||||
typedef struct RoundedSegment RoundedSegment;
|
||||
struct RoundedSegment
|
||||
typedef struct BackwardsArray BackwardsArray;
|
||||
struct BackwardsArray
|
||||
{
|
||||
F32 r;
|
||||
V2F32 p1;
|
||||
V2F32 p2;
|
||||
};
|
||||
typedef struct RoundedPolygon RoundedPolygon;
|
||||
struct RoundedPolygon
|
||||
{
|
||||
F32 r;
|
||||
U32 vals;
|
||||
U32 count;
|
||||
V2F32 *p;
|
||||
};
|
||||
typedef U32 Shape;
|
||||
enum
|
||||
typedef struct TwinType TwinType;
|
||||
struct TwinType
|
||||
{
|
||||
Shape_Circle = 1,
|
||||
Shape_Segment = 2,
|
||||
Shape_Polygon = 3,
|
||||
U32 val;
|
||||
};
|
||||
|
||||
// generated by W:/metadesk/examples/type_metadata/type_metadata.c:910
|
||||
TypeInfo* type_info_from_shape(Shape v);
|
||||
U32 max_slot_from_shape(Shape v);
|
||||
|
||||
// generated by W:/metadesk/examples/type_metadata/type_metadata.c:933
|
||||
extern TypeInfo U32_type_info;
|
||||
extern TypeInfo F32_type_info;
|
||||
extern TypeInfo V2F32_type_info;
|
||||
extern TypeInfo Circle_type_info;
|
||||
extern TypeInfo RoundedSegment_type_info;
|
||||
extern TypeInfo RoundedPolygon_type_info;
|
||||
extern TypeInfo Shape_type_info;
|
||||
extern TypeInfo MagicalPoint2D_type_info;
|
||||
extern TypeInfo BackwardsArray_type_info;
|
||||
extern TypeInfo TwinType_type_info;
|
||||
extern TypeInfo TwinType_type_info;
|
||||
|
||||
#endif // META_TYPES_H
|
||||
|
||||
@@ -39,6 +39,7 @@
|
||||
** types.mdesk - Sample input for this metaprogram. The code generated
|
||||
** from this metadesk file will be necessary to make
|
||||
** type_info_final_program.c compile.
|
||||
** bad_types.mdesk - Sample input for seeing some of the error checking work.
|
||||
**
|
||||
*/
|
||||
|
||||
@@ -198,7 +199,7 @@ gen_gather_types_and_maps(MD_Node *list)
|
||||
{
|
||||
MD_CodeLoc loc = MD_CodeLocFromNode(node);
|
||||
MD_PrintMessageFmt(error_file, loc, MD_MessageKind_Error,
|
||||
"Unrecognized type kind '%.*s'\n",
|
||||
"Unrecognized type kind '%.*s'",
|
||||
MD_S8VArg(tag_arg_str));
|
||||
}
|
||||
else
|
||||
@@ -1188,12 +1189,14 @@ gen_function_definitions_from_maps(FILE *out)
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
#if 1
|
||||
char *argv_dummy[2] = {
|
||||
0,
|
||||
"W:/metadesk/examples/type_metadata/types.mdesk"
|
||||
"W:/metadesk/examples/type_metadata/bad_types.mdesk"
|
||||
};
|
||||
argc = 2;
|
||||
argv = argv_dummy;
|
||||
#endif
|
||||
|
||||
// setup the global arena
|
||||
arena = MD_ArenaAlloc();
|
||||
|
||||
+3
-3
@@ -3,10 +3,10 @@ Example Programs:
|
||||
[x] Metadesk parse checker
|
||||
[x] User error checking
|
||||
[x] Data Desk like setup
|
||||
[ ] Example type metadata
|
||||
[x] Example type metadata
|
||||
[x] Cleanup & Simplification Pass
|
||||
[ ] Commentary
|
||||
[ ] Example Type File With Errors
|
||||
[x] Commentary
|
||||
[x] Example Type File With Errors
|
||||
[ ] Example of simple expression parser
|
||||
[ ] Example of C-like expression parser (with value and type expressions)
|
||||
[ ] Example(s) of using overrides
|
||||
|
||||
Reference in New Issue
Block a user