[examples] rearrange examples to give big examples their own folder; add hand written files for type info example

This commit is contained in:
Allen Webster
2021-09-19 16:28:06 -07:00
parent 0a07520fac
commit 2be6caf79a
14 changed files with 91 additions and 7 deletions
+10 -5
View File
@@ -9,12 +9,17 @@ cd ..
echo "~~~ Build All Exampes ~~~" echo "~~~ Build All Exampes ~~~"
bin/bld_core.sh show_ctx bin/bld_core.sh show_ctx
metasrc="examples/metaprograms" examps="examples"
bin/bld_core.sh unit type_metadata $metasrc/type_metadata.c bin/bld_core.sh unit type_metadata $examps/type_metadata/type_metadata.c
bin/bld_core.sh unit parse_check $metasrc/parse_check.c bin/bld_core.sh unit hello_world $examps/intro/hello_world.c
bin/bld_core.sh unit user_errors $metasrc/user_errors.c bin/bld_core.sh unit parse_check $examps/intro/parse_check.c
bin/bld_core.sh unit datadesk_like $metasrc/datadesk_like_template.c bin/bld_core.sh unit datadesk_like $examps/intro/datadesk_like_template.c
bin/bld_core.sh unit user_errors $examps/user_errors/user_errors.c
if [ -d $examps/type_metadata/generated/type_info_meta.h ]; then
bin/bld_core.sh unit type_info $examps/type_metadata/type_info_final_program.c
fi
echo echo
@@ -19,7 +19,7 @@ main(int argc, char **argv){
// parse a string // parse a string
MD_String8 name = MD_S8Lit("<name>"); MD_String8 name = MD_S8Lit("<name>");
MD_String8 hello_world = MD_S8Lit("hello world"); MD_String8 hello_world = MD_S8Lit("hello world");
MD_ParseResult parse = MD_ParseWholeString(arena, hello_world_name, hello_world); MD_ParseResult parse = MD_ParseWholeString(arena, name, hello_world);
// print the results // print the results
MD_PrintDebugDumpFromNode(stdout, parse.node, MD_GenerateFlags_All); MD_PrintDebugDumpFromNode(stdout, parse.node, MD_GenerateFlags_All);
+1
View File
@@ -0,0 +1 @@
generated/*
+58
View File
@@ -0,0 +1,58 @@
/*
** Example: type-metadata
**
** This is a hand written header to be included into the final program to
** define types that will be used to layout the metadata tables created by the
** generator.
**
** This file *does not* get included into the generator itself.
**
*/
#ifndef TYPE_INFO_H
#define TYPE_INFO_H
typedef enum TypeKind
{
TypeKind_Null,
TypeKind_Basic,
TypeKind_Struct,
TypeKind_Enum,
} TypeKind;
typedef struct TypeInfo TypeInfo;
struct TypeInfo
{
TypeKind kind;
char *name;
int name_length;
union
{
// basic
int size;
// struct: array of TypeInfoMember
// enum: array of TypeInfoEnumerant
int child_count;
void *children;
};
};
typedef struct TypeInfoMember TypeInfoMember;
struct TypeInfoMember
{
char *name;
int name_length;
int array_count;
TypeInfo *type;
};
typedef struct TypeInfoEnumerant TypeInfoEnumerant;
struct TypeInfoEnumerant
{
char *name;
int name_length;
int value;
};
#endif //TYPE_INFO_H
@@ -0,0 +1,20 @@
/*
** Example: type-metadata
**
** This file shows including the generated type information into a final
** program and using that type info to unpack a buffer of data.
**
*/
#include "generated/type_info_meta.h"
#include "generated/type_info_meta.c"
#include <stdio.h>
int
main(int argc, char **argv)
{
return(0);
}
@@ -161,7 +161,6 @@ main(int argc, char **argv)
printf("%.*s: map\n", MD_S8VArg(node->string)); printf("%.*s: map\n", MD_S8VArg(node->string));
} }
// TODO metadata hand-written portion
// TODO check types & build member lists // TODO check types & build member lists
// TODO check maps & build case lists // TODO check maps & build case lists
// TODO generate type definitions // TODO generate type definitions
@@ -45,6 +45,7 @@ type_info_from_shape:
Polygon -> RoundedPolygon, Polygon -> RoundedPolygon,
} }
@map(Shape -> U32; default: 0; auto: 64) @map(Shape -> U32; default: 0; auto: 64)
max_slot_from_shape: max_slot_from_shape:
{ {