Skip to content
Snippets Groups Projects
Commit 8bab18aa authored by Olivier Dion's avatar Olivier Dion Committed by Sébastien Blin
Browse files

agent: Add compilation of Scheme file

Change-Id: Ic25a41cb28ae1e8b8dc51a149c304edc7f04ef50
parent aadc8690
No related branches found
No related tags found
No related merge requests found
......@@ -3,4 +3,5 @@ agent
*.txt
*.log
.gdbinit
*.gdb
\ No newline at end of file
*.gdb
*.go
\ No newline at end of file
......@@ -17,3 +17,21 @@ agent_exe_SOURCES = \
src/bindings/signal.h
agent_exe_LDADD = $(top_builddir)/src/libring.la
MODULES = \
agent.scm \
examples/active-agent.scm \
examples/passive-agent.scm \
jami/logger.scm \
scenarios/peer-monitor/scenario.scm
GOBJECTS = $(MODULES:%=%.go)
%.go: % | agent.exe
@echo "agent.exe compile $^"
@ASAN_OPTIONS=alloc_dealloc_mismatch=0:detect_leaks=0 \
./agent.exe compile $< $@
compile: $(GOBJECTS)
CLEANFILES = $(GOBJECTS)
......@@ -33,6 +33,11 @@ struct args {
char** argv;
};
static bool streq(const char* A, const char* B)
{
return 0 == strcmp(A, B);
}
void*
main_in_guile(void* args_raw)
{
......@@ -48,18 +53,49 @@ main_in_guile(void* args_raw)
return nullptr;
}
void*
compile_in_guile(void* args_raw)
{
struct args* args = static_cast<struct args*>(args_raw);
char buf[4096];
if (args->argc < 4) {
fprintf(stderr, "Usage: agent.exe compile FILE OUT\n");
exit(EXIT_FAILURE);
}
install_scheme_primitives();
snprintf(buf, sizeof(buf),
"(use-modules (system base compile)) (compile-file \"%s\" #:output-file \"%s\")",
args->argv[2], args->argv[3]);
scm_c_eval_string(buf);
scm_gc();
return nullptr;
}
int
main(int argc, char* argv[])
{
struct args args = { argc, argv };
setenv("GUILE_LOAD_PATH", ".", 1);
setenv("GUILE_LOAD_COMPILED_PATH", ".", 1);
/* NOTE! It's very important to initialize the daemon before entering Guile!!! */
DRing::init(DRing::InitFlag(DRing::DRING_FLAG_DEBUG));
if (argc > 1 && streq(argv[1], "compile")) {
scm_with_guile(compile_in_guile, (void*)&args);
} else {
AGENT_ASSERT(DRing::start(""), "Failed to start daemon");
/* NOTE! It's very important to initialize the daemon before entering Guile!!! */
DRing::init(DRing::InitFlag(DRing::DRING_FLAG_DEBUG));
struct args args = { argc, argv };
AGENT_ASSERT(DRing::start(""), "Failed to start daemon");
/* Entering guile context - This never returns */
scm_with_guile(main_in_guile, (void*)&args);
}
/* Entering guile context - This never returns */
scm_with_guile(main_in_guile, (void*)&args);
exit(EXIT_SUCCESS);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment