-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dynamic load libraries for external functions #28
base: develop
Are you sure you want to change the base?
Conversation
4bde6ee
to
cbb8fa2
Compare
2a44623
to
d4a5c83
Compare
Shouldn't library_api.h depend on the rest of the project? This would make sense for independent library developers. |
cc77d7e
to
297e9d5
Compare
297e9d5
to
039485d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some first review comments.
The commit structure and message needs some work, it would be great if you describe more of each commit with a body, some of the time a single line doesn't do the trick.
1057782
to
f5f95c1
Compare
My commits were quite messy, now it should be much more concise. But I'm not happy with library_api.h in the last commit, any suggestions? |
f5f95c1
to
d19c9ec
Compare
I don't see a problem with the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
About the commit messages, much better, just one nitpick, capitalize the subject lines, and also you forgot to capitalize the body of the first commit
subprojects/vinumc/eval.c
Outdated
if (symbol_node->type == FUNCTION){ | ||
size_t buffer_size = 1024; | ||
char *buffer = (char*) calloc(1, buffer_size); | ||
FILE *tmp_out = fmemopen(buffer, buffer_size, "w+"); | ||
for (size_t i = 0; i < args_node->childs.len; i++) { | ||
do_calls(ast, tmp_out, VEC_AT(&args_node->childs, i)); | ||
} | ||
fflush(tmp_out); | ||
fprintf(out, "%s", symbol_node->fp(buffer)); | ||
fclose(tmp_out); | ||
free(buffer); | ||
}else{ | ||
for (size_t i = 0; i < args_node->childs.len; i++) { | ||
do_calls(ast, out, VEC_AT(&args_node->childs, i)); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (symbol_node->type == FUNCTION){ | |
size_t buffer_size = 1024; | |
char *buffer = (char*) calloc(1, buffer_size); | |
FILE *tmp_out = fmemopen(buffer, buffer_size, "w+"); | |
for (size_t i = 0; i < args_node->childs.len; i++) { | |
do_calls(ast, tmp_out, VEC_AT(&args_node->childs, i)); | |
} | |
fflush(tmp_out); | |
fprintf(out, "%s", symbol_node->fp(buffer)); | |
fclose(tmp_out); | |
free(buffer); | |
}else{ | |
for (size_t i = 0; i < args_node->childs.len; i++) { | |
do_calls(ast, out, VEC_AT(&args_node->childs, i)); | |
} | |
if (symbol_node->type == FUNCTION){ | |
size_t buffer_size = 1024; | |
char *buffer = (char*) calloc(1, buffer_size); | |
FILE *tmp_out = fmemopen(buffer, buffer_size, "w+"); | |
} | |
for (size_t i = 0; i < args_node->childs.len; i++) { | |
do_calls(ast, tmp_out, VEC_AT(&args_node->childs, i)); | |
} | |
if (symbol_node->type == FUNCTION){ | |
fflush(tmp_out); | |
fprintf(out, "%s", symbol_node->fp(buffer)); | |
fclose(tmp_out); | |
free(buffer); | |
} |
//TODO: deal with the error of not being able to open the library | ||
} | ||
|
||
struct extern_function* (*expose_library) () = dlsym(handle, "expose_library"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this could be a function pointer type, and also be exposed to the user in sseparate header file, along with extern_function
.
vunit_run_vinumc_ok(ctx, | ||
"[day_of_week 2024-09-26]\n", | ||
&out, | ||
"--with","subprojects/stdlib/libstdlib.so" , NULL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hum, maybe create an external lib just for testing inisde the vinumc project. If you want to test the stdlib behavior (which we probably should) create a test dir on the stdlib project.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that was the purpose of the stdlib of this pr
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, but I don't like that vinumc tests depend on another project.
Create another lib inside test
for isolating the two projects. For now, it could be just a dumb function that returns some string, for the current tests it will suffice.
The stdlib part of this PR will be the starting point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, documentation stuff.
Add an entry to the list of subprojects on the ./README.md
and also create a separate README.md
for stdlib.
Also, we need a way to document the API used for creating an external lib. Maybe create a file on the docs folder showing how to do it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, let's start using the semantic versioning, bump vinumc version to 0.1.0.
c405308
to
0e498bc
Compare
Add vinumc/extern_library.c and vinumc/extern_library.h which provide structures and functions for loading external libraries using dlfcn.
6480550
to
261b4c2
Compare
Gives the compiler the ability to load and execute external functions.
Add the flag "--with" allowing the user to specify a extern library.
Creates a simple stdlib to exemplify the development of external libraries for vinumc and test its execution.
1bacd6c
to
e6e6d10
Compare
Things that need attention: