mirror of
https://github.com/Ed94/metadesk.git
synced 2026-08-06 07:38:45 +00:00
[examples] edit the datadesk-like example
This commit is contained in:
@@ -9,9 +9,9 @@ cd ..
|
|||||||
echo "~~~ Build All Exampes ~~~"
|
echo "~~~ Build All Exampes ~~~"
|
||||||
bin/bld_core.sh show_ctx
|
bin/bld_core.sh show_ctx
|
||||||
|
|
||||||
bin/bld_core.sh unit old_style_custom_layer examples/old_style_custom_layer.c
|
bin/bld_core.sh unit datadesk_like examples/datadesk_like_template.c
|
||||||
bin/bld_core.sh unit node_errors examples/node_errors/node_errors.c
|
bin/bld_core.sh unit node_errors examples/node_errors/node_errors.c
|
||||||
bin/bld_core.sh unit parse_check examples/parse_check.c
|
bin/bld_core.sh unit parse_check examples/parse_check.c
|
||||||
|
|
||||||
echo
|
echo
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,86 @@
|
|||||||
|
/*
|
||||||
|
** Example: datadesk-like-template
|
||||||
|
**
|
||||||
|
** This example is setup as a copy-pastable template for creating metadesk
|
||||||
|
** based metaprograms that have the same structure as datadesk.
|
||||||
|
**
|
||||||
|
** Datadesk was a precursor language to metadesk. This example is mostly meant
|
||||||
|
** to help datadesk users understand metadesk and migrate onto it.
|
||||||
|
**
|
||||||
|
** A "datadesk-like" metaprogram is passed the input metacode files on the
|
||||||
|
** command line. These files are parsed. Then a set of three user-defined
|
||||||
|
** functions that form the "custom layer" are called. The "custom layer"
|
||||||
|
** defines all the additional analysis and code generation.
|
||||||
|
**
|
||||||
|
*/
|
||||||
|
|
||||||
|
//~ Includes and globals //////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#include "md.h"
|
||||||
|
#include "md.c"
|
||||||
|
|
||||||
|
static MD_Arena *arena = 0;
|
||||||
|
|
||||||
|
|
||||||
|
//~ Declare user defined functions (the datadesk "custom layer") //////////////
|
||||||
|
|
||||||
|
// Called when the program starts.
|
||||||
|
static void Initialize(void);
|
||||||
|
// Called for every top-level node that is parsed from passed files.
|
||||||
|
static void TopLevel(MD_Node *node);
|
||||||
|
// Runs before the program ends.
|
||||||
|
static void CleanUp(void);
|
||||||
|
|
||||||
|
|
||||||
|
//~ main //////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
int main(int argument_count, char **arguments)
|
||||||
|
{
|
||||||
|
// simple single-threaded one-run memory management setup
|
||||||
|
arena = MD_ArenaAlloc(1ull << 40);
|
||||||
|
|
||||||
|
// parse all files passed to the command line
|
||||||
|
MD_Node *list = MD_MakeList(arena);
|
||||||
|
for(int i = 1; i < argument_count; i += 1)
|
||||||
|
{
|
||||||
|
MD_Node *root = MD_ParseWholeFile(arena, MD_S8CString(arguments[i])).node;
|
||||||
|
MD_PushNewReference(arena, list, root);
|
||||||
|
}
|
||||||
|
|
||||||
|
// calls to the "custom layer"
|
||||||
|
Initialize();
|
||||||
|
for(MD_EachNode(ref, list->first_child))
|
||||||
|
{
|
||||||
|
MD_Node *root = MD_NodeFromReference(ref);
|
||||||
|
for(MD_EachNode(node, root->first_child))
|
||||||
|
{
|
||||||
|
TopLevel(node);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
CleanUp();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//~ The "custom layer" definitions ////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
Initialize(void)
|
||||||
|
{
|
||||||
|
/*TODO*/
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
TopLevel(MD_Node *node)
|
||||||
|
{
|
||||||
|
/*TODO*/
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
CleanUp(void)
|
||||||
|
{
|
||||||
|
/*TODO*/
|
||||||
|
}
|
||||||
|
|
||||||
@@ -1,51 +0,0 @@
|
|||||||
// Sample code for old Data Desk style custom layer, adapted to Metadesk.
|
|
||||||
|
|
||||||
#include "md.h"
|
|
||||||
#include "md.c"
|
|
||||||
|
|
||||||
static MD_Arena *arena = 0;
|
|
||||||
|
|
||||||
static void
|
|
||||||
Initialize(void)
|
|
||||||
{
|
|
||||||
// Called when the program starts.
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
TopLevel(MD_Node *node)
|
|
||||||
{
|
|
||||||
// Called for every top-level node that is parsed from passed files.
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
CleanUp(void)
|
|
||||||
{
|
|
||||||
// Runs before the program ends.
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(int argument_count, char **arguments)
|
|
||||||
{
|
|
||||||
arena = MD_ArenaAlloc(1ull << 40);
|
|
||||||
|
|
||||||
// NOTE(rjf): Parse all the files passed in via command line.
|
|
||||||
MD_Node *list = MD_MakeList(arena);
|
|
||||||
for(int i = 1; i < argument_count; i += 1)
|
|
||||||
{
|
|
||||||
MD_Node *root = MD_ParseWholeFile(arena, MD_S8CString(arguments[i])).node;
|
|
||||||
MD_PushNewReference(arena, list, root);
|
|
||||||
}
|
|
||||||
|
|
||||||
// NOTE(rjf): Call "custom layer" back.
|
|
||||||
Initialize();
|
|
||||||
for(MD_EachNode(ref, list->first_child))
|
|
||||||
{
|
|
||||||
MD_Node *root = MD_NodeFromReference(ref);
|
|
||||||
for(MD_EachNode(node, root->first_child))
|
|
||||||
{
|
|
||||||
TopLevel(node);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
CleanUp();
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
+1
-1
@@ -9,7 +9,7 @@ Examples:
|
|||||||
[ ] Metadesk reprinter
|
[ ] Metadesk reprinter
|
||||||
[ ] Example of helpers: string helpers, linked lists, map type
|
[ ] Example of helpers: string helpers, linked lists, map type
|
||||||
printing errors, cmd line, file iter
|
printing errors, cmd line, file iter
|
||||||
[ ] Datadesk-like setup
|
[x] Datadesk-like setup
|
||||||
[ ] Example type metadata
|
[ ] Example type metadata
|
||||||
[ ] Example of simple expression parser
|
[ ] Example of simple expression parser
|
||||||
[ ] Example of C-like expression parser (with value and type expressions)
|
[ ] Example of C-like expression parser (with value and type expressions)
|
||||||
|
|||||||
+14
-3
@@ -67,10 +67,21 @@ command_list =
|
|||||||
{ "bin/run_tests.sh", .os = "mac" },
|
{ "bin/run_tests.sh", .os = "mac" },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
.name = "build_examples",
|
||||||
|
.out = "*compilation*",
|
||||||
|
.footer_panel = true,
|
||||||
|
.save_dirty_files = true,
|
||||||
|
.cursor_at_end = false,
|
||||||
|
.cmd =
|
||||||
|
{
|
||||||
|
{ "git_bash bin\\build_examples.sh", .os = "win" },
|
||||||
|
{ "bin/build_tests.sh", .os = "linux" },
|
||||||
|
{ "bin/build_tests.sh", .os = "mac" },
|
||||||
|
},
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
fkey_command[1] = "build_tests";
|
fkey_command[1] = "build_tests";
|
||||||
fkey_command[2] = "run_tests";
|
fkey_command[2] = "run_tests";
|
||||||
|
fkey_command[3] = "build_examples";
|
||||||
fkey_command[8] = "build";
|
|
||||||
fkey_command[9] = "build_with_clang";
|
|
||||||
Reference in New Issue
Block a user