diff --git a/bin/build_examples.sh b/bin/build_examples.sh index 295368d..e798cc0 100755 --- a/bin/build_examples.sh +++ b/bin/build_examples.sh @@ -9,12 +9,17 @@ cd .. echo "~~~ Build All Exampes ~~~" 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 parse_check $metasrc/parse_check.c -bin/bld_core.sh unit user_errors $metasrc/user_errors.c -bin/bld_core.sh unit datadesk_like $metasrc/datadesk_like_template.c +bin/bld_core.sh unit type_metadata $examps/type_metadata/type_metadata.c +bin/bld_core.sh unit hello_world $examps/intro/hello_world.c +bin/bld_core.sh unit parse_check $examps/intro/parse_check.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 diff --git a/examples/metaprograms/datadesk_like_template.c b/examples/intro/datadesk_like_template.c similarity index 100% rename from examples/metaprograms/datadesk_like_template.c rename to examples/intro/datadesk_like_template.c diff --git a/examples/metaprograms/hello_world.c b/examples/intro/hello_world.c similarity index 86% rename from examples/metaprograms/hello_world.c rename to examples/intro/hello_world.c index a7fb0e0..55de86f 100644 --- a/examples/metaprograms/hello_world.c +++ b/examples/intro/hello_world.c @@ -19,7 +19,7 @@ main(int argc, char **argv){ // parse a string MD_String8 name = MD_S8Lit(""); 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 MD_PrintDebugDumpFromNode(stdout, parse.node, MD_GenerateFlags_All); diff --git a/examples/mdesk_files/hello_world.mdesk b/examples/intro/hello_world.mdesk similarity index 100% rename from examples/mdesk_files/hello_world.mdesk rename to examples/intro/hello_world.mdesk diff --git a/examples/mdesk_files/labels.mdesk b/examples/intro/labels.mdesk similarity index 100% rename from examples/mdesk_files/labels.mdesk rename to examples/intro/labels.mdesk diff --git a/examples/metaprograms/parse_check.c b/examples/intro/parse_check.c similarity index 100% rename from examples/metaprograms/parse_check.c rename to examples/intro/parse_check.c diff --git a/examples/mdesk_files/sets.mdesk b/examples/intro/sets.mdesk similarity index 100% rename from examples/mdesk_files/sets.mdesk rename to examples/intro/sets.mdesk diff --git a/examples/type_metadata/.gitignore b/examples/type_metadata/.gitignore new file mode 100644 index 0000000..11390d2 --- /dev/null +++ b/examples/type_metadata/.gitignore @@ -0,0 +1 @@ +generated/* diff --git a/examples/type_metadata/type_info.h b/examples/type_metadata/type_info.h new file mode 100644 index 0000000..581e800 --- /dev/null +++ b/examples/type_metadata/type_info.h @@ -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 diff --git a/examples/type_metadata/type_info_final_program.c b/examples/type_metadata/type_info_final_program.c new file mode 100644 index 0000000..410b749 --- /dev/null +++ b/examples/type_metadata/type_info_final_program.c @@ -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 + +int +main(int argc, char **argv) +{ + + + return(0); +} diff --git a/examples/metaprograms/type_metadata.c b/examples/type_metadata/type_metadata.c similarity index 99% rename from examples/metaprograms/type_metadata.c rename to examples/type_metadata/type_metadata.c index a77b802..5c085c9 100644 --- a/examples/metaprograms/type_metadata.c +++ b/examples/type_metadata/type_metadata.c @@ -161,7 +161,6 @@ main(int argc, char **argv) printf("%.*s: map\n", MD_S8VArg(node->string)); } - // TODO metadata hand-written portion // TODO check types & build member lists // TODO check maps & build case lists // TODO generate type definitions diff --git a/examples/mdesk_files/types.mdesk b/examples/type_metadata/types.mdesk similarity index 99% rename from examples/mdesk_files/types.mdesk rename to examples/type_metadata/types.mdesk index f19f0c2..5d3aff6 100644 --- a/examples/mdesk_files/types.mdesk +++ b/examples/type_metadata/types.mdesk @@ -45,6 +45,7 @@ type_info_from_shape: Polygon -> RoundedPolygon, } + @map(Shape -> U32; default: 0; auto: 64) max_slot_from_shape: { diff --git a/examples/metaprograms/user_errors.c b/examples/user_errors/user_errors.c similarity index 100% rename from examples/metaprograms/user_errors.c rename to examples/user_errors/user_errors.c diff --git a/examples/mdesk_files/user_errors.mdesk b/examples/user_errors/user_errors.mdesk similarity index 100% rename from examples/mdesk_files/user_errors.mdesk rename to examples/user_errors/user_errors.mdesk