]> Nishi Git Mirror - gwion.git/commitdiff
:art: Add ability to embed gw files
authorfennecdjay <fennecdjay@gmail.com>
Sat, 21 Jan 2023 00:17:17 +0000 (01:17 +0100)
committerfennecdjay <fennecdjay@gmail.com>
Sat, 21 Jan 2023 00:17:17 +0000 (01:17 +0100)
Makefile
fmt
scripts/gw_embed.sh [new file with mode: 0644]
src/main.c

index a2d0a4cc060be7abbba92dad625acb7c24c7c6e9..d2ea31457d235381607da9b248bae3e347f71b89 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -79,6 +79,11 @@ options-show:
        @$(call _options)
        @$(info libs: ${GWLIBS})
 
+embed_gw:
+       bash scripts/gw_embed.sh ${GWION_EMBED_GW} > src/embed.c
+       CFLAGS="-DGWION_EMBED_GW -Iembed $(eval ${CFLAGS})" ${MAKE}
+       rm src/embed.c
+
 almost_gwion: ${almost_obj} ${ALMOST_LIBS}
 
 lto:
diff --git a/fmt b/fmt
index bee2f7b0dc9942e804aa12d2cf3c29914c38b834..c026b026ff0a93b1fe4790f0918e315ff045a9f6 160000 (submodule)
--- a/fmt
+++ b/fmt
@@ -1 +1 @@
-Subproject commit bee2f7b0dc9942e804aa12d2cf3c29914c38b834
+Subproject commit c026b026ff0a93b1fe4790f0918e315ff045a9f6
diff --git a/scripts/gw_embed.sh b/scripts/gw_embed.sh
new file mode 100644 (file)
index 0000000..391bf03
--- /dev/null
@@ -0,0 +1,46 @@
+#!/bin/sh
+header_name() {
+  echo "$1" | sed 's/\./_/' | sed 's#/#_#g'
+}
+
+cat << EOF
+#include "gwion_util.h"
+#include "gwion_ast.h"
+#include "gwion_env.h"
+#include "vm.h"
+#include "instr.h"
+#include "emit.h"
+#include "compile.h"
+#include "gwion.h"
+
+static void compile_embed_gw(const Gwion gwion, const m_str filename,
+                              const m_str content, const size_t sz)  {
+  const m_str str = mp_malloc2(gwion->mp, sz + 1);
+  memcpy(str, content, sz);
+  str[sz] = 0;
+  compile_string(gwion, filename, str);
+  mp_free2(gwion->mp, sz + 1, str);
+}
+
+EOF
+
+for file in $GWION_EMBED_GW
+do
+  name=$(header_name "$file")
+  xxd -i "$file" > embed/"${name}.h"
+  echo "#include \"${name}.h\""
+done
+
+
+
+echo "void embed_gw(const Gwion gwion) {"
+
+for file in $GWION_EMBED_GW
+do
+  name=$(header_name "$file")
+  xxd -i "$file" > "${name}.h"
+  echo "  compile_embed_gw(gwion, \"$file\", ${name}, ${name}_len);"
+
+done
+
+echo "}"
index d8abd6efd9554581a00bccc89047fe546cc95a68..ccd94559efe52dfee2eaa59be06269a523829c83 100644 (file)
@@ -43,12 +43,19 @@ int main(int argc, char **argv) {
 
 #else
 
+#ifdef GWION_EMBED_GW
+void embed_gw(const Gwion);
+#endif
+
 int main(int argc, char **argv) {
   CliArg arg = {.arg = {.argc = argc, .argv = argv}, .loop = false};
   signal(SIGINT, sig);
   signal(SIGTERM, sig);
   const m_bool  ini   = gwion_ini(&gwion, &arg);
   arg_release(&arg);
+#ifdef GWION_EMBED_GW
+  embed_gw(&gwion);
+#endif
   if (ini > 0) gwion_run(&gwion);
   gwion_end(&gwion);
   gwion.vm = NULL;